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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. <menu name="Reports" type="reports" src="Reports" />
  23. <program>
  24. <![CDATA[
  25. this.windowTitle = TTR("productionreport", "Typica - Recent Average Coffee Production");
  26. var report = findChildObject(this, 'report');
  27. var printMenu = findChildObject(this, 'print');
  28. printMenu.triggered.connect(function() {
  29. report.print();
  30. });
  31. var sortBox = findChildObject(this, 'sort');
  32. sortBox.addItem(TTR("productionreport", "Roasted Coffee A-Z"));
  33. sortBox.addItem(TTR("productionreport", "Roasted Coffee Z-A"));
  34. sortBox.addItem(TTR("productionreport", "Weekly Use Ascending"));
  35. sortBox.addItem(TTR("productionreport", "Weekly Use Descending"));
  36. sortBox.currentIndex = QSettings.value("rwacp_sort", 3);
  37. var unitBox = findChildObject(this, 'unit');
  38. unitBox.addItem(TTR("productionreport", "Kg"));
  39. unitBox.addItem(TTR("productionreport", "Lb"));
  40. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  41. var batchType = findChildObject(this, 'batchtype');
  42. batchType.addItem(TTR("productionreport", "Any"));
  43. batchType.addItem(TTR("productionreport", "Production Roasts"));
  44. batchType.addItem(TTR("productionreport", "Sample Roasts"));
  45. batchType.currentIndex = QSettings.value("script/racpreport/batchtypefilter", 1);
  46. batchType['currentIndexChanged(int)'].connect(function() {
  47. QSettings.setValue("script/racpreport/batchtypefilter",
  48. batchType.currentIndex);
  49. refresh();
  50. });
  51. var daysBox = findChildObject(this, 'days');
  52. daysBox.text = QSettings.value("script/racpreport/days", "28");
  53. daysBox.editingFinished.connect(function() {
  54. if(Number(daysBox.text) < 1) {
  55. daysBox.text = QSettings.value("script/racpreport/days");
  56. }
  57. QSettings.setValue("script/racpreport/days", daysBox.text);
  58. refresh();
  59. });
  60. var scaleBox = findChildObject(this, 'scale');
  61. scaleBox.text = QSettings.value("script/racpreport/scale", "7");
  62. scaleBox.editingFinished.connect(function() {
  63. if(Number(scaleBox.text) < 1) {
  64. scaleBox.text = QSettings.value("script/racpreport/scale");
  65. }
  66. QSettings.setValue("script/racpreport/scale", scaleBox.text);
  67. refresh();
  68. });
  69. function refresh() {
  70. var buffer = new QBuffer;
  71. buffer.open(3);
  72. var output = new XmlWriter(buffer);
  73. output.writeStartDocument("1.0");
  74. 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">');
  75. output.writeStartElement("html");
  76. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  77. output.writeStartElement("head");
  78. output.writeTextElement("title", TTR("productionreport", "Recent Average Coffee Production"));
  79. output.writeEndElement();
  80. output.writeStartElement("body");
  81. var cdt = new Date(Date.now());
  82. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  83. output.writeTextElement("h1", TTR("productionreport", "Recent Average Coffee Production"));
  84. switch(unitBox.currentIndex)
  85. {
  86. case 0:
  87. output.writeTextElement("p", TTR("productionreport", "This is a report of average coffee production per ") + scaleBox.text +
  88. TTR("productionreport", " days in kilograms over the past ") + daysBox.text +
  89. TTR("productionreport", " days."));
  90. break;
  91. case 1:
  92. output.writeTextElement("p", TTR("productionreport", "This is a report of average coffee production per ") + scaleBox.text +
  93. TTR("productionreport", " days in pounds over the past ") + daysBox.text +
  94. TTR("productionreport", " days."));
  95. break;
  96. }
  97. output.writeStartElement("table");
  98. output.writeAttribute("rules", "groups");
  99. output.writeAttribute("cellpadding", "3px");
  100. output.writeStartElement("thead");
  101. output.writeStartElement("tr");
  102. output.writeTextElement("th", TTR("productionreport", "Roasted Coffee"));
  103. output.writeTextElement("th", TTR("productionreport", "Weekly Use"));
  104. output.writeEndElement();
  105. output.writeEndElement();
  106. output.writeStartElement("tbody");
  107. var batchClause = "";
  108. switch(batchType.currentIndex) {
  109. case 1:
  110. batchClause = " AND transaction_type = 'ROAST'";
  111. break;
  112. case 2:
  113. batchClause = " AND transaction_type = 'SAMPLEROAST'";
  114. break;
  115. }
  116. 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 "
  117. switch(sortBox.currentIndex)
  118. {
  119. case 0:
  120. q += "name ASC";
  121. break;
  122. case 1:
  123. q += "name DESC";
  124. break;
  125. case 2:
  126. q += "weekly ASC";
  127. break;
  128. case 3:
  129. q += "weekly DESC";
  130. break;
  131. }
  132. var query = new QSqlQuery();
  133. query.prepare(q);
  134. switch(unitBox.currentIndex)
  135. {
  136. case 0:
  137. query.bind(":conversion", 2.2);
  138. break;
  139. case 1:
  140. query.bind(":conversion", 1);
  141. break;
  142. }
  143. query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
  144. query.exec();
  145. while(query.next())
  146. {
  147. output.writeStartElement("tr");
  148. output.writeTextElement("td", query.value(0));
  149. output.writeTextElement("td", query.value(1));
  150. output.writeEndElement();
  151. }
  152. output.writeEndElement();
  153. output.writeStartElement("tfoot")
  154. output.writeTextElement("th", TTR("productionreport", "Total:"));
  155. 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);
  156. switch(unitBox.currentIndex)
  157. {
  158. case 0:
  159. query.bind(":conversion", 2.2);
  160. break;
  161. case 1:
  162. query.bind(":conversion", 1);
  163. break;
  164. }
  165. query.bind(":scale", Number(daysBox.text)/Number(scaleBox.text));
  166. query.exec();
  167. query.next();
  168. output.writeTextElement("td", query.value(0));
  169. query = query.invalidate();
  170. output.writeEndElement();
  171. output.writeEndElement();
  172. output.writeEndElement();
  173. output.writeEndElement();
  174. output.writeEndDocument();
  175. report.setContent(buffer);
  176. buffer.close();
  177. }
  178. refresh();
  179. sortBox['currentIndexChanged(int)'].connect(function() {
  180. QSettings.setValue("rwacp_sort", sortBox.currentIndex);
  181. refresh();
  182. });
  183. unitBox['currentIndexChanged(int)'].connect(function() {
  184. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  185. refresh();
  186. });
  187. var notifier = Application.subscribe("roastinglogchange");
  188. notifier.notify.connect(function() {
  189. refresh();
  190. });
  191. ]]>
  192. </program>
  193. </window>