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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. <menu name="Reports" type="reports" src="Reports" />
  17. <program>
  18. <![CDATA[
  19. this.windowTitle = TTR("inventoryreport", "Typica - Current Inventory and Availability Projection");
  20. var report = findChildObject(this, 'report');
  21. var printMenu = findChildObject(this, 'print');
  22. printMenu.triggered.connect(function() {
  23. report.print();
  24. });
  25. var sortBox = findChildObject(this, 'sort');
  26. sortBox.addItem(TTR("inventoryreport", "Coffee A-Z"));
  27. sortBox.addItem(TTR("inventoryreport", "Coffee Z-A"));
  28. sortBox.addItem(TTR("inventoryreport", "Stock Ascending"));
  29. sortBox.addItem(TTR("inventoryreport", "Stock Descending"));
  30. sortBox.addItem(TTR("inventoryreport", "Sacks Ascending"));
  31. sortBox.addItem(TTR("inventoryreport", "Sacks Descending"));
  32. sortBox.addItem(TTR("inventoryreport", "Unit Cost Ascending"));
  33. sortBox.addItem(TTR("inventoryreport", "Unit Cost Descending"));
  34. sortBox.addItem(TTR("inventoryreport", "Stock Cost Ascending"));
  35. sortBox.addItem(TTR("inventoryreport", "Stock Cost Descending"));
  36. sortBox.addItem(TTR("inventoryreport", "Use Rate Ascending"));
  37. sortBox.addItem(TTR("inventoryreport", "Use Rate Descending"));
  38. sortBox.addItem(TTR("inventoryreport", "Availability Shortest-Longest"));
  39. sortBox.addItem(TTR("inventoryreport", "Availability Longest-Shortest"));
  40. sortBox.currentIndex = QSettings.value("inventory_sort", 0);
  41. var unitBox = findChildObject(this, 'unit');
  42. unitBox.addItem(TTR("inventoryreport", "Kg"));
  43. unitBox.addItem(TTR("inventoryreport", "Lb"));
  44. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  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("inventoryreport", "Current Inventory and Availability Projection"));
  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. output.writeTextElement("h1", TTR("inventoryreport", "Current Inventory and Availability Projection"));
  60. output.writeTextElement("p", TTR("inventoryreport", "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."));
  61. output.writeStartElement("table");
  62. output.writeAttribute("rules", "groups");
  63. output.writeAttribute("cellpadding", "3px");
  64. output.writeStartElement("thead");
  65. output.writeStartElement("tr");
  66. output.writeTextElement("th", TTR("inventoryreport", "Coffee"));
  67. switch(unitBox.currentIndex)
  68. {
  69. case 0:
  70. output.writeTextElement("th", TTR("inventoryreport", "Stock (Kg)"));
  71. break;
  72. case 1:
  73. output.writeTextElement("th", TTR("inventoryreport", "Stock (Lb)"));
  74. break;
  75. }
  76. output.writeTextElement("th", TTR("inventoryreport", "Sacks"));
  77. output.writeTextElement("th", TTR("inventoryreport", "Unit Cost"));
  78. output.writeTextElement("th", TTR("inventoryreport", "Stock Cost"));
  79. output.writeTextElement("th", TTR("inventoryreport", "Use Rate"));
  80. output.writeTextElement("th", TTR("inventoryreport", "Availability"));
  81. output.writeEndElement();
  82. output.writeEndElement();
  83. output.writeStartElement("tbody");
  84. var query = new QSqlQuery();
  85. var q = "SELECT name || ' (' || id || ')', (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 ";
  86. switch(sortBox.currentIndex)
  87. {
  88. case 0:
  89. q = q + "ORDER BY name ASC";
  90. break;
  91. case 1:
  92. q = q + "ORDER BY name DESC";
  93. break;
  94. case 2:
  95. q = q + "ORDER BY quantity ASC";
  96. break;
  97. case 3:
  98. q = q + "ORDER BY quantity DESC";
  99. break;
  100. case 4:
  101. q = q + "ORDER BY sacks ASC";
  102. break;
  103. case 5:
  104. q = q + "ORDER BY sacks DESC";
  105. break;
  106. case 6:
  107. q = q + "ORDER BY cost ASC";
  108. break;
  109. case 7:
  110. q = q + "ORDER BY cost DESC";
  111. break;
  112. case 8:
  113. q = q + "ORDER BY stock_cost ASC";
  114. break;
  115. case 9:
  116. q = q + "ORDER BY stock_cost DESC";
  117. break;
  118. case 10:
  119. q = q + "ORDER BY rate ASC";
  120. break;
  121. case 11:
  122. q = q + "ORDER BY rate DESC";
  123. break;
  124. case 12:
  125. q = q + "ORDER BY out ASC";
  126. break;
  127. case 13:
  128. q = q + "ORDER BY out DESC";
  129. break;
  130. }
  131. query.prepare(q);
  132. switch(unitBox.currentIndex)
  133. {
  134. case 0:
  135. query.bind(":conversion", 2.2);
  136. query.bind(":conversion2", 2.2);
  137. query.bind(":conversion3", 2.2);
  138. break;
  139. case 1:
  140. query.bind(":conversion", 1);
  141. query.bind(":conversion2", 1);
  142. query.bind(":conversion3", 1);
  143. break;
  144. }
  145. query.exec();
  146. while(query.next())
  147. {
  148. output.writeStartElement("tr");
  149. output.writeTextElement("td", query.value(0));
  150. output.writeTextElement("td", query.value(1));
  151. output.writeTextElement("td", query.value(2));
  152. output.writeTextElement("td", query.value(3));
  153. output.writeTextElement("td", query.value(4));
  154. output.writeTextElement("td", query.value(5));
  155. output.writeTextElement("td", query.value(6));
  156. output.writeEndElement();
  157. }
  158. output.writeEndElement();
  159. output.writeStartElement("tfoot");
  160. output.writeStartElement("tr");
  161. output.writeTextElement("th", TTR("inventoryreport", "Totals"));
  162. 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");
  163. switch(unitBox.currentIndex)
  164. {
  165. case 0:
  166. query.bind(":conversion", 2.2);
  167. break;
  168. case 1:
  169. query.bind(":conversion", 1);
  170. break;
  171. }
  172. query.exec();
  173. query.next();
  174. output.writeTextElement("td", query.value(0));
  175. output.writeTextElement("td", "");
  176. output.writeTextElement("td", "");
  177. output.writeTextElement("td", query.value(1));
  178. output.writeTextElement("td", "");
  179. output.writeTextElement("td", "");
  180. query = query.invalidate();
  181. output.writeEndElement();
  182. output.writeEndElement();
  183. output.writeEndElement();
  184. output.writeEndElement();
  185. output.writeEndElement();
  186. output.writeEndDocument();
  187. report.setContent(buffer);
  188. buffer.close();
  189. }
  190. refresh();
  191. var notifier = Application.subscribe("transactionschange");
  192. notifier.notify.connect(function() {
  193. refresh();
  194. });
  195. sortBox['currentIndexChanged(int)'].connect(function() {
  196. QSettings.setValue("inventory_sort", sortBox.currentIndex);
  197. refresh();
  198. });
  199. unitBox['currentIndexChanged(int)'].connect(function() {
  200. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  201. refresh();
  202. });
  203. ]]>
  204. </program>
  205. </window>