summaryrefslogtreecommitdiffstats
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
parent8504754a40d47b69b0aa1e786f0b1db45405a3fd (diff)
downloadserial-barcode-scanner-e11d76395ce0ba821f58bfb1956a56f6ffc8494b.tar.bz2
web: add cashbox tracking
-rw-r--r--src/web/web.vala78
-rw-r--r--templates/cashbox/add.html17
-rw-r--r--templates/cashbox/index.html11
-rw-r--r--templates/menu.html3
4 files changed, 109 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);
diff --git a/templates/cashbox/add.html b/templates/cashbox/add.html
new file mode 100644
index 0000000..6e26f00
--- /dev/null
+++ b/templates/cashbox/add.html
@@ -0,0 +1,17 @@
+<div id="add-successful" class="alert alert-success" style="display: {{{NEW.OK}}};">
+ <p>Successfully balanced cashbox:</p>
+
+ <table class="table">
+ <tr><th>Type</th><td>{{{TYPE}}}</td></tr>
+ <tr><th>Amount</th><td>{{{AMOUNT}}}</td></tr>
+ </table>
+</div>
+
+<div id="add-failed" class="alert alert-error" style="display: {{{NEW.FAIL}}};">
+ <h4>Error</h4>
+ Creating new cashbox balance entry failed. Please make
+ sure you have sufficient permissions and gave valid
+ values for type and amount.
+</div>
+
+<a href="/cashbox">Back to cashbox overview</a>
diff --git a/templates/cashbox/index.html b/templates/cashbox/index.html
new file mode 100644
index 0000000..1466272
--- /dev/null
+++ b/templates/cashbox/index.html
@@ -0,0 +1,11 @@
+Current Cashbox Status: <input name"status" type="number" readonly="readonly" value="{{{CASHBOX_STATUS}}}"/>
+
+<form action="/cashbox/add" class="form-horizontal">
+ <legend>Cashbox Balance/Withdrawal/Deposit</legend>
+ <select name="type" size="1">
+ <option value="loss">Balance (Loss)</option>
+ <option value="user">Withdrawal / Deposit</option>
+ </select>
+ <input class="input-medium" name="amount" type="number" placeholder="Amount" />
+ <button type="submit" class="btn btn-primary"><i class="icon-plus"></i></button>
+</form>
diff --git a/templates/menu.html b/templates/menu.html
index 747853d..138cc23 100644
--- a/templates/menu.html
+++ b/templates/menu.html
@@ -4,6 +4,8 @@
<ul class="nav">
<li class="{{{MENU.home}}}"><a href="/">Home</a></li>
<li class="{{{MENU.products}}}"><a href="/products">Products</a></li>
+ <li class="{{{MENU.cashbox}}} {{{SUPERUSER}}}"><a href="/cashbox">Cashbox</a></li>
+<!--
<li class="{{{MENU.stats}}} dropdown">
<a href="#" id="statsmenu" class="dropdown-toggle" data-toggle="dropdown">Statistics <b class="caret"></b></a>
<ul class="dropdown-menu">
@@ -14,6 +16,7 @@
<li><a href="/stats/profit_per_product">Graph: Profit / Product</a></li>
</ul>
</li>
+-->
<li class="{{{MENU.users}}} {{{SUPERUSER}}} dropdown">
<a href="#" id="usersmenu" class="dropdown-toggle" data-toggle="dropdown">Users <b class="caret"></b></a>
<ul class="dropdown-menu">