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 8.9KB

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