diff --git a/db/changes/231601/00-updateIsVies.sql b/db/changes/231601/00-updateIsVies.sql new file mode 100644 index 000000000..83fde7352 --- /dev/null +++ b/db/changes/231601/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/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 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 a86a782e4..56adc8b03 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -14,7 +14,7 @@ module.exports = Self => { Self.validatesPresenceOf('street', { message: 'Street cannot be empty' }); - + Self.validatesPresenceOf('city', { message: 'City cannot be empty' }); @@ -89,8 +89,9 @@ module.exports = Self => { }; const country = await Self.app.models.Country.findOne(filter); const code = country ? country.code.toLowerCase() : null; + const countryCode = this.fi.toLowerCase().substring(0, 2); - if (!this.fi || !validateTin(this.fi, code)) + if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) err(); done(); } 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 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 c4ce0c517..ae3eb4bcc 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -67,8 +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)) + if (!this.nif || !validateTin(this.nif, code) || (this.isVies && countryCode == code)) err(); done(); } diff --git a/modules/supplier/front/fiscal-data/index.html b/modules/supplier/front/fiscal-data/index.html index 3c5f64dcf..3a0aefbf2 100644 --- a/modules/supplier/front/fiscal-data/index.html +++ b/modules/supplier/front/fiscal-data/index.html @@ -54,7 +54,8 @@ name="taxNumber" ng-model="$ctrl.supplier.nif" required="true" - rule> + rule + > @@ -210,7 +211,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 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 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 );