summaryrefslogtreecommitdiffstats
path: root/src/pdf-invoice
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2013-05-11 04:20:13 +0200
committerSebastian Reichel <sre@ring0.de>2013-05-11 04:20:13 +0200
commitceddbd0554bbc566ad008cab45748113d9713d82 (patch)
tree30f9a564548f0e840bf1531100f0c9d781bdf344 /src/pdf-invoice
parenta03f480ed4f9fe276384e2105ffd4c1bde628c77 (diff)
downloadserial-barcode-scanner-ceddbd0554bbc566ad008cab45748113d9713d82.tar.bz2
pdf-invoice: use InvoiceEntry from DB interface
Diffstat (limited to 'src/pdf-invoice')
-rw-r--r--src/pdf-invoice/Makefile2
-rw-r--r--src/pdf-invoice/pdf-invoice-interface.vala6
-rw-r--r--src/pdf-invoice/pdf-invoice.vala44
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);
}
}
}