Typica is a free program for professional coffee roasters. https://typica.us
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

historyreport.xml 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <window id="batchreport">
  2. <reporttitle>Production:->Batch Log</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <daterange id="dates" initial="6" /><!-- Last 7 Days -->
  6. <label>Batch Type: </label>
  7. <sqldrop id="batchtype" />
  8. <label>Approval: </label>
  9. <sqldrop id="approval" />
  10. <label>Search: </label>
  11. <line id="search" />
  12. <label>Weight Unit:</label>
  13. <sqldrop id="unit" />
  14. <stretch />
  15. </layout>
  16. <webview id="report" />
  17. </layout>
  18. <menu name="File">
  19. <item id="print" shortcut="Ctrl+P">Print...</item>
  20. </menu>
  21. <program>
  22. <![CDATA[
  23. this.setWindowTitle(TTR("batchreport", "Typica - Batch Log"));
  24. var dateSelect = findChildObject(this, 'dates');
  25. var dateQuery = new QSqlQuery();
  26. 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");
  27. dateQuery.next();
  28. var lifetimeStartDate = dateQuery.value(0);
  29. var lifetimeEndDate;
  30. if(dateQuery.next()) {
  31. lifetimeEndDate = dateQuery.value(0);
  32. } else {
  33. lifetimeEndDate = lifetimeStartDate;
  34. }
  35. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  36. dateQuery = dateQuery.invalidate();
  37. dateSelect.currentIndex = QSettings.value("script/history/dateIndex", 6);
  38. dateSelect.rangeUpdated.connect(function() {
  39. if(dateSelect.currentIndex != 24) {
  40. QSettings.setValue("script/history/dateIndex", dateSelect.currentIndex);
  41. }
  42. refresh();
  43. });
  44. var unitBox = findChildObject(this, 'unit');
  45. unitBox.addItem(TTR("batchreport", "Kg"));
  46. unitBox.addItem(TTR("batchreport", "Lb"));
  47. unitBox.currentIndex = QSettings.value("script/history_unit", 1);
  48. unitBox['currentIndexChanged(int)'].connect(function() {
  49. QSettings.setValue("script/history_unit", unitBox.currentIndex);
  50. refresh();
  51. });
  52. var batchType = findChildObject(this, 'batchtype');
  53. batchType.addItem(TTR("batchreport", "Any"));
  54. batchType.addItem(TTR("batchreport", "Production Roasts"));
  55. batchType.addItem(TTR("batchreport", "Sample Roasts"));
  56. batchType.currentIndex = QSettings.value("script/history/batchtypefilter", 1);
  57. batchType['currentIndexChanged(int)'].connect(function() {
  58. QSettings.setValue("script/history/batchtypefilter", batchType.currentIndex);
  59. refresh();
  60. });
  61. var approval = findChildObject(this, 'approval');
  62. approval.addItem(TTR("batchreport", "Any"));
  63. approval.addItem(TTR("batchreport", "Approved"));
  64. approval.addItem(TTR("batchreport", "Not Approved"));
  65. approval.currentIndex = QSettings.value("script/history/approvalfilter", 1);
  66. approval['currentIndexChanged(int)'].connect(function() {
  67. QSettings.setValue("script/history/approvalfilter", approval.currentIndex);
  68. refresh();
  69. });
  70. var search = findChildObject(this, 'search');
  71. search.editingFinished.connect(function() {
  72. refresh();
  73. });
  74. var view = findChildObject(this, 'report');
  75. var printMenu = findChildObject(this, 'print');
  76. printMenu.triggered.connect(function() {
  77. view.print();
  78. });
  79. view.scriptLinkClicked.connect(function(url) {
  80. var arg = decodeURI(url.slice(2, url.length));
  81. var key = arg.split("@");
  82. var details = createWindow("batchDetails");
  83. var fakeTable = new Object;
  84. fakeTable.holding = new Array(7);
  85. fakeTable.data = function(r, c) {
  86. return this.holding[c];
  87. };
  88. var conversion = 1;
  89. if(unitBox.currentIndex == 0) {
  90. conversion = 2.2;
  91. }
  92. var query = new QSqlQuery();
  93. var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity / " + conversion + " AS green, roasted_quantity / " + conversion + " AS roasted, CASE WHEN unroasted_total_quantity = 0 THEN NULL ELSE ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) END AS weight_loss, duration, annotation FROM roasting_log WHERE machine = :machine AND time = :time";
  94. query.prepare(q);
  95. query.bind(":machine", key[0]);
  96. query.bind(":time", key[1]);
  97. query.exec();
  98. query.next();
  99. for(var i = 0; i < 8; i++) {
  100. fakeTable.holding[i] = query.value(i);
  101. }
  102. fakeTable.holding[0] = key[1];
  103. query = query.invalidate();
  104. details.loadData(fakeTable, 0);
  105. });
  106. var refresh = function() {
  107. var dateRange = dateSelect.currentRange();
  108. var startDate = dateRange[0];
  109. var endDate = dateRange[dateRange.length - 1];
  110. var conversion = 1;
  111. if(unitBox.currentIndex == 0) {
  112. conversion = 2.2;
  113. }
  114. var approvalClause = "";
  115. switch(approval.currentIndex) {
  116. case 1:
  117. approvalClause = " AND approval = true";
  118. break;
  119. case 2:
  120. approvalClause = " AND approval = false";
  121. break;
  122. }
  123. var batchClause = "";
  124. switch(batchType.currentIndex) {
  125. case 1:
  126. batchClause = " AND transaction_type = 'ROAST'";
  127. break;
  128. case 2:
  129. batchClause = " AND transaction_type = 'SAMPLEROAST'";
  130. break;
  131. }
  132. var searchClause = "";
  133. if(search.text.length > 0) {
  134. searchClause = " WHERE (person ~* :p1 OR rname ~* :p2 OR mname ~* :p3 OR greens ~* :p4 OR annotation ~* :p5 OR array_to_string(files, ',') ~* :p6)";
  135. }
  136. var q = "WITH qq AS (SELECT roasting_log.time, array_to_string(files, ','), person, (SELECT name || ' (' || id || ')' FROM items WHERE id = roasted_id) AS rname, duration, (SELECT name FROM machine WHERE id = machine) AS mname, array_to_string(ARRAY(SELECT name || ' (' || id || ')' FROM items WHERE id IN (SELECT unnest(unroasted_id))), ',') AS greens, (unroasted_total_quantity/:c1)::numeric(12,2), (roasted_quantity/:c2)::numeric(12,2), loss, annotation, approval, spec_loss::numeric(12,2) || '±' || spec_tolerance::numeric(12,2) AS lspec, notes, loss_match, machine || '@' || roasting_log.time AS link, files FROM roasting_log, LATERAL (SELECT CASE WHEN (unroasted_total_quantity = 0) THEN NULL ELSE (((unroasted_total_quantity - roasted_quantity)/unroasted_total_quantity)*100)::numeric(12,2) END AS loss) lc, LATERAL (WITH q AS (SELECT (SELECT min(time) - interval '10 years' FROM roasting_log) AS time, NULL::numeric AS loss, NULL::numeric AS tolerance, NULL::text AS notes) SELECT time, (loss*100)::numeric(12,2) AS spec_loss, (tolerance*100)::numeric(12,2) AS spec_tolerance, notes FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id) UNION (SELECT * FROM q) ORDER BY time DESC LIMIT 1) spec, LATERAL (SELECT loss >= spec_loss - spec_tolerance AND loss <= spec_loss + spec_tolerance AS loss_match) m WHERE roasting_log.time >= :sd AND roasting_log.time < :ed::date + interval '1 day'" + approvalClause + batchClause + ") SELECT * FROM qq" + searchClause + " ORDER BY time DESC";
  137. var query = new QSqlQuery();
  138. query.prepare(q);
  139. query.bind(":c1", conversion);
  140. query.bind(":c2", conversion);
  141. query.bind(":sd", startDate);
  142. query.bind(":ed", endDate);
  143. if(searchClause.length > 0) {
  144. var pattern = ".*" + search.text + ".*";
  145. query.bind(":p1", pattern);
  146. query.bind(":p2", pattern);
  147. query.bind(":p3", pattern);
  148. query.bind(":p4", pattern);
  149. query.bind(":p5", pattern);
  150. query.bind(":p6", pattern);
  151. }
  152. query.exec();
  153. var buffer = new QBuffer;
  154. buffer.open(3);
  155. var output = new XmlWriter(buffer);
  156. output.writeStartDocument("1.0");
  157. 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">');
  158. output.writeStartElement("html");
  159. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  160. output.writeStartElement("head");
  161. output.writeTextElement("title", TTR("batchreport", "Batch Log"));
  162. output.writeEndElement();
  163. output.writeStartElement("body");
  164. var cdt = new Date(Date.now());
  165. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  166. output.writeStartElement("table");
  167. output.writeAttribute("style", "page-break-after: auto; text-align: left");
  168. output.writeAttribute("rules", "groups");
  169. output.writeAttribute("cellpadding", "3px");
  170. output.writeStartElement("thead");
  171. output.writeStartElement("tr");
  172. output.writeAttribute("valign", "bottom");
  173. output.writeTextElement("th", TTR("batchreport", "Time"));
  174. output.writeTextElement("th", TTR("batchreport", "File Numbers"));
  175. output.writeTextElement("th", TTR("batchreport", "Operator"));
  176. output.writeTextElement("th", TTR("batchreport", "Roasted Coffee"));
  177. output.writeEndElement();
  178. output.writeStartElement("tr");
  179. output.writeAttribute("valign", "bottom");
  180. output.writeEmptyElement("td");
  181. output.writeTextElement("th", TTR("batchreport", "Duration"));
  182. output.writeTextElement("th", TTR("batchreport", "Machine"));
  183. output.writeTextElement("th", TTR("batchreport", "Green Coffees"));
  184. output.writeEndElement();
  185. output.writeStartElement("tr");
  186. output.writeAttribute("valign", "bottom");
  187. output.writeEmptyElement("td");
  188. output.writeTextElement("th", TTR("batchreport", "Green Weight"));
  189. output.writeTextElement("th", TTR("batchreport", "Roasted Weight"));
  190. output.writeTextElement("th", TTR("batchreport", "% Weight Loss"));
  191. output.writeEndElement();
  192. output.writeStartElement("tr");
  193. output.writeAttribute("valign", "bottom");
  194. output.writeEmptyElement("td");
  195. output.writeStartElement("th");
  196. output.writeAttribute("colspan", "2");
  197. output.writeCharacters(TTR("batchreport", "Batch Notes"));
  198. output.writeEndElement();
  199. output.writeTextElement("th", TTR("batchreport", "Specification Notes"));
  200. output.writeEndElement();
  201. output.writeEndElement();
  202. output.writeStartElement("tbody");
  203. while(query.next()) {
  204. output.writeStartElement("tr");
  205. output.writeAttribute("valign", "top");
  206. output.writeStartElement("td");
  207. output.writeStartElement("a");
  208. output.writeAttribute("href", "typica://script/b/" + query.value(15));
  209. output.writeCharacters(query.value(0).replace("T", " "));
  210. output.writeEndElement();
  211. output.writeEndElement();
  212. output.writeStartElement("td");
  213. output.writeStartElement("a");
  214. output.writeAttribute("href", "typica://script/b/" + query.value(15));
  215. output.writeCharacters(query.value(1));
  216. output.writeEndElement();
  217. output.writeEndElement();
  218. output.writeTextElement("td", query.value(2));
  219. output.writeStartElement("td");
  220. output.writeStartElement("span");
  221. if(query.value(11) == "false") {
  222. output.writeAttribute("style", "color:#FF0000");
  223. }
  224. output.writeCharacters(query.value(3));
  225. output.writeEndElement();
  226. output.writeEndElement();
  227. output.writeEndElement();
  228. output.writeStartElement("tr");
  229. output.writeAttribute("valign", "top");
  230. output.writeEmptyElement("td");
  231. output.writeTextElement("td", query.value(4));
  232. output.writeTextElement("td", query.value(5));
  233. output.writeTextElement("td", query.value(6));
  234. output.writeEndElement();
  235. output.writeStartElement("tr");
  236. output.writeAttribute("valign", "top");
  237. output.writeEmptyElement("td");
  238. output.writeTextElement("td", query.value(7));
  239. output.writeTextElement("td", query.value(8));
  240. output.writeStartElement("td");
  241. output.writeStartElement("span");
  242. if(query.value(14) == "false" && query.value(12).length > 0) {
  243. output.writeAttribute("style", "color:#FF0000");
  244. } else if (query.value(14) === "true") {
  245. output.writeAttribute("style", "color:#00FF00");
  246. }
  247. output.writeAttribute("title", query.value(12));
  248. output.writeCharacters(query.value(9));
  249. output.writeEndElement();
  250. output.writeEndElement();
  251. output.writeEndElement();
  252. output.writeStartElement("tr");
  253. output.writeAttribute("valign", "top");
  254. output.writeEmptyElement("td");
  255. output.writeStartElement("td");
  256. output.writeAttribute("colspan", "2");
  257. output.writeAttribute("style", "max-width: 400px");
  258. var noteArray = query.value(10).split("\n");
  259. for(var i = 0; i < noteArray.length; i++) {
  260. output.writeStartElement("p");
  261. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  262. output.writeCharacters(noteArray[i]);
  263. output.writeEndElement();
  264. }
  265. output.writeEndElement();
  266. output.writeStartElement("td");
  267. output.writeAttribute("style", "max-width: 400px");
  268. var specArray = query.value(13).split("\n");
  269. for(var i = 0; i < specArray.length; i++) {
  270. output.writeStartElement("p", specArray[i]);
  271. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  272. output.writeCharacters(specArray[i]);
  273. output.writeEndElement();
  274. }
  275. output.writeEndElement();
  276. output.writeEndElement();
  277. }
  278. output.writeEndElement();
  279. output.writeStartElement("tfoot");
  280. output.writeStartElement("tr");
  281. output.writeAttribute("valign", "bottom");
  282. output.writeTextElement("th", TTR("batchreport", "Total Batches"));
  283. output.writeTextElement("th", TTR("batchreport", "Total Duration"));
  284. output.writeTextElement("th", TTR("batchreport", "Total Green Weight"));
  285. output.writeTextElement("th", TTR("batchreport", "Total Roasted Weight"));
  286. output.writeEndElement();
  287. output.writeStartElement("tr");
  288. output.writeAttribute("valign", "top");
  289. q = "WITH qq AS (SELECT roasting_log.time, array_to_string(files, ','), person, (SELECT name || ' (' || id || ')' FROM items WHERE id = roasted_id) AS rname, duration, (SELECT name FROM machine WHERE id = machine) AS mname, array_to_string(ARRAY(SELECT name || ' (' || id || ')' FROM items WHERE id IN (SELECT unnest(unroasted_id))), ',') AS greens, (unroasted_total_quantity/:c1)::numeric(12,2) AS uq, (roasted_quantity/:c2)::numeric(12,2) AS rq, annotation, approval, files FROM roasting_log WHERE roasting_log.time >= :sd AND roasting_log.time < :ed::date + interval '1 day'" + approvalClause + batchClause + ") SELECT count(1), sum(duration), sum(uq), sum(rq) FROM qq" + searchClause;
  290. var query = new QSqlQuery();
  291. query.prepare(q);
  292. query.bind(":c1", conversion);
  293. query.bind(":c2", conversion);
  294. query.bind(":sd", startDate);
  295. query.bind(":ed", endDate);
  296. if(searchClause.length > 0) {
  297. var pattern = ".*" + search.text + ".*";
  298. query.bind(":p1", pattern);
  299. query.bind(":p2", pattern);
  300. query.bind(":p3", pattern);
  301. query.bind(":p4", pattern);
  302. query.bind(":p5", pattern);
  303. query.bind(":p6", pattern);
  304. }
  305. query.exec();
  306. query.next();
  307. for(var i = 0; i < 4; i++) {
  308. output.writeTextElement("td", query.value(i));
  309. }
  310. output.writeEndElement();
  311. output.writeEndElement();
  312. query = query.invalidate();
  313. output.writeEndElement();
  314. output.writeEndElement();
  315. output.writeEndDocument();
  316. view.setContent(buffer);
  317. buffer.close();
  318. };
  319. refresh();
  320. ]]>
  321. </program>
  322. </window>