Typica is a free program for professional coffee roasters. https://typica.us
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

historyreport.xml 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. <menu name="Reports" type="reports" src="Reports" />
  22. <program>
  23. <![CDATA[
  24. this.setWindowTitle(TTR("batchreport", "Typica - Batch Log"));
  25. var dateSelect = findChildObject(this, 'dates');
  26. var dateQuery = new QSqlQuery();
  27. 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");
  28. dateQuery.next();
  29. var lifetimeStartDate = dateQuery.value(0);
  30. var lifetimeEndDate;
  31. if(dateQuery.next()) {
  32. lifetimeEndDate = dateQuery.value(0);
  33. } else {
  34. lifetimeEndDate = lifetimeStartDate;
  35. }
  36. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  37. dateQuery = dateQuery.invalidate();
  38. dateSelect.currentIndex = QSettings.value("script/history/dateIndex", 6);
  39. dateSelect.rangeUpdated.connect(function() {
  40. if(dateSelect.currentIndex != 24) {
  41. QSettings.setValue("script/history/dateIndex", dateSelect.currentIndex);
  42. }
  43. refresh();
  44. });
  45. var unitBox = findChildObject(this, 'unit');
  46. unitBox.addItem(TTR("batchreport", "Kg"));
  47. unitBox.addItem(TTR("batchreport", "Lb"));
  48. unitBox.currentIndex = QSettings.value("script/history_unit", 1);
  49. unitBox['currentIndexChanged(int)'].connect(function() {
  50. QSettings.setValue("script/history_unit", unitBox.currentIndex);
  51. refresh();
  52. });
  53. var batchType = findChildObject(this, 'batchtype');
  54. batchType.addItem(TTR("batchreport", "Any"));
  55. batchType.addItem(TTR("batchreport", "Production Roasts"));
  56. batchType.addItem(TTR("batchreport", "Sample Roasts"));
  57. batchType.currentIndex = QSettings.value("script/history/batchtypefilter", 1);
  58. batchType['currentIndexChanged(int)'].connect(function() {
  59. QSettings.setValue("script/history/batchtypefilter", batchType.currentIndex);
  60. refresh();
  61. });
  62. var approval = findChildObject(this, 'approval');
  63. approval.addItem(TTR("batchreport", "Any"));
  64. approval.addItem(TTR("batchreport", "Approved"));
  65. approval.addItem(TTR("batchreport", "Not Approved"));
  66. approval.currentIndex = QSettings.value("script/history/approvalfilter", 1);
  67. approval['currentIndexChanged(int)'].connect(function() {
  68. QSettings.setValue("script/history/approvalfilter", approval.currentIndex);
  69. refresh();
  70. });
  71. var search = findChildObject(this, 'search');
  72. search.editingFinished.connect(function() {
  73. refresh();
  74. });
  75. var view = findChildObject(this, 'report');
  76. var printMenu = findChildObject(this, 'print');
  77. printMenu.triggered.connect(function() {
  78. view.print();
  79. });
  80. view.scriptLinkClicked.connect(function(url) {
  81. var arg = decodeURI(url.slice(2, url.length));
  82. var key = arg.split("@");
  83. var details = createWindow("batchDetails");
  84. details.loadBatch(key[0], key[1]);
  85. });
  86. var refresh = function() {
  87. var dateRange = dateSelect.currentRange();
  88. var startDate = dateRange[0];
  89. var endDate = dateRange[dateRange.length - 1];
  90. var conversion = 1;
  91. if(unitBox.currentIndex == 0) {
  92. conversion = 2.2;
  93. }
  94. var approvalClause = "";
  95. switch(approval.currentIndex) {
  96. case 1:
  97. approvalClause = " AND approval = true";
  98. break;
  99. case 2:
  100. approvalClause = " AND approval = false";
  101. break;
  102. }
  103. var batchClause = "";
  104. switch(batchType.currentIndex) {
  105. case 1:
  106. batchClause = " AND transaction_type = 'ROAST'";
  107. break;
  108. case 2:
  109. batchClause = " AND transaction_type = 'SAMPLEROAST'";
  110. break;
  111. }
  112. var searchClause = "";
  113. if(search.text.length > 0) {
  114. searchClause = " WHERE (person ~* :p1 OR rname ~* :p2 OR mname ~* :p3 OR greens ~* :p4 OR annotation ~* :p5 OR array_to_string(files, ',') ~* :p6)";
  115. }
  116. 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, additional_data, spec 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, NULL::jsonb AS spec) SELECT time, (loss*100)::numeric(12,2) AS spec_loss, (tolerance*100)::numeric(12,2) AS spec_tolerance, notes, spec 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) rspec, 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";
  117. var query = new QSqlQuery();
  118. query.prepare(q);
  119. query.bind(":c1", conversion);
  120. query.bind(":c2", conversion);
  121. query.bind(":sd", startDate);
  122. query.bind(":ed", endDate);
  123. if(searchClause.length > 0) {
  124. var pattern = ".*" + search.text + ".*";
  125. query.bind(":p1", pattern);
  126. query.bind(":p2", pattern);
  127. query.bind(":p3", pattern);
  128. query.bind(":p4", pattern);
  129. query.bind(":p5", pattern);
  130. query.bind(":p6", pattern);
  131. }
  132. query.exec();
  133. var buffer = new QBuffer;
  134. buffer.open(3);
  135. var output = new XmlWriter(buffer);
  136. output.writeStartDocument("1.0");
  137. 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">');
  138. output.writeStartElement("html");
  139. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  140. output.writeStartElement("head");
  141. output.writeTextElement("title", TTR("batchreport", "Batch Log"));
  142. output.writeEndElement();
  143. output.writeStartElement("body");
  144. var cdt = new Date(Date.now());
  145. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  146. output.writeStartElement("table");
  147. output.writeAttribute("style", "page-break-after: auto; text-align: left");
  148. output.writeAttribute("rules", "groups");
  149. output.writeAttribute("cellpadding", "3px");
  150. output.writeStartElement("thead");
  151. output.writeStartElement("tr");
  152. output.writeAttribute("valign", "bottom");
  153. output.writeTextElement("th", TTR("batchreport", "Time"));
  154. output.writeTextElement("th", TTR("batchreport", "File Numbers"));
  155. output.writeTextElement("th", TTR("batchreport", "Operator"));
  156. output.writeTextElement("th", TTR("batchreport", "Roasted Coffee"));
  157. output.writeEndElement();
  158. output.writeStartElement("tr");
  159. output.writeAttribute("valign", "bottom");
  160. output.writeEmptyElement("td");
  161. output.writeTextElement("th", TTR("batchreport", "Duration"));
  162. output.writeTextElement("th", TTR("batchreport", "Machine"));
  163. output.writeTextElement("th", TTR("batchreport", "Green Coffees"));
  164. output.writeEndElement();
  165. output.writeStartElement("tr");
  166. output.writeAttribute("valign", "bottom");
  167. output.writeEmptyElement("td");
  168. output.writeTextElement("th", TTR("batchreport", "Green Weight"));
  169. output.writeTextElement("th", TTR("batchreport", "Roasted Weight"));
  170. output.writeTextElement("th", TTR("batchreport", "% Weight Loss"));
  171. output.writeEndElement();
  172. output.writeStartElement("tr");
  173. output.writeAttribute("valign", "bottom");
  174. output.writeEmptyElement("td");
  175. output.writeTextElement("th", TTR("batchreport", "Degree of Roast"));
  176. output.writeEndElement();
  177. output.writeStartElement("tr");
  178. output.writeAttribute("valign", "bottom");
  179. output.writeEmptyElement("td");
  180. output.writeStartElement("th");
  181. output.writeAttribute("colspan", "2");
  182. output.writeCharacters(TTR("batchreport", "Batch Notes"));
  183. output.writeEndElement();
  184. output.writeTextElement("th", TTR("batchreport", "Specification Notes"));
  185. output.writeEndElement();
  186. output.writeEndElement();
  187. output.writeStartElement("tbody");
  188. while(query.next()) {
  189. output.writeStartElement("tr");
  190. output.writeAttribute("valign", "top");
  191. output.writeStartElement("td");
  192. output.writeStartElement("a");
  193. output.writeAttribute("href", "typica://script/b/" + query.value(15));
  194. output.writeCharacters(query.value(0).replace("T", " "));
  195. output.writeEndElement();
  196. output.writeEndElement();
  197. output.writeStartElement("td");
  198. output.writeStartElement("a");
  199. output.writeAttribute("href", "typica://script/b/" + query.value(15));
  200. output.writeCharacters(query.value(1));
  201. output.writeEndElement();
  202. output.writeEndElement();
  203. output.writeTextElement("td", query.value(2));
  204. output.writeStartElement("td");
  205. output.writeStartElement("span");
  206. if(query.value(11) == "false") {
  207. output.writeAttribute("style", "color:#FF0000");
  208. }
  209. output.writeCharacters(query.value(3));
  210. output.writeEndElement();
  211. output.writeEndElement();
  212. output.writeEndElement();
  213. output.writeStartElement("tr");
  214. output.writeAttribute("valign", "top");
  215. output.writeEmptyElement("td");
  216. output.writeTextElement("td", query.value(4));
  217. output.writeTextElement("td", query.value(5));
  218. output.writeTextElement("td", query.value(6));
  219. output.writeEndElement();
  220. output.writeStartElement("tr");
  221. output.writeAttribute("valign", "top");
  222. output.writeEmptyElement("td");
  223. output.writeTextElement("td", query.value(7));
  224. output.writeTextElement("td", query.value(8));
  225. output.writeStartElement("td");
  226. output.writeStartElement("span");
  227. if(query.value(14) == "false" && query.value(12).length > 0) {
  228. output.writeAttribute("style", "color:#FF0000");
  229. } else if (query.value(14) === "true") {
  230. output.writeAttribute("style", "color:#00FF00");
  231. }
  232. output.writeAttribute("title", query.value(12));
  233. output.writeCharacters(query.value(9));
  234. output.writeEndElement();
  235. output.writeEndElement();
  236. output.writeEndElement();
  237. output.writeStartElement("tr");
  238. output.writeAttribute("valign", "top");
  239. output.writeEmptyElement("td");
  240. if(query.value(17).length > 0) {
  241. extradata = JSON.parse(query.value(17));
  242. if(extradata.color) {
  243. wcolor = "#000000";
  244. gcolor = "#000000";
  245. wtitle = "";
  246. gtitle = "";
  247. if(query.value(18).length > 0) {
  248. specdata = JSON.parse(query.value(18));
  249. if(extradata.color.whole && specdata.color.whole.expected) {
  250. wmin = Number(specdata.color.whole.expected);
  251. wmax = wmin;
  252. wtitle += specdata.color.whole.expected;
  253. if(specdata.color.whole.tolerance) {
  254. wmin -= Number(specdata.color.whole.tolerance);
  255. wmax += Number(specdata.color.whole.tolerance);
  256. wtitle += "±";
  257. wtitle += specdata.color.whole.tolerance;
  258. }
  259. if(Number(extradata.color.whole) < wmin || Number(extradata.color.whole) > wmax) {
  260. wcolor = "#FF0000";
  261. } else {
  262. wcolor = "#00FF00";
  263. }
  264. }
  265. if(extradata.color.ground && specdata.color.ground.expected) {
  266. gmin = Number(specdata.color.ground.expected);
  267. gmax = gmin;
  268. gtitle += specdata.color.ground.expected;
  269. if(specdata.color.ground.tolerance) {
  270. gmin -= Number(specdata.color.ground.tolerance);
  271. gmax += Number(specdata.color.ground.tolerance);
  272. gtitle += "±";
  273. gtitle += specdata.color.ground.tolerance;
  274. }
  275. if(Number(extradata.color.ground) < gmin || Number(extradata.color.ground) > gmax) {
  276. gcolor = "#FF0000";
  277. } else {
  278. gcolor = "#00FF00";
  279. }
  280. }
  281. }
  282. output.writeStartElement("td");
  283. if(extradata.color.whole) {
  284. output.writeStartElement("span");
  285. output.writeAttribute("style", "color:"+wcolor);
  286. output.writeAttribute("title", wtitle);
  287. output.writeCharacters(extradata.color.whole);
  288. output.writeEndElement();
  289. }
  290. output.writeStartElement("span");
  291. if(wcolor === gcolor) {
  292. output.writeAttribute("style", "color:"+wcolor);
  293. }
  294. output.writeCharacters("/");
  295. output.writeEndElement();
  296. if(extradata.color.ground) {
  297. output.writeStartElement("span");
  298. output.writeAttribute("style", "color:"+gcolor);
  299. output.writeAttribute("title", gtitle);
  300. output.writeCharacters(extradata.color.ground);
  301. output.writeEndElement();
  302. }
  303. output.writeEndElement();
  304. }
  305. }
  306. output.writeEndElement();
  307. output.writeStartElement("tr");
  308. output.writeAttribute("valign", "top");
  309. output.writeEmptyElement("td");
  310. output.writeStartElement("td");
  311. output.writeAttribute("colspan", "2");
  312. output.writeAttribute("style", "max-width: 400px");
  313. var noteArray = query.value(10).split("\n");
  314. for(var i = 0; i < noteArray.length; i++) {
  315. output.writeStartElement("p");
  316. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  317. output.writeCharacters(noteArray[i]);
  318. output.writeEndElement();
  319. }
  320. output.writeEndElement();
  321. output.writeStartElement("td");
  322. output.writeAttribute("style", "max-width: 400px");
  323. var specArray = query.value(13).split("\n");
  324. for(var i = 0; i < specArray.length; i++) {
  325. output.writeStartElement("p", specArray[i]);
  326. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  327. output.writeCharacters(specArray[i]);
  328. output.writeEndElement();
  329. }
  330. output.writeEndElement();
  331. output.writeEndElement();
  332. }
  333. output.writeEndElement();
  334. output.writeStartElement("tfoot");
  335. output.writeStartElement("tr");
  336. output.writeAttribute("valign", "bottom");
  337. output.writeTextElement("th", TTR("batchreport", "Total Batches"));
  338. output.writeTextElement("th", TTR("batchreport", "Total Duration"));
  339. output.writeTextElement("th", TTR("batchreport", "Total Green Weight"));
  340. output.writeTextElement("th", TTR("batchreport", "Total Roasted Weight"));
  341. output.writeEndElement();
  342. output.writeStartElement("tr");
  343. output.writeAttribute("valign", "top");
  344. 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;
  345. var query = new QSqlQuery();
  346. query.prepare(q);
  347. query.bind(":c1", conversion);
  348. query.bind(":c2", conversion);
  349. query.bind(":sd", startDate);
  350. query.bind(":ed", endDate);
  351. if(searchClause.length > 0) {
  352. var pattern = ".*" + search.text + ".*";
  353. query.bind(":p1", pattern);
  354. query.bind(":p2", pattern);
  355. query.bind(":p3", pattern);
  356. query.bind(":p4", pattern);
  357. query.bind(":p5", pattern);
  358. query.bind(":p6", pattern);
  359. }
  360. query.exec();
  361. query.next();
  362. for(var i = 0; i < 4; i++) {
  363. output.writeTextElement("td", query.value(i));
  364. }
  365. output.writeEndElement();
  366. output.writeEndElement();
  367. query = query.invalidate();
  368. output.writeEndElement();
  369. output.writeEndElement();
  370. output.writeEndDocument();
  371. view.setContent(buffer);
  372. buffer.close();
  373. };
  374. refresh();
  375. var notifier = Application.subscribe("roastinglogchange");
  376. notifier.notify.connect(function() {
  377. refresh();
  378. });
  379. ]]>
  380. </program>
  381. </window>