2022-12-13 10:50:17 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`supplier_beforeUpdate`
|
2022-12-13 10:50:17 +00:00
|
|
|
BEFORE UPDATE ON `supplier`
|
|
|
|
FOR EACH ROW
|
|
|
|
BEGIN
|
2022-12-14 07:06:02 +00:00
|
|
|
DECLARE vHasChange BOOL;
|
|
|
|
DECLARE vPayMethodChanged BOOL;
|
2022-12-13 10:50:17 +00:00
|
|
|
DECLARE vPayMethodHasVerified BOOL;
|
|
|
|
DECLARE vParams JSON;
|
|
|
|
DECLARE vOldPayMethodName VARCHAR(20);
|
|
|
|
DECLARE vNewPayMethodName VARCHAR(20);
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SET NEW.editorFk = account.myUser_getId();
|
|
|
|
|
2022-12-13 10:50:17 +00:00
|
|
|
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-13 10:50:17 +00:00
|
|
|
|
2022-12-14 07:06:02 +00:00
|
|
|
IF vPayMethodChanged THEN
|
2022-12-13 10:50:17 +00:00
|
|
|
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
|
|
|
|
2022-12-13 10:50:17 +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-13 10:50:17 +00:00
|
|
|
|
2022-12-14 07:06:02 +00:00
|
|
|
IF vHasChange AND vPayMethodHasVerified THEN
|
2022-12-13 10:50:17 +00:00
|
|
|
SET NEW.isPayMethodChecked = FALSE;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|