Browse Source

Allow roasted weight to be edited from batch log

Neal Wilson 9 years ago
parent
commit
17e80f9027

+ 2
- 1
config/Reports/historyreport.xml View File

@@ -91,7 +91,7 @@
91 91
                     conversion = 2.2;
92 92
                 }
93 93
                 var query = new QSqlQuery();
94
-                var q = "SELECT to_char(time, 'Dy Mon DD YYYY HH24:MI:SS'), machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity / " + conversion + " AS green, roasted_quantity  / " + conversion + " AS roasted, CASE WHEN unroasted_total_quantity = 0 THEN NULL ELSE ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) END AS weight_loss, duration, annotation FROM roasting_log WHERE machine = :machine AND time = :time";
94
+                var q = "SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity / " + conversion + " AS green, roasted_quantity  / " + conversion + " AS roasted, CASE WHEN unroasted_total_quantity = 0 THEN NULL ELSE ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) END AS weight_loss, duration, annotation FROM roasting_log WHERE machine = :machine AND time = :time";
95 95
                 query.prepare(q);
96 96
                 query.bind(":machine", key[0]);
97 97
                 query.bind(":time", key[1]);
@@ -101,6 +101,7 @@
101 101
                     print("Constructing row with " + query.value(i));
102 102
                     fakeTable.holding[i] = query.value(i);
103 103
                 }
104
+                fakeTable.holding[0] = key[1];
104 105
                 query = query.invalidate();
105 106
                 details.loadData(fakeTable, 0);
106 107
             });

+ 3
- 1
config/Windows/batchdetailsnew.xml View File

@@ -42,9 +42,10 @@
42 42
             var machine;
43 43
             var approval;
44 44
             var annotation;
45
+            var roastWeight;
45 46
             edit.clicked.connect(function() {
46 47
                 var editWindow = createWindow("editBatchDetails");
47
-                editWindow.loadData(window, tableReference, rowReference, batchTime, machine, approval, annotation);
48
+                editWindow.loadData(window, tableReference, rowReference, batchTime, machine, approval, annotation, roastWeight, unit);
48 49
             });
49 50
             compare.clicked.connect(function() {
50 51
                 var query = new QSqlQuery;
@@ -255,6 +256,7 @@
255 256
                 output.writeStartElement("td");
256 257
                 output.writeAttribute("align", "center");
257 258
                 output.writeCharacters(query.value(6));
259
+                roastWeight = query.value(6);
258 260
                 output.writeEndElement();
259 261
                 output.writeEndElement();
260 262
                 output.writeStartElement("tr");

+ 56
- 40
config/Windows/editbatchdetails.xml View File

@@ -1,47 +1,63 @@
1 1
 <window id="editBatchDetails">
2 2
     <layout type="vertical">
3
-		<button type="check" name="Approved" id="approval" />
4
-		<layout type="horizontal">
5
-			<label>Annotation</label>
6
-			<textarea id="annotation" />
7
-		</layout>
8
-		<button type="push" id="submit" name="Submit" />
9
-	</layout>
3
+        <layout type="horizontal">
4
+            <label>Roasted Weight: </label>
5
+            <line id="roasted" validator="numeric" />
6
+            <line id="roastunit" writable="false" />
7
+        </layout>
8
+        <button type="check" name="Approved" id="approval" />
9
+        <layout type="horizontal">
10
+            <label>Annotation</label>
11
+            <textarea id="annotation" />
12
+        </layout>
13
+        <button type="push" id="submit" name="Submit" />
14
+    </layout>
10 15
     <program>
11 16
         <![CDATA[
12
-			var window = this;
13
-			var approvalButton = findChildObject(this, 'approval');
14
-			var annotationField = findChildObject(this, 'annotation');
15
-			var parentWindow;
16
-			var tableReference;
17
-			var rowReference;
18
-			var timeKey;
19
-			var machineKey;
20
-			var submit = findChildObject(this, 'submit');
21
-			submit.enabled = false;
22
-			this.loadData = function(parent, table, row, time, machine, approval, annotation) {
23
-				parentWindow = parent;
24
-				tableReference = table;
25
-				rowReference = row;
26
-				if(approval == "true") {
27
-					approvalButton.checked = true;
28
-				}
29
-				annotationField.plainText = annotation;
30
-				timeKey = time;
31
-				machineKey = machine;
32
-				submit.enabled = true;
33
-			};
34
-			submit.clicked.connect(function() {
35
-				var query = new QSqlQuery;
36
-				query.prepare("UPDATE roasting_log SET approval = :approval, annotation = :annotation WHERE time = :time AND machine = :machine");
37
-				query.bind("approval", approvalButton.checked);
38
-				query.bind("annotation", annotationField.plainText);
39
-				query.bind("time", timeKey);
40
-				query.bind("machine", machineKey);
41
-				query.exec();
42
-				parentWindow.loadData(tableReference, rowReference);
43
-				window.close();
44
-			});
17
+            var window = this;
18
+            var approvalButton = findChildObject(this, 'approval');
19
+            var annotationField = findChildObject(this, 'annotation');
20
+            var parentWindow;
21
+            var tableReference;
22
+            var rowReference;
23
+            var timeKey;
24
+            var machineKey;
25
+            var submit = findChildObject(this, 'submit');
26
+            submit.enabled = false;
27
+            var roastedEdit = findChildObject(this, 'roasted');
28
+            var unitEdit = findChildObject(this, 'roastunit');
29
+            var conversion = 1;
30
+            this.loadData = function(parent, table, row, time, machine, approval, annotation, roastWeight, unit) {
31
+                parentWindow = parent;
32
+                tableReference = table;
33
+                rowReference = row;
34
+                if(approval == "true") {
35
+                    approvalButton.checked = true;
36
+                }
37
+                annotationField.plainText = annotation;
38
+                timeKey = time;
39
+                machineKey = machine;
40
+                submit.enabled = true;
41
+                roastedEdit.text = roastWeight;
42
+                if(unit == 0) {
43
+                    unitEdit.text = "Kg";
44
+                    conversion = 2.2;
45
+                } else {
46
+                    unitEdit.text = "Lb";
47
+                }
48
+            };
49
+            submit.clicked.connect(function() {
50
+                var query = new QSqlQuery;
51
+                query.prepare("UPDATE roasting_log SET roasted_quantity = :roasted, approval = :approval, annotation = :annotation WHERE time = :time AND machine = :machine");
52
+                query.bind(":approval", approvalButton.checked);
53
+                query.bind(":annotation", annotationField.plainText);
54
+                query.bind(":roasted", Number(roastedEdit.text)/conversion);
55
+                query.bind(":time", timeKey);
56
+                query.bind(":machine", Number(machineKey));
57
+                query.exec();
58
+                parentWindow.loadData(tableReference, rowReference);
59
+                window.close();
60
+            });
45 61
         ]]>
46 62
     </program>
47 63
 </window>

Loading…
Cancel
Save