Typica is a free program for professional coffee roasters. https://typica.us
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

fypurchase.xml 4.9KB

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