Browse Source

Update INSERTs and trigger functions to propagate Typica users

Neal Wilson 7 years ago
parent
commit
631f99e1ca

+ 7
- 5
config/Windows/greeninventory.xml View File

65
             button.clicked.connect(function() {
65
             button.clicked.connect(function() {
66
                 q = "INSERT INTO ";
66
                 q = "INSERT INTO ";
67
                 q += (types.currentIndex == 0 ?
67
                 q += (types.currentIndex == 0 ?
68
-                    "inventory (time, item, quantity)" :
69
-                    "loss (time, item, quantity, reason)");
68
+                    "inventory (time, item, quantity, person)" :
69
+                    "loss (time, item, quantity, reason, person)");
70
                 q += " VALUES ('now', ";
70
                 q += " VALUES ('now', ";
71
                 q = q + items.currentData();
71
                 q = q + items.currentData();
72
                 q = q + ", ";
72
                 q = q + ", ";
82
                     q = q + ")";
82
                     q = q + ")";
83
                 }
83
                 }
84
                 q += (types.currentIndex == 0 ?
84
                 q += (types.currentIndex == 0 ?
85
-                    ")" :
86
-                    ", '" + reason.text + "')");
85
+                    ", :user)" :
86
+                    ", '" + reason.text + "', :user)");
87
                 query = new QSqlQuery();
87
                 query = new QSqlQuery();
88
-                query.exec(q);
88
+                query.prepare(q);
89
+				query.bind(":user", Application.currentTypicaUser());
90
+				query.exec();
89
                 updateStatus();
91
                 updateStatus();
90
             });
92
             });
91
             items['currentIndexChanged(int)'].connect(updateStatus);
93
             items['currentIndexChanged(int)'].connect(updateStatus);

+ 2
- 1
config/Windows/greensales.xml View File

53
 			var submit = findChildObject(this, 'submit');
53
 			var submit = findChildObject(this, 'submit');
