def __init__(self, id, image, name, price, availability, qty, sellerID): super().__init__() self.id = id self.image = image self.name = name self.price = price self.subTotalPrice = price self.availability = availability self.qty = qty self.sellerID = sellerID self.imageLabel = QLabel() self.imageLabel.setPixmap(self.image) self.nameLabel = QLabel() self.nameLabel.setText(self.name) self.priceLabel = QLabel() self.priceLabel.setText(formatRupiah(self.price)) # self.quantityItem = QSpinBox(minimum=1, maximum=200) self.quantityItem = QHSpinBox(1, self.qty) self.subPriceItemLabel = QLabel() self.subPriceItemLabel.setText(formatRupiah(self.price)) self.quantityItem.valueChanged.connect(self.calculateSubTotal) self.removeButton = QPushButton() self.removeButton.setText("Hapus dari Keranjang") self.vbox = QVBoxLayout() self.vbox.addWidget(self.nameLabel) self.vbox.addWidget(self.priceLabel) self.hbox = QHBoxLayout() self.hboxQty = QHBoxLayout() self.hboxQty.addWidget(self.subPriceItemLabel) self.hboxQty.addWidget(self.quantityItem) self.vbox2 = QVBoxLayout() self.vbox2.addLayout(self.hboxQty) self.vbox2.addWidget(self.removeButton) self.hbox.addWidget(self.imageLabel) self.hbox.addLayout(self.vbox) self.hbox.addLayout(self.vbox2) self.setLayout(self.hbox)
def __init__(self): super().__init__() self.orderList = [] self.nam = QtNetwork.QNetworkAccessManager() # self.setupUi() # self.doRequestOrder() self.orderID = 0 self.orderTime = 0 self.totalPrice = 0 self.balance = 0 self.cardID = 0 self.attempt = 3 self.cardPaymentStatus = False self.doRefund = False self.refundStatus = False self.serverPaymentStatus = False # def setupUi(self): self.pleaseWaitLabel = QLabel() self.pleaseWaitLabel.setAlignment(Qt.AlignCenter) self.pleaseWaitLabel.setText("Silahkan Tunggu...") self.messageLabel = QLabel() self.messageLabel.setAlignment(Qt.AlignCenter) self.totalPriceLabel = QLabel() self.totalPriceLabel.setAlignment(Qt.AlignCenter) self.totalPriceLabel.setText("Total Price: {}".format( formatRupiah(self.totalPrice))) self.balanceLabel = QLabel() self.balanceLabel.setAlignment(Qt.AlignCenter) self.balanceLabel.hide() self.progreessBar = QProgressBar() self.progreessBar.setMinimum(0) self.progreessBar.setMaximum(0) self.cancelButton = QPushButton() self.cancelButton.setText("Cancel") self.cancelButton.setMinimumSize(200, 50) self.cancelButton.setEnabled(False) self.cancelButton.clicked.connect(self.cancelButtonClicked) cancelHBox = QHBoxLayout() cancelHBox.addStretch(1) cancelHBox.addWidget(self.cancelButton) cancelHBox.addStretch(1) vbox = QVBoxLayout() vbox.addStretch(1) vbox.addWidget(self.pleaseWaitLabel) vbox.addWidget(self.messageLabel) vbox.addWidget(self.totalPriceLabel) vbox.addWidget(self.balanceLabel) vbox.addWidget(self.progreessBar) vbox.addLayout(cancelHBox) vbox.addStretch(1) self.mylogger = get_logger("Payment") self.setLayout(vbox)
def doRequestOrder(self): # Update the Loading Text self.totalPriceLabel.setText("Total Price: {}".format( formatRupiah(self.totalPrice))) self.messageLabel.setText("Memproses Order (1/2)") QCoreApplication.processEvents() data = QByteArray() data.append("paymentID=0") data.append("&") data.append("amount=") data.append(str(self.totalPrice)) data.append("&") data.append("orderStatus=placed") # print("DO REQUEST ORDER:") # print(data) self.mylogger.debug("Req Order: {}".format(data)) setting = QSettings() url = setting.value("baseURL", "") url += "/order/" # url = "http://127.0.0.1:8000/api/order/" req = QtNetwork.QNetworkRequest(QUrl(url)) req.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader, "application/x-www-form-urlencoded") reply = self.nam.post(req, data) reply.finished.connect(self.handleResponseOrder)
def __init__(self, id, image, name, price, category, availability, qtyAvailable, qtyOnBooked): super().__init__() self.id = id self.image = image self.name = name self.price = price self.category = category self.availability = availability self.qtyAvailable = qtyAvailable self.qtyOnBooked = qtyOnBooked self.imageLabel = QLabel() self.imageLabel.setPixmap(self.image) self.nameLabel = QLabel() self.nameLabel.setText(self.name) self.priceLabel = QLabel() self.priceLabel.setText(formatRupiah(price)) self.availabilityLabel = QLabel() self.qtyAvailableLabel = QLabel() self.qtyAvailableLabel.setText("Qty Available: {}".format( self.qtyAvailable)) self.qtyOnBookedLabel = QLabel() self.qtyOnBookedLabel.setText("Qty On Booked: {}".format( self.qtyOnBooked)) self.editButton = QPushButton("Edit") if self.availability: self.availabilityLabel.setText("Ready") else: self.availabilityLabel.setText("Not Available") self.vbox = QVBoxLayout() self.vbox.addWidget(self.nameLabel) self.vbox.addWidget(self.availabilityLabel) self.vbox.addWidget(self.priceLabel) self.vbox2 = QVBoxLayout() self.vbox2.addWidget(self.qtyAvailableLabel) self.vbox2.addWidget(self.qtyOnBookedLabel) self.hbox = QHBoxLayout() self.hbox.addWidget(self.imageLabel) self.hbox.addLayout(self.vbox) self.hbox.addLayout(self.vbox2) self.hbox.addWidget(self.editButton) self.setLayout(self.hbox)
def successRefund(self, balance): self.refundStatus = True self.pleaseWaitLabel.hide() self.mylogger.debug("Success Refund") self.messageLabel.setText( "Refund Berhasil. Silahkan Keluarkan Kartunya!") self.balanceLabel.setText("Saldo Akhir: {}".format( formatRupiah(balance))) self.balanceLabel.show() QCoreApplication.processEvents()
def successReadCard(self, data): self.pleaseWaitLabel.hide() self.cardPaymentStatus = True self.cardID, self.balance = data self.mylogger.debug("Success Read Card: CardID:{} Balance:{}".format( self.cardID, self.balance)) self.messageLabel.setText( "Kartu Selesai Diproses. Silahkan Keluarkan Kartunya!") self.balanceLabel.setText("Saldo Akhir: {}".format( formatRupiah(self.balance))) QCoreApplication.processEvents() self.balanceLabel.show()
def clear(self): self.orderList.clear() self.orderID = 0 self.orderTime = 0 self.totalPrice = 0 self.balance = 0 self.cardID = 0 self.attempt = 3 self.cardPaymentStatus = False self.doRefund = False self.refundStatus = False self.serverPaymentStatus = False self.totalPriceLabel.setText("Total Price: {}".format( formatRupiah(self.totalPrice))) self.balanceLabel.hide()
def failBalance(self, data): self.pleaseWaitLabel.hide() self.attempt -= 1 balance = data self.mylogger.debug( "Fail Balance: Attempt Remaining:{} Balance:{}".format( self.attempt, self.balance)) if self.attempt > 0: self.messageLabel.setText( "Saldo Tidak Cukup. Silahkan Keluarkan Kartunya!\n" "Kesempatan Tersisa: {}x".format(self.attempt)) self.balanceLabel.setText("Sisa Saldo: {}".format( formatRupiah(balance))) self.balanceLabel.show() QCoreApplication.processEvents() else: self.cancelOrder()
def __init__(self, id, image, name, price, availability, qty, sellerID): super().__init__() self.id = id self.image = image self.name = name self.price = price self.availability = availability self.qty = qty self.sellerID = sellerID self.imageLabel = QLabel() self.imageLabel.setPixmap(self.image) self.nameLabel = QLabel() self.nameLabel.setText(self.name) self.priceLabel = QLabel() self.priceLabel.setText(formatRupiah(price)) self.availabilityLabel = QLabel() self.addToCartButton = QPushButton("Tambah ke Keranjang") if self.availability: self.availabilityLabel.setText("Tersedia") else: self.availabilityLabel.setText("Tidak Tersedia") self.addToCartButton.setText("Tidak Tersedia") self.addToCartButton.setEnabled(False) self.vbox = QVBoxLayout() self.vbox.addWidget(self.nameLabel) self.vbox.addWidget(self.availabilityLabel) self.vbox.addWidget(self.priceLabel) self.hbox = QHBoxLayout() self.hbox.addWidget(self.imageLabel) self.hbox.addLayout(self.vbox) self.hbox.addWidget(self.addToCartButton) self.setLayout(self.hbox)
def handleResponseOrderDetail(self): reply = self.sender() er = reply.error() if er == QtNetwork.QNetworkReply.NoError: bytes_string = reply.readAll() data = json.loads(str(bytes_string, 'utf-8')) # print(data) for history in data: # id = history['id'] orderID = history['orderID'] orderStatus = history['orderStatus'] cardID = history['cardID'] # sellerID = history['sellerID'] menuID = history['menuID'] menuName = history['menuName'] itemStatus = history['itemStatus'] price = formatRupiah(history['price']) qty = history['qty'] tableNumber = history['tableNumber'] rawOrderTime = history['orderTime'] orderTime = datetime.datetime.strptime( rawOrderTime, "%Y-%m-%dT%H:%M:%S.%f+07:00").strftime("%d %b %Y %H:%M:%S") rawModifiedTime = history['modifiedTime'] if rawModifiedTime is not None: modifiedTime = datetime.datetime.strptime( rawModifiedTime, "%Y-%m-%dT%H:%M:%S.%f+07:00").strftime("%d %b %Y %H:%M:%S") else: modifiedTime = "null" historyItem = [orderID, orderStatus, cardID, menuID, menuName, price, qty, itemStatus, tableNumber, orderTime, modifiedTime] self.listHistory.append(historyItem) self.populateList() else: errorMessage = "Error occured: " + str(er) + "\n" + str(reply.errorString()) QMessageBox.critical(self, "Error Order Detail", errorMessage) reply.deleteLater()
def printReceipt(self): p = File("/dev/usb/lp0", auto_flush=False) # Header Receipt p.set(align='center', text_type='B') p.text("Kantin Wisuda Oktober\n") p.text("Institut Teknologi Bandung\n") p.text(self.orderTime + "\n") # p.text("Rabu,13/02/2019,15:30\n") # printTableNumber(orderList[0]['tableNumber']) p.text("Nomor Meja: " + str(self.orderList[0]['tableNumber'])) p.text("\n") p.text("Order ID: " + str(self.orderID)) p.text("\n\n\n") # Print Receipt List p.set(align='left') p.text('\x1b\x44\x00') # reset tabulation p.text('\x1b\x44\x10\x19\x00') # tabulation setting location for item in self.orderList: subTotal = item['price'] * item['qty'] p.text(str(item['menuName']) + "\n") p.text( str(item['price']) + "\x09" + "x" + str(item['qty']) + "\x09" + str(subTotal) + "\n") p.text("--------------------------------\n\n") p.text("Total Belanja " + "\t" + "\t" + str(self.totalPrice)) p.text("\n") p.set(align='center') p.text("Card ID: {}".format(self.cardID)) p.text("\n") p.text("Saldo Akhir: {}".format(formatRupiah(self.balance))) p.text("\n\n") p.set(align='center') p.text("-TERIMAKASIH-") p.cut() p.flush()
def __init__(self, id, orderID, menuID, menuName, image, price, qty, tableNumber, orderTime): super().__init__() self.id = id self.orderID = orderID self.menuID = menuID self.menuName = menuName self.image = image self.price = price self.qty = qty self.tableNumber = tableNumber self.orderTime = orderTime self.orderIDLabel = QLabel() self.orderIDLabel.setText("Order ID: " + str(self.orderID)) self.menuIDNameLabel = QLabel() self.menuIDNameLabel.setText("ID-Name: " + str(self.menuID) + "-" + self.menuName) self.imageLabel = QLabel() self.imageLabel.setPixmap(self.image) self.priceLabel = QLabel() self.priceLabel.setText("Price: " + formatRupiah(price)) self.qtyLabel = QLabel() self.qtyLabel.setText("Qty: " + str(self.qty)) self.tableNumberLabel = QLabel() self.tableNumberLabel.setText("Table: " + str(self.tableNumber)) self.orderTimeLabel = QLabel() self.orderTimeLabel.setText( "Order Time: " + self.orderTime.strftime("%d %b %Y %H:%M:%S")) self.doneButton = QPushButton("Done") self.rejectButton = QPushButton("Reject") self.vbox = QVBoxLayout() self.vbox.addWidget(self.orderIDLabel) self.vbox.addWidget(self.menuIDNameLabel) self.vbox.addWidget(self.priceLabel) self.hbox = QHBoxLayout() self.vbox2 = QVBoxLayout() self.vbox2.addWidget(self.orderTimeLabel) self.vbox2.addWidget(self.tableNumberLabel) self.vbox2.addWidget(self.qtyLabel) self.vbox3 = QVBoxLayout() self.vbox3.addWidget(self.doneButton) self.vbox3.addWidget(self.rejectButton) self.hbox.addWidget(self.imageLabel) self.hbox.addLayout(self.vbox) self.hbox.addLayout(self.vbox2) self.hbox.addLayout(self.vbox3) self.setLayout(self.hbox)
def infoInitialBalance(self, balance): self.messageLabel.setText("Saldo Awal: {}".format( formatRupiah(balance))) self.messageLabel.show() QCoreApplication.processEvents()
def calculateSubTotal(self): self.subTotalPrice = self.price * self.quantityItem.value() self.subPriceItemLabel.setText(formatRupiah(self.subTotalPrice))