Browse Source

Add color to daily production detail report

Neal Wilson 6 years ago
parent
commit
661f71b4a4
1 changed files with 131 additions and 45 deletions
  1. 131
    45
      config/Reports/dailyproductiondetail.xml

+ 131
- 45
config/Reports/dailyproductiondetail.xml View File

@@ -58,7 +58,7 @@
58 58
 				output.writeTextElement("h1", TTR("dailyproduction", "Daily Production Report: ") + dateString);
59 59
 				output.writeTextElement("h2", TTR("dailyproduction", "Batches Roasted"));
60 60
 				var query = new QSqlQuery();
61
-				var q = "SELECT time, machine, (SELECT name FROM machine WHERE id = machine), (SELECT name FROM items WHERE id = roasted_id), unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, annotation, duration, files, (SELECT loss FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), (SELECT tolerance FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), (SELECT notes FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), approval, machine || '@' || time AS link FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1') ORDER BY time";
61
+				var q = "SELECT time, machine, (SELECT name FROM machine WHERE id = machine), (SELECT name FROM items WHERE id = roasted_id), unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, annotation, duration, files, (SELECT loss FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), (SELECT tolerance FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), (SELECT notes FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), approval, machine || '@' || time AS link, additional_data, (SELECT spec FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)) FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1') ORDER BY time";
62 62
 				query.exec(q);
63 63
 				var times = new Array();
64 64
 				var machines = new Array();
@@ -94,9 +94,20 @@
94 94
 				output.writeTextElement("th", TTR("dailyproduction", "% Weight Loss"));
95 95
 				output.writeTextElement("th", TTR("dailyproduction", "Duration"));
96 96
 				output.writeEndElement();
97
+                output.writeStartElement("tr");
98
+                output.writeAttribute("valign", "bottom");
99
+                output.writeEmptyElement("td");
100
+                output.writeEmptyElement("td");
101
+                output.writeEmptyElement("td");
102
+                output.writeEmptyElement("td");
103
+                output.writeEmptyElement("td");
104
+                output.writeEmptyElement("td");
105
+                output.writeEmptyElement("td");
106
+                output.writeTextElement("th", TTR("dailyproduction", "Degree of Roast"));
107
+                output.writeEndElement();
97 108
 				output.writeEndElement();
98 109
 				output.writeStartElement("tbody");
99
-                                output.writeAttribute("valign", "top");
110
+                output.writeAttribute("valign", "top");
100 111
 				while(query.next())
101 112
 				{
102 113
 					times.push(query.value(0));
@@ -168,63 +179,138 @@
168 179
 							output.writeCDATA(query.value(8));
169 180
 							break;
170 181
 					}
171
-                                        output.writeStartElement("td");
172
-                                        output.writeStartElement("span");
173
-                                        if(query.value(15) == "false") {
174
-                                            output.writeAttribute("style", "color:#FF0000");
175
-                                        }
176
-                                        output.writeCharacters(query.value(3) + " (" + query.value(7) + ")");
177
-                                        output.writeEndElement();
178
-                                        output.writeEndElement();
182
+                    output.writeStartElement("td");
183
+                    output.writeStartElement("span");
184
+                    if(query.value(15) == "false") {
185
+                        output.writeAttribute("style", "color:#FF0000");
186
+                    }
187
+                    output.writeCharacters(query.value(3) + " (" + query.value(7) + ")");
188
+                    output.writeEndElement();
189
+                    output.writeEndElement();
179 190
 					if(Number(query.value(6)) > 0) {
180 191
 						var loss = (Number(query.value(6)) - Number(query.value(8)))/Number(query.value(6));
181
-                                                var lossMin;
182
-                                                var lossMax;
183
-                                                var lossColor;
184
-                                                var useLoss;
185
-                                                if(query.value(12) > 0) {
186
-                                                    useLoss = true;
187
-                                                    lossMin = Number(query.value(12)) - Number(query.value(13));
188
-                                                    lossMax = Number(query.value(12)) + Number(query.value(13));
189
-                                                    if(loss >= lossMin && loss <= lossMax) {
190
-                                                        lossColor = '#00FF00';
191
-                                                    } else {
192
-                                                        lossColor = '#FF0000';
193
-                                                    }
194
-                                                } else {
195
-                                                    lossColor = '#000000';
196
-                                                    useLoss = false;
197
-                                                }
192
+                        var lossMin;
193
+                        var lossMax;
194
+                        var lossColor;
195
+                        var useLoss;
196
+                        if(query.value(12) > 0) {
197
+                            useLoss = true;
198
+                            lossMin = Number(query.value(12)) - Number(query.value(13));
199
+                            lossMax = Number(query.value(12)) + Number(query.value(13));
200
+                            if(loss >= lossMin && loss <= lossMax) {
201
+                                lossColor = '#00FF00';
202
+                            } else {
203
+                                lossColor = '#FF0000';
204
+                            }
205
+                        } else {
206
+                            lossColor = '#000000';
207
+                            useLoss = false;
208
+                        }
198 209
 						loss *= 100;
199
-                                                var lossSpec = Number(query.value(12)) * 100;
200
-                                                var lossTol = Number(query.value(13)) * 100;
201
-                                                output.writeStartElement("td");
202
-                                                output.writeStartElement("span");
203
-                                                output.writeAttribute("style", "color:"+lossColor);
204
-                                                if(useLoss) {
205
-                                                    output.writeAttribute("title", lossSpec.toFixed(2) + "+/-" + lossTol.toFixed(2) + "%");
206
-                                                }
207
-                                                output.writeCharacters(loss.toFixed(2) + "%");
208
-                                                output.writeEndElement();
209
-                                                output.writeEndElement();
210
+                        var lossSpec = Number(query.value(12)) * 100;
211
+                        var lossTol = Number(query.value(13)) * 100;
212
+                        output.writeStartElement("td");
213
+                        output.writeStartElement("span");
214
+                        output.writeAttribute("style", "color:"+lossColor);
215
+                        if(useLoss) {
216
+                            output.writeAttribute("title", lossSpec.toFixed(2) + "+/-" + lossTol.toFixed(2) + "%");
217
+                        }
218
+                        output.writeCharacters(loss.toFixed(2) + "%");
219
+                        output.writeEndElement();
220
+                        output.writeEndElement();
210 221
 					} else {
211 222
 						output.writeTextElement("td", "Undefined");
212 223
 					}
