diff options
author | Johannes Rudolph <johannes.rudolph@gmx.com> | 2018-01-05 16:56:42 +0100 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2018-06-28 01:52:53 +0200 |
commit | b46dffb399fa7752c82b8186df3e6d5f22a5315e (patch) | |
tree | 7deb06f7eaf73d9766641737296b3a0e81b34b29 /src | |
parent | b665d1cbb089615672fc661d539afcf1eb594f55 (diff) | |
download | serial-barcode-scanner-b46dffb399fa7752c82b8186df3e6d5f22a5315e.tar.bz2 |
database: add method to retrieve product details with prices
Diffstat (limited to 'src')
-rw-r--r-- | src/database/database.vala | 25 | ||||
-rw-r--r-- | src/database/db-interface.vala | 7 | ||||
-rw-r--r-- | src/pdf-stock/pdf-stock.vala | 8 | ||||
-rw-r--r-- | src/web/web.vala | 2 |
4 files changed, 29 insertions, 13 deletions
diff --git a/src/database/database.vala b/src/database/database.vala index fb7bde6..dc636b8 100644 --- a/src/database/database.vala +++ b/src/database/database.vala @@ -273,13 +273,13 @@ public class DataBase : Object { } #endif - public StockEntry[] get_stock() { - StockEntry[] result = {}; + public DetailedProduct[] get_stock() { + DetailedProduct[] result = {}; statements["stock_status"].reset(); while(statements["stock_status"].step() == Sqlite.ROW) { - StockEntry entry = { - statements["stock_status"].column_text(0), + DetailedProduct entry = { + statements["stock_status"].column_int(0), statements["stock_status"].column_text(1), statements["stock_status"].column_text(2), statements["stock_status"].column_int(3), @@ -293,6 +293,21 @@ public class DataBase : Object { return result; } + public DetailedProduct get_product_for_ean(uint64 ean) throws DatabaseError { + var p = new DetailedProduct(); + try { + p.ean = ean_alias_get(ean); + p.name = get_product_name(ean); + p.category = get_product_category(ean); + p.amount = get_product_amount(ean); + p.memberprice = get_product_price(1, ean); + p.guestprice = get_product_price(0, ean); + return p; + } catch(DatabaseError e){ + throw e; + } + } + public PriceEntry[] get_prices(uint64 product) { PriceEntry[] result = {}; @@ -1125,7 +1140,7 @@ public class DataBase : Object { foreach(var product in get_stock()) { var amount = product.amount; - var pid = uint64.parse(product.id); + var pid = product.ean; if(amount <= 0) continue; diff --git a/src/database/db-interface.vala b/src/database/db-interface.vala index bd94ce1..de5bbc4 100644 --- a/src/database/db-interface.vala +++ b/src/database/db-interface.vala @@ -15,7 +15,8 @@ [DBus (name = "io.mainframe.shopsystem.Database")] public interface Database : Object { - public abstract StockEntry[] get_stock() throws IOError; + public abstract DetailedProduct[] get_stock() throws IOError; + public abstract DetailedProduct get_product_for_ean(uint64 ean) throws IOError, DatabaseError; public abstract PriceEntry[] get_prices(uint64 product) throws IOError; public abstract RestockEntry[] get_restocks(uint64 product, bool descending) throws IOError; public abstract bool buy(int32 user, uint64 article) throws IOError, DatabaseError; @@ -71,8 +72,8 @@ public struct Category { public string name; } -public struct StockEntry { - public string id; +public struct DetailedProduct { + public uint64 ean; public string name; public string category; public int amount; diff --git a/src/pdf-stock/pdf-stock.vala b/src/pdf-stock/pdf-stock.vala index e971f78..1d16e4a 100644 --- a/src/pdf-stock/pdf-stock.vala +++ b/src/pdf-stock/pdf-stock.vala @@ -40,7 +40,7 @@ public class StockPDF { EAN ean; Cairo.Context ctx; Pango.Layout layout; - StockEntry[] stock; + DetailedProduct[] stock; /* pdf data */ private uint8[] data; @@ -99,7 +99,7 @@ public class StockPDF { ctx.restore(); } - private void render_table_row(StockEntry product) throws BarcodeError { + private void render_table_row(DetailedProduct product) throws BarcodeError { ctx.set_line_width(0.8); /* borders */ @@ -117,7 +117,7 @@ public class StockPDF { /* EAN */ ctx.move_to(col1 + padding, y + padding); - ean.draw(product.id); + ean.draw(@"$(product.ean)"); /* Product Name */ ctx.move_to(col2 + padding, y); @@ -125,7 +125,7 @@ public class StockPDF { layout.set_wrap(Pango.WrapMode.WORD_CHAR); layout.set_spacing((int) (-padding * Pango.SCALE)); layout.set_width((int) (col3-col2) * Pango.SCALE); - var text = @"$(product.id)\n$(product.name)"; + var text = @"$(product.ean)\n$(product.name)"; layout.set_text(text, text.length); Pango.cairo_update_layout(ctx, layout); Pango.cairo_show_layout(ctx, layout); diff --git a/src/web/web.vala b/src/web/web.vala index 62cfb04..37e6edc 100644 --- a/src/web/web.vala +++ b/src/web/web.vala @@ -568,7 +568,7 @@ public class WebServer { string table = ""; foreach(var e in db.get_stock()) { - table += @"<tr><td><a href=\"/products/$(e.id)\">$(e.id)</a></td><td><a href=\"/products/$(e.id)\">$(e.name)</a></td><td>$(e.category)</td><td>$(e.amount)</td><td>$(e.memberprice)€</td><td>$(e.guestprice)€</td></tr>"; + table += @"<tr><td><a href=\"/products/$(e.ean)\">$(e.ean)</a></td><td><a href=\"/products/$(e.ean)\">$(e.name)</a></td><td>$(e.category)</td><td>$(e.amount)</td><td>$(e.memberprice)€</td><td>$(e.guestprice)€</td></tr>"; } t.replace("DATA", table); |