');
output.writeStartElement("html");
output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
output.writeStartElement("head");
output.writeTextElement("title", TTR("batchDetails", "Batch Details"));
output.writeEndElement();
output.writeStartElement("body");
output.writeStartElement("div");
output.writeAttribute("style", "float: left; padding-right: 10px");
output.writeStartElement("p");
output.writeTextElement("strong", TTR("batchDetails", "Roasted Coffee: "));
output.writeTextElement("span", table.data(row, 2));
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("div");
output.writeAttribute("style", "float: left");
output.writeStartElement("p");
output.writeTextElement("strong", TTR("batchDetails", "Roasted On: "));
batchTime = table.data(row, 0);
output.writeTextElement("span", batchTime);
output.writeEndElement();
output.writeStartElement("p");
output.writeTextElement("strong", TTR("batchDetails", "Batch Duration: "));
output.writeTextElement("span", table.data(row, 6));
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("div");
output.writeAttribute("style", "clear: both");
output.writeEndElement();
output.writeStartElement("table");
output.writeStartElement("thead");
output.writeStartElement("tr");
output.writeTextElement("th", TTR("batchDetails", "Green Coffee"));
output.writeTextElement("th", TTR("batchDetails", "Weight (") + unitText + ")");
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tbody");
var query = new QSqlQuery();
query.prepare("SELECT unroasted_id, unroasted_quantity, approval, files, annotation, (unroasted_total_quantity/:c1)::numeric(12,3), (roasted_quantity/:c2)::numeric(12,3) FROM roasting_log WHERE time = :time AND machine = :machine");
query.bind(":time", batchTime);
query.bind(":c1", conversion);
query.bind(":c2", conversion);
machine = table.data(row, 1);
query.bind(":machine", machine);
query.exec();
query.next();
approval = query.value(2);
annotation = query.value(4);
var items = sqlToArray(query.value(0));
var quantities = sqlToArray(query.value(1));
var nameQuery = new QSqlQuery();
nameQuery.prepare("SELECT name FROM items WHERE id = :id");
for(var i = 0; i < items.length; i++) {
output.writeStartElement("tr");
nameQuery.bind(":id", items[i]);
nameQuery.exec();
nameQuery.next();
output.writeTextElement("td", nameQuery.value(0) + " (" + items[i] + ")");
output.writeStartElement("td");
output.writeAttribute("align", "center");
output.writeCharacters((Number(quantities[i])/conversion).toFixed(3));
output.writeEndElement();
output.writeEndElement();
}
nameQuery = nameQuery.invalidate();
output.writeEndElement();
output.writeStartElement("tfoot");
output.writeStartElement("tr");
output.writeStartElement("td");
output.writeAttribute("align", "right");
output.writeTextElement("strong", TTR("batchDetails", "Green Total:"));
output.writeEndElement();
output.writeStartElement("td");
output.writeAttribute("align", "center");
output.writeCharacters(query.value(5));
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tr");
output.writeStartElement("td");
output.writeAttribute("align", "right");
output.writeTextElement("strong", TTR("batchDetails", "Roasted Weight:"));
output.writeEndElement();
output.writeStartElement("td");
output.writeAttribute("align", "center");
output.writeCharacters(query.value(6));
roastWeight = query.value(6);
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tr");
output.writeStartElement("td");
output.writeAttribute("align", "right");
output.writeTextElement("strong", TTR("batchDetails", "Weight Loss:"));
output.writeEndElement();
output.writeStartElement("td");
output.writeAttribute("align", "center");
output.writeCharacters(table.data(row, 5));
output.writeCharacters("%");
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("p");
output.writeTextElement("strong", TTR("batchDetails", "Approved: "));
output.writeCharacters(approval);
output.writeEndElement();
output.writeStartElement("p");
output.writeTextElement("strong", TTR("batchDetails", "Files: "));
output.writeCharacters(query.value(3));
output.writeEndElement();
output.writeStartElement("p");
output.writeTextElement("strong", TTR("batchDetails", "Annotations:"));
var files = sqlToArray(query.value(3));
var annotations = annotationFromRecord(files[0]);
fileID = files[0];
var buffer2 = new QBuffer(""+annotations+"");
buffer2.open(1);
var colQuery = new XQuery;
colQuery.bind("profile", buffer2);
colQuery.setQuery('for $i in doc($profile)//tuple[1]/temperature/@series return (string($i), ";")');
var result = colQuery.exec();
buffer2.close();
var seriesHeaders = new Array();
seriesHeaders.push(TTR("batchDetails", "Time"));
var records = result.split(";");
for(var i = 0; i < records.length - 1; i++) {
seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
}
seriesHeaders.push(TTR("batchDetails", "Note"));
output.writeStartElement("table");
output.writeStartElement("thead");
output.writeStartElement("tr");
for(var i = 0; i < seriesHeaders.length; i++) {
output.writeTextElement("th", seriesHeaders[i]);
}
output.writeEndElement();
output.writeEndElement();
buffer2.open(1);
var rq = 'for $t in doc($profile) //tuple return (string($t/time), ";", ';
for(var i = 0; i < seriesHeaders.length - 2; i++) {
rq = rq + 'string($t/temperature[' + Number(i+1) + ']), ";", ';
}
rq = rq + 'string($t/annotation), "~")';
colQuery.setQuery(rq);
var annotationData = colQuery.exec();
colQuery = colQuery.invalidate();
buffer2.close();
output.writeStartElement("tbody");
var annotationRecords = annotationData.split("~");
for(var i = 0; i < annotationRecords.length - 1; i++) {
output.writeStartElement("tr");
var annotationRow = annotationRecords[i].split(";");
for(var j = 0; j < annotationRow.length; j++) {
output.writeStartElement("td");
output.writeAttribute("style", "border-left: 1px solid #000000");
if(j > 0) {
output.writeAttribute("align", "center");
}
if(j > 0 && j < annotationRow.length - 1) {
output.writeCharacters(Number(annotationRow[j].replace(/^\s+|\s+$/g,"")).toFixed(2));
}
else {
output.writeCharacters(annotationRow[j].replace(/^\s+|\s+$/g,""));
}
output.writeEndElement();
}
output.writeEndElement();
}
output.writeEndElement();
output.writeEndElement();
output.writeCharacters(annotation);
output.writeEndElement();
output.writeEndElement();
output.writeEndElement();
output.writeEndDocument();
dataView.setContent(buffer);
buffer.close();
query = query.invalidate();
edit.enabled = true;
};
var saveMenu = findChildObject(this, 'save');
saveMenu.triggered.connect(function() {
var filename = QFileDialog.getSaveFileName(window, TTR("batchDetails", "Save Log As..."), QSettings.value("script/lastDir", "") + "/");
if(filename != "") {
saveFileFromDatabase(fileID, filename);
}
});
]]>