Browse Source

Batch type and approval filtering in production summary report

Neal Wilson 9 years ago
parent
commit
31d8bae670
1 changed files with 48 additions and 2 deletions
  1. 48
    2
      config/Reports/productionsummary.xml

+ 48
- 2
config/Reports/productionsummary.xml View File

2
     <reporttitle>Production:->Production Summary</reporttitle>
2
     <reporttitle>Production:->Production Summary</reporttitle>
3
     <layout type="vertical">
3
     <layout type="vertical">
4
         <layout type="horizontal">
4
         <layout type="horizontal">
5
+            <label>Batch Type: </label>
6
+            <sqldrop id="batchtype" />
7
+            <label>Approval: </label>
8
+            <sqldrop id="approval" />
5
             <daterange id="dates" initial="9" /><!-- Current Month to Date-->
9
             <daterange id="dates" initial="9" /><!-- Current Month to Date-->
6
             <label>Weight Unit:</label>
10
             <label>Weight Unit:</label>
7
             <sqldrop id="unit" />
11
             <sqldrop id="unit" />
36
                 QSettings.setValue("script/report_unit", unitBox.currentIndex);
40
                 QSettings.setValue("script/report_unit", unitBox.currentIndex);
37
                 refresh();
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
             var view = findChildObject(this, 'report');
61
             var view = findChildObject(this, 'report');
40
             var printMenu = findChildObject(this, 'print');
62
             var printMenu = findChildObject(this, 'print');
41
             printMenu.triggered.connect(function() {
63
             printMenu.triggered.connect(function() {
63
                     conversion = 2.2;
85
                     conversion = 2.2;
64
                     unitText = 'Kg';
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
                 var query = new QSqlQuery();
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
                 query.bind(":c1", conversion);
114
                 query.bind(":c1", conversion);
69
                 query.bind(":c2", conversion);
115
                 query.bind(":c2", conversion);
70
                 query.bind(":sd", startDate);
116
                 query.bind(":sd", startDate);
75
                 var unroastedSum = query.value(1);
121
                 var unroastedSum = query.value(1);
76
                 var roastedSum = query.value(2);
122
                 var roastedSum = query.value(2);
77
                 output.writeTextElement("p", "" + roastedSum + " " + unitText + " roasted from " + unroastedSum + " " + unitText + " green in " + batchesRoasted + " batches.");
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
                 query.bind(":c1", conversion);
125
                 query.bind(":c1", conversion);
80
                 query.bind(":c2", conversion);
126
                 query.bind(":c2", conversion);
81
                 query.bind(":sd", startDate);
127
                 query.bind(":sd", startDate);

Loading…
Cancel
Save