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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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("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("Kg");
  46. unitBox.addItem("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("Any");
  54. batchType.addItem("Production Roasts");
  55. batchType.addItem("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("Any");
  63. approval.addItem("Approved");
  64. approval.addItem("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. print("Handling click with key " + key);
  83. var details = createWindow("batchDetails");
  84. var fakeTable = new Object;
  85. fakeTable.holding = new Array(7);
  86. fakeTable.data = function(r, c) {
  87. return this.holding[c];
  88. };
  89. var conversion = 1;
  90. if(unitBox.currentIndex == 0) {
  91. conversion = 2.2;
  92. }
  93. var query = new QSqlQuery();
  94. var q = "SELECT to_char(time, 'Dy Mon DD YYYY HH24:MI:SS'), 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";
  95. query.prepare(q);
  96. query.bind(":machine", key[0]);
  97. query.bind(":time", key[1]);
  98. query.exec();
  99. query.next();
  100. for(var i = 0; i < 8; i++) {
  101. print("Constructing row with " + query.value(i));
  102. fakeTable.holding[i] = query.value(i);
  103. }
  104. query = query.invalidate();
  105. details.loadData(fakeTable, 0);
  106. });
  107. var refresh = function() {
  108. var dateRange = dateSelect.currentRange();
  109. var startDate = dateRange[0];
  110. var endDate = dateRange[dateRange.length - 1];
  111. var conversion = 1;
  112. if(unitBox.currentIndex == 0) {
  113. conversion = 2.2;
  114. }
  115. var approvalClause = "";
  116. switch(approval.currentIndex) {
  117. case 1:
  118. approvalClause = " AND approval = true";
  119. break;
  120. case 2:
  121. approvalClause = " AND approval = false";
  122. break;
  123. }
  124. var batchClause = "";
  125. switch(batchType.currentIndex) {
  126. case 1:
  127. batchClause = " AND transaction_type = 'ROAST'";
  128. break;
  129. case 2:
  130. batchClause = " AND transaction_type = 'SAMPLEROAST'";
  131. break;
  132. }
  133. var searchClause = "";
  134. if(search.text.length > 0) {
  135. searchClause = " WHERE (person ~* :p1 OR rname ~* :p2 OR mname ~* :p3 OR greens ~* :p4 OR annotation ~* :p5 OR array_to_string(files, ',') ~* :p6)";
  136. }
  137. 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";
  138. var query = new QSqlQuery();
  139. query.prepare(q);
  140. query.bind(":c1", conversion);
  141. query.bind(":c2", conversion);
  142. query.bind(":sd", startDate);
  143. query.bind(":ed", endDate);
  144. if(searchClause.length > 0) {
  145. var pattern = ".*" + search.text + ".*";
  146. query.bind(":p1", pattern);
  147. query.bind(":p2", pattern);
  148. query.bind(":p3", pattern);
  149. query.bind(":p4", pattern);
  150. query.bind(":p5", pattern);
  151. query.bind(":p6", pattern);
  152. }
  153. query.exec();
  154. var buffer = new QBuffer;
  155. buffer.open(3);
  156. var output = new XmlWriter(buffer);
  157. output.writeStartDocument("1.0");
  158. 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">');
  159. output.writeStartElement("html");
  160. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  161. output.writeStartElement("head");
  162. output.writeTextElement("title", "Batch Log");
  163. output.writeEndElement();
  164. output.writeStartElement("body");
  165. output.writeStartElement("table");
  166. output.writeAttribute("style", "page-break-after: auto; text-align: left");
  167. output.writeAttribute("rules", "groups");
  168. output.writeAttribute("cellpadding", "3px");
  169. output.writeStartElement("thead");
  170. output.writeStartElement("tr");
  171. output.writeAttribute("valign", "bottom");
  172. output.writeTextElement("th", "Time");
  173. output.writeTextElement("th", "File Numbers");
  174. output.writeTextElement("th", "Operator");
  175. output.writeTextElement("th", "Roasted Coffee");
  176. output.writeEndElement();
  177. output.writeStartElement("tr");
  178. output.writeAttribute("valign", "bottom");
  179. output.writeEmptyElement("td");
  180. output.writeTextElement("th", "Duration");
  181. output.writeTextElement("th", "Machine");
  182. output.writeTextElement("th", "Green Coffees");
  183. output.writeEndElement();
  184. output.writeStartElement("tr");
  185. output.writeAttribute("valign", "bottom");
  186. output.writeEmptyElement("td");
  187. output.writeTextElement("th", "Green Weight");
  188. output.writeTextElement("th", "Roasted Weight");
  189. output.writeTextElement("th", "% Weight Loss");
  190. output.writeEndElement();
  191. output.writeStartElement("tr");
  192. output.writeAttribute("valign", "bottom");
  193. output.writeEmptyElement("td");
  194. output.writeStartElement("th");
  195. output.writeAttribute("colspan", "2");
  196. output.writeCharacters("Batch Notes");
  197. output.writeEndElement();
  198. output.writeTextElement("th", "Specification Notes");
  199. output.writeEndElement();
  200. output.writeEndElement();
  201. output.writeStartElement("tbody");
  202. while(query.next()) {
  203. output.writeStartElement("tr");
  204. output.writeAttribute("valign", "top");
  205. output.writeStartElement("td");
  206. output.writeStartElement("a");
  207. output.writeAttribute("href", "typica://script/b/" + query.value(15));
  208. output.writeCharacters(query.value(0).replace("T", " "));
  209. output.writeEndElement();
  210. output.writeEndElement();
  211. output.writeStartElement("td");
  212. output.writeStartElement("a");
  213. output.writeAttribute("href", "typica://script/b/" + query.value(15));
  214. output.writeCharacters(query.value(1));
  215. output.writeEndElement();
  216. output.writeEndElement();
  217. output.writeTextElement("td", query.value(2));
  218. output.writeStartElement("td");
  219. output.writeStartElement("span");
  220. if(query.value(11) == "false") {
  221. output.writeAttribute("style", "color:#FF0000");
  222. }
  223. output.writeCharacters(query.value(3));
  224. output.writeEndElement();
  225. output.writeEndElement();
  226. output.writeEndElement();
  227. output.writeStartElement("tr");
  228. output.writeAttribute("valign", "top");
  229. output.writeEmptyElement("td");
  230. output.writeTextElement("td", query.value(4));
  231. output.writeTextElement("td", query.value(5));
  232. output.writeTextElement("td", query.value(6));
  233. output.writeEndElement();
  234. output.writeStartElement("tr");
  235. output.writeAttribute("valign", "top");
  236. output.writeEmptyElement("td");
  237. output.writeTextElement("td", query.value(7));
  238. output.writeTextElement("td", query.value(8));
  239. output.writeStartElement("td");
  240. output.writeStartElement("span");
  241. if(query.value(14) == "false" && query.value(12).length > 0) {
  242. output.writeAttribute("style", "color:#FF0000");
  243. } else if (query.value(14) === "true") {
  244. output.writeAttribute("style", "color:#00FF00");
  245. }
  246. output.writeAttribute("title", query.value(12));
  247. output.writeCharacters(query.value(9));
  248. output.writeEndElement();
  249. output.writeEndElement();
  250. output.writeEndElement();
  251. output.writeStartElement("tr");
  252. output.writeAttribute("valign", "top");
  253. output.writeEmptyElement("td");
  254. output.writeStartElement("td");
  255. output.writeAttribute("colspan", "2");
  256. output.writeAttribute("style", "max-width: 400px");
  257. var noteArray = query.value(10).split("\n");
  258. for(var i = 0; i < noteArray.length; i++) {
  259. output.writeStartElement("p");
  260. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  261. output.writeCharacters(noteArray[i]);
  262. output.writeEndElement();
  263. }
  264. output.writeEndElement();
  265. output.writeStartElement("td");
  266. output.writeAttribute("style", "max-width: 400px");
  267. var specArray = query.value(13).split("\n");
  268. for(var i = 0; i < specArray.length; i++) {
  269. output.writeStartElement("p", specArray[i]);
  270. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  271. output.writeCharacters(specArray[i]);
  272. output.writeEndElement();
  273. }
  274. output.writeEndElement();
  275. output.writeEndElement();
  276. }
  277. output.writeEndElement();
  278. output.writeStartElement("tfoot");
  279. output.writeStartElement("tr");
  280. output.writeAttribute("valign", "bottom");
  281. output.writeTextElement("th", "Total Batches");
  282. output.writeTextElement("th", "Total Duration");
  283. output.writeTextElement("th", "Total Green Weight");
  284. output.writeTextElement("th", "Total Roasted Weight");
  285. output.writeEndElement();
  286. output.writeStartElement("tr");
  287. output.writeAttribute("valign", "top");
  288. 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;
  289. var query = new QSqlQuery();
  290. query.prepare(q);
  291. query.bind(":c1", conversion);
  292. query.bind(":c2", conversion);
  293. query.bind(":sd", startDate);
  294. query.bind(":ed", endDate);
  295. if(searchClause.length > 0) {
  296. var pattern = ".*" + search.text + ".*";
  297. query.bind(":p1", pattern);
  298. query.bind(":p2", pattern);
  299. query.bind(":p3", pattern);
  300. query.bind(":p4", pattern);
  301. query.bind(":p5", pattern);
  302. query.bind(":p6", pattern);
  303. }
  304. query.exec();
  305. query.next();
  306. for(var i = 0; i < 4; i++) {
  307. output.writeTextElement("td", query.value(i));
  308. }
  309. output.writeEndElement();
  310. output.writeEndElement();
  311. query = query.invalidate();
  312. output.writeEndElement();
  313. output.writeEndElement();
  314. output.writeEndDocument();
  315. view.setContent(buffer);
  316. buffer.close();
  317. };
  318. refresh();
  319. ]]>
  320. </program>
  321. </window>