Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dailyproductiondetail.xml 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. <menu name="Reports" type="reports" src="Reports" />
  19. <program>
  20. <![CDATA[
  21. this.windowTitle = TTR("dailyproduction", "Typica - Daily Production Report");
  22. var dateField = findChildObject(this, 'reportdate');
  23. var view = findChildObject(this, 'report');
  24. var printMenu = findChildObject(this, 'print');
  25. printMenu.triggered.connect(function() {
  26. view.print();
  27. });
  28. var unitBox = findChildObject(this, 'unit');
  29. unitBox.addItem("Kg");
  30. unitBox.addItem("Lb");
  31. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  32. unitBox['currentIndexChanged(int)'].connect(function() {
  33. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  34. refresh();
  35. });
  36. var tempUnit = findChildObject(this, 'tempunit');
  37. tempUnit.addItem("Celsius");
  38. tempUnit.addItem("Fahrenheit");
  39. tempUnit.currentIndex = QSettings.value("script/report_temperature", 1);
  40. tempUnit['currentIndexChanged(int)'].connect(function() {
  41. QSettings.setValue("script/report_temperature", tempUnit.currentIndex);
  42. refresh();
  43. });
  44. function refresh() {
  45. var buffer = new QBuffer;
  46. buffer.open(3);
  47. var output = new XmlWriter(buffer);
  48. output.writeStartDocument("1.0");
  49. 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">');
  50. output.writeStartElement("html");
  51. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  52. output.writeStartElement("head");
  53. output.writeTextElement("title", TTR("dailyproduction", "Daily Production Report"));
  54. output.writeEndElement();
  55. output.writeStartElement("body");
  56. var cdt = new Date(Date.now());
  57. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  58. var dateString = "" + dateField.year() + "-" + dateField.month() + "-" + dateField.day();
  59. output.writeTextElement("h1", TTR("dailyproduction", "Daily Production Report: ") + dateString);
  60. output.writeTextElement("h2", TTR("dailyproduction", "Batches Roasted"));
  61. var query = new QSqlQuery();
  62. 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, machine || '@' || time AS link, additional_data, (SELECT 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)) FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1') ORDER BY time";
  63. query.exec(q);
  64. var times = new Array();
  65. var machines = new Array();
  66. output.writeStartElement("table");
  67. output.writeAttribute("rules", "groups");
  68. output.writeAttribute("cellpadding", "3px");
  69. output.writeStartElement("thead");
  70. output.writeStartElement("tr");
  71. output.writeAttribute("valign", "bottom");
  72. output.writeTextElement("th", TTR("dailyproduction", "Time"));
  73. output.writeTextElement("th", TTR("dailyproduction", "Machine"));
  74. output.writeTextElement("th", TTR("dailyproduction", "Batch ID"));
  75. switch(unitBox.currentIndex)
  76. {
  77. case 0:
  78. output.writeTextElement("th", TTR("dailyproduction", "Green Weights (Kg)"));
  79. break;
  80. case 1:
  81. output.writeTextElement("th", TTR("dailyproduction", "Green Weights (Lb)"));
  82. break;
  83. }
  84. output.writeTextElement("th", "Green Coffees");
  85. switch(unitBox.currentIndex)
  86. {
  87. case 0:
  88. output.writeTextElement("th", TTR("dailyproduction", "Roasted Weight (Kg)"));
  89. break;
  90. case 1:
  91. output.writeTextElement("th", TTR("dailyproduction", "Roasted Weight (Lb)"));
  92. break;
  93. }
  94. output.writeTextElement("th", TTR("dailyproduction", "Roasted Coffee"));
  95. output.writeTextElement("th", TTR("dailyproduction", "% Weight Loss"));
  96. output.writeTextElement("th", TTR("dailyproduction", "Duration"));
  97. output.writeEndElement();
  98. output.writeStartElement("tr");
  99. output.writeAttribute("valign", "bottom");
  100. output.writeEmptyElement("td");
  101. output.writeEmptyElement("td");
  102. output.writeEmptyElement("td");
  103. output.writeEmptyElement("td");
  104. output.writeEmptyElement("td");
  105. output.writeEmptyElement("td");
  106. output.writeEmptyElement("td");
  107. output.writeTextElement("th", TTR("dailyproduction", "Degree of Roast"));
  108. output.writeEndElement();
  109. output.writeEndElement();
  110. output.writeStartElement("tbody");
  111. output.writeAttribute("valign", "top");
  112. while(query.next())
  113. {
  114. times.push(query.value(0));
  115. machines.push(query.value(1));
  116. output.writeStartElement("tr");
  117. output.writeTextElement("td", String(query.value(0)).split("T")[1]);
  118. output.writeTextElement("td", query.value(2));
  119. output.writeStartElement("td");
  120. output.writeStartElement("a");
  121. output.writeAttribute("href", "typica://script/b/" + query.value(16));
  122. output.writeCDATA(query.value(11));
  123. output.writeEndElement();
  124. output.writeEndElement();
  125. var unroastedWeightsList = sqlToArray(query.value(5));
  126. output.writeStartElement("td");
  127. for(var i = 0; i < unroastedWeightsList.length; i++)
  128. {
  129. if(i != 0)
  130. {
  131. output.writeEmptyElement("br");
  132. }
  133. switch(unitBox.currentIndex)
  134. {
  135. case 0:
  136. output.writeCDATA((unroastedWeightsList[i]/2.2).toFixed(unroastedWeightsList[i].split('.').length > 1 ? unroastedWeightsList[i].split('.')[1].length : 0));
  137. break;
  138. case 1:
  139. output.writeCDATA(unroastedWeightsList[i]);
  140. break;
  141. }
  142. }
  143. if(unroastedWeightsList.length > 1)
  144. {
  145. output.writeCDATA("Total: ");
  146. switch(unitBox.currentIndex)
  147. {
  148. case 0:
  149. output.writeCDATA((query.value(6)/2.2).toFixed(query.value(6).split('.').length > 1 ? query.value(6).split('.')[1].length : 0));
  150. break;
  151. case 1:
  152. output.writeCDATA(query.value(6));
  153. break;
  154. }
  155. }
  156. output.writeEndElement();
  157. var unroastedList = sqlToArray(query.value(4));
  158. output.writeStartElement("td");
  159. var greensQuery = new QSqlQuery();
  160. greensQuery.prepare("SELECT name, reference FROM coffees WHERE id = :id");
  161. for(var i = 0; i < unroastedList.length; i++)
  162. {
  163. greensQuery.bind(":id", Number(unroastedList[i]));
  164. greensQuery.exec();
  165. if(i != 0)
  166. {
  167. output.writeEmptyElement("br");
  168. }
  169. greensQuery.next();
  170. output.writeCDATA(greensQuery.value(0) + " (" + unroastedList[i] + ")" + (greensQuery.value(1) == "" ? "" : " ref: " + greensQuery.value(1)));
  171. }
  172. greensQuery = greensQuery.invalidate();
  173. output.writeEndElement();
  174. switch(unitBox.currentIndex)
  175. {
  176. case 0:
  177. output.writeCDATA((query.value(8)/2.2).toFixed(query.value(8).split('.').length > 1 ? query.value(8).split('.')[1].length : 0));
  178. break;
  179. case 1:
  180. output.writeCDATA(query.value(8));
  181. break;
  182. }
  183. output.writeStartElement("td");
  184. output.writeStartElement("span");
  185. if(query.value(15) == "false") {
  186. output.writeAttribute("style", "color:#FF0000");
  187. }
  188. output.writeCharacters(query.value(3) + " (" + query.value(7) + ")");
  189. output.writeEndElement();
  190. output.writeEndElement();
  191. if(Number(query.value(6)) > 0) {
  192. var loss = (Number(query.value(6)) - Number(query.value(8)))/Number(query.value(6));
  193. var lossMin;
  194. var lossMax;
  195. var lossColor;
  196. var useLoss;
  197. if(query.value(12) > 0) {
  198. useLoss = true;
  199. lossMin = Number(query.value(12)) - Number(query.value(13));
  200. lossMax = Number(query.value(12)) + Number(query.value(13));
  201. if(loss >= lossMin && loss <= lossMax) {
  202. lossColor = '#00FF00';
  203. } else {
  204. lossColor = '#FF0000';
  205. }
  206. } else {
  207. lossColor = '#000000';
  208. useLoss = false;
  209. }
  210. loss *= 100;
  211. var lossSpec = Number(query.value(12)) * 100;
  212. var lossTol = Number(query.value(13)) * 100;
  213. output.writeStartElement("td");
  214. output.writeStartElement("span");
  215. output.writeAttribute("style", "color:"+lossColor);
  216. if(useLoss) {
  217. output.writeAttribute("title", lossSpec.toFixed(2) + "+/-" + lossTol.toFixed(2) + "%");
  218. }
  219. output.writeCharacters(loss.toFixed(2) + "%");
  220. output.writeEndElement();
  221. output.writeEndElement();
  222. } else {
  223. output.writeTextElement("td", "Undefined");
  224. }
  225. output.writeTextElement("td", query.value(10));
  226. output.writeEndElement();
  227. if(query.value(17).length > 0) {
  228. extradata = JSON.parse(query.value(17));
  229. if(extradata.color) {
  230. wcolor = "#000000";
  231. gcolor = "#000000";
  232. wtitle = "";
  233. gtitle = "";
  234. output.writeStartElement("tr");
  235. output.writeEmptyElement("td");
  236. output.writeEmptyElement("td");
  237. output.writeEmptyElement("td");
  238. output.writeEmptyElement("td");
  239. output.writeEmptyElement("td");
  240. output.writeEmptyElement("td");
  241. output.writeEmptyElement("td");
  242. if(query.value(18).length > 0) {
  243. specdata = JSON.parse(query.value(18));
  244. if(extradata.color.whole && specdata.color.whole.expected) {
  245. wmin = Number(specdata.color.whole.expected);
  246. wmax = wmin;
  247. wtitle += specdata.color.whole.expected;
  248. if(specdata.color.whole.tolerance) {
  249. wmin -= Number(specdata.color.whole.tolerance);
  250. wmax += Number(specdata.color.whole.tolerance);
  251. wtitle += "±";
  252. wtitle += specdata.color.whole.tolerance;
  253. }
  254. if(Number(extradata.color.whole) < wmin || Number(extradata.color.whole) > wmax) {
  255. wcolor = "#FF0000";
  256. } else {
  257. wcolor = "#00FF00";
  258. }
  259. }
  260. if(extradata.color.ground && specdata.color.ground.expected) {
  261. gmin = Number(specdata.color.ground.expected);
  262. gmax = gmin;
  263. gtitle += specdata.color.ground.expected;
  264. if(specdata.color.ground.tolerance) {
  265. gmin -= Number(specdata.color.ground.tolerance);
  266. gmax += Number(specdata.color.ground.tolerance);
  267. gtitle += "±";
  268. gtitle += specdata.color.ground.tolerance;
  269. }
  270. if(Number(extradata.color.ground) < gmin || Number(extradata.color.ground) > gmax) {
  271. gcolor = "#FF0000";
  272. } else {
  273. gcolor = "#00FF00";
  274. }
  275. }
  276. }
  277. output.writeStartElement("td");
  278. if(extradata.color.whole) {
  279. output.writeStartElement("span");
  280. output.writeAttribute("style", "color:"+wcolor);
  281. output.writeAttribute("title", wtitle);
  282. output.writeCharacters(extradata.color.whole);
  283. output.writeEndElement();
  284. }
  285. output.writeStartElement("span");
  286. if(wcolor === gcolor) {
  287. output.writeAttribute("style", "color:"+wcolor);
  288. }
  289. output.writeCharacters("/");
  290. output.writeEndElement();
  291. if(extradata.color.ground) {
  292. output.writeStartElement("span");
  293. output.writeAttribute("style", "color:"+gcolor);
  294. output.writeAttribute("title", gtitle);
  295. output.writeCharacters(extradata.color.ground);
  296. output.writeEndElement();
  297. }
  298. output.writeEndElement();
  299. output.writeEndElement();
  300. }
  301. }
  302. if(query.value(9) != "")
  303. {
  304. output.writeStartElement("tr");
  305. output.writeEmptyElement("td");
  306. output.writeStartElement("td");
  307. output.writeAttribute("colspan", "8");
  308. var noteArray = query.value(9).split("\n");
  309. for(var i = 0; i < noteArray.length; i++) {
  310. output.writeStartElement("p");
  311. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  312. output.writeCharacters(noteArray[i]);
  313. output.writeEndElement();
  314. }
  315. output.writeEndElement();
  316. output.writeEndElement();
  317. }
  318. var files = sqlToArray(query.value(11));
  319. var annotations = annotationFromRecord(files[0]);
  320. output.writeStartElement("tr");
  321. output.writeStartElement("td");
  322. output.writeAttribute("colspan", "5");
  323. output.writeTextElement("strong", TTR("dailyproduction", "Profile Summary"));
  324. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  325. buffer2.open(1);
  326. var colQuery = new XQuery;
  327. colQuery.bind("profile", buffer2);
  328. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  329. var result = colQuery.exec();
  330. buffer2.close();
  331. var seriesHeaders = new Array();
  332. seriesHeaders.push(TTR("dailyproduction", "Time"));
  333. var records = result.split(";");
  334. for(var i = 0; i < records.length - 1; i++) {
  335. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  336. }
  337. seriesHeaders.push(TTR("dailyproduction", "Note"));
  338. output.writeStartElement("table");
  339. output.writeStartElement("thead");
  340. output.writeStartElement("tr");
  341. for(var i = 0; i < seriesHeaders.length; i++) {
  342. if(i > 0 && i < seriesHeaders.length - 1) {
  343. switch(tempUnit.currentIndex)
  344. {
  345. case 0:
  346. output.writeTextElement("th", seriesHeaders[i] + " (°C)");
  347. break;
  348. case 1:
  349. output.writeTextElement("th", seriesHeaders[i] + " (°F)");
  350. break;
  351. }
  352. } else {
  353. output.writeTextElement("th", seriesHeaders[i]);
  354. }
  355. }
  356. output.writeEndElement();
  357. output.writeEndElement();
  358. buffer2.open(1);
  359. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  360. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  361. rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  362. }
  363. rq = rq + 'string($t/annotation), "~")';
  364. colQuery.setQuery(rq);
  365. var annotationData = colQuery.exec();
  366. buffer2.close();
  367. output.writeStartElement("tbody");
  368. var annotationRecords = annotationData.split("~");
  369. for(var i = 0; i < annotationRecords.length - 1; i++) {
  370. output.writeStartElement("tr");
  371. var annotationRow = annotationRecords[i].split(";");
  372. for(var j = 0; j < annotationRow.length; j++) {
  373. output.writeStartElement("td");
  374. output.writeAttribute("style", "border-left: 1px solid #000000");
  375. if(j > 0) {
  376. output.writeAttribute("align", "center");
  377. }
  378. if(j > 0 && j < annotationRow.length - 1) {
  379. switch(tempUnit.currentIndex)
  380. {
  381. case 0:
  382. output.writeCharacters(((Number(annotationRow[j].replace(/^\s+|\s+$/g,""))-32)*5/9).toFixed(2));
  383. break;
  384. case 1:
  385. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  386. break;
  387. }
  388. }
  389. else {
  390. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  391. }
  392. output.writeEndElement();
  393. }
  394. output.writeEndElement();
  395. }
  396. output.writeEndElement();
  397. output.writeEndElement();
  398. output.writeEndElement();
  399. output.writeStartElement("td");
  400. output.writeAttribute("colspan", "4");
  401. if(query.value(14)) {
  402. output.writeTextElement("strong", "Roast Specification Notes");
  403. var specArray = query.value(14).split("\n");
  404. for(var i = 0; i < specArray.length; i++) {
  405. output.writeStartElement("p");
  406. output.writeAttribute("style", "margin-top: 0; margin-bottom: 0");
  407. output.writeCharacters(specArray[i]);
  408. output.writeEndElement();
  409. }
  410. }
  411. output.writeEndElement();
  412. output.writeEndElement();
  413. }
  414. output.writeEndElement();
  415. output.writeStartElement("tfoot");
  416. output.writeStartElement("tr");
  417. output.writeEmptyElement("td");
  418. output.writeEmptyElement("td");
  419. output.writeStartElement("td");
  420. output.writeTextElement("strong", TTR("dailyproduction", "Totals:"));
  421. output.writeEndElement();
  422. q = "SELECT sum(unroasted_total_quantity), sum(roasted_quantity), sum(duration) FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1')";
  423. query.exec(q);
  424. query.next();
  425. switch(unitBox.currentIndex)
  426. {
  427. case 0:
  428. output.writeTextElement("td", (query.value(0)/2.2).toFixed(query.value(0).split('.').length > 1 ? query.value(0).split('.')[1].length : 0));
  429. break;
  430. case 1:
  431. output.writeTextElement("td", query.value(0));
  432. break;
  433. }
  434. output.writeEmptyElement("td");
  435. switch(unitBox.currentIndex)
  436. {
  437. case 0:
  438. output.writeTextElement("td", (query.value(1)/2.2).toFixed(query.value(1).split('.').length > 1 ? query.value(1).split('.')[1].length : 0));
  439. break;
  440. case 1:
  441. output.writeTextElement("td", query.value(1));
  442. break;
  443. }
  444. output.writeEmptyElement("td");
  445. output.writeEmptyElement("td");
  446. output.writeTextElement("td", query.value(2));
  447. output.writeEndElement();
  448. output.writeEndElement(); //tfoot
  449. output.writeEndElement(); //table
  450. output.writeTextElement("h2", TTR("dailyproduction", "Inventory"));
  451. output.writeStartElement("table");
  452. output.writeAttribute("rules", "groups");
  453. output.writeAttribute("cellpadding", "3px");
  454. output.writeStartElement("thead");
  455. output.writeStartElement("tr");
  456. output.writeTextElement("th", TTR("dailyproduction", "Green Coffee"));
  457. output.writeTextElement("th", TTR("dailyproduction", "Starting Inventory"));
  458. output.writeTextElement("th", TTR("dailyproduction", "Ending Inventory"));
  459. output.writeTextElement("th", TTR("dailyproduction", "Change"));
  460. output.writeTextElement("th", TTR("dailyproduction", "Availability"));
  461. output.writeEndElement();
  462. output.writeEndElement();
  463. output.writeStartElement("tbody");
  464. 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";
  465. query.exec(q)
  466. var subQuery = new QSqlQuery();
  467. var qq;
  468. while(query.next())
  469. {
  470. var validRow = true;
  471. var td1 = query.value(1);
  472. var td2 = 0;
  473. var td3 = 0;
  474. var td4 = 0;
  475. var td5 = query.value(2);
  476. 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";
  477. subQuery.exec(qq);
  478. var startValue = "0.0";
  479. var endValue = "0.0";
  480. if(subQuery.next())
  481. {
  482. switch(unitBox.currentIndex)
  483. {
  484. case 0:
  485. td2 = (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0);
  486. break;
  487. case 1:
  488. td2 = subQuery.value(0);
  489. break;
  490. }
  491. startValue = subQuery.value(0);
  492. }
  493. else
  494. {
  495. /* This should never happen. */
  496. validRow = false;
  497. }
  498. if(subQuery.next())
  499. {
  500. switch(unitBox.currentIndex)
  501. {
  502. case 0:
  503. td3 = (subQuery.value(0)/2.2).toFixed(subQuery.value(0).split('.').length > 1 ? subQuery.value(0).split('.')[1].length : 0);
  504. break;
  505. case 1:
  506. td3 = subQuery.value(0);
  507. break;
  508. }
  509. endValue = subQuery.value(0);
  510. }
  511. else
  512. {
  513. /* If only one transaction exists for the current query
  514. this is a purchase transaction. Until something is
  515. done with the coffee, it should not appear in this
  516. section of the report. */
  517. endValue = startValue;
  518. validRow = false;
  519. }
  520. var startPrec = startValue.split('.').length > 1 ? startValue.split('.')[1].length : 0;
  521. var endPrec = endValue.split('.').length > 1 ? endValue.split('.')[1].length : 0;
  522. switch(unitBox.currentIndex)
  523. {
  524. case 0:
  525. td4 = (Number(endValue/2.2) - Number(startValue/2.2)).toFixed(Math.max(startPrec, endPrec));
  526. break;
  527. case 1:
  528. td4 = (Number(endValue) - Number(startValue)).toFixed(Math.max(startPrec, endPrec));
  529. break;
  530. }
  531. if(validRow) {
  532. output.writeStartElement("tr");
  533. output.writeTextElement("td", td1);
  534. output.writeTextElement("td", td2);
  535. output.writeTextElement("td", td3);
  536. output.writeTextElement("td", td4);
  537. output.writeTextElement("td", td5);
  538. output.writeEndElement();
  539. }
  540. }
  541. query = query.invalidate();
  542. subQuery = subQuery.invalidate();
  543. output.writeEndElement();
  544. output.writeStartElement("tfoot");
  545. output.writeEndElement();
  546. output.writeEndElement();//End of inventory table
  547. output.writeEndElement();
  548. output.writeEndElement();
  549. output.writeEndDocument();
  550. view.setContent(buffer);
  551. buffer.close();
  552. }
  553. refresh();
  554. dateField.dateChanged.connect(function() {
  555. refresh();
  556. });
  557. var notifier = Application.subscribe("roastinglogchange");
  558. notifier.notify.connect(function() {
  559. refresh();
  560. });
  561. view.scriptLinkClicked.connect(function(url) {
  562. var arg = decodeURI(url.slice(2, url.length));
  563. var key = arg.split("@");
  564. var details = createWindow("batchDetails");
  565. details.loadBatch(key[0], key[1]);
  566. });
  567. ]]>
  568. </program>
  569. </window>