Typica is a free program for professional coffee roasters. https://typica.us
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

invchange.xml 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. <menu name="Reports" type="reports" src="Reports" />
  16. <program>
  17. <![CDATA[
  18. this.windowTitle = TTR("invchange", "Typica - Inventory Change Summary");
  19. var dateSelect = findChildObject(this, 'dates');
  20. var dateQuery = new QSqlQuery();
  21. dateQuery.exec("SELECT time::date FROM transactions WHERE time = (SELECT min(time) FROM transactions) OR time = (SELECT max(time) FROM transactions) ORDER BY time ASC");
  22. dateQuery.next();
  23. var lifetimeStartDate = dateQuery.value(0);
  24. var lifetimeEndDate;
  25. if(dateQuery.next()) {
  26. lifetimeEndDate = dateQuery.value(0);
  27. } else {
  28. lifetimeEndDate = lifetimeStartDate;
  29. }
  30. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  31. dateQuery = dateQuery.invalidate();
  32. var unitBox = findChildObject(this, 'unit');
  33. unitBox.addItem(TTR("invchange", "Kg"));
  34. unitBox.addItem(TTR("invchange", "Lb"));
  35. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  36. unitBox['currentIndexChanged(int)'].connect(function() {
  37. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  38. refresh();
  39. });
  40. var view = findChildObject(this, 'report');
  41. var printMenu = findChildObject(this, 'print');
  42. printMenu.triggered.connect(function() {
  43. view.print();
  44. });
  45. function refresh() {
  46. var buffer = new QBuffer;
  47. buffer.open(3);
  48. var output = new XmlWriter(buffer);
  49. output.writeStartDocument("1.0");
  50. 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">');
  51. output.writeStartElement("html");
  52. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  53. output.writeStartElement("head");
  54. output.writeTextElement("title", TTR("invchange", "Inventory Change Summary"));
  55. output.writeEndElement();
  56. output.writeStartElement("body");
  57. var cdt = new Date(Date.now());
  58. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  59. var dateRange = dateSelect.currentRange();
  60. var startDate = dateRange[0];
  61. var endDate = dateRange[dateRange.length - 1];
  62. output.writeTextElement("h1", TTR("invchange", "Inventory Change Summary: ") + startDate + " – " + endDate);
  63. var conversion = 1;
  64. if(unitBox.currentIndex == 0) {
  65. conversion = 2.2;
  66. }
  67. var unitText = TTR("invchange", "Lb");
  68. if(unitBox.currentIndex == 0) {
  69. unitText = TTR("invchange", "Kg");
  70. }
  71. var query = new QSqlQuery();
  72. 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, COALESCE((SELECT sum(quantity) FROM loss WHERE item = id AND time >= :sd8 AND time < :ed8 ::date + interval '1 day'), 0)/:c14 AS loss, (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 < :sd9 ::date)) <> 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 - loss - quantity) 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, loss * unit_cost * :c15 AS loss_cost, quantity * unit_cost * :c12 AS quantity_cost, (starting_balance + purchase - use - sale - loss - quantity) * unit_cost * :c13 AS adjustment_cost, (SELECT sum(quantity)/:c6 FROM purchase WHERE item = id) AS total_purchase FROM q ORDER BY name";
  73. query.prepare(q);
  74. query.bind(":sd1", startDate);
  75. query.bind(":sd2", startDate);
  76. query.bind(":sd3", startDate);
  77. query.bind(":sd4", startDate);
  78. query.bind(":sd6", startDate);
  79. query.bind(":sd7", startDate);
  80. query.bind(":sd8", startDate);
  81. query.bind(":sd9", startDate);
  82. query.bind(":ed1", endDate);
  83. query.bind(":ed2", endDate);
  84. query.bind(":ed3", endDate);
  85. query.bind(":ed4", endDate);
  86. query.bind(":ed5", endDate);
  87. query.bind(":ed7", endDate);
  88. query.bind(":ed8", endDate);
  89. query.bind(":c1", conversion);
  90. query.bind(":c2", conversion);
  91. query.bind(":c3", conversion);
  92. query.bind(":c4", conversion);
  93. query.bind(":c5", conversion);
  94. query.bind(":c6", conversion);
  95. query.bind(":c8", conversion);
  96. query.bind(":c9", conversion);
  97. query.bind(":c10", conversion);
  98. query.bind(":c11", conversion);
  99. query.bind(":c12", conversion);
  100. query.bind(":c13", conversion);
  101. query.bind(":c14", conversion);
  102. query.bind(":c15", conversion);
  103. query.exec();
  104. output.writeStartElement("table");
  105. output.writeAttribute("rules", "groups");
  106. output.writeAttribute("cellpadding", "3px");
  107. output.writeStartElement("thead");
  108. output.writeStartElement("tr");
  109. output.writeTextElement("th", TTR("invchange", "ID")); // 0
  110. output.writeTextElement("th", TTR("invchange", "Coffee")); // 1
  111. output.writeTextElement("th", TTR("invchange", "Reference")); // 2
  112. output.writeTextElement("th", TTR("invchange", "Starting (") + unitText + ")"); // 3
  113. output.writeTextElement("th", TTR("invchange", "Cost")); // 11
  114. output.writeTextElement("th", TTR("invchange", "Purchase (") + unitText + ")"); // 4
  115. output.writeTextElement("th", TTR("invchange", "Cost")); // 12
  116. output.writeTextElement("th", TTR("invchange", "Use (") + unitText + ")"); // 5
  117. output.writeTextElement("th", TTR("invchange", "Cost")); // 13
  118. output.writeTextElement("th", TTR("invchange", "Sale (") + unitText + ")"); // 6
  119. output.writeTextElement("th", TTR("invchange", "Cost")); // 14
  120. output.writeTextElement("th", TTR("invchange", "Loss (") + unitText + ")"); // 7
  121. output.writeTextElement("th", TTR("invchange", "Cost")) // 15
  122. output.writeTextElement("th", TTR("invchange", "Adjustment (") + unitText + ")"); // 10
  123. output.writeTextElement("th", TTR("invchange", "Cost")); // 17
  124. output.writeTextElement("th", TTR("invchange", "Ending (") + unitText + ")"); // 8
  125. output.writeTextElement("th", TTR("invchange", "Cost")); // 16
  126. output.writeEndElement();
  127. output.writeEndElement();
  128. output.writeStartElement("tbody");
  129. var sum3 = 0;
  130. var sum10 = 0;
  131. var sum4 = 0;
  132. var sum11 = 0;
  133. var sum5 = 0;
  134. var sum12 = 0;
  135. var sum6 = 0;
  136. var sum13 = 0;
  137. var sum9 = 0;
  138. var sum15 = 0;
  139. var sum7 = 0;
  140. var sum14 = 0;
  141. var loss_sum = 0;
  142. var loss_cost_sum = 0;
  143. while(query.next())
  144. {
  145. output.writeStartElement("tr");
  146. output.writeStartElement("td");
  147. output.writeStartElement("a");
  148. output.writeAttribute("href", "typica://script/" + query.value(0));
  149. output.writeTextElement("span", query.value(0)); //ID
  150. output.writeEndElement();
  151. output.writeEndElement();
  152. output.writeTextElement("td", query.value(1)); //Coffee
  153. output.writeTextElement("td", query.value(2)); //Reference
  154. output.writeStartElement("td"); //Starting Wt
  155. output.writeAttribute("title", (parseFloat(query.value(3))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
  156. output.writeCDATA(parseFloat(query.value(3)).toFixed(2));
  157. output.writeEndElement(); //End of Starting Wt.
  158. output.writeTextElement("td", parseFloat(query.value(11)).toFixed(2)); //Starting Cost
  159. output.writeStartElement("td"); //Purchase Wt
  160. output.writeAttribute("title", (parseFloat(query.value(4))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
  161. output.writeCDATA(parseFloat(query.value(4)).toFixed(2));
  162. output.writeEndElement(); //End of Purchase Wt
  163. output.writeTextElement("td", parseFloat(query.value(12)).toFixed(2)); //Purchase Cost
  164. output.writeStartElement("td"); //Use Wt
  165. output.writeAttribute("title", (parseFloat(query.value(5))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
  166. output.writeCDATA(parseFloat(query.value(5)).toFixed(2));
  167. output.writeEndElement(); //End of Use Wt
  168. output.writeTextElement("td", parseFloat(query.value(13)).toFixed(2)); //Use Cost
  169. output.writeStartElement("td"); //Sale Wt
  170. output.writeAttribute("title", (parseFloat(query.value(6))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
  171. output.writeCDATA(parseFloat(query.value(6)).toFixed(2));
  172. output.writeEndElement(); //End of Sale Wt
  173. output.writeTextElement("td", parseFloat(query.value(14)).toFixed(2)); //Sale Cost
  174. output.writeStartElement("td"); //Loss Wt
  175. output.writeAttribute("title", (parseFloat(query.value(7))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
  176. output.writeCDATA(parseFloat(query.value(7)).toFixed(2));
  177. output.writeEndElement(); //End of loss Wt;
  178. output.writeTextElement("td", parseFloat(query.value(15)).toFixed(2)); //Loss Cost
  179. output.writeStartElement("td"); //Adjustment Wt
  180. output.writeAttribute("title", (parseFloat(query.value(10))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
  181. output.writeCDATA(parseFloat(query.value(10)).toFixed(2));
  182. output.writeEndElement(); //Adjustment Wt
  183. output.writeTextElement("td", parseFloat(query.value(17)).toFixed(2)); //Adjustment Cost
  184. output.writeStartElement("td"); //Ending Wt
  185. output.writeAttribute("title", (parseFloat(query.value(8))/parseFloat(query.value(18)) * 100).toFixed(0) + "%");
  186. output.writeCDATA(parseFloat(query.value(8)).toFixed(2));
  187. output.writeEndElement(); //End of Ending Wt
  188. output.writeTextElement("td", parseFloat(query.value(16)).toFixed(2)); //Ending Cost
  189. output.writeEndElement();
  190. sum3 += parseFloat(query.value(3));
  191. sum10 += parseFloat(query.value(11));
  192. sum4 += parseFloat(query.value(4));
  193. sum11 += parseFloat(query.value(12));
  194. sum5 += parseFloat(query.value(5));
  195. sum12 += parseFloat(query.value(13));
  196. sum6 += parseFloat(query.value(6));
  197. sum13 += parseFloat(query.value(14));
  198. sum9 += parseFloat(query.value(10));
  199. sum15 += parseFloat(query.value(17));
  200. sum7 += parseFloat(query.value(8));
  201. sum14 += parseFloat(query.value(16));
  202. loss_sum += parseFloat(query.value(7));
  203. loss_cost_sum += parseFloat(query.value(15));
  204. }
  205. output.writeEndElement(); // tbody
  206. output.writeStartElement("tfoot");
  207. output.writeStartElement("tr");
  208. output.writeTextElement("td", "");
  209. output.writeTextElement("td", "");
  210. output.writeTextElement("th", TTR("invchange", "Total:"));
  211. output.writeTextElement("td", sum3.toFixed(2));
  212. output.writeTextElement("td", sum10.toFixed(2));
  213. output.writeTextElement("td", sum4.toFixed(2));
  214. output.writeTextElement("td", sum11.toFixed(2));
  215. output.writeTextElement("td", sum5.toFixed(2));
  216. output.writeTextElement("td", sum12.toFixed(2));
  217. output.writeTextElement("td", sum6.toFixed(2));
  218. output.writeTextElement("td", sum13.toFixed(2));
  219. output.writeTextElement("td", loss_sum.toFixed(2));
  220. output.writeTextElement("td", loss_cost_sum.toFixed(2));
  221. output.writeTextElement("td", sum9.toFixed(2));
  222. output.writeTextElement("td", sum15.toFixed(2));
  223. output.writeTextElement("td", sum7.toFixed(2));
  224. output.writeTextElement("td", sum14.toFixed(2));
  225. output.writeEndElement(); // tr
  226. output.writeEndElement(); // tfoot
  227. output.writeEndElement();
  228. output.writeEndElement();
  229. output.writeEndElement();
  230. output.writeEndDocument();
  231. view.setContent(buffer);
  232. buffer.close();
  233. query = query.invalidate();
  234. }
  235. refresh();
  236. var notifier = Application.subscribe("transactionschange");
  237. notifier.notify.connect(function() {
  238. refresh();
  239. });
  240. dateSelect.rangeUpdated.connect(function() {
  241. refresh();
  242. });
  243. view.scriptLinkClicked.connect(function(url) {
  244. var itemReport = createReport("itemtransactions.xml");
  245. var sIB = findChildObject(itemReport, 'item');
  246. sIB.currentIndex = sIB.findData(url);
  247. });
  248. ]]>
  249. </program>
  250. </window>