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 9.7KB

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