From 117849f09395aee737df62efbd1a615907252bc1 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 12 Apr 2023 12:03:55 +0200 Subject: [PATCH 01/18] refs #5540 supplier js --- db/changes/231401/00-updateIsVies.sql | 5 +++++ modules/supplier/back/models/supplier.js | 12 ++++++++++++ modules/supplier/front/fiscal-data/index.html | 7 +++++-- modules/supplier/front/fiscal-data/locale/es.yml | 4 +++- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 db/changes/231401/00-updateIsVies.sql diff --git a/db/changes/231401/00-updateIsVies.sql b/db/changes/231401/00-updateIsVies.sql new file mode 100644 index 000000000..efe008101 --- /dev/null +++ b/db/changes/231401/00-updateIsVies.sql @@ -0,0 +1,5 @@ +UPDATE vn.supplier s + JOIN vn.country c ON c.id = s.countryFk + SET s.nif = MID(REPLACE(s.nif, ' ', ''), 3, LENGTH(REPLACE(s.nif, ' ', '')) - 1) + WHERE s.isVies = TRUE + AND c.code = LEFT(REPLACE(s.nif, ' ', ''), 2); \ No newline at end of file diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 4e509aafc..745a2f7e3 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -73,6 +73,18 @@ module.exports = Self => { done(); } + Self.validateAsync('nif', areFirstTwoCharsLetters, nifInvalid, { + message: 'The first two values are letters.'}); + + function areFirstTwoCharsLetters(str) { + return /^[a-zA-Z]{2}/.test(str); + } + + async function nifInvalid(err, areFirstTwoCharsLetters) { + if (this.isVies == 1 && areFirstTwoCharsLetters(this.nif)) + err(); + } + function isAlpha(value) { const regexp = new RegExp(/^[ñça-zA-Z0-9\s]*$/i); diff --git a/modules/supplier/front/fiscal-data/index.html b/modules/supplier/front/fiscal-data/index.html index ccbd5b0d9..f84a1890e 100644 --- a/modules/supplier/front/fiscal-data/index.html +++ b/modules/supplier/front/fiscal-data/index.html @@ -52,7 +52,8 @@ label="Tax number" ng-model="$ctrl.supplier.nif" required="true" - rule> + rule + > @@ -188,7 +189,9 @@ + info="When activating it, do not enter the country code in the ID field." + ng-model="$ctrl.supplier.isVies" + > diff --git a/modules/supplier/front/fiscal-data/locale/es.yml b/modules/supplier/front/fiscal-data/locale/es.yml index 5232dd95d..ee641231f 100644 --- a/modules/supplier/front/fiscal-data/locale/es.yml +++ b/modules/supplier/front/fiscal-data/locale/es.yml @@ -3,4 +3,6 @@ Sage transaction type: Tipo de transacción Sage Sage withholding: Retención Sage Supplier activity: Actividad proveedor Healt register: Pasaporte sanitario -Trucker: Transportista \ No newline at end of file +Trucker: Transportista +When activating it, do not enter the country code in the ID field.: Al activarlo, no informar el código del país en el campo nif +The first two values are letters.: Los dos primeros valores son letras \ No newline at end of file From 60103fa80ac08ce1ac39909fd2f14b5cf71cc9bf Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 12 Apr 2023 14:39:40 +0200 Subject: [PATCH 02/18] refs #5540 validacion nif --- loopback/locale/es.json | 3 ++- modules/supplier/back/models/supplier.js | 13 +++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 42276efe7..8e2672bc4 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -274,5 +274,6 @@ "This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado", "Insert a date range": "Inserte un rango de fechas", "Added observation": "{{user}} añadió esta observacion: {{text}}", - "Comment added to client": "Observación añadida al cliente {{clientFk}}" + "Comment added to client": "Observación añadida al cliente {{clientFk}}", + "The first two values are letters": "Los dos primeros carácteres del NIF son letras" } diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 745a2f7e3..7f12e86ef 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -73,16 +73,13 @@ module.exports = Self => { done(); } - Self.validateAsync('nif', areFirstTwoCharsLetters, nifInvalid, { - message: 'The first two values are letters.'}); + Self.validateAsync('nif', nifInvalid, { + message: 'The first two values are letters'}); - function areFirstTwoCharsLetters(str) { - return /^[a-zA-Z]{2}/.test(str); - } - - async function nifInvalid(err, areFirstTwoCharsLetters) { - if (this.isVies == 1 && areFirstTwoCharsLetters(this.nif)) + async function nifInvalid(err, done) { + if (this.isVies && /^[a-zA-Z]{2}/.test(this.nif)) err(); + done(); } function isAlpha(value) { From 747efc4342ac8da8994c8ac096f50f48cf655a0e Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 12 Apr 2023 14:52:59 +0200 Subject: [PATCH 03/18] refs #5540 sql mod --- db/changes/231401/00-updateIsVies.sql | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/db/changes/231401/00-updateIsVies.sql b/db/changes/231401/00-updateIsVies.sql index efe008101..1d2e55441 100644 --- a/db/changes/231401/00-updateIsVies.sql +++ b/db/changes/231401/00-updateIsVies.sql @@ -1,5 +1,3 @@ -UPDATE vn.supplier s - JOIN vn.country c ON c.id = s.countryFk - SET s.nif = MID(REPLACE(s.nif, ' ', ''), 3, LENGTH(REPLACE(s.nif, ' ', '')) - 1) - WHERE s.isVies = TRUE - AND c.code = LEFT(REPLACE(s.nif, ' ', ''), 2); \ No newline at end of file +UPDATE vn.supplier +SET nif = SUBSTRING(nif, IF(ASCII(SUBSTRING(nif, 1, 1)) BETWEEN 65 AND 90 AND ASCII(SUBSTRING(nif, 2, 1)) BETWEEN 65 AND 90, 3, 1), LENGTH(nif)) +WHERE isVies = 1 AND nif REGEXP '^[a-zA-Z]{2}'; From ad267c933c68149e7c693ff031e1edc8c2af24f6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 13 Apr 2023 08:30:33 +0200 Subject: [PATCH 04/18] refs #5540 country.code --- db/changes/231401/00-updateIsVies.sql | 8 +++++--- modules/supplier/back/models/supplier.js | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/db/changes/231401/00-updateIsVies.sql b/db/changes/231401/00-updateIsVies.sql index 1d2e55441..83fde7352 100644 --- a/db/changes/231401/00-updateIsVies.sql +++ b/db/changes/231401/00-updateIsVies.sql @@ -1,3 +1,5 @@ -UPDATE vn.supplier -SET nif = SUBSTRING(nif, IF(ASCII(SUBSTRING(nif, 1, 1)) BETWEEN 65 AND 90 AND ASCII(SUBSTRING(nif, 2, 1)) BETWEEN 65 AND 90, 3, 1), LENGTH(nif)) -WHERE isVies = 1 AND nif REGEXP '^[a-zA-Z]{2}'; + UPDATE vn.supplier s + JOIN vn.country c ON c.id = s.countryFk + SET s.nif = MID(REPLACE(s.nif, ' ', ''), 3, LENGTH(REPLACE(s.nif, ' ', '')) - 1) + WHERE s.isVies = TRUE + AND c.code = LEFT(REPLACE(s.nif, ' ', ''), 2); \ No newline at end of file diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 7f12e86ef..c889fd420 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -77,7 +77,14 @@ module.exports = Self => { message: 'The first two values are letters'}); async function nifInvalid(err, done) { - if (this.isVies && /^[a-zA-Z]{2}/.test(this.nif)) + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const countryCode = this.nif.toUpperCase().substring(0, 2); + const country = await Self.app.models.Country.findOne(filter); + const code = country ? country.code : null; + if (this.isVies && countryCode == code) err(); done(); } From d8b5659a5dd0e4fbbd48081881285ea0a9c2c1ed Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 21 Apr 2023 09:14:30 +0200 Subject: [PATCH 05/18] refs #5540 client vies --- .../{231401 => 231601}/00-updateIsVies.sql | 0 db/changes/231601/00-updateisViesClient.sql | 5 +++++ loopback/locale/es.json | 9 +++++---- modules/client/back/models/client.js | 16 ++++++++++++++++ modules/client/front/fiscal-data/index.html | 4 +++- modules/client/front/fiscal-data/locale/es.yml | 2 ++ 6 files changed, 31 insertions(+), 5 deletions(-) rename db/changes/{231401 => 231601}/00-updateIsVies.sql (100%) create mode 100644 db/changes/231601/00-updateisViesClient.sql diff --git a/db/changes/231401/00-updateIsVies.sql b/db/changes/231601/00-updateIsVies.sql similarity index 100% rename from db/changes/231401/00-updateIsVies.sql rename to db/changes/231601/00-updateIsVies.sql diff --git a/db/changes/231601/00-updateisViesClient.sql b/db/changes/231601/00-updateisViesClient.sql new file mode 100644 index 000000000..bdf62d7a8 --- /dev/null +++ b/db/changes/231601/00-updateisViesClient.sql @@ -0,0 +1,5 @@ +UPDATE IGNORE vn.client c + JOIN vn.country co ON co.id = c.countryFk + SET c.fi = MID(REPLACE(c.fi, ' ', ''), 3, LENGTH(REPLACE(c.fi, ' ', '')) - 1) + WHERE c.isVies = TRUE + AND co.code = LEFT(REPLACE(c.fi, ' ', ''), 2); \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 33741d395..1faf57ffe 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -273,7 +273,8 @@ "Not exist this branch": "La rama no existe", "This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado", "Insert a date range": "Inserte un rango de fechas", - "Added observation": "{{user}} añadió esta observacion: {{text}}", - "Comment added to client": "Observación añadida al cliente {{clientFk}}", - "Cannot create a new claimBeginning from a different ticket": "No se puede crear una línea de reclamación de un ticket diferente al origen" -} + "Added observation": "{{user}} añadió esta observacion: {{text}}", + "Comment added to client": "Observación añadida al cliente {{clientFk}}", + "Cannot create a new claimBeginning from a different ticket": "No se puede crear una línea de reclamación de un ticket diferente al origen", + "The first two values are letters": "The first two values are letters" +} \ No newline at end of file diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 7933f2f42..21dfb516d 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -23,6 +23,22 @@ module.exports = Self => { message: 'TIN must be unique' }); + Self.validateAsync('fi', fiInvalid, { + message: 'The first two values are letters'}); + + async function fiInvalid(err, done) { + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const countryCode = this.fi.toUpperCase().substring(0, 2); + const country = await Self.app.models.Country.findOne(filter); + const code = country ? country.code : null; + if (this.isVies && countryCode == code) + err(); + done(); + } + Self.validatesFormatOf('email', { message: 'Invalid email', allowNull: true, diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index 88586cff7..4b1219f31 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -72,7 +72,9 @@ - + diff --git a/modules/client/front/fiscal-data/locale/es.yml b/modules/client/front/fiscal-data/locale/es.yml index 7624c86bd..61a91828f 100644 --- a/modules/client/front/fiscal-data/locale/es.yml +++ b/modules/client/front/fiscal-data/locale/es.yml @@ -12,3 +12,5 @@ Previous client: Cliente anterior In case of a company succession, specify the grantor company: En el caso de que haya habido una sucesión de empresa, indicar la empresa cedente Incoterms authorization: Autorización incoterms Electronic invoice: Factura electrónica +When activating it, do not enter the country code in the IF.: Al activarlo, no informar el código del país en el campo IF +The first two values are letters: Los dos primeros valores son letras \ No newline at end of file From 397d8f658e1ea187d79867bbfab19c9a5fbe9403 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 21 Apr 2023 10:41:50 +0200 Subject: [PATCH 06/18] refs #5540 error trad --- modules/client/back/models/client.js | 3 ++- modules/supplier/back/models/supplier.js | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 21dfb516d..451830749 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -24,7 +24,8 @@ module.exports = Self => { }); Self.validateAsync('fi', fiInvalid, { - message: 'The first two values are letters'}); + message: 'Invalid TIN' + }); async function fiInvalid(err, done) { const filter = { diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 87f3b5d6a..7270c0405 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -73,8 +73,7 @@ module.exports = Self => { done(); } - Self.validateAsync('nif', nifInvalid, { - message: 'The first two values are letters'}); + Self.validateAsync('nif', nifInvalid); async function nifInvalid(err, done) { const filter = { From cd4f66e292118af0600563039be054e03a47f0a8 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 24 Apr 2023 08:48:35 +0200 Subject: [PATCH 07/18] refs #5540 arreglar e2e --- modules/worker/back/methods/worker/new.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index 144b07f10..5ff7135a7 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -196,7 +196,7 @@ module.exports = Self => { client = await models.Client.findById( user.id, - {fields: ['id', 'name', 'socialName', 'street', 'city', 'iban', 'bankEntityFk', 'defaultAddressFk']}, + {fields: ['id', 'name', 'socialName', 'street', 'city', 'iban', 'bankEntityFk', 'defaultAddressFk', 'fi']}, myOptions ); From dd4d0bca84a540bd2729aa67719c41a083188e02 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 27 Apr 2023 10:39:58 +0200 Subject: [PATCH 08/18] refs #5540 delete tinIsValid, solve test back, e2e --- e2e/paths/13-supplier/03_fiscal_data.spec.js | 2 +- .../supplier/specs/newSupplier.spec.js | 5 +-- modules/supplier/back/models/supplier.js | 31 ++++++++++--------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/e2e/paths/13-supplier/03_fiscal_data.spec.js b/e2e/paths/13-supplier/03_fiscal_data.spec.js index 4f9581e32..45e11fbe1 100644 --- a/e2e/paths/13-supplier/03_fiscal_data.spec.js +++ b/e2e/paths/13-supplier/03_fiscal_data.spec.js @@ -38,7 +38,7 @@ describe('Supplier fiscal data path', () => { await page.waitToClick(selectors.supplierFiscalData.saveButton); const message = await page.waitForSnackbar(); - expect(message.text).toContain('Invalid Tax number'); + expect(message.text).toContain('Data saved!'); }); it('should save the changes as the tax number is valid this time', async() => { diff --git a/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js b/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js index d4479d00b..c368ec1b8 100644 --- a/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js +++ b/modules/supplier/back/methods/supplier/specs/newSupplier.spec.js @@ -19,13 +19,14 @@ describe('Supplier newSupplier()', () => { }); }); - it('should create a new supplier containing only the name', async() => { + it('should create a new supplier containing only the name and the nif', async() => { const tx = await models.Supplier.beginTransaction({}); try { const options = {transaction: tx}; ctx.args = { - name: 'newSupplier' + name: 'newSupplier', + nif: '12345678Z' }; const result = await models.Supplier.newSupplier(ctx, options); diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 7270c0405..f30b744c4 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -32,6 +32,10 @@ module.exports = Self => { message: 'TIN must be unique' }); + Self.validateAsync('nif', nifInvalid, { + message: 'Invalid TIN' + }); + Self.validateAsync('nif', tinIsValid, { message: 'Invalid TIN' }); @@ -57,24 +61,23 @@ module.exports = Self => { done(); } - async function tinIsValid(err, done) { - if (!this.countryFk) - return done(); + // async function tinIsValid(err, done) { + // if (!this.countryFk) + // return done(); - const filter = { - fields: ['code'], - where: {id: this.countryFk} - }; - const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code.toLowerCase() : null; + // const filter = { + // fields: ['code'], + // where: {id: this.countryFk} + // }; + // const country = await Self.app.models.Country.findOne(filter); + // const code = country ? country.code.toLowerCase() : null; - if (!this.nif || !validateTin(this.nif, code)) - err(); - done(); - } + // if (!this.nif || !validateTin(this.nif, code)) + // err(); + // done(); + // } Self.validateAsync('nif', nifInvalid); - async function nifInvalid(err, done) { const filter = { fields: ['code'], From 07148f6c291c40cb5f2160c104aeecfac72e6a95 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 27 Apr 2023 11:31:26 +0200 Subject: [PATCH 09/18] refs #5540 mon message --- e2e/paths/13-supplier/03_fiscal_data.spec.js | 2 +- loopback/locale/es.json | 3 ++- modules/supplier/back/models/supplier.js | 28 ++++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/e2e/paths/13-supplier/03_fiscal_data.spec.js b/e2e/paths/13-supplier/03_fiscal_data.spec.js index 45e11fbe1..4f9581e32 100644 --- a/e2e/paths/13-supplier/03_fiscal_data.spec.js +++ b/e2e/paths/13-supplier/03_fiscal_data.spec.js @@ -38,7 +38,7 @@ describe('Supplier fiscal data path', () => { await page.waitToClick(selectors.supplierFiscalData.saveButton); const message = await page.waitForSnackbar(); - expect(message.text).toContain('Data saved!'); + expect(message.text).toContain('Invalid Tax number'); }); it('should save the changes as the tax number is valid this time', async() => { diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 696fbe18d..ca77aa77c 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -278,5 +278,6 @@ "Added observation": "{{user}} añadió esta observacion: {{text}}", "Comment added to client": "Observación añadida al cliente {{clientFk}}", "Cannot create a new claimBeginning from a different ticket": "No se puede crear una línea de reclamación de un ticket diferente al origen", - "The first two values are letters": "The first two values are letters" + "The first two values are letters": "The first two values are letters", + "NIF no valido por VIES": "NIF no valido por VIES" } \ No newline at end of file diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index f30b744c4..d543e0d48 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -33,7 +33,7 @@ module.exports = Self => { }); Self.validateAsync('nif', nifInvalid, { - message: 'Invalid TIN' + message: 'NIF no valido por VIES' }); Self.validateAsync('nif', tinIsValid, { @@ -61,21 +61,21 @@ module.exports = Self => { done(); } - // async function tinIsValid(err, done) { - // if (!this.countryFk) - // return done(); + async function tinIsValid(err, done) { + if (!this.countryFk) + return done(); - // const filter = { - // fields: ['code'], - // where: {id: this.countryFk} - // }; - // const country = await Self.app.models.Country.findOne(filter); - // const code = country ? country.code.toLowerCase() : null; + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const country = await Self.app.models.Country.findOne(filter); + const code = country ? country.code.toLowerCase() : null; - // if (!this.nif || !validateTin(this.nif, code)) - // err(); - // done(); - // } + if (!this.nif || !validateTin(this.nif, code)) + err(); + done(); + } Self.validateAsync('nif', nifInvalid); async function nifInvalid(err, done) { From d15a671359b073e378bcc61bb5098b88e804a6fe Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 27 Apr 2023 11:40:42 +0200 Subject: [PATCH 10/18] refs #5540 traduccion --- modules/supplier/back/models/supplier.js | 2 +- modules/supplier/front/locale/es.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index d543e0d48..4014aac03 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -33,7 +33,7 @@ module.exports = Self => { }); Self.validateAsync('nif', nifInvalid, { - message: 'NIF no valido por VIES' + message: 'Invalid NIF for VIES' }); Self.validateAsync('nif', tinIsValid, { diff --git a/modules/supplier/front/locale/es.yml b/modules/supplier/front/locale/es.yml index abb6a9775..a2b6dd04d 100644 --- a/modules/supplier/front/locale/es.yml +++ b/modules/supplier/front/locale/es.yml @@ -1 +1,2 @@ -Accounts: Cuentas \ No newline at end of file +Accounts: Cuentas +Invalid NIF for VIES: NIF no valido por VIES \ No newline at end of file From e1864fec092a0d1c3a8501548fd394a5f50339ad Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 27 Apr 2023 13:26:22 +0200 Subject: [PATCH 11/18] arreglo json --- loopback/locale/es.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index c0be5471e..3ef3c4a22 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -278,11 +278,6 @@ "Added observation": "{{user}} añadió esta observacion: {{text}}", "Comment added to client": "Observación añadida al cliente {{clientFk}}", "Cannot create a new claimBeginning from a different ticket": "No se puede crear una línea de reclamación de un ticket diferente al origen", -<<<<<<< HEAD - "The first two values are letters": "The first two values are letters", - "NIF no valido por VIES": "NIF no valido por VIES" -} -======= "company": "Compañía", "country": "País", "clientId": "Id cliente", @@ -296,4 +291,3 @@ "comercialId": "Id comercial", "comercialName": "Comercial" } ->>>>>>> 7f8f65567f4eb53637a1ff0c2cdbd3a93447e1ac From b8f7f7bd6955c78283c006da48e549b40740af81 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 28 Apr 2023 09:07:06 +0200 Subject: [PATCH 12/18] refs #5540 create validateIban --- loopback/util/validateNIF.js | 12 ++++++++++++ modules/client/back/models/client.js | 27 ++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 loopback/util/validateNIF.js diff --git a/loopback/util/validateNIF.js b/loopback/util/validateNIF.js new file mode 100644 index 000000000..22c10d612 --- /dev/null +++ b/loopback/util/validateNIF.js @@ -0,0 +1,12 @@ +module.exports = async function(fi) { + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const countryCode = this.fi.toUpperCase().substring(0, 2); + const country = await app.models.Country.findOne(filter); + const code = country ? country.code : null; + if (this.isVies && countryCode == code) + err(); + done(); +}; diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index c271a24e8..d51a67d05 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -4,6 +4,7 @@ const isMultiple = require('vn-loopback/util/hook').isMultiple; const validateTin = require('vn-loopback/util/validateTin'); const validateIban = require('vn-loopback/util/validateIban'); const LoopBackContext = require('loopback-context'); +const validateNIF = require('vn-loopback/util/validateNIF'); module.exports = Self => { // Methods @@ -23,22 +24,22 @@ module.exports = Self => { message: 'TIN must be unique' }); - Self.validateAsync('fi', fiInvalid, { + Self.validateAsync('fi', validateNIF(fi), { message: 'Invalid TIN' }); - async function fiInvalid(err, done) { - const filter = { - fields: ['code'], - where: {id: this.countryFk} - }; - const countryCode = this.fi.toUpperCase().substring(0, 2); - const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code : null; - if (this.isVies && countryCode == code) - err(); - done(); - } + // async function fiInvalid(err, done) { + // const filter = { + // fields: ['code'], + // where: {id: this.countryFk} + // }; + // const countryCode = this.fi.toUpperCase().substring(0, 2); + // const country = await Self.app.models.Country.findOne(filter); + // const code = country ? country.code : null; + // if (this.isVies && countryCode == code) + // err(); + // done(); + // } Self.validatesFormatOf('email', { message: 'Invalid email', From cdbbec9d36619a3c8e4db4ff06c9ba2504f8cda2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 28 Apr 2023 10:21:54 +0200 Subject: [PATCH 13/18] refs #5540 validate --- loopback/util/validateNIF.js | 16 +++++++++------- modules/client/back/models/client.js | 12 +++++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/loopback/util/validateNIF.js b/loopback/util/validateNIF.js index 22c10d612..041ca8876 100644 --- a/loopback/util/validateNIF.js +++ b/loopback/util/validateNIF.js @@ -1,12 +1,14 @@ -module.exports = async function(fi) { +const models = require('vn-loopback/server/server').models; +module.exports = async function(fi, isVies, countryFk) { const filter = { fields: ['code'], - where: {id: this.countryFk} + where: {id: countryFk} }; - const countryCode = this.fi.toUpperCase().substring(0, 2); - const country = await app.models.Country.findOne(filter); + const countryCode = fi.toUpperCase().substring(0, 2); + const country = await models.Country.findOne(filter); const code = country ? country.code : null; - if (this.isVies && countryCode == code) - err(); - done(); + if (isVies && countryCode == code) + return false; + return true; }; + diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index d51a67d05..972355e3e 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -24,7 +24,7 @@ module.exports = Self => { message: 'TIN must be unique' }); - Self.validateAsync('fi', validateNIF(fi), { + Self.validateAsync(validateNIF(this.fi, this.isVies, this.countryFk), { message: 'Invalid TIN' }); @@ -93,6 +93,16 @@ module.exports = Self => { done(); } + Self.validateAsync('fi', validationNIF, { + message: 'El NIF es incorrecto por el Vies' + }); + + async function validationNIF(err, done){ + if (!validateNIF(this.fi, this.isVies, this.countryFk)) + err(); + done(); + } + Self.validateAsync('fi', tinIsValid, { message: 'Invalid TIN' }); From 38142c121dd97755b3202c2264015d248bcf54f6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 28 Apr 2023 12:12:26 +0200 Subject: [PATCH 14/18] refs #5540 mods client --- loopback/locale/es.json | 25 +++++++++++++------------ modules/client/back/models/client.js | 6 +----- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 3ef3c4a22..45993bdd5 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -279,15 +279,16 @@ "Comment added to client": "Observación añadida al cliente {{clientFk}}", "Cannot create a new claimBeginning from a different ticket": "No se puede crear una línea de reclamación de un ticket diferente al origen", "company": "Compañía", - "country": "País", - "clientId": "Id cliente", - "clientSocialName": "Cliente", - "amount": "Importe", - "taxableBase": "Base", - "ticketFk": "Id ticket", - "isActive": "Activo", - "hasToInvoice": "Facturar", - "isTaxDataChecked": "Datos comprobados", - "comercialId": "Id comercial", - "comercialName": "Comercial" -} + "country": "País", + "clientId": "Id cliente", + "clientSocialName": "Cliente", + "amount": "Importe", + "taxableBase": "Base", + "ticketFk": "Id ticket", + "isActive": "Activo", + "hasToInvoice": "Facturar", + "isTaxDataChecked": "Datos comprobados", + "comercialId": "Id comercial", + "comercialName": "Comercial", + "Invalid NIF for VIES": "Invalid NIF for VIES" +} \ No newline at end of file diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 972355e3e..d3022af81 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -24,10 +24,6 @@ module.exports = Self => { message: 'TIN must be unique' }); - Self.validateAsync(validateNIF(this.fi, this.isVies, this.countryFk), { - message: 'Invalid TIN' - }); - // async function fiInvalid(err, done) { // const filter = { // fields: ['code'], @@ -102,7 +98,7 @@ module.exports = Self => { err(); done(); } - + Self.validateAsync('fi', tinIsValid, { message: 'Invalid TIN' }); From c0deb745d64faad1903cb0f044c4b3b4ec95070e Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 28 Apr 2023 14:03:21 +0200 Subject: [PATCH 15/18] refs #5540 arreglo en supplier --- modules/client/back/models/client.js | 24 ++++++++++++------------ modules/supplier/back/models/supplier.js | 21 ++------------------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index d3022af81..e04c4478f 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -24,18 +24,18 @@ module.exports = Self => { message: 'TIN must be unique' }); - // async function fiInvalid(err, done) { - // const filter = { - // fields: ['code'], - // where: {id: this.countryFk} - // }; - // const countryCode = this.fi.toUpperCase().substring(0, 2); - // const country = await Self.app.models.Country.findOne(filter); - // const code = country ? country.code : null; - // if (this.isVies && countryCode == code) - // err(); - // done(); - // } + async function fiInvalid(err, done) { + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const countryCode = this.fi.toUpperCase().substring(0, 2); + const country = await Self.app.models.Country.findOne(filter); + const code = country ? country.code : null; + if (this.isVies && countryCode == code) + err(); + done(); + } Self.validatesFormatOf('email', { message: 'Invalid email', diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 4014aac03..ae3eb4bcc 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -32,10 +32,6 @@ module.exports = Self => { message: 'TIN must be unique' }); - Self.validateAsync('nif', nifInvalid, { - message: 'Invalid NIF for VIES' - }); - Self.validateAsync('nif', tinIsValid, { message: 'Invalid TIN' }); @@ -71,22 +67,9 @@ module.exports = Self => { }; const country = await Self.app.models.Country.findOne(filter); const code = country ? country.code.toLowerCase() : null; + const countryCode = this.nif.toLowerCase().substring(0, 2); - if (!this.nif || !validateTin(this.nif, code)) - err(); - done(); - } - - Self.validateAsync('nif', nifInvalid); - async function nifInvalid(err, done) { - const filter = { - fields: ['code'], - where: {id: this.countryFk} - }; - const countryCode = this.nif.toUpperCase().substring(0, 2); - const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code : null; - if (this.isVies && countryCode == code) + if (!this.nif || !validateTin(this.nif, code) || (this.isVies && countryCode == code)) err(); done(); } From 0e0db960afcd3aa0e921823387fb3acca986bdf1 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 28 Apr 2023 14:23:44 +0200 Subject: [PATCH 16/18] refs #5540 supplier --- loopback/util/validateNIF.js | 14 ------------ modules/client/back/models/client.js | 33 ++++++---------------------- 2 files changed, 7 insertions(+), 40 deletions(-) delete mode 100644 loopback/util/validateNIF.js diff --git a/loopback/util/validateNIF.js b/loopback/util/validateNIF.js deleted file mode 100644 index 041ca8876..000000000 --- a/loopback/util/validateNIF.js +++ /dev/null @@ -1,14 +0,0 @@ -const models = require('vn-loopback/server/server').models; -module.exports = async function(fi, isVies, countryFk) { - const filter = { - fields: ['code'], - where: {id: countryFk} - }; - const countryCode = fi.toUpperCase().substring(0, 2); - const country = await models.Country.findOne(filter); - const code = country ? country.code : null; - if (isVies && countryCode == code) - return false; - return true; -}; - diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index e04c4478f..c95d0972f 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -4,7 +4,7 @@ const isMultiple = require('vn-loopback/util/hook').isMultiple; const validateTin = require('vn-loopback/util/validateTin'); const validateIban = require('vn-loopback/util/validateIban'); const LoopBackContext = require('loopback-context'); -const validateNIF = require('vn-loopback/util/validateNIF'); +const { ConsoleReporter } = require('jasmine'); module.exports = Self => { // Methods @@ -24,19 +24,6 @@ module.exports = Self => { message: 'TIN must be unique' }); - async function fiInvalid(err, done) { - const filter = { - fields: ['code'], - where: {id: this.countryFk} - }; - const countryCode = this.fi.toUpperCase().substring(0, 2); - const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code : null; - if (this.isVies && countryCode == code) - err(); - done(); - } - Self.validatesFormatOf('email', { message: 'Invalid email', allowNull: true, @@ -89,16 +76,6 @@ module.exports = Self => { done(); } - Self.validateAsync('fi', validationNIF, { - message: 'El NIF es incorrecto por el Vies' - }); - - async function validationNIF(err, done){ - if (!validateNIF(this.fi, this.isVies, this.countryFk)) - err(); - done(); - } - Self.validateAsync('fi', tinIsValid, { message: 'Invalid TIN' }); @@ -112,9 +89,13 @@ module.exports = Self => { where: {id: this.countryFk} }; const country = await Self.app.models.Country.findOne(filter); + console.log(country); const code = country ? country.code.toLowerCase() : null; - - if (!this.fi || !validateTin(this.fi, code)) + console.log(code); + const countryCode = this.fi.toLowerCase().substring(0, 2); + console.log(countryCode); + + if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) err(); done(); } From fb59371d54e1e91485ec56062b3b3e6676a84b5c Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 28 Apr 2023 14:38:49 +0200 Subject: [PATCH 17/18] refs #5540 quit logs --- modules/client/back/models/client.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index c95d0972f..3ca6254e1 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -89,12 +89,9 @@ module.exports = Self => { where: {id: this.countryFk} }; const country = await Self.app.models.Country.findOne(filter); - console.log(country); const code = country ? country.code.toLowerCase() : null; - console.log(code); const countryCode = this.fi.toLowerCase().substring(0, 2); - console.log(countryCode); - + if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) err(); done(); From 8156c17c7df4ba373ae142e988181d5314bbde56 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 2 May 2023 10:00:47 +0200 Subject: [PATCH 18/18] refs #5540 del jasmine --- modules/client/back/models/client.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 3ca6254e1..56adc8b03 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -4,7 +4,6 @@ const isMultiple = require('vn-loopback/util/hook').isMultiple; const validateTin = require('vn-loopback/util/validateTin'); const validateIban = require('vn-loopback/util/validateIban'); const LoopBackContext = require('loopback-context'); -const { ConsoleReporter } = require('jasmine'); module.exports = Self => { // Methods @@ -15,7 +14,7 @@ module.exports = Self => { Self.validatesPresenceOf('street', { message: 'Street cannot be empty' }); - + Self.validatesPresenceOf('city', { message: 'City cannot be empty' });