Browse Source

Generalize recent average production report.

Neal Wilson 8 years ago
parent
commit
1a128b21c6
1 changed files with 92 additions and 47 deletions
  1. 92
    47
      config/Reports/rwacp.xml

+ 92
- 47
config/Reports/rwacp.xml View File

@@ -1,11 +1,17 @@
1 1
 <window id="productionreport">
2
-	<reporttitle>Production:->Recent Average Weekly Coffee Production</reporttitle>
2
+	<reporttitle>Production:->Recent Average Coffee Production</reporttitle>
3 3
     <layout type="vertical">
4 4
         <layout type="horizontal">
5 5
             <label>Sort Order:</label>
6 6
             <sqldrop id="sort" />
7
-			<label>Weight Unit:</label>
8
-			<sqldrop id="unit" />
7
+            <label>Weight Unit:</label>
8
+            <sqldrop id="unit" />
9
+            <label>Batch Type: </label>
10
+            <sqldrop id="batchtype" />
11
+            <label>Days to Average: </label>
12
+            <line id="days" />
13
+            <label>Days to Scale: </label>
14
+            <line id="scale" />
9 15
             <stretch />
10 16
         </layout>
11 17
         <webview id="report" />
@@ -27,10 +33,38 @@
27 33
             sortBox.addItem("Weekly Use Ascending");
28 34
             sortBox.addItem("Weekly Use Descending");
29 35
             sortBox.currentIndex = QSettings.value("rwacp_sort", 3);
