Просмотр исходного кода

Batch type and approval filtering on batch log

Neal Wilson 9 лет назад
Родитель
Сommit
9e62fc66d9
1 измененных файлов: 84 добавлений и 38 удалений
  1. 84
    38
      config/Windows/history.xml

+ 84
- 38
config/Windows/history.xml Просмотреть файл

@@ -1,47 +1,93 @@
1 1
 <window id="history">
2 2
     <layout type="vertical">
3
-		<layout type="horizontal">
4
-			<daterange id="dates" initial="6" /><!-- Last 7 Days -->
5
-			<stretch />
6
-		</layout>
3
+        <layout type="horizontal">
4
+            <label>Batch Type: </label>
5
+            <sqldrop id="batchtype" />
6
+            <label>Approval: </label>
7
+            <sqldrop id="approval" />
8
+            <daterange id="dates" initial="6" /><!-- Last 7 Days -->
9
+            <stretch />
10
+        </layout>
7 11
         <sqlview id="table" />
8 12
     </layout>
9 13
     <program>
10 14
         <![CDATA[
11
-			var dateSelect = findChildObject(this, 'dates');
12
-			var dateQuery = new QSqlQuery();
13
-			dateQuery.exec("SELECT time::date FROM roasting_log WHERE time = (SELECT min(time) FROM roasting_log) OR time = (SELECT max(time) FROM roasting_log) ORDER BY time ASC");
14
-			dateQuery.next();
15
-			var lifetimeStartDate = dateQuery.value(0);
16
-			var lifetimeEndDate;
17
-			if(dateQuery.next()) {
18
-				lifetimeEndDate = dateQuery.value(0);
19
-			} else {
20
-				lifetimeEndDate = lifetimeStartDate;
21
-			}
22
-			dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
23
-			dateQuery.invalidate();
24
-			dateSelect.currentIndex = QSettings.value("script/history/dateIndex", 6);
25
-			var table = findChildObject(this, 'table');
26
-			table.openEntryRow.connect(function(arg) {
27
-				var details = createWindow("batchDetails");
28
-				details.loadData(table, arg);
29
-			});
30
-			function refresh() {
31
-				var dateRange = dateSelect.currentRange();
32
-				var startDate = "'"+dateRange[0]+"'";
33
-				var endDate = "'"+dateRange[dateRange.length - 1]+"'";
34
-				var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity AS green, roasted_quantity AS roasted, CASE WHEN unroasted_total_quantity = 0 THEN NULL ELSE ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) END AS weight_loss, duration, annotation FROM roasting_log WHERE time >= " + startDate + "::date AND time < " + endDate + "::date + interval '1 day' ORDER BY time DESC";
35
-				table.setQuery(q);
36
-				table.hideColumn(1);
37
-			}
38
-			dateSelect.rangeUpdated.connect(function() {
39
-				if(dateSelect.currentIndex != 24) { // Custom date range
40
-					QSettings.setValue("script/history/dateIndex", dateSelect.currentIndex);
41
-				}
42
-				refresh();
43
-			});
44
-			refresh();
15
+            var dateSelect = findChildObject(this, 'dates');
16
+            var dateQuery = new QSqlQuery();
17
+            dateQuery.exec("SELECT time::date FROM roasting_log WHERE time = (SELECT min(time) FROM roasting_log) OR time = (SELECT max(time) FROM roasting_log) ORDER BY time ASC");
18
+            dateQuery.next();
19
+            var lifetimeStartDate = dateQuery.value(0);
20
+            var lifetimeEndDate;
21
+            if(dateQuery.next()) {
22
+                lifetimeEndDate = dateQuery.value(0);
23
+            } else {
24
+                lifetimeEndDate = lifetimeStartDate;
25
+            }
26
+            dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
27
+            dateQuery.invalidate();
28
+            dateSelect.currentIndex = QSettings.value("script/history/dateIndex", 6);
29
+            var batchType = findChildObject(this, 'batchtype');
30
+            batchType.addItem("Any");
31
+            batchType.addItem("Production Roasts");
32
+            batchType.addItem("SampleRoasts");
33
+            batchType.currentIndex = QSettings.value("script/historybatchtypefilter", 1);
34
+            batchType['currentIndexChanged(int)'].connect(function() {
35
+                QSettings.setValue("script/historybatchtypefilter", batchType.currentIndex);
36
+                refresh();
37
+            });
38
+            var approval = findChildObject(this, 'approval');
39
+            approval.addItem("Any");
40
+            approval.addItem("Approved");
41
+            approval.addItem("Not Approved");
42
+            approval.currentIndex = QSettings.value("script/historyapprovalfilter", 1);
43
+            approval['currentIndexChanged(int)'].connect(function() {
44
+                QSettings.setValue("script/historyapprovalfilter", approval.currentIndex);
45
+                refresh();
46
+            });
47
+            var table = findChildObject(this, 'table');
48
+            table.openEntryRow.connect(function(arg) {
49
+                var details = createWindow("batchDetails");
50
+                details.loadData(table, arg);
51
+            });
52
+            function refresh() {
53
+                var transaction_filter;
54
+                var approval_filter;
55
+                switch(batchType.currentIndex) {
56
+                    case 0:
57
+                        transaction_filter = "";
58
+                        break;
59
+                    case 1:
60
+                        transaction_filter = " AND transaction_type = 'ROAST'";
61
+                        break;
62
+                    case 2:
63
+                        transaction_filter = " AND transaction_type = 'SAMPLEROAST'";
64
+                        break;
65
+                }
66
+                switch(approval.currentIndex) {
67
+                    case 0:
68
+                        approval_filter = "";
69
+                        break;
70
+                    case 1:
71
+                        approval_filter = " AND approval = true";
72
+                        break;
73
+                    case 2:
74
+                        approval_filter = " AND approval = false";
75
+                        break;
76
+                }
77
+                var dateRange = dateSelect.currentRange();
78
+                var startDate = "'"+dateRange[0]+"'";
79
+                var endDate = "'"+dateRange[dateRange.length - 1]+"'";
80
+                var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity AS green, roasted_quantity AS roasted, CASE WHEN unroasted_total_quantity = 0 THEN NULL ELSE ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) END AS weight_loss, duration, annotation FROM roasting_log WHERE time >= " + startDate + "::date AND time < " + endDate + "::date + interval '1 day'" + transaction_filter + approval_filter + " ORDER BY time DESC";
81
+                table.setQuery(q);
82
+                table.hideColumn(1);
83
+            }
84
+            dateSelect.rangeUpdated.connect(function() {
85
+                if(dateSelect.currentIndex != 24) { // Custom date range
86
+                    QSettings.setValue("script/history/dateIndex", dateSelect.currentIndex);
87
+                }
88
+                refresh();
89
+            });
90
+            refresh();
45 91
         ]]>
46 92
     </program>
47 93
 </window>

Загрузка…
Отмена
Сохранить