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.

fypurchase.xml 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <window id="fypurchase">
  2. <reporttitle>Purchase:->Coffee Purchase Previous Years Comparison</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 - Coffee Purchase Previous Years Comparison";
  21. var startDateField = findChildObject(this, 'startdate');
  22. var query = new QSqlQuery();
  23. query.exec("SELECT EXTRACT(YEAR FROM time) FROM purchase WHERE time = (SELECT min(time) FROM purchase)");
  24. query.next();
  25. startDateField.setDate(query.value(0), 1, 1);
  26. var endDateField = findChildObject(this, 'enddate');
  27. endDateField.setDate(endDateField.year(), 12, 31);
  28. var view = findChildObject(this, 'report');
  29. var printMenu = findChildObject(this, 'print');
  30. printMenu.triggered.connect(function() {
  31. view.print();
  32. });
  33. var unitBox = findChildObject(this, 'unit');
  34. unitBox.addItem("Kg");
  35. unitBox.addItem("Lb");
  36. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  37. unitBox['currentIndexChanged(int)'].connect(function() {
  38. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  39. refresh();
  40. });
  41. function refresh() {
  42. var buffer = new QBuffer;
  43. buffer.open(3);
  44. var output = new XmlWriter(buffer);
  45. output.writeStartDocument("1.0");
  46. 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">');
  47. output.writeStartElement("html");
  48. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  49. output.writeStartElement("head");
  50. output.writeTextElement("title", "Coffee Purchase Previous Years Comparison");
  51. output.writeEndElement();
  52. output.writeStartElement("body");
  53. output.writeTextElement("h1", "Coffee Purchase Previous Years Comparison");
  54. output.writeStartElement("table");
  55. output.writeAttribute("style", "page-break-after:auto;");
  56. output.writeAttribute("rules", "groups");
  57. output.writeAttribute("cellpadding", "3px");
  58. output.writeStartElement("thead");
  59. output.writeStartElement("tr");
  60. output.writeEmptyElement("th");
  61. for(var i = startDateField.year(); i <= endDateField.year(); i++)
  62. {
  63. output.writeTextElement("th", i);
  64. }
  65. output.writeEndElement();
  66. output.writeEndElement();
  67. output.writeStartElement("tbody");
  68. output.writeStartElement("tr");
  69. output.writeTextElement("th", "Sacks Purchased");
  70. var j = 0;
  71. var sacks = new Array;
  72. for(var i = startDateField.year(); i <= endDateField.year(); i++)
  73. {
  74. var q = "SELECT sum(quantity/(SELECT conversion FROM lb_bag_conversion WHERE item = purchase.item)) FROM purchase WHERE time >= '" + i + "-01-01' AND time < '" + (i+1) + "-01-01'";
  75. query.exec(q);
  76. query.next();
  77. output.writeTextElement("td", query.value(0));
  78. sacks[j] = query.value(0);
  79. j++;
  80. }
  81. output.writeEndElement();
  82. output.writeStartElement("tr");
  83. switch(unitBox.currentIndex) {
  84. case 0:
  85. output.writeTextElement("th", "Kilos Purchased");
  86. break;
  87. case 1:
  88. output.writeTextElement("th", "Pounds Purchased");
  89. break;
  90. }
  91. j = 0;
  92. var pounds = new Array;
  93. for(var i = startDateField.year(); i <= endDateField.year(); i++)
  94. {
  95. var q = "SELECT (sum(quantity) / :conversion)::numeric(12,2) FROM purchase WHERE time >= '" + i + "-01-01' AND time < '" + (i+1) + "-01-01'";
  96. query.prepare(q);
  97. query.bind(":conversion", unitBox.currentIndex == 0 ? 2.2 : 1);
  98. query.exec();
  99. query.next();
  100. output.writeTextElement("td", query.value(0));
  101. pounds[j] = query.value(0);
  102. j++;
  103. }
  104. output.writeEndElement();
  105. output.writeStartElement("tr");
  106. output.writeTextElement("th", "Cost");
  107. j = 0;
  108. var cost = new Array;
  109. for(var i = startDateField.year(); i <= endDateField.year(); i++)
  110. {
  111. var q = "SELECT sum(cost*quantity)::numeric(12,2) FROM purchase WHERE time >= '" + i + "-01-01' AND time < '" + (i+1) + "-01-01'";
  112. query.exec(q);
  113. query.next();
  114. output.writeTextElement("td", query.value(0));
  115. cost[j] = query.value(0);
  116. j++;
  117. }
  118. output.writeEndElement();
  119. output.writeEndElement();
  120. output.writeStartElement("tfoot");
  121. output.writeEndElement();
  122. output.writeEndElement();
  123. output.writeEndElement();
  124. output.writeEndElement();
  125. output.writeEndDocument();
  126. view.setContent(buffer);
  127. buffer.close();
  128. }
  129. refresh();
  130. startDateField.dateChanged.connect(function() {
  131. refresh();
  132. });
  133. endDateField.dateChanged.connect(function() {
  134. refresh();
  135. });
  136. ]]>
  137. </program>
  138. </window>