Typica is a free program for professional coffee roasters. https://typica.us
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

newbatch.xml 38KB

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