213 224
 					output.writeTextElement("td", query.value(10));
214 225
 					output.writeEndElement();
226
+                    if(query.value(17).length > 0) {
227
+                        extradata = JSON.parse(query.value(17));
228
+                        if(extradata.color) {
229
+                            wcolor = "#000000";
230
+                            gcolor = "#000000";
231
+                            wtitle = "";
232
+                            gtitle = "";
233
+                            output.writeStartElement("tr");
234
+                            output.writeEmptyElement("td");
235
+                            output.writeEmptyElement("td");
236
+                            output.writeEmptyElement("td");
237
+                            output.writeEmptyElement("td");
238
+                            output.writeEmptyElement("td");
239
+                            output.writeEmptyElement("td");
240
+                            output.writeEmptyElement("td");
241
+                            if(query.value(18).length > 0) {
242
+                                specdata = JSON.parse(query.value(18));
243
+                                if(extradata.color.whole && specdata.color.whole.expected) {
244
+                                    wmin = Number(specdata.color.whole.expected);
245
+                                    wmax = wmin;
246
+                                    wtitle += specdata.color.whole.expected;
247
+                                    if(specdata.color.whole.tolerance) {
248
+                                        wmin -= Number(specdata.color.whole.tolerance);
249
+                                        wmax += Number(specdata.color.whole.tolerance);
250
+                                        wtitle += "±";
251
+                                        wtitle += specdata.color.whole.tolerance;
252
+                                    }
253
+                                    if(Number(extradata.color.whole) < wmin || Number(extradata.color.whole) > wmax) {
254
+                                        wcolor = "#FF0000";
255
+                                    } else {
256
+                                        wcolor = "#00FF00";
257
+                                    }
258
+                                }
259
+                                if(extradata.color.ground && specdata.color.ground.expected) {
260
+                                    gmin = Number(specdata.color.ground.expected);
261
+                                    gmax = gmin;
262
+                                    gtitle += specdata.color.ground.expected;
263
+                                    if(specdata.color.ground.tolerance) {
264
+                                        gmin -= Number(specdata.color.ground.tolerance);
265
+                                        gmax += Number(specdata.color.ground.tolerance);
266
+                                        gtitle += "±";
267
+                                        gtitle += specdata.color.ground.tolerance;
268
+                                    }
269
+                                    if(Number(extradata.color.ground) < gmin || Number(extradata.color.ground) > gmax) {
270
+                                        gcolor = "#FF0000";
271
+                                    } else {
272
+                                        gcolor = "#00FF00";
273
+                                    }
274
+                                }
275
+                            }
276
+                            output.writeStartElement("td");
277
+                            if(extradata.color.whole) {
278
+                                output.writeStartElement("span");
279
+                                output.writeAttribute("style", "color:"+wcolor);
280
+                                output.writeAttribute("title", wtitle);
281
+                                output.writeCharacters(extradata.color.whole);
282
+                                output.writeEndElement();
283
+                            }
284
+                            output.writeStartElement("span");
285
+                            if(wcolor === gcolor) {
286
+                                output.writeAttribute("style", "color:"+wcolor);
287
+                            }
288
+                            output.writeCharacters("/");
289
+                            output.writeEndElement();
290
+                            if(extradata.color.ground) {
291
+                                output.writeStartElement("span");
292
+                                output.writeAttribute("style", "color:"+gcolor);
293
+                                output.writeAttribute("title", gtitle);
294
+                                output.writeCharacters(extradata.color.ground);
295
+                                output.writeEndElement();
296
+                            }
297
+                            output.writeEndElement();
298
+                            output.writeEndElement();
299
+                        }
300
+                    }
215 301
 					if(query.value(9) != "")
216 302
 					{
217 303
 						output.writeStartElement("tr");
218 304
 						output.writeEmptyElement("td");
219 305
 						output.writeStartElement("td");
220 306
 						output.writeAttribute("colspan", "8");
221
-                                                var noteArray = query.value(9).split("\n");
222
-                                                for(var i = 0; i < noteArray.length; i++) {
223
-                                                    output.writeStartElement("p");
224
-                                                    output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
225
-                                                    output.writeCharacters(noteArray[i]);
226
-                                                    output.writeEndElement();
227
-                                                }
307
+                        var noteArray = query.value(9).split("\n");
308
+                        for(var i = 0; i < noteArray.length; i++) {
309
+                            output.writeStartElement("p");
310
+                            output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
311
+                            output.writeCharacters(noteArray[i]);
312
+                            output.writeEndElement();
313
+                        }
228 314
 						output.writeEndElement();
229 315
 						output.writeEndElement();
230 316
 					}

Loading…
Cancel
Save