Batch Type:
Approval:
Weight Unit:
var dateSelect = findChildObject(this, 'dates'); var dateQuery = new QSqlQuery(); dateQuery.exec("SELECT time::date FROM roasting_log WHERE time = (SELECT min(time) FROM roasting_log) OR time = (SELECT max(time) FROM roasting_log) ORDER BY time ASC"); dateQuery.next(); var lifetimeStartDate = dateQuery.value(0); var lifetimeEndDate; if(dateQuery.next()) { lifetimeEndDate = dateQuery.value(0); } else { lifetimeEndDate = lifetimeStartDate; } dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate); dateQuery.invalidate(); dateSelect.currentIndex = QSettings.value("script/history/dateIndex", 6); var unitBox = findChildObject(this, 'unit'); unitBox.addItem("Kg"); unitBox.addItem("Lb"); unitBox.currentIndex = QSettings.value("script/history_unit", 1); unitBox['currentIndexChanged(int)'].connect(function() { QSettings.setValue("script/history_unit", unitBox.currentIndex); refresh(); }); var batchType = findChildObject(this, 'batchtype'); batchType.addItem("Any"); batchType.addItem("Production Roasts"); batchType.addItem("SampleRoasts"); batchType.currentIndex = QSettings.value("script/historybatchtypefilter", 1); batchType['currentIndexChanged(int)'].connect(function() { QSettings.setValue("script/historybatchtypefilter", batchType.currentIndex); refresh(); }); var approval = findChildObject(this, 'approval'); approval.addItem("Any"); approval.addItem("Approved"); approval.addItem("Not Approved"); approval.currentIndex = QSettings.value("script/historyapprovalfilter", 1); approval['currentIndexChanged(int)'].connect(function() { QSettings.setValue("script/historyapprovalfilter", approval.currentIndex); refresh(); }); var table = findChildObject(this, 'table'); table.openEntryRow.connect(function(arg) { var details = createWindow("batchDetails"); details.loadData(table, arg); }); function refresh() { var transaction_filter; var approval_filter; switch(batchType.currentIndex) { case 0: transaction_filter = ""; break; case 1: transaction_filter = " AND transaction_type = 'ROAST'"; break; case 2: transaction_filter = " AND transaction_type = 'SAMPLEROAST'"; break; } switch(approval.currentIndex) { case 0: approval_filter = ""; break; case 1: approval_filter = " AND approval = true"; break; case 2: approval_filter = " AND approval = false"; break; } var dateRange = dateSelect.currentRange(); var startDate = "'"+dateRange[0]+"'"; var endDate = "'"+dateRange[dateRange.length - 1]+"'"; var conversion = 1; if(unitBox.currentIndex == 0) { conversion = 2.2; } var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity / " + conversion + " AS green, roasted_quantity / " + conversion + " AS roasted, CASE WHEN unroasted_total_quantity = 0 THEN NULL ELSE ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) END AS weight_loss, duration, annotation FROM roasting_log WHERE time >= " + startDate + "::date AND time < " + endDate + "::date + interval '1 day'" + transaction_filter + approval_filter + " ORDER BY time DESC"; table.setQuery(q); table.hideColumn(1); } dateSelect.rangeUpdated.connect(function() { if(dateSelect.currentIndex != 24) { // Custom date range QSettings.setValue("script/history/dateIndex", dateSelect.currentIndex); } refresh(); }); refresh();