Browse Source

Add batch tag functionality to batch details window

Neal Wilson 6 years ago
parent
commit
8ae8f26867
1 changed files with 65 additions and 2 deletions
  1. 65
    2
      config/Windows/batchdetailsnew.xml

+ 65
- 2
config/Windows/batchdetailsnew.xml View File

@@ -56,7 +56,11 @@
56 56
             </page>
57 57
             <page>
58 58
                 <layout type="vertical">
59
-                    
59
+                    <webview id="batchTag" />
60
+                    <layout type="horizontal">
61
+                        <printerselector id="printerlist" />
62
+                        <button name="Print" id="printbutton" type="push" />
63
+                    </layout>
60 64
                 </layout>
61 65
             </page>
62 66
         </layout>
@@ -224,7 +228,7 @@
224 228
                 machine = mref;
225 229
                 batchTime = tref;
226 230
                 var query = new QSqlQuery();
227
-                var q = "WITH names AS ( WITH greens AS ( SELECT unnest(unroasted_id) AS gitem, machine, time FROM roasting_log WHERE machine = :machine AND time = :time) SELECT array_agg((SELECT name FROM items WHERE id = greens.gitem) || ' (' || gitem || ')') AS names, max(greens.machine) AS machine, max(greens.time) AS time FROM greens LIMIT 1) SELECT (SELECT name FROM items WHERE id = roasted_id), duration, names, unroasted_quantity, (unroasted_total_quantity/:c1)::numeric(12,3), (roasted_quantity/:c2)::numeric(12,3), approval, files, annotation, (SELECT file FROM files WHERE id = files[1]) AS file, additional_data FROM names, roasting_log WHERE roasting_log.machine = names.machine AND roasting_log.time = names.time";
231
+                var q = "WITH names AS ( WITH greens AS ( SELECT unnest(unroasted_id) AS gitem, machine, time FROM roasting_log WHERE machine = :machine AND time = :time) SELECT array_agg((SELECT name FROM items WHERE id = greens.gitem) || ' (' || gitem || ')') AS names, max(greens.machine) AS machine, max(greens.time) AS time FROM greens LIMIT 1) SELECT (SELECT name FROM items WHERE id = roasted_id), duration, names, unroasted_quantity, (unroasted_total_quantity/:c1)::numeric(12,3), (roasted_quantity/:c2)::numeric(12,3), approval, files, annotation, (SELECT file FROM files WHERE id = files[1]) AS file, additional_data, roasted_id FROM names, roasting_log WHERE roasting_log.machine = names.machine AND roasting_log.time = names.time";
228 232
                 query.prepare(q);
229 233
                 query.bind(":machine", mref);
230 234
                 query.bind(":time", tref);
@@ -459,6 +463,7 @@
459 463
                 annotationField.plainText = query.value(8);
460 464
                 unitEdit.text = unitText;
461 465
                 roastedEdit.text = query.value(5);
466
+                drawTag(query.value(11), query.value(0));
462 467
                 query = query.invalidate();
463 468
             }
464 469
             var saveMenu = findChildObject(this, 'save');
@@ -494,6 +499,64 @@
494 499
                 displayInfo(TTR("batchDetails", "Batch Data Saved"),
495 500
                             TTR("roastspec", "New batch details saved"));
496 501
             });
502
+            var batchTag = findChildObject(this, 'batchTag');
503
+            var printers = findChildObject(this, 'printerlist');
504
+            printers.currentIndex = printers.findText(QSettings.value("script/batchtagprinter"));
505
+            printers['currentIndexChanged(int)'].connect(function() {
506
+                QSettings.setValue("script/batchtagprinter", printers.currentText);
507
+            });
508
+            var printbutton = findChildObject(this, 'printbutton');
509
+            printbutton.clicked.connect(function() {
510
+                batchTag.print(printers.currentText);
511
+            });
512
+            function drawTag(item, name) {
513
+                var buffer = new QBuffer;
514
+                buffer.open(3);
515
+                var output = new XmlWriter(buffer);
516
+                output.writeStartDocument("1.0");
517
+                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">');
518
+                output.writeStartElement("html");
519
+                output.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
520
+                output.writeStartElement("head");
521
+                var styleFile = new QFile(QSettings.value("config") + "/Scripts/batchtag.css");
522
+                styleFile.open(1);
523
+                output.writeTextElement("style", styleFile.readToString());
524
+                styleFile.close();
525
+                output.writeStartElement("script");
526
+                scriptFile = new QFile(QSettings.value("config") + "/Scripts/qrcode.js");
527
+                scriptFile.open(1);
528
+                output.writeCDATA(scriptFile.readToString());
529
+                scriptFile.close();
530
+                output.writeEndElement();
531
+                output.writeEndElement();
532
+                output.writeStartElement("body");
533
+                output.writeStartElement("h1");
534
+                output.writeCharacters(name + " (" + item + ")");
535
+                output.writeEndElement();
536
+                output.writeTextElement("span", "Roasted at: " + batchTime);
537
+                output.writeTextElement("span", "On machine: " + machine);
538
+                output.writeTextElement("span", "Batch file: " + fileID);
539
+                output.writeStartElement("div");
540
+                output.writeAttribute("id", "container");
541
+                output.writeEndElement();
542
+                output.writeStartElement("script");
543
+                var tag = {g: "Typica", m: Number(machine), v: 1};
544
+                tag.t = batchTime;
545
+                tag.f = Number(fileID);
546
+                var scriptData = 'var width = document.getElementById("container").offsetWidth;';
547
+                scriptData += 'var qrcode = new QRCode({content: \'';
548
+                scriptData += JSON.stringify(tag);
549
+                scriptData += '\', width: width, height: width});';
550
+                scriptData += 'var svg = qrcode.svg();';
551
+                scriptData += 'document.getElementById("container").innerHTML = svg;';
552
+                output.writeCDATA(scriptData);
553
+                output.writeEndElement();
554
+                output.writeEndElement();
555
+                output.writeEndElement();
556
+                output.writeEndDocument();
557
+                batchTag.setContent(buffer);
558
+                buffer.close();
559
+            };
497 560
         ]]>
498 561
     </program>
499 562
 </window>

Loading…
Cancel
Save