Inventory:->Current Inventory and Availability Projection
');
output.writeStartElement("html");
output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
output.writeStartElement("head");
output.writeTextElement("title", TTR("inventoryreport", "Current Inventory and Availability Projection"));
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("inventoryreport", "Current Inventory and Availability Projection"));
output.writeTextElement("p", TTR("inventoryreport", "This is a report showing how much of each coffee is available, the cost of that coffee, the daily rate of use for that coffee, and the date the coffee will be gone if use continues at the current rate."));
output.writeStartElement("table");
output.writeAttribute("rules", "groups");
output.writeAttribute("cellpadding", "3px");
output.writeStartElement("thead");
output.writeStartElement("tr");
output.writeTextElement("th", TTR("inventoryreport", "Coffee"));
switch(unitBox.currentIndex)
{
case 0:
output.writeTextElement("th", TTR("inventoryreport", "Stock (Kg)"));
break;
case 1:
output.writeTextElement("th", TTR("inventoryreport", "Stock (Lb)"));
break;
}
output.writeTextElement("th", TTR("inventoryreport", "Sacks"));
output.writeTextElement("th", TTR("inventoryreport", "Unit Cost"));
output.writeTextElement("th", TTR("inventoryreport", "Stock Cost"));
output.writeTextElement("th", TTR("inventoryreport", "Use Rate"));
output.writeTextElement("th", TTR("inventoryreport", "Availability"));
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tbody");
var query = new QSqlQuery();
var q = "SELECT name || ' (' || id || ')', (quantity / :conversion)::numeric(12,2) AS quantity, (quantity / (SELECT conversion FROM lb_bag_conversion WHERE item = id))::numeric(12,2) AS sacks, (SELECT cost * :conversion2 FROM purchase WHERE item = id)::numeric(12,2) AS cost, (quantity * (SELECT cost FROM purchase WHERE item = id))::numeric(12,2) AS stock_cost, (SELECT rate / :conversion3 FROM coffee_history WHERE coffee_history.id = items.id)::numeric(12,2) AS rate, (SELECT out FROM coffee_history WHERE coffee_history.id = items.id) AS out FROM items WHERE quantity > 0 ";
switch(sortBox.currentIndex)
{
case 0:
q = q + "ORDER BY name ASC";
break;
case 1:
q = q + "ORDER BY name DESC";
break;
case 2:
q = q + "ORDER BY quantity ASC";
break;
case 3:
q = q + "ORDER BY quantity DESC";
break;
case 4:
q = q + "ORDER BY sacks ASC";
break;
case 5:
q = q + "ORDER BY sacks DESC";
break;
case 6:
q = q + "ORDER BY cost ASC";
break;
case 7:
q = q + "ORDER BY cost DESC";
break;
case 8:
q = q + "ORDER BY stock_cost ASC";
break;
case 9:
q = q + "ORDER BY stock_cost DESC";
break;
case 10:
q = q + "ORDER BY rate ASC";
break;
case 11:
q = q + "ORDER BY rate DESC";
break;
case 12:
q = q + "ORDER BY out ASC";
break;
case 13:
q = q + "ORDER BY out DESC";
break;
}
query.prepare(q);
switch(unitBox.currentIndex)
{
case 0:
query.bind(":conversion", 2.2);
query.bind(":conversion2", 2.2);
query.bind(":conversion3", 2.2);
break;
case 1:
query.bind(":conversion", 1);
query.bind(":conversion2", 1);
query.bind(":conversion3", 1);
break;
}
query.exec();
while(query.next())
{
output.writeStartElement("tr");
output.writeTextElement("td", query.value(0));
output.writeTextElement("td", query.value(1));
output.writeTextElement("td", query.value(2));
output.writeTextElement("td", query.value(3));
output.writeTextElement("td", query.value(4));
output.writeTextElement("td", query.value(5));
output.writeTextElement("td", query.value(6));
output.writeEndElement();
}
output.writeEndElement();
output.writeStartElement("tfoot");
output.writeStartElement("tr");
output.writeTextElement("th", TTR("inventoryreport", "Totals"));
query.prepare("SELECT (sum(quantity) / :conversion)::numeric(12,2), sum(quantity * (SELECT cost FROM purchase WHERE item = id))::numeric(12,2) FROM items WHERE quantity > 0");
switch(unitBox.currentIndex)
{
case 0:
query.bind(":conversion", 2.2);
break;
case 1:
query.bind(":conversion", 1);
break;
}
query.exec();
query.next();
output.writeTextElement("td", query.value(0));
output.writeTextElement("td", "");
output.writeTextElement("td", "");
output.writeTextElement("td", query.value(1));
output.writeTextElement("td", "");
output.writeTextElement("td", "");
query = query.invalidate();
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndDocument();
report.setContent(buffer);
buffer.close();
}
refresh();
var notifier = Application.subscribe("transactionschange");
notifier.notify.connect(function() {
refresh();
});
sortBox['currentIndexChanged(int)'].connect(function() {
QSettings.setValue("inventory_sort", sortBox.currentIndex);
refresh();
});
unitBox['currentIndexChanged(int)'].connect(function() {
QSettings.setValue("script/report_unit", unitBox.currentIndex);
refresh();
});
]]>