Typica is a free program for professional coffee roasters. https://typica.us
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

dailyproductiondetail.xml 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <window id="dailyproduction">
  2. <reporttitle>Production:->Daily Production Report (Detailed)</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <label>Date:</label>
  6. <calendar id="reportdate" />
  7. <label>Weight Unit:</label>
  8. <sqldrop id="unit" />
  9. <label>Temperature Unit:</label>
  10. <sqldrop id="tempunit" />
  11. <stretch />
  12. </layout>
  13. <webview id="report" />
  14. </layout>
  15. <menu name="File">
  16. <item id="print" shortcut="Ctrl+P">Print</item>
  17. </menu>
  18. <program>
  19. <![CDATA[
  20. this.windowTitle = "Typica - Daily Production Report";
  21. var dateField = findChildObject(this, 'reportdate');
  22. var view = findChildObject(this, 'report');
  23. var printMenu = findChildObject(this, 'print');
  24. printMenu.triggered.connect(function() {
  25. view.print();
  26. });
  27. var unitBox = findChildObject(this, 'unit');
  28. unitBox.addItem("Kg");
  29. unitBox.addItem("Lb");
  30. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  31. unitBox['currentIndexChanged(int)'].connect(function() {
  32. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  33. refresh();
  34. });
  35. var tempUnit = findChildObject(this, 'tempunit');
  36. tempUnit.addItem("Celsius");
  37. tempUnit.addItem("Fahrenheit");
  38. tempUnit.currentIndex = QSettings.value("script/report_temperature", 1);
  39. tempUnit['currentIndexChanged(int)'].connect(function() {
  40. QSettings.setValue("script/report_temperature", tempUnit.currentIndex);
  41. refresh();
  42. });
  43. function refresh() {
  44. var buffer = new QBuffer;
  45. buffer.open(3);
  46. var output = new XmlWriter(buffer);
  47. output.writeStartDocument("1.0");
  48. 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">');
  49. output.writeStartElement("html");
  50. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  51. output.writeStartElement("head");
  52. output.writeTextElement("title", "Daily Production Report");
  53. output.writeEndElement();
  54. output.writeStartElement("body");
  55. var dateString = "" + dateField.year() + "-" + dateField.month() + "-" + dateField.day();
  56. output.writeTextElement("h1", "Daily Production Report: " + dateString);
  57. output.writeTextElement("h2", "Batches Roasted");
  58. var query = new QSqlQuery();
  59. var q = "SELECT time, machine, (SELECT name FROM machine WHERE id = machine), (SELECT name FROM items WHERE id = roasted_id), unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, annotation, duration, files FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1') ORDER BY time";
  60. query.exec(q);
  61. var times = new Array();
  62. var machines = new Array();
  63. output.writeStartElement("table");
  64. output.writeAttribute("rules", "groups");
  65. output.writeAttribute("cellpadding", "3px");
  66. output.writeStartElement("thead");
  67. output.writeStartElement("tr");
  68. output.writeTextElement("th", "Time");
  69. output.writeTextElement("th", "Machine");
  70. output.writeTextElement("th", "Batch ID");
  71. switch(unitBox.currentIndex)
  72. {
  73. case 0:
  74. output.writeTextElement("th", "Green Weights (Kg)");
  75. break;
  76. case 1:
  77. output.writeTextElement("th", "Green Weights (Lb)");
  78. break;
  79. }
  80. output.writeTextElement("th", "Green Coffees");
  81. switch(unitBox.currentIndex)
  82. {
  83. case 0:
  84. output.writeTextElement("th", "Roasted Weight (Kg)");
  85. break;
  86. case 1:
  87. output.writeTextElement("th", "Roasted Weight (Lb)");
  88. break;
  89. }
  90. output.writeTextElement("th", "Roasted Coffee");
  91. output.writeTextElement("th", "% Weight Loss");
  92. output.writeTextElement("th", "Duration");
  93. output.writeEndElement();
  94. output.writeEndElement();
  95. output.writeStartElement("tbody");
  96. while(query.next())
  97. {
  98. times.push(query.value(0));
  99. machines.push(query.value(1));
  100. output.writeStartElement("tr");
  101. output.writeTextElement("td", String(query.value(0)).split("T")[1]);
  102. output.writeTextElement("td", query.value(2));
  103. output.writeStartElement("td");
  104. output.writeStartElement("a");
  105. output.writeAttribute("href", "typica://script/p" + query.value(11).slice(1,-1));
  106. output.writeCDATA(query.value(11));
  107. output.writeEndElement();
  108. output.writeEndElement();
  109. var unroastedWeightsList = sqlToArray(query.value(5));
  110. output.writeStartElement("td");
  111. for(var i = 0; i < unroastedWeightsList.length; i++)
  112. {
  113. if(i != 0)
  114. {
  115. output.writeEmptyElement("br");
  116. }
  117. switch(unitBox.currentIndex)
  118. {
  119. case 0:
  120. output.writeCDATA((unroastedWeightsList[i]/2.2).toFixed(unroastedWeightsList[i].split('.').length > 1 ? unroastedWeightsList[i].split('.')[1].length : 0));
  121. break;
  122. case 1:
  123. output.writeCDATA(unroastedWeightsList[i]);
  124. break;
  125. }
  126. }
  127. if(unroastedWeightsList.length > 1)
  128. {
  129. output.writeCDATA("Total: ");
  130. switch(unitBox.currentIndex)
  131. {
  132. case 0:
  133. output.writeCDATA((query.value(6)/2.2).toFixed(query.value(6).split('.').length > 1 ? query.value(6).split('.')[1].length : 0));
  134. break;
  135. case 1:
  136. output.writeCDATA(query.value(6));
  137. break;
  138. }
  139. }
  140. output.writeEndElement();
  141. var unroastedList = sqlToArray(query.value(4));
  142. output.writeStartElement("td");
  143. var greensQuery = new QSqlQuery();
  144. greensQuery.prepare("SELECT name, reference FROM coffees WHERE id = :id");
  145. for(var i = 0; i < unroastedList.length; i++)
  146. {
  147. greensQuery.bind(":id", Number(unroastedList[i]));
  148. greensQuery.exec();
  149. if(i != 0)
  150. {
  151. output.writeEmptyElement("br");
  152. }
  153. greensQuery.next();
  154. output.writeCDATA(greensQuery.value(0) + " (" + unroastedList[i] + ")" + (greensQuery.value(1) == "" ? "" : " ref: " + greensQuery.value(1)));
  155. }
  156. greensQuery = greensQuery.invalidate();
  157. output.writeEndElement();
  158. switch(unitBox.currentIndex)
  159. {
  160. case 0:
  161. output.writeCDATA((query.value(8)/2.2).toFixed(query.value(8).split('.').length > 1 ? query.value(8).split('.')[1].length : 0));
  162. break;
  163. case 1:
  164. output.writeCDATA(query.value(8));
  165. break;
  166. }
  167. output.writeTextElement("td", query.value(3) + " (" + query.value(7) + ")");
  168. if(Number(query.value(6)) > 0) {
  169. var loss = (Number(query.value(6)) - Number(query.value(8)))/Number(query.value(6));
  170. loss *= 100;
  171. output.writeTextElement("td", loss.toFixed(2)+"%");
  172. } else {
  173. output.writeTextElement("td", "Undefined");
  174. }
  175. output.writeTextElement("td", query.value(10));
  176. output.writeEndElement();
  177. if(query.value(9) != "")
  178. {
  179. output.writeStartElement("tr");
  180. output.writeEmptyElement("td");
  181. output.writeStartElement("td");
  182. output.writeAttribute("colspan", "8");
  183. output.writeTextElement("em", query.value(9));
  184. output.writeEndElement();
  185. output.writeEndElement();
  186. }
  187. var files = sqlToArray(query.value(11));
  188. var annotations = annotationFromRecord(files[0]);
  189. output.writeStartElement("tr");
  190. output.writeStartElement("td");
  191. output.writeAttribute("colspan", "9");
  192. output.writeTextElement("strong", "Profile Summary");
  193. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  194. buffer2.open(1);
  195. var colQuery = new XQuery;
  196. colQuery.bind("profile", buffer2);
  197. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  198. var result = colQuery.exec();
  199. buffer2.close();
  200. var seriesHeaders = new Array();
  201. seriesHeaders.push("Time");
  202. var records = result.split(";");
  203. for(var i = 0; i < records.length - 1; i++) {
  204. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  205. }
  206. seriesHeaders.push("Note");
  207. output.writeStartElement("table");
  208. output.writeStartElement("thead");
  209. output.writeStartElement("tr");
  210. for(var i = 0; i < seriesHeaders.length; i++) {
  211. if(i > 0 && i < seriesHeaders.length - 1) {
  212. switch(tempUnit.currentIndex)
  213. {
  214. case 0:
  215. output.writeTextElement("th", seriesHeaders[i] + " (°C)");
  216. break;
  217. case 1:
  218. output.writeTextElement("th", seriesHeaders[i] + " (°F)");
  219. break;
  220. }
  221. } else {
  222. output.writeTextElement("th", seriesHeaders[i]);
  223. }
  224. }
  225. output.writeEndElement();
  226. output.writeEndElement();
  227. buffer2.open(1);
  228. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  229. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  230. rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  231. }
  232. rq = rq + 'string($t/annotation), "~")';
  233. colQuery.setQuery(rq);
  234. var annotationData = colQuery.exec();
  235. buffer2.close();
  236. output.writeStartElement("tbody");
  237. var annotationRecords = annotationData.split("~");
  238. for(var i = 0; i < annotationRecords.length - 1; i++) {
  239. output.writeStartElement("tr");
  240. var annotationRow = annotationRecords[i].split(";");
  241. for(var j = 0; j < annotationRow.length; j++) {
  242. output.writeStartElement("td");
  243. output.writeAttribute("style", "border-left: 1px solid #000000");
  244. if(j > 0) {
  245. output.writeAttribute("align", "center");
  246. }
  247. if(j > 0 && j < annotationRow.length - 1) {
  248. switch(tempUnit.currentIndex)
  249. {
  250. case 0:
  251. output.writeCharacters(((Number(annotationRow[j].replace(/^\s+|\s+$/g,""))-32)*5/9).toFixed(2));
  252. break;
  253. case 1:
  254. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  255. break;
  256. }
  257. }
  258. else {
  259. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  260. }
  261. output.writeEndElement();
  262. }
  263. output.writeEndElement();
  264. }
  265. output.writeEndElement();
  266. output.writeEndElement();
  267. output.writeEndElement();
  268. output.writeEndElement();
  269. }
  270. output.writeEndElement();
  271. output.writeStartElement("tfoot");
  272. output.writeStartElement("tr");
  273. output.writeEmptyElement("td");
  274. output.writeEmptyElement("td");
  275. output.writeStartElement("td");
  276. output.writeTextElement("strong", "Totals:");
  277. output.writeEndElement();
  278. q = "SELECT sum(unroasted_total_quantity), sum(roasted_quantity), sum(duration) FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1')";
  279. query.exec(q);
  280. query.next();
  281. switch(unitBox.currentIndex)
  282. {
  283. case 0:
  284. output.writeTextElement("td", (query.value(0)/2.2).toFixed(query.value(0).split('.').length > 1 ? query.value(0).split('.')[1].length : 0));
  285. break;
  286. case 1:
  287. output.writeTextElement("td", query.value(0));
  288. break;
  289. }
  290. output.writeEmptyElement("td");
  291. switch(unitBox.currentIndex)
  292. {
  293. case 0:
  294. output.writeTextElement("td", (query.value(1)/2.2).toFixed(query.value(1).split('.').length > 1 ? query.value(1).split('.')[1].length : 0));
  295. break;
  296. case 1:
  297. output.writeTextElement("td", query.value(1));
  298. break;
  299. }
  300. output.writeEmptyElement("td");
  301. output.writeEmptyElement("td");
  302. output.writeTextElement("td", query.value(2));
  303. output.writeEndElement();
  304. output.writeEndElement(); //tfoot
  305. output.writeEndElement(); //table
  306. output.writeTextElement("h2", "Inventory");
  307. output.writeStartElement("table");
  308. output.writeAttribute("rules", "groups");
  309. output.writeAttribute("cellpadding", "3px");
  310. output.writeStartElement("thead");
  311. output.writeStartElement("tr");
  312. output.writeTextElement("th", "Green Coffee");
  313. output.writeTextElement("th", "Starting Inventory");
  314. output.writeTextElement("th", "Ending Inventory");
  315. output.writeTextElement("th", "Change");
  316. output.writeTextElement("th", "Availability");
  317. output.writeEndElement();
  318. output.writeEndElement();
  319. output.writeStartElement("tbody");
  320. q = "SELECT DISTINCT item, (SELECT name FROM items WHERE id = item) AS name, (SELECT out FROM coffee_history WHERE id = item) FROM all_transactions WHERE time >= '" + dateString + "' AND time < '" + dateString + "'::date + integer '1' ORDER BY name ASC";
  321. query.exec(q)
  322. var subQuery = new QSqlQuery();
  323. var qq;
  324. while(query.next())
  325. {
  326. var validRow = true;
  327. var td1 = query.value(1);
  328. var td2 = 0;
  329. var td3 = 0;
  330. var td4 = 0;
  331. var td5 = query.value(2);
  332. qq = "SELECT balance FROM item_history(" + query.value(0) + ") WHERE time = (SELECT max(time) FROM all_transactions WHERE time <= '" + dateString + "' AND item = " + query.value(0) + ") OR time = (SELECT max(time) FROM all_transactions WHERE time < '" + dateString + "'::date + integer '1' AND item = " + query.value(0) + ") ORDER BY time ASC";
  333. subQuery.exec(qq);
  334. var startValue = "0.0";
  335. var endValue = "0.0";
  336. if(subQuery.next())
  337. {
  338. switch(unitBox.currentIndex)
  339. {
  340. case 0:
  341. td2 = (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0);
  342. break;
  343. case 1:
  344. td2 = subQuery.value(0);
  345. break;
  346. }
  347. startValue = subQuery.value(0);
  348. }
  349. else
  350. {
  351. /* This should never happen. */
  352. validRow = false;
  353. }
  354. if(subQuery.next())
  355. {
  356. switch(unitBox.currentIndex)
  357. {
  358. case 0:
  359. td3 = (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0);
  360. break;
  361. case 1:
  362. td3 = subQuery.value(0);
  363. break;
  364. }
  365. endValue = subQuery.value(0);
  366. }
  367. else
  368. {
  369. /* If only one transaction exists for the current query
  370. this is a purchase transaction. Until something is
  371. done with the coffee, it should not appear in this
  372. section of the report. */
  373. endValue = startValue;
  374. validRow = false;
  375. }
  376. var startPrec = startValue.split('.').length > 1 ? startValue.split('.')[1].length : 0;
  377. var endPrec = endValue.split('.').length > 1 ? endValue.split('.')[1].length : 0;
  378. switch(unitBox.currentIndex)
  379. {
  380. case 0:
  381. td4 = (Number(endValue/2.2) - Number(startValue/2.2)).toFixed(Math.max(startPrec, endPrec));
  382. break;
  383. case 1:
  384. td4 = (Number(endValue) - Number(startValue)).toFixed(Math.max(startPrec, endPrec));
  385. break;
  386. }
  387. if(validRow) {
  388. output.writeStartElement("tr");
  389. output.writeTextElement("td", td1);
  390. output.writeTextElement("td", td2);
  391. output.writeTextElement("td", td3);
  392. output.writeTextElement("td", td4);
  393. output.writeTextElement("td", td5);
  394. output.writeEndElement();
  395. }
  396. }
  397. query = query.invalidate();
  398. subQuery = subQuery.invalidate();
  399. output.writeEndElement();
  400. output.writeStartElement("tfoot");
  401. output.writeEndElement();
  402. output.writeEndElement();//End of inventory table
  403. output.writeEndElement();
  404. output.writeEndElement();
  405. output.writeEndDocument();
  406. view.setContent(buffer);
  407. buffer.close();
  408. }
  409. refresh();
  410. dateField.dateChanged.connect(function() {
  411. refresh();
  412. });
  413. view.scriptLinkClicked.connect(function(url) {
  414. var arg = url.slice(1, url.length);
  415. var details = createWindow("batchDetails");
  416. var fakeTable = new Object;
  417. fakeTable.holding = new Array(7);
  418. fakeTable.data = function(r, c) {
  419. return this.holding[c];
  420. };
  421. var query = new QSqlQuery();
  422. query.exec("SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity AS green, roasted_quantity AS roasted, ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) AS weight_loss, duration, annotation FROM roasting_log WHERE files = '{" + arg + "}'");
  423. query.next();
  424. for(var i = 0; i < 8; i++) {
  425. fakeTable.holding[i] = query.value(i);
  426. }
  427. query = query.invalidate();
  428. details.loadData(fakeTable, 0);
  429. });
  430. ]]>
  431. </program>
  432. </window>