123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <window id="history">
- <layout type="vertical">
- <layout type="horizontal">
- <label>Batch Type: </label>
- <sqldrop id="batchtype" />
- <label>Approval: </label>
- <sqldrop id="approval" />
- <daterange id="dates" initial="6" /><!-- Last 7 Days -->
- <label>Weight Unit:</label>
- <sqldrop id="unit" />
- <stretch />
- </layout>
- <sqlview id="table" />
- </layout>
- <program>
- <![CDATA[
- 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();
- ]]>
- </program>
- </window>
|