refs #5890 feat:trigger

This commit is contained in:
Sergio De la torre 2024-04-03 07:04:12 +02:00
parent 9698c049fc
commit 6db1696094
8 changed files with 33 additions and 70 deletions

View File

@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_ad
)
BEGIN
/**
* Guarda la ubicación para el contenido de una colección
* Reserva cantidades con ubicaciones para el contenido de una colección
*
* @param vCollectionFk Identificador de collection
*/

View File

@ -1,27 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_INSERT`
AFTER INSERT ON `itemShelving`
FOR EACH ROW
BEGIN
INSERT INTO vn.itemShelvingLog(
itemShelvingFk,
workerFk,
accion,
itemFk,
shelvingFk,
visible,
`grouping`,
packing,
available)
VALUES( NEW.id,
NEW.userFk,
'CREA REGISTRO',
NEW.itemFk,
NEW.shelvingFk,
NEW.visible,
NEW.`grouping`,
NEW.packing,
NEW.available);
END$$
DELIMITER ;

View File

@ -1,16 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_UPDATE`
AFTER UPDATE ON `itemShelving`
FOR EACH ROW
BEGIN
INSERT INTO itemShelvingLog
SET itemShelvingFk = NEW.id,
workerFk = account.myUser_getId(),
accion = 'CAMBIO',
itemFk = NEW.itemFk,
shelvingFk = NEW.shelvingFk,
visible = NEW.visible,
`grouping` = NEW.`grouping`,
packing = NEW.packing;
END$$
DELIMITER ;

View File

@ -1,10 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_BEFORE_INSERT`
BEFORE INSERT ON `itemShelving`
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();
SET NEW.userFk = account.myUser_getId();
SET NEW.available = NEW.visible;
END$$
DELIMITER ;

View File

@ -1,15 +1,19 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert`
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_INSERT`
AFTER INSERT ON `itemShelving`
FOR EACH ROW
INSERT INTO vn.itemShelvingLog( itemShelvingFk,
BEGIN
INSERT INTO vn.itemShelvingLog(
itemShelvingFk,
workerFk,
accion,
itemFk,
shelvingFk,
visible,
`grouping`,
packing)
packing,
available)
VALUES( NEW.id,
NEW.userFk,
'CREA REGISTRO',
@ -17,6 +21,7 @@ INSERT INTO vn.itemShelvingLog( itemShelvingFk,
NEW.shelvingFk,
NEW.visible,
NEW.`grouping`,
NEW.packing
)$$
NEW.packing,
NEW.available);
END$$
DELIMITER ;

View File

@ -1,8 +1,9 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterUpdate`
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_UPDATE`
AFTER UPDATE ON `itemShelving`
FOR EACH ROW
INSERT INTO itemShelvingLog
BEGIN
INSERT INTO itemShelvingLog
SET itemShelvingFk = NEW.id,
workerFk = account.myUser_getId(),
accion = 'CAMBIO',
@ -10,5 +11,8 @@ INSERT INTO itemShelvingLog
shelvingFk = NEW.shelvingFk,
visible = NEW.visible,
`grouping` = NEW.`grouping`,
packing = NEW.packing$$
packing = NEW.packing,
available = NEW.available;
END$$
DELIMITER ;

View File

@ -5,6 +5,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_beforeIn
BEGIN
SET NEW.editorFk = account.myUser_getId();
SET NEW.userFk = account.myUser_getId();
SET NEW.available = NEW.visible;
END$$
DELIMITER ;

View File

@ -3,9 +3,15 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_beforeUp
BEFORE UPDATE ON `itemShelving`
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();
IF NEW.userFk IS NULL THEN
SET NEW.userFk = account.myUser_getId();
END IF;
IF (NEW.visible <> OLD.visible) THEN
SET NEW.available = GREATEST(NEW.available + NEW.visible - OLD.visible, 0);
END IF;
END$$
DELIMITER ;