diff options
| author | Sebastian Reichel <sre@ring0.de> | 2015-03-08 17:10:52 +0100 | 
|---|---|---|
| committer | Sebastian Reichel <sre@ring0.de> | 2015-03-08 17:10:52 +0100 | 
| commit | 064552cadcaf96ad9d22aaee7103e1e59826e5bf (patch) | |
| tree | b37f395f65d13cd4778377586fbc4127769f19f1 /src/database/database.vala | |
| parent | cc8960519c0a1b625c4a4073920277f39c848d4c (diff) | |
| download | serial-barcode-scanner-064552cadcaf96ad9d22aaee7103e1e59826e5bf.tar.bz2 | |
web: cashbox: try makeing update function foolproof and add history
Diffstat (limited to 'src/database/database.vala')
| -rw-r--r-- | src/database/database.vala | 18 | 
1 files changed, 18 insertions, 0 deletions
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;  	}  }  |