Browse Source

Batch log displays degree of roast data

Neal Wilson 6 years ago
parent
commit
be0150a9ab
1 changed files with 73 additions and 1 deletions
  1. 73
    1
      config/Reports/historyreport.xml

+ 73
- 1
config/Reports/historyreport.xml View File

@@ -112,7 +112,7 @@
112 112
                 if(search.text.length > 0) {
113 113
                     searchClause = " WHERE (person ~* :p1 OR rname ~* :p2 OR mname ~* :p3 OR greens ~* :p4 OR annotation ~* :p5 OR array_to_string(files, ',') ~* :p6)";
114 114
                 }
115
-                var q = "WITH qq AS (SELECT roasting_log.time, array_to_string(files, ','), person, (SELECT name || ' (' || id || ')' FROM items WHERE id = roasted_id) AS rname, duration, (SELECT name FROM machine WHERE id = machine) AS mname, array_to_string(ARRAY(SELECT name || ' (' || id || ')' FROM items WHERE id IN (SELECT unnest(unroasted_id))), ',') AS greens, (unroasted_total_quantity/:c1)::numeric(12,2), (roasted_quantity/:c2)::numeric(12,2), loss, annotation, approval, spec_loss::numeric(12,2) || '±' || spec_tolerance::numeric(12,2) AS lspec, notes, loss_match, machine || '@' || roasting_log.time AS link, files FROM roasting_log, LATERAL (SELECT CASE WHEN (unroasted_total_quantity = 0) THEN NULL ELSE (((unroasted_total_quantity - roasted_quantity)/unroasted_total_quantity)*100)::numeric(12,2) END AS loss) lc, LATERAL (WITH q AS (SELECT (SELECT min(time) - interval '10 years' FROM roasting_log) AS time, NULL::numeric AS loss, NULL::numeric AS tolerance, NULL::text AS notes) SELECT time, (loss*100)::numeric(12,2) AS spec_loss, (tolerance*100)::numeric(12,2) AS spec_tolerance, 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) UNION (SELECT * FROM q) ORDER BY time DESC LIMIT 1) spec, LATERAL (SELECT loss >= spec_loss - spec_tolerance AND loss <= spec_loss + spec_tolerance AS loss_match) m WHERE roasting_log.time >= :sd AND roasting_log.time < :ed::date + interval '1 day'" + approvalClause + batchClause + ") SELECT * FROM qq" + searchClause + " ORDER BY time DESC";
115
+                var q = "WITH qq AS (SELECT roasting_log.time, array_to_string(files, ','), person, (SELECT name || ' (' || id || ')' FROM items WHERE id = roasted_id) AS rname, duration, (SELECT name FROM machine WHERE id = machine) AS mname, array_to_string(ARRAY(SELECT name || ' (' || id || ')' FROM items WHERE id IN (SELECT unnest(unroasted_id))), ',') AS greens, (unroasted_total_quantity/:c1)::numeric(12,2), (roasted_quantity/:c2)::numeric(12,2), loss, annotation, approval, spec_loss::numeric(12,2) || '±' || spec_tolerance::numeric(12,2) AS lspec, notes, loss_match, machine || '@' || roasting_log.time AS link, files, additional_data, spec FROM roasting_log, LATERAL (SELECT CASE WHEN (unroasted_total_quantity = 0) THEN NULL ELSE (((unroasted_total_quantity - roasted_quantity)/unroasted_total_quantity)*100)::numeric(12,2) END AS loss) lc, LATERAL (WITH q AS (SELECT (SELECT min(time) - interval '10 years' FROM roasting_log) AS time, NULL::numeric AS loss, NULL::numeric AS tolerance, NULL::text AS notes, NULL::jsonb AS spec) SELECT time, (loss*100)::numeric(12,2) AS spec_loss, (tolerance*100)::numeric(12,2) AS spec_tolerance, notes, 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) UNION (SELECT * FROM q) ORDER BY time DESC LIMIT 1) rspec, LATERAL (SELECT loss >= spec_loss - spec_tolerance AND loss <= spec_loss + spec_tolerance AS loss_match) m WHERE roasting_log.time >= :sd AND roasting_log.time < :ed::date + interval '1 day'" + approvalClause + batchClause + ") SELECT * FROM qq" + searchClause + " ORDER BY time DESC";
116 116
                 var query = new QSqlQuery();
