소스 검색

Batch type and approval filtering in production summary report

Neal Wilson 9 년 전
부모
커밋
31d8bae670
1개의 변경된 파일48개의 추가작업 그리고 2개의 파일을 삭제
  1. 48
    2
      config/Reports/productionsummary.xml

+ 48
- 2
config/Reports/productionsummary.xml 파일 보기

@@ -2,6 +2,10 @@
2 2
     <reporttitle>Production:->Production Summary</reporttitle>
3 3
     <layout type="vertical">
4 4
         <layout type="horizontal">
5
+            <label>Batch Type: </label>
6
+            <sqldrop id="batchtype" />
7
+            <label>Approval: </label>
8
+            <sqldrop id="approval" />
5 9
             <daterange id="dates" initial="9" /><!-- Current Month to Date-->
6 10
             <label>Weight Unit:</label>
7 11
             <sqldrop id="unit" />
@@ -36,6 +40,24 @@
36 40
                 QSettings.setValue("script/report_unit", unitBox.currentIndex);
37 41
                 refresh();
38 42
             });
43
+            var batchType = findChildObject(this, 'batchtype');
44
+            batchType.addItem("Any");
45
+            batchType.addItem("Production Roasts");
46
+            batchType.addItem("SampleRoasts");
47
+            batchType.currentIndex = QSettings.value("script/batchtypefilter", 1);
48
+            batchType['currentIndexChanged(int)'].connect(function() {
49
+                QSettings.setValue("script/batchtypefilter", batchType.currentIndex);
50
+                refresh();
51
+            });
52
+            var approval = findChildObject(this, 'approval');
53
+            approval.addItem("Any");
54
+            approval.addItem("Approved");
55
+            approval.addItem("Not Approved");
56
+            approval.currentIndex = QSettings.value("script/approvalfilter", 1);
57
+            approval['currentIndexChanged(int)'].connect(function() {
58
+                QSettings.setValue("script/approvalfilter", approval.currentIndex);
59
+                refresh();
60
+            });
39 61
             var view = findChildObject(this, 'report');
40 62
             var printMenu = findChildObject(this, 'print');
41 63
             printMenu.triggered.connect(function() {
@@ -63,8 +85,32 @@
63 85
                     conversion = 2.2;
64 86
                     unitText = 'Kg';
65 87
                 }
88
+                var transaction_filter;
89
+                var approval_filter;
90
+                switch(batchType.currentIndex) {
91
+                    case 0:
92
+                        transaction_filter = "";
93
+                        break;
94
+                    case 1:
95
+                        transaction_filter = " AND transaction_type = 'ROAST'";
96
+                        break;
97
+                    case 2:
98
+                        transaction_filter = " AND transaction_type = 'SAMPLEROAST'";
99
+                        break;
100
+                }
101
+                switch(approval.currentIndex) {
102
+                    case 0:
103
+                        approval_filter = "";
104
+                        break;
105
+                    case 1:
106
+                        approval_filter = " AND approval = true";
107
+                        break;
108
+                    case 2:
109
+                        approval_filter = " AND approval = false";
110
+                        break;
111
+                }
66 112
                 var query = new QSqlQuery();
67
-                query.prepare("SELECT count(1), sum(unroasted_total_quantity) / :c1, sum(roasted_quantity) / :c2 FROM roasting_log WHERE time >= :sd AND time < :ed ::date + interval '1 day'");
113
+                query.prepare("SELECT count(1), sum(unroasted_total_quantity) / :c1, sum(roasted_quantity) / :c2 FROM roasting_log WHERE time >= :sd AND time < :ed ::date + interval '1 day'" + transaction_filter + approval_filter);
68 114
                 query.bind(":c1", conversion);
69 115
                 query.bind(":c2", conversion);
70 116
                 query.bind(":sd", startDate);
@@ -75,7 +121,7 @@
75 121
                 var unroastedSum = query.value(1);
76 122
                 var roastedSum = query.value(2);
77 123
                 output.writeTextElement("p", "" + roastedSum + " " + unitText + " roasted from " + unroastedSum + " " + unitText + " green in " + batchesRoasted + " batches.");
78
-                query.prepare("SELECT time::date AS date, count(1), sum(unroasted_total_quantity) / :c1, sum(roasted_quantity) / :c2 FROM roasting_log WHERE time >= :sd AND time < :ed ::date + interval '1 day' GROUP BY date ORDER BY date ASC");
124
+                query.prepare("SELECT time::date AS date, count(1), sum(unroasted_total_quantity) / :c1, sum(roasted_quantity) / :c2 FROM roasting_log WHERE time >= :sd AND time < :ed ::date + interval '1 day'" + transaction_filter + approval_filter + " GROUP BY date ORDER BY date ASC");
79 125
                 query.bind(":c1", conversion);
80 126
                 query.bind(":c2", conversion);
81 127
                 query.bind(":sd", startDate);

Loading…
취소
저장