Typica is a free program for professional coffee roasters. https://typica.us
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

invoices.xml 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. <menu name="Reports" type="reports" src="Reports" />
  18. <program>
  19. <![CDATA[
  20. var vendor = findChildObject(this, "vendor");
  21. vendor.addItem(TTR("invoicereport", "Any"));
  22. var query = new QSqlQuery();
  23. query.exec("SELECT DISTINCT vendor FROM invoices");
  24. while(query.next()) {
  25. vendor.addItem(query.value(0));
  26. }
  27. vendor['currentIndexChanged(int)'].connect(refresh);
  28. var dateSelect = findChildObject(this, 'dates');
  29. 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");
  30. query.next();
  31. var lifetimeStartDate = query.value(0);
  32. var lifetimeEndDate;
  33. if(query.next()) {
  34. lifetimeEndDate = query.value(0);
  35. } else {
  36. lifetimeEndDate = lifetimeStartDate;
  37. }
  38. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  39. dateSelect.rangeUpdated.connect(refresh);
  40. query = query.invalidate();
  41. var search = findChildObject(this, "search");
  42. search.editingFinished.connect(refresh);
  43. var view = findChildObject(this, "report");
  44. view.scriptLinkClicked.connect(function(url) {
  45. var info = createWindow("invoiceinfo");
  46. info.setInvoiceID(url);
  47. var invquery = new QSqlQuery();
  48. invquery.exec("SELECT time, invoice, vendor FROM invoices WHERE id = " + url);
  49. invquery.next();
  50. var timefield = findChildObject(info, 'date');
  51. timefield.text = invquery.value(0);
  52. var vendorfield = findChildObject(info, 'vendor');
  53. vendorfield.text = invquery.value(2);
  54. var invoicefield = findChildObject(info, 'invoice');
  55. invoicefield.text = invquery.value(1);
  56. var itemtable = findChildObject(info, 'itemtable');
  57. 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");
  58. invquery = invquery.invalidate();
  59. });
  60. function refresh() {
  61. var dateRange = dateSelect.currentRange();
  62. var startDate = dateRange[0];
  63. var endDate = dateRange[dateRange.length - 1];
  64. var buffer = new QBuffer;
  65. buffer.open(3);
  66. var output = new XmlWriter(buffer);
  67. output.writeStartDocument("1.0");
  68. 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">');
  69. output.writeStartElement("html");
  70. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  71. output.writeStartElement("head");
  72. output.writeTextElement("title", TTR("invoicereport", "Invoices"));
  73. output.writeEndElement();
  74. output.writeStartElement("body");
  75. var cdt = new Date(Date.now());
  76. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  77. output.writeTextElement("h1", TTR("invoicereport", "Invoices ") + startDate + " - " + endDate);
  78. output.writeStartElement("table");
  79. output.writeAttribute("style", "page-break-after: auto; text-align: left");
  80. output.writeAttribute("rules", "groups");
  81. output.writeAttribute("cellpadding", "3px");
  82. output.writeStartElement("thead");
  83. output.writeStartElement("tr");
  84. output.writeTextElement("th", TTR("invoicereport", "Date"));
  85. output.writeTextElement("th", TTR("invoicereport", "Vendor"));
  86. output.writeTextElement("th", TTR("invoicereport", "Invoice"));
  87. output.writeTextElement("th", TTR("invoicereport", "Cost"));
  88. output.writeEndElement();
  89. output.writeEndElement();
  90. output.writeStartElement("tbody");
  91. var query = new QSqlQuery();
  92. var vendorclause = "";
  93. if(vendor.currentIndex > 0) {
  94. vendorclause = " AND vendor = :vendor";
  95. }
  96. var searchclause = "";
  97. if(search.text.length > 0)
  98. {
  99. 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)";
  100. }
  101. 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");
  102. query.bind(":sd", startDate);
  103. query.bind(":ed", endDate);
  104. if(vendorclause.length > 0) {
  105. query.bind(":vendor", vendor.currentText);
  106. }
  107. if(searchclause.length > 0)
  108. {
  109. var pattern = ".*" + search.text + ".*";
  110. query.bind(":p1", pattern);
  111. query.bind(":p2", pattern);
  112. query.bind(":p3", pattern);
  113. query.bind(":p4", pattern);
  114. query.bind(":p5", pattern);
  115. query.bind(":p6", pattern);
  116. query.bind(":p7", pattern);
  117. query.bind(":p8", pattern);
  118. query.bind(":p9", pattern);
  119. query.bind(":p10", pattern);
  120. query.bind(":p11", pattern);
  121. query.bind(":p12", pattern);
  122. query.bind(":p13", pattern);
  123. }
  124. query.exec();
  125. var cost_sum = 0;
  126. while(query.next()) {
  127. output.writeStartElement("tr");
  128. output.writeStartElement("td");
  129. output.writeStartElement("a");
  130. output.writeAttribute("href", "typica://script/" + query.value(0));
  131. output.writeCharacters(query.value(1));
  132. output.writeEndElement();
  133. output.writeEndElement();
  134. for(var i = 2; i <= 4; i++) {
  135. output.writeTextElement("td", query.value(i));
  136. }
  137. output.writeEndElement();
  138. cost_sum += Number(query.value(4));
  139. }
  140. query = query.invalidate();
  141. output.writeEndElement();
  142. output.writeStartElement("tfoot");
  143. output.writeStartElement("tr");
  144. output.writeEmptyElement("td");
  145. output.writeEmptyElement("td");
  146. output.writeTextElement("th", TTR("invoicereport", "Total:"));
  147. output.writeTextElement("td", Number(cost_sum).toFixed(2));
  148. output.writeEndElement();
  149. output.writeEndElement();
  150. output.writeEndElement();
  151. output.writeEndElement();
  152. output.writeEndElement();
  153. output.writeEndDocument();
  154. view.setContent(buffer);
  155. buffer.close();
  156. }
  157. refresh();
  158. var notifier = Application.subscribe("invoiceschange");
  159. notifier.notify.connect(function() {
  160. refresh();
  161. });
  162. ]]>
  163. </program>