Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

productionsummary.xml 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 = TTR("dailyproduction", "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(TTR("dailyproduction", "Kg"));
  37. unitBox.addItem(TTR("dailyproduction", "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(TTR("dailyproduction", "Any"));
  45. batchType.addItem(TTR("dailyproduction", "Production Roasts"));
  46. batchType.addItem(TTR("dailyproduction", "Sample Roasts"));
  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(TTR("dailyproduction", "Any"));
  54. approval.addItem(TTR("dailyproduction", "Approved"));
  55. approval.addItem(TTR("dailyproduction", "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", TTR("dailyproduction", "Production Summary"));
  76. output.writeEndElement();
  77. output.writeStartElement("body");
  78. var cdt = new Date(Date.now());
  79. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  80. var dateRange = dateSelect.currentRange();
  81. var startDate = dateRange[0];
  82. var endDate = dateRange[dateRange.length - 1];
  83. output.writeTextElement("h1", TTR("dailyproduction", "Production Summary: ") + startDate + " - " + endDate);
  84. var conversion = 1;
  85. var unitText = TTR("dailyproduction", "Lb");
  86. if(unitBox.currentIndex == 0) {
  87. conversion = 2.2;
  88. unitText = TTR("dailyproduction", "Kg");
  89. }
  90. var transaction_filter;
  91. var approval_filter;
  92. switch(batchType.currentIndex) {
  93. case 0:
  94. transaction_filter = "";
  95. break;
  96. case 1:
  97. transaction_filter = " AND transaction_type = 'ROAST'";
  98. break;
  99. case 2:
  100. transaction_filter = " AND transaction_type = 'SAMPLEROAST'";
  101. break;
  102. }
  103. switch(approval.currentIndex) {
  104. case 0:
  105. approval_filter = "";
  106. break;
  107. case 1:
  108. approval_filter = " AND approval = true";
  109. break;
  110. case 2:
  111. approval_filter = " AND approval = false";
  112. break;
  113. }
  114. var query = new QSqlQuery();
  115. 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);
  116. query.bind(":c1", conversion);
  117. query.bind(":c2", conversion);
  118. query.bind(":sd", startDate);
  119. query.bind(":ed", endDate);
  120. query.exec();
  121. query.next();
  122. var batchesRoasted = query.value(0);
  123. var unroastedSum = query.value(1);
  124. var roastedSum = query.value(2);
  125. output.writeTextElement("p", "" + roastedSum + " " + unitText + TTR("dailyproduction", " roasted from ") +
  126. unroastedSum + " " + unitText + TTR("dailyproduction", " green in ") +
  127. batchesRoasted + TTR("dailyproduction", " batches."));
  128. 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");
  129. query.bind(":c1", conversion);
  130. query.bind(":c2", conversion);
  131. query.bind(":sd", startDate);
  132. query.bind(":ed", endDate);
  133. query.exec();
  134. output.writeStartElement("table");
  135. output.writeAttribute("rules", "groups");
  136. output.writeAttribute("cellpadding", "3px");
  137. output.writeStartElement("thead");
  138. output.writeStartElement("tr");
  139. output.writeTextElement("th", TTR("dailyproduction", "Date"));
  140. output.writeTextElement("th", TTR("dailyproduction", "Batches"));
  141. output.writeTextElement("th", TTR("dailyproduction", "Unroasted (") + unitText + ")");
  142. output.writeTextElement("th", TTR("dailyproduction", "Roasted (") + unitText + ")");
  143. output.writeEndElement();
  144. output.writeEndElement();
  145. output.writeStartElement("tbody");
  146. while(query.next()) {
  147. output.writeStartElement("tr");
  148. output.writeStartElement("td");
  149. output.writeStartElement("a");
  150. output.writeAttribute("href", "typica://script/d" + query.value(0));
  151. output.writeCDATA(query.value(0));
  152. output.writeEndElement();
  153. output.writeEndElement();
  154. output.writeTextElement("td", query.value(1));
  155. output.writeTextElement("td", query.value(2));
  156. output.writeTextElement("td", query.value(3));
  157. output.writeEndElement();
  158. }
  159. output.writeEndElement();
  160. output.writeStartElement("tfoot");
  161. output.writeStartElement("tr");
  162. output.writeStartElement("td");
  163. output.writeTextElement("strong", TTR("dailyproduction", "Totals:"));
  164. output.writeEndElement();
  165. output.writeTextElement("td", batchesRoasted);
  166. output.writeTextElement("td", unroastedSum);
  167. output.writeTextElement("td", roastedSum);
  168. output.writeEndElement();
  169. output.writeEndElement();
  170. output.writeEndElement();
  171. output.writeEndElement();
  172. output.writeEndElement();
  173. output.writeEndDocument();
  174. view.setContent(buffer);
  175. buffer.close();
  176. query = query.invalidate();
  177. }
  178. refresh();
  179. dateSelect.rangeUpdated.connect(refresh);
  180. var notifier = Application.subscribe("roastinglogchange");
  181. notifier.notify.connect(function() {
  182. refresh();
  183. });
  184. view.scriptLinkClicked.connect(function(url) {
  185. var arg = url.slice(1, url.length).split("-");
  186. var details = createReport("dailyproductiondetail.xml");
  187. var selector = findChildObject(details, "reportdate");
  188. selector.setDate(arg[0], arg[1], arg[2]);
  189. });
  190. ]]>
  191. </program>
  192. </window>