|
|
|
|
261
|
output.writeEndElement();
|
261
|
output.writeEndElement();
|
262
|
output.writeEndElement();
|
262
|
output.writeEndElement();
|
263
|
}
|
263
|
}
|
264
|
- query = query.invalidate();
|
|
|
265
|
output.writeEndElement();
|
264
|
output.writeEndElement();
|
|
|
265
|
+ output.writeStartElement("tfoot");
|
|
|
266
|
+ output.writeStartElement("tr");
|
|
|
267
|
+ output.writeTextElement("th", "Total Batches");
|
|
|
268
|
+ output.writeTextElement("th", "Total Duration");
|
|
|
269
|
+ output.writeTextElement("th", "Total Green Weight");
|
|
|
270
|
+ output.writeTextElement("th", "Total Roasted Weight");
|
|
|
271
|
+ output.writeEndElement();
|
|
|
272
|
+ output.writeStartElement("tr");
|
|
|
273
|
+ 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) AS uq, (roasted_quantity/:c2)::numeric(12,2) AS rq, 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 count(1), sum(duration), sum(uq), sum(rq) FROM qq" + searchClause;
|
|
|
274
|
+ var query = new QSqlQuery();
|
|
|
275
|
+ query.prepare(q);
|
|
|
276
|
+ query.bind(":c1", conversion);
|
|
|
277
|
+ query.bind(":c2", conversion);
|
|
|
278
|
+ query.bind(":sd", startDate);
|
|
|
279
|
+ query.bind(":ed", endDate);
|
|
|
280
|
+ if(searchClause.length > 0) {
|
|
|
281
|
+ var pattern = ".*" + search.text + ".*";
|
|
|
282
|
+ query.bind(":p1", pattern);
|
|
|
283
|
+ query.bind(":p2", pattern);
|
|
|
284
|
+ query.bind(":p3", pattern);
|
|
|
285
|
+ query.bind(":p4", pattern);
|
|
|
286
|
+ query.bind(":p5", pattern);
|
|
|
287
|
+ query.bind(":p6", pattern);
|
|
|
288
|
+ }
|
|
|
289
|
+ query.exec();
|
|
|
290
|
+ query.next();
|
|
|
291
|
+ for(var i = 0; i < 4; i++) {
|
|
|
292
|
+ output.writeTextElement("td", query.value(i));
|
|
|
293
|
+ }
|
|
|
294
|
+ output.writeEndElement();
|
|
|
295
|
+ output.writeEndElement();
|
|
|
296
|
+ query = query.invalidate();
|
266
|
output.writeEndElement();
|
297
|
output.writeEndElement();
|
267
|
output.writeEndElement();
|
298
|
output.writeEndElement();
|
268
|
output.writeEndDocument();
|
299
|
output.writeEndDocument();
|