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

50 lines
1.3 KiB
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`supplier_beforeUpdate`
BEFORE UPDATE ON `supplier`
FOR EACH ROW
BEGIN
2022-12-14 07:06:02 +00:00
DECLARE vHasChange BOOL;
DECLARE vPayMethodChanged BOOL;
DECLARE vPayMethodHasVerified BOOL;
DECLARE vParams JSON;
DECLARE vOldPayMethodName VARCHAR(20);
DECLARE vNewPayMethodName VARCHAR(20);
SET NEW.editorFk = account.myUser_getId();
SELECT hasVerified INTO vPayMethodHasVerified
FROM payMethod
WHERE id = NEW.payMethodFk;
2022-12-14 07:06:02 +00:00
SET vPayMethodChanged = NOT(NEW.payMethodFk <=> OLD.payMethodFk);
2022-12-14 07:06:02 +00:00
IF vPayMethodChanged THEN
SELECT name INTO vOldPayMethodName
FROM payMethod
WHERE id = OLD.payMethodFk;
SELECT name INTO vNewPayMethodName
FROM payMethod
WHERE id = NEW.payMethodFk;
2022-12-14 07:06:02 +00:00
SET vParams = JSON_OBJECT(
'name', NEW.name,
'oldPayMethod', vOldPayMethodName,
'newPayMethod', vNewPayMethodName
);
SELECT util.notification_send('supplier-pay-method-update', vParams, NULL) INTO @id;
END IF;
2022-12-14 07:06:02 +00:00
SET vHasChange = NOT(NEW.payDemFk <=> OLD.payDemFk AND NEW.payDay <=> OLD.payDay) OR vPayMethodChanged;
2022-12-14 07:06:02 +00:00
IF vHasChange AND vPayMethodHasVerified THEN
SET NEW.isPayMethodChecked = FALSE;
END IF;
2024-11-14 08:27:38 +00:00
IF NOT (NEW.provinceFk <=> OLD.provinceFk)
2024-11-14 08:32:02 +00:00
OR (NEW.postCode <=> OLD.postCode) THEN
2024-11-14 08:27:38 +00:00
2024-11-14 08:30:36 +00:00
SET NEW.geoFk = supplier_getGeo(NEW.id);
2024-11-14 08:27:38 +00:00
END IF;
END$$
DELIMITER ;