117 117
                 query.prepare(q);
118 118
                 query.bind(":c1", conversion);
@@ -171,6 +171,11 @@
171 171
                 output.writeStartElement("tr");
172 172
                 output.writeAttribute("valign", "bottom");
173 173
                 output.writeEmptyElement("td");
174
+                output.writeTextElement("th", TTR("batchreport", "Degree of Roast"));
175
+                output.writeEndElement();
176
+                output.writeStartElement("tr");
177
+                output.writeAttribute("valign", "bottom");
178
+                output.writeEmptyElement("td");
174 179
                 output.writeStartElement("th");
175 180
                 output.writeAttribute("colspan", "2");
176 181
                 output.writeCharacters(TTR("batchreport", "Batch Notes"));
@@ -231,6 +236,73 @@
231 236
                     output.writeStartElement("tr");
232 237
                     output.writeAttribute("valign", "top");
233 238
                     output.writeEmptyElement("td");
239
+                    if(query.value(17).length > 0) {
240
+                        extradata = JSON.parse(query.value(17));
241
+                        wcolor = "#000000";
242
+                        gcolor = "#000000";
243
+                        wtitle = "";
244
+                        gtitle = "";
245
+                        if(query.value(18).length > 0) {
246
+                            specdata = JSON.parse(query.value(18));
247
+                            if(extradata.color.whole && specdata.color.whole.expected) {
248
+                                wmin = Number(specdata.color.whole.expected);
249
+                                wmax = wmin;
250
+                                wtitle += specdata.color.whole.expected;
251
+                                if(specdata.color.whole.tolerance) {
252
+                                    wmin -= Number(specdata.color.whole.tolerance);
253
+                                    wmax += Number(specdata.color.whole.tolerance);
254
+                                    wtitle += "±";
255
+                                    wtitle += specdata.color.whole.tolerance;
256
+                                }
257
+                                if(Number(extradata.color.whole) < wmin || Number(extradata.color.whole) > wmax) {
258
+                                    wcolor = "#FF0000";
259
+                                } else {
260
+                                    wcolor = "#00FF00";
261
+                                }
262
+                            }
263
+                            if(extradata.color.ground && specdata.color.ground.expected) {
264
+                                gmin = Number(specdata.color.ground.expected);
265
+                                gmax = gmin;
266
+                                gtitle += specdata.color.ground.expected;
267
+                                if(specdata.color.ground.tolerance) {
268
+                                    gmin -= Number(specdata.color.ground.tolerance);
269
+                                    gmax += Number(specdata.color.ground.tolerance);
270
+                                    gtitle += "±";
271
+                                    gtitle += specdata.color.ground.tolerance;
272
+                                }
273
+                                if(Number(extradata.color.ground) < gmin || Number(extradata.color.ground) > gmax) {
274
+                                    gcolor = "#FF0000";
275
+                                } else {
276
+                                    gcolor = "#00FF00";
277
+                                }
278
+                            }
279
+                        }
280
+                        if(extradata.color.whole) {
281
+                            output.writeStartElement("span");
282
+                            output.writeAttribute("style", "color:"+wcolor);
283
+                            output.writeAttribute("title", wtitle);
284
+                            output.writeCharacters(extradata.color.whole);
285
+                            output.writeEndElement();
286
+                        }
287
+                        output.writeStartElement("span");
288
+                        if(wcolor === gcolor) {
289
+                            output.writeAttribute("style", "color:"+wcolor);
290
+                        }
291
+                        output.writeCharacters("/");
292
+                        output.writeEndElement();
293
+                        if(extradata.color.ground) {
294
+                            output.writeStartElement("span");
295
+                            output.writeAttribute("style", "color:"+gcolor);
296
+                            output.writeAttribute("title", gtitle);
297
+                            output.writeCharacters(extradata.color.ground);
298
+                            output.writeEndElement();
299
+                        }
300
+                    }
301
+                    output.writeEndElement();
302
+                    output.writeEndElement();
303
+                    output.writeStartElement("tr");
304
+                    output.writeAttribute("valign", "top");
305
+                    output.writeEmptyElement("td");
234 306
                     output.writeStartElement("td");
235 307
                     output.writeAttribute("colspan", "2");
236 308
                     output.writeAttribute("style", "max-width: 400px");

Loading…
Cancel
Save