summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--data/templates/menu.html2
-rw-r--r--data/templates/suppliers/index.html39
-rw-r--r--src/web/web.vala56
3 files changed, 94 insertions, 3 deletions
diff --git a/data/templates/menu.html b/data/templates/menu.html
index a1a0930..713351d 100644
--- a/data/templates/menu.html
+++ b/data/templates/menu.html
@@ -19,6 +19,8 @@
</ul>
</li>
+ <li class="{{{MENU.suppliers}}}"><a href="/suppliers">Suppliers</a></li>
+
<li class="{{{MENU.aliases}}}"><a href="/aliases">Aliases</a></li>
<li class="{{{MENU.cashbox}}} {{{AUTH_CASHBOX}}}"><a href="/cashbox">Cashbox</a></li>
<!--
diff --git a/data/templates/suppliers/index.html b/data/templates/suppliers/index.html
new file mode 100644
index 0000000..1472720
--- /dev/null
+++ b/data/templates/suppliers/index.html
@@ -0,0 +1,39 @@
+{{{MESSAGE}}}
+
+<table id="suppliertable" class="table table-bordered table-striped table-condensed">
+ <thead>
+ <tr>
+ <th>ID</th>
+ <th>Name</th>
+ <th>City</th>
+ <th>Postal Code</th>
+ <th>Street</th>
+ <th>Phone</th>
+ <th>Website</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{{DATA}}}
+ </tbody>
+</table>
+
+<div id="newsupplier" style="display: {{{NEWSUPPLIER}}};">
+ <legend>New Supplier</legend>
+ <form method="POST" enctype="multipart/form-data" action="#" class="form-inline">
+ <div class="form-group">
+ <input class="form-control" name="name" type="text" placeholder="Name" />
+ <input class="form-control" name="postal_code" type="number" min="0" placeholder="Postal Code" />
+ <input class="form-control" name="city" type="text" placeholder="City" />
+ <input class="form-control" name="street" type="text" placeholder="Street" />
+ <input class="form-control" name="phone" type="text" placeholder="Phone" />
+ <input class="form-control" name="website" type="text" placeholder="Website" />
+ <button type="submit" class="form-control btn btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
+ </div>
+ </form>
+</div>
+
+<script type="text/javascript">
+$(document).ready(function() {
+ $('#suppliertable').DataTable({"lengthMenu": [ [25, 50, 100, -1], [25, 50, 100, "All"] ] });
+} );
+</script>
diff --git a/src/web/web.vala b/src/web/web.vala
index 94c2ca1..5dcceef 100644
--- a/src/web/web.vala
+++ b/src/web/web.vala
@@ -549,6 +549,52 @@ public class WebServer {
}
}
+ void handler_suppliers(Soup.Server server, Soup.Message msg, string path, GLib.HashTable? query, Soup.ClientContext client) {
+ try {
+ var session = new WebSession(server, msg, path, query, client);
+ var message = "";
+
+ var t = new WebTemplate("suppliers/index.html", session);
+ t.replace("TITLE", shortname + " Shop System: Suppliers");
+ t.menu_set_active("suppliers");
+
+ if(session.superuser || session.auth_products) {
+ t.replace("NEWSUPPLIER", "block");
+
+ var postdata = Soup.Form.decode_multipart(msg, null, null, null, null);
+ if(postdata != null) {
+ message = "<div class=\"alert alert-success\">New supplier has been added!</div>";
+ try {
+ db.add_supplier(postdata["name"], postdata["postal_code"], postdata["city"], postdata["street"], postdata["phone"], postdata["website"]);
+ } catch(DatabaseError e) {
+ message = @"<div class=\"alert alert-error\">Error: $(e.message)</div>";
+ }
+ }
+ } else {
+ t.replace("NEWSUPPLIER", "none");
+ }
+
+ string table = "";
+ foreach(var s in db.get_supplier_list()) {
+ table += @"<tr><td>$(s.id)</td><td>$(s.name)</td><td>$(s.postal_code)</td><td>$(s.city)</td><td>$(s.street)</td><td>$(s.phone)</td><td><a href=\"$(s.website)\">$(s.website)</a></td></tr>";
+ }
+ t.replace("DATA", table);
+ t.replace("MESSAGE", message);
+
+ msg.set_response("text/html", Soup.MemoryUse.COPY, t.data);
+ msg.set_status(200);
+ } catch(TemplateError e) {
+ stderr.printf(e.message+"\n");
+ handler_404(server, msg, path, query, client);
+ } catch(DatabaseError e) {
+ handler_400(server, msg, path, query, client, e.message);
+ } catch(IOError e) {
+ handler_400(server, msg, path, query, client, e.message);
+ } catch(DBusError e) {
+ handler_400(server, msg, path, query, client, e.message);
+ }
+ }
+
void handler_products(Soup.Server server, Soup.Message msg, string path, GLib.HashTable? query, Soup.ClientContext client) {
string[] pathparts = path.split("/");
@@ -796,7 +842,7 @@ public class WebServer {
string successClassTemplate = "hidden";
if (msg.method == "POST") {
var postdata = Soup.Form.decode((string) msg.request_body.data);
-
+
if (!postdata.contains("apply_inventory")) {
// PUT / show changes and request an apply
foreach(var e in db.get_stock()) {
@@ -827,7 +873,7 @@ public class WebServer {
var user = db.get_user_info(uId);
usersTemplate += "<option value=\"%d\">%s %s (%d)</option>".printf(uId, user.firstname, user.lastname, uId);
}
-
+
restockClassTemplate = ""; // this shows the option list
} else {
// PUT / apply changes
@@ -841,7 +887,7 @@ public class WebServer {
var realAmount = int.parse(realAmountStr);
if (realAmount < e.amount) {
// Loss transaction
-
+
for (int i=0; i< e.amount - realAmount; i++) {
db.buy(userId, pId);
}
@@ -1638,6 +1684,10 @@ public class WebServer {
srv.add_handler("/products/inventory", handler_products_inventory);
srv.add_handler("/products/inventory-pdf", handler_stock_as_pdf);
+ /* suppliers */
+ srv.add_handler("/suppliers", handler_suppliers);
+
+ /* aliases */
srv.add_handler("/aliases", handler_alias_list);
srv.add_handler("/aliases/new", handler_alias_new);