|
@@ -319,7 +319,108 @@
|
319
|
319
|
var roastDataExists = function() {
|
320
|
320
|
return (pluginContext.table.rowCount() > 0);
|
321
|
321
|
}
|
|
322
|
+ var roastTime = findChildObject(this, 'roastTime');
|
|
323
|
+ var attributes = findChildObject(this, 'attributes');
|
|
324
|
+ var sampleGreenArrivalDate = findChildObject(this, 'sampleGreenArrivalDate');
|
|
325
|
+ var convertToPounds = function(w, u) {
|
|
326
|
+ switch(u) {
|
|
327
|
+ case "g":
|
|
328
|
+ return w * 0.0022;
|
|
329
|
+ case "oz":
|
|
330
|
+ return w * 0.0625;
|
|
331
|
+ case "Kg":
|
|
332
|
+ return w * 2.2;
|
|
333
|
+ }
|
|
334
|
+ return w;
|
|
335
|
+ };
|
|
336
|
+ var roastedWeight = findChildObject(this, 'roastedWeight');
|
|
337
|
+ var notes = findChildObject(this, 'notes');
|
|
338
|
+ var roastDuration = findChildObject(this, 'roastDuration');
|
322
|
339
|
var doSubmit = function() {
|
|
340
|
+ var fileID = -1;
|
|
341
|
+ var query = new QSqlQuery();
|
|
342
|
+ if(roastDataExists()) {
|
|
343
|
+ var buffer = new QBuffer;
|
|
344
|
+ buffer.open(3);
|
|
345
|
+ pluginContext.table.saveXML(buffer);
|
|
346
|
+ var q = "INSERT INTO files (id, name, type, note, file) VALUES (default, :name, 'profile', NULL, :data) RETURNING id";
|
|
347
|
+ query.prepare(q);
|
|
348
|
+ query.bind(":name", roastTime.text + " Manual Entry");
|
|
349
|
+ query.bindDeviceData(":data", buffer);
|
|
350
|
+ query.exec();
|
|
351
|
+ query.next();
|
|
352
|
+ fileID = Number(query.value(0));
|
|
353
|
+ }
|
|
354
|
+ var rootIndex = machineModel.index(machineSelector.currentIndex, 0);
|
|
355
|
+ var selectedRoasterName = machineModel.data(rootIndex, 0);
|
|
356
|
+ var machineReference = machineModel.referenceElement(machineModel.data(rootIndex, 32));
|
|
357
|
+ var selectedRoasterID = machineReference.databaseid;
|
|
358
|
+ query.exec("SELECT 1 FROM machine WHERE id = " + selectedRoasterID);
|
|
359
|
+ if(!query.next()) {
|
|
360
|
+ query.prepare("INSERT INTO machine (id, name) VALUES (:id, :name)");
|
|
361
|
+ query.bind(":id", selectedRoasterID);
|
|
362
|
+ query.bind(":name", selectedRoasterName);
|
|
363
|
+ query.exec();
|
|
364
|
+ }
|
|
365
|
+ if(batchType.currentIndex == 0) {
|
|
366
|
+ /* Sample roast */
|
|
367
|
+ var attnames = sqlToArray(attributes.columnArray(0, 0));
|
|
368
|
+ for(var i = 0; i < attnames.length; i++) {
|
|
369
|
+ var attname = attnames[i];
|
|
370
|
+ if(attname[0] == '{') {
|
|
371
|
+ attname = attname.substr(1);
|
|
372
|
+ }
|
|
373
|
+ if(attname[0] == ' ') {
|
|
374
|
+ attname = attname.substr(1);
|
|
375
|
+ }
|
|
376
|
+ if(attname[attname.length - 1] == '}') {
|
|
377
|
+ attname = attname.substr(0, attname.length - 1);
|
|
378
|
+ }
|
|
379
|
+ if(attname.length == 0) {
|
|
380
|
+ break;
|
|
381
|
+ }
|
|
382
|
+ query.prepare("SELECT id FROM item_attributes WHERE name = :name");
|
|
383
|
+ query.bind(":name", attname);
|
|
384
|
+ query.exec();
|
|
385
|
+ if(query.next()) {
|
|
386
|
+ attributes.setData(i, 0, query.value(0), 32);
|
|
387
|
+ } else {
|
|
388
|
+ query.prepare("INSERT INTO item_attributes(id, name) VALUES (DEFAULT, :name) RETURNING id");
|
|
389
|
+ query.bind(":name", attname);
|
|
390
|
+ query.exec();
|
|
391
|
+ query.next();
|
|
392
|
+ attributes.setData(i, 0, query.value(0), 32);
|
|
393
|
+ }
|
|
394
|
+ }
|
|
395
|
+ query.prepare("INSERT INTO coffee_sample_items(id, name, reference, unit, quantity, category, arrival, vendor, attribute_ids, attribute_values) VALUES (DEFAULT, :name, NULL, 'lb', 0, 'Coffee: Green Sample', :arrival, :vendor, :attrids, :attrvals) RETURNING id");
|
|
396
|
+ query.bind(":name", sampleGreenName.text);
|
|
397
|
+ query.bind(":arrival", sampleGreenArrival.date);
|
|
398
|
+ query.bind(":attrids", attributes.bindableColumnArray(0, 32));
|
|
399
|
+ query.bind(":attrvals", attributes.bindableQuotedColumnArray(1, 0));
|
|
400
|
+ query.exec();
|
|
401
|
+ query.next();
|
|
402
|
+ var greenId = query.value(0);
|
|
403
|
+ query.prepare("INSERT INTO items (id, name, reference, unit, quantity, category) VALUES (DEFAULT, :name, NULL, 'lb', 0, 'Coffee: Roasted Sample') RETURNING id");
|
|
404
|
+ query.bind(":name", sampleGreenName.text + " Roasted Sample");
|
|
405
|
+ query.exec();
|
|
406
|
+ query.next();
|
|
407
|
+ var roastedId = query.value(0);
|
|
408
|
+ query.prepare("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, :unroastedids, :greens, :green, :roastedid, :roasted, 'SAMPLEROAST', :note, :machine, :duration, TRUE, NULL, NULL, NULL, NULL, :files)");
|
|
409
|
+ query.bind(":time", roastTime.text);
|
|
410
|
+ query.bind(":unroastedids", "{" + greenId + "}");
|
|
411
|
+ query.bind(":greens", "{" + convertToPounds(parseFloat(sampleGreenWeight.text), sampleGreenUnit.currentText) + "}");
|
|
412
|
+ query.bind(":green", convertToPounds(parseFloat(sampleGreenWeight.text), sampleGreenUnit.currentText));
|
|
413
|
+ query.bind("roastedid", Number(roastedId));
|
|
414
|
+ query.bind("roasted", convertToPounds(parseFloat(roastedWeight.text), sampleGreenUnit.currentText));
|
|
415
|
+ query.bind(":note", notes.plainText);
|
|
416
|
+ query.bind(":machine", Number(selectedRoasterID));
|
|
417
|
+ query.bind(":duration", roastDuration.text);
|
|
418
|
+ query.bind(":files", "{" + fileID + "}");
|
|
419
|
+ query.exec();
|
|
420
|
+ } else {
|
|
421
|
+ /* Production roast */
|
|
422
|
+ }
|
|
423
|
+ query = query.invalidate();
|
323
|
424
|
window.close();
|
324
|
425
|
}
|
325
|
426
|
var submit = findChildObject(this, 'submit');
|