Typica is a free program for professional coffee roasters. https://typica.us
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

monthcompare.xml 8.9KB

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