Typica is a free program for professional coffee roasters. https://typica.us
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

productionsummary.xml 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. <menu name="Reports" type="reports" src="Reports" />
  20. <program>
  21. <![CDATA[
  22. this.windowTitle = TTR("dailyproduction", "Typica - Production Summary");
  23. var dateSelect = findChildObject(this, 'dates');
  24. var dateQuery = new QSqlQuery();
  25. 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");
  26. dateQuery.next();
  27. var lifetimeStartDate = dateQuery.value(0);
  28. var lifetimeEndDate;
  29. if(dateQuery.next()) {
  30. lifetimeEndDate = dateQuery.value(0);
  31. } else {
  32. lifetimeEndDate = lifetimeStartDate;
  33. }
  34. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  35. dateQuery = dateQuery.invalidate();
  36. var unitBox = findChildObject(this, 'unit');
  37. unitBox.addItem(TTR("dailyproduction", "Kg"));
  38. unitBox.addItem(TTR("dailyproduction", "Lb"));
  39. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  40. unitBox['currentIndexChanged(int)'].connect(function() {
  41. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  42. refresh();
  43. });
  44. var batchType = findChildObject(this, 'batchtype');
  45. batchType.addItem(TTR("dailyproduction", "Any"));
  46. batchType.addItem(TTR("dailyproduction", "Production Roasts"));
  47. batchType.addItem(TTR("dailyproduction", "Sample Roasts"));
  48. batchType.currentIndex = QSettings.value("script/batchtypefilter", 1);
  49. batchType['currentIndexChanged(int)'].connect(function() {
  50. QSettings.setValue("script/batchtypefilter", batchType.currentIndex);
  51. refresh();
  52. });
  53. var approval = findChildObject(this, 'approval');
  54. approval.addItem(TTR("dailyproduction", "Any"));
  55. approval.addItem(TTR("dailyproduction", "Approved"));
  56. approval.addItem(TTR("dailyproduction", "Not Approved"));
  57. approval.currentIndex = QSettings.value("script/approvalfilter", 1);
  58. approval['currentIndexChanged(int)'].connect(function() {
  59. QSettings.setValue("script/approvalfilter", approval.currentIndex);
  60. refresh();
  61. });
  62. var view = findChildObject(this, 'report');
  63. var printMenu = findChildObject(this, 'print');
  64. printMenu.triggered.connect(function() {
  65. view.print();
  66. });
  67. function refresh() {
  68. var buffer = new QBuffer;
  69. buffer.open(3);
  70. var output = new XmlWriter(buffer);
  71. output.writeStartDocument("1.0");
  72. 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">');
  73. output.writeStartElement("html");
  74. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  75. output.writeStartElement("head");
  76. output.writeTextElement("title", TTR("dailyproduction", "Production Summary"));
  77. output.writeEndElement();
  78. output.writeStartElement("body");
  79. var cdt = new Date(Date.now());
  80. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  81. var dateRange = dateSelect.currentRange();
  82. var startDate = dateRange[0];
  83. var endDate = dateRange[dateRange.length - 1];
  84. output.writeTextElement("h1", TTR("dailyproduction", "Production Summary: ") + startDate + " - " + endDate);
  85. var conversion = 1;
  86. var unitText = TTR("dailyproduction", "Lb");
  87. if(unitBox.currentIndex == 0) {
  88. conversion = 2.2;
  89. unitText = TTR("dailyproduction", "Kg");
  90. }
  91. var transaction_filter;
  92. var approval_filter;
  93. switch(batchType.currentIndex) {
  94. case 0:
  95. transaction_filter = "";
  96. break;
  97. case 1:
  98. transaction_filter = " AND transaction_type = 'ROAST'";
  99. break;
  100. case 2:
  101. transaction_filter = " AND transaction_type = 'SAMPLEROAST'";
  102. break;
  103. }
  104. switch(approval.currentIndex) {
  105. case 0:
  106. approval_filter = "";
  107. break;
  108. case 1:
  109. approval_filter = " AND approval = true";
  110. break;
  111. case 2:
  112. approval_filter = " AND approval = false";
  113. break;
  114. }
  115. var query = new QSqlQuery();
  116. 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);
  117. query.bind(":c1", conversion);
  118. query.bind(":c2", conversion);
  119. query.bind(":sd", startDate);
  120. query.bind(":ed", endDate);
  121. query.exec();
  122. query.next();
  123. var batchesRoasted = query.value(0);
  124. var unroastedSum = query.value(1);
  125. var roastedSum = query.value(2);
  126. output.writeTextElement("p", "" + roastedSum + " " + unitText + TTR("dailyproduction", " roasted from ") +
  127. unroastedSum + " " + unitText + TTR("dailyproduction", " green in ") +
  128. batchesRoasted + TTR("dailyproduction", " batches."));
  129. 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");
  130. query.bind(":c1", conversion);
  131. query.bind(":c2", conversion);
  132. query.bind(":sd", startDate);
  133. query.bind(":ed", endDate);
  134. query.exec();
  135. output.writeStartElement("table");
  136. output.writeAttribute("rules", "groups");
  137. output.writeAttribute("cellpadding", "3px");
  138. output.writeStartElement("thead");
  139. output.writeStartElement("tr");
  140. output.writeTextElement("th", TTR("dailyproduction", "Date"));
  141. output.writeTextElement("th", TTR("dailyproduction", "Batches"));
  142. output.writeTextElement("th", TTR("dailyproduction", "Unroasted (") + unitText + ")");
  143. output.writeTextElement("th", TTR("dailyproduction", "Roasted (") + unitText + ")");
  144. output.writeEndElement();
  145. output.writeEndElement();
  146. output.writeStartElement("tbody");
  147. while(query.next()) {
  148. output.writeStartElement("tr");
  149. output.writeStartElement("td");
  150. output.writeStartElement("a");
  151. output.writeAttribute("href", "typica://script/d" + query.value(0));
  152. output.writeCDATA(query.value(0));
  153. output.writeEndElement();
  154. output.writeEndElement();
  155. output.writeTextElement("td", query.value(1));
  156. output.writeTextElement("td", query.value(2));
  157. output.writeTextElement("td", query.value(3));
  158. output.writeEndElement();
  159. }
  160. output.writeEndElement();
  161. output.writeStartElement("tfoot");
  162. output.writeStartElement("tr");
  163. output.writeStartElement("td");
  164. output.writeTextElement("strong", TTR("dailyproduction", "Totals:"));
  165. output.writeEndElement();
  166. output.writeTextElement("td", batchesRoasted);
  167. output.writeTextElement("td", unroastedSum);
  168. output.writeTextElement("td", roastedSum);
  169. output.writeEndElement();
  170. output.writeEndElement();
  171. output.writeEndElement();
  172. output.writeEndElement();
  173. output.writeEndElement();
  174. output.writeEndDocument();
  175. view.setContent(buffer);
  176. buffer.close();
  177. query = query.invalidate();
  178. }
  179. refresh();
  180. dateSelect.rangeUpdated.connect(refresh);
  181. var notifier = Application.subscribe("roastinglogchange");
  182. notifier.notify.connect(function() {
  183. refresh();
  184. });
  185. view.scriptLinkClicked.connect(function(url) {
  186. var arg = url.slice(1, url.length).split("-");
  187. var details = createReport("dailyproductiondetail.xml");
  188. var selector = findChildObject(details, "reportdate");
  189. selector.setDate(arg[0], arg[1], arg[2]);
  190. });
  191. ]]>
  192. </program>
  193. </window>