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

reminders.xml 9.0KB

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