Purchase:->Invoices Print... '); output.writeStartElement("html"); output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml"); output.writeStartElement("head"); output.writeTextElement("title", TTR("invoicereport", "Invoices")); 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("invoicereport", "Invoices ") + startDate + " - " + endDate); 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.writeTextElement("th", TTR("invoicereport", "Date")); output.writeTextElement("th", TTR("invoicereport", "Vendor")); output.writeTextElement("th", TTR("invoicereport", "Invoice")); output.writeTextElement("th", TTR("invoicereport", "Cost")); output.writeEndElement(); output.writeEndElement(); output.writeStartElement("tbody"); var query = new QSqlQuery(); var vendorclause = ""; if(vendor.currentIndex > 0) { vendorclause = " AND vendor = :vendor"; } var searchclause = ""; if(search.text.length > 0) { searchclause = " AND id IN (SELECT invoice_id FROM invoice_items WHERE item_id IN (SELECT item FROM certifications WHERE certification ~* :p1 UNION SELECT id FROM coffees WHERE origin ~* :p2 UNION SELECT id FROM items WHERE name ~* :p3 UNION SELECT id FROM coffees WHERE reference ~* :p4 UNION SELECT id FROM coffees WHERE region ~* :p5 UNION SELECT id FROM coffees WHERE producer ~* :p6 UNION SELECT id FROM coffees WHERE grade ~* :p7 UNION SELECT id FROM coffees WHERE milling ~* :p8 UNION SELECT id FROM coffees WHERE drying ~* :p9 UNION SELECT id FROM decaf_coffees WHERE decaf_method ~* :p10) OR description ~* :p11 UNION SELECT id FROM invoices WHERE invoice ~* :p12 UNION SELECT id FROM invoices WHERE vendor ~* :p13)"; } query.prepare("SELECT id, time::date, vendor, invoice, (SELECT sum(cost) FROM invoice_items WHERE invoice_id = id)::numeric(12,2) AS cost FROM invoices WHERE time >= :sd AND time < :ed::date + interval '1 day'" + vendorclause + searchclause + " ORDER BY time DESC"); query.bind(":sd", startDate); query.bind(":ed", endDate); if(vendorclause.length > 0) { query.bind(":vendor", vendor.currentText); } if(searchclause.length > 0) { var pattern = ".*" + search.text + ".*"; query.bind(":p1", pattern); query.bind(":p2", pattern); query.bind(":p3", pattern); query.bind(":p4", pattern); query.bind(":p5", pattern); query.bind(":p6", pattern); query.bind(":p7", pattern); query.bind(":p8", pattern); query.bind(":p9", pattern); query.bind(":p10", pattern); query.bind(":p11", pattern); query.bind(":p12", pattern); query.bind(":p13", pattern); } query.exec(); var cost_sum = 0; while(query.next()) { output.writeStartElement("tr"); output.writeStartElement("td"); output.writeStartElement("a"); output.writeAttribute("href", "typica://script/" + query.value(0)); output.writeCharacters(query.value(1)); output.writeEndElement(); output.writeEndElement(); for(var i = 2; i <= 4; i++) { output.writeTextElement("td", query.value(i)); } output.writeEndElement(); cost_sum += Number(query.value(4)); } query = query.invalidate(); output.writeEndElement(); output.writeStartElement("tfoot"); output.writeStartElement("tr"); output.writeEmptyElement("td"); output.writeEmptyElement("td"); output.writeTextElement("th", TTR("invoicereport", "Total:")); output.writeTextElement("td", Number(cost_sum).toFixed(2)); output.writeEndElement(); output.writeEndElement(); output.writeEndElement(); output.writeEndElement(); output.writeEndElement(); output.writeEndDocument(); view.setContent(buffer); buffer.close(); } refresh(); var notifier = Application.subscribe("invoiceschange"); notifier.notify.connect(function() { refresh(); }); ]]>