Browse Source

Add production summary report

Neal Wilson 8 years ago
parent
commit
93b3094800
1 changed files with 138 additions and 0 deletions
  1. 138
    0
      config/Reports/productionsummary.xml

+ 138
- 0
config/Reports/productionsummary.xml View File

@@ -0,0 +1,138 @@
1
+<window id="dailyproduction">
2
+    <reporttitle>Production:->Production Summary</reporttitle>
3
+    <layout type="vertical">
4
+        <layout type="horizontal">
5
+            <daterange id="dates" initial="9" /><!-- Current Month to Date-->
6
+            <label>Weight Unit:</label>
7
+            <sqldrop id="unit" />
8
+            <stretch />
9
+        </layout>
10
+        <webview id="report" />
11
+    </layout>
12
+    <menu name="File">
13
+        <item id="print" shortcut="Ctrl+P">Print</item>
14
+    </menu>
15
+    <program>
16
+        <![CDATA[
17
+            this.windowTitle = "Typica - Production Summary";
18
+            var dateSelect = findChildObject(this, 'dates');
19
+            var dateQuery = new QSqlQuery();
20
+            dateQuery.exec("SELECT time::date FROM roasting_log WHERE time = (SELECT min(time) FROM roasting_log) OR time = (SELECT max(time) FROM roasting_log) ORDER BY time ASC");
21
+            dateQuery.next();
22
+            var lifetimeStartDate = dateQuery.value(0);
23
+            var lifetimeEndDate;
24
+            if(dateQuery.next()) {
25
+                lifetimeEndDate = dateQuery.value(0);
26
+            } else {
27
+                lifetimeEndDate = lifetimeStartDate;
28
+            }
29
+            dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
30
+            dateQuery = dateQuery.invalidate();
31
+            var unitBox = findChildObject(this, 'unit');
32
+            unitBox.addItem("Kg");
33
+            unitBox.addItem("Lb");
34
+            unitBox.currentIndex = QSettings.value("script/report_unit", 1);
35
+            unitBox['currentIndexChanged(int)'].connect(function() {
36
+                QSettings.setValue("script/report_unit", unitBox.currentIndex);
37
+                refresh();
38
+            });
39
+            var view = findChildObject(this, 'report');
40
+            var printMenu = findChildObject(this, 'print');
41
+            printMenu.triggered.connect(function() {
42
+                view.print();
43
+            });
44
+            function refresh() {
45
+                var buffer = new QBuffer;
46
+                buffer.open(3);
47
+                var output = new XmlWriter(buffer);
48
+                output.writeStartDocument("1.0");
49
+                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">');
50
+                output.writeStartElement("html");
51
+                output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
52
+                output.writeStartElement("head");
53
+                output.writeTextElement("title", "Production Summary");
54
+                output.writeEndElement();
55
+                output.writeStartElement("body");
56
+                var dateRange = dateSelect.currentRange();
57
+                var startDate = dateRange[0];
58
+                var endDate = dateRange[dateRange.length - 1];
59
+                output.writeTextElement("h1", "Production Summary: " + startDate + " - " + endDate);
60
+                var conversion = 1;
61
+                var unitText = 'Lb';
62
+                if(unitBox.currentIndex == 0) {
63
+                    conversion = 2.2;
64
+                    unitText = 'Kg';
65
+                }
66
+                var query = new QSqlQuery();
67
+                query.prepare("SELECT count(1), sum(unroasted_total_quantity) / :c1, sum(roasted_quantity) / :c2 FROM roasting_log WHERE time >= :sd AND time < :ed ::date + interval '1 day'");
68
+                query.bind(":c1", conversion);
69
+                query.bind(":c2", conversion);
70
+                query.bind(":sd", startDate);
71
+                query.bind(":ed", endDate);
72
+                query.exec();
73
+                query.next();
74
+                var batchesRoasted = query.value(0);
75
+                var unroastedSum = query.value(1);
76
+                var roastedSum = query.value(2);
77
+                output.writeTextElement("p", "" + roastedSum + " " + unitText + " roasted from " + unroastedSum + " " + unitText + " green in " + batchesRoasted + " batches.");
78
+                query.prepare("SELECT time::date AS date, count(1), sum(unroasted_total_quantity) / :c1, sum(roasted_quantity) / :c2 FROM roasting_log WHERE time >= :sd AND time < :ed ::date + interval '1 day' GROUP BY date ORDER BY date ASC");
79
+                query.bind(":c1", conversion);
80
+                query.bind(":c2", conversion);
81
+                query.bind(":sd", startDate);
82
+                query.bind(":ed", endDate);
83
+                query.exec();
84
+                output.writeStartElement("table");
85
+                output.writeAttribute("rules", "groups");
86
+                output.writeAttribute("cellpadding", "3px");
87
+                output.writeStartElement("thead");
88
+                output.writeStartElement("tr");
89
+                output.writeTextElement("th", "Date");
90
+                output.writeTextElement("th", "Batches");
91
+                output.writeTextElement("th", "Unroasted (" + unitText + ")");
92
+                output.writeTextElement("th", "Roasted (" + unitText + ")");
93
+                output.writeEndElement();
94
+                output.writeEndElement();
95
+                output.writeStartElement("tbody");
96
+                while(query.next()) {
97
+                    output.writeStartElement("tr");
98
+                    output.writeStartElement("td");
99
+                    output.writeStartElement("a");
100
+                    output.writeAttribute("href", "typica://script/d" + query.value(0));
101
+                    output.writeCDATA(query.value(0));
102
+                    output.writeEndElement();
103
+                    output.writeEndElement();
104
+                    output.writeTextElement("td", query.value(1));
105
+                    output.writeTextElement("td", query.value(2));
106
+                    output.writeTextElement("td", query.value(3));
107
+                    output.writeEndElement();
108
+                }
109
+                output.writeEndElement();
110
+                output.writeStartElement("tfoot");
111
+                output.writeStartElement("tr");
112
+                output.writeStartElement("td");
113
+                output.writeTextElement("strong", "Totals:");
114
+                output.writeEndElement();
115
+                output.writeTextElement("td", batchesRoasted);
116
+                output.writeTextElement("td", unroastedSum);
117
+                output.writeTextElement("td", roastedSum);
118
+                output.writeEndElement();
119
+                output.writeEndElement();
120
+                output.writeEndElement();
121
+                output.writeEndElement();
122
+                output.writeEndElement();
123
+                output.writeEndDocument();
124
+                view.setContent(buffer);
125
+                buffer.close();
126
+                query = query.invalidate();
127
+            }
128
+            refresh();
129
+            dateSelect.rangeUpdated.connect(refresh);
130
+            view.scriptLinkClicked.connect(function(url) {
131
+                var arg = url.slice(1, url.length).split("-");
132
+                var details = createReport("dailyproductiondetail.xml");
133
+                var selector = findChildObject(details, "reportdate");
134
+                selector.setDate(arg[0], arg[1], arg[2]);
135
+            });
136
+        ]]>
137
+    </program>
138
+</window>

Loading…
Cancel
Save