Typica is a free program for professional coffee roasters. https://typica.us
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

greensales.xml 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <window id="greensales">
  2. <reporttitle>Sales:->Green Coffee Sales</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <daterange id="dates" initial="9" /><!-- Current Month to Date-->
  6. <label>Weight Unit:</label>
  7. <sqldrop id="unit" />
  8. <stretch />
  9. </layout>
  10. <webview id="report" />
  11. </layout>
  12. <menu name="File">
  13. <item id="print" shortcut="Ctrl+P">Print</item>
  14. </menu>
  15. <program>
  16. <![CDATA[
  17. this.windowTitle = TTR("greensales", "Typica - Green Coffee Sales");
  18. var dateSelect = findChildObject(this, 'dates');
  19. var dateQuery = new QSqlQuery();
  20. dateQuery.exec("SELECT time::date FROM sale WHERE time = (SELECT min(time) FROM sale) OR time = (SELECT max(time) FROM sale) ORDER BY time ASC");
  21. dateQuery.next();
  22. var lifetimeStartDate = dateQuery.value(0);
  23. var lifetimeEndDate;
  24. if(dateQuery.next()) {
  25. lifetimeEndDate = dateQuery.value(0);
  26. } else {
  27. lifetimeEndDate = lifetimeStartDate;
  28. }
  29. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  30. dateQuery = dateQuery.invalidate();
  31. var unitBox = findChildObject(this, 'unit');
  32. unitBox.addItem(TTR("greensales", "Kg"));
  33. unitBox.addItem(TTR("greensales", "Lb"));
  34. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  35. unitBox['currentIndexChanged(int)'].connect(function() {
  36. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  37. refresh();
  38. });
  39. var view = findChildObject(this, 'report');
  40. var printMenu = findChildObject(this, 'print');
  41. printMenu.triggered.connect(function() {
  42. view.print();
  43. });
  44. var reportitems = new Array();
  45. function refresh() {
  46. var buffer = new QBuffer;
  47. buffer.open(3);
  48. var output = new XmlWriter(buffer);
  49. output.writeStartDocument("1.0");
  50. 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">');
  51. output.writeStartElement("html");
  52. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  53. output.writeStartElement("head");
  54. output.writeTextElement("title", TTR("greensales", "Green Coffee Sales"));
  55. output.writeEndElement();
  56. output.writeStartElement("body");
  57. var dateRange = dateSelect.currentRange();
  58. var startDate = dateRange[0];
  59. var endDate = dateRange[dateRange.length - 1];
  60. output.writeTextElement("h1", TTR("greensales", "Green Coffee Sales: ") + startDate + " - " + endDate);
  61. var conversion = 1;
  62. var unitText = TTR("greensales", "Lb");
  63. if(unitBox.currentIndex == 0) {
  64. conversion = 2.2;
  65. unitText = TTR("greensales", "Kg");
  66. }
  67. var query = new QSqlQuery();
  68. query.prepare("SELECT item, (SELECT name FROM coffees WHERE id = item) AS name, (SELECT origin FROM coffees WHERE id = item) AS origin, (SELECT reference FROM coffees WHERE id = item) AS reference, (SUM(quantity)/:conversion)::numeric(12,3) FROM sale WHERE time < :ed ::date + interval '1 day' AND time >= :sd GROUP BY item ORDER BY name ASC");
  69. query.bind(":conversion", conversion);
  70. query.bind(":ed", endDate);
  71. query.bind(":sd", startDate);
  72. query.exec();
  73. output.writeStartElement("table");
  74. output.writeAttribute("rules", "groups");
  75. output.writeAttribute("cellpadding", "3px");
  76. output.writeStartElement("thead");
  77. output.writeStartElement("tr");
  78. output.writeTextElement("th", TTR("greensales", "ID")); // 0
  79. output.writeTextElement("th", TTR("greensales", "Coffee")); // 1
  80. output.writeTextElement("th", TTR("greensales", "Origin")); // 2
  81. output.writeTextElement("th", TTR("greensales", "Reference")); // 3
  82. output.writeTextElement("th", TTR("greensales", "Quantity")); // 4
  83. output.writeEndElement();
  84. output.writeEndElement();
  85. output.writeStartElement("tbody");
  86. while(query.next()) {
  87. output.writeStartElement("tr");
  88. output.writeAttribute("id", "r"+query.value(0));
  89. reportitems.push(query.value(0));
  90. output.writeTextElement("td", query.value(0));
  91. output.writeTextElement("td", query.value(1));
  92. output.writeTextElement("td", query.value(2));
  93. output.writeTextElement("td", query.value(3));
  94. output.writeTextElement("td", query.value(4));
  95. output.writeEndElement();
  96. }
  97. output.writeEndElement();
  98. output.writeStartElement("tfoot");
  99. query.prepare("SELECT (sum(quantity)/:conversion)::numeric(12,3) FROM sale WHERE time < :ed ::date + interval '1 day' AND time >= :sd");
  100. query.bind(":conversion", conversion);
  101. query.bind(":ed", endDate);
  102. query.bind(":sd", startDate);
  103. query.exec();
  104. if(query.next()) {
  105. output.writeStartElement("tr");
  106. output.writeEmptyElement("td");
  107. output.writeEmptyElement("td");
  108. output.writeEmptyElement("td");
  109. output.writeTextElement("th", TTR("greensales", "Total:"));
  110. output.writeTextElement("td", query.value(0));
  111. output.writeEndElement();
  112. }
  113. output.writeEndElement();
  114. output.writeEndElement();
  115. output.writeEndElement();
  116. output.writeEndElement();
  117. output.writeEndDocument();
  118. view.setContent(buffer);
  119. buffer.close();
  120. query = query.invalidate();
  121. }
  122. refresh();
  123. dateSelect.rangeUpdated.connect(refresh);
  124. ]]>
  125. </program>
  126. </window>