feat(client.create): refs #6150 clientCredit update fix
This commit is contained in:
parent
175e73e565
commit
a75565f2ce
|
@ -1,3 +1,7 @@
|
||||||
|
ALTER TABLE `vn`.`client` MODIFY COLUMN `credit` decimal(10,2) unsigned DEFAULT 0.00 NOT NULL;
|
||||||
|
|
||||||
|
DELETE FROM `salix`.`ACL` WHERE `model` = 'Client' AND `property` = 'create';
|
||||||
|
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeUpdate`
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeUpdate`
|
||||||
BEFORE UPDATE ON `client`
|
BEFORE UPDATE ON `client`
|
||||||
|
@ -72,6 +76,48 @@ BEGIN
|
||||||
IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
|
IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
|
||||||
SET NEW.isTaxDataChecked = 0;
|
SET NEW.isTaxDataChecked = 0;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_afterInsert`
|
||||||
|
AFTER INSERT ON `ticket`
|
||||||
|
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
|
||||||
|
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
|
||||||
|
|
||||||
|
SELECT typeFk INTO vClientType
|
||||||
|
FROM vn.`client` WHERE id = NEW.clientFk;
|
||||||
|
|
||||||
|
IF vClientType = 'loses' THEN
|
||||||
|
SET vStateCode = 'DELIVERED';
|
||||||
|
ELSE
|
||||||
|
SET vStateCode = 'FREE';
|
||||||
|
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();
|
||||||
|
END IF;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
|
|
@ -491,7 +491,8 @@ INSERT INTO `vn`.`clientCreditLimit`(`id`, `maxAmount`, `roleFk`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 9999999, 20),
|
(1, 9999999, 20),
|
||||||
(2, 10000, 21),
|
(2, 10000, 21),
|
||||||
(3, 600, 13);
|
(3, 600, 13),
|
||||||
|
(4, 300, 37);
|
||||||
|
|
||||||
INSERT INTO `vn`.`clientObservation`(`id`, `clientFk`, `workerFk`, `text`, `created`)
|
INSERT INTO `vn`.`clientObservation`(`id`, `clientFk`, `workerFk`, `text`, `created`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -189,16 +189,6 @@ module.exports = Self => {
|
||||||
myOptions
|
myOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
const {defaultCredit} = await models.ClientConfig.findOne(myOptions);
|
|
||||||
|
|
||||||
await models.ClientCredit.create(
|
|
||||||
{
|
|
||||||
clientFk: user.id,
|
|
||||||
amount: defaultCredit,
|
|
||||||
workerFk: userId
|
|
||||||
}, myOptions
|
|
||||||
);
|
|
||||||
|
|
||||||
const address = await models.Address.create(
|
const address = await models.Address.create(
|
||||||
{
|
{
|
||||||
clientFk: user.id,
|
clientFk: user.id,
|
||||||
|
|
Loading…
Reference in New Issue