|
@@ -0,0 +1,393 @@
|
|
1
|
+<window id="dailyproduction">
|
|
2
|
+ <reporttitle>Production:->Daily Production Report (Detailed)</reporttitle>
|
|
3
|
+ <layout type="vertical">
|
|
4
|
+ <layout type="horizontal">
|
|
5
|
+ <label>Date:</label>
|
|
6
|
+ <calendar id="reportdate" />
|
|
7
|
+ <label>Weight Unit:</label>
|
|
8
|
+ <sqldrop id="unit" />
|
|
9
|
+ <label>Temperature Unit:</label>
|
|
10
|
+ <sqldrop id="tempunit" />
|
|
11
|
+ <stretch />
|
|
12
|
+ </layout>
|
|
13
|
+ <webview id="report" />
|
|
14
|
+ </layout>
|
|
15
|
+ <menu name="File">
|
|
16
|
+ <item id="print" shortcut="Ctrl+P">Print</item>
|
|
17
|
+ </menu>
|
|
18
|
+ <program>
|
|
19
|
+ <![CDATA[
|
|
20
|
+ this.windowTitle = "Typica - Daily Production Report";
|
|
21
|
+ var dateField = findChildObject(this, 'reportdate');
|
|
22
|
+ var view = findChildObject(this, 'report');
|
|
23
|
+ var printMenu = findChildObject(this, 'print');
|
|
24
|
+ printMenu.triggered.connect(function() {
|
|
25
|
+ view.print();
|
|
26
|
+ });
|
|
27
|
+ var unitBox = findChildObject(this, 'unit');
|
|
28
|
+ unitBox.addItem("Kg");
|
|
29
|
+ unitBox.addItem("Lb");
|
|
30
|
+ unitBox.currentIndex = QSettings.value("script/report_unit", 1);
|
|
31
|
+ unitBox['currentIndexChanged(int)'].connect(function() {
|
|
32
|
+ QSettings.setValue("script/report_unit", unitBox.currentIndex);
|
|
33
|
+ refresh();
|
|
34
|
+ });
|
|
35
|
+ var tempUnit = findChildObject(this, 'tempunit');
|
|
36
|
+ tempUnit.addItem("Celsius");
|
|
37
|
+ tempUnit.addItem("Fahrenheit");
|
|
38
|
+ tempUnit.currentIndex = QSettings.value("script/report_temperature", 1);
|
|
39
|
+ tempUnit['currentIndexChanged(int)'].connect(function() {
|
|
40
|
+ QSettings.setValue("script/report_temperature", tempUnit.currentIndex);
|
|
41
|
+ refresh();
|
|
42
|
+ });
|
|
43
|
+ function refresh() {
|
|
44
|
+ var buffer = new QBuffer;
|
|
45
|
+ buffer.open(3);
|
|
46
|
+ var output = new XmlWriter(buffer);
|
|
47
|
+ output.writeStartDocument("1.0");
|
|
48
|
+ 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">');
|
|
49
|
+ output.writeStartElement("html");
|
|
50
|
+ output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
|
51
|
+ output.writeStartElement("head");
|
|
52
|
+ output.writeTextElement("title", "Daily Production Report");
|
|
53
|
+ output.writeEndElement();
|
|
54
|
+ output.writeStartElement("body");
|
|
55
|
+ var dateString = "" + dateField.year() + "-" + dateField.month() + "-" + dateField.day();
|
|
56
|
+ output.writeTextElement("h1", "Daily Production Report: " + dateString);
|
|
57
|
+ output.writeTextElement("h2", "Batches Roasted");
|
|
58
|
+ var query = new QSqlQuery();
|
|
59
|
+ var q = "SELECT time, machine, (SELECT name FROM machine WHERE id = machine), (SELECT name FROM items WHERE id = roasted_id), unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, annotation, duration, files FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1') ORDER BY time";
|
|
60
|
+ query.exec(q);
|
|
61
|
+ var times = new Array();
|
|
62
|
+ var machines = new Array();
|
|
63
|
+ output.writeStartElement("table");
|
|
64
|
+ output.writeAttribute("rules", "groups");
|
|
65
|
+ output.writeAttribute("cellpadding", "3px");
|
|
66
|
+ output.writeStartElement("thead");
|
|
67
|
+ output.writeStartElement("tr");
|
|
68
|
+ output.writeTextElement("th", "Time");
|
|
69
|
+ output.writeTextElement("th", "Machine");
|
|
70
|
+ output.writeTextElement("th", "Batch ID");
|
|
71
|
+ switch(unitBox.currentIndex)
|
|
72
|
+ {
|
|
73
|
+ case 0:
|
|
74
|
+ output.writeTextElement("th", "Green Weights (Kg)");
|
|
75
|
+ break;
|
|
76
|
+ case 1:
|
|
77
|
+ output.writeTextElement("th", "Green Weights (Lb)");
|
|
78
|
+ break;
|
|
79
|
+ }
|
|
80
|
+ output.writeTextElement("th", "Green Coffees");
|
|
81
|
+ switch(unitBox.currentIndex)
|
|
82
|
+ {
|
|
83
|
+ case 0:
|
|
84
|
+ output.writeTextElement("th", "Roasted Weight (Kg)");
|
|
85
|
+ break;
|
|
86
|
+ case 1:
|
|
87
|
+ output.writeTextElement("th", "Roasted Weight (Lb)");
|
|
88
|
+ break;
|
|
89
|
+ }
|
|
90
|
+ output.writeTextElement("th", "Roasted Coffee");
|
|
91
|
+ output.writeTextElement("th", "% Weight Loss");
|
|
92
|
+ output.writeTextElement("th", "Duration");
|
|
93
|
+ output.writeEndElement();
|
|
94
|
+ output.writeEndElement();
|
|
95
|
+ output.writeStartElement("tbody");
|
|
96
|
+ while(query.next())
|
|
97
|
+ {
|
|
98
|
+ times.push(query.value(0));
|
|
99
|
+ machines.push(query.value(1));
|
|
100
|
+ output.writeStartElement("tr");
|
|
101
|
+ output.writeTextElement("td", String(query.value(0)).split("T")[1]);
|
|
102
|
+ output.writeTextElement("td", query.value(2));
|
|
103
|
+ output.writeTextElement("td", query.value(11));
|
|
104
|
+ var unroastedWeightsList = sqlToArray(query.value(5));
|
|
105
|
+ output.writeStartElement("td");
|
|
106
|
+ for(var i = 0; i < unroastedWeightsList.length; i++)
|
|
107
|
+ {
|
|
108
|
+ if(i != 0)
|
|
109
|
+ {
|
|
110
|
+ output.writeEmptyElement("br");
|
|
111
|
+ }
|
|
112
|
+ switch(unitBox.currentIndex)
|
|
113
|
+ {
|
|
114
|
+ case 0:
|
|
115
|
+ output.writeCDATA((unroastedWeightsList[i]/2.2).toFixed(unroastedWeightsList[i].split('.').length > 1 ? unroastedWeightsList[i].split('.')[1].length : 0));
|
|
116
|
+ break;
|
|
117
|
+ case 1:
|
|
118
|
+ output.writeCDATA(unroastedWeightsList[i]);
|
|
119
|
+ break;
|
|
120
|
+ }
|
|
121
|
+ }
|
|
122
|
+ if(unroastedWeightsList.length > 1)
|
|
123
|
+ {
|
|
124
|
+ output.writeCDATA("Total: ");
|
|
125
|
+ switch(unitBox.currentIndex)
|
|
126
|
+ {
|
|
127
|
+ case 0:
|
|
128
|
+ output.writeCDATA((query.value(6)/2.2).toFixed(query.value(6).split('.').length > 1 ? query.value(6).split('.')[1].length : 0));
|
|
129
|
+ break;
|
|
130
|
+ case 1:
|
|
131
|
+ output.writeCDATA(query.value(6));
|
|
132
|
+ break;
|
|
133
|
+ }
|
|
134
|
+ }
|
|
135
|
+ output.writeEndElement();
|
|
136
|
+ var unroastedList = sqlToArray(query.value(4));
|
|
137
|
+ output.writeStartElement("td");
|
|
138
|
+ for(var i = 0; i < unroastedList.length; i++)
|
|
139
|
+ {
|
|
140
|
+ var greensQuery = new QSqlQuery();
|
|
141
|
+ greensQuery.prepare("SELECT name FROM items WHERE id = :id");
|
|
142
|
+ greensQuery.bind(":id", Number(unroastedList[i]));
|
|
143
|
+ greensQuery.exec();
|
|
144
|
+ if(i != 0)
|
|
145
|
+ {
|
|
146
|
+ output.writeEmptyElement("br");
|
|
147
|
+ }
|
|
148
|
+ greensQuery.next();
|
|
149
|
+ output.writeCDATA(greensQuery.value(0) + " (" + unroastedList[i] + ")");
|
|
150
|
+ }
|
|
151
|
+ output.writeEndElement();
|
|
152
|
+ switch(unitBox.currentIndex)
|
|
153
|
+ {
|
|
154
|
+ case 0:
|
|
155
|
+ output.writeCDATA((query.value(8)/2.2).toFixed(query.value(8).split('.').length > 1 ? query.value(8).split('.')[1].length : 0));
|
|
156
|
+ break;
|
|
157
|
+ case 1:
|
|
158
|
+ output.writeCDATA(query.value(8));
|
|
159
|
+ break;
|
|
160
|
+ }
|
|
161
|
+ output.writeTextElement("td", query.value(3) + " (" + query.value(7) + ")");
|
|
162
|
+ if(Number(query.value(6)) > 0) {
|
|
163
|
+ var loss = (Number(query.value(6)) - Number(query.value(8)))/Number(query.value(6));
|
|
164
|
+ loss *= 100;
|
|
165
|
+ output.writeTextElement("td", loss.toFixed(2)+"%");
|
|
166
|
+ } else {
|
|
167
|
+ output.writeTextElement("td", "Undefined");
|
|
168
|
+ }
|
|
169
|
+ output.writeTextElement("td", query.value(10));
|
|
170
|
+ output.writeEndElement();
|
|
171
|
+ if(query.value(9) != "")
|
|
172
|
+ {
|
|
173
|
+ output.writeStartElement("tr");
|
|
174
|
+ output.writeEmptyElement("td");
|
|
175
|
+ output.writeStartElement("td");
|
|
176
|
+ output.writeAttribute("colspan", "8");
|
|
177
|
+ output.writeTextElement("em", query.value(9));
|
|
178
|
+ output.writeEndElement();
|
|
179
|
+ output.writeEndElement();
|
|
180
|
+ }
|
|
181
|
+ var files = sqlToArray(query.value(11));
|
|
182
|
+ var annotations = annotationFromRecord(files[0]);
|
|
183
|
+ output.writeStartElement("tr");
|
|
184
|
+ output.writeStartElement("td");
|
|
185
|
+ output.writeAttribute("colspan", "9");
|
|
186
|
+ output.writeTextElement("strong", "Profile Summary");
|
|
187
|
+ var buffer2 = new QBuffer("<points>"+annotations+"</points>");
|
|
188
|
+ buffer2.open(1);
|
|
189
|
+ var colQuery = new XQuery;
|
|
190
|
+ colQuery.bind("profile", buffer2);
|
|
191
|
+ colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
|
|
192
|
+ var result = colQuery.exec();
|
|
193
|
+ buffer2.close();
|
|
194
|
+ var seriesHeaders = new Array();
|
|
195
|
+ seriesHeaders.push("Time");
|
|
196
|
+ var records = result.split(";");
|
|
197
|
+ for(var i = 0; i < records.length - 1; i++) {
|
|
198
|
+ seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
|
|
199
|
+ }
|
|
200
|
+ seriesHeaders.push("Note");
|
|
201
|
+ output.writeStartElement("table");
|
|
202
|
+ output.writeStartElement("thead");
|
|
203
|
+ output.writeStartElement("tr");
|
|
204
|
+ for(var i = 0; i < seriesHeaders.length; i++) {
|
|
205
|
+ if(i > 0 && i < seriesHeaders.length - 1) {
|
|
206
|
+ switch(tempUnit.currentIndex)
|
|
207
|
+ {
|
|
208
|
+ case 0:
|
|
209
|
+ output.writeTextElement("th", seriesHeaders[i] + " (°C)");
|
|
210
|
+ break;
|
|
211
|
+ case 1:
|
|
212
|
+ output.writeTextElement("th", seriesHeaders[i] + " (°F)");
|
|
213
|
+ break;
|
|
214
|
+ }
|
|
215
|
+ } else {
|
|
216
|
+ output.writeTextElement("th", seriesHeaders[i]);
|
|
217
|
+ }
|
|
218
|
+ }
|
|
219
|
+ output.writeEndElement();
|
|
220
|
+ output.writeEndElement();
|
|
221
|
+ buffer2.open(1);
|
|
222
|
+ var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
|
|
223
|
+ for(var i = 0; i < seriesHeaders.length - 2; i++) {
|
|
224
|
+ rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
|
|
225
|
+ }
|
|
226
|
+ rq = rq + 'string($t/annotation), "~")';
|
|
227
|
+ colQuery.setQuery(rq);
|
|
228
|
+ var annotationData = colQuery.exec();
|
|
229
|
+ buffer2.close();
|
|
230
|
+ output.writeStartElement("tbody");
|
|
231
|
+ var annotationRecords = annotationData.split("~");
|
|
232
|
+ for(var i = 0; i < annotationRecords.length - 1; i++) {
|
|
233
|
+ output.writeStartElement("tr");
|
|
234
|
+ var annotationRow = annotationRecords[i].split(";");
|
|
235
|
+ for(var j = 0; j < annotationRow.length; j++) {
|
|
236
|
+ output.writeStartElement("td");
|
|
237
|
+ output.writeAttribute("style", "border-left: 1px solid #000000");
|
|
238
|
+ if(j > 0) {
|
|
239
|
+ output.writeAttribute("align", "center");
|
|
240
|
+ }
|
|
241
|
+ if(j > 0 && j < annotationRow.length - 1) {
|
|
242
|
+ switch(tempUnit.currentIndex)
|
|
243
|
+ {
|
|
244
|
+ case 0:
|
|
245
|
+ output.writeCharacters(((Number(annotationRow[j].replace(/^\s+|\s+$/g,""))-32)*5/9).toFixed(2));
|
|
246
|
+ break;
|
|
247
|
+ case 1:
|
|
248
|
+ output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
|
|
249
|
+ break;
|
|
250
|
+ }
|
|
251
|
+ }
|
|
252
|
+ else {
|
|
253
|
+ output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
|
|
254
|
+ }
|
|
255
|
+ output.writeEndElement();
|
|
256
|
+ }
|
|
257
|
+ output.writeEndElement();
|
|
258
|
+ }
|
|
259
|
+ output.writeEndElement();
|
|
260
|
+ output.writeEndElement();
|
|
261
|
+ output.writeEndElement();
|
|
262
|
+ output.writeEndElement();
|
|
263
|
+ }
|
|
264
|
+ output.writeEndElement();
|
|
265
|
+ output.writeStartElement("tfoot");
|
|
266
|
+ output.writeStartElement("tr");
|
|
267
|
+ output.writeEmptyElement("td");
|
|
268
|
+ output.writeEmptyElement("td");
|
|
269
|
+ output.writeStartElement("td");
|
|
270
|
+ output.writeTextElement("strong", "Totals:");
|
|
271
|
+ output.writeEndElement();
|
|
272
|
+ q = "SELECT sum(unroasted_total_quantity), sum(roasted_quantity), sum(duration) FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1')";
|
|
273
|
+ query.exec(q);
|
|
274
|
+ query.next();
|
|
275
|
+ switch(unitBox.currentIndex)
|
|
276
|
+ {
|
|
277
|
+ case 0:
|
|
278
|
+ output.writeTextElement("td", (query.value(0)/2.2).toFixed(query.value(0).split('.').length > 1 ? query.value(0).split('.')[1].length : 0));
|
|
279
|
+ break;
|
|
280
|
+ case 1:
|
|
281
|
+ output.writeTextElement("td", query.value(0));
|
|
282
|
+ break;
|
|
283
|
+ }
|
|
284
|
+ output.writeEmptyElement("td");
|
|
285
|
+ switch(unitBox.currentIndex)
|
|
286
|
+ {
|
|
287
|
+ case 0:
|
|
288
|
+ output.writeTextElement("td", (query.value(1)/2.2).toFixed(query.value(1).split('.').length > 1 ? query.value(1).split('.')[1].length : 0));
|
|
289
|
+ break;
|
|
290
|
+ case 1:
|
|
291
|
+ output.writeTextElement("td", query.value(1));
|
|
292
|
+ break;
|
|
293
|
+ }
|
|
294
|
+ output.writeEmptyElement("td");
|
|
295
|
+ output.writeEmptyElement("td");
|
|
296
|
+ output.writeTextElement("td", query.value(2));
|
|
297
|
+ output.writeEndElement();
|
|
298
|
+ output.writeEndElement(); //tfoot
|
|
299
|
+ output.writeEndElement(); //table
|
|
300
|
+ output.writeTextElement("h2", "Inventory");
|
|
301
|
+ output.writeStartElement("table");
|
|
302
|
+ output.writeAttribute("rules", "groups");
|
|
303
|
+ output.writeAttribute("cellpadding", "3px");
|
|
304
|
+ output.writeStartElement("thead");
|
|
305
|
+ output.writeStartElement("tr");
|
|
306
|
+ output.writeTextElement("th", "Green Coffee");
|
|
307
|
+ output.writeTextElement("th", "Starting Inventory");
|
|
308
|
+ output.writeTextElement("th", "Ending Inventory");
|
|
309
|
+ output.writeTextElement("th", "Change");
|
|
310
|
+ output.writeTextElement("th", "Availability");
|
|
311
|
+ output.writeEndElement();
|
|
312
|
+ output.writeEndElement();
|
|
313
|
+ output.writeStartElement("tbody");
|
|
314
|
+ q = "SELECT DISTINCT item, (SELECT name FROM items WHERE id = item) AS name, (SELECT out FROM coffee_history WHERE id = item) FROM all_transactions WHERE time > '" + dateString + "' AND time < '" + dateString + "'::date + integer '1' ORDER BY name ASC";
|
|
315
|
+ query.exec(q)
|
|
316
|
+ var subQuery = new QSqlQuery();
|
|
317
|
+ var qq;
|
|
318
|
+ while(query.next())
|
|
319
|
+ {
|
|
320
|
+ output.writeStartElement("tr");
|
|
321
|
+ output.writeTextElement("td", query.value(1));
|
|
322
|
+ qq = "SELECT balance FROM item_history(" + query.value(0) + ") WHERE time = (SELECT max(time) FROM all_transactions WHERE time < '" + dateString + "' AND item = " + query.value(0) + ") OR time = (SELECT max(time) FROM all_transactions WHERE time < '" + dateString + "'::date + integer '1' AND item = " + query.value(0) + ") ORDER BY time ASC";
|
|
323
|
+ subQuery.exec(qq);
|
|
324
|
+ var startValue = 0;
|
|
325
|
+ var endValue = 0;
|
|
326
|
+ if(subQuery.next())
|
|
327
|
+ {
|
|
328
|
+ switch(unitBox.currentIndex)
|
|
329
|
+ {
|
|
330
|
+ case 0:
|
|
331
|
+ output.writeTextElement("td", (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0));
|
|
332
|
+ break;
|
|
333
|
+ case 1:
|
|
334
|
+ output.writeTextElement("td", subQuery.value(0));
|
|
335
|
+ break;
|
|
336
|
+ }
|
|
337
|
+ startValue = subQuery.value(0);
|
|
338
|
+ }
|
|
339
|
+ else
|
|
340
|
+ {
|
|
341
|
+ output.writeEmptyElement("td");
|
|
342
|
+ }
|
|
343
|
+ if(subQuery.next())
|
|
344
|
+ {
|
|
345
|
+ switch(unitBox.currentIndex)
|
|
346
|
+ {
|
|
347
|
+ case 0:
|
|
348
|
+ output.writeTextElement("td", (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0));
|
|
349
|
+ break;
|
|
350
|
+ case 1:
|
|
351
|
+ output.writeTextElement("td", subQuery.value(0));
|
|
352
|
+ break;
|
|
353
|
+ }
|
|
354
|
+ endValue = subQuery.value(0);
|
|
355
|
+ }
|
|
356
|
+ else
|
|
357
|
+ {
|
|
358
|
+ output.writeEmptyElement("td");
|
|
359
|
+ }
|
|
360
|
+ var startPrec = startValue.split('.').length > 1 ? startValue.split('.')[1].length : 0;
|
|
361
|
+ var endPrec = endValue.split('.').length > 1 ? endValue.split('.')[1].length : 0;
|
|
362
|
+ switch(unitBox.currentIndex)
|
|
363
|
+ {
|
|
364
|
+ case 0:
|
|
365
|
+ output.writeTextElement("td", (Number(endValue/2.2) - Number(startValue/2.2)).toFixed(Math.max(startPrec, endPrec)));
|
|
366
|
+ break;
|
|
367
|
+ case 1:
|
|
368
|
+ output.writeTextElement("td", (Number(endValue) - Number(startValue)).toFixed(Math.max(startPrec, endPrec)));
|
|
369
|
+ break;
|
|
370
|
+ }
|
|
371
|
+ output.writeTextElement("td", query.value(2));
|
|
372
|
+ output.writeEndElement();
|
|
373
|
+ }
|
|
374
|
+ output.writeEndElement();
|
|
375
|
+ output.writeStartElement("tfoot");
|
|
376
|
+
|
|
377
|
+ output.writeEndElement();
|
|
378
|
+ output.writeEndElement();//End of inventory table
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+ output.writeEndElement();
|
|
382
|
+ output.writeEndElement();
|
|
383
|
+ output.writeEndDocument();
|
|
384
|
+ view.setContent(buffer);
|
|
385
|
+ buffer.close();
|
|
386
|
+ }
|
|
387
|
+ refresh();
|
|
388
|
+ dateField.dateChanged.connect(function() {
|
|
389
|
+ refresh();
|
|
390
|
+ });
|
|
391
|
+ ]]>
|
|
392
|
+ </program>
|
|
393
|
+</window>
|