Typica is a free program for professional coffee roasters. https://typica.us
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

historyreport.xml 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. output.writeStartElement("table");
  165. output.writeAttribute("style", "page-break-after: auto; text-align: left");
  166. output.writeAttribute("rules", "groups");
  167. output.writeAttribute("cellpadding", "3px");
  168. output.writeStartElement("thead");
  169. output.writeStartElement("tr");
  170. output.writeAttribute("valign", "bottom");
  171. output.writeTextElement("th", TTR("batchreport", "Time"));
  172. output.writeTextElement("th", TTR("batchreport", "File Numbers"));
  173. output.writeTextElement("th", TTR("batchreport", "Operator"));
  174. output.writeTextElement("th", TTR("batchreport", "Roasted Coffee"));
  175. output.writeEndElement();
  176. output.writeStartElement("tr");
  177. output.writeAttribute("valign", "bottom");
  178. output.writeEmptyElement("td");
  179. output.writeTextElement("th", TTR("batchreport", "Duration"));
  180. output.writeTextElement("th", TTR("batchreport", "Machine"));
  181. output.writeTextElement("th", TTR("batchreport", "Green Coffees"));
  182. output.writeEndElement();
  183. output.writeStartElement("tr");
  184. output.writeAttribute("valign", "bottom");
  185. output.writeEmptyElement("td");
  186. output.writeTextElement("th", TTR("batchreport", "Green Weight"));
  187. output.writeTextElement("th", TTR("batchreport", "Roasted Weight"));
  188. output.writeTextElement("th", TTR("batchreport", "% Weight Loss"));
  189. output.writeEndElement();
  190. output.writeStartElement("tr");
  191. output.writeAttribute("valign", "bottom");
  192. output.writeEmptyElement("td");
  193. output.writeStartElement("th");
  194. output.writeAttribute("colspan", "2");
  195. output.writeCharacters(TTR("batchreport", "Batch Notes"));
  196. output.writeEndElement();
  197. output.writeTextElement("th", TTR("batchreport", "Specification Notes"));
  198. output.writeEndElement();
  199. output.writeEndElement();
  200. output.writeStartElement("tbody");
  201. while(query.next()) {
  202. output.writeStartElement("tr");
  203. output.writeAttribute("valign", "top");
  204. output.writeStartElement("td");
  205. output.writeStartElement("a");
  206. output.writeAttribute("href", "typica://script/b/" + query.value(15));
  207. output.writeCharacters(query.value(0).replace("T", " "));
  208. output.writeEndElement();
  209. output.writeEndElement();
  210. output.writeStartElement("td");
  211. output.writeStartElement("a");
  212. output.writeAttribute("href", "typica://script/b/" + query.value(15));
  213. output.writeCharacters(query.value(1));
  214. output.writeEndElement();
  215. output.writeEndElement();
  216. output.writeTextElement("td", query.value(2));
  217. output.writeStartElement("td");
  218. output.writeStartElement("span");
  219. if(query.value(11) == "false") {
  220. output.writeAttribute("style", "color:#FF0000");
  221. }
  222. output.writeCharacters(query.value(3));
  223. output.writeEndElement();
  224. output.writeEndElement();
  225. output.writeEndElement();
  226. output.writeStartElement("tr");
  227. output.writeAttribute("valign", "top");
  228. output.writeEmptyElement("td");
  229. output.writeTextElement("td", query.value(4));
  230. output.writeTextElement("td", query.value(5));
  231. output.writeTextElement("td", query.value(6));
  232. output.writeEndElement();
  233. output.writeStartElement("tr");
  234. output.writeAttribute("valign", "top");
  235. output.writeEmptyElement("td");
  236. output.writeTextElement("td", query.value(7));
  237. output.writeTextElement("td", query.value(8));
  238. output.writeStartElement("td");
  239. output.writeStartElement("span");
  240. if(query.value(14) == "false" && query.value(12).length > 0) {
  241. output.writeAttribute("style", "color:#FF0000");
  242. } else if (query.value(14) === "true") {
  243. output.writeAttribute("style", "color:#00FF00");
  244. }
  245. output.writeAttribute("title", query.value(12));
  246. output.writeCharacters(query.value(9));
  247. output.writeEndElement();
  248. output.writeEndElement();
  249. output.writeEndElement();
  250. output.writeStartElement("tr");
  251. output.writeAttribute("valign", "top");
  252. output.writeEmptyElement("td");
  253. output.writeStartElement("td");
  254. output.writeAttribute("colspan", "2");
  255. output.writeAttribute("style", "max-width: 400px");
  256. var noteArray = query.value(10).split("\n");
  257. for(var i = 0; i < noteArray.length; i++) {
  258. output.writeStartElement("p");
  259. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  260. output.writeCharacters(noteArray[i]);
  261. output.writeEndElement();
  262. }
  263. output.writeEndElement();
  264. output.writeStartElement("td");
  265. output.writeAttribute("style", "max-width: 400px");
  266. var specArray = query.value(13).split("\n");
  267. for(var i = 0; i < specArray.length; i++) {
  268. output.writeStartElement("p", specArray[i]);
  269. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  270. output.writeCharacters(specArray[i]);
  271. output.writeEndElement();
  272. }
  273. output.writeEndElement();
  274. output.writeEndElement();
  275. }
  276. output.writeEndElement();
  277. output.writeStartElement("tfoot");
  278. output.writeStartElement("tr");
  279. output.writeAttribute("valign", "bottom");
  280. output.writeTextElement("th", TTR("batchreport", "Total Batches"));
  281. output.writeTextElement("th", TTR("batchreport", "Total Duration"));
  282. output.writeTextElement("th", TTR("batchreport", "Total Green Weight"));
  283. output.writeTextElement("th", TTR("batchreport", "Total Roasted Weight"));
  284. output.writeEndElement();
  285. output.writeStartElement("tr");
  286. output.writeAttribute("valign", "top");
  287. 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;
  288. var query = new QSqlQuery();
  289. query.prepare(q);
  290. query.bind(":c1", conversion);
  291. query.bind(":c2", conversion);
  292. query.bind(":sd", startDate);
  293. query.bind(":ed", endDate);
  294. if(searchClause.length > 0) {
  295. var pattern = ".*" + search.text + ".*";
  296. query.bind(":p1", pattern);
  297. query.bind(":p2", pattern);
  298. query.bind(":p3", pattern);
  299. query.bind(":p4", pattern);
  300. query.bind(":p5", pattern);
  301. query.bind(":p6", pattern);
  302. }
  303. query.exec();
  304. query.next();
  305. for(var i = 0; i < 4; i++) {
  306. output.writeTextElement("td", query.value(i));
  307. }
  308. output.writeEndElement();
  309. output.writeEndElement();
  310. query = query.invalidate();
  311. output.writeEndElement();
  312. output.writeEndElement();
  313. output.writeEndDocument();
  314. view.setContent(buffer);
  315. buffer.close();
  316. };
  317. refresh();
  318. ]]>
  319. </program>
  320. </window>