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

37 lines
945 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`address_afterUpdate`
AFTER UPDATE ON `address`
FOR EACH ROW
BEGIN
-- Recargos de equivalencia distintos implican facturacion por consignatario
IF NEW.isEqualizated != OLD.isEqualizated THEN
IF
(SELECT COUNT(*) FROM
(
SELECT DISTINCT (isEqualizated = FALSE) as Equ
FROM address
WHERE clientFk = NEW.clientFk
) t1
) > 1
THEN
UPDATE client
SET hasToInvoiceByAddress = TRUE
WHERE id = NEW.clientFk;
END IF;
END IF;
IF NEW.isDefaultAddress AND NEW.isActive = FALSE THEN
CALL util.throw ('Cannot desactivate the default address');
END IF;
IF (NEW.clientFk <> OLD.clientFk
OR NEW.isActive <> OLD.isActive
OR NOT (NEW.provinceFk <=> OLD.provinceFk))
AND (SELECT client_hasDifferentCountries(NEW.clientFk)) THEN
UPDATE client
SET hasToInvoiceByAddress = TRUE
WHERE id = NEW.clientFk;
END IF;
END$$
DELIMITER ;