Typica is a free program for professional coffee roasters. https://typica.us
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

greenforroasted.xml 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. var cdt = new Date(Date.now());
  67. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  68. output.writeTextElement("h1", TTR("greenforroasted", "Green Coffees Used for Roasted Coffees ") + startDate + "-" + endDate);
  69. output.writeStartElement("ul");
  70. var query = new QSqlQuery();
  71. 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");
  72. query.bind(":sd1", startDate);
  73. query.bind(":sd2", startDate);
  74. query.bind(":ed1", endDate);
  75. query.bind(":ed2", endDate);
  76. query.bind(":c1", conversion);
  77. query.bind(":c2", conversion);
  78. query.exec();
  79. var prevRid = -1;
  80. var prevGid = "";
  81. var first = true;
  82. while(query.next()) {
  83. if(query.value(0) != prevRid) { // New roasted item
  84. if(!first) {
  85. output.writeEndElement(); //ul from previous roasted item
  86. output.writeEndElement(); //ul from previous roasted item
  87. } else {
  88. first = false;
  89. }
  90. output.writeTextElement("li", query.value(2) + " (" + query.value(0) + ")");
  91. output.writeStartElement("ul");
  92. output.writeTextElement("li", query.value(4) + " " + unitText + " roasted between " + query.value(5) + " and " + query.value(6) + " with:");
  93. output.writeStartElement("ul");
  94. output.writeTextElement("li", query.value(8) + " " + unitText + " of " + query.value(7));
  95. }
  96. else { // Same roasted item
  97. if(query.value(1) != prevGid) { // New set of greens
  98. output.writeEndElement(); //ul
  99. output.writeTextElement("li", query.value(4) + " " + unitText + " roasted between " + query.value(5) + " and " + query.value(6) + " with:");
  100. output.writeStartElement("ul");
  101. output.writeTextElement("li", query.value(8) + " " + unitText + " of " + query.value(7));
  102. } else { // Same set of greens
  103. output.writeTextElement("li", query.value(8) + " " + unitText + " of " + query.value(7));
  104. }
  105. }
  106. prevRid = query.value(0);
  107. prevGid = query.value(1);
  108. }
  109. output.writeEndElement(); //ul
  110. output.writeEndElement(); //body
  111. output.writeEndElement(); //html
  112. output.writeEndDocument();
  113. report.setContent(buffer);
  114. buffer.close();
  115. }
  116. refresh();
  117. ]]>
  118. </program>
  119. </window>