diff options
Diffstat (limited to 'src/invoice')
-rw-r--r-- | src/invoice/invoice.vala | 41 |
1 files changed, 35 insertions, 6 deletions
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; } |