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 34KB

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