Typica is a free program for professional coffee roasters. https://typica.us
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

invoices.xml 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. var cdt = new Date(Date.now());
  75. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  76. output.writeTextElement("h1", TTR("invoicereport", "Invoices ") + startDate + " - " + endDate);
  77. output.writeStartElement("table");
  78. output.writeAttribute("style", "page-break-after: auto; text-align: left");
  79. output.writeAttribute("rules", "groups");
  80. output.writeAttribute("cellpadding", "3px");
  81. output.writeStartElement("thead");
  82. output.writeStartElement("tr");
  83. output.writeTextElement("th", TTR("invoicereport", "Date"));
  84. output.writeTextElement("th", TTR("invoicereport", "Vendor"));
  85. output.writeTextElement("th", TTR("invoicereport", "Invoice"));
  86. output.writeTextElement("th", TTR("invoicereport", "Cost"));
  87. output.writeEndElement();
  88. output.writeEndElement();
  89. output.writeStartElement("tbody");
  90. var query = new QSqlQuery();
  91. var vendorclause = "";
  92. if(vendor.currentIndex > 0) {
  93. vendorclause = " AND vendor = :vendor";
  94. }
  95. var searchclause = "";
  96. if(search.text.length > 0)
  97. {
  98. 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)";
  99. }
  100. 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");
  101. query.bind(":sd", startDate);
  102. query.bind(":ed", endDate);
  103. if(vendorclause.length > 0) {
  104. query.bind(":vendor", vendor.currentText);
  105. }
  106. if(searchclause.length > 0)
  107. {
  108. var pattern = ".*" + search.text + ".*";
  109. query.bind(":p1", pattern);
  110. query.bind(":p2", pattern);
  111. query.bind(":p3", pattern);
  112. query.bind(":p4", pattern);
  113. query.bind(":p5", pattern);
  114. query.bind(":p6", pattern);
  115. query.bind(":p7", pattern);
  116. query.bind(":p8", pattern);
  117. query.bind(":p9", pattern);
  118. query.bind(":p10", pattern);
  119. query.bind(":p11", pattern);
  120. query.bind(":p12", pattern);
  121. query.bind(":p13", pattern);
  122. }
  123. query.exec();
  124. var cost_sum = 0;
  125. while(query.next()) {
  126. output.writeStartElement("tr");
  127. output.writeStartElement("td");
  128. output.writeStartElement("a");
  129. output.writeAttribute("href", "typica://script/" + query.value(0));
  130. output.writeCharacters(query.value(1));
  131. output.writeEndElement();
  132. output.writeEndElement();
  133. for(var i = 2; i <= 4; i++) {
  134. output.writeTextElement("td", query.value(i));
  135. }
  136. output.writeEndElement();
  137. cost_sum += Number(query.value(4));
  138. }
  139. query = query.invalidate();
  140. output.writeEndElement();
  141. output.writeStartElement("tfoot");
  142. output.writeStartElement("tr");
  143. output.writeEmptyElement("td");
  144. output.writeEmptyElement("td");
  145. output.writeTextElement("th", TTR("invoicereport", "Total:"));
  146. output.writeTextElement("td", Number(cost_sum).toFixed(2));
  147. output.writeEndElement();
  148. output.writeEndElement();
  149. output.writeEndElement();
  150. output.writeEndElement();
  151. output.writeEndElement();
  152. output.writeEndDocument();
  153. view.setContent(buffer);
  154. buffer.close();
  155. }
  156. refresh();
  157. var notifier = Application.subscribe("invoiceschange");
  158. notifier.notify.connect(function() {
  159. refresh();
  160. });
  161. ]]>
  162. </program>