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

productionsummary.xml 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 dateRange = dateSelect.currentRange();
  79. var startDate = dateRange[0];
  80. var endDate = dateRange[dateRange.length - 1];
  81. output.writeTextElement("h1", TTR("dailyproduction", "Production Summary: ") + startDate + " - " + endDate);
  82. var conversion = 1;
  83. var unitText = TTR("dailyproduction", "Lb");
  84. if(unitBox.currentIndex == 0) {
  85. conversion = 2.2;
  86. unitText = TTR("dailyproduction", "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 + TTR("dailyproduction", " roasted from ") +
  124. unroastedSum + " " + unitText + TTR("dailyproduction", " green in ") +
  125. batchesRoasted + TTR("dailyproduction", " batches."));
  126. 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");
  127. query.bind(":c1", conversion);
  128. query.bind(":c2", conversion);
  129. query.bind(":sd", startDate);
  130. query.bind(":ed", endDate);
  131. query.exec();
  132. output.writeStartElement("table");
  133. output.writeAttribute("rules", "groups");
  134. output.writeAttribute("cellpadding", "3px");
  135. output.writeStartElement("thead");
  136. output.writeStartElement("tr");
  137. output.writeTextElement("th", TTR("dailyproduction", "Date"));
  138. output.writeTextElement("th", TTR("dailyproduction", "Batches"));
  139. output.writeTextElement("th", TTR("dailyproduction", "Unroasted (") + unitText + ")");
  140. output.writeTextElement("th", TTR("dailyproduction", "Roasted (") + unitText + ")");
  141. output.writeEndElement();
  142. output.writeEndElement();
  143. output.writeStartElement("tbody");
  144. while(query.next()) {
  145. output.writeStartElement("tr");
  146. output.writeStartElement("td");
  147. output.writeStartElement("a");
  148. output.writeAttribute("href", "typica://script/d" + query.value(0));
  149. output.writeCDATA(query.value(0));
  150. output.writeEndElement();
  151. output.writeEndElement();
  152. output.writeTextElement("td", query.value(1));
  153. output.writeTextElement("td", query.value(2));
  154. output.writeTextElement("td", query.value(3));
  155. output.writeEndElement();
  156. }
  157. output.writeEndElement();
  158. output.writeStartElement("tfoot");
  159. output.writeStartElement("tr");
  160. output.writeStartElement("td");
  161. output.writeTextElement("strong", TTR("dailyproduction", "Totals:"));
  162. output.writeEndElement();
  163. output.writeTextElement("td", batchesRoasted);
  164. output.writeTextElement("td", unroastedSum);
  165. output.writeTextElement("td", roastedSum);
  166. output.writeEndElement();
  167. output.writeEndElement();
  168. output.writeEndElement();
  169. output.writeEndElement();
  170. output.writeEndElement();
  171. output.writeEndDocument();
  172. view.setContent(buffer);
  173. buffer.close();
  174. query = query.invalidate();
  175. }
  176. refresh();
  177. dateSelect.rangeUpdated.connect(refresh);
  178. view.scriptLinkClicked.connect(function(url) {
  179. var arg = url.slice(1, url.length).split("-");
  180. var details = createReport("dailyproductiondetail.xml");
  181. var selector = findChildObject(details, "reportdate");
  182. selector.setDate(arg[0], arg[1], arg[2]);
  183. });
  184. ]]>
  185. </program>
  186. </window>