Production:->Previous Year Production Comparison By Month
');
output.writeStartElement("html");
output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
output.writeStartElement("head");
output.writeTextElement("title", TTR("pytdprodcomp", "Previous Year Production Comparison By Month"));
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")));
output.writeTextElement("h1", TTR("pytdprodcomp", "Previous Year Production Comparison By Month"));
switch(unitBox.currentIndex)
{
case 0:
output.writeTextElement("p", TTR("pytdprodcomp", "This report compares total roasted coffee production in kilograms with the previous year on a monthly basis."));
break;
case 1:
output.writeTextElement("p", TTR("pytdprodcomp", "This report compares total roasted coffee production in pounds with the previous year on a monthly basis."));
break;
}
output.writeStartElement("table");
output.writeAttribute("style", "page-break-after:auto;");
output.writeAttribute("rules", "groups");
output.writeAttribute("cellpadding", "3px");
output.writeStartElement("thead");
output.writeStartElement("tr");
output.writeTextElement("th", TTR("pytdprodcomp", "Month"));
var query = new QSqlQuery();
query.exec("SELECT EXTRACT(YEAR FROM 'now'::date) AS current_year");
query.next();
var current_year = query.value(0);
output.writeTextElement("th", current_year-1);
output.writeTextElement("th", current_year);
output.writeTextElement("th", "Change");
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tbody");
var month_names = [TTR("pytdprodcomp", "January"),
TTR("pytdprodcomp", "February"),
TTR("pytdprodcomp", "March"),
TTR("pytdprodcomp", "April"),
TTR("pytdprodcomp", "May"),
TTR("pytdprodcomp", "June"),
TTR("pytdprodcomp", "July"),
TTR("pytdprodcomp", "August"),
TTR("pytdprodcomp", "September"),
TTR("pytdprodcomp", "October"),
TTR("pytdprodcomp", "November"),
TTR("pytdprodcomp", "December")];
var current_data = new Array();
var previous_data = new Array();
for(var i = 0; i < 12; i++) {
var q = "SELECT SUM(roasted_quantity) FROM roasting_log WHERE roasted_id IS NOT NULL AND time > '"
q += current_year;
q += "-";
q += 1+i;
q += "-01' AND time < '";
if(i == 11) {
q += 1+current_year;
} else {
q += current_year;
}
q += "-";
if(i == 11) {
q += "01"
} else {
q += 2+i;
}
q += "-01'";
query.exec(q);
query.next();
current_data.push(query.value(0));
}
for(var i = 0; i < 12; i++) {
var q = "SELECT SUM(roasted_quantity) FROM roasting_log WHERE roasted_id IS NOT NULL AND time > '"
q += current_year-1;
q += "-";
q += 1+i;
q += "-01' AND time < '";
if(i == 11) {
q += current_year;
} else {
q += current_year-1;
}
q += "-";
if(i == 11) {
q += "01"
} else {
q += 2+i;
}
q += "-01'";
query.exec(q);
query.next();
previous_data.push(query.value(0));
}
query = query.invalidate();
for(var i = 0; i < 12; i++) {
output.writeStartElement("tr");
output.writeTextElement("td", month_names[i]);
switch(unitBox.currentIndex)
{
case 0:
output.writeTextElement("td", Number(previous_data[i] / 2.2).toFixed(2));
output.writeTextElement("td", Number(current_data[i] / 2.2).toFixed(2));
output.writeTextElement("td", Number((current_data[i] - previous_data[i]) / 2.2).toFixed(2));
break;
case 1:
output.writeTextElement("td", Number(previous_data[i]).toFixed(2));
output.writeTextElement("td", Number(current_data[i]).toFixed(2));
output.writeTextElement("td", Number(current_data[i]-previous_data[i]).toFixed(2));
break;
}
output.writeEndElement();
}
output.writeEndElement();
output.writeStartElement("tfoot");
output.writeTextElement("th", TTR("pytdprodcomp", "Totals"));
var current_total = current_data.reduce(function(a,b) {return Number(a) + Number(b);}, 0);
var previous_total = previous_data.reduce(function(a,b) {return Number(a) + Number(b);}, 0);
switch(unitBox.currentIndex)
{
case 0:
output.writeTextElement("td", (previous_total/2.2).toFixed(2));
output.writeTextElement("td", (current_total/2.2).toFixed(2));
output.writeTextElement("td", ((current_total-previous_total)/2.2).toFixed(2));
break;
case 1:
output.writeTextElement("td", previous_total.toFixed(2));
output.writeTextElement("td", current_total.toFixed(2));
output.writeTextElement("td", (current_total-previous_total).toFixed(2));
break;
}
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndDocument();
view.setContent(buffer);
buffer.close();
}
refresh();
]]>