');
output.writeStartElement("html");
output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
output.writeStartElement("head");
output.writeTextElement("title", "Batch Details");
output.writeEndElement();
output.writeStartElement("body");
output.writeStartElement("div");
output.writeAttribute("style", "float: left; padding-right: 10px");
output.writeStartElement("p");
output.writeTextElement("strong", "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", "Roasted On: ");
batchTime = table.data(row, 0);
output.writeTextElement("span", batchTime);
output.writeEndElement();
output.writeStartElement("p");
output.writeTextElement("strong", "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", "Green Coffee");
output.writeTextElement("th", "Weight (lb)");
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tbody");
var query = new QSqlQuery();
query.prepare("SELECT unroasted_id, unroasted_quantity, approval, files, annotation FROM roasting_log WHERE time = :time AND machine = :machine");
query.bind(":time", batchTime);
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));
output.writeStartElement("td");
output.writeAttribute("align", "center");
output.writeCharacters(quantities[i]);
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", "Green Total:");
output.writeEndElement();
output.writeStartElement("td");
output.writeAttribute("align", "center");
output.writeCharacters(table.data(row, 3));
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tr");
output.writeStartElement("td");
output.writeAttribute("align", "right");
output.writeTextElement("strong", "Roasted Weight:");
output.writeEndElement();
output.writeStartElement("td");
output.writeAttribute("align", "center");
output.writeCharacters(table.data(row, 4));
output.writeEndElement();
output.writeEndElement();
output.writeStartElement("tr");
output.writeStartElement("td");
output.writeAttribute("align", "right");
output.writeTextElement("strong", "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", "Approved: ");
output.writeCharacters(approval);
output.writeEndElement();
output.writeStartElement("p");
output.writeTextElement("strong", "Files: ");
output.writeCharacters(query.value(3));
output.writeEndElement();
output.writeStartElement("p");
output.writeTextElement("strong", "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("Time");
var records = result.split(";");
for(var i = 0; i < records.length - 1; i++) {
seriesHeaders.push(records[i].replace(/^\s+|\s+$/g,""));
}
seriesHeaders.push("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;
};
]]>