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

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