|
|
|
|
8
|
<calendar id="enddate" />
|
8
|
<calendar id="enddate" />
|
9
|
<label>Days to Average</label>
|
9
|
<label>Days to Average</label>
|
10
|
<line validator="integer" id="days">7</line>
|
10
|
<line validator="integer" id="days">7</line>
|
|
|
11
|
+ <label>Weight Unit:</label>
|
|
|
12
|
+ <sqldrop id="unit" />
|
11
|
<stretch />
|
13
|
<stretch />
|
12
|
</layout>
|
14
|
</layout>
|
13
|
<webview id="report" />
|
15
|
<webview id="report" />
|
|
|
|
|
27
|
view.print();
|
29
|
view.print();
|
28
|
});
|
30
|
});
|
29
|
var avgField = findChildObject(this, 'days');
|
31
|
var avgField = findChildObject(this, 'days');
|
|
|
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
|
+ });
|
30
|
function refresh() {
|
39
|
function refresh() {
|
|
|
40
|
+ var conversion = 1;
|
|
|
41
|
+ if(unitBox.currentIndex == 0) {
|
|
|
42
|
+ conversion = 2.2;
|
|
|
43
|
+ }
|
31
|
var buffer = new QBuffer;
|
44
|
var buffer = new QBuffer;
|
32
|
buffer.open(3);
|
45
|
buffer.open(3);
|
33
|
var output = new XmlWriter(buffer);
|
46
|
var output = new XmlWriter(buffer);
|
|
|
|
|
48
|
output.writeStartElement("thead");
|
61
|
output.writeStartElement("thead");
|
49
|
output.writeStartElement("tr");
|
62
|
output.writeStartElement("tr");
|
50
|
output.writeTextElement("th", "Coffee");
|
63
|
output.writeTextElement("th", "Coffee");
|
51
|
- output.writeTextElement("th", "Previous");
|
|
|
52
|
- output.writeTextElement("th", "Current");
|
|
|
53
|
- output.writeTextElement("th", "Change");
|
|
|
|
|
64
|
+ switch(unitBox.currentIndex) {
|
|
|
65
|
+ case 0:
|
|
|
66
|
+ output.writeTextElement("th", "Previous (Kg)");
|
|
|
67
|
+ output.writeTextElement("th", "Current (Kg)");
|
|
|
68
|
+ output.writeTextElement("th", "Change (Kg)");
|
|
|
69
|
+ break;
|
|
|
70
|
+ case 1:
|
|
|
71
|
+ output.writeTextElement("th", "Previous (Lb)");
|
|
|
72
|
+ output.writeTextElement("th", "Current (Lb)");
|
|
|
73
|
+ output.writeTextElement("th", "Change (Lb)");
|
|
|
74
|
+ break;
|
|
|
75
|
+ }
|
54
|
output.writeEndElement();
|
76
|
output.writeEndElement();
|
55
|
output.writeEndElement();
|
77
|
output.writeEndElement();
|
56
|
output.writeStartElement("tbody");
|
78
|
output.writeStartElement("tbody");
|
57
|
var query = new QSqlQuery();
|
79
|
var query = new QSqlQuery();
|
58
|
query.exec("START TRANSACTION");
|
80
|
query.exec("START TRANSACTION");
|
59
|
- print(query.executedQuery());
|
|
|
60
|
var curStartDate = "'"+startDateField.year()+"-"+startDateField.month()+"-"+startDateField.day()+"'";
|
81
|
var curStartDate = "'"+startDateField.year()+"-"+startDateField.month()+"-"+startDateField.day()+"'";
|
61
|
query.exec("SELECT "+curStartDate+"::date - interval '1 year', '"+endDateField.year()+"-"+endDateField.month()+"-"+endDateField.day()+"'::date - interval '1 year' + interval '1 day', '"+endDateField.year()+"-"+endDateField.month()+"-"+endDateField.day()+"'::date + interval '1 day'");
|
82
|
query.exec("SELECT "+curStartDate+"::date - interval '1 year', '"+endDateField.year()+"-"+endDateField.month()+"-"+endDateField.day()+"'::date - interval '1 year' + interval '1 day', '"+endDateField.year()+"-"+endDateField.month()+"-"+endDateField.day()+"'::date + interval '1 day'");
|
62
|
- print(query.executedQuery());
|
|
|
63
|
query.next();
|
83
|
query.next();
|
64
|
var curEndDate = "'"+query.value(2)+"'";
|
84
|
var curEndDate = "'"+query.value(2)+"'";
|
65
|
var prevStartDate = "'"+query.value(0)+"'";
|
85
|
var prevStartDate = "'"+query.value(0)+"'";
|
66
|
var prevEndDate = "'"+query.value(1)+"'";
|
86
|
var prevEndDate = "'"+query.value(1)+"'";
|
67
|
var q = "CREATE TEMPORARY TABLE previous ON COMMIT DROP AS SELECT roasted_id, sum(roasted_quantity) AS p FROM roasting_log WHERE time > "+prevStartDate+" AND time < "+prevEndDate+" AND roasted_id IS NOT NULL GROUP BY roasted_id";
|
87
|
var q = "CREATE TEMPORARY TABLE previous ON COMMIT DROP AS SELECT roasted_id, sum(roasted_quantity) AS p FROM roasting_log WHERE time > "+prevStartDate+" AND time < "+prevEndDate+" AND roasted_id IS NOT NULL GROUP BY roasted_id";
|
68
|
query.exec(q);
|
88
|
query.exec(q);
|
69
|
- print(query.executedQuery());
|
|
|
70
|
q = "CREATE TEMPORARY TABLE current ON COMMIT DROP AS SELECT roasted_id, sum(roasted_quantity) AS c FROM roasting_log WHERE time > "+curStartDate+" AND time < "+curEndDate+" AND roasted_id IS NOT NULL GROUP BY roasted_id";
|
89
|
q = "CREATE TEMPORARY TABLE current ON COMMIT DROP AS SELECT roasted_id, sum(roasted_quantity) AS c FROM roasting_log WHERE time > "+curStartDate+" AND time < "+curEndDate+" AND roasted_id IS NOT NULL GROUP BY roasted_id";
|
71
|
query.exec(q);
|
90
|
query.exec(q);
|
72
|
- print(query.executedQuery());
|
|
|
73
|
query.exec("INSERT INTO previous SELECT roasted_id, 0 FROM current WHERE roasted_id NOT IN (SELECT roasted_id FROM previous)");
|
91
|
query.exec("INSERT INTO previous SELECT roasted_id, 0 FROM current WHERE roasted_id NOT IN (SELECT roasted_id FROM previous)");
|
74
|
- print(query.executedQuery());
|
|
|
75
|
query.exec("INSERT INTO current SELECT roasted_id, 0 FROM previous WHERE roasted_id NOT IN (SELECT roasted_id FROM current)");
|
92
|
query.exec("INSERT INTO current SELECT roasted_id, 0 FROM previous WHERE roasted_id NOT IN (SELECT roasted_id FROM current)");
|
76
|
- print(query.executedQuery());
|
|
|
77
|
query.exec("CREATE TEMPORARY TABLE comp ON COMMIT DROP AS SELECT previous.roasted_id, p, c FROM previous LEFT OUTER JOIN current ON previous.roasted_id = current.roasted_id");
|
93
|
query.exec("CREATE TEMPORARY TABLE comp ON COMMIT DROP AS SELECT previous.roasted_id, p, c FROM previous LEFT OUTER JOIN current ON previous.roasted_id = current.roasted_id");
|
78
|
- print(query.executedQuery());
|
|
|
79
|
query.exec("SELECT (SELECT name FROM items WHERE id = roasted_id) AS name, p, c, (c-p) FROM comp WHERE p > 0 OR c > 0 ORDER BY name");
|
94
|
query.exec("SELECT (SELECT name FROM items WHERE id = roasted_id) AS name, p, c, (c-p) FROM comp WHERE p > 0 OR c > 0 ORDER BY name");
|
80
|
- print(query.executedQuery());
|
|
|
81
|
while(query.next())
|
95
|
while(query.next())
|
82
|
{
|
96
|
{
|
83
|
output.writeStartElement("tr");
|
97
|
output.writeStartElement("tr");
|
84
|
output.writeTextElement("td", query.value(0));
|
98
|
output.writeTextElement("td", query.value(0));
|
85
|
- output.writeTextElement("td", query.value(1));
|
|
|
86
|
- output.writeTextElement("td", query.value(2));
|
|
|
87
|
- output.writeTextElement("td", query.value(3));
|
|
|
|
|
99
|
+ output.writeTextElement("td", query.value(1) / conversion);
|
|
|
100
|
+ output.writeTextElement("td", query.value(2) / conversion);
|
|
|
101
|
+ output.writeTextElement("td", query.value(3) / conversion);
|
88
|
output.writeEndElement();
|
102
|
output.writeEndElement();
|
89
|
}
|
103
|
}
|
90
|
output.writeEndElement();
|
104
|
output.writeEndElement();
|
91
|
output.writeStartElement("tfoot");
|
105
|
output.writeStartElement("tfoot");
|
92
|
output.writeTextElement("th", "Totals");
|
106
|
output.writeTextElement("th", "Totals");
|
93
|
query.exec("SELECT sum(p), sum(c), sum(c-p) FROM comp");
|
107
|
query.exec("SELECT sum(p), sum(c), sum(c-p) FROM comp");
|
94
|
- print(query.executedQuery());
|
|
|
95
|
query.next();
|
108
|
query.next();
|
96
|
- output.writeTextElement("td", query.value(0));
|
|
|
97
|
- output.writeTextElement("td", query.value(1));
|
|
|
98
|
- output.writeTextElement("td", query.value(2));
|
|
|
|
|
109
|
+ output.writeTextElement("td", query.value(0) / conversion);
|
|
|
110
|
+ output.writeTextElement("td", query.value(1) / conversion);
|
|
|
111
|
+ output.writeTextElement("td", query.value(2) / conversion);
|
99
|
output.writeEndElement();
|
112
|
output.writeEndElement();
|
100
|
query.exec("ABORT");
|
113
|
query.exec("ABORT");
|
101
|
- print(query.executedQuery());
|
|
|
102
|
output.writeEndElement();
|
114
|
output.writeEndElement();
|
103
|
output.writeStartElement("svg");
|
115
|
output.writeStartElement("svg");
|
104
|
output.writeAttribute("xmlns", "http://www.w3.org/2000/svg");
|
116
|
output.writeAttribute("xmlns", "http://www.w3.org/2000/svg");
|