Browse Source

Unit selection for purchase comparison report. Fixes #3

Neal Wilson 11 years ago
parent
commit
08bb79cd01
1 changed files with 22 additions and 3 deletions
  1. 22
    3
      config/Reports/fypurchase.xml

+ 22
- 3
config/Reports/fypurchase.xml View File

6
 			<calendar id="startdate" />
6
 			<calendar id="startdate" />
7
 			<label>End Date:</label>
7
 			<label>End Date:</label>
8
 			<calendar id="enddate" />
8
 			<calendar id="enddate" />
9
+			<label>Weight Unit:</label>
10
+			<sqldrop id="unit" />
9
 			<stretch />
11
 			<stretch />
10
 		</layout>
12
 		</layout>
11
 		<webview id="report" />
13
 		<webview id="report" />
28
 			printMenu.triggered.connect(function() {
30
 			printMenu.triggered.connect(function() {
29
 				view.print();
31
 				view.print();
30
 			});
32
 			});
33
+			var unitBox = findChildObject(this, 'unit');
34
+			unitBox.addItem("Kg");
35
+			unitBox.addItem("Lb");
36
+			unitBox.currentIndex = QSettings.value("script/report_unit", 1);
37
+			unitBox['currentIndexChanged(int)'].connect(function() {
38
+				QSettings.setValue("script/report_unit", unitBox.currentIndex);
39
+				refresh();
40
+			});
31
 			function refresh() {
41
 			function refresh() {
32
 				var buffer = new QBuffer;
42
 				var buffer = new QBuffer;
33
 				buffer.open(3);
43
 				buffer.open(3);
70
 				}
80
 				}
71
 				output.writeEndElement();
81
 				output.writeEndElement();
72
 				output.writeStartElement("tr");
82
 				output.writeStartElement("tr");
73
-				output.writeTextElement("th", "Pounds Purchased");
83
+				switch(unitBox.currentIndex) {
84
+					case 0:
85
+						output.writeTextElement("th", "Kilos Purchased");
86
+						break;
87
+					case 1:
88
+						output.writeTextElement("th", "Pounds Purchased");
89
+						break;
90
+				}
74
 				j = 0;
91
 				j = 0;
75
 				var pounds = new Array;
92
 				var pounds = new Array;
76
 				for(var i = startDateField.year(); i <= endDateField.year(); i++)
93
 				for(var i = startDateField.year(); i <= endDateField.year(); i++)
77
 				{
94
 				{
78
-					var q = "SELECT sum(quantity) FROM purchase WHERE time >= '" + i + "-01-01' AND time < '" + (i+1) + "-01-01'";
79
-					query.exec(q);
95
+					var q = "SELECT (sum(quantity) / :conversion)::numeric(12,2) FROM purchase WHERE time >= '" + i + "-01-01' AND time < '" + (i+1) + "-01-01'";
96
+					query.prepare(q);
97
+					query.bind(":conversion", unitBox.currentIndex == 0 ? 2.2 : 1);
98
+					query.exec();
80
 					query.next();
99
 					query.next();
81
 					output.writeTextElement("td", query.value(0));
100
 					output.writeTextElement("td", query.value(0));
82
 					pounds[j] = query.value(0);
101
 					pounds[j] = query.value(0);

Loading…
Cancel
Save