Typica is a free program for professional coffee roasters. https://typica.us
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

inventory.xml 9.8KB

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