Typica is a free program for professional coffee roasters. https://typica.us
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

invoices.xml 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <window id="invoicereport">
  2. <reporttitle>Purchase:->Invoices</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <daterange id="dates" initial="23" /><!-- Lifetime -->
  6. <label>Vendor: </label>
  7. <sqldrop id="vendor" />
  8. <label>Search: </label>
  9. <line id="search" />
  10. <stretch />
  11. </layout>
  12. <webview id="report" />
  13. </layout>
  14. <menu name="File">
  15. <item id="print" shortcut="Ctrl+P">Print...</item>
  16. </menu>
  17. <program>
  18. <![CDATA[
  19. var vendor = findChildObject(this, "vendor");
  20. vendor.addItem(TTR("invoicereport", "Any"));
  21. var query = new QSqlQuery();
  22. query.exec("SELECT DISTINCT vendor FROM invoices");
  23. while(query.next()) {
  24. vendor.addItem(query.value(0));
  25. }
  26. vendor['currentIndexChanged(int)'].connect(refresh);
  27. var dateSelect = findChildObject(this, 'dates');
  28. query.exec("SELECT time::date FROM invoices WHERE time = (SELECT min(time) FROM invoices) OR time = (SELECT max(time) FROM invoices) ORDER BY time ASC");
  29. query.next();
  30. var lifetimeStartDate = query.value(0);
  31. var lifetimeEndDate;
  32. if(query.next()) {
  33. lifetimeEndDate = query.value(0);
  34. } else {
  35. lifetimeEndDate = lifetimeStartDate;
  36. }
  37. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  38. dateSelect.rangeUpdated.connect(refresh);
  39. query = query.invalidate();
  40. var search = findChildObject(this, "search");
  41. search.editingFinished.connect(refresh);
  42. var view = findChildObject(this, "report");
  43. view.scriptLinkClicked.connect(function(url) {
  44. var info = createWindow("invoiceinfo");
  45. info.setInvoiceID(url);
  46. var invquery = new QSqlQuery();
  47. invquery.exec("SELECT time, invoice, vendor FROM invoices WHERE id = " + url);
  48. invquery.next();
  49. var timefield = findChildObject(info, 'date');
  50. timefield.text = invquery.value(0);
  51. var vendorfield = findChildObject(info, 'vendor');
  52. vendorfield.text = invquery.value(2);
  53. var invoicefield = findChildObject(info, 'invoice');
  54. invoicefield.text = invquery.value(1);
  55. var itemtable = findChildObject(info, 'itemtable');
  56. 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 = " + url + " AND record_type = 'PURCHASE' UNION SELECT record_type, NULL, description, NULL, NULL, NULL, NULL, cost FROM invoice_items WHERE invoice_id = " + url + " AND record_type = 'FEE' ORDER BY item_id");
  57. invquery = invquery.invalidate();
  58. });
  59. function refresh() {
  60. var dateRange = dateSelect.currentRange();
  61. var startDate = dateRange[0];
  62. var endDate = dateRange[dateRange.length - 1];
  63. var buffer = new QBuffer;
  64. buffer.open(3);
  65. var output = new XmlWriter(buffer);
  66. output.writeStartDocument("1.0");
  67. output.writeDTD('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg.dtd">');
  68. output.writeStartElement("html");
  69. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  70. output.writeStartElement("head");
  71. output.writeTextElement("title", TTR("invoicereport", "Invoices"));
  72. output.writeEndElement();
  73. output.writeStartElement("body");
  74. output.writeTextElement("h1", TTR("invoicereport", "Invoices ") + startDate + " - " + endDate);
  75. output.writeStartElement("table");
  76. output.writeAttribute("style", "page-break-after: auto; text-align: left");
  77. output.writeAttribute("rules", "groups");
  78. output.writeAttribute("cellpadding", "3px");
  79. output.writeStartElement("thead");
  80. output.writeStartElement("tr");
  81. output.writeTextElement("th", TTR("invoicereport", "Date"));
  82. output.writeTextElement("th", TTR("invoicereport", "Vendor"));
  83. output.writeTextElement("th", TTR("invoicereport", "Invoice"));
  84. output.writeTextElement("th", TTR("invoicereport", "Cost"));
  85. output.writeEndElement();
  86. output.writeEndElement();
  87. output.writeStartElement("tbody");
  88. var query = new QSqlQuery();
  89. var vendorclause = "";
  90. if(vendor.currentIndex > 0) {
  91. vendorclause = " AND vendor = :vendor";
  92. }
  93. var searchclause = "";
  94. if(search.text.length > 0)
  95. {
  96. 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)";
  97. }
  98. 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");
  99. query.bind(":sd", startDate);
  100. query.bind(":ed", endDate);
  101. if(vendorclause.length > 0) {
  102. query.bind(":vendor", vendor.currentText);
  103. }
  104. if(searchclause.length > 0)
  105. {
  106. var pattern = ".*" + search.text + ".*";
  107. query.bind(":p1", pattern);
  108. query.bind(":p2", pattern);
  109. query.bind(":p3", pattern);
  110. query.bind(":p4", pattern);
  111. query.bind(":p5", pattern);
  112. query.bind(":p6", pattern);
  113. query.bind(":p7", pattern);
  114. query.bind(":p8", pattern);
  115. query.bind(":p9", pattern);
  116. query.bind(":p10", pattern);
  117. query.bind(":p11", pattern);
  118. query.bind(":p12", pattern);
  119. query.bind(":p13", pattern);
  120. }
  121. query.exec();
  122. var cost_sum = 0;
  123. while(query.next()) {
  124. output.writeStartElement("tr");
  125. output.writeStartElement("td");
  126. output.writeStartElement("a");
  127. output.writeAttribute("href", "typica://script/" + query.value(0));
  128. output.writeCharacters(query.value(1));
  129. output.writeEndElement();
  130. output.writeEndElement();
  131. for(var i = 2; i <= 4; i++) {
  132. output.writeTextElement("td", query.value(i));
  133. }
  134. output.writeEndElement();
  135. cost_sum += Number(query.value(4));
  136. }
  137. query = query.invalidate();
  138. output.writeEndElement();
  139. output.writeStartElement("tfoot");
  140. output.writeStartElement("tr");
  141. output.writeEmptyElement("td");
  142. output.writeEmptyElement("td");
  143. output.writeTextElement("th", TTR("invoicereport", "Total:"));
  144. output.writeTextElement("td", Number(cost_sum).toFixed(2));
  145. output.writeEndElement();
  146. output.writeEndElement();
  147. output.writeEndElement();
  148. output.writeEndElement();
  149. output.writeEndElement();
  150. output.writeEndDocument();
  151. view.setContent(buffer);
  152. buffer.close();
  153. }
  154. refresh();
  155. ]]>
  156. </program>