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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. print("Error 1");
  50. }
  51. }
  52. 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");
  53. var mins = new Array();
  54. var maxes = new Array();
  55. var means = new Array();
  56. for(var i = 0; i < roastedItems.length; i++) {
  57. query.bind(":ri", Number(roastedItems[i]));
  58. query.bind(":gi", recipes[i]);
  59. query.exec();
  60. if(query.next()) {
  61. mins.push(query.value(0));
  62. maxes.push(query.value(1));
  63. means.push(query.value(2));
  64. } else {
  65. print("Error 2");
  66. }
  67. }
  68. var proportionalCosts = new Array();
  69. query.prepare("SELECT cost * :proportion FROM purchase WHERE item = :id");
  70. for(var i = 0; i < roastedItems.length; i++) {
  71. greens = sqlToArray(recipes[i]);
  72. weights = sqlToArray(recipeQuantities[i]);
  73. proportions = new Array();
  74. quantitySum = weights.reduce(function(p, c) {
  75. return p + c;
  76. });
  77. for(var j = 0; j < weights.length; j++) {
  78. proportions.push(weights[j]/quantitySum);
  79. }
  80. partialSum = 0;
  81. for(var j = 0; j < greens.length; j++) {
  82. query.bind(":proportion", proportions[j]);
  83. query.bind(":id", greens[j]);
  84. query.exec();
  85. if(query.next()) {
  86. partialSum += query.value(0);
  87. } else {
  88. print("Error 3");
  89. }
  90. }
  91. proportionalCosts.push(partialSum);
  92. }
  93. var minCosts = new Array();
  94. var maxCosts = new Array();
  95. var meanCosts = new Array();
  96. for(var i = 0; i < roastedItems.length; i++) {
  97. minCosts.push(proportionalCosts[i] * mins[i]);
  98. maxCosts.push(proportionalCosts[i] * maxes[i]);
  99. meanCosts.push(proportionalCosts[i] * means[i]);
  100. }
  101. output.writeStartElement("table");
  102. output.writeAttribute("rules", "groups");
  103. output.writeAttribute("cellpadding", "3px");
  104. output.writeStartElement("thead");
  105. output.writeStartElement("tr");
  106. output.writeTextElement("th", "Coffee");
  107. output.writeTextElement("th", "Minimum Cost");
  108. output.writeTextElement("th", "Maximum Cost");
  109. output.writeTextElement("th", "Mean Cost");
  110. output.writeEndElement();
  111. output.writeEndElement();
  112. output.writeStartElement("tbody");
  113. for(var i = 0; i < roastedItems.length; i++) {
  114. output.writeStartElement("tr");
  115. output.writeTextElement("td", roastedNames[i]);
  116. output.writeTextElement("td", Number(minCosts[i]).toFixed(2));
  117. output.writeTextElement("td", Number(maxCosts[i]).toFixed(2));
  118. output.writeTextElement("td", Number(meanCosts[i]).toFixed(2));
  119. output.writeEndElement();
  120. }
  121. output.writeEndElement();
  122. output.writeEndElement();
  123. output.writeEndElement();
  124. output.writeEndElement();
  125. output.writeEndDocument();
  126. report.setContent(buffer);
  127. buffer.close();
  128. };
  129. refresh();
  130. ]]>
  131. </program>
  132. </window>