2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`travel_beforeUpdate`
|
2024-01-15 11:31:03 +00:00
|
|
|
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-11-19 12:40:12 +00:00
|
|
|
IF NOT (NEW.landed <=> OLD.landed)
|
2024-02-26 11:18:57 +00:00
|
|
|
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
|
|
|
|
2024-11-19 12:40:12 +00:00
|
|
|
IF NOT (NEW.isRaid <=> OLD.isRaid) OR NOT (NEW.daysInForward <=> OLD.daysInForward) THEN
|
|
|
|
CALL travel_checkRaid(NEW.isRaid, NEW.daysInForward);
|
|
|
|
END IF;
|
|
|
|
|
2024-02-26 14:43:17 +00:00
|
|
|
IF NOT (NEW.awbFk <=> OLD.awbFk)THEN
|
2024-11-19 12:40:12 +00:00
|
|
|
SELECT COUNT(*) INTO vHasAnyInvoiceBooked
|
2024-02-26 14:43:17 +00:00
|
|
|
FROM travel t
|
2024-11-19 12:40:12 +00:00
|
|
|
JOIN entry e ON e.travelFk = t.id
|
|
|
|
JOIN invoiceIn ii ON ii.id = e.invoiceInFk
|
2024-02-26 14:43:17 +00:00
|
|
|
WHERE t.id = NEW.id
|
2024-11-19 12:40:12 +00:00
|
|
|
AND ii.isBooked;
|
|
|
|
|
2024-02-26 14:43:17 +00:00
|
|
|
IF vHasAnyInvoiceBooked THEN
|
|
|
|
CALL util.throw('The travel has entries with booked invoices');
|
|
|
|
END IF;
|
2024-11-19 12:40:12 +00:00
|
|
|
END IF;
|
|
|
|
|
2024-05-16 13:34:45 +00:00
|
|
|
IF (NOT(NEW.awbFk <=> OLD.awbFk)) AND NEW.awbFk IS NOT NULL THEN
|
2024-05-17 06:16:50 +00:00
|
|
|
CALL travel_throwAwb(NEW.id);
|
2024-03-27 13:12:34 +00:00
|
|
|
END IF;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|