3900-client_credit #946

Merged
carlosjr merged 4 commits from 3900-client_credit into dev 2022-05-09 13:53:51 +00:00
2 changed files with 29 additions and 13 deletions

View File

@ -26,7 +26,7 @@
.icon-agency-term:before {
content: "\e950";
}
.icon-deaulter:before {
.icon-defaulter:before {
content: "\e94b";
}
.icon-100:before {

View File

@ -46,10 +46,6 @@ module.exports = Self => {
message: 'TIN must be unique'
});
Self.validatesUniquenessOf('socialName', {
message: 'The company name must be unique'
});
Self.validatesFormatOf('email', {
message: 'Invalid email',
allowNull: true,
@ -63,17 +59,37 @@ module.exports = Self => {
min: 3, max: 10
});
Self.validateAsync('socialName', socialNameIsUnique, {
message: 'The company name must be unique'
});
async function socialNameIsUnique(err, done) {
const filter = {
where: {
and: [
{socialName: this.socialName},
{isActive: true},
{id: {neq: this.id}}
]
}
};
const client = await Self.app.models.Client.findOne(filter);
if (client)
err();
done();
}
Self.validateAsync('iban', ibanNeedsValidation, {
message: 'The IBAN does not have the correct format'
});
async function ibanNeedsValidation(err, done) {
let filter = {
const filter = {
fields: ['code'],
where: {id: this.countryFk}
};
let country = await Self.app.models.Country.findOne(filter);
let code = country ? country.code.toLowerCase() : null;
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code.toLowerCase() : null;
if (code != 'es')
return done();
@ -90,12 +106,12 @@ module.exports = Self => {
if (!this.isTaxDataChecked)
return done();
let filter = {
const filter = {
fields: ['code'],
where: {id: this.countryFk}
};
let country = await Self.app.models.Country.findOne(filter);
let code = country ? country.code.toLowerCase() : null;
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code.toLowerCase() : null;
if (!this.fi || !validateTin(this.fi, code))
err();
@ -118,8 +134,8 @@ module.exports = Self => {
function cannotHaveET(err) {
if (!this.fi) return;
let tin = this.fi.toUpperCase();
let cannotHaveET = /^[A-B]/.test(tin);
const tin = this.fi.toUpperCase();
const cannotHaveET = /^[A-B]/.test(tin);
if (cannotHaveET && this.isEqualizated)
err();