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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. output.writeTextElement("h1", TTR("remindersreport", "Reminders"));
  143. output.writeStartElement("a");
  144. output.writeAttribute("href", "typica://script/0");
  145. output.writeStartElement("div");
  146. output.writeAttribute("class", "reminder");
  147. output.writeStartElement("div");
  148. output.writeAttribute("class", "nocolor");
  149. output.writeEndElement();
  150. output.writeStartElement("span");
  151. output.writeAttribute("class", "title");
  152. output.writeCDATA(TTR("remindersreport", "New Reminder"));
  153. output.writeEndElement();
  154. output.writeEndElement();
  155. output.writeEndElement();
  156. output.writeTextElement("script", "e = " + JSON.stringify(passedData));
  157. var styleFile = new QFile(QSettings.value("config") + "/Scripts/reminders.css");
  158. styleFile.open(1);
  159. output.writeTextElement("style", styleFile.readToString());
  160. styleFile.close();
  161. output.writeStartElement("script");
  162. scriptFile = new QFile(QSettings.value("config") + "/Scripts/reminders.js");
  163. scriptFile.open(1);
  164. output.writeCDATA(scriptFile.readToString());
  165. scriptFile.close();
  166. output.writeEndElement();
  167. output.writeEndElement();
  168. output.writeEndDocument();
  169. report.setContent(buffer);
  170. buffer.close();
  171. }
  172. refresh();
  173. var doRefresh = function() {
  174. refresh();
  175. }
  176. report.scriptLinkClicked.connect(function(url) {
  177. var reminder = createWindow("editreminder");
  178. if(url != "0")
  179. {
  180. reminder.loadData(e[url]);
  181. }
  182. reminder.setRefreshFunction(doRefresh);
  183. });
  184. ]]>
  185. </program>
  186. </window>