| Id | ' + TTR("fypurchase", "Invoice") +
' | ' + TTR("fypurchase", "Vendor") +
' | ' + TTR("fypurchase", "Cost") +
' | ';
q = "SELECT id, invoice, vendor, (SELECT sum(cost) FROM invoice_items WHERE invoice_id = id) FROM invoices WHERE time >= '" + year + "-01-01' AND time <= '" + year + "-12-31'";
var query = new QSqlQuery();
query.exec(q);
while(query.next())
{
details += '' + query.value(0) + ' | ';
details += '' + query.value(1) + ' | ';
details += '' + query.value(2) + ' | ';
details += '' + Number(query.value(3)).toFixed(2) + ' | ';
}
query = query.invalidate();
details += '
|
'
element.appendOutside(details);
}
};
/* Open invoices */
var openInvoice = function(url) {
var arg = url.slice(1, url.length);
var info = createWindow("invoiceinfo");
info.setInvoiceID(arg);
var query = new QSqlQuery();
query.exec("SELECT time, invoice, vendor FROM invoices WHERE id = " + arg);
query.next();
var timefield = findChildObject(info, 'date');
timefield.text = query.value(0);
var vendorfield = findChildObject(info, 'vendor');
vendorfield.text = query.value(2);
var invoicefield = findChildObject(info, 'invoice');
invoicefield.text = query.value(1);
var itemtable = findChildObject(info, 'itemtable');
itemtable.setQuery("SELECT record_type, item_id, description, (SELECT reference FROM items WHERE id = item_id) AS reference, (SELECT cost FROM purchase WHERE item = item_id) AS unit_cost, (SELECT quantity FROM purchase WHERE item = item_id) AS quantity, ((SELECT quantity FROM purchase WHERE item = item_id)/(SELECT conversion FROM lb_bag_conversion WHERE item = item_id))::numeric(12,2) AS sacks, cost FROM invoice_items WHERE invoice_id = " + arg + " AND record_type = 'PURCHASE' UNION SELECT record_type, NULL, description, NULL, NULL, NULL, NULL, cost FROM invoice_items WHERE invoice_id = " + arg + " AND record_type = 'FEE' ORDER BY item_id");
query = query.invalidate();
};
/* Dispatch script link clicks */
view.scriptLinkClicked.connect(function(url) {
var linkType = url[0];
switch(linkType) {
case 'y':
expandYear(url);
break
case 'i':
openInvoice(url);
break;
}
});
]]>