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.

newbatch.xml 29KB

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