Bladeren bron

Alternative invoice list

Neal Wilson 9 jaren geleden
bovenliggende
commit
38f19d6dd4
1 gewijzigde bestanden met toevoegingen van 147 en 0 verwijderingen
  1. 147
    0
      config/Reports/invoices.xml

+ 147
- 0
config/Reports/invoices.xml Bestand weergeven

@@ -0,0 +1,147 @@
1
+<window id="invoicereport">
2
+    <reporttitle>Purchase:->Invoices</reporttitle>
3
+    <layout type="vertical">
4
+        <layout type="horizontal">
5
+            <daterange id="dates" initial="23" /><!-- Lifetime -->
6
+            <label>Vendor: </label>
7
+            <sqldrop id="vendor" />
8
+            <label>Search: </label>
9
+            <line id="search" />
10
+            <stretch />
11
+        </layout>
12
+        <webview id="report" />
13
+    </layout>
14
+    <menu name="File">
15
+        <item id="print" shortcut="Ctrl+P">Print...</item>
16
+    </menu>
17
+    <program>
18
+        <![CDATA[
19
+            var vendor = findChildObject(this, "vendor");
20
+            vendor.addItem("Any");
21
+            var query = new QSqlQuery();
22
+            query.exec("SELECT DISTINCT vendor FROM invoices");
23
+            while(query.next()) {
24
+                vendor.addItem(query.value(0));
25
+            }
26
+            vendor['currentIndexChanged(int)'].connect(refresh);
27
+            var dateSelect = findChildObject(this, 'dates');
28
+            query.exec("SELECT time::date FROM invoices WHERE time = (SELECT min(time) FROM invoices) OR time = (SELECT max(time) FROM invoices) ORDER BY time ASC");
29
+            query.next();
30
+            var lifetimeStartDate = query.value(0);
31
+            var lifetimeEndDate;
32
+            if(query.next()) {
33
+                lifetimeEndDate = query.value(0);
34
+            } else {
35
+                lifetimeEndDate = lifetimeStartDate;
36
+            }
37
+            dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
38
+            dateSelect.rangeUpdated.connect(refresh);
39
+            query = query.invalidate();
40
+            var search = findChildObject(this, "search");
41
+            search.editingFinished.connect(refresh);
42
+            var view = findChildObject(this, "report");
43
+            view.scriptLinkClicked.connect(function(url) {
44
+                var info = createWindow("invoiceinfo");
45
+                info.setInvoiceID(url);
46
+                var invquery = new QSqlQuery();
47
+                invquery.exec("SELECT time, invoice, vendor FROM invoices WHERE id = " + url);
48
+                invquery.next();
49
+                var timefield = findChildObject(info, 'date');
50
+                timefield.text = invquery.value(0);
51
+                var vendorfield = findChildObject(info, 'vendor');
52
+                vendorfield.text = invquery.value(2);
53
+                var invoicefield = findChildObject(info, 'invoice');
54
+                invoicefield.text = invquery.value(1);
55
+                var itemtable = findChildObject(info, 'itemtable');
56
+                itemtable.setQuery("SELECT record_type, item_id, description, (SELECT reference FROM items WHERE id = item_id) AS reference, (SELECT cost FROM purchase WHERE item = item_id) AS unit_cost, (SELECT quantity FROM purchase WHERE item = item_id) AS quantity, ((SELECT quantity FROM purchase WHERE item = item_id)/(SELECT conversion FROM lb_bag_conversion WHERE item = item_id))::numeric(12,2) AS sacks, cost FROM invoice_items WHERE invoice_id = " + url + " AND record_type = 'PURCHASE' UNION SELECT record_type, NULL, description, NULL, NULL, NULL, NULL, cost FROM invoice_items WHERE invoice_id = " + url + " AND record_type = 'FEE' ORDER BY item_id");
57
+                invquery = invquery.invalidate();
58
+            });
59
+            function refresh() {
60
+                var dateRange = dateSelect.currentRange();
61
+                var startDate = dateRange[0];
62
+                var endDate = dateRange[dateRange.length - 1];
63
+                var buffer = new QBuffer;
64
+                buffer.open(3);
65
+                var output = new XmlWriter(buffer);
66
+                output.writeStartDocument("1.0");
67
+                output.writeDTD('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg.dtd">');
68
+                output.writeStartElement("html");
69
+                output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
70
+                output.writeStartElement("head");
71
+                output.writeTextElement("title", "Invoices");
72
+                output.writeEndElement();
73
+                output.writeStartElement("body");
74
+                output.writeTextElement("h1", "Invoices " + startDate + " - " + endDate);
75
+                output.writeStartElement("table");
76
+                output.writeAttribute("style", "page-break-after: auto; text-align: left");
77
+                output.writeAttribute("rules", "groups");
78
+                output.writeAttribute("cellpadding", "3px");
79
+                output.writeStartElement("thead");
80
+                output.writeStartElement("tr");
81
+                output.writeTextElement("th", "Date");
82
+                output.writeTextElement("th", "Vendor");
83
+                output.writeTextElement("th", "Invoice");
84
+                output.writeTextElement("th", "Cost");
85
+                output.writeEndElement();
86
+                output.writeEndElement();
87
+                output.writeStartElement("tbody");
88
+                var query = new QSqlQuery();
89
+                var vendorclause = "";
90
+                if(vendor.currentIndex > 0) {
91
+                    vendorclause = " AND vendor = :vendor";
92
+                }
93
+                var searchclause = "";
94
+                if(search.text.length > 0)
95
+                {
96
+                    searchclause = " AND id IN (SELECT invoice_id FROM invoice_items WHERE item_id IN (SELECT item FROM certifications WHERE certification ~* :p1 UNION SELECT id FROM coffees WHERE origin ~* :p2 UNION SELECT id FROM items WHERE name ~* :p3 UNION SELECT id FROM coffees WHERE reference ~* :p4))";
97
+                }
98
+                query.prepare("SELECT id, time::date, vendor, invoice, (SELECT sum(cost) FROM invoice_items WHERE invoice_id = id) AS cost FROM invoices WHERE time >= :sd AND time < :ed::date + interval '1 day'" + vendorclause + searchclause + " ORDER BY time DESC");
99
+                query.bind(":sd", startDate);
100
+                query.bind(":ed", endDate);
101
+                if(vendorclause.length > 0) {
102
+                    query.bind(":vendor", vendor.currentText);
103
+                }
104
+                if(searchclause.length > 0)
105
+                {
106
+                    var pattern = ".*" + search.text + ".*";
107
+                    query.bind(":p1", pattern);
108
+                    query.bind(":p2", pattern);
109
+                    query.bind(":p3", pattern);
110
+                    query.bind(":p4", pattern);
111
+                }
112
+                query.exec();
113
+                var cost_sum = 0;
114
+                while(query.next()) {
115
+                    output.writeStartElement("tr");
116
+                    output.writeStartElement("td");
117
+                    output.writeStartElement("a");
118
+                    output.writeAttribute("href", "typica://script/" + query.value(0));
119
+                    output.writeCharacters(query.value(1));
120
+                    output.writeEndElement();
121
+                    output.writeEndElement();
122
+                    for(var i = 2; i <= 4; i++) {
123
+                        output.writeTextElement("td", query.value(i));
124
+                    }
125
+                    output.writeEndElement();
126
+                    cost_sum += Number(query.value(4));
127
+                }
128
+                query = query.invalidate();
129
+                output.writeEndElement();
130
+                output.writeStartElement("tfoot");
131
+                output.writeStartElement("tr");
132
+                output.writeEmptyElement("td");
133
+                output.writeEmptyElement("td");
134
+                output.writeTextElement("th", "Total:");
135
+                output.writeTextElement("td", cost_sum);
136
+                output.writeEndElement();
137
+                output.writeEndElement();
138
+                output.writeEndElement();
139
+                output.writeEndElement();
140
+                output.writeEndElement();
141
+                output.writeEndDocument();
142
+                view.setContent(buffer);
143
+                buffer.close();
144
+            }
145
+            refresh();
146
+        ]]>
147
+    </program>

Laden…
Annuleren
Opslaan