From 117849f09395aee737df62efbd1a615907252bc1 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 12 Apr 2023 12:03:55 +0200 Subject: [PATCH] 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