Browse Source

Selectable weight units on Average Use and Cost by Origin report. Fixes #1

Neal Wilson 11 years ago
parent
commit
bf9dac441e
1 changed files with 41 additions and 13 deletions
  1. 41
    13
      config/Reports/auco.xml

+ 41
- 13
config/Reports/auco.xml View File

4
         <layout type="horizontal">
4
         <layout type="horizontal">
5
             <label>Sort Order:</label>
5
             <label>Sort Order:</label>
6
             <sqldrop id="sort" />
6
             <sqldrop id="sort" />
7
+			<label>Weight Unit:</label>
8
+			<sqldrop id="unit" />
7
             <stretch />
9
             <stretch />
8
         </layout>
10
         </layout>
9
         <webview id="report" />
11
         <webview id="report" />
27
             sortBox.addItem("Avg. Cost Ascending");
29
             sortBox.addItem("Avg. Cost Ascending");
28
             sortBox.addItem("Avg. Cost Descending");
30
             sortBox.addItem("Avg. Cost Descending");
29
             sortBox.currentIndex = QSettings.value("auco_sort", 0);
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
             function refresh() {
40
             function refresh() {
31
                 var buffer = new QBuffer;
41
                 var buffer = new QBuffer;
32
                 buffer.open(3);
42
                 buffer.open(3);
40
                 output.writeEndElement();
50
                 output.writeEndElement();
41
                 output.writeStartElement("body");
51
                 output.writeStartElement("body");
42
                 output.writeTextElement("h1", "Average Use and Cost by Origin");
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
                 output.writeStartElement("table");
62
                 output.writeStartElement("table");
45
                 output.writeAttribute("rules", "groups");
63
                 output.writeAttribute("rules", "groups");
46
                 output.writeAttribute("cellpadding", "3px");
64
                 output.writeAttribute("cellpadding", "3px");
59
                 output.writeEndElement();
77
                 output.writeEndElement();
60
                 output.writeStartElement("tbody");
78
                 output.writeStartElement("tbody");
61
                 var query = new QSqlQuery();
79
                 var query = new QSqlQuery();
80
+				var conversion = 1;
81
+				if(unitBox.currentIndex == 0) {
82
+					conversion = 2.2;
83
+				}
62
                 switch(sortBox.currentIndex)
84
                 switch(sortBox.currentIndex)
63
                 {
85
                 {
64
                     case 0:
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
                         break;
88
                         break;
67
                     case 1:
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
                         break;
91
                         break;
70
                     case 2:
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
                         break;
94
                         break;
73
                     case 3:
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
                         break;
97
                         break;
76
                     case 4:
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
                         break;
100
                         break;
79
                     case 5:
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
                         break;
103
                         break;
82
                 }
104
                 }
105
+				query.bind(":conversion", conversion);
106
+				query.bind(":conversion2", conversion);
107
+				query.exec();
83
                 while(query.next())
108
                 while(query.next())
84
                 {
109
                 {
85
                     output.writeStartElement("tr");
110
                     output.writeStartElement("tr");
97
                 switch(sortBox.currentIndex)
122
                 switch(sortBox.currentIndex)
98
                 {
123
                 {
99
                     case 0:
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
                         break;
126
                         break;
102
                     case 1:
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
                         break;
129
                         break;
105
                     case 2:
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
                         break;
132
                         break;
108
                     case 3:
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
                         break;
135
                         break;
111
                     case 4:
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
                         break;
138
                         break;
114
                     case 5:
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
                         break;
141
                         break;
117
                 }
142
                 }
143
+				query.bind(":conversion", conversion);
144
+				query.bind(":conversion2", conversion);
145
+				query.exec();
118
                 while(query.next())
146
                 while(query.next())
119
                 {
147
                 {
120
                     output.writeStartElement("tr");
148
                     output.writeStartElement("tr");

Loading…
Cancel
Save