Typica is a free program for professional coffee roasters. https://typica.us
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

greensales.xml 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 cdt = new Date(Date.now());
  58. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  59. var dateRange = dateSelect.currentRange();
  60. var startDate = dateRange[0];
  61. var endDate = dateRange[dateRange.length - 1];
  62. output.writeTextElement("h1", TTR("greensales", "Green Coffee Sales: ") + startDate + " - " + endDate);
  63. var conversion = 1;
  64. var unitText = TTR("greensales", "Lb");
  65. if(unitBox.currentIndex == 0) {
  66. conversion = 2.2;
  67. unitText = TTR("greensales", "Kg");
  68. }
  69. var query = new QSqlQuery();
  70. 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");
  71. query.bind(":conversion", conversion);
  72. query.bind(":ed", endDate);
  73. query.bind(":sd", startDate);
  74. query.exec();
  75. output.writeStartElement("table");
  76. output.writeAttribute("rules", "groups");
  77. output.writeAttribute("cellpadding", "3px");
  78. output.writeStartElement("thead");
  79. output.writeStartElement("tr");
  80. output.writeTextElement("th", TTR("greensales", "ID")); // 0
  81. output.writeTextElement("th", TTR("greensales", "Coffee")); // 1
  82. output.writeTextElement("th", TTR("greensales", "Origin")); // 2
  83. output.writeTextElement("th", TTR("greensales", "Reference")); // 3
  84. output.writeTextElement("th", TTR("greensales", "Quantity")); // 4
  85. output.writeEndElement();
  86. output.writeEndElement();
  87. output.writeStartElement("tbody");
  88. while(query.next()) {
  89. output.writeStartElement("tr");
  90. output.writeAttribute("id", "r"+query.value(0));
  91. reportitems.push(query.value(0));
  92. output.writeTextElement("td", query.value(0));
  93. output.writeTextElement("td", query.value(1));
  94. output.writeTextElement("td", query.value(2));
  95. output.writeTextElement("td", query.value(3));
  96. output.writeTextElement("td", query.value(4));
  97. output.writeEndElement();
  98. }
  99. output.writeEndElement();
  100. output.writeStartElement("tfoot");
  101. query.prepare("SELECT (sum(quantity)/:conversion)::numeric(12,3) FROM sale WHERE time < :ed ::date + interval '1 day' AND time >= :sd");
  102. query.bind(":conversion", conversion);
  103. query.bind(":ed", endDate);
  104. query.bind(":sd", startDate);
  105. query.exec();
  106. if(query.next()) {
  107. output.writeStartElement("tr");
  108. output.writeEmptyElement("td");
  109. output.writeEmptyElement("td");
  110. output.writeEmptyElement("td");
  111. output.writeTextElement("th", TTR("greensales", "Total:"));
  112. output.writeTextElement("td", query.value(0));
  113. output.writeEndElement();
  114. }
  115. output.writeEndElement();
  116. output.writeEndElement();
  117. output.writeEndElement();
  118. output.writeEndElement();
  119. output.writeEndDocument();
  120. view.setContent(buffer);
  121. buffer.close();
  122. query = query.invalidate();
  123. }
  124. refresh();
  125. dateSelect.rangeUpdated.connect(refresh);
  126. ]]>
  127. </program>
  128. </window>