Typica is a free program for professional coffee roasters. https://typica.us
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

rwacp.xml 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. var cdt = new Date(Date.now());
  81. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  82. output.writeTextElement("h1", TTR("productionreport", "Recent Average Coffee Production"));
  83. switch(unitBox.currentIndex)
  84. {
  85. case 0:
  86. output.writeTextElement("p", TTR("productionreport", "This is a report of average coffee production per ") + scaleBox.text +
  87. TTR("productionreport", " days in kilograms over the past ") + daysBox.text +
  88. TTR("productionreport", " days."));
  89. break;
  90. case 1:
  91. output.writeTextElement("p", TTR("productionreport", "This is a report of average coffee production per ") + scaleBox.text +
  92. TTR("productionreport", " days in pounds over the past ") + daysBox.text +
  93. TTR("productionreport", " days."));
  94. break;
  95. }
  96. output.writeStartElement("table");
  97. output.writeAttribute("rules", "groups");
  98. output.writeAttribute("cellpadding", "3px");
  99. output.writeStartElement("thead");
  100. output.writeStartElement("tr");
  101. output.writeTextElement("th", TTR("productionreport", "Roasted Coffee"));
  102. output.writeTextElement("th", TTR("productionreport", "Weekly Use"));
  103. output.writeEndElement();
  104. output.writeEndElement();
  105. output.writeStartElement("tbody");
  106. var batchClause = "";
  107. switch(batchType.currentIndex) {
  108. case 1:
  109. batchClause = " AND transaction_type = 'ROAST'";
  110. break;
  111. case 2:
  112. batchClause = " AND transaction_type = 'SAMPLEROAST'";
  113. break;
  114. }
  115. 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 "
  116. switch(sortBox.currentIndex)
  117. {
  118. case 0:
  119. q += "name ASC";
  120. break;
  121. case 1:
  122. q += "name DESC";
  123. break;
  124. case 2:
  125. q += "weekly ASC";
  126. break;
  127. case 3:
  128. q += "weekly DESC";
  129. break;
  130. }
  131. var query = new QSqlQuery();
  132. query.prepare(q);
  133. switch(unitBox.currentIndex)
  134. {
  135. case 0:
  136. query.bind(":conversion", 2.2);
  137. break;
  138. case 1:
  139. query.bind(":conversion", 1);
  140. break;
  141. }
  142. query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
  143. query.exec();
  144. while(query.next())
  145. {
  146. output.writeStartElement("tr");
  147. output.writeTextElement("td", query.value(0));
  148. output.writeTextElement("td", query.value(1));
  149. output.writeEndElement();
  150. }
  151. output.writeEndElement();
  152. output.writeStartElement("tfoot")
  153. output.writeTextElement("th", TTR("productionreport", "Total:"));
  154. 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);
  155. switch(unitBox.currentIndex)
  156. {
  157. case 0:
  158. query.bind(":conversion", 2.2);
  159. break;
  160. case 1:
  161. query.bind(":conversion", 1);
  162. break;
  163. }
  164. query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
  165. query.exec();
  166. query.next();
  167. output.writeTextElement("td", query.value(0));
  168. query = query.invalidate();
  169. output.writeEndElement();
  170. output.writeEndElement();
  171. output.writeEndElement();
  172. output.writeEndElement();
  173. output.writeEndDocument();
  174. report.setContent(buffer);
  175. buffer.close();
  176. }
  177. refresh();
  178. sortBox['currentIndexChanged(int)'].connect(function() {
  179. QSettings.setValue("rwacp_sort", sortBox.currentIndex);
  180. refresh();
  181. });
  182. unitBox['currentIndexChanged(int)'].connect(function() {
  183. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  184. refresh();
  185. });
  186. var notifier = Application.subscribe("roastinglogchange");
  187. notifier.notify.connect(function() {
  188. refresh();
  189. });
  190. ]]>
  191. </program>
  192. </window>