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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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", "5");
  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.writeTextElement("th", "Last Cost");
  77. output.writeTextElement("th", "Last Purchase Date");
  78. output.writeEndElement();
  79. output.writeEndElement();
  80. output.writeStartElement("tbody");
  81. var query = new QSqlQuery();
  82. var conversion = 1;
  83. if(unitBox.currentIndex == 0) {
  84. conversion = 2.2;
  85. }
  86. var orderClause;
  87. switch(sortBox.currentIndex)
  88. {
  89. case 0:
  90. orderClause = "origin ASC";
  91. break;
  92. case 1:
  93. orderClause = "origin DESC";
  94. break;
  95. case 2:
  96. orderClause = "rate ASC";
  97. break;
  98. case 3:
  99. orderClause = "rate DESC";
  100. break;
  101. case 4:
  102. orderClause = "cost ASC";
  103. break;
  104. case 5:
  105. orderClause = "cost DESC";
  106. break;
  107. }
  108. 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, (SELECT avg(cost)*:conversion3 FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin) AND time = (SELECT max(time) FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))), (SELECT max(time)::date FROM purchase WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin)) FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY " + orderClause);
  109. query.bind(":conversion", conversion);
  110. query.bind(":conversion2", conversion);
  111. query.bind(":conversion3", conversion);
  112. query.exec();
  113. while(query.next())
  114. {
  115. output.writeStartElement("tr");
  116. output.writeTextElement("td", query.value(0));
  117. output.writeTextElement("td", query.value(1));
  118. output.writeTextElement("td", query.value(2));
  119. output.writeTextElement("td", query.value(3));
  120. output.writeTextElement("td", query.value(4));
  121. output.writeEndElement();
  122. }
  123. output.writeStartElement("tr");
  124. output.writeStartElement("th");
  125. output.writeAttribute("colspan", "5");
  126. output.writeCharacters("Decaffeinated Coffees");
  127. output.writeEndElement();
  128. output.writeEndElement();
  129. 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, (SELECT avg(cost)*:conversion3 FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin) AND time = (SELECT max(time) FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))), (SELECT max(time)::date FROM purchase WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin)) FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY " + orderClause);
  130. query.bind(":conversion", conversion);
  131. query.bind(":conversion2", conversion);
  132. query.bind(":conversion3", conversion);
  133. query.exec();
  134. while(query.next())
  135. {
  136. output.writeStartElement("tr");
  137. output.writeTextElement("td", query.value(0));
  138. output.writeTextElement("td", query.value(1));
  139. output.writeTextElement("td", query.value(2));
  140. output.writeTextElement("td", query.value(3));
  141. output.writeTextElement("td", query.value(4));
  142. output.writeEndElement();
  143. }
  144. query = query.invalidate();
  145. output.writeEndElement();
  146. output.writeEndElement();
  147. output.writeEndElement();
  148. output.writeEndElement();
  149. output.writeEndDocument();
  150. report.setContent(buffer);
  151. buffer.close();
  152. }
  153. refresh();
  154. sortBox['currentIndexChanged(int)'].connect(function() {
  155. QSettings.setValue("auco_sort", sortBox.currentIndex);
  156. refresh();
  157. });
  158. ]]>
  159. </program>
  160. </window>