1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <window id="history">
- <layout type="vertical">
- <layout type="horizontal">
- <daterange id="dates" initial="6" /><!-- Last 7 Days -->
- <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 table = findChildObject(this, 'table');
- table.openEntryRow.connect(function(arg) {
- var details = createWindow("batchDetails");
- details.loadData(table, arg);
- });
- function refresh() {
- var dateRange = dateSelect.currentRange();
- var startDate = "'"+dateRange[0]+"'";
- var endDate = "'"+dateRange[dateRange.length - 1]+"'";
- var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity AS green, roasted_quantity AS roasted, ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) AS weight_loss, duration, annotation FROM roasting_log WHERE time >= " + startDate + "::date AND time < " + endDate + "::date + interval '1 day' 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>
|