Production:->Production Summary
');
output.writeStartElement("html");
output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
output.writeStartElement("head");
output.writeTextElement("title", "Production Summary");
output.writeEndElement();
output.writeStartElement("body");
var dateRange = dateSelect.currentRange();
var startDate = dateRange[0];
var endDate = dateRange[dateRange.length - 1];
output.writeTextElement("h1", "Production Summary: " + startDate + " - " + endDate);
var conversion = 1;
var unitText = 'Lb';
if(unitBox.currentIndex == 0) {
conversion = 2.2;
unitText = 'Kg';
}
var query = new QSqlQuery();
query.prepare("SELECT count(1), sum(unroasted_total_quantity) / :c1, sum(roasted_quantity) / :c2 FROM roasting_log WHERE time >= :sd AND time < :ed ::date + interval '1 day'");
query.bind(":c1", conversion);
query.bind(":c2", conversion);
query.bind(":sd", startDate);
query.bind(":ed", endDate);
query.exec();
query.next();
var batchesRoasted = query.value(0);
var unroastedSum = query.value(1);
var roastedSum = query.value(2);
output.writeTextElement("p", "" + roastedSum + " " + unitText + " roasted from " + unroastedSum + " " + unitText + " green in " + batchesRoasted + " batches.");
query.prepare("SELECT time::date AS date, count(1), sum(unroasted_total_quantity) / :c1, sum(roasted_quantity) / :c2 FROM roasting_log WHERE time >= :sd AND time < :ed ::date + interval '1 day' GROUP BY date ORDER BY date ASC");
query.bind(":c1", conversion);
query.bind(":c2", conversion);
query.bind(":sd", startDate);
query.bind(":ed", endDate);
query.exec();
output.writeStartElement("table");
output.writeAttribute("rules", "groups");
output.writeAttribute("cellpadding", "3px");
output.writeStartElement("thead");
output.writeStartElement("tr");
output.writeTextElement("th", "Date");
output.writeTextElement("th", "Batches");
output.writeTextElement("th", "Unroasted (" + unitText + ")");
output.writeTextElement("th", "Roasted (" + unitText + ")");
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tbody");
while(query.next()) {
output.writeStartElement("tr");
output.writeStartElement("td");
output.writeStartElement("a");
output.writeAttribute("href", "typica://script/d" + query.value(0));
output.writeCDATA(query.value(0));
output.writeEndElement();
output.writeEndElement();
output.writeTextElement("td", query.value(1));
output.writeTextElement("td", query.value(2));
output.writeTextElement("td", query.value(3));
output.writeEndElement();
}
output.writeEndElement();
output.writeStartElement("tfoot");
output.writeStartElement("tr");
output.writeStartElement("td");
output.writeTextElement("strong", "Totals:");
output.writeEndElement();
output.writeTextElement("td", batchesRoasted);
output.writeTextElement("td", unroastedSum);
output.writeTextElement("td", roastedSum);
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndDocument();
view.setContent(buffer);
buffer.close();
query = query.invalidate();
}
refresh();
dateSelect.rangeUpdated.connect(refresh);
view.scriptLinkClicked.connect(function(url) {
var arg = url.slice(1, url.length).split("-");
var details = createReport("dailyproductiondetail.xml");
var selector = findChildObject(details, "reportdate");
selector.setDate(arg[0], arg[1], arg[2]);
});
]]>