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

dailyproductiondetail.xml 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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", TTR("dailyproduction", "Daily Production Report"));
  53. output.writeEndElement();
  54. output.writeStartElement("body");
  55. var dateString = "" + dateField.year() + "-" + dateField.month() + "-" + dateField.day();
  56. output.writeTextElement("h1", TTR("dailyproduction", "Daily Production Report: ") + dateString);
  57. output.writeTextElement("h2", TTR("dailyproduction", "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, (SELECT loss FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), (SELECT tolerance FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), (SELECT 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)), approval 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.writeAttribute("valign", "bottom");
  69. output.writeTextElement("th", TTR("dailyproduction", "Time"));
  70. output.writeTextElement("th", TTR("dailyproduction", "Machine"));
  71. output.writeTextElement("th", TTR("dailyproduction", "Batch ID"));
  72. switch(unitBox.currentIndex)
  73. {
  74. case 0:
  75. output.writeTextElement("th", TTR("dailyproduction", "Green Weights (Kg)"));
  76. break;
  77. case 1:
  78. output.writeTextElement("th", TTR("dailyproduction", "Green Weights (Lb)"));
  79. break;
  80. }
  81. output.writeTextElement("th", "Green Coffees");
  82. switch(unitBox.currentIndex)
  83. {
  84. case 0:
  85. output.writeTextElement("th", TTR("dailyproduction", "Roasted Weight (Kg)"));
  86. break;
  87. case 1:
  88. output.writeTextElement("th", TTR("dailyproduction", "Roasted Weight (Lb)"));
  89. break;
  90. }
  91. output.writeTextElement("th", TTR("dailyproduction", "Roasted Coffee"));
  92. output.writeTextElement("th", TTR("dailyproduction", "% Weight Loss"));
  93. output.writeTextElement("th", TTR("dailyproduction", "Duration"));
  94. output.writeEndElement();
  95. output.writeEndElement();
  96. output.writeStartElement("tbody");
  97. output.writeAttribute("valign", "top");
  98. while(query.next())
  99. {
  100. times.push(query.value(0));
  101. machines.push(query.value(1));
  102. output.writeStartElement("tr");
  103. output.writeTextElement("td", String(query.value(0)).split("T")[1]);
  104. output.writeTextElement("td", query.value(2));
  105. output.writeStartElement("td");
  106. output.writeStartElement("a");
  107. output.writeAttribute("href", "typica://script/p" + query.value(11).slice(1,-1));
  108. output.writeCDATA(query.value(11));
  109. output.writeEndElement();
  110. output.writeEndElement();
  111. var unroastedWeightsList = sqlToArray(query.value(5));
  112. output.writeStartElement("td");
  113. for(var i = 0; i < unroastedWeightsList.length; i++)
  114. {
  115. if(i != 0)
  116. {
  117. output.writeEmptyElement("br");
  118. }
  119. switch(unitBox.currentIndex)
  120. {
  121. case 0:
  122. output.writeCDATA((unroastedWeightsList[i]/2.2).toFixed(unroastedWeightsList[i].split('.').length > 1 ? unroastedWeightsList[i].split('.')[1].length : 0));
  123. break;
  124. case 1:
  125. output.writeCDATA(unroastedWeightsList[i]);
  126. break;
  127. }
  128. }
  129. if(unroastedWeightsList.length > 1)
  130. {
  131. output.writeCDATA("Total: ");
  132. switch(unitBox.currentIndex)
  133. {
  134. case 0:
  135. output.writeCDATA((query.value(6)/2.2).toFixed(query.value(6).split('.').length > 1 ? query.value(6).split('.')[1].length : 0));
  136. break;
  137. case 1:
  138. output.writeCDATA(query.value(6));
  139. break;
  140. }
  141. }
  142. output.writeEndElement();
  143. var unroastedList = sqlToArray(query.value(4));
  144. output.writeStartElement("td");
  145. var greensQuery = new QSqlQuery();
  146. greensQuery.prepare("SELECT name, reference FROM coffees WHERE id = :id");
  147. for(var i = 0; i < unroastedList.length; i++)
  148. {
  149. greensQuery.bind(":id", Number(unroastedList[i]));
  150. greensQuery.exec();
  151. if(i != 0)
  152. {
  153. output.writeEmptyElement("br");
  154. }
  155. greensQuery.next();
  156. output.writeCDATA(greensQuery.value(0) + " (" + unroastedList[i] + ")" + (greensQuery.value(1) == "" ? "" : " ref: " + greensQuery.value(1)));
  157. }
  158. greensQuery = greensQuery.invalidate();
  159. output.writeEndElement();
  160. switch(unitBox.currentIndex)
  161. {
  162. case 0:
  163. output.writeCDATA((query.value(8)/2.2).toFixed(query.value(8).split('.').length > 1 ? query.value(8).split('.')[1].length : 0));
  164. break;
  165. case 1:
  166. output.writeCDATA(query.value(8));
  167. break;
  168. }
  169. output.writeStartElement("td");
  170. output.writeStartElement("span");
  171. if(query.value(15) == "false") {
  172. output.writeAttribute("style", "color:#FF0000");
  173. }
  174. output.writeCharacters(query.value(3) + " (" + query.value(7) + ")");
  175. output.writeEndElement();
  176. output.writeEndElement();
  177. if(Number(query.value(6)) > 0) {
  178. var loss = (Number(query.value(6)) - Number(query.value(8)))/Number(query.value(6));
  179. var lossMin;
  180. var lossMax;
  181. var lossColor;
  182. var useLoss;
  183. if(query.value(12) > 0) {
  184. useLoss = true;
  185. lossMin = Number(query.value(12)) - Number(query.value(13));
  186. lossMax = Number(query.value(12)) + Number(query.value(13));
  187. if(loss >= lossMin && loss <= lossMax) {
  188. lossColor = '#00FF00';
  189. } else {
  190. lossColor = '#FF0000';
  191. }
  192. } else {
  193. lossColor = '#000000';
  194. useLoss = false;
  195. }
  196. loss *= 100;
  197. var lossSpec = Number(query.value(12)) * 100;
  198. var lossTol = Number(query.value(13)) * 100;
  199. output.writeStartElement("td");
  200. output.writeStartElement("span");
  201. output.writeAttribute("style", "color:"+lossColor);
  202. if(useLoss) {
  203. output.writeAttribute("title", lossSpec.toFixed(2) + "+/-" + lossTol.toFixed(2) + "%");
  204. }
  205. output.writeCharacters(loss.toFixed(2) + "%");
  206. output.writeEndElement();
  207. output.writeEndElement();
  208. } else {
  209. output.writeTextElement("td", "Undefined");
  210. }
  211. output.writeTextElement("td", query.value(10));
  212. output.writeEndElement();
  213. if(query.value(9) != "")
  214. {
  215. output.writeStartElement("tr");
  216. output.writeEmptyElement("td");
  217. output.writeStartElement("td");
  218. output.writeAttribute("colspan", "8");
  219. var noteArray = query.value(9).split("\n");
  220. for(var i = 0; i < noteArray.length; i++) {
  221. output.writeStartElement("p");
  222. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  223. output.writeCharacters(noteArray[i]);
  224. output.writeEndElement();
  225. }
  226. output.writeEndElement();
  227. output.writeEndElement();
  228. }
  229. var files = sqlToArray(query.value(11));
  230. var annotations = annotationFromRecord(files[0]);
  231. output.writeStartElement("tr");
  232. output.writeStartElement("td");
  233. output.writeAttribute("colspan", "5");
  234. output.writeTextElement("strong", TTR("dailyproduction", "Profile Summary"));
  235. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  236. buffer2.open(1);
  237. var colQuery = new XQuery;
  238. colQuery.bind("profile", buffer2);
  239. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  240. var result = colQuery.exec();
  241. buffer2.close();
  242. var seriesHeaders = new Array();
  243. seriesHeaders.push(TTR("dailyproduction", "Time"));
  244. var records = result.split(";");
  245. for(var i = 0; i < records.length - 1; i++) {
  246. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  247. }
  248. seriesHeaders.push(TTR("dailyproduction", "Note"));
  249. output.writeStartElement("table");
  250. output.writeStartElement("thead");
  251. output.writeStartElement("tr");
  252. for(var i = 0; i < seriesHeaders.length; i++) {
  253. if(i > 0 && i < seriesHeaders.length - 1) {
  254. switch(tempUnit.currentIndex)
  255. {
  256. case 0:
  257. output.writeTextElement("th", seriesHeaders[i] + " (°C)");
  258. break;
  259. case 1:
  260. output.writeTextElement("th", seriesHeaders[i] + " (°F)");
  261. break;
  262. }
  263. } else {
  264. output.writeTextElement("th", seriesHeaders[i]);
  265. }
  266. }
  267. output.writeEndElement();
  268. output.writeEndElement();
  269. buffer2.open(1);
  270. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  271. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  272. rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  273. }
  274. rq = rq + 'string($t/annotation), "~")';
  275. colQuery.setQuery(rq);
  276. var annotationData = colQuery.exec();
  277. buffer2.close();
  278. output.writeStartElement("tbody");
  279. var annotationRecords = annotationData.split("~");
  280. for(var i = 0; i < annotationRecords.length - 1; i++) {
  281. output.writeStartElement("tr");
  282. var annotationRow = annotationRecords[i].split(";");
  283. for(var j = 0; j < annotationRow.length; j++) {
  284. output.writeStartElement("td");
  285. output.writeAttribute("style", "border-left: 1px solid #000000");
  286. if(j > 0) {
  287. output.writeAttribute("align", "center");
  288. }
  289. if(j > 0 && j < annotationRow.length - 1) {
  290. switch(tempUnit.currentIndex)
  291. {
  292. case 0:
  293. output.writeCharacters(((Number(annotationRow[j].replace(/^\s+|\s+$/g,""))-32)*5/9).toFixed(2));
  294. break;
  295. case 1:
  296. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  297. break;
  298. }
  299. }
  300. else {
  301. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  302. }
  303. output.writeEndElement();
  304. }
  305. output.writeEndElement();
  306. }
  307. output.writeEndElement();
  308. output.writeEndElement();
  309. output.writeEndElement();
  310. output.writeStartElement("td");
  311. output.writeAttribute("colspan", "4");
  312. if(query.value(14)) {
  313. output.writeTextElement("strong", "Roast Specification Notes");
  314. var specArray = query.value(14).split("\n");
  315. for(var i = 0; i < noteArray.length; i++) {
  316. output.writeStartElement("p");
  317. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  318. output.writeCharacters(specArray[i]);
  319. output.writeEndElement();
  320. }
  321. }
  322. output.writeEndElement();
  323. output.writeEndElement();
  324. }
  325. output.writeEndElement();
  326. output.writeStartElement("tfoot");
  327. output.writeStartElement("tr");
  328. output.writeEmptyElement("td");
  329. output.writeEmptyElement("td");
  330. output.writeStartElement("td");
  331. output.writeTextElement("strong", TTR("dailyproduction", "Totals:"));
  332. output.writeEndElement();
  333. q = "SELECT sum(unroasted_total_quantity), sum(roasted_quantity), sum(duration) FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1')";
  334. query.exec(q);
  335. query.next();
  336. switch(unitBox.currentIndex)
  337. {
  338. case 0:
  339. output.writeTextElement("td", (query.value(0)/2.2).toFixed(query.value(0).split('.').length > 1 ? query.value(0).split('.')[1].length : 0));
  340. break;
  341. case 1:
  342. output.writeTextElement("td", query.value(0));
  343. break;
  344. }
  345. output.writeEmptyElement("td");
  346. switch(unitBox.currentIndex)
  347. {
  348. case 0:
  349. output.writeTextElement("td", (query.value(1)/2.2).toFixed(query.value(1).split('.').length > 1 ? query.value(1).split('.')[1].length : 0));
  350. break;
  351. case 1:
  352. output.writeTextElement("td", query.value(1));
  353. break;
  354. }
  355. output.writeEmptyElement("td");
  356. output.writeEmptyElement("td");
  357. output.writeTextElement("td", query.value(2));
  358. output.writeEndElement();
  359. output.writeEndElement(); //tfoot
  360. output.writeEndElement(); //table
  361. output.writeTextElement("h2", TTR("dailyproduction", "Inventory"));
  362. output.writeStartElement("table");
  363. output.writeAttribute("rules", "groups");
  364. output.writeAttribute("cellpadding", "3px");
  365. output.writeStartElement("thead");
  366. output.writeStartElement("tr");
  367. output.writeTextElement("th", TTR("dailyproduction", "Green Coffee"));
  368. output.writeTextElement("th", TTR("dailyproduction", "Starting Inventory"));
  369. output.writeTextElement("th", TTR("dailyproduction", "Ending Inventory"));
  370. output.writeTextElement("th", TTR("dailyproduction", "Change"));
  371. output.writeTextElement("th", TTR("dailyproduction", "Availability"));
  372. output.writeEndElement();
  373. output.writeEndElement();
  374. output.writeStartElement("tbody");
  375. 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";
  376. query.exec(q)
  377. var subQuery = new QSqlQuery();
  378. var qq;
  379. while(query.next())
  380. {
  381. var validRow = true;
  382. var td1 = query.value(1);
  383. var td2 = 0;
  384. var td3 = 0;
  385. var td4 = 0;
  386. var td5 = query.value(2);
  387. 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";
  388. subQuery.exec(qq);
  389. var startValue = "0.0";
  390. var endValue = "0.0";
  391. if(subQuery.next())
  392. {
  393. switch(unitBox.currentIndex)
  394. {
  395. case 0:
  396. td2 = (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0);
  397. break;
  398. case 1:
  399. td2 = subQuery.value(0);
  400. break;
  401. }
  402. startValue = subQuery.value(0);
  403. }
  404. else
  405. {
  406. /* This should never happen. */
  407. validRow = false;
  408. }
  409. if(subQuery.next())
  410. {
  411. switch(unitBox.currentIndex)
  412. {
  413. case 0:
  414. td3 = (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0);
  415. break;
  416. case 1:
  417. td3 = subQuery.value(0);
  418. break;
  419. }
  420. endValue = subQuery.value(0);
  421. }
  422. else
  423. {
  424. /* If only one transaction exists for the current query
  425. this is a purchase transaction. Until something is
  426. done with the coffee, it should not appear in this
  427. section of the report. */
  428. endValue = startValue;
  429. validRow = false;
  430. }
  431. var startPrec = startValue.split('.').length > 1 ? startValue.split('.')[1].length : 0;
  432. var endPrec = endValue.split('.').length > 1 ? endValue.split('.')[1].length : 0;
  433. switch(unitBox.currentIndex)
  434. {
  435. case 0:
  436. td4 = (Number(endValue/2.2) - Number(startValue/2.2)).toFixed(Math.max(startPrec, endPrec));
  437. break;
  438. case 1:
  439. td4 = (Number(endValue) - Number(startValue)).toFixed(Math.max(startPrec, endPrec));
  440. break;
  441. }
  442. if(validRow) {
  443. output.writeStartElement("tr");
  444. output.writeTextElement("td", td1);
  445. output.writeTextElement("td", td2);
  446. output.writeTextElement("td", td3);
  447. output.writeTextElement("td", td4);
  448. output.writeTextElement("td", td5);
  449. output.writeEndElement();
  450. }
  451. }
  452. query = query.invalidate();
  453. subQuery = subQuery.invalidate();
  454. output.writeEndElement();
  455. output.writeStartElement("tfoot");
  456. output.writeEndElement();
  457. output.writeEndElement();//End of inventory table
  458. output.writeEndElement();
  459. output.writeEndElement();
  460. output.writeEndDocument();
  461. view.setContent(buffer);
  462. buffer.close();
  463. }
  464. refresh();
  465. dateField.dateChanged.connect(function() {
  466. refresh();
  467. });
  468. view.scriptLinkClicked.connect(function(url) {
  469. var arg = url.slice(1, url.length);
  470. var details = createWindow("batchDetails");
  471. var fakeTable = new Object;
  472. fakeTable.holding = new Array(7);
  473. fakeTable.data = function(r, c) {
  474. return this.holding[c];
  475. };
  476. var query = new QSqlQuery();
  477. 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 + "}'");
  478. query.next();
  479. for(var i = 0; i < 8; i++) {
  480. fakeTable.holding[i] = query.value(i);
  481. }
  482. query = query.invalidate();
  483. details.loadData(fakeTable, 0);
  484. });
  485. ]]>
  486. </program>
  487. </window>