Typica is a free program for professional coffee roasters. https://typica.us
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

dailyproductiondetail.xml 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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.writeTextElement("td", query.value(11));
  104. var unroastedWeightsList = sqlToArray(query.value(5));
  105. output.writeStartElement("td");
  106. for(var i = 0; i < unroastedWeightsList.length; i++)
  107. {
  108. if(i != 0)
  109. {
  110. output.writeEmptyElement("br");
  111. }
  112. switch(unitBox.currentIndex)
  113. {
  114. case 0:
  115. output.writeCDATA((unroastedWeightsList[i]/2.2).toFixed(unroastedWeightsList[i].split('.').length > 1 ? unroastedWeightsList[i].split('.')[1].length : 0));
  116. break;
  117. case 1:
  118. output.writeCDATA(unroastedWeightsList[i]);
  119. break;
  120. }
  121. }
  122. if(unroastedWeightsList.length > 1)
  123. {
  124. output.writeCDATA("Total: ");
  125. switch(unitBox.currentIndex)
  126. {
  127. case 0:
  128. output.writeCDATA((query.value(6)/2.2).toFixed(query.value(6).split('.').length > 1 ? query.value(6).split('.')[1].length : 0));
  129. break;
  130. case 1:
  131. output.writeCDATA(query.value(6));
  132. break;
  133. }
  134. }
  135. output.writeEndElement();
  136. var unroastedList = sqlToArray(query.value(4));
  137. output.writeStartElement("td");
  138. var greensQuery = new QSqlQuery();
  139. greensQuery.prepare("SELECT name, reference FROM coffees WHERE id = :id");
  140. for(var i = 0; i < unroastedList.length; i++)
  141. {
  142. greensQuery.bind(":id", Number(unroastedList[i]));
  143. greensQuery.exec();
  144. if(i != 0)
  145. {
  146. output.writeEmptyElement("br");
  147. }
  148. greensQuery.next();
  149. output.writeCDATA(greensQuery.value(0) + " (" + unroastedList[i] + ")" + (greensQuery.value(1) == "" ? "" : " ref: " + greensQuery.value(1)));
  150. }
  151. greensQuery = greensQuery.invalidate();
  152. output.writeEndElement();
  153. switch(unitBox.currentIndex)
  154. {
  155. case 0:
  156. output.writeCDATA((query.value(8)/2.2).toFixed(query.value(8).split('.').length > 1 ? query.value(8).split('.')[1].length : 0));
  157. break;
  158. case 1:
  159. output.writeCDATA(query.value(8));
  160. break;
  161. }
  162. output.writeTextElement("td", query.value(3) + " (" + query.value(7) + ")");
  163. if(Number(query.value(6)) > 0) {
  164. var loss = (Number(query.value(6)) - Number(query.value(8)))/Number(query.value(6));
  165. loss *= 100;
  166. output.writeTextElement("td", loss.toFixed(2)+"%");
  167. } else {
  168. output.writeTextElement("td", "Undefined");
  169. }
  170. output.writeTextElement("td", query.value(10));
  171. output.writeEndElement();
  172. if(query.value(9) != "")
  173. {
  174. output.writeStartElement("tr");
  175. output.writeEmptyElement("td");
  176. output.writeStartElement("td");
  177. output.writeAttribute("colspan", "8");
  178. output.writeTextElement("em", query.value(9));
  179. output.writeEndElement();
  180. output.writeEndElement();
  181. }
  182. var files = sqlToArray(query.value(11));
  183. var annotations = annotationFromRecord(files[0]);
  184. output.writeStartElement("tr");
  185. output.writeStartElement("td");
  186. output.writeAttribute("colspan", "9");
  187. output.writeTextElement("strong", "Profile Summary");
  188. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  189. buffer2.open(1);
  190. var colQuery = new XQuery;
  191. colQuery.bind("profile", buffer2);
  192. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  193. var result = colQuery.exec();
  194. buffer2.close();
  195. var seriesHeaders = new Array();
  196. seriesHeaders.push("Time");
  197. var records = result.split(";");
  198. for(var i = 0; i < records.length - 1; i++) {
  199. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  200. }
  201. seriesHeaders.push("Note");
  202. output.writeStartElement("table");
  203. output.writeStartElement("thead");
  204. output.writeStartElement("tr");
  205. for(var i = 0; i < seriesHeaders.length; i++) {
  206. if(i > 0 && i < seriesHeaders.length - 1) {
  207. switch(tempUnit.currentIndex)
  208. {
  209. case 0:
  210. output.writeTextElement("th", seriesHeaders[i] + " (°C)");
  211. break;
  212. case 1:
  213. output.writeTextElement("th", seriesHeaders[i] + " (°F)");
  214. break;
  215. }
  216. } else {
  217. output.writeTextElement("th", seriesHeaders[i]);
  218. }
  219. }
  220. output.writeEndElement();
  221. output.writeEndElement();
  222. buffer2.open(1);
  223. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  224. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  225. rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  226. }
  227. rq = rq + 'string($t/annotation), "~")';
  228. colQuery.setQuery(rq);
  229. var annotationData = colQuery.exec();
  230. buffer2.close();
  231. output.writeStartElement("tbody");
  232. var annotationRecords = annotationData.split("~");
  233. for(var i = 0; i < annotationRecords.length - 1; i++) {
  234. output.writeStartElement("tr");
  235. var annotationRow = annotationRecords[i].split(";");
  236. for(var j = 0; j < annotationRow.length; j++) {
  237. output.writeStartElement("td");
  238. output.writeAttribute("style", "border-left: 1px solid #000000");
  239. if(j > 0) {
  240. output.writeAttribute("align", "center");
  241. }
  242. if(j > 0 && j < annotationRow.length - 1) {
  243. switch(tempUnit.currentIndex)
  244. {
  245. case 0:
  246. output.writeCharacters(((Number(annotationRow[j].replace(/^\s+|\s+$/g,""))-32)*5/9).toFixed(2));
  247. break;
  248. case 1:
  249. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  250. break;
  251. }
  252. }
  253. else {
  254. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  255. }
  256. output.writeEndElement();
  257. }
  258. output.writeEndElement();
  259. }
  260. output.writeEndElement();
  261. output.writeEndElement();
  262. output.writeEndElement();
  263. output.writeEndElement();
  264. }
  265. output.writeEndElement();
  266. output.writeStartElement("tfoot");
  267. output.writeStartElement("tr");
  268. output.writeEmptyElement("td");
  269. output.writeEmptyElement("td");
  270. output.writeStartElement("td");
  271. output.writeTextElement("strong", "Totals:");
  272. output.writeEndElement();
  273. q = "SELECT sum(unroasted_total_quantity), sum(roasted_quantity), sum(duration) FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1')";
  274. query.exec(q);
  275. query.next();
  276. switch(unitBox.currentIndex)
  277. {
  278. case 0:
  279. output.writeTextElement("td", (query.value(0)/2.2).toFixed(query.value(0).split('.').length > 1 ? query.value(0).split('.')[1].length : 0));
  280. break;
  281. case 1:
  282. output.writeTextElement("td", query.value(0));
  283. break;
  284. }
  285. output.writeEmptyElement("td");
  286. switch(unitBox.currentIndex)
  287. {
  288. case 0:
  289. output.writeTextElement("td", (query.value(1)/2.2).toFixed(query.value(1).split('.').length > 1 ? query.value(1).split('.')[1].length : 0));
  290. break;
  291. case 1:
  292. output.writeTextElement("td", query.value(1));
  293. break;
  294. }
  295. output.writeEmptyElement("td");
  296. output.writeEmptyElement("td");
  297. output.writeTextElement("td", query.value(2));
  298. output.writeEndElement();
  299. output.writeEndElement(); //tfoot
  300. output.writeEndElement(); //table
  301. output.writeTextElement("h2", "Inventory");
  302. output.writeStartElement("table");
  303. output.writeAttribute("rules", "groups");
  304. output.writeAttribute("cellpadding", "3px");
  305. output.writeStartElement("thead");
  306. output.writeStartElement("tr");
  307. output.writeTextElement("th", "Green Coffee");
  308. output.writeTextElement("th", "Starting Inventory");
  309. output.writeTextElement("th", "Ending Inventory");
  310. output.writeTextElement("th", "Change");
  311. output.writeTextElement("th", "Availability");
  312. output.writeEndElement();
  313. output.writeEndElement();
  314. output.writeStartElement("tbody");
  315. 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";
  316. query.exec(q)
  317. var subQuery = new QSqlQuery();
  318. var qq;
  319. while(query.next())
  320. {
  321. var validRow = true;
  322. var td1 = query.value(1);
  323. var td2 = 0;
  324. var td3 = 0;
  325. var td4 = 0;
  326. var td5 = query.value(2);
  327. 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";
  328. subQuery.exec(qq);
  329. var startValue = "0.0";
  330. var endValue = "0.0";
  331. if(subQuery.next())
  332. {
  333. switch(unitBox.currentIndex)
  334. {
  335. case 0:
  336. td2 = (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0);
  337. break;
  338. case 1:
  339. td2 = subQuery.value(0);
  340. break;
  341. }
  342. startValue = subQuery.value(0);
  343. }
  344. else
  345. {
  346. /* This should never happen. */
  347. validRow = false;
  348. }
  349. if(subQuery.next())
  350. {
  351. switch(unitBox.currentIndex)
  352. {
  353. case 0:
  354. td3 = (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0);
  355. break;
  356. case 1:
  357. td3 = subQuery.value(0);
  358. break;
  359. }
  360. endValue = subQuery.value(0);
  361. }
  362. else
  363. {
  364. /* If only one transaction exists for the current query
  365. this is a purchase transaction. Until something is
  366. done with the coffee, it should not appear in this
  367. section of the report. */
  368. endValue = startValue;
  369. validRow = false;
  370. }
  371. var startPrec = startValue.split('.').length > 1 ? startValue.split('.')[1].length : 0;
  372. var endPrec = endValue.split('.').length > 1 ? endValue.split('.')[1].length : 0;
  373. switch(unitBox.currentIndex)
  374. {
  375. case 0:
  376. td4 = (Number(endValue/2.2) - Number(startValue/2.2)).toFixed(Math.max(startPrec, endPrec));
  377. break;
  378. case 1:
  379. td4 = (Number(endValue) - Number(startValue)).toFixed(Math.max(startPrec, endPrec));
  380. break;
  381. }
  382. if(validRow) {
  383. output.writeStartElement("tr");
  384. output.writeTextElement("td", td1);
  385. output.writeTextElement("td", td2);
  386. output.writeTextElement("td", td3);
  387. output.writeTextElement("td", td4);
  388. output.writeTextElement("td", td5);
  389. output.writeEndElement();
  390. }
  391. }
  392. query = query.invalidate();
  393. subQuery = subQuery.invalidate();
  394. output.writeEndElement();
  395. output.writeStartElement("tfoot");
  396. output.writeEndElement();
  397. output.writeEndElement();//End of inventory table
  398. output.writeEndElement();
  399. output.writeEndElement();
  400. output.writeEndDocument();
  401. view.setContent(buffer);
  402. buffer.close();
  403. }
  404. refresh();
  405. dateField.dateChanged.connect(function() {
  406. refresh();
  407. });
  408. ]]>
  409. </program>
  410. </window>