Typica is a free program for professional coffee roasters. https://typica.us
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

invoices.xml 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. });
  48. function refresh() {
  49. var dateRange = dateSelect.currentRange();
  50. var startDate = dateRange[0];
  51. var endDate = dateRange[dateRange.length - 1];
  52. var buffer = new QBuffer;
  53. buffer.open(3);
  54. var output = new XmlWriter(buffer);
  55. output.writeStartDocument("1.0");
  56. 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">');
  57. output.writeStartElement("html");
  58. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  59. output.writeStartElement("head");
  60. output.writeTextElement("title", TTR("invoicereport", "Invoices"));
  61. output.writeEndElement();
  62. output.writeStartElement("body");
  63. var cdt = new Date(Date.now());
  64. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  65. output.writeTextElement("h1", TTR("invoicereport", "Invoices ") + startDate + " - " + endDate);
  66. output.writeStartElement("table");
  67. output.writeAttribute("style", "page-break-after: auto; text-align: left");
  68. output.writeAttribute("rules", "groups");
  69. output.writeAttribute("cellpadding", "3px");
  70. output.writeStartElement("thead");
  71. output.writeStartElement("tr");
  72. output.writeTextElement("th", TTR("invoicereport", "Date"));
  73. output.writeTextElement("th", TTR("invoicereport", "Vendor"));
  74. output.writeTextElement("th", TTR("invoicereport", "Invoice"));
  75. output.writeTextElement("th", TTR("invoicereport", "Cost"));
  76. output.writeEndElement();
  77. output.writeEndElement();
  78. output.writeStartElement("tbody");
  79. var query = new QSqlQuery();
  80. var vendorclause = "";
  81. if(vendor.currentIndex > 0) {
  82. vendorclause = " AND vendor = :vendor";
  83. }
  84. var searchclause = "";
  85. if(search.text.length > 0)
  86. {
  87. 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)";
  88. }
  89. 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");
  90. query.bind(":sd", startDate);
  91. query.bind(":ed", endDate);
  92. if(vendorclause.length > 0) {
  93. query.bind(":vendor", vendor.currentText);
  94. }
  95. if(searchclause.length > 0)
  96. {
  97. var pattern = ".*" + search.text + ".*";
  98. query.bind(":p1", pattern);
  99. query.bind(":p2", pattern);
  100. query.bind(":p3", pattern);
  101. query.bind(":p4", pattern);
  102. query.bind(":p5", pattern);
  103. query.bind(":p6", pattern);
  104. query.bind(":p7", pattern);
  105. query.bind(":p8", pattern);
  106. query.bind(":p9", pattern);
  107. query.bind(":p10", pattern);
  108. query.bind(":p11", pattern);
  109. query.bind(":p12", pattern);
  110. query.bind(":p13", pattern);
  111. }
  112. query.exec();
  113. var cost_sum = 0;
  114. while(query.next()) {
  115. output.writeStartElement("tr");
  116. output.writeStartElement("td");
  117. output.writeStartElement("a");
  118. output.writeAttribute("href", "typica://script/" + query.value(0));
  119. output.writeCharacters(query.value(1));
  120. output.writeEndElement();
  121. output.writeEndElement();
  122. for(var i = 2; i <= 4; i++) {
  123. output.writeTextElement("td", query.value(i));
  124. }
  125. output.writeEndElement();
  126. cost_sum += Number(query.value(4));
  127. }
  128. query = query.invalidate();
  129. output.writeEndElement();
  130. output.writeStartElement("tfoot");
  131. output.writeStartElement("tr");
  132. output.writeEmptyElement("td");
  133. output.writeEmptyElement("td");
  134. output.writeTextElement("th", TTR("invoicereport", "Total:"));
  135. output.writeTextElement("td", Number(cost_sum).toFixed(2));
  136. output.writeEndElement();
  137. output.writeEndElement();
  138. output.writeEndElement();
  139. output.writeEndElement();
  140. output.writeEndElement();
  141. output.writeEndDocument();
  142. view.setContent(buffer);
  143. buffer.close();
  144. }
  145. refresh();
  146. var notifier = Application.subscribe("invoiceschange");
  147. notifier.notify.connect(function() {
  148. refresh();
  149. });
  150. ]]>
  151. </program>