|
@@ -0,0 +1,99 @@
|
|
1
|
+<window id="greenforroasted">
|
|
2
|
+ <reporttitle>Production:->Green Coffees Used for Roasted Coffees</reporttitle>
|
|
3
|
+ <layout type="vertical">
|
|
4
|
+ <layout type="horizontal">
|
|
5
|
+ <daterange id="dates" initial="19" /><!-- Year to Date -->
|
|
6
|
+ <stretch />
|
|
7
|
+ </layout>
|
|
8
|
+ <webview id="report" />
|
|
9
|
+ </layout>
|
|
10
|
+ <menu name="File">
|
|
11
|
+ <item id="print" shortcut="Ctrl+P">Print...</item>
|
|
12
|
+ </menu>
|
|
13
|
+ <program>
|
|
14
|
+ <![CDATA[
|
|
15
|
+ this.windowTitle = TTR("greenforroasted", "Typica - Green Coffees Used for Roasted Coffees");
|
|
16
|
+ var report = findChildObject(this, 'report');
|
|
17
|
+ var printMenu = findChildObject(this, 'print');
|
|
18
|
+ printMenu.triggered.connect(function() {
|
|
19
|
+ report.print();
|
|
20
|
+ });
|
|
21
|
+ var dateSelect = findChildObject(this, 'dates');
|
|
22
|
+ var dateQuery = new QSqlQuery;
|
|
23
|
+ dateQuery.exec("SELECT time::date FROM transactions WHERE time = (SELECT min(time) FROM transactions) OR time = (SELECT max(time) FROM transactions) ORDER BY time ASC");
|
|
24
|
+ dateQuery.next();
|
|
25
|
+ var lifetimeStartDate = dateQuery.value(0);
|
|
26
|
+ var lifetimeEndDate;
|
|
27
|
+ if(dateQuery.next()) {
|
|
28
|
+ lifetimeEndDate = dateQuery.value(0);
|
|
29
|
+ } else {
|
|
30
|
+ lifetimeEndDate = lifetimeStartDate;
|
|
31
|
+ }
|
|
32
|
+ dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
|
|
33
|
+ dateQuery = dateQuery.invalidate();
|
|
34
|
+ dateSelect.rangeUpdated.connect(refresh);
|
|
35
|
+ function refresh() {
|
|
36
|
+ var dateRange = dateSelect.currentRange();
|
|
37
|
+ var startDate = dateRange[0];
|
|
38
|
+ var endDate = dateRange[dateRange.length - 1];
|
|
39
|
+ var buffer = new QBuffer;
|
|
40
|
+ buffer.open(3);
|
|
41
|
+ var output = new XmlWriter(buffer);
|
|
42
|
+ output.writeStartDocument("1.0");
|
|
43
|
+ 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">');
|
|
44
|
+ output.writeStartElement("html");
|
|
45
|
+ output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
|
46
|
+ output.writeStartElement("head");
|
|
47
|
+ output.writeTextElement("title", TTR("greenforroasted", "Green Coffees Used for Roasted Coffees"));
|
|
48
|
+ output.writeEndElement(); //head
|
|
49
|
+ output.writeStartElement("body");
|
|
50
|
+ output.writeTextElement("h1", TTR("greenforroasted", "Green Coffees Used for Roasted Coffees ") + startDate + "-" + endDate);
|
|
51
|
+ output.writeStartElement("ul");
|
|
52
|
+ var query = new QSqlQuery();
|
|
53
|
+ query.prepare("WITH q AS (SELECT roasted_id, unroasted_id, (SELECT name FROM items WHERE id = roasted_id) AS rname, generate_subscripts(unroasted_id, 1) AS s, sum(roasted_quantity) AS rq, min(time)::date, max(time)::date FROM roasting_log WHERE time >= :sd1 AND time < :ed1 ::date + interval '1 day' GROUP BY roasted_id, unroasted_id) SELECT q.*, (SELECT name FROM items WHERE id = unroasted_id[q.s]) || ' (' || unroasted_id[q.s] || ')' AS gname, (SELECT SUM(unroasted_quantity[q.s]) AS gq FROM roasting_log WHERE roasted_id = q.roasted_id AND unroasted_id = q.unroasted_id AND time >= :sd2 AND time < :ed2 ::date + interval '1 day') FROM q ORDER BY q.rname ASC, min ASC");
|
|
54
|
+ query.bind(":sd1", startDate);
|
|
55
|
+ query.bind(":sd2", startDate);
|
|
56
|
+ query.bind(":ed1", endDate);
|
|
57
|
+ query.bind(":ed2", endDate);
|
|
58
|
+ query.exec();
|
|
59
|
+ var prevRid = -1;
|
|
60
|
+ var prevGid = "";
|
|
61
|
+ var first = true;
|
|
62
|
+ while(query.next()) {
|
|
63
|
+ if(query.value(0) != prevRid) { // New roasted item
|
|
64
|
+ if(!first) {
|
|
65
|
+ output.writeEndElement(); //ul from previous roasted item
|
|
66
|
+ output.writeEndElement(); //ul from previous roasted item
|
|
67
|
+ } else {
|
|
68
|
+ first = false;
|
|
69
|
+ }
|
|
70
|
+ output.writeTextElement("li", query.value(2) + " (" + query.value(0) + ")");
|
|
71
|
+ output.writeStartElement("ul");
|
|
72
|
+ output.writeTextElement("li", query.value(4) + " pounds roasted between " + query.value(5) + " and " + query.value(6) + " with:");
|
|
73
|
+ output.writeStartElement("ul");
|
|
74
|
+ output.writeTextElement("li", query.value(8) + " pounds of " + query.value(7));
|
|
75
|
+ }
|
|
76
|
+ else { // Same roasted item
|
|
77
|
+ if(query.value(1) != prevGid) { // New set of greens
|
|
78
|
+ output.writeEndElement(); //ul
|
|
79
|
+ output.writeTextElement("li", query.value(4) + " pounds roasted between " + query.value(5) + " and " + query.value(6) + " with:");
|
|
80
|
+ output.writeStartElement("ul");
|
|
81
|
+ output.writeTextElement("li", query.value(8) + " pounds of " + query.value(7));
|
|
82
|
+ } else { // Same set of greens
|
|
83
|
+ output.writeTextElement("li", query.value(8) + " pounds of " + query.value(7));
|
|
84
|
+ }
|
|
85
|
+ }
|
|
86
|
+ prevRid = query.value(0);
|
|
87
|
+ prevGid = query.value(1);
|
|
88
|
+ }
|
|
89
|
+ output.writeEndElement(); //ul
|
|
90
|
+ output.writeEndElement(); //body
|
|
91
|
+ output.writeEndElement(); //html
|
|
92
|
+ output.writeEndDocument();
|
|
93
|
+ report.setContent(buffer);
|
|
94
|
+ buffer.close();
|
|
95
|
+ }
|
|
96
|
+ refresh();
|
|
97
|
+ ]]>
|
|
98
|
+ </program>
|
|
99
|
+</window>
|