From a9e72d736cef4770bd12a924bca5aa9d254074fd Mon Sep 17 00:00:00 2001 From: brmbar Date: Sun, 10 Jan 2016 21:03:59 +0100 Subject: [PATCH] brmbar-cli userlog --- brmbar3/SQL | 5 ++--- brmbar3/brmbar-cli.py | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/brmbar3/SQL b/brmbar3/SQL index 7e640a6..b25908f 100644 --- a/brmbar3/SQL +++ b/brmbar3/SQL @@ -107,8 +107,7 @@ CREATE VIEW transaction_nicesplits AS FROM transaction_splits AS ts LEFT JOIN accounts AS a ON a.id = ts.account ORDER BY ts.id; --- List transactions with summary information regarding their cash element --- (except in case of transfers between cash and debt accounts, which will cancel out). +-- List transactions with summary information regarding their cash element. CREATE VIEW transaction_cashsums AS SELECT t.id AS id, t.time AS time, SUM(credit_cash) AS cash_credit, SUM(debit_cash) AS cash_debit, t.description AS description FROM transactions AS t @@ -124,4 +123,4 @@ CREATE VIEW transaction_cashsums AS WHERE a.currency = (SELECT currency FROM accounts WHERE name = 'BrmBar Cash') AND a.acctype IN ('cash', 'debt') AND dts.amount > 0) debit ON dts_t = t.id - GROUP BY t.id ORDER BY t.id; + GROUP BY t.id ORDER BY t.id DESC; diff --git a/brmbar3/brmbar-cli.py b/brmbar3/brmbar-cli.py index e967f0a..4ad26ab 100755 --- a/brmbar3/brmbar-cli.py +++ b/brmbar3/brmbar-cli.py @@ -19,6 +19,7 @@ Usage: brmbar-cli.py COMMAND ARGS... You can use negative AMT to undo a sale. restock ITEM AMT userinfo USER + userlog USER TIMESTAMP iteminfo ITEM 2. Management commands @@ -142,6 +143,14 @@ elif sys.argv[1] == "userinfo": res = db.execute_and_fetchall("SELECT barcode FROM barcodes WHERE account = %s", [acct.id]) print("Barcodes: " + ", ".join(map((lambda r: r[0]), res))) +elif sys.argv[1] == "userlog": + acct = load_user(sys.argv[2]) + timestamp = sys.argv[3] + + res = db.execute_and_fetchall("SELECT transactions.time,transactions.description FROM transactions INNER JOIN accounts ON accounts.id=transactions.responsible WHERE accounts.name=%s and time > TIMESTAMP %s ORDER BY time", [acct.name,timestamp]) + for transaction in res: + print("{}\t{}\t".format(transaction[0],transaction[1])) + elif sys.argv[1] == "iteminfo": acct = load_item(sys.argv[2]) print("{} (id {}): {} pcs".format(acct.name, acct.id, acct.balance()))