fix: refs #6150 ticket to client trigger

This commit is contained in:
Pablo Natek 2023-11-06 14:54:56 +01:00
parent aa800b1fd3
commit b442c9f5ed
1 changed files with 12 additions and 26 deletions

View File

@ -80,44 +80,30 @@ END$$
DELIMITER ;
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_afterInsert`
AFTER INSERT ON `ticket`
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeInsert`
BEFORE INSERT ON `client`
FOR EACH ROW
BEGIN
DECLARE vClientType VARCHAR(255);
DECLARE vStateCode VARCHAR(255);
DECLARE vTransferorFirstShipped DATE;
IF NEW.credit NOT NULL AND NEW.credit <> 0 THEN
IF NEW.credit NOT NULL AND NEW.credit THEN
INSERT INTO clientCredit
SET clientFk = NEW.id,
workerFk = NEW.editorFk,
amount = NEW.credit;
END IF;
-- Borrar cuando se cambie el insert ticket en la APP móvil
SET NEW.editorFk = account.myUser_getId();
SELECT typeFk INTO vClientType
FROM vn.`client` WHERE id = NEW.clientFk;
IF vClientType = 'loses' THEN
SET vStateCode = 'DELIVERED';
ELSE
SET vStateCode = 'FREE';
IF (NEW.phone <> '') THEN
CALL pbx.phone_isValid(NEW.phone);
END IF;
CALL ticket_setState(NEW.id, vStateCode);
IF YEAR(NEW.shipped) > 2000 THEN
SELECT cnb.firstShipped INTO vTransferorFirstShipped
FROM bs.clientNewBorn cnb
JOIN `client` c ON c.transferorFk = cnb.clientFk
WHERE c.id = NEW.clientFk;
INSERT INTO bs.clientNewBorn(clientFk, firstShipped, lastShipped)
VALUES(NEW.clientFk, IFNULL(vTransferorFirstShipped, util.VN_CURDATE()), util.VN_CURDATE())
ON DUPLICATE KEY UPDATE lastShipped = util.VN_CURDATE();
IF (NEW.mobile <> '') THEN
CALL pbx.phone_isValid(NEW.mobile);
END IF;
SET NEW.accountingAccount = 4300000000 + NEW.id;
SET NEW.lastSalesPersonFk = NEW.salesPersonFk;
END$$
DELIMITER ;