3900-client_credit #946
|
@ -26,7 +26,7 @@
|
||||||
.icon-agency-term:before {
|
.icon-agency-term:before {
|
||||||
content: "\e950";
|
content: "\e950";
|
||||||
}
|
}
|
||||||
.icon-deaulter:before {
|
.icon-defaulter:before {
|
||||||
content: "\e94b";
|
content: "\e94b";
|
||||||
}
|
}
|
||||||
.icon-100:before {
|
.icon-100:before {
|
||||||
|
|
|
@ -46,10 +46,6 @@ module.exports = Self => {
|
||||||
message: 'TIN must be unique'
|
message: 'TIN must be unique'
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.validatesUniquenessOf('socialName', {
|
|
||||||
message: 'The company name must be unique'
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.validatesFormatOf('email', {
|
Self.validatesFormatOf('email', {
|
||||||
message: 'Invalid email',
|
message: 'Invalid email',
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
|
@ -63,17 +59,37 @@ module.exports = Self => {
|
||||||
min: 3, max: 10
|
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, {
|
Self.validateAsync('iban', ibanNeedsValidation, {
|
||||||
message: 'The IBAN does not have the correct format'
|
message: 'The IBAN does not have the correct format'
|
||||||
});
|
});
|
||||||
|
|
||||||
async function ibanNeedsValidation(err, done) {
|
async function ibanNeedsValidation(err, done) {
|
||||||
let filter = {
|
const filter = {
|
||||||
fields: ['code'],
|
fields: ['code'],
|
||||||
where: {id: this.countryFk}
|
where: {id: this.countryFk}
|
||||||
};
|
};
|
||||||
let country = await Self.app.models.Country.findOne(filter);
|
const country = await Self.app.models.Country.findOne(filter);
|
||||||
let code = country ? country.code.toLowerCase() : null;
|
const code = country ? country.code.toLowerCase() : null;
|
||||||
if (code != 'es')
|
if (code != 'es')
|
||||||
return done();
|
return done();
|
||||||
|
|
||||||
|
@ -90,12 +106,12 @@ module.exports = Self => {
|
||||||
if (!this.isTaxDataChecked)
|
if (!this.isTaxDataChecked)
|
||||||
return done();
|
return done();
|
||||||
|
|
||||||
let filter = {
|
const filter = {
|
||||||
fields: ['code'],
|
fields: ['code'],
|
||||||
where: {id: this.countryFk}
|
where: {id: this.countryFk}
|
||||||
};
|
};
|
||||||
let country = await Self.app.models.Country.findOne(filter);
|
const country = await Self.app.models.Country.findOne(filter);
|
||||||
let code = country ? country.code.toLowerCase() : null;
|
const code = country ? country.code.toLowerCase() : null;
|
||||||
|
|
||||||
if (!this.fi || !validateTin(this.fi, code))
|
if (!this.fi || !validateTin(this.fi, code))
|
||||||
err();
|
err();
|
||||||
|
@ -118,8 +134,8 @@ module.exports = Self => {
|
||||||
function cannotHaveET(err) {
|
function cannotHaveET(err) {
|
||||||
if (!this.fi) return;
|
if (!this.fi) return;
|
||||||
|
|
||||||
let tin = this.fi.toUpperCase();
|
const tin = this.fi.toUpperCase();
|
||||||
let cannotHaveET = /^[A-B]/.test(tin);
|
const cannotHaveET = /^[A-B]/.test(tin);
|
||||||
|
|
||||||
if (cannotHaveET && this.isEqualizated)
|
if (cannotHaveET && this.isEqualizated)
|
||||||
err();
|
err();
|
||||||
|
|
Loading…
Reference in New Issue