Typica is a free program for professional coffee roasters. https://typica.us
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

newbatch.xml 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <window id="batchWindow">
  2. <menu name="File">
  3. <item id="print" shortcut="Ctrl+P">Print...</item>
  4. </menu>
  5. <menu name="Batch">
  6. <item id="new" shortcut="Ctrl+N">New Batch...</item>
  7. </menu>
  8. <layout type="horizontal">
  9. <layout type="vertical">
  10. <layout type="horizontal">
  11. <label>Machine:</label>
  12. <line id="machine" writable="false" />
  13. <label>Unit:</label>
  14. <sqldrop id="unit" />
  15. <stretch />
  16. </layout>
  17. <layout type="horizontal">
  18. <label>Roasted Coffee:</label>
  19. <sqldrop data="0" display="1" showdata="true" id="roasted">
  20. <null />
  21. <query>SELECT id, name FROM items WHERE category = 'Coffee: Roasted' AND id IN (SELECT item FROM current_items) ORDER BY name</query>
  22. </sqldrop>
  23. <stretch />
  24. </layout>
  25. <label>Green Coffee:</label>
  26. <sqltablearray columns="3" id="greens">
  27. <column name="Coffee" delegate="sql" showdata="true" null="true" nulltext="Delete" nulldata="delete" data="0" display="1">SELECT id, name FROM coffees WHERE quantity &lt;&gt; 0 ORDER BY name</column>
  28. <column name="Weight" delegate="numeric" />
  29. <column name="Remaining" />
  30. </sqltablearray>
  31. <layout type="horizontal">
  32. <label>Green Weight:</label>
  33. <line id="green" writable="false">0.0</line>
  34. </layout>
  35. <layout type="horizontal">
  36. <button name="Load Profile" type="push" id="load" />
  37. <button name="No Profile" type="push" id="noprofile" />
  38. </layout>
  39. <layout type="horizontal">
  40. <label>Time:</label>
  41. <line id="time" writable="false" />
  42. <label>Duration:</label>
  43. <line id="duration" writable="false" />
  44. </layout>
  45. <layout type="horizontal">
  46. <label>Roasted Weight:</label>
  47. <line id="roast" validator="numeric">0.0</line>
  48. <label>Weight Loss:</label>
  49. <line id="wloss" writable="false" />
  50. <button type="check" id="approval" name="Approved" />
  51. </layout>
  52. <layout type="horizontal">
  53. <label>Annotation:</label>
  54. <textarea id="annotation" />
  55. </layout>
  56. <layout type="horizontal">
  57. <button name="Submit" id="submit" type="push" />
  58. <button name="Save log as target profile" type="check" id="target" />
  59. </layout>
  60. </layout>
  61. <layout type="vertical">
  62. <label>Connected Scales</label>
  63. <layout type="vertical" id="scales" />
  64. <label>Expected Weight Loss</label>
  65. <line id="lossspec" writable="false" />
  66. <label>Expected Roasted Weight</label>
  67. <layout type="horizontal">
  68. <label>Min:</label>
  69. <line id="minroastweight" writable="false" />
  70. </layout>
  71. <layout type="horizontal">
  72. <label>Expected:</label>
  73. <line id="expectedroastweight" writable="false" />
  74. </layout>
  75. <layout type="horizontal">
  76. <label>Max:</label>
  77. <line id="maxroastweight" writable="false" />
  78. </layout>
  79. <label>Specification Details</label>
  80. <textarea id="specnotes" />
  81. <layout type="horizontal">
  82. <label>File ID:</label>
  83. <line id="filenofield" writable="false" />
  84. </layout>
  85. <stretch />
  86. </layout>
  87. <layout type="vertical">
  88. <webview id="batchTag" />
  89. <layout type="horizontal">
  90. <printerselector id="printerlist" />
  91. <button name="Print" id="printbutton" type="push" />
  92. </layout>
  93. </layout>
  94. </layout>
  95. <program>
  96. <![CDATA[
  97. var unitBox = findChildObject(this, 'unit');
  98. unitBox.addItem("g");
  99. unitBox.addItem("Kg");
  100. unitBox.addItem("oz");
  101. unitBox.addItem("lb");
  102. unitBox.currentIndex = (QSettings.value("script/batch_unit", unitBox.findText("lb")));
  103. unitBox['currentIndexChanged(int)'].connect(function() {
  104. QSettings.setValue("script/batch_unit", unitBox.currentIndex);
  105. });
  106. var machine = findChildObject(this, "machine");
  107. machine.setText(selectedRoasterName + " (" + selectedRoasterID + ")");
  108. var newMenu = findChildObject(this, 'new');
  109. newMenu.triggered.connect(function() {
  110. var bwindow = createWindow("batchWindow");
  111. bwindow.windowTitle = "Typica - [*]New Batch";
  112. });
  113. var batch = this;
  114. var table = findChildObject(this, 'greens');
  115. var green = findChildObject(this, 'green');
  116. var model = table.model();
  117. var lossField = findChildObject(this, 'wloss');
  118. lossField.maximumWidth = 80;
  119. var roasted = findChildObject(this, 'roasted');
  120. var roastwt = findChildObject(this, 'roast');
  121. roastwt.maximumWidth = 80;
  122. var scalesLayout = findChildObject(this, 'scales');
  123. scalesLayout.spacing = 10;
  124. var batchTag = findChildObject(this, 'batchTag');
  125. if(navigationwindow.loggingWindow.scales.length > 0) {
  126. for(var i = 0; i < navigationwindow.loggingWindow.scales.length; i++) {
  127. var scale = navigationwindow.loggingWindow.scales[i];
  128. var label = new DragLabel();
  129. var weighButton = new QPushButton();
  130. weighButton.text = "Weigh";
  131. weighButton.clicked.connect(scale.weigh);
  132. label.updateMeasurement = function(m, u) {
  133. switch(unitBox.currentIndex) {
  134. case 0:
  135. this.text = Units.convertWeight(m, u, Units.Gram).toFixed(1);
  136. break;
  137. case 1:
  138. this.text = Units.convertWeight(m, u, Units.Kilogram).toFixed(4);
  139. break;
  140. case 2:
  141. this.text = Units.convertWeight(m, u, Units.Ounce).toFixed(3);
  142. break;
  143. case 3:
  144. this.text = Units.convertWeight(m, u, Units.Pound).toFixed(4);
  145. break;
  146. }
  147. };
  148. scalesLayout.addWidget(label);
  149. scalesLayout.addWidget(weighButton);
  150. scale.newMeasurement.connect(function(m, u) {
  151. label.updateMeasurement(m, u);
  152. });
  153. scale.weigh();
  154. unitBox['currentIndexChanged(int)'].connect(scale.weigh);
  155. }
  156. }
  157. var remainingStock = new Array();
  158. var query = new QSqlQuery();
  159. query.exec("SELECT id, quantity, (SELECT conversion FROM lb_bag_conversion WHERE item = id) FROM coffees WHERE quantity <> 0");
  160. while(query.next()) {
  161. remainingStock.push({id: query.value(0),
  162. quantity: query.value(1),
  163. conversion: query.value(2)});
  164. }
  165. query = query.invalidate();
  166. var convertToPounds = function(w, u) {
  167. switch(u) {
  168. case "g":
  169. return w * 0.0022;
  170. case "oz":
  171. return w * 0.0625;
  172. case "Kg":
  173. return w * 2.2;
  174. }
  175. return w;
  176. };
  177. var convertFromPounds = function(w, u) {
  178. switch(u) {
  179. case "g":
  180. return w / 0.0022;
  181. case "oz":
  182. return w / 0.0625;
  183. case "Kg":
  184. return w / 2.2;
  185. }
  186. return w;
  187. };
  188. var specnotes = findChildObject(this, 'specnotes');
  189. specnotes.readOnly = true;
  190. var lossspec = findChildObject(this, 'lossspec');
  191. var minfield = findChildObject(this, 'minroastweight');
  192. var midfield = findChildObject(this, 'expectedroastweight');
  193. var maxfield = findChildObject(this, 'maxroastweight');
  194. var minloss = 0;
  195. var maxloss = 0;
  196. var expectloss = 0;
  197. var updateGreenTable = function() {
  198. var deleteRow = -1;
  199. /* The combo box delegate updates user data before display data
  200. and this code is executed before the model update is fully
  201. complete. Rather than rely on this behavior continuing, we
  202. check that the display value has also been updated and defer
  203. row removal until both updates are complete.
  204. */
  205. while((deleteRow = table.findData("delete", 0)) > -1) {
  206. if(table.data(deleteRow, 0, 0) == "Delete") {
  207. table.removeRow(table.findData("delete", 0));
  208. } else {
  209. break;
  210. }
  211. }
  212. green.text = table.columnSum(1, 0);
  213. table.resizeColumnToContents(0);
  214. var gid = 0;
  215. var r = 0;
  216. while(gid >= 0)
  217. {
  218. gid = Number(table.data(r, 0, 32));
  219. if(isNaN(gid))
  220. {
  221. gid = -1;
  222. break;
  223. }
  224. var bagConversion = 1;
  225. for(var i = 0; i < remainingStock.length; i++)
  226. {
  227. if(gid == Number(remainingStock[i].id))
  228. {
  229. var displayValue = Number(remainingStock[i].quantity);
  230. bagConversion = Number(remainingStock[i].conversion);
  231. if(!isNaN(Number(table.data(r, 1, 0))))
  232. {
  233. var change = Number(table.data(r, 1, 0));
  234. switch(unitBox.currentIndex)
  235. {
  236. case 0:
  237. change = convertToPounds(change, "g");
  238. break;
  239. case 1:
  240. change = convertToPounds(change, "Kg");
  241. break;
  242. case 2:
  243. change = convertToPounds(change, "oz");
  244. break;
  245. }
  246. displayValue -= change;
  247. }
  248. var bagCount = (displayValue / bagConversion).toFixed(2);
  249. switch(unitBox.currentIndex)
  250. {
  251. case 0:
  252. displayValue = convertFromPounds(displayValue, "g");
  253. break;
  254. case 1:
  255. displayValue = convertFromPounds(displayValue, "Kg");
  256. break;
  257. case 2:
  258. displayValue = convertFromPounds(displayValue, "oz");
  259. break;
  260. }
  261. displayValue = "" + Number(displayValue).toFixed(3) + " (" + Number(bagCount).toFixed(3) + " bags)";
  262. if(table.data(r, 2, 0) != displayValue)
  263. {
  264. table.setData(r, 2, displayValue, 0);
  265. table.setData(r, 2, displayValue, 2);
  266. table.resizeColumnToContents(2);
  267. }
  268. }
  269. }
  270. r++;
  271. }
  272. if(parseFloat(green.text) > 0)
  273. {
  274. var expectedLossDesc = "";
  275. if(lossspec.text.length > 0) {
  276. if(minloss != expectloss) {
  277. minfield.text = (-(parseFloat(green.text)) * (maxloss - 1)).toFixed(2);
  278. maxfield.text = (-(parseFloat(green.text)) * (minloss - 1)).toFixed(2);
  279. }
  280. midfield.text = (-(parseFloat(green.text)) * (expectloss - 1)).toFixed(2);
  281. }
  282. if(parseFloat(roastwt.text) > 0)
  283. {
  284. lossField.text = (((parseFloat(green.text) - parseFloat(roastwt.text)) / parseFloat(green.text)) * 100).toFixed(2) + "%";
  285. }
  286. else
  287. {
  288. lossField.text = "100%";
  289. }
  290. }
  291. };
  292. model.dataChanged.connect(updateGreenTable);
  293. unitBox['currentIndexChanged(int)'].connect(updateGreenTable);
  294. roastwt.textChanged.connect(function() {
  295. if(parseFloat(green.text) > 0)
  296. {
  297. if(parseFloat(roastwt.text) > 0)
  298. {
  299. lossField.text = (((parseFloat(green.text) - parseFloat(roastwt.text)) / parseFloat(green.text)) * 100).toFixed(2) + "%";
  300. }
  301. else
  302. {
  303. lossField.text = "100%";
  304. }
  305. }
  306. });
  307. var profilebutton = findChildObject(this, 'load');
  308. profilebutton.setEnabled(false);
  309. roasted['currentIndexChanged(int)'].connect(function() {
  310. print("Roasted coffee item changed");
  311. table.clear();
  312. var query = new QSqlQuery();
  313. var q = "SELECT EXISTS(SELECT 1 FROM item_files WHERE item = ";
  314. q = q + roasted.currentData();
  315. q = q + ")";
  316. query.exec(q);
  317. if(query.next())
  318. {
  319. if(query.value(0) == 'false')
  320. {
  321. profilebutton.setEnabled(false);
  322. }
  323. else
  324. {
  325. profilebutton.setEnabled(true);
  326. }
  327. }
  328. else
  329. {
  330. profilebutton.setEnabled(false);
  331. }
  332. var title = "Typica - [*]New Batch (";
  333. title = title + roasted.currentText;
  334. title = title + ")";
  335. print("Updating window title");
  336. batch.windowTitle = title;
  337. print("Checking green coffees");
  338. q = "SELECT unroasted_id FROM roasting_log WHERE roasted_id = ";
  339. q = q + roasted.currentData();
  340. q = q + " AND time = (SELECT max(time) FROM roasting_log WHERE roasted_id = ";
  341. q = q + roasted.currentData();
  342. q = q + ")";
  343. query.exec(q);
  344. print("Updating green table");
  345. if(query.next())
  346. {
  347. var unroasted_items = sqlToArray(query.value(0));
  348. var names = [];
  349. q = "SELECT name FROM items WHERE id = :id AND quantity <> 0";
  350. query.prepare(q);
  351. var allInStock = true;
  352. for(var i = 0; i < unroasted_items.length; i++)
  353. {
  354. query.bind("id", unroasted_items[i]);
  355. query.exec();
  356. if(query.next())
  357. {
  358. names[i] = query.value(0);
  359. }
  360. else
  361. {
  362. allInStock = false;
  363. }
  364. }
  365. if(allInStock)
  366. {
  367. for(var i = 0; i < unroasted_items.length; i++)
  368. {
  369. table.setData(i, 0, names[i], 0);
  370. table.setData(i, 0, unroasted_items[i], 32);
  371. }
  372. }
  373. }
  374. print("About to query product spec");
  375. query.prepare("SELECT loss, tolerance, notes FROM roasting_specification WHERE item = :id1 AND time = (SELECT max(time) FROM roasting_specification WHERE item = :id2)");
  376. query.bind(":id1", roasted.currentData());
  377. query.bind(":id2", roasted.currentData());
  378. query.exec();
  379. var lossSpecDescription = "";
  380. print("About to read loss spec");
  381. if(query.next()) {
  382. if(query.value(0).length > 0) {
  383. lossSpecDescription += (Number(query.value(0)) * 100).toFixed(2);
  384. minloss = Number(query.value(0));
  385. maxloss = Number(query.value(0));
  386. expectloss = Number(query.value(0));
  387. }
  388. if(query.value(1).length > 0) {
  389. lossSpecDescription += " +/- " + (Number(query.value(1)) * 100).toFixed(2);
  390. minloss -= Number(query.value(1));
  391. maxloss += Number(query.value(1));
  392. }
  393. if(lossSpecDescription.length > 0) {
  394. lossSpecDescription += "%";
  395. }
  396. lossspec.text = lossSpecDescription;
  397. specnotes.plainText = query.value(2);
  398. } else {
  399. lossspec.text = "";
  400. specnotes.plainText = "";
  401. }
  402. print("Updated roast spec");
  403. //roastestimate.text = "";
  404. print("Cleared roast estimate");
  405. query = query.invalidate();
  406. print("About to redraw tag");
  407. drawTag();
  408. print("Tag redrawn");
  409. });
  410. var validateCapacity = function() {
  411. if(checkCapacity == "true") {
  412. if(convertToPounds(parseFloat(green.text), unitBox.currentText) > poundsCapacity) {
  413. return false;
  414. }
  415. }
  416. return true;
  417. }
  418. var duration = findChildObject(this, 'duration');
  419. var timefield = findChildObject(this, 'time');
  420. profilebutton.clicked.connect(function() {
  421. var proceed = false;
  422. if(validateCapacity()) {
  423. proceed = true;
  424. } else {
  425. proceed = displayWarning(TTR("batchWindow", "Suspicious Input"),
  426. TTR("batchWindow", "Entered green coffee weight exceeds maximum batch size. Continue?"));
  427. }
  428. if((proceed == true) && (timefield.text.length != 0)) {
  429. proceed = displayWarning(TTR("batchWindow", "Batch Already Roasted"),
  430. TTR("batchWindow", "Roasting data already exists for this batch. Roasting another batch from this window will overwrite existing data. Are you sure you want to do this?"));
  431. }
  432. if(proceed) {
  433. doLoadProfile();
  434. }
  435. });
  436. var doLoadProfile = function() {
  437. batch.windowModified = true;
  438. currentBatchInfo = batch;
  439. query = new QSqlQuery();
  440. var q = "SELECT files FROM item_files WHERE item = :item AND time = (SELECT max(time) FROM item_files WHERE item = :again)";
  441. query.prepare(q);
  442. query.bind(":item", Number(roasted.currentData()));
  443. query.bind(":again", Number(roasted.currentData()));
  444. query.exec();
  445. var graph;
  446. var log;
  447. if(query.next())
  448. {
  449. var files = query.value(0);
  450. files = files.replace("{", "(");
  451. files = files.replace("}", ")");
  452. q = "SELECT file, name FROM files WHERE id IN ";
  453. q = q + files;
  454. q = q + " AND type = 'profile'";
  455. query.exec(q);
  456. if(query.next())
  457. {
  458. var targetseries = -1;
  459. var buffer = new QBuffer(query.value(0));
  460. var pname = query.value(1);
  461. var input = new XMLInput(buffer, 1);
  462. graph = findChildObject(navigationwindow.loggingWindow, 'graph');
  463. log = findChildObject(navigationwindow.loggingWindow, 'log');
  464. log.clear();
  465. graph.clear();
  466. input.newTemperatureColumn.connect(log.setHeaderData);
  467. input.newTemperatureColumn.connect(function(col, text) {
  468. if(text == navigationwindow.loggingWindow.targetcolumnname)
  469. {
  470. targetseries = col;
  471. }
  472. });
  473. input.newAnnotationColumn.connect(log.setHeaderData);
  474. input.measure.connect(graph.newMeasurement);
  475. input.measure.connect(log.newMeasurement);
  476. input.measure.connect(function(data, series) {
  477. if(series == targetseries)
  478. {
  479. targetDetector.newMeasurement(data);
  480. }
  481. });
  482. var lc;
  483. input.lastColumn.connect(function(c) {
  484. lc = c;
  485. QSettings.setValue("liveColumn", c + 1);
  486. navigationwindow.loggingWindow.postLoadColumnSetup(c)
  487. });
  488. input.annotation.connect(function(note, tcol, ncol) {
  489. for(var i = tcol; i < ncol; i++) {
  490. log.newAnnotation(note, i, ncol);
  491. }
  492. });
  493. }
  494. }
  495. query = query.invalidate();
  496. navigationwindow.loggingWindow.windowTitle = "Typica - [*]" + pname;
  497. navigationwindow.loggingWindow.raise();
  498. navigationwindow.loggingWindow.activateWindow();
  499. graph.updatesEnabled = false;
  500. log.updatesEnabled = false;
  501. input.input();
  502. log.updatesEnabled = true;
  503. graph.updatesEnabled = true;
  504. log.newAnnotation(TTR("batchWindow", "End"), 1, lc);
  505. }
  506. var noprofilebutton = findChildObject(this, 'noprofile');
  507. noprofilebutton.clicked.connect(function() {
  508. var proceed = false;
  509. if(validateCapacity()) {
  510. proceed = true;
  511. } else {
  512. proceed = displayWarning(TTR("batchWindow", "Suspicious Input"),
  513. TTR("batchWindow", "Entered green coffee weight exceeds maximum batch size. Continue?"));
  514. }
  515. if((proceed == true) && (timefield.text.length != 0)) {
  516. proceed = displayWarning(TTR("batchWindow", "Batch Already Roasted"),
  517. TTR("batchWindow", "Roasting data already exists for this batch. Roasting another batch from this window will overwrite existing data. Are you sure you want to do this?"));
  518. }
  519. if(proceed) {
  520. doNoProfile();
  521. }
  522. });
  523. var doNoProfile = function() {
  524. batch.windowModified = true;
  525. currentBatchInfo = batch;
  526. navigationwindow.loggingWindow.raise();
  527. navigationwindow.loggingWindow.activateWindow();
  528. }
  529. var submitbutton = findChildObject(this, 'submit');
  530. var notes = findChildObject(this, 'annotation');
  531. var approval = findChildObject(this, 'approval');
  532. approval.checked = true;
  533. var target = findChildObject(this, 'target');
  534. var greenCheck = function() {
  535. var itemArray = table.columnArray(0, 32).split("\\s*,\\s*");
  536. var weightArray = table.columnArray(1, 0).split("\\s*,\\s*");
  537. return (itemArray.length == weightArray.length) && (itemArray.length > 0);
  538. }
  539. var checkSubmitEnable = function () {
  540. if(roasted.currentIndex > 0) {
  541. if(timefield.text.length > 0) {
  542. if(duration.text.length > 0) {
  543. if(batch.tempData.length > 0) {
  544. if(green.text.length > 0) {
  545. if(greenCheck()) {
  546. return true;
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. return false;
  554. }
  555. submitbutton.clicked.connect(function() {
  556. var proceed = false;
  557. if(validateCapacity()) {
  558. proceed = true;
  559. } else {
  560. proceed = displayWarning(TTR("batchWindow", "Suspicious Input"),
  561. TTR("batchWindow", "Entered green coffee weight exceeds maximum batch size. Continue?"));
  562. }
  563. if(proceed) {
  564. if(checkSubmitEnable()) {
  565. doSubmit();
  566. } else {
  567. displayError(TTR("batchWindow", "Incomplete Input"),
  568. TTR("batchWindow", "Some required information is not available. Please check inputs and try again."));
  569. }
  570. }
  571. });
  572. var filenofield = findChildObject(this, 'filenofield');
  573. this.endBatch = function() {
  574. var q = "INSERT INTO files (id, name, type, note, file) VALUES(default, :name, 'profile', NULL, :data) RETURNING id";
  575. var query = new QSqlQuery();
  576. query.prepare(q);
  577. query.bind(":name", timefield.text + " " + roasted.currentText);
  578. query.bindFileData(":data", batch.tempData);
  579. query.exec();
  580. query.next();
  581. filenofield.text = query.value(0);
  582. var file = new QFile(batch.tempData);
  583. file.remove();
  584. drawTag();
  585. }
  586. var doSubmit = function() {
  587. checkQuery = new QSqlQuery();
  588. checkQuery.exec("SELECT 1 FROM machine WHERE id = " + selectedRoasterID);
  589. if(!checkQuery.next())
  590. {
  591. checkQuery.prepare("INSERT INTO machine (id, name) VALUES(:id, :name)");
  592. checkQuery.bind(":id", selectedRoasterID);
  593. checkQuery.bind(":name", selectedRoasterName);
  594. checkQuery.exec();
  595. }
  596. checkQuery = checkQuery.invalidate();
  597. query = new QSqlQuery();
  598. var fileno = Number(filenofield.text);
  599. var q2 = "INSERT INTO roasting_log (time, unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, machine, duration, approval, humidity, barometric, indoor_air, outdoor_air, files) VALUES(:time, ";
  600. q2 = q2 + table.columnArray(0, 32);
  601. q2 = q2 + ", ";
  602. for(var i = 0; table.data(i, 1, 0).value != ""; i++)
  603. {
  604. table.setData(i, 1, convertToPounds(parseFloat(table.data(i, 1, 0)), unitBox.currentText) ,32)
  605. }
  606. q2 = q2 + table.columnArray(1, 32);
  607. q2 = q2 + ", ";
  608. q2 = q2 + convertToPounds(parseFloat(green.text), unitBox.currentText);
  609. q2 = q2 + ", ";
  610. q2 = q2 + roasted.currentData();
  611. q2 = q2 + ", ";
  612. q2 = q2 + convertToPounds(parseFloat(roastwt.text), unitBox.currentText);
  613. q2 = q2 + ", 'ROAST', :annotation, ";
  614. q2 = q2 + selectedRoasterID;
  615. q2 = q2 + ", :duration, :approval, NULL, NULL, NULL, NULL, '{";
  616. q2 = q2 + fileno;
  617. q2 = q2 + "}') RETURNING time";
  618. query2 = new QSqlQuery();
  619. query2.prepare(q2);
  620. query2.bind(":time", timefield.text);
  621. query2.bind(":annotation", notes.plainText);
  622. query2.bind(":duration", duration.text);
  623. query2.bind(":approval", approval.checked);
  624. query2.exec();
  625. if(!query2.next()) {
  626. displayError(TTR("batchWindow", "Database Insert Failed"), TTR("batchWindow", "Failed to save batch to database. Please check inputs and connection and try again."));
  627. query2 = query2.invalidate();
  628. query = query.invalidate();
  629. return;
  630. }
  631. query2 = query2.invalidate();
  632. if(target.checked) {
  633. var q3 = "INSERT INTO item_files (time, item, files) VALUES(:time, :item, '{";
  634. q3 = q3 + fileno;
  635. q3 = q3 + "}')";
  636. query.prepare(q3);
  637. query.bind(":time", timefield.text);
  638. query.bind(":item", roasted.currentData());
  639. query.exec();
  640. }
  641. query = query.invalidate();
  642. batch.windowModified = false;
  643. batch.close();
  644. }
  645. function drawTag() {
  646. var buffer = new QBuffer;
  647. buffer.open(3);
  648. var output = new XmlWriter(buffer);
  649. output.writeStartDocument("1.0");
  650. 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">');
  651. output.writeStartElement("html");
  652. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  653. output.writeStartElement("head");
  654. var styleFile = new QFile(QSettings.value("config") + "/Scripts/batchtag.css");
  655. styleFile.open(1);
  656. output.writeTextElement("style", styleFile.readToString());
  657. styleFile.close();
  658. output.writeStartElement("script");
  659. scriptFile = new QFile(QSettings.value("config") + "/Scripts/qrcode.js");
  660. scriptFile.open(1);
  661. output.writeCDATA(scriptFile.readToString());
  662. scriptFile.close();
  663. output.writeEndElement();
  664. output.writeEndElement();
  665. output.writeStartElement("body");
  666. output.writeStartElement("h1");
  667. output.writeCharacters(roasted.currentText);
  668. output.writeEndElement();
  669. output.writeTextElement("span", "Roasted at: " + timefield.text);
  670. output.writeTextElement("span", "On machine: " + machine.text);
  671. output.writeTextElement("span", "Batch file: " + filenofield.text);
  672. output.writeStartElement("div");
  673. output.writeAttribute("id", "container");
  674. output.writeEndElement();
  675. output.writeStartElement("script");
  676. var tag = {g: "Typica", m: Number(selectedRoasterID), v: 1};
  677. if(timefield.text.length > 0) {
  678. tag.t = timefield.text;
  679. }
  680. if(filenofield.text.length > 0) {
  681. tag.f = Number(filenofield.text);
  682. }
  683. var scriptData = 'var width = document.getElementById("container").offsetWidth;';
  684. scriptData += 'var qrcode = new QRCode({content: \'';
  685. scriptData += JSON.stringify(tag);
  686. scriptData += '\', width: width, height: width});';
  687. scriptData += 'var svg = qrcode.svg();';
  688. scriptData += 'document.getElementById("container").innerHTML = svg;';
  689. output.writeCDATA(scriptData);
  690. output.writeEndElement();
  691. output.writeEndElement();
  692. output.writeEndElement();
  693. output.writeEndDocument();
  694. batchTag.setContent(buffer);
  695. buffer.close();
  696. };
  697. drawTag();
  698. var printMenu = findChildObject(this, 'print');
  699. printMenu.triggered.connect(function() {
  700. batchTag.print();
  701. });
  702. var printers = findChildObject(this, 'printerlist');
  703. printers.currentIndex = printers.findText(QSettings.value("script/batchtagprinter"));
  704. printers['currentIndexChanged(int)'].connect(function() {
  705. QSettings.setValue("script/batchtagprinter", printers.currentText);
  706. });
  707. var printbutton = findChildObject(this, 'printbutton');
  708. printbutton.clicked.connect(function() {
  709. batchTag.print(printers.currentText);
  710. });
  711. ]]>
  712. </program>
  713. </window>