Browse Source

Generalize recent average production report.

Neal Wilson 9 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
 <window id="productionreport">
1
 <window id="productionreport">
2
-	<reporttitle>Production:->Recent Average Weekly Coffee Production</reporttitle>
2
+	<reporttitle>Production:->Recent Average Coffee Production</reporttitle>
3
     <layout type="vertical">
3
     <layout type="vertical">
4
         <layout type="horizontal">
4
         <layout type="horizontal">
5
             <label>Sort Order:</label>
5
             <label>Sort Order:</label>
6
             <sqldrop id="sort" />
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
             <stretch />
15
             <stretch />
10
         </layout>
16
         </layout>
11
         <webview id="report" />
17
         <webview id="report" />
27
             sortBox.addItem("Weekly Use Ascending");
33
             sortBox.addItem("Weekly Use Ascending");
28
             sortBox.addItem("Weekly Use Descending");
34
             sortBox.addItem("Weekly Use Descending");
29
             sortBox.currentIndex = QSettings.value("rwacp_sort", 3);
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
             function refresh() {
68
             function refresh() {
35
                 var buffer = new QBuffer;
69
                 var buffer = new QBuffer;
36
                 buffer.open(3);
70
                 buffer.open(3);
44
                 output.writeEndElement();
78
                 output.writeEndElement();
45
                 output.writeStartElement("body");
79
                 output.writeStartElement("body");
46
                 output.writeTextElement("h1", "Recent Average Weekly Coffee Production");
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
                 output.writeStartElement("table");
90
                 output.writeStartElement("table");
57
                 output.writeAttribute("rules", "groups");
91
                 output.writeAttribute("rules", "groups");
58
                 output.writeAttribute("cellpadding", "3px");
92
                 output.writeAttribute("cellpadding", "3px");
63
                 output.writeEndElement();
97
                 output.writeEndElement();
64
                 output.writeEndElement();
98
                 output.writeEndElement();
65
                 output.writeStartElement("tbody");
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
                 switch(sortBox.currentIndex)
110
                 switch(sortBox.currentIndex)
68
                 {
111
                 {
69
                     case 0:
112
                     case 0:
70
-						q += "name ASC";
113
+                        q += "name ASC";
71
                         break;
114
                         break;
72
                     case 1:
115
                     case 1:
73
-						q += "name DESC";
74
-						break;
116
+                        q += "name DESC";
117
+                        break;
75
                     case 2:
118
                     case 2:
76
-						q += "weekly ASC";
77
-						break;
119
+                        q += "weekly ASC";
120
+                        break;
78
                     case 3:
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
                 query.exec();
137
                 query.exec();
94
                 while(query.next())
138
                 while(query.next())
95
                 {
139
                 {
101
                 output.writeEndElement();
145
                 output.writeEndElement();
102
                 output.writeStartElement("tfoot")
146
                 output.writeStartElement("tfoot")
103
                 output.writeTextElement("th", "Total");
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
                 switch(unitBox.currentIndex)
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
                 output.writeTextElement("td", query.value(0));
161
                 output.writeTextElement("td", query.value(0));
117
                 query = query.invalidate();
162
                 query = query.invalidate();
118
-				output.writeEndElement();
163
+                output.writeEndElement();
119
                 output.writeEndElement();
164
                 output.writeEndElement();
120
                 output.writeEndElement();
165
                 output.writeEndElement();
121
                 output.writeEndElement();
166
                 output.writeEndElement();

Loading…
Cancel
Save