Purchase:->Coffee Purchase Previous Years Comparison
');
output.writeStartElement("html");
output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
output.writeStartElement("head");
output.writeTextElement("title", "Coffee Purchase Previous Years Comparison");
output.writeEndElement();
output.writeStartElement("body");
output.writeTextElement("h1", "Coffee Purchase Previous Years Comparison");
output.writeStartElement("table");
output.writeAttribute("style", "page-break-after: auto; text-align: left");
output.writeAttribute("rules", "groups");
output.writeAttribute("cellpadding", "3px");
output.writeStartElement("thead");
output.writeStartElement("tr");
output.writeEmptyElement("th");
output.writeTextElement("th", "Sacks Purchased");
switch(unitBox.currentIndex) {
case 0:
output.writeTextElement("th", "Kilos Purchased");
break;
case 1:
output.writeTextElement("th", "Pounds Purchased");
break;
}
output.writeTextElement("th", "Cost");
output.writeEndElement(); //tr
output.writeEndElement(); //thead
output.writeStartElement("tbody");
var sacktotal = 0;
var unittotal = 0;
var costtotal = 0;
for(var i = startDateField.year(); i <= endDateField.year(); i++)
{
output.writeStartElement("tr");
output.writeAttribute("id", "y"+i);
var q = "SELECT sum(quantity/(SELECT conversion FROM lb_bag_conversion WHERE item = purchase.item)), (sum(quantity) / :conversion)::numeric(12,2), sum(cost*quantity)::numeric(12,2) FROM purchase WHERE time >= '" + i + "-01-01' AND time < '" + (i+1) + "-01-01'";
query.prepare(q);
query.bind(":conversion", unitBox.currentIndex == 0 ? 2.2 : 1);
query.exec();
query.next();
output.writeStartElement("th");
output.writeCharacters(i);
output.writeEndElement(); //th
output.writeTextElement("td", query.value(0));
output.writeTextElement("td", query.value(1));
output.writeTextElement("td", Number(query.value(2)).toFixed(2));
sacktotal += Number(query.value(0));
unittotal += Number(query.value(1));
costtotal += Number(query.value(2));
output.writeEndElement(); //tr
}
output.writeEndElement(); //tbody
output.writeStartElement("tfoot");
output.writeTextElement("th", "Totals:");
output.writeTextElement("td", sacktotal);
output.writeTextElement("td", unittotal.toFixed(2));
output.writeTextElement("td", costtotal.toFixed(2));
output.writeEndElement(); //tfoot
output.writeEndElement(); //table
output.writeEndElement(); //body
output.writeEndElement(); //html
output.writeEndDocument();
view.setContent(buffer);
buffer.close();
}
refresh();
/* Update report as needed. */
startDateField.dateChanged.connect(function() {
refresh();
});
endDateField.dateChanged.connect(function() {
refresh();
});
]]>