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 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. <menu name="Reports" type="reports" src="Reports" />
  16. <program>
  17. <![CDATA[
  18. this.windowTitle = TTR("greensales", "Typica - Green Coffee Sales");
  19. var dateSelect = findChildObject(this, 'dates');
  20. var dateQuery = new QSqlQuery();
  21. 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");
  22. dateQuery.next();
  23. var lifetimeStartDate = dateQuery.value(0);
  24. var lifetimeEndDate;
  25. if(dateQuery.next()) {
  26. lifetimeEndDate = dateQuery.value(0);
  27. } else {
  28. lifetimeEndDate = lifetimeStartDate;
  29. }
  30. dateSelect.setLifetimeRange(lifetimeStartDate, lifetimeEndDate);
  31. dateQuery = dateQuery.invalidate();
  32. var unitBox = findChildObject(this, 'unit');
  33. unitBox.addItem(TTR("greensales", "Kg"));
  34. unitBox.addItem(TTR("greensales", "Lb"));
  35. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  36. unitBox['currentIndexChanged(int)'].connect(function() {
  37. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  38. refresh();
  39. });
  40. var view = findChildObject(this, 'report');
  41. var printMenu = findChildObject(this, 'print');
  42. printMenu.triggered.connect(function() {
  43. view.print();
  44. });
  45. var reportitems = new Array();
  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", TTR("greensales", "Green Coffee Sales"));
  56. output.writeEndElement();
  57. output.writeStartElement("body");
  58. var cdt = new Date(Date.now());
  59. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  60. var dateRange = dateSelect.currentRange();
  61. var startDate = dateRange[0];
  62. var endDate = dateRange[dateRange.length - 1];
  63. output.writeTextElement("h1", TTR("greensales", "Green Coffee Sales: ") + startDate + " - " + endDate);
  64. var conversion = 1;
  65. var unitText = TTR("greensales", "Lb");
  66. if(unitBox.currentIndex == 0) {
  67. conversion = 2.2;
  68. unitText = TTR("greensales", "Kg");
  69. }
  70. var query = new QSqlQuery();
  71. 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");
  72. query.bind(":conversion", conversion);
  73. query.bind(":ed", endDate);
  74. query.bind(":sd", startDate);
  75. query.exec();
  76. output.writeStartElement("table");
  77. output.writeAttribute("rules", "groups");
  78. output.writeAttribute("cellpadding", "3px");
  79. output.writeStartElement("thead");
  80. output.writeStartElement("tr");
  81. output.writeTextElement("th", TTR("greensales", "ID")); // 0
  82. output.writeTextElement("th", TTR("greensales", "Coffee")); // 1
  83. output.writeTextElement("th", TTR("greensales", "Origin")); // 2
  84. output.writeTextElement("th", TTR("greensales", "Reference")); // 3
  85. output.writeTextElement("th", TTR("greensales", "Quantity")); // 4
  86. output.writeEndElement();
  87. output.writeEndElement();
  88. output.writeStartElement("tbody");
  89. while(query.next()) {
  90. output.writeStartElement("tr");
  91. output.writeAttribute("id", "r"+query.value(0));
  92. reportitems.push(query.value(0));
  93. output.writeTextElement("td", query.value(0));
  94. output.writeTextElement("td", query.value(1));
  95. output.writeTextElement("td", query.value(2));
  96. output.writeTextElement("td", query.value(3));
  97. output.writeTextElement("td", query.value(4));
  98. output.writeEndElement();
  99. }
  100. output.writeEndElement();
  101. output.writeStartElement("tfoot");
  102. query.prepare("SELECT (sum(quantity)/:conversion)::numeric(12,3) FROM sale WHERE time < :ed ::date + interval '1 day' AND time >= :sd");
  103. query.bind(":conversion", conversion);
  104. query.bind(":ed", endDate);
  105. query.bind(":sd", startDate);
  106. query.exec();
  107. if(query.next()) {
  108. output.writeStartElement("tr");
  109. output.writeEmptyElement("td");
  110. output.writeEmptyElement("td");
  111. output.writeEmptyElement("td");
  112. output.writeTextElement("th", TTR("greensales", "Total:"));
  113. output.writeTextElement("td", query.value(0));
  114. output.writeEndElement();
  115. }
  116. output.writeEndElement();
  117. output.writeEndElement();
  118. output.writeEndElement();
  119. output.writeEndElement();
  120. output.writeEndDocument();
  121. view.setContent(buffer);
  122. buffer.close();
  123. query = query.invalidate();
  124. }
  125. refresh();
  126. var notifier = Application.subscribe("salechange");
  127. notifier.notify.connect(function() {
  128. refresh();
  129. });
  130. dateSelect.rangeUpdated.connect(refresh);
  131. ]]>
  132. </program>
  133. </window>