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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <window id="greencost">
  2. <reporttitle>Production:->Cost of Green Coffee for Roasted Coffee</reporttitle>
  3. <layout type="vertical">
  4. <webview id="report" />
  5. </layout>
  6. <menu name="File">
  7. <item id="print" shortcut="Ctrl+P">Print</item>
  8. </menu>
  9. <program>
  10. <![CDATA[
  11. this.windowTitle = "Typica - Cost of Green Coffee for Roasted Coffee";
  12. var report = findChildObject(this, 'report');
  13. var printMenu = findChildObject(this, 'print');
  14. printMenu.triggered.connect(function() {
  15. report.print();
  16. });
  17. function refresh() {
  18. var buffer = new QBuffer;
  19. buffer.open(3);
  20. var output = new XmlWriter(buffer);
  21. output.writeStartDocument("1.0");
  22. 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">');
  23. output.writeStartElement("html");
  24. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  25. output.writeStartElement("head");
  26. output.writeTextElement("title", "Cost of Green Coffee for Roasted Coffee");
  27. output.writeEndElement();
  28. output.writeStartElement("body");
  29. output.writeTextElement("h1", "Cost of Green Coffee for Roasted Coffee");
  30. var query = new QSqlQuery();
  31. query.exec("SELECT item, (SELECT name FROM items WHERE id = item) AS name FROM current_items ORDER BY name");
  32. var roastedItems = new Array();
  33. var roastedNames = new Array();
  34. while(query.next()) {
  35. roastedItems.push(query.value(0));
  36. roastedNames.push(query.value(1));
  37. }
  38. var recipes = new Array();
  39. var recipeQuantities = new Array();
  40. 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)");
  41. for(var i = 0; i < roastedItems.length; i++) {
  42. query.bind("item", roastedItems[i]);
  43. query.bind("item2", roastedItems[i]);
  44. query.exec();
  45. if(query.next()) {
  46. recipes.push(query.value(0));
  47. recipeQuantities.push(query.value(1));
  48. } else {
  49. recipes.push("{-1}");
  50. recipeQuantities.push("{-1}");
  51. }
  52. }
  53. 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");
  54. var mins = new Array();
  55. var maxes = new Array();
  56. var means = new Array();
  57. for(var i = 0; i < roastedItems.length; i++) {
  58. if(recipes[i] == "{-1}") {
  59. mins.push("undefined");
  60. maxes.push("undefined");
  61. means.push("undefined");
  62. } else {
  63. query.bind(":ri", Number(roastedItems[i]));
  64. query.bind(":gi", recipes[i]);
  65. query.exec();
  66. if(query.next()) {
  67. mins.push(query.value(0));
  68. maxes.push(query.value(1));
  69. means.push(query.value(2));
  70. } else {
  71. print("Error 2");
  72. }
  73. }
  74. }
  75. var proportionalCosts = new Array();
  76. query.prepare("SELECT cost * :proportion FROM purchase WHERE item = :id");
  77. for(var i = 0; i < roastedItems.length; i++) {
  78. if(recipes[i] == "{-1}") {
  79. proportionalCosts.push("undefined");
  80. } else {
  81. greens = sqlToArray(recipes[i]);
  82. weights = sqlToArray(recipeQuantities[i]);
  83. proportions = new Array();
  84. quantitySum = weights.reduce(function(p, c) {
  85. return p + c;
  86. });
  87. for(var j = 0; j < weights.length; j++) {
  88. proportions.push(weights[j]/quantitySum);
  89. }
  90. partialSum = 0;
  91. for(var j = 0; j < greens.length; j++) {
  92. query.bind(":proportion", proportions[j]);
  93. query.bind(":id", greens[j]);
  94. query.exec();
  95. if(query.next()) {
  96. partialSum += query.value(0);
  97. } else {
  98. print("Error 3");
  99. }
  100. }
  101. proportionalCosts.push(partialSum);
  102. }
  103. }
  104. var minCosts = new Array();
  105. var maxCosts = new Array();
  106. var meanCosts = new Array();
  107. for(var i = 0; i < roastedItems.length; i++) {
  108. if(recipes[i] == "{-1}") {
  109. minCosts.push("undefined");
  110. maxCosts.push("undefined");
  111. meanCosts.push("undefined");
  112. } else {
  113. minCosts.push(proportionalCosts[i] * mins[i]);
  114. maxCosts.push(proportionalCosts[i] * maxes[i]);
  115. meanCosts.push(proportionalCosts[i] * means[i]);
  116. }
  117. }
  118. output.writeStartElement("table");
  119. output.writeAttribute("rules", "groups");
  120. output.writeAttribute("cellpadding", "3px");
  121. output.writeStartElement("thead");
  122. output.writeStartElement("tr");
  123. output.writeTextElement("th", "Coffee");
  124. output.writeTextElement("th", "Minimum Cost");
  125. output.writeTextElement("th", "Maximum Cost");
  126. output.writeTextElement("th", "Mean Cost");
  127. output.writeEndElement();
  128. output.writeEndElement();
  129. output.writeStartElement("tbody");
  130. for(var i = 0; i < roastedItems.length; i++) {
  131. output.writeStartElement("tr");
  132. output.writeTextElement("td", roastedNames[i]);
  133. output.writeTextElement("td", Number(minCosts[i]).toFixed(2));
  134. output.writeTextElement("td", Number(maxCosts[i]).toFixed(2));
  135. output.writeTextElement("td", Number(meanCosts[i]).toFixed(2));
  136. output.writeEndElement();
  137. }
  138. output.writeEndElement();
  139. output.writeEndElement();
  140. output.writeEndElement();
  141. output.writeEndElement();
  142. output.writeEndDocument();
  143. report.setContent(buffer);
  144. buffer.close();
  145. };
  146. refresh();
  147. ]]>
  148. </program>
  149. </window>