Typica is a free program for professional coffee roasters. https://typica.us
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

itemtransactions.xml 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <window id="item_transactions">
  2. <reporttitle>Inventory:->Item Transactions</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <label>Item:</label>
  6. <sqldrop id="item" data="0" display="1" showdata="true">
  7. <null />
  8. <query>SELECT id, name FROM items WHERE category = 'Coffee: Unroasted' ORDER BY name</query>
  9. </sqldrop>
  10. <label>Weight Unit:</label>
  11. <sqldrop id="unit" />
  12. <stretch />
  13. </layout>
  14. <webview id="report" />
  15. </layout>
  16. <menu name="File">
  17. <item id="print" shortcut="Ctrl+P">Print</item>
  18. </menu>
  19. <program>
  20. <![CDATA[
  21. this.windowTitle = "Typica - Item Transactions";
  22. var itemBox = findChildObject(this, 'item');
  23. var unitBox = findChildObject(this, 'unit');
  24. unitBox.addItem("Kg");
  25. unitBox.addItem("Lb");
  26. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  27. unitBox['currentIndexChanged(int)'].connect(function() {
  28. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  29. refresh();
  30. });
  31. var view = findChildObject(this, 'report');
  32. var printMenu = findChildObject(this, 'print');
  33. printMenu.triggered.connect(function() {
  34. view.print();
  35. });
  36. itemBox['currentIndexChanged(int)'].connect(function() {
  37. refresh();
  38. });
  39. function refresh() {
  40. var buffer = new QBuffer;
  41. buffer.open(3);
  42. var output = new XmlWriter(buffer);
  43. output.writeStartDocument("1.0");
  44. 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">');
  45. output.writeStartElement("html");
  46. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  47. output.writeStartElement("head");
  48. output.writeTextElement("title", "Item Transactions");
  49. output.writeStartElement("style");
  50. output.writeAttribute("type", "text/css");
  51. output.writeCDATA("tr.PURCHASE {background-color: #77FF77}");
  52. output.writeCDATA("tr.USE {background-color: #FFFFFF}");
  53. output.writeCDATA("tr.INVENTORY {background-color: #7777FF}");
  54. output.writeCDATA("tr.SALE {background-color: #FF77FF}");
  55. output.writeCDATA("tr.LOSS {background-color: #FF7777}");
  56. output.writeCDATA("tr.MAKE {background-color: #FFFF77}");
  57. output.writeEndElement(); // style
  58. output.writeEndElement();
  59. output.writeStartElement("body");
  60. output.writeTextElement("h1", "Item Transactions:");
  61. output.writeStartElement("table");
  62. output.writeStartElement("tr");
  63. output.writeStartElement("td");
  64. output.writeTextElement("strong", "Item: ")
  65. output.writeTextElement("span", itemBox.currentText);
  66. output.writeEndElement(); // td
  67. var query = new QSqlQuery();
  68. query.prepare("SELECT reference, category FROM items WHERE id = :item");
  69. query.bind(":item", itemBox.currentData());
  70. query.exec();
  71. if(query.next()) {
  72. output.writeStartElement("td");
  73. output.writeTextElement("strong", "Reference: ");
  74. output.writeTextElement("span", query.value(0));
  75. output.writeEndElement(); // td
  76. output.writeStartElement("td");
  77. output.writeTextElement("strong", "Category: ");
  78. output.writeTextElement("span", query.value(1));
  79. output.writeEndElement(); //td
  80. output.writeEndElement(); //tr
  81. query.prepare("SELECT origin, region, producer, grade, milling, drying FROM coffees WHERE id = :item");
  82. query.bind(":item", itemBox.currentData());
  83. query.exec();
  84. if(query.next()) {
  85. output.writeStartElement("tr");
  86. output.writeStartElement("td");
  87. output.writeTextElement("strong", "Origin: ");
  88. output.writeTextElement("span", query.value(0));
  89. output.writeEndElement(); // td
  90. output.writeStartElement("td");
  91. output.writeTextElement("strong", "Region: ");
  92. output.writeTextElement("span", query.value(1));
  93. output.writeEndElement(); // td
  94. output.writeStartElement("td");
  95. output.writeTextElement("strong", "Producer: ");
  96. output.writeTextElement("span", query.value(2));
  97. output.writeEndElement(); // td
  98. output.writeEndElement(); // tr
  99. output.writeStartElement("tr");
  100. output.writeStartElement("td");
  101. output.writeTextElement("strong", "Grade: ");
  102. output.writeTextElement("span", query.value(3));
  103. output.writeEndElement(); // td
  104. output.writeStartElement("td");
  105. output.writeTextElement("strong", "Milling: ");
  106. output.writeTextElement("span", query.value(4));
  107. output.writeEndElement(); // td
  108. output.writeStartElement("td");
  109. output.writeTextElement("strong", "Drying: ");
  110. output.writeTextElement("span", query.value(5));
  111. output.writeEndElement(); // td
  112. output.writeEndElement(); // tr
  113. query.prepare("SELECT decaf_method FROM decaf_coffees WHERE id = :item");
  114. query.bind(":item", itemBox.currentData());
  115. query.exec();
  116. if(query.next()) {
  117. output.writeStartElement("tr");
  118. output.writeStartElement("td");
  119. output.writeAttribute("colspan", "3");
  120. output.writeTextElement("strong", "Decaffeination Method: ");
  121. output.writeTextElement("span", query.value(0));
  122. output.writeEndElement(); // td
  123. output.writeEndElement(); // tr
  124. }
  125. }
  126. output.writeEndElement() // table
  127. query.prepare("SELECT time::date, type, quantity / :c1, balance / :c2 FROM item_history(:item)");
  128. switch(unitBox.currentIndex)
  129. {
  130. case 0:
  131. query.bind(":c1", 2.2);
  132. query.bind(":c2", 2.2);
  133. break;
  134. case 1:
  135. query.bind(":c1", 1);
  136. query.bind(":c2", 1);
  137. break;
  138. }
  139. query.bind(":item", itemBox.currentData());
  140. query.exec();
  141. output.writeStartElement("table");
  142. output.writeStartElement("tr");
  143. output.writeTextElement("th", "Date");
  144. output.writeTextElement("th", "Type");
  145. output.writeTextElement("th", "Quantity");
  146. output.writeTextElement("th", "Balance");
  147. output.writeEndElement(); // tr
  148. var prev_balance = "0";
  149. var prev_prec = 0;
  150. var cur_prec = 0;
  151. while(query.next()) {
  152. output.writeStartElement("tr");
  153. output.writeAttribute("class", query.value(1));
  154. output.writeTextElement("td", query.value(0));
  155. output.writeTextElement("td", query.value(1));
  156. if(query.value(1) == "INVENTORY") {
  157. var split = prev_balance.split('.');
  158. if(split.length > 1) {
  159. prev_prec = split[1].length;
  160. } else {
  161. prev_prec = 0;
  162. }
  163. split = query.value(2).split('.');
  164. if(split.length > 1) {
  165. cur_prec = split[1].length;
  166. } else {
  167. cur_prec = 0;
  168. }
  169. var prec = prev_prec > cur_prec ? prev_prec : cur_prec;
  170. output.writeTextElement("td", (Number(query.value(2)) - Number(prev_balance)).toFixed(prec));
  171. } else {
  172. output.writeTextElement("td", query.value(2));
  173. }
  174. output.writeTextElement("td", query.value(3));
  175. prev_balance = query.value(3);
  176. output.writeEndElement(); // tr
  177. }
  178. output.writeEndElement(); // table
  179. /* Put the rest of the report here. No sense running queries if
  180. the item doesn't exist. */
  181. } else {
  182. /* Close tags if item data not found. */
  183. output.writeEndElement(); // tr
  184. output.writeEndElement(); // table
  185. }
  186. output.writeEndElement(); // body
  187. output.writeEndElement(); // html
  188. output.writeEndDocument();
  189. view.setContent(buffer);
  190. buffer.close();
  191. query = query.invalidate();
  192. }
  193. refresh();
  194. ]]>
  195. </program>
  196. </window>