From 064552cadcaf96ad9d22aaee7103e1e59826e5bf Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Sun, 8 Mar 2015 17:10:52 +0100 Subject: web: cashbox: try makeing update function foolproof and add history --- src/database/database.vala | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/database/database.vala') diff --git a/src/database/database.vala b/src/database/database.vala index 9c4e495..012842b 100644 --- a/src/database/database.vala +++ b/src/database/database.vala @@ -127,6 +127,7 @@ public class DataBase : Object { queries["user_invoice_sum"] = "SELECT SUM(CASE WHEN user < 0 THEN (SELECT price FROM purchaseprices WHERE purchaseprices.product = id) else (SELECT CASE WHEN user=0 THEN guestprice else memberprice END FROM prices WHERE product = id AND valid_from <= timestamp ORDER BY valid_from DESC LIMIT 1) END) FROM sales INNER JOIN products ON sales.product = products.id WHERE user = ? AND timestamp >= ? AND timestamp <= ? ORDER BY timestamp"; queries["cashbox_status"] = "SELECT amount FROM current_cashbox_status"; queries["cashbox_add"] = "INSERT INTO cashbox_diff ('user', 'amount', 'timestamp') VALUES (?, ?, ?)"; + queries["cashbox_history"] = "SELECT user, amount, timestamp FROM cashbox_diff ORDER BY timestamp DESC LIMIT 10"; /* compile queries into statements */ foreach(var entry in queries.entries) { @@ -928,6 +929,23 @@ public class DataBase : Object { if(rc != Sqlite.DONE) { throw new DatabaseError.INTERNAL_ERROR("internal error: %d", rc); } + } + + public CashboxDiff[] cashbox_history() { + CashboxDiff[] result = {}; + + statements["cashbox_history"].reset(); + + while(statements["cashbox_history"].step() == Sqlite.ROW) { + CashboxDiff entry = { + statements["cashbox_history"].column_int(0), + statements["cashbox_history"].column_int(1), + statements["cashbox_history"].column_int64(2), + }; + + result += entry; + }; + return result; } } -- cgit v1.2.3