123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <window id="dailyproduction">
- <reporttitle>Production:->Production Summary</reporttitle>
- <layout type="vertical">
- <layout type="horizontal">
- <label>Batch Type: </label>
- <sqldrop id="batchtype" />
- <label>Approval: </label>
- <sqldrop id="approval" />
- <daterange id="dates" initial="9" /><!-- Current Month to Date-->
- <label>Weight Unit:</label>
- <sqldrop id="unit" />
- <stretch />
- </layout>
- <webview id="report" />
- </layout>
- <menu name="File">
- <item id="print" shortcut="Ctrl+P">Print</item>
- </menu>
- <menu name="Reports" type="reports" src="Reports" />
- <program>
- <![CDATA[
- this.windowTitle = TTR("dailyproduction", "Typica - Production Summary");
- var dateSelect = findChildObject(this, 'dates');
- var dateQuery = new QSqlQuery();
- dateQuery.exec("SELECT time::date FROM roasting_log WHERE time = (SELECT min(time) FROM roasting_log) OR time = (SELECT max(time) FROM roasting_log) ORDER BY time ASC");
- dateQuery.next();
- var lifetimeStartDate = dateQuery.value(0);
- var lifetimeEndDate;
- if(dateQuery.next()) {
- lifetimeEndDate = dateQuery.value(0);
- } else {
- lifetimeEndDate = lifetimeStartDate;
- }
- dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
- dateQuery = dateQuery.invalidate();
- var unitBox = findChildObject(this, 'unit');
- unitBox.addItem(TTR("dailyproduction", "Kg"));
- unitBox.addItem(TTR("dailyproduction", "Lb"));
- unitBox.currentIndex = QSettings.value("script/report_unit", 1);
- unitBox['currentIndexChanged(int)'].connect(function() {
- QSettings.setValue("script/report_unit", unitBox.currentIndex);
- refresh();
- });
- var batchType = findChildObject(this, 'batchtype');
- batchType.addItem(TTR("dailyproduction", "Any"));
- batchType.addItem(TTR("dailyproduction", "Production Roasts"));
- batchType.addItem(TTR("dailyproduction", "Sample Roasts"));
- batchType.currentIndex = QSettings.value("script/batchtypefilter", 1);
- batchType['currentIndexChanged(int)'].connect(function() {
- QSettings.setValue("script/batchtypefilter", batchType.currentIndex);
- refresh();
- });
- var approval = findChildObject(this, 'approval');
- approval.addItem(TTR("dailyproduction", "Any"));
- approval.addItem(TTR("dailyproduction", "Approved"));
- approval.addItem(TTR("dailyproduction", "Not Approved"));
- approval.currentIndex = QSettings.value("script/approvalfilter", 1);
- approval['currentIndexChanged(int)'].connect(function() {
- QSettings.setValue("script/approvalfilter", approval.currentIndex);
- refresh();
- });
- var view = findChildObject(this, 'report');
- var printMenu = findChildObject(this, 'print');
- printMenu.triggered.connect(function() {
- view.print();
- });
- function refresh() {
- var buffer = new QBuffer;
- buffer.open(3);
- var output = new XmlWriter(buffer);
- output.writeStartDocument("1.0");
- output.writeDTD('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg.dtd">');
- output.writeStartElement("html");
- output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
- output.writeStartElement("head");
- output.writeTextElement("title", TTR("dailyproduction", "Production Summary"));
- output.writeEndElement();
- output.writeStartElement("body");
- var cdt = new Date(Date.now());
- output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
- var dateRange = dateSelect.currentRange();
- var startDate = dateRange[0];
- var endDate = dateRange[dateRange.length - 1];
- output.writeTextElement("h1", TTR("dailyproduction", "Production Summary: ") + startDate + " - " + endDate);
- var conversion = 1;
- var unitText = TTR("dailyproduction", "Lb");
- if(unitBox.currentIndex == 0) {
- conversion = 2.2;
- unitText = TTR("dailyproduction", "Kg");
- }
- var transaction_filter;
- var approval_filter;
- switch(batchType.currentIndex) {
- case 0:
- transaction_filter = "";
- break;
- case 1:
- transaction_filter = " AND transaction_type = 'ROAST'";
- break;
- case 2:
- transaction_filter = " AND transaction_type = 'SAMPLEROAST'";
- break;
- }
- switch(approval.currentIndex) {
- case 0:
- approval_filter = "";
- break;
- case 1:
- approval_filter = " AND approval = true";
- break;
- case 2:
- approval_filter = " AND approval = false";
- break;
- }
- 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'" + transaction_filter + approval_filter);
- 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 + TTR("dailyproduction", " roasted from ") +
- unroastedSum + " " + unitText + TTR("dailyproduction", " green in ") +
- batchesRoasted + TTR("dailyproduction", " 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'" + transaction_filter + approval_filter + " 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", TTR("dailyproduction", "Date"));
- output.writeTextElement("th", TTR("dailyproduction", "Batches"));
- output.writeTextElement("th", TTR("dailyproduction", "Unroasted (") + unitText + ")");
- output.writeTextElement("th", TTR("dailyproduction", "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", TTR("dailyproduction", "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);
- var notifier = Application.subscribe("roastinglogchange");
- notifier.notify.connect(function() {
- 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]);
- });
- ]]>
- </program>
- </window>
|