|
@@ -4,6 +4,8 @@
|
4
|
4
|
<layout type="horizontal">
|
5
|
5
|
<label>Sort Order:</label>
|
6
|
6
|
<sqldrop id="sort" />
|
|
7
|
+ <label>Weight Unit:</label>
|
|
8
|
+ <sqldrop id="unit" />
|
7
|
9
|
<stretch />
|
8
|
10
|
</layout>
|
9
|
11
|
<webview id="report" />
|
|
@@ -27,6 +29,14 @@
|
27
|
29
|
sortBox.addItem("Avg. Cost Ascending");
|
28
|
30
|
sortBox.addItem("Avg. Cost Descending");
|
29
|
31
|
sortBox.currentIndex = QSettings.value("auco_sort", 0);
|
|
32
|
+ var unitBox = findChildObject(this, 'unit');
|
|
33
|
+ unitBox.addItem("Kg");
|
|
34
|
+ unitBox.addItem("Lb");
|
|
35
|
+ unitBox.currentIndex = QSettings.value("script/report_unit", 1);
|
|
36
|
+ unitBox['currentIndexChanged(int)'].connect(function() {
|
|
37
|
+ QSettings.setValue("script/report_unit", unitBox.currentIndex);
|
|
38
|
+ refresh();
|
|
39
|
+ });
|
30
|
40
|
function refresh() {
|
31
|
41
|
var buffer = new QBuffer;
|
32
|
42
|
buffer.open(3);
|
|
@@ -40,7 +50,15 @@
|
40
|
50
|
output.writeEndElement();
|
41
|
51
|
output.writeStartElement("body");
|
42
|
52
|
output.writeTextElement("h1", "Average Use and Cost by Origin");
|
43
|
|
- output.writeTextElement("p", "This is a report of average rate of use in pounds per day and cost of unroasted coffee.");
|
|
53
|
+ switch(unitBox.currentIndex)
|
|
54
|
+ {
|
|
55
|
+ case 0:
|
|
56
|
+ output.writeTextElement("p", "This is a report of average rate of use in kilograms per day and cost of unroasted coffee.");
|
|
57
|
+ break;
|
|
58
|
+ case 1:
|
|
59
|
+ output.writeTextElement("p", "This is a report of average rate of use in pounds per day and cost of unroasted coffee.");
|
|
60
|
+ break;
|
|
61
|
+ }
|
44
|
62
|
output.writeStartElement("table");
|
45
|
63
|
output.writeAttribute("rules", "groups");
|
46
|
64
|
output.writeAttribute("cellpadding", "3px");
|
|
@@ -59,27 +77,34 @@
|
59
|
77
|
output.writeEndElement();
|
60
|
78
|
output.writeStartElement("tbody");
|
61
|
79
|
var query = new QSqlQuery();
|
|
80
|
+ var conversion = 1;
|
|
81
|
+ if(unitBox.currentIndex == 0) {
|
|
82
|
+ conversion = 2.2;
|
|
83
|
+ }
|
62
|
84
|
switch(sortBox.currentIndex)
|
63
|
85
|
{
|
64
|
86
|
case 0:
|
65
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY origin ASC");
|
|
87
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY origin ASC");
|
66
|
88
|
break;
|
67
|
89
|
case 1:
|
68
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY origin DESC");
|
|
90
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY origin DESC");
|
69
|
91
|
break;
|
70
|
92
|
case 2:
|
71
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY rate ASC");
|
|
93
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY rate ASC");
|
72
|
94
|
break;
|
73
|
95
|
case 3:
|
74
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY rate DESC");
|
|
96
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY rate DESC");
|
75
|
97
|
break;
|
76
|
98
|
case 4:
|
77
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY cost ASC");
|
|
99
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY cost ASC");
|
78
|
100
|
break;
|
79
|
101
|
case 5:
|
80
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY cost DESC");
|
|
102
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY cost DESC");
|
81
|
103
|
break;
|
82
|
104
|
}
|
|
105
|
+ query.bind(":conversion", conversion);
|
|
106
|
+ query.bind(":conversion2", conversion);
|
|
107
|
+ query.exec();
|
83
|
108
|
while(query.next())
|
84
|
109
|
{
|
85
|
110
|
output.writeStartElement("tr");
|
|
@@ -97,24 +122,27 @@
|
97
|
122
|
switch(sortBox.currentIndex)
|
98
|
123
|
{
|
99
|
124
|
case 0:
|
100
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY origin ASC");
|
|
125
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY origin ASC");
|
101
|
126
|
break;
|
102
|
127
|
case 1:
|
103
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY origin DESC");
|
|
128
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY origin DESC");
|
104
|
129
|
break;
|
105
|
130
|
case 2:
|
106
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY rate ASC");
|
|
131
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY rate ASC");
|
107
|
132
|
break;
|
108
|
133
|
case 3:
|
109
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY rate DESC");
|
|
134
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY rate DESC");
|
110
|
135
|
break;
|
111
|
136
|
case 4:
|
112
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY cost ASC");
|
|
137
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY cost ASC");
|
113
|
138
|
break;
|
114
|
139
|
case 5:
|
115
|
|
- query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY cost DESC");
|
|
140
|
+ query.prepare("SELECT DISTINCT origin, (avg(rate)/:conversion)::numeric(10,2) AS rate, (SELECT avg(cost)*:conversion2 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY cost DESC");
|
116
|
141
|
break;
|
117
|
142
|
}
|
|
143
|
+ query.bind(":conversion", conversion);
|
|
144
|
+ query.bind(":conversion2", conversion);
|
|
145
|
+ query.exec();
|
118
|
146
|
while(query.next())
|
119
|
147
|
{
|
120
|
148
|
output.writeStartElement("tr");
|