Преглед на файлове

Unit selection for purchase comparison report. Fixes #3

Neal Wilson преди 11 години
родител
ревизия
08bb79cd01
променени са 1 файла, в които са добавени 22 реда и са изтрити 3 реда
  1. 22
    3
      config/Reports/fypurchase.xml

+ 22
- 3
config/Reports/fypurchase.xml Целия файл

@@ -6,6 +6,8 @@
6 6
 			<calendar id="startdate" />
7 7
 			<label>End Date:</label>
8 8
 			<calendar id="enddate" />
9
+			<label>Weight Unit:</label>
10
+			<sqldrop id="unit" />
9 11
 			<stretch />
10 12
 		</layout>
11 13
 		<webview id="report" />
@@ -28,6 +30,14 @@
28 30
 			printMenu.triggered.connect(function() {
29 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 41
 			function refresh() {
32 42
 				var buffer = new QBuffer;
33 43
 				buffer.open(3);
@@ -70,13 +80,22 @@
70 80
 				}
71 81
 				output.writeEndElement();
72 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 91
 				j = 0;
75 92
 				var pounds = new Array;
76 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 99
 					query.next();
81 100
 					output.writeTextElement("td", query.value(0));
82 101
 					pounds[j] = query.value(0);

Loading…
Отказ
Запис