summaryrefslogtreecommitdiffstats
path: root/src/web/web.vala
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2013-06-15 23:12:26 +0200
committerSebastian Reichel <sre@ring0.de>2013-06-15 23:12:26 +0200
commite11d76395ce0ba821f58bfb1956a56f6ffc8494b (patch)
treec01a24058b017c9f2b36d934e02f3cea5c408fde /src/web/web.vala
parent8504754a40d47b69b0aa1e786f0b1db45405a3fd (diff)
downloadserial-barcode-scanner-e11d76395ce0ba821f58bfb1956a56f6ffc8494b.tar.bz2
web: add cashbox tracking
Diffstat (limited to 'src/web/web.vala')
-rw-r--r--src/web/web.vala78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/web/web.vala b/src/web/web.vala
index 0bfa08d..28c5d87 100644
--- a/src/web/web.vala
+++ b/src/web/web.vala
@@ -909,6 +909,80 @@ public class WebServer {
}
}
+ void handler_cashbox(Soup.Server server, Soup.Message msg, string path, GLib.HashTable? query, Soup.ClientContext client) {
+ try {
+ var session = new WebSession(server, msg, path, query, client);
+
+ if(!session.superuser) {
+ handler_403(server, msg, path, query, client);
+ return;
+ }
+
+ var template = new WebTemplate("cashbox/index.html", session);
+ template.replace("TITLE", "KtT Shop System: Cashbox");
+ template.replace("CASHBOX_STATUS", db.cashbox_status().to_string());
+ template.menu_set_active("cashbox");
+ msg.set_response("text/html", Soup.MemoryUse.COPY, template.data);
+ } catch(TemplateError e) {
+ stderr.printf(e.message+"\n");
+ handler_404(server, msg, path, query, client);
+ } catch(DatabaseError e) {
+ stderr.printf(e.message+"\n");
+ handler_400(server, msg, path, query, client);
+ } catch(IOError e) {
+ stderr.printf(e.message+"\n");
+ handler_400(server, msg, path, query, client);
+ }
+ }
+
+ void handler_cashbox_add(Soup.Server server, Soup.Message msg, string path, GLib.HashTable<string,string>? query, Soup.ClientContext client) {
+ try {
+ var session = new WebSession(server, msg, path, query, client);
+
+ if(!session.superuser) {
+ handler_403(server, msg, path, query, client);
+ return;
+ }
+
+ var template = new WebTemplate("cashbox/add.html", session);
+ template.replace("TITLE", "KtT Shop System: Cashbox Balance");
+ template.menu_set_active("cashbox");
+
+ bool error = false;
+ if(query == null || !query.contains("type") || !query.contains("amount"))
+ error = true;
+
+ int64 timestamp = (new DateTime.now_utc()).to_unix();
+ Price amount = Price.parse(query["amount"]);
+ string type = query["type"];
+
+ if(type != "user" && type != "loss")
+ error = true;
+
+ if(!error)
+ db.cashbox_add(type == "user" ? session.user : -3, amount, timestamp);
+
+ if(error) {
+ template.replace("NEW.OK", "none");
+ template.replace("NEW.FAIL", "block");
+ } else {
+ template.replace("NEW.OK", "block");
+ template.replace("NEW.FAIL", "none");
+ }
+
+ msg.set_response("text/html", Soup.MemoryUse.COPY, template.data);
+ } catch(TemplateError e) {
+ stderr.printf(e.message+"\n");
+ handler_404(server, msg, path, query, client);
+ } catch(DatabaseError e) {
+ stderr.printf(e.message+"\n");
+ handler_400(server, msg, path, query, client);
+ } catch(IOError e) {
+ stderr.printf(e.message+"\n");
+ handler_400(server, msg, path, query, client);
+ }
+ }
+
public WebServer(int port = 8080) {
srv = new Soup.Server(Soup.SERVER_PORT, port);
@@ -923,6 +997,10 @@ public class WebServer {
srv.add_handler("/css", handler_css);
srv.add_handler("/img", handler_img);
+ /* cashbox */
+ srv.add_handler("/cashbox", handler_cashbox);
+ srv.add_handler("/cashbox/add", handler_cashbox_add);
+
/* products */
srv.add_handler("/products", handler_products);
srv.add_handler("/products/new", handler_products_new);