Browse Source

Use new interface for loading batch data in batch details window

Neal Wilson 6 years ago
parent
commit
bb2488ecd2
2 changed files with 12 additions and 34 deletions
  1. 6
    17
      config/Reports/dailyproductiondetail.xml
  2. 6
    17
      config/Reports/itemtransactions.xml

+ 6
- 17
config/Reports/dailyproductiondetail.xml View File

@@ -58,7 +58,7 @@
58 58
 				output.writeTextElement("h1", TTR("dailyproduction", "Daily Production Report: ") + dateString);
59 59
 				output.writeTextElement("h2", TTR("dailyproduction", "Batches Roasted"));
60 60
 				var query = new QSqlQuery();
61
-				var q = "SELECT time, machine, (SELECT name FROM machine WHERE id = machine), (SELECT name FROM items WHERE id = roasted_id), unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, annotation, duration, files, (SELECT loss FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), (SELECT tolerance FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), (SELECT notes FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), approval FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1') ORDER BY time";
61
+				var q = "SELECT time, machine, (SELECT name FROM machine WHERE id = machine), (SELECT name FROM items WHERE id = roasted_id), unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, annotation, duration, files, (SELECT loss FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), (SELECT tolerance FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), (SELECT notes FROM roasting_specification WHERE item = roasted_id AND time = (SELECT max(time) FROM roasting_specification WHERE time <= roasting_log.time AND item = roasted_id)), approval, machine || '@' || time AS link FROM roasting_log WHERE time > '" + dateString + "' AND time < ('" + dateString + "'::date + integer '1') ORDER BY time";
62 62
 				query.exec(q);
63 63
 				var times = new Array();
64 64
 				var machines = new Array();
@@ -106,7 +106,7 @@
106 106
 					output.writeTextElement("td", query.value(2));
107 107
 					output.writeStartElement("td");
108 108
 					output.writeStartElement("a");
109
-					output.writeAttribute("href", "typica://script/p" + query.value(11).slice(1,-1));
109
+					output.writeAttribute("href", "typica://script/b/" + query.value(16));
110 110
 					output.writeCDATA(query.value(11));
111 111
 					output.writeEndElement();
112 112
 					output.writeEndElement();
@@ -475,21 +475,10 @@
475 475
             });
476 476
 			
477 477
 			view.scriptLinkClicked.connect(function(url) {
478
-				var arg = url.slice(1, url.length);
479
-				var details = createWindow("batchDetails");
480
-				var fakeTable = new Object;
481
-				fakeTable.holding = new Array(7);
482
-				fakeTable.data = function(r, c) {
483
-					return this.holding[c];
484
-				};
485
-				var query = new QSqlQuery();
486
-				query.exec("SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity AS green, roasted_quantity AS roasted, ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) AS weight_loss, duration, annotation FROM roasting_log WHERE files = '{" + arg + "}'");
487
-				query.next();
488
-				for(var i = 0; i < 8; i++) {
489
-					fakeTable.holding[i] = query.value(i);
490
-				}
491
-				query = query.invalidate();
492
-				details.loadData(fakeTable, 0);
478
+                var arg = decodeURI(url.slice(2, url.length));
479
+                var key = arg.split("@");
480
+                var details = createWindow("batchDetails");
481
+                details.loadBatch(key[0], key[1]);
493 482
 			});
494 483
 		]]>
495 484
 	</program>

+ 6
- 17
config/Reports/itemtransactions.xml View File

@@ -224,7 +224,7 @@
224 224
                     }, 0));
225 225
                     output.writeEndElement();
226 226
                     output.writeEndElement();
227
-                    query.prepare("SELECT time::date, type, quantity / :c1, balance / :c2, (SELECT files FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id)), (SELECT invoice_id FROM invoice_items WHERE item = item_id AND item_history.type = 'PURCHASE'), (SELECT vendor || ' ' || invoice FROM invoices WHERE id = (SELECT invoice_id FROM invoice_items WHERE item = item_id AND item_history.type = 'PURCHASE')), (SELECT name FROM items WHERE id = (SELECT roasted_id FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id))), customer, reason, (SELECT person FROM transactions WHERE time = item_history.time AND item = item_history.item) FROM item_history(:item) WHERE time >= :sd AND time < :ed ::date + interval '1 day'");
227
+                    query.prepare("SELECT time::date, type, quantity / :c1, balance / :c2, (SELECT files FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id)), (SELECT invoice_id FROM invoice_items WHERE item = item_id AND item_history.type = 'PURCHASE'), (SELECT vendor || ' ' || invoice FROM invoices WHERE id = (SELECT invoice_id FROM invoice_items WHERE item = item_id AND item_history.type = 'PURCHASE')), (SELECT name FROM items WHERE id = (SELECT roasted_id FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id))), customer, reason, (SELECT person FROM transactions WHERE time = item_history.time AND item = item_history.item), (SELECT machine || '@' || time FROM roasting_log WHERE roasting_log.time = item_history.time AND item = ANY(unroasted_id)) AS link FROM item_history(:item) WHERE time >= :sd AND time < :ed ::date + interval '1 day'");
228 228
                     query.bind(":sd", startDate);
229 229
                     query.bind(":ed", endDate);
230 230
                     switch(unitBox.currentIndex)
@@ -289,7 +289,7 @@
289 289
                         } else if(query.value(1) == "USE") {
290 290
                             output.writeStartElement("td");
291 291
                             output.writeStartElement("a");
292
-                            output.writeAttribute("href", "typica://script/p" + query.value(4).slice(1,-1));
292
+                            output.writeAttribute("href", "typica://script/b/" + query.value(11));
293 293
                             output.writeCDATA(query.value(7) + " " + query.value(4));
294 294
                             output.writeEndElement();
295 295
                             output.writeEndElement();
@@ -345,21 +345,10 @@
345 345
             };
346 346
             /* Open batch data */
347 347
             var openProfile = function(url) {
348
-                var arg = url.slice(1, url.length);
348
+                var arg = decodeURI(url.slice(2, url.length));
349
+                var key = arg.split("@");
349 350
                 var details = createWindow("batchDetails");
350
-                var fakeTable = new Object;
351
-                fakeTable.holding = new Array(7);
352
-                fakeTable.data = function(r, c) {
353
-                    return this.holding[c];
354
-                };
355
-                var query = new QSqlQuery();
356
-                query.exec("SELECT time, machine, (SELECT name FROM items WHERE id = roasted_id) AS name, unroasted_total_quantity AS green, roasted_quantity AS roasted, ((unroasted_total_quantity - roasted_quantity) / unroasted_total_quantity * 100::numeric)::numeric(12,2) AS weight_loss, duration, annotation FROM roasting_log WHERE files = '{" + arg + "}'");
357
-                query.next();
358
-                for(var i = 0; i < 8; i++) {
359
-                    fakeTable.holding[i] = query.value(i);
360
-                }
361
-                query = query.invalidate();
362
-                details.loadData(fakeTable, 0);
351
+                details.loadBatch(key[0], key[1]);
363 352
             };
364 353
             view.scriptLinkClicked.connect(function(url) {
365 354
                 var linkType = url[0];
@@ -367,7 +356,7 @@
367 356
                     case 'i':
368 357
                         openInvoice(url);
369 358
                         break;
370
-                    case 'p':
359
+                    case 'b':
371 360
                         openProfile(url);
372 361
                         break;
373 362
                 }

Loading…
Cancel
Save