123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <window id="productionreport">
- <reporttitle>Production:->Recent Average Coffee Production</reporttitle>
- <layout type="vertical">
- <layout type="horizontal">
- <label>Sort Order:</label>
- <sqldrop id="sort" />
- <label>Weight Unit:</label>
- <sqldrop id="unit" />
- <label>Batch Type: </label>
- <sqldrop id="batchtype" />
- <label>Days to Average: </label>
- <line id="days" />
- <label>Days to Scale: </label>
- <line id="scale" />
- <stretch />
- </layout>
- <webview id="report" />
- </layout>
- <menu name="File">
- <item id="print" shortcut="Ctrl+P">Print</item>
- </menu>
- <program>
- <![CDATA[
- this.windowTitle = "Typica - Recent Average Coffee Production";
- var report = findChildObject(this, 'report');
- var printMenu = findChildObject(this, 'print');
- printMenu.triggered.connect(function() {
- report.print();
- });
- var sortBox = findChildObject(this, 'sort');
- sortBox.addItem("Roasted Coffee A-Z");
- sortBox.addItem("Roasted Coffee Z-A");
- sortBox.addItem("Weekly Use Ascending");
- sortBox.addItem("Weekly Use Descending");
- sortBox.currentIndex = QSettings.value("rwacp_sort", 3);
- var unitBox = findChildObject(this, 'unit');
- unitBox.addItem("Kg");
- unitBox.addItem("Lb");
- unitBox.currentIndex = QSettings.value("script/report_unit", 1);
- var batchType = findChildObject(this, 'batchtype');
- batchType.addItem("Any");
- batchType.addItem("Production Roasts");
- batchType.addItem("Sample Roasts");
- batchType.currentIndex = QSettings.value("script/racpreport/batchtypefilter", 1);
- batchType['currentIndexChanged(int)'].connect(function() {
- QSettings.setValue("script/racpreport/batchtypefilter",
- batchType.currentIndex);
- refresh();
- });
- var daysBox = findChildObject(this, 'days');
- daysBox.text = QSettings.value("script/racpreport/days", "28");
- daysBox.editingFinished.connect(function() {
- if(Number(daysBox.text) < 1) {
- daysBox.text = QSettings.value("script/racpreport/days");
- }
- QSettings.setValue("script/racpreport/days", daysBox.text);
- refresh();
- });
- var scaleBox = findChildObject(this, 'scale');
- scaleBox.text = QSettings.value("script/racpreport/scale", "7");
- scaleBox.editingFinished.connect(function() {
- if(Number(scaleBox.text) < 1) {
- scaleBox.text = QSettings.value("script/racpreport/scale");
- }
- QSettings.setValue("script/racpreport/scale", scaleBox.text);
- refresh();
- });
- 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", "Recent Average Coffee Production");
- output.writeEndElement();
- output.writeStartElement("body");
- output.writeTextElement("h1", "Recent Average Coffee Production");
- switch(unitBox.currentIndex)
- {
- case 0:
- output.writeTextElement("p", "This is a report of average coffee production per " + scaleBox.text + " days in kilograms over the past " + daysBox.text + " days.");
- break;
- case 1:
- output.writeTextElement("p", "This is a report of average coffee production per " + scaleBox.text + " days in pounds over the past " + daysBox.text + " days.");
- break;
- }
- output.writeStartElement("table");
- output.writeAttribute("rules", "groups");
- output.writeAttribute("cellpadding", "3px");
- output.writeStartElement("thead");
- output.writeStartElement("tr");
- output.writeTextElement("th", "Roasted Coffee");
- output.writeTextElement("th", "Weekly Use");
- output.writeEndElement();
- output.writeEndElement();
- output.writeStartElement("tbody");
- var batchClause = "";
- switch(batchType.currentIndex) {
- case 1:
- batchClause = " AND transaction_type = 'ROAST'";
- break;
- case 2:
- batchClause = " AND transaction_type = 'SAMPLEROAST'";
- break;
- }
- var q = "SELECT (SELECT name FROM items WHERE id = roasted_id) AS name, ((sum(roasted_quantity) / :scale) / :conversion)::numeric(18,2) AS weekly FROM roasting_log WHERE time > current_date - integer '" + daysBox.text + "' AND roasted_quantity > 0 " + batchClause + " GROUP BY roasted_id ORDER BY "
- switch(sortBox.currentIndex)
- {
- case 0:
- q += "name ASC";
- break;
- case 1:
- q += "name DESC";
- break;
- case 2:
- q += "weekly ASC";
- break;
- case 3:
- q += "weekly DESC";
- break;
- }
- var query = new QSqlQuery();
- query.prepare(q);
- switch(unitBox.currentIndex)
- {
- case 0:
- query.bind(":conversion", 2.2);
- break;
- case 1:
- query.bind(":conversion", 1);
- break;
- }
- query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
- query.exec();
- while(query.next())
- {
- output.writeStartElement("tr");
- output.writeTextElement("td", query.value(0));
- output.writeTextElement("td", query.value(1));
- output.writeEndElement();
- }
- output.writeEndElement();
- output.writeStartElement("tfoot")
- output.writeTextElement("th", "Total");
- query.prepare("SELECT ((sum(roasted_quantity) / :scale) / :conversion)::numeric(18,2) FROM roasting_log WHERE time > current_date - integer '" + daysBox.text + "' AND roasted_quantity > 0 " + batchClause);
- switch(unitBox.currentIndex)
- {
- case 0:
- query.bind(":conversion", 2.2);
- break;
- case 1:
- query.bind(":conversion", 1);
- break;
- }
- query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
- query.exec();
- query.next();
- output.writeTextElement("td", query.value(0));
- query = query.invalidate();
- output.writeEndElement();
- output.writeEndElement();
- output.writeEndElement();
- output.writeEndElement();
- output.writeEndDocument();
- report.setContent(buffer);
- buffer.close();
- }
- refresh();
- sortBox['currentIndexChanged(int)'].connect(function() {
- QSettings.setValue("rwacp_sort", sortBox.currentIndex);
- refresh();
- });
- unitBox['currentIndexChanged(int)'].connect(function() {
- QSettings.setValue("script/report_unit", unitBox.currentIndex);
- refresh();
- });
- ]]>
- </program>
- </window>
|