From ceddbd0554bbc566ad008cab45748113d9713d82 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Sat, 11 May 2013 04:20:13 +0200 Subject: pdf-invoice: use InvoiceEntry from DB interface --- src/pdf-invoice/Makefile | 2 +- src/pdf-invoice/pdf-invoice-interface.vala | 6 ---- src/pdf-invoice/pdf-invoice.vala | 44 ++++++++++++++++-------------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/pdf-invoice/Makefile b/src/pdf-invoice/Makefile index cc6db94..ef07ba1 100644 --- a/src/pdf-invoice/Makefile +++ b/src/pdf-invoice/Makefile @@ -1,6 +1,6 @@ all: pdf-invoice -pdf-invoice: main.vala pdf-invoice.vala pdf-invoice-interface.vala ../price.vapi +pdf-invoice: main.vala pdf-invoice.vala pdf-invoice-interface.vala ../database/db-interface.vala ../price.vapi valac -g -o $@ --pkg pangocairo --pkg librsvg-2.0 --pkg posix --pkg gdk-2.0 --pkg gio-2.0 $^ test: pdf-invoice-interface.vala test.vala ../price.vapi diff --git a/src/pdf-invoice/pdf-invoice-interface.vala b/src/pdf-invoice/pdf-invoice-interface.vala index d2c04d9..8fccbf0 100644 --- a/src/pdf-invoice/pdf-invoice-interface.vala +++ b/src/pdf-invoice/pdf-invoice-interface.vala @@ -36,12 +36,6 @@ public struct InvoiceRecipient { public string gender; } -public struct InvoiceEntry { - int timestamp; - string article; - Price price; -} - [DBus (name = "io.mainframe.shopsystem.InvoicePDF")] public interface PDFInvoice : Object { public abstract string invoice_id { set; owned get; } diff --git a/src/pdf-invoice/pdf-invoice.vala b/src/pdf-invoice/pdf-invoice.vala index 7e02b07..5182425 100644 --- a/src/pdf-invoice/pdf-invoice.vala +++ b/src/pdf-invoice/pdf-invoice.vala @@ -20,10 +20,21 @@ public class InvoicePDF { private const double height = 841.88976; /* 297mm */ /* invoice content, which should appear in the PDF */ - public string invoice_id { set; owned get; } - public int64 invoice_date { set; get; } - public InvoiceRecipient invoice_recipient { set; owned get; } - public InvoiceEntry[] invoice_entries { set; owned get; } + public string invoice_id { set; owned get; default = ""; } + public int64 invoice_date { set; get; default = 0; } + public InvoiceEntry[] invoice_entries { set; owned get; default = null; } + public InvoiceRecipient invoice_recipient { + set; + owned get; + default = InvoiceRecipient() { + firstname = "", + lastname = "", + street = "", + postal_code = "", + city = "", + gender = "" + }; + } /* pdf data */ private uint8[] data; @@ -48,7 +59,6 @@ public class InvoicePDF { }; public InvoicePDF() { - clear(); } private void render_svg(Cairo.Context ctx, string file) { @@ -307,20 +317,12 @@ public class InvoicePDF { } private string get_address() { - string address; - switch(invoice_recipient.gender) { - case "masculinum": - address = "Sehr geehrter Herr"; - break; - case "femininum": - address = "Sehr geehrte Frau"; - break; - default: - address = "Moin"; - break; - } - - return address; + if(invoice_recipient.gender == "masculinum") + return "Sehr geehrter Herr"; + else if(invoice_recipient.gender == "femininum") + return "Sehr geehrte Frau"; + else + return "Moin"; } private void draw_first_page_text(Cairo.Context ctx) { @@ -439,7 +441,7 @@ public class InvoicePDF { var tm = new DateTime.from_unix_local(e.timestamp); var date = tm.format("%Y-%m-%d"); var time = tm.format("%H:%M:%S"); - var article = e.article; + var article = e.product.name; var price = @"$(e.price)€".replace(".", ","); if(e.price > 999999) { @@ -563,7 +565,7 @@ public class InvoicePDF { /* retry adding the entry */ if(!draw_invoice_table_entry(ctx, y, entry, out y)) { - throw new InvoicePDFError.ARTICLE_NAME_TOO_LONG("Article name \"%s\" does not fit on a single page!", entry.article); + throw new InvoicePDFError.ARTICLE_NAME_TOO_LONG("Article name \"%s\" does not fit on a single page!", entry.product.name); } } } -- cgit v1.2.3