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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <window id="useandcostreport">
  2. <reporttitle>Production:->Average Use and Cost by Origin</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <label>Sort Order:</label>
  6. <sqldrop id="sort" />
  7. <stretch />
  8. </layout>
  9. <webview id="report" />
  10. </layout>
  11. <menu name="File">
  12. <item id="print" shortcut="Ctrl+P">Print</item>
  13. </menu>
  14. <program>
  15. <![CDATA[
  16. this.windowTitle = "Typica - Average Use and Cost by Origin";
  17. var report = findChildObject(this, 'report');
  18. var printMenu = findChildObject(this, 'print');
  19. printMenu.triggered.connect(function() {
  20. report.print();
  21. });
  22. var sortBox = findChildObject(this, 'sort');
  23. sortBox.addItem("Origin A-Z");
  24. sortBox.addItem("Origin Z-A");
  25. sortBox.addItem("Avg. Rate Ascending");
  26. sortBox.addItem("Avg. Rate Descending");
  27. sortBox.addItem("Avg. Cost Ascending");
  28. sortBox.addItem("Avg. Cost Descending");
  29. sortBox.currentIndex = QSettings.value("auco_sort", 0);
  30. function refresh() {
  31. var buffer = new QBuffer;
  32. buffer.open(3);
  33. var output = new XmlWriter(buffer);
  34. output.writeStartDocument("1.0");
  35. 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">');
  36. output.writeStartElement("html");
  37. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  38. output.writeStartElement("head");
  39. output.writeTextElement("title", "Recent Use and Cost by Origin");
  40. output.writeEndElement();
  41. output.writeStartElement("body");
  42. output.writeTextElement("h1", "Average Use and Cost by Origin");
  43. output.writeTextElement("p", "This is a report of average rate of use in pounds per day and cost of unroasted coffee.");
  44. output.writeStartElement("table");
  45. output.writeAttribute("rules", "groups");
  46. output.writeAttribute("cellpadding", "3px");
  47. output.writeStartElement("thead");
  48. output.writeStartElement("tr");
  49. output.writeStartElement("th");
  50. output.writeAttribute("colspan", "3");
  51. output.writeCharacters("Regular Coffees");
  52. output.writeEndElement();
  53. output.writeEndElement();
  54. output.writeStartElement("tr");
  55. output.writeTextElement("th", "Origin");
  56. output.writeTextElement("th", "Avg. Rate");
  57. output.writeTextElement("th", "Avg. Cost");
  58. output.writeEndElement();
  59. output.writeEndElement();
  60. output.writeStartElement("tbody");
  61. var query = new QSqlQuery();
  62. switch(sortBox.currentIndex)
  63. {
  64. case 0:
  65. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY origin ASC");
  66. break;
  67. case 1:
  68. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY origin DESC");
  69. break;
  70. case 2:
  71. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY rate ASC");
  72. break;
  73. case 3:
  74. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY rate DESC");
  75. break;
  76. case 4:
  77. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY cost ASC");
  78. break;
  79. case 5:
  80. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY cost DESC");
  81. break;
  82. }
  83. while(query.next())
  84. {
  85. output.writeStartElement("tr");
  86. output.writeTextElement("td", query.value(0));
  87. output.writeTextElement("td", query.value(1));
  88. output.writeTextElement("td", query.value(2));
  89. output.writeEndElement();
  90. }
  91. output.writeStartElement("tr");
  92. output.writeStartElement("th");
  93. output.writeAttribute("colspan", "3");
  94. output.writeCharacters("Decaffeinated Coffees");
  95. output.writeEndElement();
  96. output.writeEndElement();
  97. switch(sortBox.currentIndex)
  98. {
  99. case 0:
  100. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY origin ASC");
  101. break;
  102. case 1:
  103. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY origin DESC");
  104. break;
  105. case 2:
  106. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY rate ASC");
  107. break;
  108. case 3:
  109. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY rate DESC");
  110. break;
  111. case 4:
  112. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY cost ASC");
  113. break;
  114. case 5:
  115. query.exec("SELECT DISTINCT origin, avg(rate)::numeric(10,2) AS rate, (SELECT avg(cost) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS cost FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY cost DESC");
  116. break;
  117. }
  118. while(query.next())
  119. {
  120. output.writeStartElement("tr");
  121. output.writeTextElement("td", query.value(0));
  122. output.writeTextElement("td", query.value(1));
  123. output.writeTextElement("td", query.value(2));
  124. output.writeEndElement();
  125. }
  126. output.writeEndElement();
  127. output.writeEndElement();
  128. output.writeEndElement();
  129. output.writeEndElement();
  130. output.writeEndDocument();
  131. report.setContent(buffer);
  132. buffer.close();
  133. }
  134. refresh();
  135. sortBox['currentIndexChanged(int)'].connect(function() {
  136. QSettings.setValue("auco_sort", sortBox.currentIndex);
  137. refresh();
  138. });
  139. ]]>
  140. </program>
  141. </window>