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

invchange.xml 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <window id="invchange">
  2. <reporttitle>Inventory:->Inventory Change Summary</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <daterange id="dates" initial="19" /><!-- Current Year to Date-->
  6. <label>Weight Unit:</label>
  7. <sqldrop id="unit" />
  8. <stretch />
  9. </layout>
  10. <webview id="report" />
  11. </layout>
  12. <menu name="File">
  13. <item id="print" shortcut="Ctrl+P">Print</item>
  14. </menu>
  15. <program>
  16. <![CDATA[
  17. this.windowTitle = "Typica - Inventory Change Summary";
  18. var dateSelect = findChildObject(this, 'dates');
  19. var unitBox = findChildObject(this, 'unit');
  20. unitBox.addItem("Kg");
  21. unitBox.addItem("Lb");
  22. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  23. unitBox['currentIndexChanged(int)'].connect(function() {
  24. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  25. refresh();
  26. });
  27. var view = findChildObject(this, 'report');
  28. var printMenu = findChildObject(this, 'print');
  29. printMenu.triggered.connect(function() {
  30. view.print();
  31. });
  32. function refresh() {
  33. var buffer = new QBuffer;
  34. buffer.open(3);
  35. var output = new XmlWriter(buffer);
  36. output.writeStartDocument("1.0");
  37. 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">');
  38. output.writeStartElement("html");
  39. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  40. output.writeStartElement("head");
  41. output.writeTextElement("title", "Inventory Change Summary");
  42. output.writeEndElement();
  43. output.writeStartElement("body");
  44. var dateRange = dateSelect.currentRange();
  45. var startDate = dateRange[0];
  46. var endDate = dateRange[dateRange.length - 1];
  47. output.writeTextElement("h1", "Inventory Change Summary: " + startDate + " – " + endDate);
  48. var conversion = 1;
  49. if(unitBox.currentIndex == 0) {
  50. conversion = 2.2;
  51. }
  52. var unitText = "Lb";
  53. if(unitBox.currentIndex == 0) {
  54. unitText = "Kg";
  55. }
  56. var query = new QSqlQuery();
  57. var q = "WITH q AS (SELECT id, name, reference, COALESCE((SELECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :sd1)), 0)/:c1 AS starting_balance, COALESCE((SELECT sum(quantity) FROM purchase WHERE item = id AND time >= :sd2 AND time < :ed1 ::date + interval '1 day'), 0)/:c2 AS purchase, COALESCE((SELECT sum(quantity) FROM use WHERE item = id AND time >= :sd3 AND time < :ed2 ::date + interval '1 day'), 0)/:c3 AS use, COALESCE((SELECT sum(quantity) FROM sale WHERE item = id AND time >= :sd4 AND time < :ed3 ::date + interval '1 day'), 0)/:c4 AS sale, (SElECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :ed4 ::date + interval '1 day'))/:c5 AS quantity, (SELECT sum(cost * quantity) / sum(quantity) FROM purchase WHERE item = id) AS unit_cost FROM coffees WHERE id IN (SELECT item FROM purchase WHERE time >= :sd6 AND time < :ed5 ::date + interval '1 day') OR id IN (SELECT id FROM items WHERE (SELECT balance FROM item_history(id) WHERE time = (SELECT max(time) FROM item_history(id) WHERE time < :ed6 ::date + interval '1 day')) > 0) OR id IN (SELECT DISTINCT item FROM all_transactions WHERE time > :sd7 AND time < :ed7 ::date + interval '1 day')) SELECT *, (starting_balance + purchase - use - sale - quantity)/:c7 AS adjustment, starting_balance * unit_cost * :c8 AS starting_cost, purchase * unit_cost * :c9 AS purchase_cost, use * unit_cost * :c10 AS use_cost, sale * unit_cost * :c11 AS sale_cost, quantity * unit_cost * :c12 AS quantity_cost, (starting_balance + purchase - use - sale - quantity) * unit_cost * :c13 AS adjustment_cost, (SELECT sum(quantity)/:c6 FROM purchase WHERE item = id) AS total_purchase FROM q ORDER BY name";
  58. query.prepare(q);
  59. query.bind(":sd1", startDate);
  60. query.bind(":sd2", startDate);
  61. query.bind(":sd3", startDate);
  62. query.bind(":sd4", startDate);
  63. query.bind(":sd6", startDate);
  64. query.bind(":sd7", startDate);
  65. query.bind(":ed1", endDate);
  66. query.bind(":ed2", endDate);
  67. query.bind(":ed3", endDate);
  68. query.bind(":ed4", endDate);
  69. query.bind(":ed5", endDate);
  70. query.bind(":ed6", endDate);
  71. query.bind(":ed7", endDate);
  72. query.bind(":c1", conversion);
  73. query.bind(":c2", conversion);
  74. query.bind(":c3", conversion);
  75. query.bind(":c4", conversion);
  76. query.bind(":c5", conversion);
  77. query.bind(":c6", conversion);
  78. query.bind(":c7", conversion);
  79. query.bind(":c8", conversion);
  80. query.bind(":c9", conversion);
  81. query.bind(":c10", conversion);
  82. query.bind(":c11", conversion);
  83. query.bind(":c12", conversion);
  84. query.bind(":c13", conversion);
  85. query.exec();
  86. output.writeStartElement("table");
  87. output.writeAttribute("rules", "groups");
  88. output.writeAttribute("cellpadding", "3px");
  89. output.writeStartElement("thead");
  90. output.writeStartElement("tr");
  91. output.writeTextElement("th", "ID"); // 0
  92. output.writeTextElement("th", "Coffee"); // 1
  93. output.writeTextElement("th", "Reference"); // 2
  94. output.writeTextElement("th", "Starting (" + unitText + ")"); // 3
  95. output.writeTextElement("th", "Cost"); // 10
  96. output.writeTextElement("th", "Purchase (" + unitText + ")"); // 4
  97. output.writeTextElement("th", "Cost"); // 11
  98. output.writeTextElement("th", "Use (" + unitText + ")"); // 5
  99. output.writeTextElement("th", "Cost"); // 12
  100. output.writeTextElement("th", "Sale (" + unitText + ")"); // 6
  101. output.writeTextElement("th", "Cost"); // 13
  102. output.writeTextElement("th", "Adjustment (" + unitText + ")"); // 9
  103. output.writeTextElement("th", "Cost"); // 15
  104. output.writeTextElement("th", "Ending (" + unitText + ")"); // 7
  105. output.writeTextElement("th", "Cost"); // 14
  106. output.writeEndElement();
  107. output.writeEndElement();
  108. output.writeStartElement("tbody");
  109. var sum3 = 0;
  110. var sum10 = 0;
  111. var sum4 = 0;
  112. var sum11 = 0;
  113. var sum5 = 0;
  114. var sum12 = 0;
  115. var sum6 = 0;
  116. var sum13 = 0;
  117. var sum9 = 0;
  118. var sum15 = 0;
  119. var sum7 = 0;
  120. var sum14 = 0;;
  121. while(query.next())
  122. {
  123. output.writeStartElement("tr");
  124. output.writeStartElement("td");
  125. output.writeStartElement("a");
  126. output.writeAttribute("href", "typica://script/" + query.value(0));
  127. output.writeTextElement("span", query.value(0)); //ID
  128. output.writeEndElement();
  129. output.writeEndElement();
  130. output.writeTextElement("td", query.value(1)); //Coffee
  131. output.writeTextElement("td", query.value(2)); //Reference
  132. output.writeStartElement("td"); //Starting Wt
  133. output.writeAttribute("title", (parseFloat(query.value(3))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
  134. output.writeCDATA(parseFloat(query.value(3)).toFixed(2));
  135. output.writeEndElement(); //End of Starting Wt.
  136. output.writeTextElement("td", parseFloat(query.value(10)).toFixed(2)); //Starting Cost
  137. output.writeStartElement("td"); //Purchase Wt
  138. output.writeAttribute("title", (parseFloat(query.value(4))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
  139. output.writeCDATA(parseFloat(query.value(4)).toFixed(2));
  140. output.writeEndElement(); //End of Purchase Wt
  141. output.writeTextElement("td", parseFloat(query.value(11)).toFixed(2)); //Purchase Cost
  142. output.writeStartElement("td"); //Use Wt
  143. output.writeAttribute("title", (parseFloat(query.value(5))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
  144. output.writeCDATA(parseFloat(query.value(5)).toFixed(2));
  145. output.writeEndElement(); //End of Use Wt
  146. output.writeTextElement("td", parseFloat(query.value(12)).toFixed(2)); //Use Cost
  147. output.writeStartElement("td"); //Sale Wt
  148. output.writeAttribute("title", (parseFloat(query.value(6))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
  149. output.writeCDATA(parseFloat(query.value(6)).toFixed(2));
  150. output.writeEndElement(); //End of Sale Wt
  151. output.writeTextElement("td", parseFloat(query.value(13)).toFixed(2)); //Sale Cost
  152. output.writeStartElement("td"); //Adjustment Wt
  153. output.writeAttribute("title", (parseFloat(query.value(9))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
  154. output.writeCDATA(parseFloat(query.value(9)).toFixed(2));
  155. output.writeEndElement(); //Adjustment Wt
  156. output.writeTextElement("td", parseFloat(query.value(15)).toFixed(2)); //Adjustment Cost
  157. output.writeStartElement("td"); //Ending Wt
  158. output.writeAttribute("title", (parseFloat(query.value(7))/parseFloat(query.value(16)) * 100).toFixed(0) + "%");
  159. output.writeCDATA(parseFloat(query.value(7)).toFixed(2));
  160. output.writeEndElement(); //End of Ending Wt
  161. output.writeTextElement("td", parseFloat(query.value(14)).toFixed(2)); //Ending Cost
  162. output.writeEndElement();
  163. sum3 += parseFloat(query.value(3));
  164. sum10 += parseFloat(query.value(10));
  165. sum4 += parseFloat(query.value(4));
  166. sum11 += parseFloat(query.value(11));
  167. sum5 += parseFloat(query.value(5));
  168. sum12 += parseFloat(query.value(12));
  169. sum6 += parseFloat(query.value(6));
  170. sum13 += parseFloat(query.value(13));
  171. sum9 += parseFloat(query.value(9));
  172. sum15 += parseFloat(query.value(15));
  173. sum7 += parseFloat(query.value(7));
  174. sum14 += parseFloat(query.value(14));
  175. }
  176. output.writeEndElement(); // tbody
  177. output.writeStartElement("tfoot");
  178. output.writeStartElement("tr");
  179. output.writeTextElement("td", "");
  180. output.writeTextElement("td", "");
  181. output.writeTextElement("th", "Total:");
  182. output.writeTextElement("td", sum3.toFixed(2));
  183. output.writeTextElement("td", sum10.toFixed(2));
  184. output.writeTextElement("td", sum4.toFixed(2));
  185. output.writeTextElement("td", sum11.toFixed(2));
  186. output.writeTextElement("td", sum5.toFixed(2));
  187. output.writeTextElement("td", sum12.toFixed(2));
  188. output.writeTextElement("td", sum6.toFixed(2));
  189. output.writeTextElement("td", sum13.toFixed(2));
  190. output.writeTextElement("td", sum9.toFixed(2));
  191. output.writeTextElement("td", sum15.toFixed(2));
  192. output.writeTextElement("td", sum7.toFixed(2));
  193. output.writeTextElement("td", sum14.toFixed(2));
  194. output.writeEndElement(); // tr
  195. output.writeEndElement(); // tfoot
  196. output.writeEndElement();
  197. output.writeEndElement();
  198. output.writeEndElement();
  199. output.writeEndDocument();
  200. view.setContent(buffer);
  201. buffer.close();
  202. query = query.invalidate();
  203. }
  204. refresh();
  205. dateSelect.rangeUpdated.connect(function() {
  206. refresh();
  207. });
  208. view.scriptLinkClicked.connect(function(url) {
  209. var itemReport = createReport("itemtransactions.xml");
  210. var sIB = findChildObject(itemReport, 'item');
  211. sIB.currentIndex = sIB.findData(url);
  212. });
  213. ]]>
  214. </program>
  215. </window>