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.

productionsummary.xml 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <window id="dailyproduction">
  2. <reporttitle>Production:->Production Summary</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <label>Batch Type: </label>
  6. <sqldrop id="batchtype" />
  7. <label>Approval: </label>
  8. <sqldrop id="approval" />
  9. <daterange id="dates" initial="9" /><!-- Current Month to Date-->
  10. <label>Weight Unit:</label>
  11. <sqldrop id="unit" />
  12. <stretch />
  13. </layout>
  14. <webview id="report" />
  15. </layout>
  16. <menu name="File">
  17. <item id="print" shortcut="Ctrl+P">Print</item>
  18. </menu>
  19. <program>
  20. <![CDATA[
  21. this.windowTitle = "Typica - Production Summary";
  22. var dateSelect = findChildObject(this, 'dates');
  23. var dateQuery = new QSqlQuery();
  24. dateQuery.exec("SELECT time::date FROM roasting_log WHERE time = (SELECT min(time) FROM roasting_log) OR time = (SELECT max(time) FROM roasting_log) ORDER BY time ASC");
  25. dateQuery.next();
  26. var lifetimeStartDate = dateQuery.value(0);
  27. var lifetimeEndDate;
  28. if(dateQuery.next()) {
  29. lifetimeEndDate = dateQuery.value(0);
  30. } else {
  31. lifetimeEndDate = lifetimeStartDate;
  32. }
  33. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  34. dateQuery = dateQuery.invalidate();
  35. var unitBox = findChildObject(this, 'unit');
  36. unitBox.addItem("Kg");
  37. unitBox.addItem("Lb");
  38. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  39. unitBox['currentIndexChanged(int)'].connect(function() {
  40. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  41. refresh();
  42. });
  43. var batchType = findChildObject(this, 'batchtype');
  44. batchType.addItem("Any");
  45. batchType.addItem("Production Roasts");
  46. batchType.addItem("SampleRoasts");
  47. batchType.currentIndex = QSettings.value("script/batchtypefilter", 1);
  48. batchType['currentIndexChanged(int)'].connect(function() {
  49. QSettings.setValue("script/batchtypefilter", batchType.currentIndex);
  50. refresh();
  51. });
  52. var approval = findChildObject(this, 'approval');
  53. approval.addItem("Any");
  54. approval.addItem("Approved");
  55. approval.addItem("Not Approved");
  56. approval.currentIndex = QSettings.value("script/approvalfilter", 1);
  57. approval['currentIndexChanged(int)'].connect(function() {
  58. QSettings.setValue("script/approvalfilter", approval.currentIndex);
  59. refresh();
  60. });
  61. var view = findChildObject(this, 'report');
  62. var printMenu = findChildObject(this, 'print');
  63. printMenu.triggered.connect(function() {
  64. view.print();
  65. });
  66. function refresh() {
  67. var buffer = new QBuffer;
  68. buffer.open(3);
  69. var output = new XmlWriter(buffer);
  70. output.writeStartDocument("1.0");
  71. 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">');
  72. output.writeStartElement("html");
  73. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  74. output.writeStartElement("head");
  75. output.writeTextElement("title", "Production Summary");
  76. output.writeEndElement();
  77. output.writeStartElement("body");
  78. var dateRange = dateSelect.currentRange();
  79. var startDate = dateRange[0];
  80. var endDate = dateRange[dateRange.length - 1];
  81. output.writeTextElement("h1", "Production Summary: " + startDate + " - " + endDate);
  82. var conversion = 1;
  83. var unitText = 'Lb';
  84. if(unitBox.currentIndex == 0) {
  85. conversion = 2.2;
  86. unitText = 'Kg';
  87. }
  88. var transaction_filter;
  89. var approval_filter;
  90. switch(batchType.currentIndex) {
  91. case 0:
  92. transaction_filter = "";
  93. break;
  94. case 1:
  95. transaction_filter = " AND transaction_type = 'ROAST'";
  96. break;
  97. case 2:
  98. transaction_filter = " AND transaction_type = 'SAMPLEROAST'";
  99. break;
  100. }
  101. switch(approval.currentIndex) {
  102. case 0:
  103. approval_filter = "";
  104. break;
  105. case 1:
  106. approval_filter = " AND approval = true";
  107. break;
  108. case 2:
  109. approval_filter = " AND approval = false";
  110. break;
  111. }
  112. var query = new QSqlQuery();
  113. query.prepare("SELECT count(1), sum(unroasted_total_quantity) / :c1, sum(roasted_quantity) / :c2 FROM roasting_log WHERE time >= :sd AND time < :ed ::date + interval '1 day'" + transaction_filter + approval_filter);
  114. query.bind(":c1", conversion);
  115. query.bind(":c2", conversion);
  116. query.bind(":sd", startDate);
  117. query.bind(":ed", endDate);
  118. query.exec();
  119. query.next();
  120. var batchesRoasted = query.value(0);
  121. var unroastedSum = query.value(1);
  122. var roastedSum = query.value(2);
  123. output.writeTextElement("p", "" + roastedSum + " " + unitText + " roasted from " + unroastedSum + " " + unitText + " green in " + batchesRoasted + " batches.");
  124. query.prepare("SELECT time::date AS date, count(1), sum(unroasted_total_quantity) / :c1, sum(roasted_quantity) / :c2 FROM roasting_log WHERE time >= :sd AND time < :ed ::date + interval '1 day'" + transaction_filter + approval_filter + " GROUP BY date ORDER BY date ASC");
  125. query.bind(":c1", conversion);
  126. query.bind(":c2", conversion);
  127. query.bind(":sd", startDate);
  128. query.bind(":ed", endDate);
  129. query.exec();
  130. output.writeStartElement("table");
  131. output.writeAttribute("rules", "groups");
  132. output.writeAttribute("cellpadding", "3px");
  133. output.writeStartElement("thead");
  134. output.writeStartElement("tr");
  135. output.writeTextElement("th", "Date");
  136. output.writeTextElement("th", "Batches");
  137. output.writeTextElement("th", "Unroasted (" + unitText + ")");
  138. output.writeTextElement("th", "Roasted (" + unitText + ")");
  139. output.writeEndElement();
  140. output.writeEndElement();
  141. output.writeStartElement("tbody");
  142. while(query.next()) {
  143. output.writeStartElement("tr");
  144. output.writeStartElement("td");
  145. output.writeStartElement("a");
  146. output.writeAttribute("href", "typica://script/d" + query.value(0));
  147. output.writeCDATA(query.value(0));
  148. output.writeEndElement();
  149. output.writeEndElement();
  150. output.writeTextElement("td", query.value(1));
  151. output.writeTextElement("td", query.value(2));
  152. output.writeTextElement("td", query.value(3));
  153. output.writeEndElement();
  154. }
  155. output.writeEndElement();
  156. output.writeStartElement("tfoot");
  157. output.writeStartElement("tr");
  158. output.writeStartElement("td");
  159. output.writeTextElement("strong", "Totals:");
  160. output.writeEndElement();
  161. output.writeTextElement("td", batchesRoasted);
  162. output.writeTextElement("td", unroastedSum);
  163. output.writeTextElement("td", roastedSum);
  164. output.writeEndElement();
  165. output.writeEndElement();
  166. output.writeEndElement();
  167. output.writeEndElement();
  168. output.writeEndElement();
  169. output.writeEndDocument();
  170. view.setContent(buffer);
  171. buffer.close();
  172. query = query.invalidate();
  173. }
  174. refresh();
  175. dateSelect.rangeUpdated.connect(refresh);
  176. view.scriptLinkClicked.connect(function(url) {
  177. var arg = url.slice(1, url.length).split("-");
  178. var details = createReport("dailyproductiondetail.xml");
  179. var selector = findChildObject(details, "reportdate");
  180. selector.setDate(arg[0], arg[1], arg[2]);
  181. });
  182. ]]>
  183. </program>
  184. </window>