Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

history.xml 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <window id="history">
  2. <layout type="vertical">
  3. <layout type="horizontal">
  4. <daterange id="dates" initial="6" /><!-- Last 7 Days -->
  5. <stretch />
  6. </layout>
  7. <sqlview id="table" />
  8. </layout>
  9. <program>
  10. <![CDATA[
  11. var dateSelect = findChildObject(this, 'dates');
  12. var dateQuery = new QSqlQuery();
  13. 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");
  14. dateQuery.next();
  15. var lifetimeStartDate = dateQuery.value(0);
  16. var lifetimeEndDate;
  17. if(dateQuery.next()) {
  18. lifetimeEndDate = dateQuery.value(0);
  19. } else {
  20. lifetimeEndDate = lifetimeStartDate;
  21. }
  22. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  23. dateQuery.invalidate();
  24. dateSelect.currentIndex = QSettings.value("script/history/dateIndex", 6);
  25. var table = findChildObject(this, 'table');
  26. table.openEntryRow.connect(function(arg) {
  27. var details = createWindow("batchDetails");
  28. details.loadData(table, arg);
  29. });
  30. function refresh() {
  31. var dateRange = dateSelect.currentRange();
  32. var startDate = "'"+dateRange[0]+"'";
  33. var endDate = "'"+dateRange[dateRange.length - 1]+"'";
  34. var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity AS green, roasted_quantity 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' ORDER BY time DESC";
  35. table.setQuery(q);
  36. table.hideColumn(1);
  37. }
  38. dateSelect.rangeUpdated.connect(function() {
  39. if(dateSelect.currentIndex != 24) { // Custom date range
  40. QSettings.setValue("script/history/dateIndex", dateSelect.currentIndex);
  41. }
  42. refresh();
  43. });
  44. refresh();
  45. ]]>
  46. </program>
  47. </window>