From b315a8359caf4422fa68f39887c4367c8e098b85 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 29 Sep 2012 00:23:26 +0200 Subject: [PATCH] brmbarv3 Receipt: New view for entering and paying receipts --- brmbar3/TODO | 2 +- brmbar3/brmbar-gui-qt4.py | 8 ++ brmbar3/brmbar-gui-qt4/MainPage.qml | 8 +- brmbar3/brmbar-gui-qt4/Receipt.qml | 192 ++++++++++++++++++++++++++++ 4 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 brmbar3/brmbar-gui-qt4/Receipt.qml diff --git a/brmbar3/TODO b/brmbar3/TODO index 1f554e9..5afc2de 100644 --- a/brmbar3/TODO +++ b/brmbar3/TODO @@ -16,7 +16,7 @@ + Support for adding new items + Alphanumeric manual entry support + Use in item editor -- Withdrawal for brmbar receipts ++ Withdrawal for brmbar receipts 1. User responsible 2. Amount and description diff --git a/brmbar3/brmbar-gui-qt4.py b/brmbar3/brmbar-gui-qt4.py index e88ba42..460a504 100755 --- a/brmbar3/brmbar-gui-qt4.py +++ b/brmbar3/brmbar-gui-qt4.py @@ -138,6 +138,14 @@ class ShopAdapter(QtCore.QObject): db.commit() return { "dbid": acct.id, "cost": (currency.str(cost) if cost != "" else "") } + @QtCore.Slot('QVariant', 'QVariant', 'QVariant', result='QVariant') + def newReceipt(self, userid, description, amount): + if (description == "" or amount == ""): + return None + user = brmbar.Account.load(db, id = userid) + shop.receipt_to_credit(user, amount, description) + return user.negbalance_str() + db = psycopg2.connect("dbname=brmbar") shop = brmbar.Shop.new_with_defaults(db) currency = shop.currency diff --git a/brmbar3/brmbar-gui-qt4/MainPage.qml b/brmbar3/brmbar-gui-qt4/MainPage.qml index 5bee9e5..4a71053 100644 --- a/brmbar3/brmbar-gui-qt4/MainPage.qml +++ b/brmbar3/brmbar-gui-qt4/MainPage.qml @@ -30,7 +30,7 @@ Item { x: 65 y: 430 width: 360 - text: "Withdrawal" + text: "Select Item" fontSize: 44 btnColor: "#666666" } @@ -50,8 +50,10 @@ Item { x: 65 y: 582 width: 360 - text: "Select Item" - btnColor: "#666666" + text: "Receipt" + onButtonClick: { + loadPage("Receipt") + } } BarButton { diff --git a/brmbar3/brmbar-gui-qt4/Receipt.qml b/brmbar3/brmbar-gui-qt4/Receipt.qml new file mode 100644 index 0000000..55f28f2 --- /dev/null +++ b/brmbar3/brmbar-gui-qt4/Receipt.qml @@ -0,0 +1,192 @@ +// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5 +import QtQuick 1.1 +import QtQuick 1.0 + +Item { + id: page + anchors.fill: parent + + property variant user + property variant description: "" + property variant amount: "" + + state: "normal" + + BarcodeInput { + color: "#00ff00" /* just for debugging */ + onAccepted: { + var acct = shop.barcodeInput(text) + text = "" + if (typeof(acct) == "undefined" || acct.acctype != "debt") { + status_text.setStatus("Unknown barcode", "#ff4444") + return + } + user = acct + } + } + + Item { + id: description_row + visible: page.state == "normal" || page.state == "description_edit" + x: 65 + y: 166 + width: 890 + height: 60 + + Text { + id: description_input + x: 0 + y: 0 + width: 640 + height: 60 + color: "#ffff7c" + text: page.description + wrapMode: Text.WordWrap + verticalAlignment: Text.AlignVCenter + font.pointSize: 34 + } + + BarButton { + id: description_edit + x: 591 + y: 0 + width: 300 + height: 60 + fontSize: 34 + text: page.state == "description_edit" ? "Assign" : "Description" + onButtonClick: { if (page.state == "description_edit") page.state = "normal"; else page.state = "description_edit"; } + } + } + + BarKeyPad { + id: item_name_pad + x: 65 + y: 239 + visible: page.state == "description_edit" + onLetterEntered: { page.description = page.description + letter; } + onLetterBackspace: { page.description = page.description.replace(/.$/, ''); } + } + + Item { + id: amount_row + visible: page.state == "normal" || page.state == "amount_edit" + x: 65 + y: page.state == "amount_edit" ? 166 : 239; + width: 890 + height: 60 + + Text { + id: item_sellprice_label + x: 0 + y: 0 + height: 60 + width: 200 + color: "#ffffff" + text: "Money Amount:" + verticalAlignment: Text.AlignVCenter + font.pointSize: 34 + } + + Text { + id: amount_input + x: 320 + y: 0 + height: 60 + width: 269 + color: "#ffff7c" + text: amount + horizontalAlignment: Text.AlignRight + verticalAlignment: Text.AlignVCenter + font.pointSize: 34 + } + + BarButton { + id: amount_edit + x: 650 + y: 0 + width: 240 + height: 60 + fontSize: 34 + text: page.state == "amount_edit" ? "Assign" : "Edit" + onButtonClick: { if (page.state == "amount_edit") page.state = "normal"; else page.state = "amount_edit"; } + } + } + + BarNumPad { + id: amount_pad + x: 65 + y: 239 + visible: page.state == "amount_edit" + onLetterEntered: { amount = amount.toString() + letter } + onLetterBackspace: { amount = amount.toString().replace(/.$/, '') } + } + + BarTextHint { + id: barcode_row + visible: page.state == "normal" + x: 65 + y: 314 + hint_goal: "Receipt owner:" + hint_action: typeof(user) != "undefined" ? user.name : "Scan user now" + } + + Text { + id: legend + visible: page.state == "normal" + x: 65 + y: 410 + height: 154 + width: 894 + color: "#71cccc" + text: "This is for cashing in small brmlab expenses.\nWrite the current date on the receipt and put it to the money box.\nDo not forget to announce this on a meetup and add it to the [[newz]].\nFor restocking brmbar items, please go to the Management view instead." + wrapMode: Text.WordWrap + horizontalAlignment: Text.AlignHCenter + font.pointSize: 20 + } + + BarButton { + id: save + x: 65 + y: 582 + width: 360 + text: "Create" + onButtonClick: { + if (typeof(user) == "undefined") { + status_text.setStatus("Someone must be responsible for each receipt.", "#ff4444") + return + } + var balance = shop.newReceipt(user.id, description, amount) + if (typeof(balance) == "undefined") { + status_text.setStatus("Please fill all values first.", "#ff4444") + return + } + + status_text.setStatus("Added to "+user.name+"'s credit, now "+balance+".", "#ffff7c") + loadPage("MainPage") + } + } + + BarButton { + id: cancel + x: 599 + y: 582 + width: 360 + text: "Cancel" + onButtonClick: { + status_text.setStatus("Receipt cancelled", "#ff4444") + loadPage("MainPage") + } + } + + states: [ + State { + name: "normal" + }, + State { + name: "amount_edit" + }, + State { + name: "description_edit" + } + ] +}