2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travel_beforeUpdate`
|
|
|
|
BEFORE UPDATE ON `travel`
|
|
|
|
FOR EACH ROW
|
|
|
|
BEGIN
|
2024-02-26 14:43:17 +00:00
|
|
|
DECLARE vHasAnyInvoiceBooked BOOL;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SET NEW.editorFk = account.myUser_getId();
|
2024-01-30 14:07:13 +00:00
|
|
|
|
2024-02-26 11:18:57 +00:00
|
|
|
IF NOT (NEW.landed <=> OLD.landed)
|
|
|
|
OR NOT (NEW.shipped <=> OLD.shipped) THEN
|
2024-01-15 11:31:03 +00:00
|
|
|
CALL travel_checkDates(NEW.shipped, NEW.landed);
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
IF NOT (NEW.isReceived <=> OLD.isReceived) THEN
|
|
|
|
CALL travel_checkPackaging(NEW.id);
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
IF NOT (NEW.warehouseInFk <=> OLD.warehouseInFk) THEN
|
|
|
|
CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk);
|
|
|
|
END IF;
|
2024-02-26 14:43:17 +00:00
|
|
|
|
|
|
|
IF NOT (NEW.awbFk <=> OLD.awbFk)THEN
|
|
|
|
SELECT COUNT(*) INTO vHasAnyInvoiceBooked
|
|
|
|
FROM travel t
|
|
|
|
JOIN entry e ON e.travelFk = t.id
|
|
|
|
JOIN invoiceIn ii ON ii.id = e.invoiceInFk
|
|
|
|
WHERE t.id = NEW.id
|
|
|
|
AND ii.isBooked;
|
|
|
|
|
|
|
|
IF vHasAnyInvoiceBooked THEN
|
|
|
|
CALL util.throw('The travel has entries with booked invoices');
|
|
|
|
END IF;
|
|
|
|
END IF;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|