Typica is a free program for professional coffee roasters. https://typica.us
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

greenforroasted.xml 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. <program>
  16. <![CDATA[
  17. this.windowTitle = TTR("greenforroasted", "Typica - Green Coffees Used for Roasted Coffees");
  18. var report = findChildObject(this, 'report');
  19. var printMenu = findChildObject(this, 'print');
  20. printMenu.triggered.connect(function() {
  21. report.print();
  22. });
  23. var dateSelect = findChildObject(this, 'dates');
  24. var dateQuery = new QSqlQuery;
  25. 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");
  26. dateQuery.next();
  27. var lifetimeStartDate = dateQuery.value(0);
  28. var lifetimeEndDate;
  29. if(dateQuery.next()) {
  30. lifetimeEndDate = dateQuery.value(0);
  31. } else {
  32. lifetimeEndDate = lifetimeStartDate;
  33. }
  34. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  35. dateQuery = dateQuery.invalidate();
  36. dateSelect.rangeUpdated.connect(refresh);
  37. var unitBox = findChildObject(this, 'unit');
  38. unitBox.addItem(TTR("greenforroasted", "Kg"));
  39. unitBox.addItem(TTR("greenforroasted", "Lb"));
  40. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  41. unitBox['currentIndexChanged(int)'].connect(function() {
  42. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  43. refresh();
  44. });
  45. function refresh() {
  46. var dateRange = dateSelect.currentRange();
  47. var startDate = dateRange[0];
  48. var endDate = dateRange[dateRange.length - 1];
  49. var conversion = 1;
  50. var unitText = TTR("greensales", "Lb");
  51. if(unitBox.currentIndex == 0) {
  52. conversion = 2.2;
  53. unitText = TTR("greensales", "Kg");
  54. }
  55. var buffer = new QBuffer;
  56. buffer.open(3);
  57. var output = new XmlWriter(buffer);
  58. output.writeStartDocument("1.0");
  59. 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">');
  60. output.writeStartElement("html");
  61. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  62. output.writeStartElement("head");
  63. output.writeTextElement("title", TTR("greenforroasted", "Green Coffees Used for Roasted Coffees"));
  64. output.writeEndElement(); //head
  65. output.writeStartElement("body");
  66. output.writeTextElement("h1", TTR("greenforroasted", "Green Coffees Used for Roasted Coffees ") + startDate + "-" + endDate);
  67. output.writeStartElement("ul");
  68. var query = new QSqlQuery();
  69. 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");
  70. query.bind(":sd1", startDate);
  71. query.bind(":sd2", startDate);
  72. query.bind(":ed1", endDate);
  73. query.bind(":ed2", endDate);
  74. query.bind(":c1", conversion);
  75. query.bind(":c2", conversion);
  76. query.exec();
  77. var prevRid = -1;
  78. var prevGid = "";
  79. var first = true;
  80. while(query.next()) {
  81. if(query.value(0) != prevRid) { // New roasted item
  82. if(!first) {
  83. output.writeEndElement(); //ul from previous roasted item
  84. output.writeEndElement(); //ul from previous roasted item
  85. } else {
  86. first = false;
  87. }
  88. output.writeTextElement("li", query.value(2) + " (" + query.value(0) + ")");
  89. output.writeStartElement("ul");
  90. output.writeTextElement("li", query.value(4) + " " + unitText + " roasted between " + query.value(5) + " and " + query.value(6) + " with:");
  91. output.writeStartElement("ul");
  92. output.writeTextElement("li", query.value(8) + " " + unitText + " of " + query.value(7));
  93. }
  94. else { // Same roasted item
  95. if(query.value(1) != prevGid) { // New set of greens
  96. output.writeEndElement(); //ul
  97. output.writeTextElement("li", query.value(4) + " " + unitText + " roasted between " + query.value(5) + " and " + query.value(6) + " with:");
  98. output.writeStartElement("ul");
  99. output.writeTextElement("li", query.value(8) + " " + unitText + " of " + query.value(7));
  100. } else { // Same set of greens
  101. output.writeTextElement("li", query.value(8) + " " + unitText + " of " + query.value(7));
  102. }
  103. }
  104. prevRid = query.value(0);
  105. prevGid = query.value(1);
  106. }
  107. output.writeEndElement(); //ul
  108. output.writeEndElement(); //body
  109. output.writeEndElement(); //html
  110. output.writeEndDocument();
  111. report.setContent(buffer);
  112. buffer.close();
  113. }
  114. refresh();
  115. ]]>
  116. </program>
  117. </window>