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`.`entry_beforeUpdate`
|
2024-01-15 11:31:03 +00:00
|
|
|
BEFORE UPDATE ON `entry`
|
|
|
|
FOR EACH ROW
|
|
|
|
BEGIN
|
|
|
|
DECLARE vIsVirtual BOOL;
|
|
|
|
DECLARE vPrintedCount INT;
|
|
|
|
DECLARE vHasDistinctWarehouses BOOL;
|
2024-04-22 13:03:08 +00:00
|
|
|
DECLARE vTotalBuy INT;
|
2024-06-13 05:09:48 +00:00
|
|
|
|
|
|
|
IF NEW.isBooked = OLD.isBooked AND (
|
|
|
|
NOT (NEW.supplierFk <=> OLD.supplierFk) OR
|
|
|
|
NOT (NEW.dated <=> OLD.dated) OR
|
|
|
|
NOT (NEW.travelFk <=> OLD.travelFk) OR
|
|
|
|
NOT (NEW.companyFk <=> OLD.companyFk) OR
|
|
|
|
NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) OR
|
|
|
|
NOT (NEW.typeFk <=> OLD.typeFk)
|
|
|
|
) THEN
|
|
|
|
|
2024-06-05 13:44:11 +00:00
|
|
|
CALL entry_isEditable(OLD.id);
|
2024-04-22 13:03:08 +00:00
|
|
|
ELSE
|
2024-06-13 05:09:48 +00:00
|
|
|
|
2024-04-29 17:40:43 +00:00
|
|
|
IF NEW.isBooked THEN
|
2024-04-22 13:03:08 +00:00
|
|
|
SELECT COUNT(*) INTO vTotalBuy
|
2024-04-29 17:40:43 +00:00
|
|
|
FROM buy
|
|
|
|
WHERE entryFk = NEW.id;
|
2024-04-30 12:37:06 +00:00
|
|
|
IF NOT vTotalBuy THEN
|
|
|
|
CALL util.throw('Entry must have lines to be marked booked');
|
2024-04-22 13:03:08 +00:00
|
|
|
END IF;
|
2024-04-18 14:09:05 +00:00
|
|
|
END IF;
|
|
|
|
END IF;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SET NEW.editorFk = account.myUser_getId();
|
2024-03-25 07:47:06 +00:00
|
|
|
|
2024-03-01 13:36:49 +00:00
|
|
|
IF NOT (NEW.travelFk <=> OLD.travelFk) THEN
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-05-16 13:34:45 +00:00
|
|
|
IF NEW.travelFk IS NOT NULL THEN
|
2024-05-17 06:16:50 +00:00
|
|
|
CALL travel_throwAwb(NEW.travelFk);
|
2024-03-05 16:30:29 +00:00
|
|
|
END IF;
|
2024-03-01 13:26:36 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT COUNT(*) > 0 INTO vIsVirtual
|
|
|
|
FROM entryVirtual WHERE entryFk = NEW.id;
|
|
|
|
|
2024-03-01 13:36:49 +00:00
|
|
|
SELECT NOT (o.warehouseInFk <=> n.warehouseInFk)
|
|
|
|
OR NOT (o.warehouseOutFk <=> n.warehouseOutFk)
|
2024-01-15 11:31:03 +00:00
|
|
|
INTO vHasDistinctWarehouses
|
|
|
|
FROM travel o, travel n
|
|
|
|
WHERE o.id = OLD.travelFk
|
|
|
|
AND n.id = NEW.travelFk;
|
|
|
|
|
|
|
|
IF vIsVirtual AND vHasDistinctWarehouses THEN
|
|
|
|
SIGNAL SQLSTATE '45000'
|
|
|
|
SET MESSAGE_TEXT = 'A cloned entry cannot be moved to a travel with different warehouses';
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
IF NEW.travelFk IS NULL THEN
|
|
|
|
SELECT COUNT(*) INTO vPrintedCount
|
|
|
|
FROM buy
|
|
|
|
WHERE entryFk = OLD.id
|
|
|
|
AND printedStickers > 0;
|
|
|
|
|
|
|
|
IF vPrintedCount > 0 THEN
|
|
|
|
SIGNAL SQLSTATE '45000'
|
|
|
|
SET MESSAGE_TEXT = 'An entry that contains lines with printed labels cannot be deleted';
|
|
|
|
END IF;
|
|
|
|
END IF;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
IF NOT (NEW.supplierFk <=> OLD.supplierFk) THEN
|
|
|
|
CALL supplier_checkIsActive(NEW.supplierFk);
|
|
|
|
SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk);
|
|
|
|
END IF;
|
|
|
|
|
2024-09-16 10:26:29 +00:00
|
|
|
IF NOT (NEW.travelFk <=> OLD.travelFk)
|
|
|
|
OR NOT (NEW.currencyFk <=> OLD.currencyFk)
|
2024-09-16 11:37:35 +00:00
|
|
|
OR NOT (NEW.supplierFk <=> OLD.supplierFk) THEN
|
2024-09-16 10:26:29 +00:00
|
|
|
|
2024-03-01 13:36:49 +00:00
|
|
|
SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk, NEW.supplierFk);
|
2024-01-15 11:31:03 +00:00
|
|
|
END IF;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|