fix: refs #6150 ticket to client trigger
This commit is contained in:
parent
aa800b1fd3
commit
b442c9f5ed
|
@ -80,44 +80,30 @@ END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_afterInsert`
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeInsert`
|
||||||
AFTER INSERT ON `ticket`
|
BEFORE INSERT ON `client`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE vClientType VARCHAR(255);
|
IF NEW.credit NOT NULL AND NEW.credit THEN
|
||||||
DECLARE vStateCode VARCHAR(255);
|
|
||||||
DECLARE vTransferorFirstShipped DATE;
|
|
||||||
|
|
||||||
IF NEW.credit NOT NULL AND NEW.credit <> 0 THEN
|
|
||||||
INSERT INTO clientCredit
|
INSERT INTO clientCredit
|
||||||
SET clientFk = NEW.id,
|
SET clientFk = NEW.id,
|
||||||
workerFk = NEW.editorFk,
|
workerFk = NEW.editorFk,
|
||||||
amount = NEW.credit;
|
amount = NEW.credit;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Borrar cuando se cambie el insert ticket en la APP móvil
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
|
||||||
SELECT typeFk INTO vClientType
|
IF (NEW.phone <> '') THEN
|
||||||
FROM vn.`client` WHERE id = NEW.clientFk;
|
CALL pbx.phone_isValid(NEW.phone);
|
||||||
|
|
||||||
IF vClientType = 'loses' THEN
|
|
||||||
SET vStateCode = 'DELIVERED';
|
|
||||||
ELSE
|
|
||||||
SET vStateCode = 'FREE';
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
CALL ticket_setState(NEW.id, vStateCode);
|
IF (NEW.mobile <> '') THEN
|
||||||
|
CALL pbx.phone_isValid(NEW.mobile);
|
||||||
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();
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
SET NEW.accountingAccount = 4300000000 + NEW.id;
|
||||||
|
|
||||||
|
SET NEW.lastSalesPersonFk = NEW.salesPersonFk;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue