Typica is a free program for professional coffee roasters. https://typica.us
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

newbatch.xml 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. table.clear();
  311. var query = new QSqlQuery();
  312. var q = "SELECT EXISTS(SELECT 1 FROM item_files WHERE item = ";
  313. q = q + roasted.currentData();
  314. q = q + ")";
  315. query.exec(q);
  316. if(query.next())
  317. {
  318. if(query.value(0) == 'false')
  319. {
  320. profilebutton.setEnabled(false);
  321. }
  322. else
  323. {
  324. profilebutton.setEnabled(true);
  325. }
  326. }
  327. else
  328. {
  329. profilebutton.setEnabled(false);
  330. }
  331. var title = "Typica - [*]New Batch (";
  332. title = title + roasted.currentText;
  333. title = title + ")";
  334. batch.windowTitle = title;
  335. q = "SELECT unroasted_id FROM roasting_log WHERE roasted_id = ";
  336. q = q + roasted.currentData();
  337. q = q + " AND time = (SELECT max(time) FROM roasting_log WHERE roasted_id = ";
  338. q = q + roasted.currentData();
  339. q = q + ")";
  340. query.exec(q);
  341. if(query.next())
  342. {
  343. var unroasted_items = sqlToArray(query.value(0));
  344. var names = [];
  345. q = "SELECT name FROM items WHERE id = :id AND quantity <> 0";
  346. query.prepare(q);
  347. var allInStock = true;
  348. for(var i = 0; i < unroasted_items.length; i++)
  349. {
  350. query.bind("id", unroasted_items[i]);
  351. query.exec();
  352. if(query.next())
  353. {
  354. names[i] = query.value(0);
  355. }
  356. else
  357. {
  358. allInStock = false;
  359. }
  360. }
  361. if(allInStock)
  362. {
  363. for(var i = 0; i < unroasted_items.length; i++)
  364. {
  365. table.setData(i, 0, names[i], 0);
  366. table.setData(i, 0, unroasted_items[i], 32);
  367. }
  368. }
  369. }
  370. query.prepare("SELECT loss, tolerance, notes FROM roasting_specification WHERE item = :id1 AND time = (SELECT max(time) FROM roasting_specification WHERE item = :id2)");
  371. query.bind(":id1", roasted.currentData());
  372. query.bind(":id2", roasted.currentData());
  373. query.exec();
  374. var lossSpecDescription = "";
  375. if(query.next()) {
  376. if(query.value(0).length > 0) {
  377. lossSpecDescription += (Number(query.value(0)) * 100).toFixed(2);
  378. minloss = Number(query.value(0));
  379. maxloss = Number(query.value(0));
  380. expectloss = Number(query.value(0));
  381. }
  382. if(query.value(1).length > 0) {
  383. lossSpecDescription += " +/- " + (Number(query.value(1)) * 100).toFixed(2);
  384. minloss -= Number(query.value(1));
  385. maxloss += Number(query.value(1));
  386. }
  387. if(lossSpecDescription.length > 0) {
  388. lossSpecDescription += "%";
  389. }
  390. lossspec.text = lossSpecDescription;
  391. specnotes.plainText = query.value(2);
  392. } else {
  393. lossspec.text = "";
  394. specnotes.plainText = "";
  395. }
  396. query = query.invalidate();
  397. drawTag();
  398. });
  399. var validateCapacity = function() {
  400. if(checkCapacity == "true") {
  401. if(convertToPounds(parseFloat(green.text), unitBox.currentText) > poundsCapacity) {
  402. return false;
  403. }
  404. }
  405. return true;
  406. }
  407. var duration = findChildObject(this, 'duration');
  408. var timefield = findChildObject(this, 'time');
  409. profilebutton.clicked.connect(function() {
  410. var proceed = false;
  411. if(validateCapacity()) {
  412. proceed = true;
  413. } else {
  414. proceed = displayWarning(TTR("batchWindow", "Suspicious Input"),
  415. TTR("batchWindow", "Entered green coffee weight exceeds maximum batch size. Continue?"));
  416. }
  417. if((proceed == true) && (timefield.text.length != 0)) {
  418. proceed = displayWarning(TTR("batchWindow", "Batch Already Roasted"),
  419. 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?"));
  420. }
  421. if(proceed) {
  422. doLoadProfile();
  423. }
  424. });
  425. var doLoadProfile = function() {
  426. batch.windowModified = true;
  427. currentBatchInfo = batch;
  428. query = new QSqlQuery();
  429. var q = "SELECT files FROM item_files WHERE item = :item AND time = (SELECT max(time) FROM item_files WHERE item = :again)";
  430. query.prepare(q);
  431. query.bind(":item", Number(roasted.currentData()));
  432. query.bind(":again", Number(roasted.currentData()));
  433. query.exec();
  434. var graph;
  435. var log;
  436. if(query.next())
  437. {
  438. var files = query.value(0);
  439. files = files.replace("{", "(");
  440. files = files.replace("}", ")");
  441. q = "SELECT file, name FROM files WHERE id IN ";
  442. q = q + files;
  443. q = q + " AND type = 'profile'";
  444. query.exec(q);
  445. if(query.next())
  446. {
  447. var targetseries = -1;
  448. var buffer = new QBuffer(query.value(0));
  449. var pname = query.value(1);
  450. var input = new XMLInput(buffer, 1);
  451. graph = findChildObject(navigationwindow.loggingWindow, 'graph');
  452. log = findChildObject(navigationwindow.loggingWindow, 'log');
  453. log.clear();
  454. graph.clear();
  455. input.newTemperatureColumn.connect(log.setHeaderData);
  456. input.newTemperatureColumn.connect(function(col, text) {
  457. if(text == navigationwindow.loggingWindow.targetcolumnname)
  458. {
  459. targetseries = col;
  460. }
  461. });
  462. input.newAnnotationColumn.connect(log.setHeaderData);
  463. input.measure.connect(graph.newMeasurement);
  464. input.measure.connect(log.newMeasurement);
  465. input.measure.connect(function(data, series) {
  466. if(series == targetseries)
  467. {
  468. targetDetector.newMeasurement(data);
  469. }
  470. });
  471. var lc;
  472. input.lastColumn.connect(function(c) {
  473. lc = c;
  474. QSettings.setValue("liveColumn", c + 1);
  475. navigationwindow.loggingWindow.postLoadColumnSetup(c)
  476. });
  477. input.annotation.connect(function(note, tcol, ncol) {
  478. for(var i = tcol; i < ncol; i++) {
  479. log.newAnnotation(note, i, ncol);
  480. }
  481. });
  482. }
  483. }
  484. query = query.invalidate();
  485. navigationwindow.loggingWindow.windowTitle = "Typica - [*]" + pname;
  486. navigationwindow.loggingWindow.raise();
  487. navigationwindow.loggingWindow.activateWindow();
  488. graph.updatesEnabled = false;
  489. log.updatesEnabled = false;
  490. input.input();
  491. log.updatesEnabled = true;
  492. graph.updatesEnabled = true;
  493. log.newAnnotation(TTR("batchWindow", "End"), 1, lc);
  494. }
  495. var noprofilebutton = findChildObject(this, 'noprofile');
  496. noprofilebutton.clicked.connect(function() {
  497. var proceed = false;
  498. if(validateCapacity()) {
  499. proceed = true;
  500. } else {
  501. proceed = displayWarning(TTR("batchWindow", "Suspicious Input"),
  502. TTR("batchWindow", "Entered green coffee weight exceeds maximum batch size. Continue?"));
  503. }
  504. if((proceed == true) && (timefield.text.length != 0)) {
  505. proceed = displayWarning(TTR("batchWindow", "Batch Already Roasted"),
  506. 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?"));
  507. }
  508. if(proceed) {
  509. doNoProfile();
  510. }
  511. });
  512. var doNoProfile = function() {
  513. batch.windowModified = true;
  514. currentBatchInfo = batch;
  515. navigationwindow.loggingWindow.raise();
  516. navigationwindow.loggingWindow.activateWindow();
  517. }
  518. var submitbutton = findChildObject(this, 'submit');
  519. var notes = findChildObject(this, 'annotation');
  520. var approval = findChildObject(this, 'approval');
  521. approval.checked = true;
  522. var target = findChildObject(this, 'target');
  523. var greenCheck = function() {
  524. var itemArray = table.columnArray(0, 32).split("\\s*,\\s*");
  525. var weightArray = table.columnArray(1, 0).split("\\s*,\\s*");
  526. return (itemArray.length == weightArray.length) && (itemArray.length > 0);
  527. }
  528. var checkSubmitEnable = function () {
  529. if(roasted.currentIndex > 0) {
  530. if(timefield.text.length > 0) {
  531. if(duration.text.length > 0) {
  532. if(batch.tempData.length > 0) {
  533. if(green.text.length > 0) {
  534. if(greenCheck()) {
  535. return true;
  536. }
  537. }
  538. }
  539. }
  540. }
  541. }
  542. return false;
  543. }
  544. submitbutton.clicked.connect(function() {
  545. var proceed = false;
  546. if(validateCapacity()) {
  547. proceed = true;
  548. } else {
  549. proceed = displayWarning(TTR("batchWindow", "Suspicious Input"),
  550. TTR("batchWindow", "Entered green coffee weight exceeds maximum batch size. Continue?"));
  551. }
  552. if(proceed) {
  553. if(checkSubmitEnable()) {
  554. doSubmit();
  555. } else {
  556. displayError(TTR("batchWindow", "Incomplete Input"),
  557. TTR("batchWindow", "Some required information is not available. Please check inputs and try again."));
  558. }
  559. }
  560. });
  561. var filenofield = findChildObject(this, 'filenofield');
  562. this.endBatch = function() {
  563. var q = "INSERT INTO files (id, name, type, note, file) VALUES(default, :name, 'profile', NULL, :data) RETURNING id";
  564. var query = new QSqlQuery();
  565. query.prepare(q);
  566. query.bind(":name", timefield.text + " " + roasted.currentText);
  567. query.bindFileData(":data", batch.tempData);
  568. query.exec();
  569. query.next();
  570. filenofield.text = query.value(0);
  571. var file = new QFile(batch.tempData);
  572. file.remove();
  573. drawTag();
  574. }
  575. var doSubmit = function() {
  576. checkQuery = new QSqlQuery();
  577. checkQuery.exec("SELECT 1 FROM machine WHERE id = " + selectedRoasterID);
  578. if(!checkQuery.next())
  579. {
  580. checkQuery.prepare("INSERT INTO machine (id, name) VALUES(:id, :name)");
  581. checkQuery.bind(":id", selectedRoasterID);
  582. checkQuery.bind(":name", selectedRoasterName);
  583. checkQuery.exec();
  584. }
  585. checkQuery = checkQuery.invalidate();
  586. query = new QSqlQuery();
  587. var fileno = Number(filenofield.text);
  588. 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, ";
  589. q2 = q2 + table.columnArray(0, 32);
  590. q2 = q2 + ", ";
  591. for(var i = 0; table.data(i, 1, 0).value != ""; i++)
  592. {
  593. table.setData(i, 1, convertToPounds(parseFloat(table.data(i, 1, 0)), unitBox.currentText) ,32)
  594. }
  595. q2 = q2 + table.columnArray(1, 32);
  596. q2 = q2 + ", ";
  597. q2 = q2 + convertToPounds(parseFloat(green.text), unitBox.currentText);
  598. q2 = q2 + ", ";
  599. q2 = q2 + roasted.currentData();
  600. q2 = q2 + ", ";
  601. q2 = q2 + convertToPounds(parseFloat(roastwt.text), unitBox.currentText);
  602. q2 = q2 + ", 'ROAST', :annotation, ";
  603. q2 = q2 + selectedRoasterID;
  604. q2 = q2 + ", :duration, :approval, NULL, NULL, NULL, NULL, '{";
  605. q2 = q2 + fileno;
  606. q2 = q2 + "}', :user) RETURNING time";
  607. query2 = new QSqlQuery();
  608. query2.prepare(q2);
  609. query2.bind(":time", timefield.text);
  610. query2.bind(":annotation", notes.plainText);
  611. query2.bind(":duration", duration.text);
  612. query2.bind(":approval", approval.checked);
  613. query2.bind(":user", Application.currentTypicaUser());
  614. query2.exec();
  615. if(!query2.next()) {
  616. displayError(TTR("batchWindow", "Database Insert Failed"), TTR("batchWindow", "Failed to save batch to database. Please check inputs and connection and try again."));
  617. query2 = query2.invalidate();
  618. query = query.invalidate();
  619. return;
  620. }
  621. query2 = query2.invalidate();
  622. if(target.checked) {
  623. var q3 = "INSERT INTO item_files (time, item, files) VALUES(:time, :item, '{";
  624. q3 = q3 + fileno;
  625. q3 = q3 + "}')";
  626. query.prepare(q3);
  627. query.bind(":time", timefield.text);
  628. query.bind(":item", roasted.currentData());
  629. query.exec();
  630. }
  631. query = query.invalidate();
  632. batch.windowModified = false;
  633. batch.close();
  634. }
  635. function drawTag() {
  636. var buffer = new QBuffer;
  637. buffer.open(3);
  638. var output = new XmlWriter(buffer);
  639. output.writeStartDocument("1.0");
  640. 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">');
  641. output.writeStartElement("html");
  642. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  643. output.writeStartElement("head");
  644. var styleFile = new QFile(QSettings.value("config") + "/Scripts/batchtag.css");
  645. styleFile.open(1);
  646. output.writeTextElement("style", styleFile.readToString());
  647. styleFile.close();
  648. output.writeStartElement("script");
  649. scriptFile = new QFile(QSettings.value("config") + "/Scripts/qrcode.js");
  650. scriptFile.open(1);
  651. output.writeCDATA(scriptFile.readToString());
  652. scriptFile.close();
  653. output.writeEndElement();
  654. output.writeEndElement();
  655. output.writeStartElement("body");
  656. output.writeStartElement("h1");
  657. output.writeCharacters(roasted.currentText);
  658. output.writeEndElement();
  659. output.writeTextElement("span", "Roasted at: " + timefield.text);
  660. output.writeTextElement("span", "On machine: " + machine.text);
  661. output.writeTextElement("span", "Batch file: " + filenofield.text);
  662. output.writeStartElement("div");
  663. output.writeAttribute("id", "container");
  664. output.writeEndElement();
  665. output.writeStartElement("script");
  666. var tag = {g: "Typica", m: Number(selectedRoasterID), v: 1};
  667. if(timefield.text.length > 0) {
  668. tag.t = timefield.text;
  669. }
  670. if(filenofield.text.length > 0) {
  671. tag.f = Number(filenofield.text);
  672. }
  673. var scriptData = 'var width = document.getElementById("container").offsetWidth;';
  674. scriptData += 'var qrcode = new QRCode({content: \'';
  675. scriptData += JSON.stringify(tag);
  676. scriptData += '\', width: width, height: width});';
  677. scriptData += 'var svg = qrcode.svg();';
  678. scriptData += 'document.getElementById("container").innerHTML = svg;';
  679. output.writeCDATA(scriptData);
  680. output.writeEndElement();
  681. output.writeEndElement();
  682. output.writeEndElement();
  683. output.writeEndDocument();
  684. batchTag.setContent(buffer);
  685. buffer.close();
  686. };
  687. drawTag();
  688. var printMenu = findChildObject(this, 'print');
  689. printMenu.triggered.connect(function() {
  690. batchTag.print();
  691. });
  692. var printers = findChildObject(this, 'printerlist');
  693. printers.currentIndex = printers.findText(QSettings.value("script/batchtagprinter"));
  694. printers['currentIndexChanged(int)'].connect(function() {
  695. QSettings.setValue("script/batchtagprinter", printers.currentText);
  696. });
  697. var printbutton = findChildObject(this, 'printbutton');
  698. printbutton.clicked.connect(function() {
  699. batchTag.print(printers.currentText);
  700. });
  701. ]]>
  702. </program>
  703. </window>