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;");
output.writeAttribute("rules", "groups");
output.writeAttribute("cellpadding", "3px");
output.writeStartElement("thead");
output.writeStartElement("tr");
output.writeEmptyElement("th");
for(var i = startDateField.year(); i <= endDateField.year(); i++)
{
output.writeTextElement("th", i);
}
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tbody");
output.writeStartElement("tr");
output.writeTextElement("th", "Sacks Purchased");
var j = 0;
var sacks = new Array;
for(var i = startDateField.year(); i <= endDateField.year(); i++)
{
var q = "SELECT sum(quantity/(SELECT conversion FROM lb_bag_conversion WHERE item = purchase.item)) FROM purchase WHERE time >= '" + i + "-01-01' AND time < '" + (i+1) + "-01-01'";
query.exec(q);
query.next();
output.writeTextElement("td", query.value(0));
sacks[j] = query.value(0);
j++;
}
output.writeEndElement();
output.writeStartElement("tr");
switch(unitBox.currentIndex) {
case 0:
output.writeTextElement("th", "Kilos Purchased");
break;
case 1:
output.writeTextElement("th", "Pounds Purchased");
break;
}
j = 0;
var pounds = new Array;
for(var i = startDateField.year(); i <= endDateField.year(); i++)
{
var q = "SELECT (sum(quantity) / :conversion)::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.writeTextElement("td", query.value(0));
pounds[j] = query.value(0);
j++;
}
output.writeEndElement();
output.writeStartElement("tr");
output.writeTextElement("th", "Cost");
j = 0;
var cost = new Array;
for(var i = startDateField.year(); i <= endDateField.year(); i++)
{
var q = "SELECT sum(cost*quantity)::numeric(12,2) FROM purchase WHERE time >= '" + i + "-01-01' AND time < '" + (i+1) + "-01-01'";
query.exec(q);
query.next();
output.writeTextElement("td", query.value(0));
cost[j] = query.value(0);
j++;
}
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tfoot");
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndDocument();
view.setContent(buffer);
buffer.close();
}
refresh();
startDateField.dateChanged.connect(function() {
refresh();
});
endDateField.dateChanged.connect(function() {
refresh();
});
]]>