Typica is a free program for professional coffee roasters. https://typica.us
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

rwacp.xml 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 = "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("Roasted Coffee A-Z");
  32. sortBox.addItem("Roasted Coffee Z-A");
  33. sortBox.addItem("Weekly Use Ascending");
  34. sortBox.addItem("Weekly Use Descending");
  35. sortBox.currentIndex = QSettings.value("rwacp_sort", 3);
  36. var unitBox = findChildObject(this, 'unit');
  37. unitBox.addItem("Kg");
  38. unitBox.addItem("Lb");
  39. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  40. var batchType = findChildObject(this, 'batchtype');
  41. batchType.addItem("Any");
  42. batchType.addItem("Production Roasts");
  43. batchType.addItem("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", "Recent Average Coffee Production");
  78. output.writeEndElement();
  79. output.writeStartElement("body");
  80. output.writeTextElement("h1", "Recent Average Coffee Production");
  81. switch(unitBox.currentIndex)
  82. {
  83. case 0:
  84. output.writeTextElement("p", "This is a report of average coffee production per " + scaleBox.text + " days in kilograms over the past " + daysBox.text + " days.");
  85. break;
  86. case 1:
  87. output.writeTextElement("p", "This is a report of average coffee production per " + scaleBox.text + " days in pounds over the past " + daysBox.text + " days.");
  88. break;
  89. }
  90. output.writeStartElement("table");
  91. output.writeAttribute("rules", "groups");
  92. output.writeAttribute("cellpadding", "3px");
  93. output.writeStartElement("thead");
  94. output.writeStartElement("tr");
  95. output.writeTextElement("th", "Roasted Coffee");
  96. output.writeTextElement("th", "Weekly Use");
  97. output.writeEndElement();
  98. output.writeEndElement();
  99. output.writeStartElement("tbody");
  100. var batchClause = "";
  101. switch(batchType.currentIndex) {
  102. case 1:
  103. batchClause = " AND transaction_type = 'ROAST'";
  104. break;
  105. case 2:
  106. batchClause = " AND transaction_type = 'SAMPLEROAST'";
  107. break;
  108. }
  109. 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 "
  110. switch(sortBox.currentIndex)
  111. {
  112. case 0:
  113. q += "name ASC";
  114. break;
  115. case 1:
  116. q += "name DESC";
  117. break;
  118. case 2:
  119. q += "weekly ASC";
  120. break;
  121. case 3:
  122. q += "weekly DESC";
  123. break;
  124. }
  125. var query = new QSqlQuery();
  126. query.prepare(q);
  127. switch(unitBox.currentIndex)
  128. {
  129. case 0:
  130. query.bind(":conversion", 2.2);
  131. break;
  132. case 1:
  133. query.bind(":conversion", 1);
  134. break;
  135. }
  136. query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
  137. query.exec();
  138. while(query.next())
  139. {
  140. output.writeStartElement("tr");
  141. output.writeTextElement("td", query.value(0));
  142. output.writeTextElement("td", query.value(1));
  143. output.writeEndElement();
  144. }
  145. output.writeEndElement();
  146. output.writeStartElement("tfoot")
  147. output.writeTextElement("th", "Total");
  148. 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);
  149. switch(unitBox.currentIndex)
  150. {
  151. case 0:
  152. query.bind(":conversion", 2.2);
  153. break;
  154. case 1:
  155. query.bind(":conversion", 1);
  156. break;
  157. }
  158. query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
  159. query.exec();
  160. query.next();
  161. output.writeTextElement("td", query.value(0));
  162. query = query.invalidate();
  163. output.writeEndElement();
  164. output.writeEndElement();
  165. output.writeEndElement();
  166. output.writeEndElement();
  167. output.writeEndDocument();
  168. report.setContent(buffer);
  169. buffer.close();
  170. }
  171. refresh();
  172. sortBox['currentIndexChanged(int)'].connect(function() {
  173. QSettings.setValue("rwacp_sort", sortBox.currentIndex);
  174. refresh();
  175. });
  176. unitBox['currentIndexChanged(int)'].connect(function() {
  177. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  178. refresh();
  179. });
  180. ]]>
  181. </program>
  182. </window>