Typica is a free program for professional coffee roasters. https://typica.us
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dailyproductiondetail.xml 25KB

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