Production:->Reminders
:since");
dq.bind(":conversion", convert);
dq.bind(":since", start_time);
dq.exec();
dq.next();
var proportion;
var remain;
if(reminder.value == 0 || (reminder.value < Number(dq.value(0))))
{
proportion = 1;
}
else
{
proportion = Number(dq.value(0)) / reminder.value;
}
remain = (reminder.value - Number(dq.value(0))).toFixed(0);
reminder.completion = proportion;
reminder.detail = remain + unittext;
dq = dq.invalidate();
}
else if(reminder.condition == "DAYS")
{
var dq = new QSqlQuery;
dq.prepare("SELECT 'now'::date - :since::date");
dq.bind(":since", start_time);
dq.exec();
dq.next();
var proportion;
var remain;
if(reminder.value == 0 || (reminder.value < Number(dq.value(0))))
{
proportion = 1;
}
else
{
proportion = Number(dq.value(0)) / reminder.value;
}
remain = reminder.value - Number(dq.value(0));
reminder.completion = proportion;
reminder.detail = remain + TTR("remindersreport", " Days");
dq = dq.invalidate();
}
else if(reminder.condition == "PRODUCTIONBATCHES")
{
var dq = new QSqlQuery;
dq.prepare("SELECT count(1) FROM roasting_log WHERE time > :since");
dq.bind(":since", start_time);
dq.exec();
dq.next();
var proportion;
var remain;
if(reminder.value == 0 || (reminder.value < Number(dq.value(0))))
{
proportion = 1;
}
else
{
proportion = Number(dq.value(0)) / reminder.value;
}
remain = reminder.value - Number(dq.value(0));
reminder.completion = proportion;
reminder.detail = remain + TTR("remindersreport", " Batches");
dq = dq.invalidate();
}
else if(reminder.condition == "PRODUCTIONHOURS")
{
var dq = new QSqlQuery;
dq.prepare("SELECT extract(epoch FROM (SELECT sum(duration) FROM roasting_log WHERE time > :since) / 3600)");
dq.bind(":since", start_time);
dq.exec();
dq.next();
var proportion;
var remain;
if(reminder.value == 0 || (reminder.value < Number(dq.value(0))))
{
proportion = 1;
}
else
{
proportion = Number(dq.value(0)) / reminder.value;
}
remain = reminder.value - Number(dq.value(0));
reminder.completion = proportion;
reminder.detail = remain.toFixed(1) + TTR("remindersreport", " Hours");
dq = dq.invalidate();
}
e[reminder.dbid] = reminder;
}
query = query.invalidate();
}
function refresh() {
populateReminderData();
var passedData = e.filter(function(n){return n.hasOwnProperty("completion")}).sort(function(a,b){return b.completion-a.completion});
var buffer = new QBuffer;
buffer.open(3);
var output = new XmlWriter(buffer);
output.writeStartDocument("1.0");
output.writeDTD('');
output.writeStartElement("html");
output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
output.writeStartElement("head");
output.writeTextElement("title", TTR("remindersreport", "Reminders"));
output.writeEndElement();
output.writeStartElement("body");
var cdt = new Date(Date.now());
output.writeTextElement("p", cdt.toLocaleDateString(TTR("reports", "en-US")) + " " + cdt.toLocaleTimeString(TTR("reports", "en-US")));
output.writeTextElement("h1", TTR("remindersreport", "Reminders"));
output.writeStartElement("a");
output.writeAttribute("href", "typica://script/0");
output.writeStartElement("div");
output.writeAttribute("class", "reminder");
output.writeStartElement("div");
output.writeAttribute("class", "nocolor");
output.writeEndElement();
output.writeStartElement("span");
output.writeAttribute("class", "title");
output.writeCDATA(TTR("remindersreport", "New Reminder"));
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeTextElement("script", "e = " + JSON.stringify(passedData));
var styleFile = new QFile(QSettings.value("config") + "/Scripts/reminders.css");
styleFile.open(1);
output.writeTextElement("style", styleFile.readToString());
styleFile.close();
output.writeStartElement("script");
scriptFile = new QFile(QSettings.value("config") + "/Scripts/reminders.js");
scriptFile.open(1);
output.writeCDATA(scriptFile.readToString());
scriptFile.close();
output.writeEndElement();
output.writeEndElement();
output.writeEndDocument();
report.setContent(buffer);
buffer.close();
}
refresh();
var doRefresh = function() {
refresh();
}
var notifier = Application.subscribe("roastinglogchange");
notifier.notify.connect(function() {
refresh();
});
report.scriptLinkClicked.connect(function(url) {
var reminder = createWindow("editreminder");
if(url != "0")
{
reminder.loadData(e[url]);
}
reminder.setRefreshFunction(doRefresh);
});
]]>