| Id | Name | Rate | Cost | Inventory | First Use | Last Use | ';
var query = new QSqlQuery();
query.prepare("SELECT id, name, (rate/:conversion1)::numeric(12,3), (SELECT (cost*:conversion2)::numeric(12,2) FROM purchase WHERE item = id), (stock/:conversion3)::numeric(12,3), (SELECT min(time)::date FROM use WHERE item = id) AS first_use, (SELECT max(time)::date FROM use WHERE item = id) AS last_use FROM coffee_history WHERE origin = :origin AND id IN (SELECT id FROM " + tableref + ") AND id IN (SELECT item FROM transactions WHERE time >= :startDate AND time < :endDate::date + interval '1 day') ORDER BY first_use DESC");
var conversion = 1;
if(unitBox.currentIndex == 0) {
conversion = 2.2;
}
var dateRange = dateSelect.currentRange();
var startDate = dateRange[0];
var endDate = dateRange[dateRange.length - 1];
query.bind(":conversion1", conversion);
query.bind(":conversion2", conversion);
query.bind(":conversion3", conversion);
query.bind(":origin", origin);
query.bind(":startDate", startDate);
query.bind(":endDate", endDate);
query.exec();
while(query.next()) {
details += "";
details += '' + query.value(0) + " | ";
for(var i = 1; i < 7; i++) {
details += "" + query.value(i) + " | ";
}
details += " ";
}
query = query.invalidate();
details += "
|
";
element.appendOutside(details);
});
]]>