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

fypurchase.xml 4.8KB

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