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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. var rowData = new Array();
  41. var rowIndex;
  42. function refresh() {
  43. rowIndex = 0;
  44. var buffer = new QBuffer;
  45. buffer.open(3);
  46. var output = new XmlWriter(buffer);
  47. output.writeStartDocument("1.0");
  48. 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">');
  49. output.writeStartElement("html");
  50. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  51. output.writeStartElement("head");
  52. output.writeTextElement("title", "Recent Use and Cost by Origin");
  53. output.writeEndElement();
  54. output.writeStartElement("body");
  55. output.writeTextElement("h1", "Average Use and Cost by Origin");
  56. switch(unitBox.currentIndex)
  57. {
  58. case 0:
  59. output.writeTextElement("p", "This is a report of average rate of use in kilograms per day and cost of unroasted coffee.");
  60. break;
  61. case 1:
  62. output.writeTextElement("p", "This is a report of average rate of use in pounds per day and cost of unroasted coffee.");
  63. break;
  64. }
  65. output.writeStartElement("table");
  66. output.writeAttribute("rules", "groups");
  67. output.writeAttribute("cellpadding", "3px");
  68. output.writeStartElement("thead");
  69. output.writeStartElement("tr");
  70. output.writeStartElement("th");
  71. output.writeAttribute("colspan", "8");
  72. output.writeCharacters("Regular Coffees");
  73. output.writeEndElement();
  74. output.writeEndElement();
  75. output.writeStartElement("tr");
  76. output.writeTextElement("th", "Origin");
  77. output.writeTextElement("th", "Avg. Rate");
  78. output.writeTextElement("th", "Avg. Cost");
  79. output.writeTextElement("th", "Last Cost");
  80. output.writeTextElement("th", "Last Purchase Date");
  81. output.writeTextElement("th", "Bag Size (min)");
  82. output.writeTextElement("th", "Bag Size (max)");
  83. output.writeTextElement("th", "Bag Size (mean)");
  84. output.writeEndElement();
  85. output.writeEndElement();
  86. output.writeStartElement("tbody");
  87. var query = new QSqlQuery();
  88. var conversion = 1;
  89. if(unitBox.currentIndex == 0) {
  90. conversion = 2.2;
  91. }
  92. var orderClause;
  93. switch(sortBox.currentIndex)
  94. {
  95. case 0:
  96. orderClause = "origin ASC";
  97. break;
  98. case 1:
  99. orderClause = "origin DESC";
  100. break;
  101. case 2:
  102. orderClause = "rate ASC";
  103. break;
  104. case 3:
  105. orderClause = "rate DESC";
  106. break;
  107. case 4:
  108. orderClause = "cost ASC";
  109. break;
  110. case 5:
  111. orderClause = "cost DESC";
  112. break;
  113. }
  114. 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)), (SELECT min(conversion)/:conversion4 FROM lb_bag_conversion WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS minbag, (SELECT max(conversion)/:conversion5 FROM lb_bag_conversion WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS maxbag, (SELECT avg(conversion)/:conversion6 FROM lb_bag_conversion WHERE item IN (SELECT id FROM regular_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS meanbag FROM coffee_history WHERE id IN (SELECT id FROM regular_coffees) GROUP BY origin ORDER BY " + orderClause);
  115. query.bind(":conversion", conversion);
  116. query.bind(":conversion2", conversion);
  117. query.bind(":conversion3", conversion);
  118. query.bind(":conversion4", conversion);
  119. query.bind(":conversion5", conversion);
  120. query.bind(":conversion6", conversion);
  121. query.exec();
  122. while(query.next())
  123. {
  124. output.writeStartElement("tr");
  125. output.writeAttribute("id", "r" + rowIndex);
  126. output.writeStartElement("td");
  127. output.writeStartElement("a");
  128. output.writeAttribute("href", "typica://script/r" + rowIndex);
  129. rowIndex++;
  130. rowData.push(query.value(0));
  131. output.writeCharacters(query.value(0));
  132. output.writeEndElement();
  133. output.writeEndElement();
  134. output.writeTextElement("td", query.value(1));
  135. output.writeTextElement("td", query.value(2));
  136. output.writeTextElement("td", query.value(3));
  137. output.writeTextElement("td", query.value(4));
  138. output.writeTextElement("td", query.value(5));
  139. output.writeTextElement("td", query.value(6));
  140. output.writeTextElement("td", query.value(7));
  141. output.writeEndElement();
  142. }
  143. output.writeStartElement("tr");
  144. output.writeStartElement("th");
  145. output.writeAttribute("colspan", "8");
  146. output.writeCharacters("Decaffeinated Coffees");
  147. output.writeEndElement();
  148. output.writeEndElement();
  149. 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)), (SELECT min(conversion)/:conversion4 FROM lb_bag_conversion WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS minbag, (SELECT max(conversion)/:conversion5 FROM lb_bag_conversion WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS maxbag, (SELECT avg(conversion)/:conversion6 FROM lb_bag_conversion WHERE item IN (SELECT id FROM decaf_coffees WHERE origin = coffee_history.origin))::numeric(10,2) AS meanbag FROM coffee_history WHERE id IN (SELECT id FROM decaf_coffees) GROUP BY origin ORDER BY " + orderClause);
  150. query.bind(":conversion", conversion);
  151. query.bind(":conversion2", conversion);
  152. query.bind(":conversion3", conversion);
  153. query.bind(":conversion4", conversion);
  154. query.bind(":conversion5", conversion);
  155. query.bind(":conversion6", conversion);
  156. query.exec();
  157. while(query.next())
  158. {
  159. output.writeStartElement("tr");
  160. output.writeAttribute("id", "d" + rowIndex);
  161. output.writeStartElement("td");
  162. output.writeStartElement("a");
  163. output.writeAttribute("href", "typica://script/d" + rowIndex);
  164. rowIndex++;
  165. rowData.push(query.value(0));
  166. output.writeCharacters(query.value(0));
  167. output.writeEndElement();
  168. output.writeEndElement();
  169. output.writeTextElement("td", query.value(1));
  170. output.writeTextElement("td", query.value(2));
  171. output.writeTextElement("td", query.value(3));
  172. output.writeTextElement("td", query.value(4));
  173. output.writeTextElement("td", query.value(5));
  174. output.writeTextElement("td", query.value(6));
  175. output.writeTextElement("td", query.value(7));
  176. output.writeEndElement();
  177. }
  178. query = query.invalidate();
  179. output.writeEndElement();
  180. output.writeEndElement();
  181. output.writeEndElement();
  182. output.writeEndElement();
  183. output.writeEndDocument();
  184. report.setContent(buffer);
  185. buffer.close();
  186. }
  187. refresh();
  188. sortBox['currentIndexChanged(int)'].connect(function() {
  189. QSettings.setValue("auco_sort", sortBox.currentIndex);
  190. refresh();
  191. });
  192. report.scriptLinkClicked.connect(function(url) {
  193. var element = new WebElement(report.findFirstElement("#" + url));
  194. var regular = url[0] == 'r';
  195. var index = url.slice(1, url.length);
  196. var tableref;
  197. if(regular) {
  198. tableref = "regular_coffees";
  199. } else {
  200. tableref = "decaf_coffees";
  201. }
  202. var origin = rowData[Number(url.slice(1, url.length))];
  203. var details = '<tr><td /><td colspan="6"><table><tr><th>Id</th><th>Name</th><th>Rate</th><th>Inventory</th><th>First Use</th><th>Last Use</th></tr>';
  204. var query = new QSqlQuery();
  205. query.prepare("SELECT id, name, (rate/:conversion1)::numeric(12,3), (stock/:conversion2)::numeric(12,3), (SELECT min(time)::date FROM use WHERE item = id) AS first_use, (SELECT max(time)::date FROM use WHERE item = id) AS last_use FROM coffee_history WHERE origin = :origin AND id IN (SELECT id FROM " + tableref + ") ORDER BY first_use DESC");
  206. var conversion = 1;
  207. if(unitBox.currentIndex == 0) {
  208. conversion = 2.2;
  209. }
  210. query.bind(":conversion1", conversion);
  211. query.bind(":conversion2", conversion);
  212. query.bind(":origin", origin);
  213. query.exec();
  214. while(query.next()) {
  215. details += "<tr>";
  216. for(var i = 0; i < 6; i++) {
  217. details += "<td>" + query.value(i) + "</td>";
  218. }
  219. details += "</tr>";
  220. }
  221. query = query.invalidate();
  222. details += "</table></td></tr>";
  223. element.appendOutside(details);
  224. });
  225. ]]>
  226. </program>
  227. </window>