Typica is a free program for professional coffee roasters. https://typica.us
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

dailyproductiondetail.xml 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. output.writeStartElement("tr");
  322. output.writeTextElement("td", query.value(1));
  323. 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";
  324. subQuery.exec(qq);
  325. var startValue = "0.0";
  326. var endValue = "0.0";
  327. if(subQuery.next())
  328. {
  329. switch(unitBox.currentIndex)
  330. {
  331. case 0:
  332. output.writeTextElement("td", (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0));
  333. break;
  334. case 1:
  335. output.writeTextElement("td", subQuery.value(0));
  336. break;
  337. }
  338. startValue = subQuery.value(0);
  339. }
  340. else
  341. {
  342. output.writeEmptyElement("td");
  343. }
  344. if(subQuery.next())
  345. {
  346. switch(unitBox.currentIndex)
  347. {
  348. case 0:
  349. output.writeTextElement("td", (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0));
  350. break;
  351. case 1:
  352. output.writeTextElement("td", subQuery.value(0));
  353. break;
  354. }
  355. endValue = subQuery.value(0);
  356. }
  357. else
  358. {
  359. output.writeEmptyElement("td");
  360. }
  361. var startPrec = startValue.split('.').length > 1 ? startValue.split('.')[1].length : 0;
  362. var endPrec = endValue.split('.').length > 1 ? endValue.split('.')[1].length : 0;
  363. switch(unitBox.currentIndex)
  364. {
  365. case 0:
  366. output.writeTextElement("td", (Number(endValue/2.2) - Number(startValue/2.2)).toFixed(Math.max(startPrec, endPrec)));
  367. break;
  368. case 1:
  369. output.writeTextElement("td", (Number(endValue) - Number(startValue)).toFixed(Math.max(startPrec, endPrec)));
  370. break;
  371. }
  372. output.writeTextElement("td", query.value(2));
  373. output.writeEndElement();
  374. }
  375. query = query.invalidate();
  376. subQuery = subQuery.invalidate();
  377. output.writeEndElement();
  378. output.writeStartElement("tfoot");
  379. output.writeEndElement();
  380. output.writeEndElement();//End of inventory table
  381. output.writeEndElement();
  382. output.writeEndElement();
  383. output.writeEndDocument();
  384. view.setContent(buffer);
  385. buffer.close();
  386. }
  387. refresh();
  388. dateField.dateChanged.connect(function() {
  389. refresh();
  390. });
  391. ]]>
  392. </program>
  393. </window>