fix(clientCredit): refs #6150 se arreglan los inserts en clientCredit
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
d2468033ea
commit
175e73e565
|
@ -0,0 +1,77 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeUpdate`
|
||||
BEFORE UPDATE ON `client`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE vText VARCHAR(255) DEFAULT NULL;
|
||||
DECLARE vPayMethodFk INT;
|
||||
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
|
||||
IF NOT(NEW.credit <=> OLD.credit) THEN
|
||||
INSERT INTO clientCredit
|
||||
SET clientFk = NEW.id,
|
||||
amount = NEW.credit,
|
||||
workerFk = NEW.editorFk;
|
||||
END IF;
|
||||
-- Comprueba que el formato de los teléfonos es válido
|
||||
|
||||
IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN
|
||||
CALL pbx.phone_isValid(NEW.phone);
|
||||
END IF;
|
||||
|
||||
IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN
|
||||
CALL pbx.phone_isValid(NEW.mobile);
|
||||
END IF;
|
||||
|
||||
SELECT id INTO vPayMethodFk
|
||||
FROM vn.payMethod
|
||||
WHERE code = 'bankDraft';
|
||||
|
||||
IF NEW.payMethodFk = vPayMethodFk AND NEW.dueDay = 0 THEN
|
||||
SET NEW.dueDay = 5;
|
||||
END IF;
|
||||
|
||||
-- Avisar al comercial si ha llegado la documentación sepa/core
|
||||
|
||||
IF NEW.hasSepaVnl AND !OLD.hasSepaVnl THEN
|
||||
SET vText = 'Sepa de VNL';
|
||||
END IF;
|
||||
|
||||
IF NEW.hasCoreVnl AND !OLD.hasCoreVnl THEN
|
||||
SET vText = 'Core de VNL';
|
||||
END IF;
|
||||
|
||||
IF vText IS NOT NULL
|
||||
THEN
|
||||
INSERT INTO mail(receiver, replyTo, `subject`, body)
|
||||
SELECT
|
||||
CONCAT(IF(ac.id,u.name, 'jgallego'), '@verdnatura.es'),
|
||||
'administracion@verdnatura.es',
|
||||
CONCAT('Cliente ', NEW.id),
|
||||
CONCAT('Recibida la documentación: ', vText)
|
||||
FROM worker w
|
||||
LEFT JOIN account.user u ON w.id = u.id AND u.active
|
||||
LEFT JOIN account.account ac ON ac.id = u.id
|
||||
WHERE w.id = NEW.salesPersonFk;
|
||||
END IF;
|
||||
|
||||
IF NEW.salespersonFk IS NULL AND OLD.salespersonFk IS NOT NULL THEN
|
||||
IF (SELECT COUNT(clientFk)
|
||||
FROM clientProtected
|
||||
WHERE clientFk = NEW.id
|
||||
) > 0 THEN
|
||||
CALL util.throw("HAS_CLIENT_PROTECTED");
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN
|
||||
SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk);
|
||||
END IF;
|
||||
|
||||
IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
|
||||
SET NEW.isTaxDataChecked = 0;
|
||||
END IF;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -17,6 +17,9 @@
|
|||
},
|
||||
"maxCreditRows": {
|
||||
"type": "number"
|
||||
},
|
||||
"defaultCredit": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -483,12 +483,6 @@ module.exports = Self => {
|
|||
if (userRequiredRoles <= 0)
|
||||
throw new UserError(`You don't have enough privileges to set this credit amount`);
|
||||
}
|
||||
|
||||
await models.ClientCredit.create({
|
||||
amount: changes.credit,
|
||||
clientFk: finalState.id,
|
||||
workerFk: userId
|
||||
}, ctx.options);
|
||||
};
|
||||
|
||||
Self.changeCreditManagement = async function changeCreditManagement(ctx, finalState, changes) {
|
||||
|
|
|
@ -62,13 +62,13 @@ describe('Client Model', () => {
|
|||
const options = {transaction: tx};
|
||||
const ctx = {options};
|
||||
|
||||
// Set credit to zero by a financialBoss
|
||||
const financialBoss = await models.VnUser.findOne({
|
||||
where: {name: 'financialBoss'}
|
||||
}, options);
|
||||
ctx.options.accessToken = {userId: financialBoss.id};
|
||||
|
||||
await models.Client.changeCredit(ctx, instance, {credit: 0});
|
||||
const testClient = await models.Client.findById(instance.id, options);
|
||||
await testClient.updateAttributes({credit: 0}, ctx.options);
|
||||
|
||||
const salesAssistant = await models.VnUser.findOne({
|
||||
where: {name: 'salesAssistant'}
|
||||
|
|
|
@ -212,7 +212,7 @@
|
|||
<vn-td number shrink>{{::sale.quantity}}</vn-td>
|
||||
<vn-td vn-fetched-tags>
|
||||
<div>
|
||||
<vn-one title="{{::sale.item.name}}">{{::sale.item.name}}</vn-one>
|
||||
<vn-one title="{{::sale.concept}}">{{::sale.concept}}</vn-one>
|
||||
<vn-one ng-if="::sale.item.subName">
|
||||
<h3 title="{{::sale.item.subName}}">{{::sale.item.subName}}</h3>
|
||||
</vn-one>
|
||||
|
|
|
@ -119,7 +119,8 @@ module.exports = Self => {
|
|||
|
||||
Self.new = async(ctx, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
const {userId} = ctx.req.accessToken;
|
||||
const myOptions = {userId};
|
||||
const args = ctx.args;
|
||||
|
||||
let tx;
|
||||
|
@ -188,6 +189,16 @@ module.exports = Self => {
|
|||
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(
|
||||
{
|
||||
clientFk: user.id,
|
||||
|
|
Loading…
Reference in New Issue