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.

greenforroasted.xml 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <window id="greenforroasted">
  2. <reporttitle>Production:->Green Coffees Used for Roasted Coffees</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <daterange id="dates" initial="19" /><!-- Year to Date -->
  6. <label>Weight Unit:</label>
  7. <sqldrop id="unit" />
  8. <stretch />
  9. </layout>
  10. <webview id="report" />
  11. </layout>
  12. <menu name="File">
  13. <item id="print" shortcut="Ctrl+P">Print...</item>
  14. </menu>
  15. <menu name="Reports" type="reports" src="Reports" />
  16. <program>
  17. <![CDATA[
  18. this.windowTitle = TTR("greenforroasted", "Typica - Green Coffees Used for Roasted Coffees");
  19. var report = findChildObject(this, 'report');
  20. var printMenu = findChildObject(this, 'print');
  21. printMenu.triggered.connect(function() {
  22. report.print();
  23. });
  24. var dateSelect = findChildObject(this, 'dates');
  25. var dateQuery = new QSqlQuery;
  26. dateQuery.exec("SELECT time::date FROM transactions WHERE time = (SELECT min(time) FROM transactions) OR time = (SELECT max(time) FROM transactions) ORDER BY time ASC");
  27. dateQuery.next();
  28. var lifetimeStartDate = dateQuery.value(0);
  29. var lifetimeEndDate;
  30. if(dateQuery.next()) {
  31. lifetimeEndDate = dateQuery.value(0);
  32. } else {
  33. lifetimeEndDate = lifetimeStartDate;
  34. }
  35. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  36. dateQuery = dateQuery.invalidate();
  37. dateSelect.rangeUpdated.connect(refresh);
  38. var unitBox = findChildObject(this, 'unit');
  39. unitBox.addItem(TTR("greenforroasted", "Kg"));
  40. unitBox.addItem(TTR("greenforroasted", "Lb"));
  41. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  42. unitBox['currentIndexChanged(int)'].connect(function() {
  43. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  44. refresh();
  45. });
  46. function refresh() {
  47. var dateRange = dateSelect.currentRange();
  48. var startDate = dateRange[0];
  49. var endDate = dateRange[dateRange.length - 1];
  50. var conversion = 1;
  51. var unitText = TTR("greensales", "Lb");
  52. if(unitBox.currentIndex == 0) {
  53. conversion = 2.2;
  54. unitText = TTR("greensales", "Kg");
  55. }
  56. var buffer = new QBuffer;
  57. buffer.open(3);
  58. var output = new XmlWriter(buffer);
  59. output.writeStartDocument("1.0");
  60. output.writeDTD('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg.dtd">');
  61. output.writeStartElement("html");
  62. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  63. output.writeStartElement("head");
  64. output.writeTextElement("title", TTR("greenforroasted", "Green Coffees Used for Roasted Coffees"));
  65. output.writeEndElement(); //head
  66. output.writeStartElement("body");
  67. var cdt = new Date(Date.now());
  68. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  69. output.writeTextElement("h1", TTR("greenforroasted", "Green Coffees Used for Roasted Coffees ") + startDate + "-" + endDate);
  70. output.writeStartElement("ul");
  71. var query = new QSqlQuery();
  72. query.prepare("WITH q AS (SELECT roasted_id, unroasted_id, (SELECT name FROM items WHERE id = roasted_id) AS rname, generate_subscripts(unroasted_id, 1) AS s, sum(roasted_quantity)/:c1 AS rq, min(time)::date, max(time)::date FROM roasting_log WHERE time >= :sd1 AND time < :ed1 ::date + interval '1 day' GROUP BY roasted_id, unroasted_id) SELECT q.*, (SELECT name FROM items WHERE id = unroasted_id[q.s]) || ' (' || unroasted_id[q.s] || ')' AS gname, (SELECT SUM(unroasted_quantity[q.s])/:c2 AS gq FROM roasting_log WHERE roasted_id = q.roasted_id AND unroasted_id = q.unroasted_id AND time >= :sd2 AND time < :ed2 ::date + interval '1 day') FROM q ORDER BY q.rname ASC, min ASC");
  73. query.bind(":sd1", startDate);
  74. query.bind(":sd2", startDate);
  75. query.bind(":ed1", endDate);
  76. query.bind(":ed2", endDate);
  77. query.bind(":c1", conversion);
  78. query.bind(":c2", conversion);
  79. query.exec();
  80. var prevRid = -1;
  81. var prevGid = "";
  82. var first = true;
  83. while(query.next()) {
  84. if(query.value(0) != prevRid) { // New roasted item
  85. if(!first) {
  86. output.writeEndElement(); //ul from previous roasted item
  87. output.writeEndElement(); //ul from previous roasted item
  88. } else {
  89. first = false;
  90. }
  91. output.writeTextElement("li", query.value(2) + " (" + query.value(0) + ")");
  92. output.writeStartElement("ul");
  93. output.writeTextElement("li", query.value(4) + " " + unitText + " roasted between " + query.value(5) + " and " + query.value(6) + " with:");
  94. output.writeStartElement("ul");
  95. output.writeTextElement("li", query.value(8) + " " + unitText + " of " + query.value(7));
  96. }
  97. else { // Same roasted item
  98. if(query.value(1) != prevGid) { // New set of greens
  99. output.writeEndElement(); //ul
  100. output.writeTextElement("li", query.value(4) + " " + unitText + " roasted between " + query.value(5) + " and " + query.value(6) + " with:");
  101. output.writeStartElement("ul");
  102. output.writeTextElement("li", query.value(8) + " " + unitText + " of " + query.value(7));
  103. } else { // Same set of greens
  104. output.writeTextElement("li", query.value(8) + " " + unitText + " of " + query.value(7));
  105. }
  106. }
  107. prevRid = query.value(0);
  108. prevGid = query.value(1);
  109. }
  110. output.writeEndElement(); //ul
  111. output.writeEndElement(); //body
  112. output.writeEndElement(); //html
  113. output.writeEndDocument();
  114. report.setContent(buffer);
  115. buffer.close();
  116. }
  117. refresh();
  118. var notifier = Application.subscribe("roastinglogchange");
  119. notifier.notify.connect(function() {
  120. refresh();
  121. });
  122. ]]>
  123. </program>
  124. </window>