Typica is a free program for professional coffee roasters. https://typica.us
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cogr.xml 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <window id="greencost">
  2. <reporttitle>Production:->Cost of Green Coffee for Roasted Coffee</reporttitle> <layout type="vertical">
  3. <layout type="horizontal">
  4. <label>Weight Unit:</label>
  5. <sqldrop id="unit" />
  6. <stretch />
  7. </layout>
  8. <webview id="report" />
  9. </layout>
  10. <menu name="File">
  11. <item id="print" shortcut="Ctrl+P">Print...</item>
  12. </menu>
  13. <menu name="Reports" type="reports" src="Reports" />
  14. <program>
  15. <![CDATA[
  16. this.windowTitle = TTR("greencost", "Typica - Cost of Green Coffee for Roasted Coffee");
  17. var report = findChildObject(this, 'report');
  18. var printMenu = findChildObject(this, 'print');
  19. printMenu.triggered.connect(function() {
  20. report.print();
  21. });
  22. var unitBox = findChildObject(this, 'unit');
  23. unitBox.addItem(TTR("greencost", "Kg"));
  24. unitBox.addItem(TTR("greencost", "Lb"));
  25. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  26. unitBox['currentIndexChanged(int)'].connect(function() {
  27. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  28. refresh();
  29. });
  30. function refresh() {
  31. var conversion = 1;
  32. if(unitBox.currentIndex == 0) {
  33. conversion = 2.2;
  34. }
  35. var buffer = new QBuffer;
  36. buffer.open(3);
  37. var output = new XmlWriter(buffer);
  38. output.writeStartDocument("1.0");
  39. 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">');
  40. output.writeStartElement("html");
  41. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  42. output.writeStartElement("head");
  43. output.writeTextElement("title", TTR("greencost", "Cost of Green Coffee for Roasted Coffee"));
  44. output.writeEndElement();
  45. output.writeStartElement("body");
  46. var cdt = new Date(Date.now());
  47. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  48. var unit = (unitBox.currentIndex == 0 ? TTR("greencost", "Kg") :
  49. TTR("greencost", "Lb"));
  50. output.writeTextElement("h1", TTR("greencost", "Cost of Green Coffee for Roasted Coffee"));
  51. output.writeTextElement("p", TTR("greencost", "Cost of green coffee per ") +
  52. unit + TTR("greencost", " of roasted coffee"));
  53. var query = new QSqlQuery();
  54. query.exec("SELECT item, (SELECT name FROM items WHERE id = item) AS name FROM current_items ORDER BY name");
  55. var roastedItems = new Array();
  56. var roastedNames = new Array();
  57. while(query.next()) {
  58. roastedItems.push(query.value(0));
  59. roastedNames.push(query.value(1));
  60. }
  61. var recipes = new Array();
  62. var recipeQuantities = new Array();
  63. query.prepare("SELECT unroasted_id, unroasted_quantity FROM roasting_log WHERE roasted_id = :item AND time = (SELECT max(time) FROM roasting_log WHERE roasted_id = :item2)");
  64. for(var i = 0; i < roastedItems.length; i++) {
  65. query.bind("item", roastedItems[i]);
  66. query.bind("item2", roastedItems[i]);
  67. query.exec();
  68. if(query.next()) {
  69. recipes.push(query.value(0));
  70. recipeQuantities.push(query.value(1));
  71. } else {
  72. recipes.push("{-1}");
  73. recipeQuantities.push("{-1}");
  74. }
  75. }
  76. query.prepare("SELECT min(unroasted_total_quantity / roasted_quantity), max(unroasted_total_quantity / roasted_quantity), avg(unroasted_total_quantity / roasted_quantity) FROM roasting_log WHERE roasted_id = :ri AND unroasted_id = :gi AND unroasted_total_quantity > 0 AND roasted_quantity > 0 AND approval = true");
  77. var mins = new Array();
  78. var maxes = new Array();
  79. var means = new Array();
  80. for(var i = 0; i < roastedItems.length; i++) {
  81. if(recipes[i] == "{-1}") {
  82. mins.push("undefined");
  83. maxes.push("undefined");
  84. means.push("undefined");
  85. } else {
  86. query.bind(":ri", Number(roastedItems[i]));
  87. query.bind(":gi", recipes[i]);
  88. query.exec();
  89. if(query.next()) {
  90. mins.push(query.value(0));
  91. maxes.push(query.value(1));
  92. means.push(query.value(2));
  93. } else {
  94. print("Error 2");
  95. }
  96. }
  97. }
  98. var proportionalCosts = new Array();
  99. query.prepare("SELECT cost * :proportion * :conversion FROM purchase WHERE item = :id");
  100. for(var i = 0; i < roastedItems.length; i++) {
  101. if(recipes[i] == "{-1}") {
  102. proportionalCosts.push("undefined");
  103. } else {
  104. greens = sqlToArray(recipes[i]);
  105. weights = sqlToArray(recipeQuantities[i]);
  106. proportions = new Array();
  107. quantitySum = weights.reduce(function(p, c) {
  108. return Number(p) + Number(c);
  109. });
  110. for(var j = 0; j < weights.length; j++) {
  111. proportions.push(weights[j]/quantitySum);
  112. }
  113. partialSum = 0;
  114. for(var j = 0; j < greens.length; j++) {
  115. query.bind(":proportion", proportions[j]);
  116. query.bind(":id", greens[j]);
  117. query.bind(":conversion", conversion);
  118. query.exec();
  119. if(query.next()) {
  120. partialSum += Number(query.value(0));
  121. } else {
  122. print("Error 3");
  123. }
  124. }
  125. proportionalCosts.push(partialSum);
  126. }
  127. }
  128. query = query.invalidate();
  129. var minCosts = new Array();
  130. var maxCosts = new Array();
  131. var meanCosts = new Array();
  132. for(var i = 0; i < roastedItems.length; i++) {
  133. if(recipes[i] == "{-1}") {
  134. minCosts.push("undefined");
  135. maxCosts.push("undefined");
  136. meanCosts.push("undefined");
  137. } else {
  138. minCosts.push(proportionalCosts[i] * mins[i]);
  139. maxCosts.push(proportionalCosts[i] * maxes[i]);
  140. meanCosts.push(proportionalCosts[i] * means[i]);
  141. }
  142. }
  143. output.writeStartElement("table");
  144. output.writeAttribute("rules", "groups");
  145. output.writeAttribute("cellpadding", "3px");
  146. output.writeStartElement("thead");
  147. output.writeStartElement("tr");
  148. output.writeTextElement("th", TTR("greencost", "Coffee"));
  149. output.writeTextElement("th", TTR("greencost", "Minimum Cost"));
  150. output.writeTextElement("th", TTR("greencost", "Maximum Cost"));
  151. output.writeTextElement("th", TTR("greencost", "Mean Cost"));
  152. output.writeEndElement();
  153. output.writeEndElement();
  154. output.writeStartElement("tbody");
  155. for(var i = 0; i < roastedItems.length; i++) {
  156. output.writeStartElement("tr");
  157. output.writeTextElement("td", roastedNames[i]);
  158. output.writeTextElement("td", Number(minCosts[i]).toFixed(2));
  159. output.writeTextElement("td", Number(maxCosts[i]).toFixed(2));
  160. output.writeTextElement("td", Number(meanCosts[i]).toFixed(2));
  161. output.writeEndElement();
  162. }
  163. output.writeEndElement();
  164. output.writeEndElement();
  165. output.writeEndElement();
  166. output.writeEndElement();
  167. output.writeEndDocument();
  168. report.setContent(buffer);
  169. buffer.close();
  170. };
  171. refresh();
  172. var notifier = Application.subscribe("roastinglogchange");
  173. notifier.notify.connect(function() {
  174. refresh();
  175. });
  176. var notifier2 = Application.subscribe("purchasechange");
  177. notifier2.notify.connect(function() {
  178. refresh();
  179. });
  180. ]]>
  181. </program>
  182. </window>