54
 			submit.clicked.connect(function() {
54
 			submit.clicked.connect(function() {
55
 				var query = new QSqlQuery();
55
 				var query = new QSqlQuery();
56
-				query.prepare("INSERT INTO sale (time, item, quantity, customer) VALUES(:time, :item, :quantity, :customer)");
56
+				query.prepare("INSERT INTO sale (time, item, quantity, customer, person) VALUES(:time, :item, :quantity, :customer, :user)");
57
 				query.bind(":time", dateField.text);
57
 				query.bind(":time", dateField.text);
58
 				if(customerField.text == "") {
58
 				if(customerField.text == "") {
59
 					query.bind(":customer", null);
59
 					query.bind(":customer", null);
62
 					query.bind(":customer", customerField.text);
62
 					query.bind(":customer", customerField.text);
63
 				}
63
 				}
64
 				var coffeesArray = sqlToArray(items.columnArray(0, 32));
64
 				var coffeesArray = sqlToArray(items.columnArray(0, 32));
65
+				query.bind(":user", Application.currentTypicaUser());
65
 				if(coffeesArray.length > 0)
66
 				if(coffeesArray.length > 0)
66
 				{
67
 				{
67
 					for(var i = 0; i < coffeesArray.length; i++)
68
 					for(var i = 0; i < coffeesArray.length; i++)

+ 5
- 3
config/Windows/manuallogentry.xml View File

405
 				query.exec();
405
 				query.exec();
406
 				query.next();
406
 				query.next();
407
 				var roastedId = query.value(0);
407
 				var roastedId = query.value(0);
408
-				query.prepare("INSERT INTO roasting_log (time, unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, machine, duration, approval, humidity, barometric, indoor_air, outdoor_air, files) VALUES (:time, :unroastedids, :greens, :green, :roastedid, :roasted, 'SAMPLEROAST', :note, :machine, :duration, TRUE, NULL, NULL, NULL, NULL, :files)");
408
+				query.prepare("INSERT INTO roasting_log (time, unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, machine, duration, approval, humidity, barometric, indoor_air, outdoor_air, files, person) VALUES (:time, :unroastedids, :greens, :green, :roastedid, :roasted, 'SAMPLEROAST', :note, :machine, :duration, TRUE, NULL, NULL, NULL, NULL, :files, :user)");
409
 				query.bind(":time", roastTime.text);
409
 				query.bind(":time", roastTime.text);
410
 				query.bind(":unroastedids", "{" + greenId + "}");
410
 				query.bind(":unroastedids", "{" + greenId + "}");
411
 				query.bind(":greens", "{" + convertToPounds(parseFloat(sampleGreenWeight.text), sampleGreenUnit.currentText) + "}");
411
 				query.bind(":greens", "{" + convertToPounds(parseFloat(sampleGreenWeight.text), sampleGreenUnit.currentText) + "}");
416
 				query.bind(":machine", Number(selectedRoasterID));
416
 				query.bind(":machine", Number(selectedRoasterID));
417
 				query.bind(":duration", roastDuration.text);
417
 				query.bind(":duration", roastDuration.text);
418
 				query.bind(":files", "{" + fileID + "}");
418
 				query.bind(":files", "{" + fileID + "}");
419
+				query.bind(":user", Application.currentTypicaUser());
419
 				query.exec();
420
 				query.exec();
420
 			} else {
421
 			} else {
421
-				var q = "INSERT INTO roasting_log (time, unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, machine, duration, approval, humidity, barometric, indoor_air, outdoor_air, files) VALUES (:time, ";
422
+				var q = "INSERT INTO roasting_log (time, unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, machine, duration, approval, humidity, barometric, indoor_air, outdoor_air, files, person) VALUES (:time, ";
422
 				q += productionGreenTable.columnArray(0, 32);
423
 				q += productionGreenTable.columnArray(0, 32);
423
 				q += ", ";
424
 				q += ", ";
424
 				for(var i = 0; i < productionGreenTable.data(i, 1, 0).value != ""; i++) {
425
 				for(var i = 0; i < productionGreenTable.data(i, 1, 0).value != ""; i++) {
433
 				q += selectedRoasterID;
434
 				q += selectedRoasterID;
434
 				q += ", :duration, TRUE, NULL, NULL, NULL, NULL, '{";
435
 				q += ", :duration, TRUE, NULL, NULL, NULL, NULL, '{";
435
 				q += fileID;
436
 				q += fileID;
436
-				q += "}')";
437
+				q += "}', :user)";
437
 				query.prepare(q);
438
 				query.prepare(q);
438
 				query.bind(":time", roastTime.text);
439
 				query.bind(":time", roastTime.text);
439
 				query.bind(":annotation", notes.plainText);
440
 				query.bind(":annotation", notes.plainText);
440
 				query.bind(":duration", roastDuration.text);
441
 				query.bind(":duration", roastDuration.text);
442
+				query.bind(":user", Application.currentTypicaUser());
441
 				query.exec();
443
 				query.exec();
442
 			}
444
 			}
443
 			query = query.invalidate();
445
 			query = query.invalidate();

+ 2
- 2
config/Windows/navigation.xml View File

285
 		/* Update trigger functions to make column names explicit */
285
 		/* Update trigger functions to make column names explicit */
286
 		var DBUpdateTriggers = function() {
286
 		var DBUpdateTriggers = function() {
287
 			var query = new QSqlQuery;
287
 			var query = new QSqlQuery;
288
-			query.exec("CREATE OR REPLACE FUNCTION log_make() RETURNS trigger AS $$ BEGIN IF NEW.roasted_quantity IS NOT NULL THEN INSERT INTO make (time, item, quantity) VALUES(NEW.time, NEW.roasted_id, NEW.roasted_quantity); END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
289
 			query.exec("CREATE OR REPLACE FUNCTION log_make_update() RETURNS trigger AS $$ BEGIN IF NEW.roasted_quantity <> OLD.roasted_quantity AND NEW.roasted_quantity IS NOT NULL THEN INSERT INTO make (time, item, quantity) VALUES(NEW.time, NEW.roasted_id, NEW.roasted_quantity); END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
288
 			query.exec("CREATE OR REPLACE FUNCTION log_make_update() RETURNS trigger AS $$ BEGIN IF NEW.roasted_quantity <> OLD.roasted_quantity AND NEW.roasted_quantity IS NOT NULL THEN INSERT INTO make (time, item, quantity) VALUES(NEW.time, NEW.roasted_id, NEW.roasted_quantity); END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
290
-			query.exec("CREATE OR REPLACE FUNCTION log_use() RETURNS trigger AS $$ DECLARE i integer := array_lower(NEW.unroasted_id, 1); u integer := array_upper(NEW.unroasted_id, 1); BEGIN IF NEW.transaction_type = 'ROAST' THEN WHILE i <= u LOOP INSERT INTO use (time, item, quantity) VALUES(NEW.time, NEW.unroasted_id[i], NEW.unroasted_quantity[i]); i := i + 1; END LOOP; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
291
 			query.exec("UPDATE TypicaFeatures SET version = 4 WHERE feature = 'base-features'");
289
 			query.exec("UPDATE TypicaFeatures SET version = 4 WHERE feature = 'base-features'");
292
 		};
290
 		};
293
         var DBUpdateReminders = function() {
291
         var DBUpdateReminders = function() {
310
 			query.exec("CREATE TABLE IF NOT EXISTS typica_users(name TEXT PRIMARY KEY NOT NULL, password TEXT, active boolean NOT NULL, auto_login boolean NOT NULL)");
308
 			query.exec("CREATE TABLE IF NOT EXISTS typica_users(name TEXT PRIMARY KEY NOT NULL, password TEXT, active boolean NOT NULL, auto_login boolean NOT NULL)");
311
 			/* Update session user logging to only use the database user when a Typica user is not explicitly provided. This maintains compatibility for mixed version use. */
309
 			/* Update session user logging to only use the database user when a Typica user is not explicitly provided. This maintains compatibility for mixed version use. */
312
 			query.exec("CREATE OR REPLACE FUNCTION log_session_user() RETURNS trigger AS $$ BEGIN IF NEW.person IS NULL THEN NEW.person := session_user; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
310
 			query.exec("CREATE OR REPLACE FUNCTION log_session_user() RETURNS trigger AS $$ BEGIN IF NEW.person IS NULL THEN NEW.person := session_user; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
311
+			query.exec("CREATE OR REPLACE FUNCTION log_use() RETURNS trigger AS $$ DECLARE i integer := array_lower(NEW.unroasted_id, 1); u integer := array_upper(NEW.unroasted_id, 1); BEGIN IF NEW.transaction_type = 'ROAST' THEN WHILE i <= u LOOP INSERT INTO use (time, item, quantity, person) VALUES(NEW.time, NEW.unroasted_id[i], NEW.unroasted_quantity[i], NEW.person); i := i + 1; END LOOP; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
312
+			query.exec("CREATE OR REPLACE FUNCTION log_make() RETURNS trigger AS $$ BEGIN IF NEW.roasted_quantity IS NOT NULL THEN INSERT INTO make (time, item, quantity, person) VALUES(NEW.time, NEW.roasted_id, NEW.roasted_quantity, NEW.person); END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
313
 			
313
 			
314
 			/* Uncomment before release */
314
 			/* Uncomment before release */
315
 			// query.exec("UPDATE TypicaFeatures SET version = 7 WHERE feature = 'base-features'");
315
 			// query.exec("UPDATE TypicaFeatures SET version = 7 WHERE feature = 'base-features'");

+ 3
- 2
config/Windows/newbatch.xml View File

585
                 checkQuery = checkQuery.invalidate();
585
                 checkQuery = checkQuery.invalidate();
586
                 query = new QSqlQuery();
586
                 query = new QSqlQuery();
587
                 var fileno = Number(filenofield.text);
587
                 var fileno = Number(filenofield.text);
588
-                var q2 = "INSERT INTO roasting_log (time, unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, machine, duration, approval, humidity, barometric, indoor_air, outdoor_air, files) VALUES(:time, ";
588
+                var q2 = "INSERT INTO roasting_log (time, unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, machine, duration, approval, humidity, barometric, indoor_air, outdoor_air, files, person) VALUES(:time, ";
589
                 q2 = q2 + table.columnArray(0, 32);
589
                 q2 = q2 + table.columnArray(0, 32);
590
                 q2 = q2 + ", ";
590
                 q2 = q2 + ", ";
591
                 for(var i = 0; table.data(i, 1, 0).value != ""; i++)
591
                 for(var i = 0; table.data(i, 1, 0).value != ""; i++)
603
                 q2 = q2 + selectedRoasterID;
603
                 q2 = q2 + selectedRoasterID;
604
                 q2 = q2 + ", :duration, :approval, NULL, NULL, NULL, NULL, '{";
604
                 q2 = q2 + ", :duration, :approval, NULL, NULL, NULL, NULL, '{";
605
                 q2 = q2 + fileno;
605
                 q2 = q2 + fileno;
606
-                q2 = q2 + "}') RETURNING time";
606
+                q2 = q2 + "}', :user) RETURNING time";
607
                 query2 = new QSqlQuery();
607
                 query2 = new QSqlQuery();
608
                 query2.prepare(q2);
608
                 query2.prepare(q2);
609
                 query2.bind(":time", timefield.text);
609
                 query2.bind(":time", timefield.text);
610
                 query2.bind(":annotation", notes.plainText);
610
                 query2.bind(":annotation", notes.plainText);
611
                 query2.bind(":duration", duration.text);
611
                 query2.bind(":duration", duration.text);
612
                 query2.bind(":approval", approval.checked);
612
                 query2.bind(":approval", approval.checked);
613
+				query2.bind(":user", Application.currentTypicaUser());
613
                 query2.exec();
614
                 query2.exec();
614
                 if(!query2.next()) {
615
                 if(!query2.next()) {
615
                     displayError(TTR("batchWindow", "Database Insert Failed"), TTR("batchWindow", "Failed to save batch to database. Please check inputs and connection and try again."));
616
                     displayError(TTR("batchWindow", "Database Insert Failed"), TTR("batchWindow", "Failed to save batch to database. Please check inputs and connection and try again."));

+ 2
- 1
config/Windows/newsamplebatch.xml View File

347
 				query.exec();
347
 				query.exec();
348
 				query.next();
348
 				query.next();
349
 				var roastedId = query.value(0);
349
 				var roastedId = query.value(0);
350
-				query.prepare("INSERT INTO roasting_log (time, unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, machine, duration, approval, humidity, barometric, indoor_air, outdoor_air, files) VALUES(:time, :unroastedids, :greens, :green, :roastedid, :roasted, 'SAMPLEROAST', :note, :machine, :duration, TRUE, NULL, NULL, NULL, NULL, :files)");
350
+				query.prepare("INSERT INTO roasting_log (time, unroasted_id, unroasted_quantity, unroasted_total_quantity, roasted_id, roasted_quantity, transaction_type, annotation, machine, duration, approval, humidity, barometric, indoor_air, outdoor_air, files, person) VALUES(:time, :unroastedids, :greens, :green, :roastedid, :roasted, 'SAMPLEROAST', :note, :machine, :duration, TRUE, NULL, NULL, NULL, NULL, :files, :user)");
351
 				query.bind(":time", timefield.text);
351
 				query.bind(":time", timefield.text);
352
 				query.bind(":unroastedids", "{" + greenId + "}");
352
 				query.bind(":unroastedids", "{" + greenId + "}");
353
                                 query.bind(":greens", "{" + convertToPounds(parseFloat(green.text), GunitBox.currentText) + "}");
353
                                 query.bind(":greens", "{" + convertToPounds(parseFloat(green.text), GunitBox.currentText) + "}");
358
 				query.bind(":machine", Number(selectedRoasterID));
358
 				query.bind(":machine", Number(selectedRoasterID));
359
 				query.bind(":duration", duration.text);
359
 				query.bind(":duration", duration.text);
360
 				query.bind(":files", "{" + fileno + "}");
360
 				query.bind(":files", "{" + fileno + "}");
361
+				query.bind(":user", Application.currentTypicaUser());
361
 				query.exec();
362
 				query.exec();
362
 				query = query.invalidate();
363
 				query = query.invalidate();
363
 				batch.close();
364
 				batch.close();

+ 2
- 1
config/Windows/purchase.xml View File

317
                     query.exec();
317
                     query.exec();
318
                     query.next();
318
                     query.next();
319
                     var item_id = query.value(0);
319
                     var item_id = query.value(0);
320
-                    q = "INSERT INTO purchase (time, item, quantity, cost, vendor) VALUES(:time, :item, :quantity, :cost, :vendor)";
320
+                    q = "INSERT INTO purchase (time, item, quantity, cost, vendor, person) VALUES(:time, :item, :quantity, :cost, :vendor, :user)";
321
                     query.prepare(q);
321
                     query.prepare(q);
322
                     query.bind(":time", dateField.date);
322
                     query.bind(":time", dateField.date);
323
                     query.bind(":item", item_id);
323
                     query.bind(":item", item_id);
332
                         query.bind(":cost", Number(costEntry.text) / convertToPounds(parseFloat(quantityEntry.text), unitEntry.currentText));
332
                         query.bind(":cost", Number(costEntry.text) / convertToPounds(parseFloat(quantityEntry.text), unitEntry.currentText));
333
                     }
333
                     }
334
                     query.bind(":vendor", vendorField.currentText);
334
                     query.bind(":vendor", vendorField.currentText);
335
+					query.bind(":user", Application.currentTypicaUser());
335
                     query.exec();
336
                     query.exec();
336
                     q = "INSERT INTO lb_bag_conversion (item, conversion) VALUES(:item, :conversion)";
337
                     q = "INSERT INTO lb_bag_conversion (item, conversion) VALUES(:item, :conversion)";
337
                     query.prepare(q);
338
                     query.prepare(q);

Loading…
Cancel
Save