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

rwacp.xml 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <window id="productionreport">
  2. <reporttitle>Production:->Recent Average Coffee Production</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <label>Sort Order:</label>
  6. <sqldrop id="sort" />
  7. <label>Weight Unit:</label>
  8. <sqldrop id="unit" />
  9. <label>Batch Type: </label>
  10. <sqldrop id="batchtype" />
  11. <label>Days to Average: </label>
  12. <line id="days" />
  13. <label>Days to Scale: </label>
  14. <line id="scale" />
  15. <stretch />
  16. </layout>
  17. <webview id="report" />
  18. </layout>
  19. <menu name="File">
  20. <item id="print" shortcut="Ctrl+P">Print</item>
  21. </menu>
  22. <program>
  23. <![CDATA[
  24. this.windowTitle = TTR("productionreport", "Typica - Recent Average Coffee Production");
  25. var report = findChildObject(this, 'report');
  26. var printMenu = findChildObject(this, 'print');
  27. printMenu.triggered.connect(function() {
  28. report.print();
  29. });
  30. var sortBox = findChildObject(this, 'sort');
  31. sortBox.addItem(TTR("productionreport", "Roasted Coffee A-Z"));
  32. sortBox.addItem(TTR("productionreport", "Roasted Coffee Z-A"));
  33. sortBox.addItem(TTR("productionreport", "Weekly Use Ascending"));
  34. sortBox.addItem(TTR("productionreport", "Weekly Use Descending"));
  35. sortBox.currentIndex = QSettings.value("rwacp_sort", 3);
  36. var unitBox = findChildObject(this, 'unit');
  37. unitBox.addItem(TTR("productionreport", "Kg"));
  38. unitBox.addItem(TTR("productionreport", "Lb"));
  39. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  40. var batchType = findChildObject(this, 'batchtype');
  41. batchType.addItem(TTR("productionreport", "Any"));
  42. batchType.addItem(TTR("productionreport", "Production Roasts"));
  43. batchType.addItem(TTR("productionreport", "Sample Roasts"));
  44. batchType.currentIndex = QSettings.value("script/racpreport/batchtypefilter", 1);
  45. batchType['currentIndexChanged(int)'].connect(function() {
  46. QSettings.setValue("script/racpreport/batchtypefilter",
  47. batchType.currentIndex);
  48. refresh();
  49. });
  50. var daysBox = findChildObject(this, 'days');
  51. daysBox.text = QSettings.value("script/racpreport/days", "28");
  52. daysBox.editingFinished.connect(function() {
  53. if(Number(daysBox.text) < 1) {
  54. daysBox.text = QSettings.value("script/racpreport/days");
  55. }
  56. QSettings.setValue("script/racpreport/days", daysBox.text);
  57. refresh();
  58. });
  59. var scaleBox = findChildObject(this, 'scale');
  60. scaleBox.text = QSettings.value("script/racpreport/scale", "7");
  61. scaleBox.editingFinished.connect(function() {
  62. if(Number(scaleBox.text) < 1) {
  63. scaleBox.text = QSettings.value("script/racpreport/scale");
  64. }
  65. QSettings.setValue("script/racpreport/scale", scaleBox.text);
  66. refresh();
  67. });
  68. function refresh() {
  69. var buffer = new QBuffer;
  70. buffer.open(3);
  71. var output = new XmlWriter(buffer);
  72. output.writeStartDocument("1.0");
  73. 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">');
  74. output.writeStartElement("html");
  75. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  76. output.writeStartElement("head");
  77. output.writeTextElement("title", TTR("productionreport", "Recent Average Coffee Production"));
  78. output.writeEndElement();
  79. output.writeStartElement("body");
  80. output.writeTextElement("h1", TTR("productionreport", "Recent Average Coffee Production"));
  81. switch(unitBox.currentIndex)
  82. {
  83. case 0:
  84. output.writeTextElement("p", TTR("productionreport", "This is a report of average coffee production per ") + scaleBox.text +
  85. TTR("productionreport", " days in kilograms over the past ") + daysBox.text +
  86. TTR("productionreport", " days."));
  87. break;
  88. case 1:
  89. output.writeTextElement("p", TTR("productionreport", "This is a report of average coffee production per ") + scaleBox.text +
  90. TTR("productionreport", " days in pounds over the past ") + daysBox.text +
  91. TTR("productionreport", " days."));
  92. break;
  93. }
  94. output.writeStartElement("table");
  95. output.writeAttribute("rules", "groups");
  96. output.writeAttribute("cellpadding", "3px");
  97. output.writeStartElement("thead");
  98. output.writeStartElement("tr");
  99. output.writeTextElement("th", TTR("productionreport", "Roasted Coffee"));
  100. output.writeTextElement("th", TTR("productionreport", "Weekly Use"));
  101. output.writeEndElement();
  102. output.writeEndElement();
  103. output.writeStartElement("tbody");
  104. var batchClause = "";
  105. switch(batchType.currentIndex) {
  106. case 1:
  107. batchClause = " AND transaction_type = 'ROAST'";
  108. break;
  109. case 2:
  110. batchClause = " AND transaction_type = 'SAMPLEROAST'";
  111. break;
  112. }
  113. var q = "SELECT (SELECT name FROM items WHERE id = roasted_id) AS name, ((sum(roasted_quantity) / :scale) / :conversion)::numeric(18,2) AS weekly FROM roasting_log WHERE time > current_date - integer '" + daysBox.text + "' AND roasted_quantity > 0 " + batchClause + " GROUP BY roasted_id ORDER BY "
  114. switch(sortBox.currentIndex)
  115. {
  116. case 0:
  117. q += "name ASC";
  118. break;
  119. case 1:
  120. q += "name DESC";
  121. break;
  122. case 2:
  123. q += "weekly ASC";
  124. break;
  125. case 3:
  126. q += "weekly DESC";
  127. break;
  128. }
  129. var query = new QSqlQuery();
  130. query.prepare(q);
  131. switch(unitBox.currentIndex)
  132. {
  133. case 0:
  134. query.bind(":conversion", 2.2);
  135. break;
  136. case 1:
  137. query.bind(":conversion", 1);
  138. break;
  139. }
  140. query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
  141. query.exec();
  142. while(query.next())
  143. {
  144. output.writeStartElement("tr");
  145. output.writeTextElement("td", query.value(0));
  146. output.writeTextElement("td", query.value(1));
  147. output.writeEndElement();
  148. }
  149. output.writeEndElement();
  150. output.writeStartElement("tfoot")
  151. output.writeTextElement("th", TTR("productionreport", "Total:"));
  152. query.prepare("SELECT ((sum(roasted_quantity) / :scale) / :conversion)::numeric(18,2) FROM roasting_log WHERE time > current_date - integer '" + daysBox.text + "' AND roasted_quantity > 0 " + batchClause);
  153. switch(unitBox.currentIndex)
  154. {
  155. case 0:
  156. query.bind(":conversion", 2.2);
  157. break;
  158. case 1:
  159. query.bind(":conversion", 1);
  160. break;
  161. }
  162. query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
  163. query.exec();
  164. query.next();
  165. output.writeTextElement("td", query.value(0));
  166. query = query.invalidate();
  167. output.writeEndElement();
  168. output.writeEndElement();
  169. output.writeEndElement();
  170. output.writeEndElement();
  171. output.writeEndDocument();
  172. report.setContent(buffer);
  173. buffer.close();
  174. }
  175. refresh();
  176. sortBox['currentIndexChanged(int)'].connect(function() {
  177. QSettings.setValue("rwacp_sort", sortBox.currentIndex);
  178. refresh();
  179. });
  180. unitBox['currentIndexChanged(int)'].connect(function() {
  181. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  182. refresh();
  183. });
  184. ]]>
  185. </program>
  186. </window>