salix/db/routines/stock/triggers/outbound_afterDelete.sql

23 lines
468 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `stock`.`outbound_afterDelete`
AFTER DELETE ON `outbound`
FOR EACH ROW
BEGIN
UPDATE inbound i
JOIN inboundPick ou ON ou.inboundFk = i.id
SET i.available = i.available + ou.quantity,
i.isSync = FALSE
WHERE ou.outboundFk = OLD.id;
DELETE FROM inboundPick
WHERE outboundFk = OLD.id;
CALL visible_log(
OLD.isPicked,
OLD.warehouseFk,
OLD.itemFk,
OLD.quantity
);
END$$
DELIMITER ;