fixed client billing data bic validations
This commit is contained in:
parent
043454bab2
commit
d2fc6b7b8b
|
@ -30,6 +30,7 @@
|
||||||
vn-one
|
vn-one
|
||||||
label="IBAN"
|
label="IBAN"
|
||||||
field="$ctrl.client.iban"
|
field="$ctrl.client.iban"
|
||||||
|
on-change="$ctrl.autofillBic()"
|
||||||
vn-acl="salesAssistant">
|
vn-acl="salesAssistant">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-autocomplete vn-one
|
<vn-autocomplete vn-one
|
||||||
|
|
|
@ -28,6 +28,7 @@ export default class Controller {
|
||||||
if (this.hasPaymethodChanges())
|
if (this.hasPaymethodChanges())
|
||||||
shouldNotify = true;
|
shouldNotify = true;
|
||||||
|
|
||||||
|
this.autofillBic();
|
||||||
this.$scope.watcher.submit().then(() => {
|
this.$scope.watcher.submit().then(() => {
|
||||||
if (shouldNotify)
|
if (shouldNotify)
|
||||||
this.notifyChanges();
|
this.notifyChanges();
|
||||||
|
@ -57,7 +58,7 @@ export default class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
onBankEntityResponse(response) {
|
onBankEntityResponse(response) {
|
||||||
if (response == 'ACCEPT')
|
if (response == 'ACCEPT') {
|
||||||
try {
|
try {
|
||||||
if (!this.newBankEntity.name)
|
if (!this.newBankEntity.name)
|
||||||
throw new Error(`Name can't be empty`);
|
throw new Error(`Name can't be empty`);
|
||||||
|
@ -72,9 +73,26 @@ export default class Controller {
|
||||||
this.vnApp.showError(this.$translate.instant(e.message));
|
this.vnApp.showError(this.$translate.instant(e.message));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autofillBic() {
|
||||||
|
if (!this.client.iban) return;
|
||||||
|
|
||||||
|
let countryCode = this.client.iban.substr(0, 2);
|
||||||
|
let bankEntityId = parseInt(this.client.iban.substr(4, 4));
|
||||||
|
let filter = {where: {id: bankEntityId}};
|
||||||
|
|
||||||
|
if (countryCode != 'ES') return;
|
||||||
|
|
||||||
|
let json = encodeURIComponent(JSON.stringify(filter));
|
||||||
|
this.client.bankEntityFk = undefined;
|
||||||
|
this.$http.get(`/client/api/BankEntities?filter=${json}`).then(response => {
|
||||||
|
if (response.data)
|
||||||
|
this.client.bankEntityFk = response.data.id;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
|
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import './index';
|
import './index';
|
||||||
import {watcher} from '../../../helpers/watcherHelper';
|
import {watcher} from '../../../helpers/watcherHelper';
|
||||||
|
|
||||||
describe('Client', () => {
|
fdescribe('Client', () => {
|
||||||
describe('Component vnClientBillingData', () => {
|
describe('Component vnClientBillingData', () => {
|
||||||
let $componentController;
|
let $componentController;
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
|
@ -106,5 +106,35 @@ describe('Client', () => {
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('autofillBic() should perform a GET query if client iban is specified and country code is "ES".', () => {
|
||||||
|
it(`Should not define bankEntityFk property`, () => {
|
||||||
|
controller.client.payMethodFk = 5;
|
||||||
|
controller.client.iban = 'ES9121000418450200051332';
|
||||||
|
let expectedFilter = {where: {id: 2100}};
|
||||||
|
let json = encodeURIComponent(JSON.stringify(expectedFilter));
|
||||||
|
|
||||||
|
$httpBackend.when('GET', `/client/api/BankEntities?filter=${json}`).respond('done');
|
||||||
|
$httpBackend.expect('GET', `/client/api/BankEntities?filter=${json}`);
|
||||||
|
controller.autofillBic();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.client.bankEntityFk).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`Should define bankEntityFk property`, () => {
|
||||||
|
controller.client.payMethodFk = 5;
|
||||||
|
controller.client.iban = 'ES1501280010120123456789';
|
||||||
|
let expectedFilter = {where: {id: 128}};
|
||||||
|
let json = encodeURIComponent(JSON.stringify(expectedFilter));
|
||||||
|
|
||||||
|
$httpBackend.when('GET', `/client/api/BankEntities?filter=${json}`).respond({id: 128});
|
||||||
|
$httpBackend.expect('GET', `/client/api/BankEntities?filter=${json}`);
|
||||||
|
controller.autofillBic();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.client.bankEntityFk).toEqual(128);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,7 +29,7 @@ export default class LeftMenu {
|
||||||
for (let child of item.childs) {
|
for (let child of item.childs) {
|
||||||
let route = states[child.state];
|
let route = states[child.state];
|
||||||
|
|
||||||
if(!route) continue;
|
if (!route) continue;
|
||||||
|
|
||||||
newItem.description = item.description;
|
newItem.description = item.description;
|
||||||
newItem.childs.push({
|
newItem.childs.push({
|
||||||
|
@ -37,7 +37,7 @@ export default class LeftMenu {
|
||||||
icon: child.icon,
|
icon: child.icon,
|
||||||
state: child.state
|
state: child.state
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
items.push(newItem);
|
items.push(newItem);
|
||||||
|
|
|
@ -1,42 +1,21 @@
|
||||||
{
|
{
|
||||||
"PHONE_INVALID_FORMAT": "The phone format is invalid",
|
|
||||||
"You are not allowed to change the credit": "You are not allowed to change the credit",
|
|
||||||
"Unable to mark the equivalence surcharge": "Unable to mark the equivalence surcharge",
|
|
||||||
"The default consignee can not be unchecked": "The default consignee can not be unchecked",
|
|
||||||
"Unable to default a disabled consignee": "Unable to default a disabled consignee",
|
|
||||||
"Can't be blank": "Can't be blank",
|
|
||||||
"Invalid TIN": "Invalid TIN",
|
|
||||||
"TIN must be unique": "TIN must be unique",
|
|
||||||
"A client with that Web User name already exists": "A client with that Web User name already exists",
|
|
||||||
"Is invalid": "Is invalid",
|
|
||||||
"Quantity cannot be zero": "Quantity cannot be zero",
|
|
||||||
"Enter an integer different to zero": "Enter an integer different to zero",
|
|
||||||
"The company name must be unique": "The company name must be unique",
|
|
||||||
"Invalid email": "Invalid email",
|
|
||||||
"The IBAN does not have the correct format": "The IBAN does not have the correct format",
|
|
||||||
"That payment method requires an IBAN": "That payment method requires an IBAN",
|
|
||||||
"State cannot be blank": "State cannot be blank",
|
"State cannot be blank": "State cannot be blank",
|
||||||
"Cannot change the payment method if no salesperson": "Cannot change the payment method if no salesperson",
|
|
||||||
"Only manager can change the credit": "Only manager can change the credit",
|
|
||||||
"Name cannot be blank": "Name cannot be blank",
|
|
||||||
"Phone cannot be blank": "Phone cannot be blank",
|
|
||||||
"Observation type cannot be blank": "Observation type cannot be blank",
|
|
||||||
"NO_AGENCY_AVAILABLE": "NO_AGENCY_AVAILABLE",
|
|
||||||
"can't be blank": "can't be blank",
|
|
||||||
"Cannot be blank": "Cannot be blank",
|
"Cannot be blank": "Cannot be blank",
|
||||||
"Description should have maximum of 45 characters": "Description should have maximum of 45 characters",
|
"Observation type cannot be blank": "Observation type cannot be blank",
|
||||||
"Period cannot be blank": "Period cannot be blank",
|
|
||||||
"The credit must be an integer greater than or equal to zero": "The credit must be an integer greater than or equal to zero",
|
"The credit must be an integer greater than or equal to zero": "The credit must be an integer greater than or equal to zero",
|
||||||
"The grade must be an integer greater than or equal to zero": "The grade must be an integer greater than or equal to zero",
|
"The grade must be an integer greater than or equal to zero": "The grade must be an integer greater than or equal to zero",
|
||||||
|
"Invalid email": "Invalid email",
|
||||||
|
"Name cannot be blank": "Name cannot be blank",
|
||||||
|
"Phone cannot be blank": "Phone cannot be blank",
|
||||||
|
"Description should have maximum of 45 characters": "Description should have maximum of 45 characters",
|
||||||
|
"Period cannot be blank": "Period cannot be blank",
|
||||||
"Sample type cannot be blank": "Sample type cannot be blank",
|
"Sample type cannot be blank": "Sample type cannot be blank",
|
||||||
"The package cannot be blank": "The package cannot be blank",
|
"That payment method requires an IBAN": "That payment method requires an IBAN",
|
||||||
"The warehouse can't be repeated": "The warehouse can't be repeated",
|
"That payment method requires a BIC": "That payment method requires a BIC",
|
||||||
"The new quantity should be smaller than the old one": "The new quantity should be smaller than the old one",
|
"The default consignee can not be unchecked": "The default consignee can not be unchecked",
|
||||||
"Package cannot be blank": "Package cannot be blank",
|
|
||||||
"The sales of this ticket can't be modified": "The sales of this ticket can't be modified",
|
|
||||||
"You don't have enough privileges to do that": "You don't have enough privileges to do that",
|
|
||||||
"You don't have enough privileges to change that field": "You don't have enough privileges to change that field",
|
|
||||||
"You don't have enough privileges": "You don't have enough privileges",
|
|
||||||
"You can't make changes on a client with verified data": "You can't make changes on a client with verified data",
|
"You can't make changes on a client with verified data": "You can't make changes on a client with verified data",
|
||||||
"That payment method requires a BIC": "That payment method requires a BIC"
|
"Enter an integer different to zero": "Enter an integer different to zero",
|
||||||
|
"Package cannot be blank": "Package cannot be blank",
|
||||||
|
"The new quantity should be smaller than the old one": "The new quantity should be smaller than the old one",
|
||||||
|
"The sales of this ticket can't be modified": "The sales of this ticket can't be modified"
|
||||||
}
|
}
|
|
@ -15,7 +15,8 @@
|
||||||
"The company name must be unique": "La razón social debe ser única",
|
"The company name must be unique": "La razón social debe ser única",
|
||||||
"Invalid email": "Correo electrónico inválido",
|
"Invalid email": "Correo electrónico inválido",
|
||||||
"The IBAN does not have the correct format": "El IBAN no tiene el formato correcto",
|
"The IBAN does not have the correct format": "El IBAN no tiene el formato correcto",
|
||||||
"That payment method requires an IBAN": "El método de pago seleccionado requiere que se especifique el IBAN",
|
"That payment method requires an IBAN": "El método de pago seleccionado requiere un IBAN",
|
||||||
|
"That payment method requires a BIC": "El método de pago seleccionado requiere un BIC",
|
||||||
"State cannot be blank": "El estado no puede estar en blanco",
|
"State cannot be blank": "El estado no puede estar en blanco",
|
||||||
"Cannot change the payment method if no salesperson": "No se puede cambiar la forma de pago si no hay comercial asignado",
|
"Cannot change the payment method if no salesperson": "No se puede cambiar la forma de pago si no hay comercial asignado",
|
||||||
"can't be blank": "El campo no puede estar vacío",
|
"can't be blank": "El campo no puede estar vacío",
|
||||||
|
@ -56,6 +57,5 @@
|
||||||
"The sales of this ticket can't be modified": "Los movimientos de este tiquet no pueden ser modificadas",
|
"The sales of this ticket can't be modified": "Los movimientos de este tiquet no pueden ser modificadas",
|
||||||
"You can't create an order for a inactive client": "You can't create an order for a inactive client",
|
"You can't create an order for a inactive client": "You can't create an order for a inactive client",
|
||||||
"You can't create an order for a client that doesn't has tax data verified": "You can't create an order for a client that doesn't has tax data verified",
|
"You can't create an order for a client that doesn't has tax data verified": "You can't create an order for a client that doesn't has tax data verified",
|
||||||
"You don't have enough privileges": "You don't have enough privileges",
|
"You don't have enough privileges": "You don't have enough privileges"
|
||||||
"That payment method requires a BIC": "That payment method requires a BIC"
|
|
||||||
}
|
}
|
|
@ -91,6 +91,30 @@ module.exports = Self => {
|
||||||
err();
|
err();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Self.validateAsync('payMethodFk', hasIban, {
|
||||||
|
message: 'That payment method requires an IBAN'
|
||||||
|
});
|
||||||
|
|
||||||
|
function hasIban(err, done) {
|
||||||
|
Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => {
|
||||||
|
if (instance && instance.ibanRequired && !this.iban)
|
||||||
|
err();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Self.validateAsync('bankEntityFk', hasBic, {
|
||||||
|
message: 'That payment method requires a BIC'
|
||||||
|
});
|
||||||
|
|
||||||
|
function hasBic(err, done) {
|
||||||
|
Self.app.models.PayMethod.findById(this.payMethodFk, (_, instance) => {
|
||||||
|
if (instance && instance.ibanRequired && !this.bankEntityFk)
|
||||||
|
err();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx) {
|
Self.observe('before save', async function(ctx) {
|
||||||
let changes = ctx.data || ctx.instance;
|
let changes = ctx.data || ctx.instance;
|
||||||
let orgData = ctx.currentInstance;
|
let orgData = ctx.currentInstance;
|
||||||
|
@ -131,16 +155,6 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
await Self.app.models.ClientCredit.create(newCredit);
|
await Self.app.models.ClientCredit.create(newCredit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finalState && finalState.payMethodFk) {
|
|
||||||
let payMethod = await Self.app.models.PayMethod.findById(finalState.payMethodFk);
|
|
||||||
|
|
||||||
if (payMethod && payMethod.ibanRequired && !finalState.iban)
|
|
||||||
throw new UserError('That payment method requires an IBAN');
|
|
||||||
|
|
||||||
if (payMethod && payMethod.ibanRequired && !finalState.bankEntityFk)
|
|
||||||
throw new UserError('That payment method requires a BIC');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function validateCreditChange(ctx, finalState) {
|
async function validateCreditChange(ctx, finalState) {
|
||||||
|
|
Loading…
Reference in New Issue