2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`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
|
2024-04-17 11:21:27 +00:00
|
|
|
IF
|
2024-01-15 11:31:03 +00:00
|
|
|
(SELECT COUNT(*) FROM
|
|
|
|
(
|
|
|
|
SELECT DISTINCT (isEqualizated = FALSE) as Equ
|
2024-04-17 11:21:27 +00:00
|
|
|
FROM address
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE clientFk = NEW.clientFk
|
|
|
|
) t1
|
|
|
|
) > 1
|
2024-04-17 11:21:27 +00:00
|
|
|
THEN
|
|
|
|
UPDATE client
|
2024-01-15 11:31:03 +00:00
|
|
|
SET hasToInvoiceByAddress = TRUE
|
|
|
|
WHERE id = NEW.clientFk;
|
|
|
|
END IF;
|
|
|
|
END IF;
|
2024-04-17 11:21:27 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
IF NEW.isDefaultAddress AND NEW.isActive = FALSE THEN
|
|
|
|
CALL util.throw ('Cannot desactivate the default address');
|
|
|
|
END IF;
|
|
|
|
|
2024-04-17 11:21:27 +00:00
|
|
|
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
|
2024-01-15 11:31:03 +00:00
|
|
|
SET hasToInvoiceByAddress = TRUE
|
|
|
|
WHERE id = NEW.clientFk;
|
2024-04-17 11:21:27 +00:00
|
|
|
END IF;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|