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

reminders.xml 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <window id="remindersreport">
  2. <reporttitle>Production:->Reminders</reporttitle>
  3. <layout type="vertical">
  4. <webview id="report" />
  5. </layout>
  6. <menu name="File">
  7. <item id="print" shortcut="Ctrl+P">Print</item>
  8. </menu>
  9. <menu name="Reports" type="reports" src="Reports" />
  10. <program>
  11. <![CDATA[
  12. var window = this;
  13. this.windowTitle = TTR("remindersreport", "Typica - Reminders");
  14. var report = findChildObject(this, 'report');
  15. var printMenu = findChildObject(this, 'print');
  16. printMenu.triggered.connect(function() {
  17. report.print();
  18. });
  19. var e = new Array();
  20. function populateReminderData() {
  21. e = new Array();
  22. var query = new QSqlQuery;
  23. query.exec("SELECT id, reminder FROM reminders");
  24. while(query.next())
  25. {
  26. var reminder = JSON.parse(query.value(1));
  27. reminder.dbid = query.value(0);
  28. var start_time = "" + reminder.start_year + "-" + reminder.start_month + "-" + reminder.start_day + " " + reminder.start_time;
  29. if(reminder.condition == "PRODUCTIONWEIGHT")
  30. {
  31. var convert = 1;
  32. var unittext = TTR("remindersreport", " Lb");
  33. if(reminder.unit == "KG")
  34. {
  35. convert = 2.2;
  36. unittext = TTR("remindersreport", " Kg");
  37. }
  38. var dq = new QSqlQuery;
  39. dq.prepare("SELECT sum(roasted_quantity)/:conversion FROM roasting_log WHERE time > :since");
  40. dq.bind(":conversion", convert);
  41. dq.bind(":since", start_time);
  42. dq.exec();
  43. dq.next();
  44. var proportion;
  45. var remain;
  46. if(reminder.value == 0 || (reminder.value < Number(dq.value(0))))
  47. {
  48. proportion = 1;
  49. }
  50. else
  51. {
  52. proportion = Number(dq.value(0)) / reminder.value;
  53. }
  54. remain = (reminder.value - Number(dq.value(0))).toFixed(0);
  55. reminder.completion = proportion;
  56. reminder.detail = remain + unittext;
  57. dq = dq.invalidate();
  58. }
  59. else if(reminder.condition == "DAYS")
  60. {
  61. var dq = new QSqlQuery;
  62. dq.prepare("SELECT 'now'::date - :since::date");
  63. dq.bind(":since", start_time);
  64. dq.exec();
  65. dq.next();
  66. var proportion;
  67. var remain;
  68. if(reminder.value == 0 || (reminder.value < Number(dq.value(0))))
  69. {
  70. proportion = 1;
  71. }
  72. else
  73. {
  74. proportion = Number(dq.value(0)) / reminder.value;
  75. }
  76. remain = reminder.value - Number(dq.value(0));
  77. reminder.completion = proportion;
  78. reminder.detail = remain + TTR("remindersreport", " Days");
  79. dq = dq.invalidate();
  80. }
  81. else if(reminder.condition == "PRODUCTIONBATCHES")
  82. {
  83. var dq = new QSqlQuery;
  84. dq.prepare("SELECT count(1) FROM roasting_log WHERE time > :since");
  85. dq.bind(":since", start_time);
  86. dq.exec();
  87. dq.next();
  88. var proportion;
  89. var remain;
  90. if(reminder.value == 0 || (reminder.value < Number(dq.value(0))))
  91. {
  92. proportion = 1;
  93. }
  94. else
  95. {
  96. proportion = Number(dq.value(0)) / reminder.value;
  97. }
  98. remain = reminder.value - Number(dq.value(0));
  99. reminder.completion = proportion;
  100. reminder.detail = remain + TTR("remindersreport", " Batches");
  101. dq = dq.invalidate();
  102. }
  103. else if(reminder.condition == "PRODUCTIONHOURS")
  104. {
  105. var dq = new QSqlQuery;
  106. dq.prepare("SELECT extract(epoch FROM (SELECT sum(duration) FROM roasting_log WHERE time > :since) / 3600)");
  107. dq.bind(":since", start_time);
  108. dq.exec();
  109. dq.next();
  110. var proportion;
  111. var remain;
  112. if(reminder.value == 0 || (reminder.value < Number(dq.value(0))))
  113. {
  114. proportion = 1;
  115. }
  116. else
  117. {
  118. proportion = Number(dq.value(0)) / reminder.value;
  119. }
  120. remain = reminder.value - Number(dq.value(0));
  121. reminder.completion = proportion;
  122. reminder.detail = remain.toFixed(1) + TTR("remindersreport", " Hours");
  123. dq = dq.invalidate();
  124. }
  125. e[reminder.dbid] = reminder;
  126. }
  127. query = query.invalidate();
  128. }
  129. function refresh() {
  130. populateReminderData();
  131. var passedData = e.filter(function(n){return n.hasOwnProperty("completion")}).sort(function(a,b){return b.completion-a.completion});
  132. var buffer = new QBuffer;
  133. buffer.open(3);
  134. var output = new XmlWriter(buffer);
  135. output.writeStartDocument("1.0");
  136. 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">');
  137. output.writeStartElement("html");
  138. output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  139. output.writeStartElement("head");
  140. output.writeTextElement("title", TTR("remindersreport", "Reminders"));
  141. output.writeEndElement();
  142. output.writeStartElement("body");
  143. var cdt = new Date(Date.now());
  144. output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
  145. output.writeTextElement("h1", TTR("remindersreport", "Reminders"));
  146. output.writeStartElement("a");
  147. output.writeAttribute("href", "typica://script/0");
  148. output.writeStartElement("div");
  149. output.writeAttribute("class", "reminder");
  150. output.writeStartElement("div");
  151. output.writeAttribute("class", "nocolor");
  152. output.writeEndElement();
  153. output.writeStartElement("span");
  154. output.writeAttribute("class", "title");
  155. output.writeCDATA(TTR("remindersreport", "New Reminder"));
  156. output.writeEndElement();
  157. output.writeEndElement();
  158. output.writeEndElement();
  159. output.writeTextElement("script", "e = " + JSON.stringify(passedData));
  160. var styleFile = new QFile(QSettings.value("config") + "/Scripts/reminders.css");
  161. styleFile.open(1);
  162. output.writeTextElement("style", styleFile.readToString());
  163. styleFile.close();
  164. output.writeStartElement("script");
  165. scriptFile = new QFile(QSettings.value("config") + "/Scripts/reminders.js");
  166. scriptFile.open(1);
  167. output.writeCDATA(scriptFile.readToString());
  168. scriptFile.close();
  169. output.writeEndElement();
  170. output.writeEndElement();
  171. output.writeEndDocument();
  172. report.setContent(buffer);
  173. buffer.close();
  174. }
  175. refresh();
  176. var doRefresh = function() {
  177. refresh();
  178. }
  179. var notifier = Application.subscribe("roastinglogchange");
  180. notifier.notify.connect(function() {
  181. refresh();
  182. });
  183. report.scriptLinkClicked.connect(function(url) {
  184. var reminder = createWindow("editreminder");
  185. if(url != "0")
  186. {
  187. reminder.loadData(e[url]);
  188. }
  189. reminder.setRefreshFunction(doRefresh);
  190. });
  191. ]]>
  192. </program>
  193. </window>