Typica is a free program for professional coffee roasters. https://typica.us
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

history.xml 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <window id="history">
  2. <layout type="vertical">
  3. <layout type="horizontal">
  4. <label>Batch Type: </label>
  5. <sqldrop id="batchtype" />
  6. <label>Approval: </label>
  7. <sqldrop id="approval" />
  8. <daterange id="dates" initial="6" /><!-- Last 7 Days -->
  9. <label>Weight Unit:</label>
  10. <sqldrop id="unit" />
  11. <stretch />
  12. </layout>
  13. <sqlview id="table" />
  14. </layout>
  15. <program>
  16. <![CDATA[
  17. var dateSelect = findChildObject(this, 'dates');
  18. var dateQuery = new QSqlQuery();
  19. 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");
  20. dateQuery.next();
  21. var lifetimeStartDate = dateQuery.value(0);
  22. var lifetimeEndDate;
  23. if(dateQuery.next()) {
  24. lifetimeEndDate = dateQuery.value(0);
  25. } else {
  26. lifetimeEndDate = lifetimeStartDate;
  27. }
  28. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  29. dateQuery.invalidate();
  30. dateSelect.currentIndex = QSettings.value("script/history/dateIndex", 6);
  31. var unitBox = findChildObject(this, 'unit');
  32. unitBox.addItem("Kg");
  33. unitBox.addItem("Lb");
  34. unitBox.currentIndex = QSettings.value("script/history_unit", 1);
  35. unitBox['currentIndexChanged(int)'].connect(function() {
  36. QSettings.setValue("script/history_unit", unitBox.currentIndex);
  37. refresh();
  38. });
  39. var batchType = findChildObject(this, 'batchtype');
  40. batchType.addItem("Any");
  41. batchType.addItem("Production Roasts");
  42. batchType.addItem("SampleRoasts");
  43. batchType.currentIndex = QSettings.value("script/historybatchtypefilter", 1);
  44. batchType['currentIndexChanged(int)'].connect(function() {
  45. QSettings.setValue("script/historybatchtypefilter", batchType.currentIndex);
  46. refresh();
  47. });
  48. var approval = findChildObject(this, 'approval');
  49. approval.addItem("Any");
  50. approval.addItem("Approved");
  51. approval.addItem("Not Approved");
  52. approval.currentIndex = QSettings.value("script/historyapprovalfilter", 1);
  53. approval['currentIndexChanged(int)'].connect(function() {
  54. QSettings.setValue("script/historyapprovalfilter", approval.currentIndex);
  55. refresh();
  56. });
  57. var table = findChildObject(this, 'table');
  58. table.openEntryRow.connect(function(arg) {
  59. var details = createWindow("batchDetails");
  60. details.loadData(table, arg);
  61. });
  62. function refresh() {
  63. var transaction_filter;
  64. var approval_filter;
  65. switch(batchType.currentIndex) {
  66. case 0:
  67. transaction_filter = "";
  68. break;
  69. case 1:
  70. transaction_filter = " AND transaction_type = 'ROAST'";
  71. break;
  72. case 2:
  73. transaction_filter = " AND transaction_type = 'SAMPLEROAST'";
  74. break;
  75. }
  76. switch(approval.currentIndex) {
  77. case 0:
  78. approval_filter = "";
  79. break;
  80. case 1:
  81. approval_filter = " AND approval = true";
  82. break;
  83. case 2:
  84. approval_filter = " AND approval = false";
  85. break;
  86. }
  87. var dateRange = dateSelect.currentRange();
  88. var startDate = "'"+dateRange[0]+"'";
  89. var endDate = "'"+dateRange[dateRange.length - 1]+"'";
  90. var conversion = 1;
  91. if(unitBox.currentIndex == 0)
  92. {
  93. conversion = 2.2;
  94. }
  95. 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";
  96. table.setQuery(q);
  97. table.hideColumn(1);
  98. }
  99. dateSelect.rangeUpdated.connect(function() {
  100. if(dateSelect.currentIndex != 24) { // Custom date range
  101. QSettings.setValue("script/history/dateIndex", dateSelect.currentIndex);
  102. }
  103. refresh();
  104. });
  105. refresh();
  106. ]]>
  107. </program>
  108. </window>