Typica is a free program for professional coffee roasters. https://typica.us
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dailyproduction.xml 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <window id="dailyproduction">
  2. <reporttitle>Production:->Daily Production Report</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <label>Date:</label>
  6. <calendar id="reportdate" />
  7. <stretch />
  8. </layout>
  9. <webview id="report" />
  10. </layout>
  11. <menu name="File">
  12. <item id="print" shortcut="Ctrl+P">Print</item>
  13. </menu>
  14. <program>
  15. <![CDATA[
  16. this.windowTitle = "Typica - Daily Production Report";
  17. var dateField = findChildObject(this, 'reportdate');
  18. var view = findChildObject(this, 'report');
  19. var printMenu = findChildObject(this, 'print');
  20. printMenu.triggered.connect(function() {
  21. view.print();
  22. });
  23. function refresh() {
  24. var buffer = new QBuffer;
  25. buffer.open(3);
  26. var output = new XmlWriter(buffer);
  27. output.writeStartDocument("1.0");
  28. 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">');
  29. output.writeStartElement("html");
  30. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  31. output.writeStartElement("head");
  32. output.writeTextElement("title", "Daily Production Report");
  33. output.writeEndElement();
  34. output.writeStartElement("body");
  35. var dateString = "" + dateField.year() + "-" + dateField.month() + "-" + dateField.day();
  36. output.writeTextElement("h1", "Daily Production Report: " + dateString);
  37. output.writeTextElement("h2", "Batches Roasted");
  38. var query = new QSqlQuery();
  39. var q = "SELECT time, machine, (SELECT name FROM machine WHERE id = machine), (SELECT name FROM items WHERE id = roasted_id), unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, annotation, duration, files FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1') ORDER BY time";
  40. query.exec(q);
  41. var times = new Array();
  42. var machines = new Array();
  43. output.writeStartElement("table");
  44. output.writeAttribute("rules", "groups");
  45. output.writeAttribute("cellpadding", "3px");
  46. output.writeStartElement("thead");
  47. output.writeStartElement("tr");
  48. output.writeTextElement("th", "Time");
  49. output.writeTextElement("th", "Machine");
  50. output.writeTextElement("th", "Green Weights");
  51. output.writeTextElement("th", "Green Coffees");
  52. output.writeTextElement("th", "Roasted Weight");
  53. output.writeTextElement("th", "Roasted Coffee");
  54. output.writeTextElement("th", "% Weight Loss");
  55. output.writeTextElement("th", "Duration");
  56. output.writeEndElement();
  57. output.writeEndElement();
  58. output.writeStartElement("tbody");
  59. while(query.next())
  60. {
  61. times.push(query.value(0));
  62. machines.push(query.value(1));
  63. output.writeStartElement("tr");
  64. output.writeTextElement("td", String(query.value(0)).split("T")[1]);
  65. output.writeTextElement("td", query.value(2));
  66. var unroastedWeightsList = sqlToArray(query.value(5));
  67. output.writeStartElement("td");
  68. for(var i = 0; i < unroastedWeightsList.length; i++)
  69. {
  70. if(i != 0)
  71. {
  72. output.writeEmptyElement("br");
  73. }
  74. output.writeCDATA(unroastedWeightsList[i]);
  75. }
  76. if(unroastedWeightsList.length > 1)
  77. {
  78. output.writeCDATA("Total: ");
  79. output.writeCDATA(query.value(6));
  80. }
  81. output.writeEndElement();
  82. var unroastedList = sqlToArray(query.value(4));
  83. output.writeStartElement("td");
  84. for(var i = 0; i < unroastedList.length; i++)
  85. {
  86. var greensQuery = new QSqlQuery();
  87. greensQuery.prepare("SELECT name FROM items WHERE id = :id");
  88. greensQuery.bind(":id", Number(unroastedList[i]));
  89. greensQuery.exec();
  90. if(i != 0)
  91. {
  92. output.writeEmptyElement("br");
  93. }
  94. greensQuery.next();
  95. output.writeCDATA(greensQuery.value(0));
  96. }
  97. output.writeEndElement();
  98. output.writeTextElement("td", query.value(8));
  99. output.writeTextElement("td", query.value(3));
  100. var loss = (Number(query.value(6)) - Number(query.value(8)))/Number(query.value(6));
  101. loss *= 100;
  102. output.writeTextElement("td", loss.toFixed(2)+"%");
  103. output.writeTextElement("td", query.value(10));
  104. output.writeEndElement();
  105. if(query.value(9) != "")
  106. {
  107. output.writeStartElement("tr");
  108. output.writeEmptyElement("td");
  109. output.writeStartElement("td");
  110. output.writeAttribute("colspan", "7");
  111. output.writeTextElement("em", query.value(9));
  112. output.writeEndElement();
  113. output.writeEndElement();
  114. }
  115. }
  116. output.writeEndElement();
  117. output.writeStartElement("tfoot");
  118. output.writeStartElement("tr");
  119. output.writeEmptyElement("td");
  120. output.writeStartElement("td");
  121. output.writeTextElement("strong", "Totals:");
  122. output.writeEndElement();
  123. q = "SELECT sum(unroasted_total_quantity), sum(roasted_quantity), sum(duration) FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1')";
  124. query.exec(q);
  125. query.next();
  126. output.writeTextElement("td", query.value(0));
  127. output.writeEmptyElement("td");
  128. output.writeTextElement("td", query.value(1));
  129. output.writeEmptyElement("td");
  130. output.writeEmptyElement("td");
  131. output.writeTextElement("td", query.value(2));
  132. output.writeEndElement();
  133. output.writeEndElement(); //tfoot
  134. output.writeEndElement(); //table
  135. output.writeTextElement("h2", "Inventory");
  136. output.writeStartElement("table");
  137. output.writeAttribute("rules", "groups");
  138. output.writeAttribute("cellpadding", "3px");
  139. output.writeStartElement("thead");
  140. output.writeStartElement("tr");
  141. output.writeTextElement("th", "Green Coffee");
  142. output.writeTextElement("th", "Starting Inventory");
  143. output.writeTextElement("th", "Ending Inventory");
  144. output.writeTextElement("th", "Change");
  145. output.writeTextElement("th", "Availability");
  146. output.writeEndElement();
  147. output.writeEndElement();
  148. output.writeStartElement("tbody");
  149. q = "SELECT DISTINCT item, (SELECT name FROM items WHERE id = item) AS name, (SELECT out FROM coffee_history WHERE id = item) FROM all_transactions WHERE time > '" + dateString + "' AND time < '" + dateString + "'::date + integer '1' ORDER BY name ASC";
  150. query.exec(q)
  151. var subQuery = new QSqlQuery();
  152. var qq;
  153. while(query.next())
  154. {
  155. output.writeStartElement("tr");
  156. output.writeTextElement("td", query.value(1));
  157. qq = "SELECT balance FROM item_history(" + query.value(0) + ") WHERE time = (SELECT max(time) FROM all_transactions WHERE time < '" + dateString + "' AND item = " + query.value(0) + ") OR time = (SELECT max(time) FROM all_transactions WHERE time < '" + dateString + "'::date + integer '1' AND item = " + query.value(0) + ") ORDER BY time ASC";
  158. subQuery.exec(qq);
  159. var startValue = 0;
  160. var endValue = 0;
  161. if(subQuery.next())
  162. {
  163. output.writeTextElement("td", subQuery.value(0));
  164. startValue = subQuery.value(0);
  165. }
  166. else
  167. {
  168. output.writeEmptyElement("td");
  169. }
  170. if(subQuery.next())
  171. {
  172. output.writeTextElement("td", subQuery.value(0));
  173. endValue = subQuery.value(0);
  174. }
  175. else
  176. {
  177. output.writeEmptyElement("td");
  178. }
  179. var startPrec = startValue.split('.').length > 1 ? startValue.split('.')[1].length : 0;
  180. var endPrec = endValue.split('.').length > 1 ? endValue.split('.')[1].length : 0;
  181. output.writeTextElement("td", (Number(endValue) - Number(startValue)).toFixed(Math.max(startPrec, endPrec)));
  182. output.writeTextElement("td", query.value(2));
  183. output.writeEndElement();
  184. }
  185. output.writeEndElement();
  186. output.writeStartElement("tfoot");
  187. output.writeEndElement();
  188. output.writeEndElement();//End of inventory table
  189. output.writeEndElement();
  190. output.writeEndElement();
  191. output.writeEndDocument();
  192. view.setContent(buffer);
  193. buffer.close();
  194. }
  195. refresh();
  196. dateField.dateChanged.connect(function() {
  197. refresh();
  198. });
  199. ]]>
  200. </program>
  201. </window>