Production:->Recent Average Coffee Production Print '); output.writeStartElement("html"); output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml"); output.writeStartElement("head"); output.writeTextElement("title", TTR("productionreport", "Recent Average Coffee Production")); output.writeEndElement(); output.writeStartElement("body"); output.writeTextElement("h1", TTR("productionreport", "Recent Average Coffee Production")); switch(unitBox.currentIndex) { case 0: output.writeTextElement("p", TTR("productionreport", "This is a report of average coffee production per ") + scaleBox.text + TTR("productionreport", " days in kilograms over the past ") + daysBox.text + TTR("productionreport", " days.")); break; case 1: output.writeTextElement("p", TTR("productionreport", "This is a report of average coffee production per ") + scaleBox.text + TTR("productionreport", " days in pounds over the past ") + daysBox.text + TTR("productionreport", " days.")); break; } output.writeStartElement("table"); output.writeAttribute("rules", "groups"); output.writeAttribute("cellpadding", "3px"); output.writeStartElement("thead"); output.writeStartElement("tr"); output.writeTextElement("th", TTR("productionreport", "Roasted Coffee")); output.writeTextElement("th", TTR("productionreport", "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", TTR("productionreport", "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(); }); ]]>