salix/db/routines/vn/triggers/travel_afterUpdate.sql

32 lines
957 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travel_afterUpdate`
AFTER UPDATE ON `travel`
FOR EACH ROW
BEGIN
CALL stock.log_add('travel', NEW.id, OLD.id);
IF NOT(NEW.shipped <=> OLD.shipped) THEN
UPDATE entry
SET commission = entry_getCommission(travelFk, currencyFk,supplierFk)
WHERE travelFk = NEW.id;
END IF;
IF NOT (NEW.agencyModeFk <=> OLD.agencyModeFk) THEN
IF (SELECT hasWeightVolumetric FROM agencyMode WHERE id = NEW.agencyModeFk) THEN
CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck
SELECT b.id
FROM entry e
JOIN buy b ON b.entryFk = e.id
JOIN item i ON i.id = b.itemFk
WHERE e.travelFk = NEW.id;
CALL buy_checkItem();
END IF;
END IF;
IF (NOT(NEW.awbFk <=> OLD.awbFk)) AND NEW.awbFk IS NOT NULL AND NOT travel_hasUniqueAwb(NEW.id) THEN
CALL util.throw('The AWB is incorrect, there is a different AWB in the associated entries');
END IF;
END$$
DELIMITER ;