30
-			var unitBox = findChildObject(this, 'unit');
31
-			unitBox.addItem("Kg");
32
-			unitBox.addItem("Lb");
33
-			unitBox.currentIndex = QSettings.value("script/report_unit", 1);
36
+            var unitBox = findChildObject(this, 'unit');
37
+            unitBox.addItem("Kg");
38
+            unitBox.addItem("Lb");
39
+            unitBox.currentIndex = QSettings.value("script/report_unit", 1);
40
+            var batchType = findChildObject(this, 'batchtype');
41
+            batchType.addItem("Any");
42
+            batchType.addItem("Production Roasts");
43
+            batchType.addItem("Sample Roasts");
44
+            batchType.currentIndex = QSettings.value("script/racpreport/batchtypefilter", 1);
45
+            batchType['currentIndexChanged(int)'].connect(function() {
46
+                QSettings.setValue("script/racpreport/batchtypefilter",
47
+                                   batchType.currentIndex);
48
+                refresh();
49
+            });
50
+            var daysBox = findChildObject(this, 'days');
51
+            daysBox.text = QSettings.value("script/racpreport/days", "28");
52
+            daysBox.editingFinished.connect(function() {
53
+                if(Number(daysBox.text) < 1) {
54
+                    daysBox.text = QSettings.value("script/racpreport/days");
55
+                }
56
+                QSettings.setValue("script/racpreport/days", daysBox.text);
57
+                refresh();
58
+            });
59
+            var scaleBox = findChildObject(this, 'scale');
60
+            scaleBox.text = QSettings.value("script/racpreport/scale", "7");
61
+            scaleBox.editingFinished.connect(function() {
62
+                if(Number(scaleBox.text) < 1) {
63
+                    scaleBox.text = QSettings.value("script/racpreport/scale");
64
+                }
65
+                QSettings.setValue("script/racpreport/scale", scaleBox.text);
66
+                refresh();
67
+            });
34 68
             function refresh() {
35 69
                 var buffer = new QBuffer;
36 70
                 buffer.open(3);
@@ -44,15 +78,15 @@
44 78
                 output.writeEndElement();
45 79
                 output.writeStartElement("body");
46 80
                 output.writeTextElement("h1", "Recent Average Weekly Coffee Production");
47
-				switch(unitBox.currentIndex)
48
-				{
49
-					case 0:
50
-						output.writeTextElement("p", "This is a report of average weekly coffee production in kilograms over the past 28 days.");
51
-						break;
52
-					case 1:
53
-						output.writeTextElement("p", "This is a report of average weekly coffee production in pounds over the past 28 days.");
54
-						break;
55
-				}
81
+                switch(unitBox.currentIndex)
82
+                {
83
+                    case 0:
84
+                        output.writeTextElement("p", "This is a report of average coffee production per " + scaleBox.text + " days in kilograms over the past " + daysBox.text + " days.");
85
+                        break;
86
+                    case 1:
87
+                        output.writeTextElement("p", "This is a report of average coffee production per " + scaleBox.text + " days in pounds over the past " + daysBox.text + " days.");
88
+                        break;
89
+                }
56 90
                 output.writeStartElement("table");
57 91
                 output.writeAttribute("rules", "groups");
58 92
                 output.writeAttribute("cellpadding", "3px");
@@ -63,33 +97,43 @@
63 97
                 output.writeEndElement();
64 98
                 output.writeEndElement();
65 99
                 output.writeStartElement("tbody");
66
-				var q = "SELECT (SELECT name FROM items WHERE id = roasted_id) AS name, ((sum(roasted_quantity) / 4) / :conversion)::numeric(18,2) AS weekly FROM roasting_log WHERE time > current_date - integer '28' AND roasted_quantity > 0 GROUP BY roasted_id ORDER BY "
100
+                var batchClause = "";
101
+                switch(batchType.currentIndex) {
102
+                    case 1:
103
+                        batchClause = " AND transaction_type = 'ROAST'";
104
+                        break;
105
+                    case 2:
106
+                        batchClause = " AND transaction_type = 'SAMPLEROAST'";
107
+                        break;
108
+                }
109
+                var q = "SELECT (SELECT name FROM items WHERE id = roasted_id) AS name, ((sum(roasted_quantity) / :scale) / :conversion)::numeric(18,2) AS weekly FROM roasting_log WHERE time > current_date - integer '" + daysBox.text + "' AND roasted_quantity > 0 " + batchClause + " GROUP BY roasted_id ORDER BY "
67 110
                 switch(sortBox.currentIndex)
68 111
                 {
69 112
                     case 0:
70
-						q += "name ASC";
113
+                        q += "name ASC";
71 114
                         break;
72 115
                     case 1:
73
-						q += "name DESC";
74
-						break;
116
+                        q += "name DESC";
117
+                        break;
75 118
                     case 2:
76
-						q += "weekly ASC";
77
-						break;
119
+                        q += "weekly ASC";
120
+                        break;
78 121
                     case 3:
79
-						q += "weekly DESC";
80
-						break;
122
+                        q += "weekly DESC";
123
+                        break;
81 124
                 }
82
-				var query = new QSqlQuery();
83
-				query.prepare(q);
84
-				switch(unitBox.currentIndex)
85
-				{
86
-					case 0:
87
-						query.bind(":conversion", 2.2);
88
-						break;
89
-					case 1:
90
-						query.bind(":conversion", 1);
91
-						break;
92
-				}
125
+                var query = new QSqlQuery();
126
+                query.prepare(q);
127
+                switch(unitBox.currentIndex)
128
+                {
129
+                    case 0:
130
+                        query.bind(":conversion", 2.2);
131
+                        break;
132
+                    case 1:
133
+                        query.bind(":conversion", 1);
134
+                        break;
135
+                }
136
+                query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
93 137
                 query.exec();
94 138
                 while(query.next())
95 139
                 {
@@ -101,21 +145,22 @@
101 145
                 output.writeEndElement();
102 146
                 output.writeStartElement("tfoot")
103 147
                 output.writeTextElement("th", "Total");
104
-                query.prepare("SELECT (sum(roasted_quantity) / 4 / :conversion)::numeric(18,2) FROM roasting_log WHERE time > current_date - integer '28' AND roasted_quantity > 0");
148
+                query.prepare("SELECT ((sum(roasted_quantity) / :scale) / :conversion)::numeric(18,2) FROM roasting_log WHERE time > current_date - integer '" + daysBox.text + "' AND roasted_quantity > 0 " + batchClause);
105 149
                 switch(unitBox.currentIndex)
106
-				{
107
-					case 0:
108
-						query.bind(":conversion", 2.2);
109
-						break;
110
-					case 1:
111
-						query.bind(":conversion", 1);
112
-						break;
113
-				}
114
-				query.exec();
115
-				query.next();
150
+                {
151
+                    case 0:
152
+                        query.bind(":conversion", 2.2);
153
+                        break;
154
+                    case 1:
155
+                        query.bind(":conversion", 1);
156
+                        break;
157
+                }
158
+                query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
159
+                query.exec();
160
+                query.next();
116 161
                 output.writeTextElement("td", query.value(0));
117 162
                 query = query.invalidate();
118
-				output.writeEndElement();
163
+                output.writeEndElement();
119 164
                 output.writeEndElement();
120 165
                 output.writeEndElement();
121 166
                 output.writeEndElement();

Loading…
Cancel
Save