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.

batchdetailsnew.xml 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <window id="batchDetails">
  2. <layout type="vertical">
  3. <layout type="horizontal">
  4. <button type="push" id="target" name="Load profile as target" />
  5. <stretch />
  6. <label>Search:</label>
  7. <line id="search" />
  8. </layout>
  9. <tabbar id="tabs" />
  10. <layout type="stack" id="pages">
  11. <page>
  12. <layout type="vertical">
  13. <webview id="view" />
  14. </layout>
  15. </page>
  16. <page>
  17. <layout type="vertical">
  18. <splitter type="horizontal" id="logsplit">
  19. <measurementtable id="log">
  20. <column>Time</column>
  21. <column>Bean</column>
  22. <column>Air</column>
  23. <column>Note</column>
  24. </measurementtable>
  25. <graph id="graph" />
  26. </splitter>
  27. </layout>
  28. </page>
  29. <page>
  30. <layout type="vertical">
  31. <layout type="horizontal">
  32. <label>Roasted Weight: </label>
  33. <line id="roasted" validator="numeric" />
  34. <line id="roastunit" writable="false" />
  35. <stretch />
  36. </layout>
  37. <label>Degree of Roast</label>
  38. <layout type="horizontal">
  39. <label>Whole Bean:</label>
  40. <roastcoloredit id="wholecolor" />
  41. <stretch />
  42. </layout>
  43. <label id="wholespec">-</label>
  44. <layout type="horizontal">
  45. <label>Ground:</label>
  46. <roastcoloredit id="groundcolor" />
  47. <stretch />
  48. </layout>
  49. <label id="groundspec">-</label>
  50. <button type="check" name="Approved" id="approval" />
  51. <layout type="horizontal">
  52. <label>Annotation</label>
  53. <textarea id="annotation" />
  54. </layout>
  55. <button type="push" id="submit" name="Save" />
  56. <stretch />
  57. </layout>
  58. </page>
  59. <page>
  60. <layout type="vertical">
  61. <webview id="batchTag" />
  62. <layout type="horizontal">
  63. <printerselector id="printerlist" />
  64. <button name="Print" id="printbutton" type="push" />
  65. </layout>
  66. </layout>
  67. </page>
  68. </layout>
  69. </layout>
  70. <menu name="File">
  71. <item id="save" shortcut="Ctrl+S">Save Profile...</item>
  72. <item id="print" shortcut="Ctrl+P">Print Report...</item>
  73. </menu>
  74. <menu name="Log">
  75. <item id="showC">Display Celsius</item>
  76. <item id="showF">Display Fahrenheit</item>
  77. <separator />
  78. <item id="ms">Millisecond View</item>
  79. <item id="1s">1 Second View</item>
  80. <item id="5s">5 Second View</item>
  81. <item id="10s">10 Second View</item>
  82. <item id="15s">15 Second View</item>
  83. <item id="30s">30 Second View</item>
  84. <item id="1m">1 Minute View</item>
  85. </menu>
  86. <program>
  87. <![CDATA[
  88. var window = this;
  89. window.windowTitle = TTR("batchDetails", "Typica - Batch Details");
  90. var tabs = findChildObject(this, 'tabs');
  91. tabs.addTab(TTR("batchDetails", "Report"));
  92. tabs.addTab(TTR("batchDetails", "Profile"));
  93. tabs.addTab(TTR("batchDetails", "Edit"));
  94. tabs.addTab(TTR("batchDetails", "Batch Tag"));
  95. var pages = findChildObject(this, 'pages');
  96. tabs.currentChanged.connect(function(index) {
  97. pages.setCurrentIndex(index);
  98. });
  99. var log = findChildObject(this, 'log');
  100. var graph = findChildObject(this, 'graph');
  101. var showC = findChildObject(this, 'showC');
  102. showC.triggered.connect(function() {
  103. log.setDisplayUnits(Units.Celsius);
  104. graph.showC();
  105. });
  106. var showF = findChildObject(this, 'showF');
  107. showF.triggered.connect(function() {
  108. log.setDisplayUnits(Units.Fahrenheit);
  109. graph.showF();
  110. });
  111. var v1 = findChildObject(this, 'ms');
  112. v1.triggered.connect(log.LOD_ms);
  113. var v2 = findChildObject(this, '1s');
  114. v2.triggered.connect(log.LOD_1s);
  115. var v3 = findChildObject(this, '5s');
  116. v3.triggered.connect(log.LOD_5s);
  117. var v4 = findChildObject(this, '10s');
  118. v4.triggered.connect(log.LOD_10s);
  119. var v5 = findChildObject(this, '15s');
  120. v5.triggered.connect(log.LOD_15s);
  121. var v6 = findChildObject(this, '30s');
  122. v6.triggered.connect(log.LOD_30s);
  123. var v7 = findChildObject(this, '1m');
  124. v7.triggered.connect(log.LOD_1m);
  125. var splitter = findChildObject(this, 'logsplit');
  126. splitter.restoreState("script/offlineViewSplitter");
  127. window.saveTemperatureColumns = new Array();
  128. window.saveAnnotationColumns = new Array();
  129. this.aboutToClose.connect(function() {
  130. splitter.saveState("script/batchdetails/profileSplitter");
  131. });
  132. var unit = QSettings.value("script/history_unit", 1);
  133. var conversion = 1;
  134. if(unit == 0)
  135. {
  136. conversion = 2.2;
  137. }
  138. var unitText = (unit == 0 ? TTR("batchDetails", "Kg") :
  139. TTR("batchDetails", "Lb"));
  140. dataView = findChildObject(this, 'view');
  141. var printMenu = findChildObject(this, 'print');
  142. printMenu.triggered.connect(function() {
  143. dataView.print();
  144. });
  145. var fileID;
  146. var target = findChildObject(this, 'target');
  147. if(typeof(Windows.loggingWindow) == "undefined") {
  148. target.enabled = false;
  149. }
  150. var tableReference;
  151. var rowReference;
  152. var batchTime;
  153. var machine;
  154. var approval;
  155. var annotation;
  156. var roastWeight;
  157. target.clicked.connect(function() {
  158. var query = new QSqlQuery;
  159. query.prepare("SELECT file, name FROM files WHERE id = :id");
  160. query.bind(":id", Number(fileID));
  161. query.exec();
  162. query.next();
  163. var buffer = new QBuffer(query.value(0));
  164. var pname = query.value(1);
  165. query = query.invalidate();
  166. var input = new XMLInput(buffer, 1);
  167. var graph = findChildObject(Windows.loggingWindow, 'graph');
  168. var log = findChildObject(Windows.loggingWindow, 'log');
  169. log.clear();
  170. graph.clear();
  171. input.newTemperatureColumn.connect(log.setHeaderData);
  172. input.newTemperatureColumn.connect(function(col, text) {
  173. if(text == Windows.loggingWindow.targetcolumnname) {
  174. targetseries = col;
  175. }
  176. });
  177. input.newAnnotationColumn.connect(log.setHeaderData);
  178. input.measure.connect(graph.newMeasurement);
  179. input.measure.connect(log.newMeasurement);
  180. var targetDetector = Windows.loggingWindow.targetDetector;
  181. input.measure.connect(function(data, series) {
  182. if(series == targetseries) {
  183. targetDetector.newMeasurement(data);
  184. }
  185. });
  186. var lc;
  187. input.lastColumn.connect(function(c) {
  188. lc = c;
  189. QSettings.setValue("liveColumn", c + 1);
  190. Windows.loggingWindow.postLoadColumnSetup(c);
  191. });
  192. input.annotation.connect(log.newAnnotation);
  193. input.annotation.connect(function(note, tcol, ncol) {
  194. for(var i = tcol; i < ncol; i++) {
  195. log.newAnnotation(note, i, ncol);
  196. }
  197. });
  198. Windows.loggingWindow.windowTitle = "Typica - " + pname;
  199. Windows.loggingWindow.raise();
  200. Windows.loggingWindow.activateWindow();
  201. graph.updatesEnabled = false;
  202. log.updatesEnabled = false;
  203. input.input();
  204. log.updatesEnabled = true;
  205. graph.updatesEnabled = true;
  206. log.newAnnotation(TTR("batchDetails", "End"), 1, lc);
  207. query = query.invalidate();
  208. });
  209. var approvalButton = findChildObject(this, 'approval');
  210. var annotationField = findChildObject(this, 'annotation');
  211. var roastedEdit = findChildObject(this, 'roasted');
  212. var unitEdit = findChildObject(this, 'roastunit');
  213. var wholecolor = findChildObject(this, 'wholecolor');
  214. var groundcolor = findChildObject(this, 'groundcolor');
  215. window.loadBatch = function(mref, tref) {
  216. machine = mref;
  217. batchTime = tref;
  218. var query = new QSqlQuery();
  219. var q = "WITH names AS ( WITH greens AS ( SELECT unnest(unroasted_id) AS gitem, machine, time FROM roasting_log WHERE machine = :machine AND time = :time) SELECT array_agg((SELECT name FROM items WHERE id = greens.gitem) || ' (' || gitem || ')') AS names, max(greens.machine) AS machine, max(greens.time) AS time FROM greens LIMIT 1) SELECT (SELECT name FROM items WHERE id = roasted_id), duration, names, unroasted_quantity, (unroasted_total_quantity/:c1)::numeric(12,3), (roasted_quantity/:c2)::numeric(12,3), approval, files, annotation, (SELECT file FROM files WHERE id = files[1]) AS file, additional_data, roasted_id FROM names, roasting_log WHERE roasting_log.machine = names.machine AND roasting_log.time = names.time";
  220. query.prepare(q);
  221. query.bind(":machine", mref);
  222. query.bind(":time", tref);
  223. query.bind(":c1", conversion);
  224. query.bind(":c2", conversion);
  225. query.exec();
  226. query.next();
  227. var buffer = new QBuffer;
  228. buffer.open(3);
  229. var output = new XmlWriter(buffer);
  230. output.writeStartDocument("1.0");
  231. 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">');
  232. output.writeStartElement("html");
  233. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  234. output.writeStartElement("head");
  235. output.writeTextElement("title", "Batch Details");
  236. output.writeEndElement();
  237. output.writeStartElement("body");
  238. output.writeStartElement("div");
  239. output.writeAttribute("style", "float: left; padding-right: 10px");
  240. output.writeStartElement("p");
  241. output.writeTextElement("strong", TTR("batchDetails", "Roasted Coffee: "));
  242. output.writeTextElement("span", query.value(0));
  243. output.writeEndElement();
  244. output.writeEndElement();
  245. output.writeStartElement("div");
  246. output.writeAttribute("style", "float: left");
  247. output.writeStartElement("p");
  248. output.writeTextElement("strong", TTR("batchDetails", "Roasted At: "));
  249. output.writeTextElement("span", batchTime);
  250. output.writeEndElement();
  251. output.writeStartElement("p");
  252. output.writeTextElement("strong", TTR("batchDetails", "Batch Duration: "));
  253. output.writeTextElement("span", query.value(1));
  254. output.writeEndElement();
  255. output.writeEndElement();
  256. output.writeStartElement("div");
  257. output.writeAttribute("style", "clear: both");
  258. output.writeEndElement();
  259. output.writeStartElement("table");
  260. output.writeStartElement("thead");
  261. output.writeStartElement("tr");
  262. output.writeTextElement("th", TTR("batchDetails", "Green Coffee"));
  263. output.writeTextElement("th", TTR("batchDetails", "Weight") + "(" + unitText + ")");
  264. output.writeEndElement();
  265. output.writeEndElement();
  266. output.writeStartElement("tbody");
  267. var items = sqlToArray(query.value(2));
  268. var quantities = sqlToArray(query.value(3));
  269. for(var i = 0; i < items.length; i++) {
  270. output.writeStartElement("tr");
  271. output.writeTextElement("td", items[i]);
  272. output.writeStartElement("td");
  273. output.writeAttribute("align", "center");
  274. output.writeCharacters(Number(quantities[i]/conversion).toFixed(3));
  275. output.writeEndElement();
  276. output.writeEndElement();
  277. }
  278. output.writeEndElement();
  279. output.writeStartElement("tfoot");
  280. output.writeStartElement("tr");
  281. output.writeStartElement("td");
  282. output.writeAttribute("align", "right");
  283. output.writeTextElement("strong", TTR("batchDetails", "Green Total:"));
  284. output.writeEndElement();
  285. output.writeStartElement("td");
  286. output.writeAttribute("align", "center");
  287. output.writeCharacters(query.value(4));
  288. output.writeEndElement();
  289. output.writeEndElement();
  290. output.writeStartElement("tr");
  291. output.writeStartElement("td");
  292. output.writeAttribute("align", "right");
  293. output.writeTextElement("strong", TTR("batchDetails", "Roasted Weight:"));
  294. output.writeEndElement();
  295. output.writeStartElement("td");
  296. output.writeAttribute("align", "center");
  297. output.writeCharacters(query.value(5));
  298. output.writeEndElement();
  299. output.writeEndElement();
  300. output.writeStartElement("tr");
  301. output.writeStartElement("td");
  302. output.writeAttribute("align", "right");
  303. output.writeTextElement("strong", TTR("batchDetails", "Weight Loss:"));
  304. output.writeEndElement();
  305. output.writeStartElement("td");
  306. output.writeAttribute("align", "center");
  307. if(Number(query.value(4)) > 0) {
  308. output.writeCharacters(Number(((Number(query.value(4)) - Number(query.value(5)))/Number(query.value(4))) * 100).toFixed(2));
  309. output.writeCharacters("%");
  310. } else {
  311. output.writeCharacters("unknown");
  312. }
  313. output.writeEndElement();
  314. output.writeEndElement();
  315. output.writeEndElement();
  316. output.writeEndElement();
  317. if(query.value(10).length > 0) {
  318. var extradata = JSON.parse(query.value(10));
  319. if(extradata.color) {
  320. output.writeStartElement("p");
  321. output.writeTextElement("strong", TTR("batchDetails", "Degree of Roast"));
  322. output.writeEndElement();
  323. if(extradata.color.whole) {
  324. wholecolor.value = extradata.color.whole;
  325. output.writeStartElement("p");
  326. output.writeTextElement("strong", TTR("batchDetails", "Whole Bean: "));
  327. output.writeTextElement("span", extradata.color.whole);
  328. output.writeEndElement();
  329. } else {
  330. wholecolor.value = "";
  331. }
  332. if(extradata.color.ground) {
  333. groundcolor.value = extradata.color.ground;
  334. output.writeStartElement("p");
  335. output.writeTextElement("strong", TTR("batchDetails", "Ground: "));
  336. output.writeTextElement("span", extradata.color.ground);
  337. output.writeEndElement();
  338. } else {
  339. groundcolor.value = "";
  340. }
  341. } else {
  342. wholecolor.value = "";
  343. groundcolor.value = "";
  344. }
  345. } else {
  346. wholecolor.value = "";
  347. groundcolor.value = "";
  348. }
  349. output.writeStartElement("p");
  350. output.writeTextElement("strong", TTR("batchDetails", "Approved: "));
  351. output.writeCharacters(query.value(6));
  352. output.writeEndElement();
  353. output.writeStartElement("p");
  354. output.writeTextElement("strong", TTR("batchDetails", "Files: "));
  355. output.writeCharacters(query.value(7));
  356. output.writeEndElement();
  357. output.writeStartElement("p");
  358. output.writeTextElement("strong", TTR("batchDetails", "Annotations:"));
  359. var files = sqlToArray(query.value(7));
  360. var annotations = annotationFromRecord(files[0]);
  361. fileID = files[0];
  362. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  363. buffer2.open(1);
  364. var colQuery = new XQuery;
  365. colQuery.bind("profile", buffer2);
  366. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  367. var result = colQuery.exec();
  368. buffer2.close();
  369. var seriesHeaders = new Array();
  370. seriesHeaders.push(TTR("batchDetails", "Time"));
  371. var records = result.split(";");
  372. for(var i = 0; i < records.length - 1; i++) {
  373. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  374. }
  375. seriesHeaders.push(TTR("batchDetails", "Note"));
  376. output.writeStartElement("table");
  377. output.writeStartElement("thead");
  378. output.writeStartElement("tr");
  379. for(var i = 0; i < seriesHeaders.length; i++) {
  380. output.writeTextElement("th", seriesHeaders[i]);
  381. }
  382. output.writeEndElement();
  383. output.writeEndElement();
  384. buffer2.open(1);
  385. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  386. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  387. rq += 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  388. }
  389. rq += 'string($t/annotation), "~")';
  390. colQuery.setQuery(rq);
  391. var annotationData = colQuery.exec();
  392. colQuery = colQuery.invalidate();
  393. buffer2.close();
  394. output.writeStartElement("tbody");
  395. var annotationRecords = annotationData.split("~");
  396. for(var i = 0; i < annotationRecords.length - 1; i++) {
  397. output.writeStartElement("tr");
  398. var annotationRow = annotationRecords[i].split(";");
  399. for(var j = 0; j < annotationRow.length; j++) {
  400. output.writeStartElement("td");
  401. output.writeAttribute("style", "border-left: 1px solid #000000");
  402. if(j > 0) {
  403. output.writeAttribute("align", "center");
  404. }
  405. if(j > 0 && j < annotationRow.length - 1) {
  406. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  407. } else {
  408. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  409. }
  410. output.writeEndElement();
  411. }
  412. output.writeEndElement();
  413. }
  414. output.writeEndElement();
  415. output.writeEndElement();
  416. output.writeCharacters(query.value(8));
  417. output.writeEndElement();
  418. output.writeEndElement();
  419. output.writeEndElement();
  420. output.writeEndDocument();
  421. dataView.setContent(buffer);
  422. buffer.close();
  423. log.clear();
  424. graph.clear();
  425. var buffer3 = new QBuffer(query.value(9));
  426. var input = new XMLInput(buffer3, 1);
  427. input.newTemperatureColumn.connect(log.setHeaderData);
  428. input.newAnnotationColumn.connect(log.setHeaderData);
  429. var lc;
  430. input.lastColumn.connect(function(c) {
  431. lc = c;
  432. if(c < 3) {
  433. log.setHeaderData(3, "");
  434. }
  435. });
  436. input.measure.connect(graph.newMeasurement);
  437. input.measure.connect(log.newMeasurement);
  438. input.annotation.connect(function(note,tcol,ncol) {
  439. for(var i = tcol; i < ncol; i++) {
  440. log.newAnnotation(note, i, ncol);
  441. }
  442. });
  443. graph.updatesEnabled = false;
  444. log.updatesEnabled = false;
  445. input.input();
  446. log.updatesEnabled = true;
  447. graph.updatesEnabled = true;
  448. log.newAnnotation("End", 1, lc);
  449. if(query.value(6) == "true") {
  450. approvalButton.checked = true;
  451. }
  452. annotationField.plainText = query.value(8);
  453. unitEdit.text = unitText;
  454. roastedEdit.text = query.value(5);
  455. drawTag(query.value(11), query.value(0));
  456. query = query.invalidate();
  457. }
  458. var saveMenu = findChildObject(this, 'save');
  459. saveMenu.triggered.connect(function() {
  460. var filename = QFileDialog.getSaveFileName(window, TTR("batchDetails", "Save Log As..."), QSettings.value("script/lastDir", "") + "/");
  461. if(filename != "") {
  462. saveFileFromDatabase(fileID, filename);
  463. }
  464. });
  465. var submit = findChildObject(this, 'submit');
  466. submit.clicked.connect(function() {
  467. var query = new QSqlQuery;
  468. query.prepare("UPDATE roasting_log SET roasted_quantity = :roasted, approval = :approval, annotation = :annotation, additional_data = :extradata WHERE time = :time AND machine = :machine");
  469. query.bind(":approval", approvalButton.checked);
  470. query.bind(":annotation", annotationField.plainText);
  471. query.bind(":roasted", Number(Number(roastedEdit.text)*conversion));
  472. var extradata = new Object;
  473. var colordata = new Object;
  474. if(wholecolor.value.length > 0) {
  475. colordata.whole = wholecolor.value;
  476. }
  477. if(groundcolor.value.length > 0) {
  478. colordata.ground = groundcolor.value;
  479. }
  480. if(colordata.whole || colordata.ground) {
  481. extradata.color = colordata;
  482. }
  483. query.bind(":extradata", JSON.stringify(extradata));
  484. query.bind(":time", batchTime);
  485. query.bind(":machine", Number(machine));
  486. query.exec();
  487. query = query.invalidate();
  488. window.loadBatch(machine, batchTime);
  489. displayInfo(TTR("batchDetails", "Batch Data Saved"),
  490. TTR("roastspec", "New batch details saved"));
  491. });
  492. var batchTag = findChildObject(this, 'batchTag');
  493. var printers = findChildObject(this, 'printerlist');
  494. printers.currentIndex = printers.findText(QSettings.value("script/batchtagprinter"));
  495. printers['currentIndexChanged(int)'].connect(function() {
  496. QSettings.setValue("script/batchtagprinter", printers.currentText);
  497. });
  498. var printbutton = findChildObject(this, 'printbutton');
  499. printbutton.clicked.connect(function() {
  500. batchTag.print(printers.currentText);
  501. });
  502. function drawTag(item, name) {
  503. var buffer = new QBuffer;
  504. buffer.open(3);
  505. var output = new XmlWriter(buffer);
  506. output.writeStartDocument("1.0");
  507. 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">');
  508. output.writeStartElement("html");
  509. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  510. output.writeStartElement("head");
  511. var styleFile = new QFile(QSettings.value("config") + "/Scripts/batchtag.css");
  512. styleFile.open(1);
  513. output.writeTextElement("style", styleFile.readToString());
  514. styleFile.close();
  515. styleFile = new QFile(QSettings.value("config") + "/Scripts/barcode.css");
  516. styleFile.open(1);
  517. output.writeTextElement("style", styleFile.readToString());
  518. styleFile.close();
  519. output.writeStartElement("script");
  520. scriptFile = new QFile(QSettings.value("config") + "/Scripts/qrcode.js");
  521. scriptFile.open(1);
  522. output.writeCDATA(scriptFile.readToString());
  523. scriptFile.close();
  524. output.writeEndElement();
  525. output.writeStartElement("script");
  526. scriptFile = new QFile(QSettings.value("config") + "/Scripts/barcode.js");
  527. scriptFile.open(1);
  528. output.writeCDATA(scriptFile.readToString());
  529. scriptFile.close();
  530. output.writeEndElement();
  531. output.writeEndElement();
  532. output.writeStartElement("body");
  533. output.writeStartElement("h1");
  534. output.writeCharacters(name + " (" + item + ")");
  535. output.writeEndElement();
  536. output.writeTextElement("span", "Roasted at: " + batchTime);
  537. output.writeTextElement("span", "On machine: " + machine);
  538. output.writeTextElement("span", "Batch file: " + fileID);
  539. output.writeStartElement("div");
  540. output.writeAttribute("id", "barcode");
  541. output.writeAttribute("class", "barcode128h");
  542. output.writeAttribute("align", "center");
  543. output.writeEndElement();
  544. output.writeStartElement("script");
  545. var c128data = 'var strBarcodeHTML = code128("';
  546. c128data += fileID;
  547. c128data += '", "C");'
  548. c128data += 'document.getElementById("barcode").innerHTML = strBarcodeHTML;';
  549. output.writeCDATA(c128data);
  550. output.writeEndElement();
  551. output.writeStartElement("div");
  552. output.writeAttribute("id", "container");
  553. output.writeEndElement();
  554. output.writeStartElement("script");
  555. var tag = {g: "Typica", m: Number(machine), v: 1};
  556. tag.t = batchTime;
  557. tag.f = Number(fileID);
  558. var scriptData = 'var width = document.getElementById("container").offsetWidth;';
  559. scriptData += 'var qrcode = new QRCode({content: \'';
  560. scriptData += JSON.stringify(tag);
  561. scriptData += '\', width: width, height: width});';
  562. scriptData += 'var svg = qrcode.svg();';
  563. scriptData += 'document.getElementById("container").innerHTML = svg;';
  564. output.writeCDATA(scriptData);
  565. output.writeEndElement();
  566. output.writeEndElement();
  567. output.writeEndElement();
  568. output.writeEndDocument();
  569. batchTag.setContent(buffer);
  570. buffer.close();
  571. };
  572. var search = findChildObject(this, 'search');
  573. search.returnPressed.connect(function() {
  574. if(search.text.length == 0) {
  575. return;
  576. }
  577. if(Number(search.text)) {
  578. if(search.text[0] == '0' && search.text[1] == '0') {
  579. var query = new QSqlQuery();
  580. query.prepare("SELECT machine, time FROM scheduled_roasts WHERE id = :id");
  581. query.bind(":id", Number(search.text));
  582. query.exec();
  583. if(query.next()) {
  584. window.loadBatch(query.value(0), query.value(1));
  585. }
  586. query = query.invalidate();
  587. } else {
  588. var query = new QSqlQuery();
  589. query.prepare("SELECT machine, time FROM roasting_log WHERE files[1] = :file");
  590. query.bind(":file", Number(search.text));
  591. query.exec();
  592. if(query.next()) {
  593. window.loadBatch(query.value(0), query.value(1));
  594. }
  595. query = query.invalidate();
  596. }
  597. } else {
  598. var tag = JSON.parse(search.text);
  599. if(tag.m != undefined && tag.t != undefined) {
  600. window.loadBatch(tag.m, tag.t);
  601. }
  602. }
  603. search.text = "";
  604. });
  605. ]]>
  606. </program>
  607. </window>