Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

inventory.xml 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <window id="inventoryreport">
  2. <reporttitle>Inventory:->Current Inventory and Availability Projection</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <label>Sort Order:</label>
  6. <sqldrop id="sort" />
  7. <label>Weight Unit:</label>
  8. <sqldrop id="unit" />
  9. <stretch />
  10. </layout>
  11. <webview id="report" />
  12. </layout>
  13. <menu name="File">
  14. <item id="print" shortcut="Ctrl+P">Print</item>
  15. </menu>
  16. <program>
  17. <![CDATA[
  18. this.windowTitle = "Typica - Current Inventory and Availability Projection";
  19. var report = findChildObject(this, 'report');
  20. var printMenu = findChildObject(this, 'print');
  21. printMenu.triggered.connect(function() {
  22. report.print();
  23. });
  24. var sortBox = findChildObject(this, 'sort');
  25. sortBox.addItem("Coffee A-Z");
  26. sortBox.addItem("Coffee Z-A");
  27. sortBox.addItem("Stock Ascending");
  28. sortBox.addItem("Stock Descending");
  29. sortBox.addItem("Sacks Ascending");
  30. sortBox.addItem("Sacks Descending");
  31. sortBox.addItem("Unit Cost Ascending");
  32. sortBox.addItem("Unit Cost Descending");
  33. sortBox.addItem("Stock Cost Ascending");
  34. sortBox.addItem("Stock Cost Descending");
  35. sortBox.addItem("Use Rate Ascending");
  36. sortBox.addItem("Use Rate Descending");
  37. sortBox.addItem("Availability Shortest-Longest");
  38. sortBox.addItem("Availability Longest-Shortest");
  39. sortBox.currentIndex = QSettings.value("inventory_sort", 0);
  40. var unitBox = findChildObject(this, 'unit');
  41. unitBox.addItem("Kg");
  42. unitBox.addItem("Lb");
  43. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  44. function refresh() {
  45. var buffer = new QBuffer;
  46. buffer.open(3);
  47. var output = new XmlWriter(buffer);
  48. output.writeStartDocument("1.0");
  49. 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">');
  50. output.writeStartElement("html");
  51. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  52. output.writeStartElement("head");
  53. output.writeTextElement("title", "Current Inventory and Availability Projection");
  54. output.writeEndElement();
  55. output.writeStartElement("body");
  56. output.writeTextElement("h1", "Current Inventory and Availability Projection");
  57. output.writeTextElement("p", "This is a report showing how much of each coffee is available, the cost of that coffee, the daily rate of use for that coffee, and the date the coffee will be gone if use continues at the current rate.");
  58. output.writeStartElement("table");
  59. output.writeAttribute("rules", "groups");
  60. output.writeAttribute("cellpadding", "3px");
  61. output.writeStartElement("thead");
  62. output.writeStartElement("tr");
  63. output.writeTextElement("th", "Coffee");
  64. switch(unitBox.currentIndex)
  65. {
  66. case 0:
  67. output.writeTextElement("th", "Stock (Kg)");
  68. break;
  69. case 1:
  70. output.writeTextElement("th", "Stock (Lb)");
  71. break;
  72. }
  73. output.writeTextElement("th", "Sacks");
  74. output.writeTextElement("th", "Unit Cost");
  75. output.writeTextElement("th", "Stock Cost");
  76. output.writeTextElement("th", "Use Rate");
  77. output.writeTextElement("th", "Availability");
  78. output.writeEndElement();
  79. output.writeEndElement();
  80. output.writeStartElement("tbody");
  81. var query = new QSqlQuery();
  82. var q = "SELECT name, (quantity / :conversion)::numeric(12,2) AS quantity, (quantity / (SELECT conversion FROM lb_bag_conversion WHERE item = id))::numeric(12,2) AS sacks, (SELECT cost * :conversion2 FROM purchase WHERE item = id)::numeric(12,2) AS cost, (quantity * (SELECT cost FROM purchase WHERE item = id))::numeric(12,2) AS stock_cost, (SELECT rate / :conversion3 FROM coffee_history WHERE coffee_history.id = items.id)::numeric(12,2) AS rate, (SELECT out FROM coffee_history WHERE coffee_history.id = items.id) AS out FROM items WHERE quantity > 0 ";
  83. switch(sortBox.currentIndex)
  84. {
  85. case 0:
  86. q = q + "ORDER BY name ASC";
  87. break;
  88. case 1:
  89. q = q + "ORDER BY name DESC";
  90. break;
  91. case 2:
  92. q = q + "ORDER BY quantity ASC";
  93. break;
  94. case 3:
  95. q = q + "ORDER BY quantity DESC";
  96. break;
  97. case 4:
  98. q = q + "ORDER BY sacks ASC";
  99. break;
  100. case 5:
  101. q = q + "ORDER BY sacks DESC";
  102. break;
  103. case 6:
  104. q = q + "ORDER BY cost ASC";
  105. break;
  106. case 7:
  107. q = q + "ORDER BY cost DESC";
  108. break;
  109. case 8:
  110. q = q + "ORDER BY stock_cost ASC";
  111. break;
  112. case 9:
  113. q = q + "ORDER BY stock_cost DESC";
  114. break;
  115. case 10:
  116. q = q + "ORDER BY rate ASC";
  117. break;
  118. case 11:
  119. q = q + "ORDER BY rate DESC";
  120. break;
  121. case 12:
  122. q = q + "ORDER BY out ASC";
  123. break;
  124. case 13:
  125. q = q + "ORDER BY out DESC";
  126. break;
  127. }
  128. query.prepare(q);
  129. switch(unitBox.currentIndex)
  130. {
  131. case 0:
  132. query.bind(":conversion", 2.2);
  133. query.bind(":conversion2", 2.2);
  134. query.bind(":conversion3", 2.2);
  135. break;
  136. case 1:
  137. query.bind(":conversion", 1);
  138. query.bind(":conversion2", 1);
  139. query.bind(":conversion3", 1);
  140. break;
  141. }
  142. query.exec();
  143. while(query.next())
  144. {
  145. output.writeStartElement("tr");
  146. output.writeTextElement("td", query.value(0));
  147. output.writeTextElement("td", query.value(1));
  148. output.writeTextElement("td", query.value(2));
  149. output.writeTextElement("td", query.value(3));
  150. output.writeTextElement("td", query.value(4));
  151. output.writeTextElement("td", query.value(5));
  152. output.writeTextElement("td", query.value(6));
  153. output.writeEndElement();
  154. }
  155. output.writeEndElement();
  156. output.writeStartElement("tfoot");
  157. output.writeStartElement("tr");
  158. output.writeTextElement("th", "Totals");
  159. query.prepare("SELECT (sum(quantity) / :conversion)::numeric(12,2), sum(quantity * (SELECT cost FROM purchase WHERE item = id))::numeric(12,2) FROM items WHERE quantity > 0");
  160. switch(unitBox.currentIndex)
  161. {
  162. case 0:
  163. query.bind(":conversion", 2.2);
  164. break;
  165. case 1:
  166. query.bind(":conversion", 1);
  167. break;
  168. }
  169. query.exec();
  170. query.next();
  171. output.writeTextElement("td", query.value(0));
  172. output.writeTextElement("td", "");
  173. output.writeTextElement("td", "");
  174. output.writeTextElement("td", query.value(1));
  175. output.writeTextElement("td", "");
  176. output.writeTextElement("td", "");
  177. output.writeEndElement();
  178. output.writeEndElement();
  179. output.writeEndElement();
  180. output.writeEndElement();
  181. output.writeEndElement();
  182. output.writeEndDocument();
  183. report.setContent(buffer);
  184. buffer.close();
  185. }
  186. refresh();
  187. sortBox['currentIndexChanged(int)'].connect(function() {
  188. QSettings.setValue("inventory_sort", sortBox.currentIndex);
  189. refresh();
  190. });
  191. unitBox['currentIndexChanged(int)'].connect(function() {
  192. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  193. refresh();
  194. });
  195. ]]>
  196. </program>
  197. </window>