refactor sql
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alexandre Riera 2022-12-14 08:06:02 +01:00
parent 95967a29db
commit f00fdcff7c
1 changed files with 9 additions and 11 deletions

View File

@ -1,5 +1,5 @@
DROP TRIGGER IF EXISTS vn.supplier_beforeUpdate;
USE vn;
DROP TRIGGER IF EXISTS `vn`.`supplier_beforeUpdate`;
USE `vn`;
DELIMITER $$
$$
@ -7,7 +7,8 @@ CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_beforeUpdate`
BEFORE UPDATE ON `supplier`
FOR EACH ROW
BEGIN
DECLARE vHasChange BOOL DEFAULT FALSE;
DECLARE vHasChange BOOL;
DECLARE vPayMethodChanged BOOL;
DECLARE vPayMethodHasVerified BOOL;
DECLARE vParams JSON;
DECLARE vOldPayMethodName VARCHAR(20);
@ -17,15 +18,16 @@ BEGIN
FROM payMethod
WHERE id = NEW.payMethodFk;
SET vHasChange = (NEW.payMethodFk <=> OLD.payMethodFk);
SET vPayMethodChanged = NOT(NEW.payMethodFk <=> OLD.payMethodFk);
IF !vHasChange THEN
IF vPayMethodChanged THEN
SELECT name INTO vOldPayMethodName
FROM payMethod
WHERE id = OLD.payMethodFk;
SELECT name INTO vNewPayMethodName
FROM payMethod
WHERE id = NEW.payMethodFk;
SET vParams = JSON_OBJECT(
'name', NEW.name,
'oldPayMethod', vOldPayMethodName,
@ -34,13 +36,9 @@ BEGIN
SELECT util.notification_send('supplier-pay-method-update', vParams, NULL) INTO @id;
END IF;
SET vHasChange = (NEW.payDemFk <=> OLD.payDemFk) OR (NEW.payDay <=> OLD.payDay);
SET vHasChange = NOT(NEW.payDemFk <=> OLD.payDemFk AND NEW.payDay <=> OLD.payDay) OR vPayMethodChanged;
IF vPayMethodHasVerified AND !vHasChange THEN
SET vHasChange = (NEW.payMethodFk <=> OLD.payMethodFk);
END IF;
IF vHasChange THEN
IF vHasChange AND vPayMethodHasVerified THEN
SET NEW.isPayMethodChecked = FALSE;
END IF;