diff options
author | Johannes Rudolph <johannes.rudolph@gmx.com> | 2018-01-02 13:58:11 +0100 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2018-06-28 01:52:53 +0200 |
commit | 207e77c7cbab87f3bf537dd11ca391f12df01129 (patch) | |
tree | c8ad4ae435dca1b2e77d0ddfab72c5a57dd3290b /src | |
parent | f07b648ce9b6f06200bdd0090d1fdac15fd3351d (diff) | |
download | serial-barcode-scanner-207e77c7cbab87f3bf537dd11ca391f12df01129.tar.bz2 |
all: replace hard-coded KtT branding with dynamic text
* extend config file with general details
* extend curves-ui makefile add config
* Use name from config
* replace static text with dynamic text
* read short name and long name from config
* replace SHORTNAME tags with the shortname
* replace mail related branding information
* add missing Replacement
* make VAT (Umsatzsteuer) optional
* make space name dynamic
* make short name in treasuremail text dynamic
* make pdf text more dynamic
Diffstat (limited to 'src')
-rw-r--r-- | src/curses-ui/Makefile | 2 | ||||
-rw-r--r-- | src/curses-ui/main.vala | 9 | ||||
-rw-r--r-- | src/invoice/invoice.vala | 41 | ||||
-rw-r--r-- | src/pdf-invoice/pdf-invoice.vala | 37 | ||||
-rw-r--r-- | src/web/web.vala | 87 |
5 files changed, 134 insertions, 42 deletions
diff --git a/src/curses-ui/Makefile b/src/curses-ui/Makefile index 1ca68cf..bfdea51 100644 --- a/src/curses-ui/Makefile +++ b/src/curses-ui/Makefile @@ -1,7 +1,7 @@ all: curses-ui @echo > /dev/null -curses-ui: *.vala ../audio/audio-interface.vala ../scanner-session/scannersession-interface.vala +curses-ui: *.vala ../audio/audio-interface.vala ../scanner-session/scannersession-interface.vala ../config/config-interface.vala valac -X -w -o $@ --pkg curses -X -lncursesw --pkg posix --pkg gio-2.0 $^ clean: diff --git a/src/curses-ui/main.vala b/src/curses-ui/main.vala index 7020586..47be40a 100644 --- a/src/curses-ui/main.vala +++ b/src/curses-ui/main.vala @@ -62,6 +62,15 @@ public static int main(string[] args) { scanner.msg.connect(msg_handler); scanner.msg_overlay.connect(msg_overlay_handler); + /* get configuration */ + Config config = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); + var shopname = "--SHOPNAME--"; + try { + shopname = config.get_string("GENERAL", "longname"); + } catch(KeyFileError e) { + shopname = "Missing in Config"; + } + ui.log(MessageType.INFO, "KtT Shop System has been started"); play("startup.ogg"); diff --git a/src/invoice/invoice.vala b/src/invoice/invoice.vala index 1e6dd58..68710ca 100644 --- a/src/invoice/invoice.vala +++ b/src/invoice/invoice.vala @@ -32,6 +32,11 @@ public class InvoiceImplementation { Database db; PDFInvoice pdf; string datadir; + string mailfromaddress; + string treasurermailaddress; + string shortname; + string spacename; + string vat; public InvoiceImplementation() throws IOError, KeyFileError { mailer = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Mail", "/io/mainframe/shopsystem/mailer"); @@ -39,6 +44,11 @@ public class InvoiceImplementation { pdf = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.InvoicePDF", "/io/mainframe/shopsystem/invoicepdf"); Config cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); datadir = cfg.get_string("INVOICE", "datadir"); + mailfromaddress = cfg.get_string("MAIL", "mailfromaddress"); + treasurermailaddress = cfg.get_string("MAIL", "treasurermailaddress"); + shortname = cfg.get_string("GENERAL", "shortname"); + spacename = cfg.get_string("GENERAL", "spacename"); + vat = cfg.get_string("INVOICE", "vat"); } public void send_invoice(bool temporary, int64 timestamp, int user) throws IOError, InvoicePDFError, DatabaseError { @@ -67,9 +77,9 @@ public class InvoiceImplementation { string treasurer_path = mailer.create_mail(); Mail treasurer_mail = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Mail", treasurer_path); - treasurer_mail.from = {"KtT Shopsystem", "shop@kreativitaet-trifft-technik.de"}; + treasurer_mail.from = {shortname + " Shopsystem", mailfromaddress}; treasurer_mail.subject = mailtitle; - treasurer_mail.add_recipient({"Schatzmeister", "shop-einzug@kreativitaet-trifft-technik.de"}, RecipientType.TO); + treasurer_mail.add_recipient({"Schatzmeister", treasurermailaddress}, RecipientType.TO); var csvinvoicedata = ""; foreach(var userid in users) { @@ -82,7 +92,7 @@ public class InvoiceImplementation { var invoicedata = generate_invoice(temporary, timestamp, userid, invoiceid); string mail_path = mailer.create_mail(); Mail mail = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Mail", mail_path); - mail.from = {"KtT Shopsystem", "shop@kreativitaet-trifft-technik.de"}; + mail.from = {shortname + " Shopsystem", mailfromaddress}; mail.subject = mailtitle; mail.add_recipient({@"$(userdata.firstname) $(userdata.lastname)", userdata.email}, RecipientType.TO); @@ -135,9 +145,9 @@ public class InvoiceImplementation { string treasurer_path = mailer.create_mail(); Mail treasurer_mail = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Mail", treasurer_path); - treasurer_mail.from = {"KtT Shopsystem", "shop@kreativitaet-trifft-technik.de"}; + treasurer_mail.from = {shortname + " Shopsystem", mailfromaddress}; treasurer_mail.subject = mailtitle; - treasurer_mail.add_recipient({"Schatzmeister", "shop-einzug@kreativitaet-trifft-technik.de"}, RecipientType.TO); + treasurer_mail.add_recipient({"Schatzmeister", treasurermailaddress}, RecipientType.TO); var csvinvoicedata = ""; foreach(var userid in users) { @@ -149,7 +159,7 @@ public class InvoiceImplementation { string mail_path = mailer.create_mail(); Mail mail = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Mail", mail_path); - mail.from = {"KtT Shopsystem", "shop@kreativitaet-trifft-technik.de"}; + mail.from = {shortname + " Shopsystem", mailfromaddress}; mail.subject = mailtitle; mail.add_recipient({@"$(userdata.firstname) $(userdata.lastname)", userdata.email}, RecipientType.TO); @@ -227,6 +237,8 @@ public class InvoiceImplementation { throw new IOError.FAILED("Could not open invoice template: %s", e.message); } + text = text.replace("{{{SHORTNAME}}}", shortname); + return text; } @@ -294,9 +306,26 @@ public class InvoiceImplementation { text = text.replace("{{{ADDRESS}}}", address); text = text.replace("{{{LASTNAME}}}", name); + text = text.replace("{{{SPACENAME}}}", spacename); text = text.replace("{{{INVOICE_TABLE}}}", table); text = text.replace("{{{SUM_MONTH}}}", "%d,%02d".printf(total_sum / 100, total_sum % 100)); + if(vat == "yes") { + text = text.replace("{{{VAT}}}", ""); + } else { + string vattext; + string vattextfilename; + vattextfilename = (type == MessageType.HTML) ? "vat.html" : "vat.txt"; + + try { + FileUtils.get_contents(datadir + "/" + vattextfilename, out vattext); + } catch(GLib.FileError e) { + throw new IOError.FAILED("Could not open VAT template: %s", e.message); + } + + text = text.replace("{{{VAT}}}", vattext); + } + return text; } diff --git a/src/pdf-invoice/pdf-invoice.vala b/src/pdf-invoice/pdf-invoice.vala index c50fe6c..6fd4383 100644 --- a/src/pdf-invoice/pdf-invoice.vala +++ b/src/pdf-invoice/pdf-invoice.vala @@ -15,6 +15,8 @@ [DBus (name = "io.mainframe.shopsystem.InvoicePDF")] public class InvoicePDF { + Config cfg; + /* A4 sizes (in points, 72 DPI) */ private const double width = 595.27559; /* 210mm */ private const double height = 841.88976; /* 297mm */ @@ -60,8 +62,14 @@ public class InvoicePDF { "Dezember" }; + string longname; + string vat; + public InvoicePDF(string datadir) { this.datadir = datadir; + cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); + longname = cfg.get_string("GENERAL", "longname"); + vat = cfg.get_string("INVOICE", "vat"); } private void render_svg(Cairo.Context ctx, string file) { @@ -104,8 +112,7 @@ public class InvoicePDF { ctx.set_font_size(8.45); ctx.move_to(56.5, 142); - /* TODO: get string from config file */ - ctx.show_text("Kreativität trifft Technik e.V., Bahnhofsplatz 10, 26122 Oldenburg"); + ctx.show_text(cfg.get_string("INVOICE", "addressrow")); /* actually LMRoman12 */ ctx.select_font_face("LMSans10", Cairo.FontSlant.NORMAL, Cairo.FontWeight.NORMAL); @@ -194,7 +201,6 @@ public class InvoicePDF { ctx.move_to(56.5, 323); - /* TODO: get text from config file */ ctx.show_text(@"Rechnung Nr. $invoice_id"); ctx.restore(); @@ -224,8 +230,7 @@ public class InvoicePDF { /* set page width */ layout.set_width((int) 140 * Pango.SCALE); - /* TODO: get text from config file */ - var text = "<b>Kreativität trifft Technik e.V.</b>\nAmtsgericht Oldenburg VR 201044\n\nHackspace „Mainframe“\nFabLab „Fab-O-Lab“\nSchnittstelle „Schnittstelle“\n\nBahnhofsplatz 10 • 26122 Oldenburg"; + var text = cfg.get_string("INVOICE", "footer1"); /* write invoice date */ layout.set_markup(text, text.length); @@ -261,8 +266,7 @@ public class InvoicePDF { /* set page width */ layout.set_width((int) 190 * Pango.SCALE); - /* TODO: get text from config file */ - var text = "<b>Mail:</b> vorstand@kreativitaet-trifft-technik.de\n<b>Web:</b> www.kreativitaet-trifft-technik.de\n\n\n\n<b>BGB-Vorstand:</b>\nPatrick Günther, Michael Pensler, Jan Janssen"; + var text = cfg.get_string("INVOICE", "footer2"); /* write invoice date */ layout.set_markup(text, text.length); @@ -298,8 +302,7 @@ public class InvoicePDF { /* set page width */ layout.set_width((int) 150 * Pango.SCALE); - /* TODO: get text from config file */ - var text = "<b>Raiffeisenbank Oldenburg</b>\nIBAN: DE34 2806 0228 0037 0185 00\nBIC: GENODEF1OL2\n\n\n<b>Finanzamt Oldenburg</b>\nAls gemeinnützig anerkannt.\nSteuer Nr.: 64/220/18413"; + var text = cfg.get_string("INVOICE", "footer3"); /* write invoice date */ layout.set_markup(text, text.length); @@ -362,6 +365,22 @@ public class InvoicePDF { text = text.replace("{{{ADDRESS}}}", address); text = text.replace("{{{LASTNAME}}}", invoice_recipient.lastname); text = text.replace("{{{SUM}}}", @"$sum"); + text = text.replace("{{{ORGANIZATION}}}", longname); + + if(vat == "yes") { + text = text.replace("{{{VAT}}}", ""); + } else { + string vattext; + + try { + FileUtils.get_contents(datadir + "/" + "vat.txt", out vattext); + } catch(GLib.FileError e) { + throw new IOError.FAILED("Could not open VAT template: %s", e.message); + } + + text = text.replace("{{{VAT}}}", vattext); + } + layout.set_markup(text, text.length); } catch(GLib.FileError e) { error("File Error: %s\n", e.message); diff --git a/src/web/web.vala b/src/web/web.vala index ea0c667..62cfb04 100644 --- a/src/web/web.vala +++ b/src/web/web.vala @@ -15,12 +15,15 @@ public class WebServer { private Soup.Server srv; + private string longname; + private string shortname; void handler_default(Soup.Server server, Soup.Message msg, string path, GLib.HashTable<string,string>? query, Soup.ClientContext client) { try { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("index.html", l); - t.replace("TITLE", "KtT Shop System"); + t.replace("TITLE", shortname + " Shop System"); + t.replace("SHORTNAME", shortname); t.menu_set_active("home"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); msg.set_status(200); @@ -39,7 +42,8 @@ public class WebServer { var l = new WebSession(server, msg, path, query, client); l.logout(); var t = new WebTemplate("logout.html", l); - t.replace("TITLE", "KtT Shop System"); + t.replace("TITLE", shortname + " Shop System"); + t.replace("SHORTNAME", shortname); t.menu_set_active("home"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); msg.set_status(200); @@ -96,7 +100,8 @@ public class WebServer { } var t = new WebTemplate("users/index.html", session); - t.replace("TITLE", "KtT Shop System: User"); + t.replace("TITLE", shortname + " Shop System: User"); + t.replace("SHORTNAME", shortname); t.menu_set_active("users"); var data = ""; foreach(var m in db.get_member_ids()) { @@ -130,7 +135,8 @@ public class WebServer { } var t = new WebTemplate("users/import-pgp.html", session); - t.replace("TITLE", "KtT Shop System: PGP Key Import"); + t.replace("TITLE", shortname + " Shop System: PGP Key Import"); + t.replace("SHORTNAME", shortname); t.menu_set_active("users"); Soup.Buffer filedata; @@ -182,7 +188,8 @@ public class WebServer { return; } var t = new WebTemplate("users/import.html", session); - t.replace("TITLE", "KtT Shop System: User Import"); + t.replace("TITLE", shortname + " Shop System: User Import"); + t.replace("SHORTNAME", shortname); t.menu_set_active("users"); Soup.Buffer filedata; @@ -327,7 +334,8 @@ public class WebServer { return; } var t = new WebTemplate("users/entry.html", session); - t.replace("TITLE", "KtT Shop System: User Info %llu".printf(id)); + t.replace("TITLE", shortname + " Shop System: User Info %llu".printf(id)); + t.replace("SHORTNAME", shortname); t.menu_set_active("users"); var userinfo = db.get_user_info(id); @@ -431,7 +439,8 @@ public class WebServer { return; } var t = new WebTemplate("users/invoice.html", l); - t.replace("TITLE", "KtT Shop System: User Invoice %llu".printf(id)); + t.replace("TITLE", shortname + " Shop System: User Invoice %llu".printf(id)); + t.replace("SHORTNAME", shortname); t.menu_set_active("users"); /* years, in which something has been purchased by the user */ @@ -553,7 +562,8 @@ public class WebServer { try { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("products/index.html", l); - t.replace("TITLE", "KtT Shop System: Product List"); + t.replace("TITLE", shortname + " Shop System: Product List"); + t.replace("SHORTNAME", shortname); t.menu_set_active("products"); string table = ""; @@ -590,7 +600,8 @@ public class WebServer { try { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("products/bestbefore.html", l); - t.replace("TITLE", "KtT Shop System: Best Before List"); + t.replace("TITLE", shortname + " Shop System: Best Before List"); + t.replace("SHORTNAME", shortname); t.menu_set_active("products"); string table = ""; @@ -645,7 +656,8 @@ public class WebServer { try { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("products/entry.html", l); - t.replace("TITLE", "KtT Shop System: Product %llu".printf(id)); + t.replace("TITLE", shortname + " Shop System: Product %llu".printf(id)); + t.replace("SHORTNAME", shortname); t.menu_set_active("products"); /* ean */ @@ -725,7 +737,8 @@ public class WebServer { try { var session = new WebSession(server, msg, path, query, client); var template = new WebTemplate("products/new.html", session); - template.replace("TITLE", "KtT Shop System: New Product"); + template.replace("TITLE", shortname + " Shop System: New Product"); + template.replace("SHORTNAME", shortname); template.menu_set_active("products"); if(!session.superuser && !session.auth_products) { @@ -781,7 +794,8 @@ public class WebServer { } var template = new WebTemplate("products/restock.html", session); - template.replace("TITLE", "KtT Shop System: Restock Product %llu".printf(id)); + template.replace("TITLE", shortname + " Shop System: Restock Product %llu".printf(id)); + template.replace("SHORTNAME", shortname); template.replace("NAME", db.get_product_name(id)); template.menu_set_active("products"); @@ -839,7 +853,7 @@ public class WebServer { } var template = new WebTemplate("products/newprice.html", session); - template.replace("TITLE", "KtT Shop System: New Price for Product %llu".printf(id)); + template.replace("TITLE", shortname + " Shop System: New Price for Product %llu".printf(id)); template.replace("NAME", db.get_product_name(id)); template.menu_set_active("products"); @@ -878,7 +892,8 @@ public class WebServer { try { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("aliases/index.html", l); - t.replace("TITLE", "KtT Shop System: Alias List"); + t.replace("TITLE", shortname + " Shop System: Alias List"); + t.replace("SHORTNAME", shortname); t.menu_set_active("aliases"); string table = ""; @@ -910,7 +925,8 @@ public class WebServer { try { var session = new WebSession(server, msg, path, query, client); var template = new WebTemplate("aliases/new.html", session); - template.replace("TITLE", "KtT Shop System: New Alias"); + template.replace("TITLE", shortname + " Shop System: New Alias"); + template.replace("SHORTNAME", shortname); template.menu_set_active("aliases"); if(!session.superuser && !session.auth_products) { @@ -958,7 +974,8 @@ public class WebServer { try { var l = new WebSession(server, msg, path, query, client); var t = new WebTemplate("stats/index.html", l); - t.replace("TITLE", "KtT Shop System: Statistics"); + t.replace("TITLE", shortname + " Shop System: Statistics"); + t.replace("SHORTNAME", shortname); t.menu_set_active("stats"); var stats = db.get_stats_info(); @@ -991,7 +1008,8 @@ public class WebServer { var t = new WebTemplate("stats/stock.html", l); string data = db.get_stats_stock().json; t.replace("DATA", data); - t.replace("TITLE", "KtT Shop System: Statistics: Stock"); + t.replace("SHORTNAME", shortname); + t.replace("TITLE", shortname + " Shop System: Statistics: Stock"); t.menu_set_active("stats"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); msg.set_status(200); @@ -1007,7 +1025,8 @@ public class WebServer { var t = new WebTemplate("stats/profit_per_day.html", l); string data = db.get_stats_profit_per_day().json; t.replace("DATA", data); - t.replace("TITLE", "KtT Shop System: Statistics: Profit"); + t.replace("SHORTNAME", shortname); + t.replace("TITLE", shortname + " Shop System: Statistics: Profit"); t.menu_set_active("stats"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); msg.set_status(200); @@ -1023,7 +1042,8 @@ public class WebServer { var t = new WebTemplate("stats/profit_per_weekday.html", l); string data = db.get_stats_profit_per_weekday().json; t.replace("DATA", data); - t.replace("TITLE", "KtT Shop System: Statistics: Profit/Weekday"); + t.replace("SHORTNAME", shortname); + t.replace("TITLE", shortname + " Shop System: Statistics: Profit/Weekday"); t.menu_set_active("stats"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); msg.set_status(200); @@ -1039,7 +1059,8 @@ public class WebServer { var t = new WebTemplate("stats/profit_per_product.html", l); string data = db.get_stats_profit_per_products().json; t.replace("DATA", data); - t.replace("TITLE", "KtT Shop System: Statistics: Profit/Product"); + t.replace("SHORTNAME", shortname); + t.replace("TITLE", shortname + " Shop System: Statistics: Profit/Product"); t.menu_set_active("stats"); msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); msg.set_status(200); @@ -1148,7 +1169,8 @@ public class WebServer { try { var session = new WebSession(server, msg, path, query, client); var template = new WebTemplate("errors/todo.html", session); - template.replace("TITLE", "KtT Shop System: ToDo"); + template.replace("TITLE", shortname + " Shop System: ToDo"); + template.replace("SHORTNAME", shortname); template.menu_set_active(""); msg.set_response("text/html", Soup.MemoryUse.COPY, template.data); msg.set_status(200); @@ -1193,7 +1215,8 @@ public class WebServer { hist += "</tr>\n"; } - template.replace("TITLE", "KtT Shop System: Cashbox"); + template.replace("TITLE", shortname + " Shop System: Cashbox"); + template.replace("SHORTNAME", shortname); template.replace("CASHBOX_STATUS", status); template.replace("CASHBOX_HISTORY", hist); template.menu_set_active("cashbox"); @@ -1219,7 +1242,8 @@ public class WebServer { } var template = new WebTemplate("cashbox/add.html", session); - template.replace("TITLE", "KtT Shop System: Cashbox Balance"); + template.replace("TITLE", shortname + " Shop System: Cashbox Balance"); + template.replace("SHORTNAME", shortname); template.menu_set_active("cashbox"); bool error = false; @@ -1291,7 +1315,8 @@ public class WebServer { try { var session = new WebSession(server, msg, path, query, client); var template = new WebTemplate("cashbox/selection.html", session); - template.replace("TITLE", "KtT Shop System: Cashbox Detail"); + template.replace("TITLE", shortname + " Shop System: Cashbox Detail"); + template.replace("SHORTNAME", shortname); template.menu_set_active("cashbox"); msg.set_response("text/html", Soup.MemoryUse.COPY, template.data); msg.set_status(200); @@ -1361,9 +1386,9 @@ public class WebServer { } var template = new WebTemplate("cashbox/detail.html", session); - template.replace("TITLE", "KtT Shop System: Cashbox Detail"); + template.replace("TITLE", shortname + " Shop System: Cashbox Detail"); template.menu_set_active("cashbox"); - + template.replace("SHORTNAME", shortname); template.replace("DATE", start.format("%B %Y")); template.replace("DEBIT", debit.to_string()); template.replace("LOSS", loss.to_string()); @@ -1387,6 +1412,16 @@ public class WebServer { } public WebServer(uint port = 8080, TlsCertificate? cert = null) throws Error { + /* get configuration */ + Config config = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); + try { + longname = config.get_string("GENERAL", "longname"); + shortname = config.get_string("GENERAL", "shortname"); + } catch(KeyFileError e) { + longname = "Logname Missing in Config"; + shortname = "Shortname Missing in Config"; + } + srv = new Soup.Server("tls-certificate", cert); Soup.ServerListenOptions options = 0; |