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

monthcompare.xml 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <window id="pytdprodcomp">
  2. <reporttitle>Production:->Previous Year Production Comparison By Month</reporttitle>
  3. <layout type="vertical">
  4. <layout type="horizontal">
  5. <label>Weight Unit:</label>
  6. <sqldrop id="unit" />
  7. <stretch />
  8. </layout>
  9. <webview id="report" />
  10. </layout>
  11. <menu name="File">
  12. <item id="print" shortcut="Ctrl+P">Print</item>
  13. </menu>
  14. <menu name="Reports" type="reports" src="Reports" />
  15. <program>
  16. <![CDATA[
  17. this.windowTitle = TTR("pytdprodcomp", "Typica - Previous Year Production Comparison By Month");
  18. var view = findChildObject(this, 'report');
  19. var printMenu = findChildObject(this, 'print');
  20. printMenu.triggered.connect(function() {
  21. view.print();
  22. });
  23. var unitBox = findChildObject(this, 'unit');
  24. unitBox.addItem(TTR("pytdprodcomp", "Kg"));
  25. unitBox.addItem(TTR("pytdprodcomp", "Lb"));
  26. unitBox.currentIndex = QSettings.value("script/report_unit", 1);
  27. unitBox['currentIndexChanged(int)'].connect(function() {
  28. QSettings.setValue("script/report_unit", unitBox.currentIndex);
  29. refresh();
  30. });
  31. function refresh() {
  32. var buffer = new QBuffer;
  33. buffer.open(3);
  34. var output = new XmlWriter(buffer);
  35. output.writeStartDocument("1.0");
  36. 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">');
  37. output.writeStartElement("html");
  38. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  39. output.writeStartElement("head");
  40. output.writeTextElement("title", TTR("pytdprodcomp", "Previous Year Production Comparison By Month"));
  41. output.writeEndElement();
  42. output.writeStartElement("body");
  43. var cdt = new Date(Date.now());
  44. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  45. output.writeTextElement("h1", TTR("pytdprodcomp", "Previous Year Production Comparison By Month"));
  46. switch(unitBox.currentIndex)
  47. {
  48. case 0:
  49. output.writeTextElement("p", TTR("pytdprodcomp", "This report compares total roasted coffee production in kilograms with the previous year on a monthly basis."));
  50. break;
  51. case 1:
  52. output.writeTextElement("p", TTR("pytdprodcomp", "This report compares total roasted coffee production in pounds with the previous year on a monthly basis."));
  53. break;
  54. }
  55. output.writeStartElement("table");
  56. output.writeAttribute("style", "page-break-after:auto;");
  57. output.writeAttribute("rules", "groups");
  58. output.writeAttribute("cellpadding", "3px");
  59. output.writeStartElement("thead");
  60. output.writeStartElement("tr");
  61. output.writeTextElement("th", TTR("pytdprodcomp", "Month"));
  62. var query = new QSqlQuery();
  63. query.exec("SELECT EXTRACT(YEAR FROM 'now'::date) AS current_year");
  64. query.next();
  65. var current_year = query.value(0);
  66. output.writeTextElement("th", current_year-1);
  67. output.writeTextElement("th", current_year);
  68. output.writeTextElement("th", "Change");
  69. output.writeEndElement();
  70. output.writeEndElement();
  71. output.writeStartElement("tbody");
  72. var month_names = [TTR("pytdprodcomp", "January"),
  73. TTR("pytdprodcomp", "February"),
  74. TTR("pytdprodcomp", "March"),
  75. TTR("pytdprodcomp", "April"),
  76. TTR("pytdprodcomp", "May"),
  77. TTR("pytdprodcomp", "June"),
  78. TTR("pytdprodcomp", "July"),
  79. TTR("pytdprodcomp", "August"),
  80. TTR("pytdprodcomp", "September"),
  81. TTR("pytdprodcomp", "October"),
  82. TTR("pytdprodcomp", "November"),
  83. TTR("pytdprodcomp", "December")];
  84. var current_data = new Array();
  85. var previous_data = new Array();
  86. for(var i = 0; i < 12; i++) {
  87. var q = "SELECT SUM(roasted_quantity) FROM roasting_log WHERE roasted_id IS NOT NULL AND time > '"
  88. q += current_year;
  89. q += "-";
  90. q += 1+i;
  91. q += "-01' AND time < '";
  92. if(i == 11) {
  93. q += 1+current_year;
  94. } else {
  95. q += current_year;
  96. }
  97. q += "-";
  98. if(i == 11) {
  99. q += "01"
  100. } else {
  101. q += 2+i;
  102. }
  103. q += "-01'";
  104. query.exec(q);
  105. query.next();
  106. current_data.push(query.value(0));
  107. }
  108. for(var i = 0; i < 12; i++) {
  109. var q = "SELECT SUM(roasted_quantity) FROM roasting_log WHERE roasted_id IS NOT NULL AND time > '"
  110. q += current_year-1;
  111. q += "-";
  112. q += 1+i;
  113. q += "-01' AND time < '";
  114. if(i == 11) {
  115. q += current_year;
  116. } else {
  117. q += current_year-1;
  118. }
  119. q += "-";
  120. if(i == 11) {
  121. q += "01"
  122. } else {
  123. q += 2+i;
  124. }
  125. q += "-01'";
  126. query.exec(q);
  127. query.next();
  128. previous_data.push(query.value(0));
  129. }
  130. query = query.invalidate();
  131. for(var i = 0; i < 12; i++) {
  132. output.writeStartElement("tr");
  133. output.writeTextElement("td", month_names[i]);
  134. switch(unitBox.currentIndex)
  135. {
  136. case 0:
  137. output.writeTextElement("td", Number(previous_data[i] / 2.2).toFixed(2));
  138. output.writeTextElement("td", Number(current_data[i] / 2.2).toFixed(2));
  139. output.writeTextElement("td", Number((current_data[i] - previous_data[i]) / 2.2).toFixed(2));
  140. break;
  141. case 1:
  142. output.writeTextElement("td", Number(previous_data[i]).toFixed(2));
  143. output.writeTextElement("td", Number(current_data[i]).toFixed(2));
  144. output.writeTextElement("td", Number(current_data[i]-previous_data[i]).toFixed(2));
  145. break;
  146. }
  147. output.writeEndElement();
  148. }
  149. output.writeEndElement();
  150. output.writeStartElement("tfoot");
  151. output.writeTextElement("th", TTR("pytdprodcomp", "Totals"));
  152. var current_total = current_data.reduce(function(a,b) {return Number(a) + Number(b);}, 0);
  153. var previous_total = previous_data.reduce(function(a,b) {return Number(a) + Number(b);}, 0);
  154. switch(unitBox.currentIndex)
  155. {
  156. case 0:
  157. output.writeTextElement("td", (previous_total/2.2).toFixed(2));
  158. output.writeTextElement("td", (current_total/2.2).toFixed(2));
  159. output.writeTextElement("td", ((current_total-previous_total)/2.2).toFixed(2));
  160. break;
  161. case 1:
  162. output.writeTextElement("td", previous_total.toFixed(2));
  163. output.writeTextElement("td", current_total.toFixed(2));
  164. output.writeTextElement("td", (current_total-previous_total).toFixed(2));
  165. break;
  166. }
  167. output.writeEndElement();
  168. output.writeEndElement();
  169. output.writeEndElement();
  170. output.writeEndDocument();
  171. view.setContent(buffer);
  172. buffer.close();
  173. }
  174. refresh();
  175. var notifier = Application.subscribe("roastinglogchange");
  176. notifier.notify.connect(function() {
  177. refresh();
  178. });
  179. ]]>
  180. </program>
  181. </window>