Typica is a free program for professional coffee roasters. https://typica.us
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

batchdetailsnew.xml 35KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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. Windows.loggingWindow.loadPlan(buffer, pname);
  167. });
  168. var approvalButton = findChildObject(this, 'approval');
  169. var annotationField = findChildObject(this, 'annotation');
  170. var roastedEdit = findChildObject(this, 'roasted');
  171. var unitEdit = findChildObject(this, 'roastunit');
  172. var wholecolor = findChildObject(this, 'wholecolor');
  173. var groundcolor = findChildObject(this, 'groundcolor');
  174. window.loadBatch = function(mref, tref) {
  175. machine = mref;
  176. batchTime = tref;
  177. var query = new QSqlQuery();
  178. 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";
  179. query.prepare(q);
  180. query.bind(":machine", mref);
  181. query.bind(":time", tref);
  182. query.bind(":c1", conversion);
  183. query.bind(":c2", conversion);
  184. query.exec();
  185. if(query.next()) {
  186. var buffer = new QBuffer;
  187. buffer.open(3);
  188. var output = new XmlWriter(buffer);
  189. output.writeStartDocument("1.0");
  190. 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">');
  191. output.writeStartElement("html");
  192. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  193. output.writeStartElement("head");
  194. output.writeTextElement("title", "Batch Details");
  195. output.writeEndElement();
  196. output.writeStartElement("body");
  197. output.writeStartElement("div");
  198. output.writeAttribute("style", "float: left; padding-right: 10px");
  199. output.writeStartElement("p");
  200. output.writeTextElement("strong", TTR("batchDetails", "Roasted Coffee: "));
  201. output.writeTextElement("span", query.value(0));
  202. output.writeEndElement();
  203. output.writeEndElement();
  204. output.writeStartElement("div");
  205. output.writeAttribute("style", "float: left");
  206. output.writeStartElement("p");
  207. output.writeTextElement("strong", TTR("batchDetails", "Roasted At: "));
  208. output.writeTextElement("span", batchTime);
  209. output.writeEndElement();
  210. output.writeStartElement("p");
  211. output.writeTextElement("strong", TTR("batchDetails", "Batch Duration: "));
  212. output.writeTextElement("span", query.value(1));
  213. output.writeEndElement();
  214. output.writeEndElement();
  215. output.writeStartElement("div");
  216. output.writeAttribute("style", "clear: both");
  217. output.writeEndElement();
  218. output.writeStartElement("table");
  219. output.writeStartElement("thead");
  220. output.writeStartElement("tr");
  221. output.writeTextElement("th", TTR("batchDetails", "Green Coffee"));
  222. output.writeTextElement("th", TTR("batchDetails", "Weight") + "(" + unitText + ")");
  223. output.writeEndElement();
  224. output.writeEndElement();
  225. output.writeStartElement("tbody");
  226. var items = sqlToArray(query.value(2));
  227. var quantities = sqlToArray(query.value(3));
  228. for(var i = 0; i < items.length; i++) {
  229. output.writeStartElement("tr");
  230. output.writeTextElement("td", items[i]);
  231. output.writeStartElement("td");
  232. output.writeAttribute("align", "center");
  233. output.writeCharacters(Number(quantities[i]/conversion).toFixed(3));
  234. output.writeEndElement();
  235. output.writeEndElement();
  236. }
  237. output.writeEndElement();
  238. output.writeStartElement("tfoot");
  239. output.writeStartElement("tr");
  240. output.writeStartElement("td");
  241. output.writeAttribute("align", "right");
  242. output.writeTextElement("strong", TTR("batchDetails", "Green Total:"));
  243. output.writeEndElement();
  244. output.writeStartElement("td");
  245. output.writeAttribute("align", "center");
  246. output.writeCharacters(query.value(4));
  247. output.writeEndElement();
  248. output.writeEndElement();
  249. output.writeStartElement("tr");
  250. output.writeStartElement("td");
  251. output.writeAttribute("align", "right");
  252. output.writeTextElement("strong", TTR("batchDetails", "Roasted Weight:"));
  253. output.writeEndElement();
  254. output.writeStartElement("td");
  255. output.writeAttribute("align", "center");
  256. output.writeCharacters(query.value(5));
  257. output.writeEndElement();
  258. output.writeEndElement();
  259. output.writeStartElement("tr");
  260. output.writeStartElement("td");
  261. output.writeAttribute("align", "right");
  262. output.writeTextElement("strong", TTR("batchDetails", "Weight Loss:"));
  263. output.writeEndElement();
  264. output.writeStartElement("td");
  265. output.writeAttribute("align", "center");
  266. if(Number(query.value(4)) > 0) {
  267. output.writeCharacters(Number(((Number(query.value(4)) - Number(query.value(5)))/Number(query.value(4))) * 100).toFixed(2));
  268. output.writeCharacters("%");
  269. } else {
  270. output.writeCharacters("unknown");
  271. }
  272. output.writeEndElement();
  273. output.writeEndElement();
  274. output.writeEndElement();
  275. output.writeEndElement();
  276. if(query.value(10).length > 0) {
  277. var extradata = JSON.parse(query.value(10));
  278. if(extradata.color) {
  279. output.writeStartElement("p");
  280. output.writeTextElement("strong", TTR("batchDetails", "Degree of Roast"));
  281. output.writeEndElement();
  282. if(extradata.color.whole) {
  283. wholecolor.value = extradata.color.whole;
  284. output.writeStartElement("p");
  285. output.writeTextElement("strong", TTR("batchDetails", "Whole Bean: "));
  286. output.writeTextElement("span", extradata.color.whole);
  287. output.writeEndElement();
  288. } else {
  289. wholecolor.value = "";
  290. }
  291. if(extradata.color.ground) {
  292. groundcolor.value = extradata.color.ground;
  293. output.writeStartElement("p");
  294. output.writeTextElement("strong", TTR("batchDetails", "Ground: "));
  295. output.writeTextElement("span", extradata.color.ground);
  296. output.writeEndElement();
  297. } else {
  298. groundcolor.value = "";
  299. }
  300. } else {
  301. wholecolor.value = "";
  302. groundcolor.value = "";
  303. }
  304. } else {
  305. wholecolor.value = "";
  306. groundcolor.value = "";
  307. }
  308. output.writeStartElement("p");
  309. output.writeTextElement("strong", TTR("batchDetails", "Approved: "));
  310. output.writeCharacters(query.value(6));
  311. output.writeEndElement();
  312. output.writeStartElement("p");
  313. output.writeTextElement("strong", TTR("batchDetails", "Files: "));
  314. output.writeCharacters(query.value(7));
  315. output.writeEndElement();
  316. output.writeStartElement("p");
  317. output.writeTextElement("strong", TTR("batchDetails", "Annotations:"));
  318. var files = sqlToArray(query.value(7));
  319. var annotations = annotationFromRecord(files[0]);
  320. fileID = files[0];
  321. var buffer2 = new QBuffer("<points>"+annotations+"</points>");
  322. buffer2.open(1);
  323. var colQuery = new XQuery;
  324. colQuery.bind("profile", buffer2);
  325. colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
  326. var result = colQuery.exec();
  327. buffer2.close();
  328. var seriesHeaders = new Array();
  329. seriesHeaders.push(TTR("batchDetails", "Time"));
  330. var records = result.split(";");
  331. for(var i = 0; i < records.length - 1; i++) {
  332. seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
  333. }
  334. seriesHeaders.push(TTR("batchDetails", "Note"));
  335. output.writeStartElement("table");
  336. output.writeStartElement("thead");
  337. output.writeStartElement("tr");
  338. for(var i = 0; i < seriesHeaders.length; i++) {
  339. output.writeTextElement("th", seriesHeaders[i]);
  340. }
  341. output.writeEndElement();
  342. output.writeEndElement();
  343. buffer2.open(1);
  344. var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
  345. for(var i = 0; i < seriesHeaders.length - 2; i++) {
  346. rq += 'string($t/temperature[' + Number(i+1) + ']), ";", ';
  347. }
  348. rq += 'string($t/annotation), "~")';
  349. colQuery.setQuery(rq);
  350. var annotationData = colQuery.exec();
  351. colQuery = colQuery.invalidate();
  352. buffer2.close();
  353. output.writeStartElement("tbody");
  354. var annotationRecords = annotationData.split("~");
  355. for(var i = 0; i < annotationRecords.length - 1; i++) {
  356. output.writeStartElement("tr");
  357. var annotationRow = annotationRecords[i].split(";");
  358. for(var j = 0; j < annotationRow.length; j++) {
  359. output.writeStartElement("td");
  360. output.writeAttribute("style", "border-left: 1px solid #000000");
  361. if(j > 0) {
  362. output.writeAttribute("align", "center");
  363. }
  364. if(j > 0 && j < annotationRow.length - 1) {
  365. output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
  366. } else {
  367. output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
  368. }
  369. output.writeEndElement();
  370. }
  371. output.writeEndElement();
  372. }
  373. output.writeEndElement();
  374. output.writeEndElement();
  375. output.writeCharacters(query.value(8));
  376. output.writeEndElement();
  377. output.writeEndElement();
  378. output.writeEndElement();
  379. output.writeEndDocument();
  380. dataView.setContent(buffer);
  381. buffer.close();
  382. log.clear();
  383. graph.clear();
  384. var buffer3 = new QBuffer(query.value(9));
  385. var input = new XMLInput(buffer3, 1);
  386. input.newTemperatureColumn.connect(log.setHeaderData);
  387. input.newAnnotationColumn.connect(log.setHeaderData);
  388. var lc;
  389. input.lastColumn.connect(function(c) {
  390. lc = c;
  391. if(c < 3) {
  392. log.setHeaderData(3, "");
  393. }
  394. });
  395. input.measure.connect(graph.newMeasurement);
  396. input.measure.connect(log.newMeasurement);
  397. input.annotation.connect(function(note,tcol,ncol) {
  398. for(var i = tcol; i < ncol; i++) {
  399. log.newAnnotation(note, i, ncol);
  400. }
  401. });
  402. graph.updatesEnabled = false;
  403. log.updatesEnabled = false;
  404. input.input();
  405. log.updatesEnabled = true;
  406. graph.updatesEnabled = true;
  407. log.newAnnotation("End", 1, lc);
  408. if(query.value(6) == "true") {
  409. approvalButton.checked = true;
  410. }
  411. annotationField.plainText = query.value(8);
  412. unitEdit.text = unitText;
  413. roastedEdit.text = query.value(5);
  414. drawTag(query.value(11), query.value(0));
  415. } else {
  416. print("Something is wrong with batch data on machine " + machine + " at time " + batchTime);
  417. print("Attempting alternate query. Edit and Batch Tag tabs will not work.");
  418. query.prepare("SELECT unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, duration, approval, files, person, additional_data FROM roasting_log WHERE time = :tref AND machine = :mref");
  419. query.bind(":tref", batchTime);
  420. query.bind(":mref", machine);
  421. query.exec();
  422. if(query.next()) {
  423. var buffer = new QBuffer;
  424. buffer.open(3);
  425. var output = new XmlWriter(buffer);
  426. output.writeStartDocument("1.0");
  427. 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">');
  428. output.writeStartElement("html");
  429. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  430. output.writeStartElement("head");
  431. output.writeTextElement("title", "Batch Details");
  432. output.writeEndElement();
  433. output.writeStartElement("body");
  434. output.writeTextElement("p", "Something is wrong with the data for this batch. Falling back to a less detailed view.");
  435. output.writeTextElement("p", "unroasted_id: " + query.value(0));
  436. output.writeTextElement("p", "unroasted_quantity: " + query.value(1));
  437. output.writeTextElement("p", "unroasted_total_quantity: " + query.value(2));
  438. output.writeTextElement("p", "roasted_id: " + query.value(3));
  439. output.writeTextElement("p", "roasted_quantity: " + query.value(4));
  440. output.writeTextElement("p", "transaction_type: " + query.value(5));
  441. output.writeTextElement("p", "annotation: " + query.value(6));
  442. output.writeTextElement("p", "duration: " + query.value(7));
  443. output.writeTextElement("p", "approval: " + query.value(8));
  444. output.writeTextElement("p", "files: " + query.value(9));
  445. var files = sqlToArray(query.value(9));
  446. fileID = files[0];
  447. output.writeTextElement("p", "person: " + query.value(10));
  448. output.writeTextElement("p", "additional_data: " + query.value(11));
  449. output.writeEndElement();
  450. output.writeEndElement();
  451. output.writeEndDocument();
  452. dataView.setContent(buffer);
  453. buffer.close();
  454. query.prepare("SELECT file FROM files WHERE id = :id");
  455. query.bind(":id", fileID);
  456. query.exec();
  457. if(query.next())
  458. {
  459. var buffer = new QBuffer(query.value(0));
  460. var input = new XMLInput(buffer, 1);
  461. input.newTemperatureColumn.connect(log.setHeaderData);
  462. input.newAnnotationColumn.connect(log.setHeaderData);
  463. var lc;
  464. input.lastColumn.connect(function(c) {
  465. lc = c;
  466. if(c < 3) {
  467. log.setHeaderData(3, "");
  468. }
  469. });
  470. input.measure.connect(graph.newMeasurement);
  471. input.measure.connect(log.newMeasurement);
  472. input.annotation.connect(function(note,tcol,ncol) {
  473. for(var i = tcol; i < ncol; i++) {
  474. log.newAnnotation(note, i, ncol);
  475. }
  476. });
  477. graph.updatesEnabled = false;
  478. log.updatesEnabled = false;
  479. input.input();
  480. log.updatesEnabled = true;
  481. graph.updatesEnabled = true;
  482. log.newAnnotation("End", 1, lc);
  483. }
  484. } else {
  485. var buffer = new QBuffer;
  486. buffer.open(3);
  487. var output = new XmlWriter(buffer);
  488. output.writeStartDocument("1.0");
  489. 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">');
  490. output.writeStartElement("html");
  491. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  492. output.writeStartElement("head");
  493. output.writeTextElement("title", "Batch Details");
  494. output.writeEndElement();
  495. output.writeStartElement("body");
  496. output.writeTextElement("p", "Record not found on machine: " + machine + " at time: " + batchTime);
  497. output.writeEndElement();
  498. output.writeEndElement();
  499. output.writeEndDocument();
  500. dataView.setContent(buffer);
  501. buffer.close();
  502. }
  503. }
  504. query = query.invalidate();
  505. }
  506. var saveMenu = findChildObject(this, 'save');
  507. saveMenu.triggered.connect(function() {
  508. var filename = QFileDialog.getSaveFileName(window, TTR("batchDetails", "Save Log As..."), QSettings.value("script/lastDir", "") + "/");
  509. if(filename != "") {
  510. saveFileFromDatabase(fileID, filename);
  511. }
  512. });
  513. var submit = findChildObject(this, 'submit');
  514. submit.clicked.connect(function() {
  515. var query = new QSqlQuery;
  516. query.prepare("UPDATE roasting_log SET roasted_quantity = :roasted, approval = :approval, annotation = :annotation, additional_data = :extradata WHERE time = :time AND machine = :machine");
  517. query.bind(":approval", approvalButton.checked);
  518. query.bind(":annotation", annotationField.plainText);
  519. query.bind(":roasted", Number(Number(roastedEdit.text)*conversion));
  520. var extradata = new Object;
  521. var colordata = new Object;
  522. if(wholecolor.value.length > 0) {
  523. colordata.whole = wholecolor.value;
  524. }
  525. if(groundcolor.value.length > 0) {
  526. colordata.ground = groundcolor.value;
  527. }
  528. if(colordata.whole || colordata.ground) {
  529. extradata.color = colordata;
  530. }
  531. query.bind(":extradata", JSON.stringify(extradata));
  532. query.bind(":time", batchTime);
  533. query.bind(":machine", Number(machine));
  534. query.exec();
  535. query = query.invalidate();
  536. window.loadBatch(machine, batchTime);
  537. displayInfo(TTR("batchDetails", "Batch Data Saved"),
  538. TTR("roastspec", "New batch details saved"));
  539. });
  540. var batchTag = findChildObject(this, 'batchTag');
  541. var printers = findChildObject(this, 'printerlist');
  542. printers.currentIndex = printers.findText(QSettings.value("script/batchtagprinter"));
  543. printers['currentIndexChanged(int)'].connect(function() {
  544. QSettings.setValue("script/batchtagprinter", printers.currentText);
  545. });
  546. var printbutton = findChildObject(this, 'printbutton');
  547. printbutton.clicked.connect(function() {
  548. batchTag.print(printers.currentText);
  549. });
  550. function drawTag(item, name) {
  551. var buffer = new QBuffer;
  552. buffer.open(3);
  553. var output = new XmlWriter(buffer);
  554. output.writeStartDocument("1.0");
  555. 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">');
  556. output.writeStartElement("html");
  557. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  558. output.writeStartElement("head");
  559. var styleFile = new QFile(QSettings.value("config") + "/Scripts/batchtag.css");
  560. styleFile.open(1);
  561. output.writeTextElement("style", styleFile.readToString());
  562. styleFile.close();
  563. styleFile = new QFile(QSettings.value("config") + "/Scripts/barcode.css");
  564. styleFile.open(1);
  565. output.writeTextElement("style", styleFile.readToString());
  566. styleFile.close();
  567. output.writeStartElement("script");
  568. scriptFile = new QFile(QSettings.value("config") + "/Scripts/qrcode.js");
  569. scriptFile.open(1);
  570. output.writeCDATA(scriptFile.readToString());
  571. scriptFile.close();
  572. output.writeEndElement();
  573. output.writeStartElement("script");
  574. scriptFile = new QFile(QSettings.value("config") + "/Scripts/barcode.js");
  575. scriptFile.open(1);
  576. output.writeCDATA(scriptFile.readToString());
  577. scriptFile.close();
  578. output.writeEndElement();
  579. output.writeEndElement();
  580. output.writeStartElement("body");
  581. output.writeStartElement("h1");
  582. output.writeCharacters(name + " (" + item + ")");
  583. output.writeEndElement();
  584. output.writeTextElement("span", "Roasted at: " + batchTime);
  585. output.writeTextElement("span", "On machine: " + machine);
  586. output.writeTextElement("span", "Batch file: " + fileID);
  587. output.writeStartElement("div");
  588. output.writeAttribute("id", "barcode");
  589. output.writeAttribute("class", "barcode128h");
  590. output.writeAttribute("align", "center");
  591. output.writeEndElement();
  592. output.writeStartElement("script");
  593. var c128data = 'var strBarcodeHTML = code128("';
  594. c128data += fileID;
  595. c128data += '", "C");'
  596. c128data += 'document.getElementById("barcode").innerHTML = strBarcodeHTML;';
  597. output.writeCDATA(c128data);
  598. output.writeEndElement();
  599. output.writeStartElement("div");
  600. output.writeAttribute("id", "container");
  601. output.writeEndElement();
  602. output.writeStartElement("script");
  603. var tag = {g: "Typica", m: Number(machine), v: 1};
  604. tag.t = batchTime;
  605. tag.f = Number(fileID);
  606. var scriptData = 'var width = document.getElementById("container").offsetWidth;';
  607. scriptData += 'var qrcode = new QRCode({content: \'';
  608. scriptData += JSON.stringify(tag);
  609. scriptData += '\', width: width, height: width});';
  610. scriptData += 'var svg = qrcode.svg();';
  611. scriptData += 'document.getElementById("container").innerHTML = svg;';
  612. output.writeCDATA(scriptData);
  613. output.writeEndElement();
  614. output.writeEndElement();
  615. output.writeEndElement();
  616. output.writeEndDocument();
  617. batchTag.setContent(buffer);
  618. buffer.close();
  619. };
  620. var search = findChildObject(this, 'search');
  621. search.returnPressed.connect(function() {
  622. if(search.text.length == 0) {
  623. return;
  624. }
  625. if(Number(search.text)) {
  626. if(search.text[0] == '0' && search.text[1] == '0') {
  627. var query = new QSqlQuery();
  628. query.prepare("SELECT machine, time FROM scheduled_roasts WHERE id = :id");
  629. query.bind(":id", Number(search.text));
  630. query.exec();
  631. if(query.next()) {
  632. window.loadBatch(query.value(0), query.value(1));
  633. }
  634. query = query.invalidate();
  635. } else {
  636. var query = new QSqlQuery();
  637. query.prepare("SELECT machine, time FROM roasting_log WHERE files[1] = :file");
  638. query.bind(":file", Number(search.text));
  639. query.exec();
  640. if(query.next()) {
  641. window.loadBatch(query.value(0), query.value(1));
  642. }
  643. query = query.invalidate();
  644. }
  645. } else {
  646. var tag = JSON.parse(search.text);
  647. if(tag.m != undefined && tag.t != undefined) {
  648. window.loadBatch(tag.m, tag.t);
  649. }
  650. }
  651. search.text = "";
  652. });
  653. ]]>
  654. </program>
  655. </window>