From ef6af87d892a3747b8858d5797ad5bd79f280a1f Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 18 Nov 2022 09:21:21 +0100 Subject: [PATCH 1/6] feat: add supplier.isVies funcionality --- .../10503-november/00-supplierIsVies.sql | 3 + .../10503-november/01-sage_supplierAdd.sql | 124 ++++++++++++++++++ .../back/methods/supplier/updateFiscalData.js | 7 +- modules/supplier/back/models/supplier.json | 5 +- modules/supplier/front/fiscal-data/index.html | 23 ++-- 5 files changed, 152 insertions(+), 10 deletions(-) create mode 100644 db/changes/10503-november/00-supplierIsVies.sql create mode 100644 db/changes/10503-november/01-sage_supplierAdd.sql diff --git a/db/changes/10503-november/00-supplierIsVies.sql b/db/changes/10503-november/00-supplierIsVies.sql new file mode 100644 index 000000000..e1911a7b7 --- /dev/null +++ b/db/changes/10503-november/00-supplierIsVies.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`supplier` ADD `isVies` tinyint(4) DEFAULT 0 NOT NULL; + +/*FALTA HACER EL UPDATE MASIVO SOBRE SUPPLIER */ diff --git a/db/changes/10503-november/01-sage_supplierAdd.sql b/db/changes/10503-november/01-sage_supplierAdd.sql new file mode 100644 index 000000000..e678fa2f0 --- /dev/null +++ b/db/changes/10503-november/01-sage_supplierAdd.sql @@ -0,0 +1,124 @@ +CREATE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`(vCompanyFk INT) +BEGIN +/** + * Prepara los datos de clientes y proveedores para exportarlos a Sage + * @vCompanyFk Empresa dela que se quiere trasladar datos + */ + DECLARE vCountryCeutaMelillaFk INT; + DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2); + + SELECT SiglaNacion INTO vCountryCanariasCode + FROM Naciones + WHERE Nacion ='ISLAS CANARIAS'; + + SELECT CodigoNacion, SiglaNacion INTO vCountryCeutaMelillaFk, vCountryCeutaMelillaCode + FROM Naciones + WHERE Nacion ='CEUTA Y MELILLA'; + + TRUNCATE TABLE clientesProveedores; + + INSERT INTO clientesProveedores + (CodigoEmpresa, + ClienteOProveedor, + CodigoClienteProveedor, + RazonSocial, + Nombre, + Domicilio, + CodigoCuenta, + CifDni, + CifEuropeo, + CodigoPostal, + Municipio, + CodigoProvincia, + Provincia, + CodigoNacion, + SiglaNacion, + PersonaFisicaJuridica, + TipoDocumentoPersona, + CodigoIva, + Nacion, + Telefono, + Telefono2, + CodigoTransaccion, + CodigoRetencion, + Email1, + iban) + SELECT + company_getCode(vCompanyFk), + 'C', + c.id, + c.socialName, + c.socialName, + IFNULL(c.street, ''), + c.accountingAccount, + TRIM(IF(cu.code = LEFT(c.fi, 2), MID(c.fi, 3, LENGTH(c.fi)-1), c.fi)), + IF(n.NacionCEE,TRIM(IF(cu.code = LEFT(c.fi, 2), c.fi, CONCAT(cu.code,c.fi))) , ''), + IFNULL(c.postcode, ''), + IFNULL(c.city, ''), + IFNULL(pr.CodigoProvincia, ''), + IFNULL(p.name, ''), + IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, IF(@isCeutaMelilla := IF(pr.Provincia IN ('CEUTA', 'MELILLA'), TRUE, FALSE), vCountryCeutaMelillaFk, IF (@isCanarias, vCountryCanariasCode, n.CodigoNacion)), n.CodigoNacion), + IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, IF(@isCeutaMelilla, vCountryCeutaMelillaCode, IF (@isCanarias, vCountryCanariasCode, n.SiglaNacion)), n.SiglaNacion), + IF((c.fi REGEXP '^([[:blank:]]|[[:digit:]])'), 'J','F'), + IF(cu.code IN('ES','EX'), + 1, + IF((cu.isUeeMember AND c.isVies), 2, 4)), + IFNULL(c.taxTypeSageFk,0), + IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, + IF(@isCeutaMelilla, 'CEUTA Y MELILLA', IF (@isCanarias, 'ISLAS CANARIAS', n.Nacion)), + n.Nacion), + IFNULL(c.phone, ''), + IFNULL(c.mobile, ''), + IFNULL(c.transactionTypeSageFk, 0), + '0', + IFNULL(SUBSTR(c.email, 1, LOCATE(',', CONCAT(c.email, ','))-1), ''), + IFNULL(c.iban, '') + FROM vn.`client` c + JOIN clientLastTwoMonths clm ON clm.clientFk = c.id + LEFT JOIN vn.country cu ON cu.id = c.countryFk + LEFT JOIN Naciones n ON n.countryFk = cu.id + LEFT JOIN vn.province p ON p.id = c.provinceFk + LEFT JOIN Provincias pr ON pr.provinceFk = p.id + WHERE c.isRelevant + AND clm.companyFk = vCompanyFk + UNION ALL + SELECT company_getCode(vCompanyFk), + 'P', + s.id, + s.name, + s.name, + IFNULL(s.street, ''), + s.account, + TRIM(IF(co.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif) - 1), s.nif)), + IF(n.NacionCEE, TRIM(CONCAT(co.code, IF(co.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif) - 1), s.nif))), ''), + IFNULL(s.postCode,''), + IFNULL(s.city, ''), + IFNULL(pr.CodigoProvincia, ''), + IFNULL(p.name, ''), + n.CodigoNacion, + n.SiglaNacion COLLATE utf8mb3_unicode_ci, + IF((s.nif REGEXP '^([[:blank:]]|[[:digit:]])'),'J','F'), + IF(co.code IN('ES','EX'), + 1, + IF((co.isUeeMember AND s.isVies), 2, 4)), + IFNULL(s.taxTypeSageFk, 0), + n.Nacion, + IFNULL(sc.phone, ''), + IFNULL(sc.mobile, ''), + IFNULL(s.transactionTypeSageFk, 0), + IFNULL(s.withholdingSageFk, '0'), + IFNULL(SUBSTR(sc.email, 1, (COALESCE(NULLIF(LOCATE(',', sc.email), 0), 99) - 1)), ''), + IFNULL(iban, '') + FROM vn.supplier s + JOIN supplierLastThreeMonths pl ON pl.supplierFk = s.id + LEFT JOIN vn.country co ON co.id = s.countryFk + LEFT JOIN Naciones n ON n.countryFk = co.id + LEFT JOIN vn.province p ON p.id = s.provinceFk + LEFT JOIN Provincias pr ON pr.provinceFk = p.id + LEFT JOIN vn.supplierContact sc ON sc.supplierFk = s.id + LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id + WHERE pl.companyFk = vCompanyFk AND + s.isActive AND + s.nif <> '' + GROUP BY pl.supplierFk, pl.companyFk; +END diff --git a/modules/supplier/back/methods/supplier/updateFiscalData.js b/modules/supplier/back/methods/supplier/updateFiscalData.js index 4604b3f91..51e02bf94 100644 --- a/modules/supplier/back/methods/supplier/updateFiscalData.js +++ b/modules/supplier/back/methods/supplier/updateFiscalData.js @@ -64,7 +64,12 @@ module.exports = Self => { { arg: 'healthRegister', type: 'string' - }], + }, + { + arg: 'isVies', + type: 'boolean' + } + ], returns: { arg: 'res', type: 'string', diff --git a/modules/supplier/back/models/supplier.json b/modules/supplier/back/models/supplier.json index 3cd6386a8..ee2c4fbbd 100644 --- a/modules/supplier/back/models/supplier.json +++ b/modules/supplier/back/models/supplier.json @@ -110,6 +110,9 @@ }, "healthRegister": { "type": "string" + }, + "isVies": { + "type": "boolean" } }, "relations": { @@ -175,4 +178,4 @@ "foreignKey": "supplierActivityFk" } } -} \ No newline at end of file +} diff --git a/modules/supplier/front/fiscal-data/index.html b/modules/supplier/front/fiscal-data/index.html index a3ede2058..ccbd5b0d9 100644 --- a/modules/supplier/front/fiscal-data/index.html +++ b/modules/supplier/front/fiscal-data/index.html @@ -129,7 +129,7 @@ show-field="code" rule> - {{code}} - {{town.name}} ({{town.province.name}}, + {{code}} - {{town.name}} ({{town.province.name}}, {{town.province.country.country}}) @@ -144,7 +144,7 @@ - - - - + + + + + + @@ -203,4 +210,4 @@ - \ No newline at end of file + From 7e98a255b847838f9338dc9360b5d069169869fc Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 21 Nov 2022 08:11:01 +0100 Subject: [PATCH 2/6] refs #4849 SQL --- db/changes/10503-november/00-supplierIsVies.sql | 15 ++++++++++++++- db/changes/10503-november/01-sage_supplierAdd.sql | 15 +++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/db/changes/10503-november/00-supplierIsVies.sql b/db/changes/10503-november/00-supplierIsVies.sql index e1911a7b7..0af1a61ab 100644 --- a/db/changes/10503-november/00-supplierIsVies.sql +++ b/db/changes/10503-november/00-supplierIsVies.sql @@ -1,3 +1,16 @@ ALTER TABLE `vn`.`supplier` ADD `isVies` tinyint(4) DEFAULT 0 NOT NULL; -/*FALTA HACER EL UPDATE MASIVO SOBRE SUPPLIER */ +UPDATE `vn`.`supplier` s + JOIN vn.country c ON c.id = s.countryFk + SET s.nif = MID(s.nif, 3, LENGTH(s.nif)-1), s.isVies = TRUE +WHERE s.nif <> TRIM(IF(c.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif)-1), s.nif)); + +INSERT IGNORE INTO `vn`.`chat` +(senderFk, recipient, checkUserStatus, message, status, attempts) +VALUES(19294, '#informatica-cau', 0, ' +``` +UPDATE `vn`.`supplier` s + JOIN vn.country c ON c.id = s.countryFk + SET s.nif = MID(s.nif, 3, LENGTH(s.nif)-1), s.isVies = TRUE +WHERE s.nif <> TRIM(IF(c.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif)-1), s.nif)); +```', 0, 0); diff --git a/db/changes/10503-november/01-sage_supplierAdd.sql b/db/changes/10503-november/01-sage_supplierAdd.sql index e678fa2f0..cd68ebfcb 100644 --- a/db/changes/10503-november/01-sage_supplierAdd.sql +++ b/db/changes/10503-november/01-sage_supplierAdd.sql @@ -1,3 +1,7 @@ +DROP PROCEDURE IF EXISTS `sage`.`clientSupplier_add`; + +DELIMITER $$ +$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`(vCompanyFk INT) BEGIN /** @@ -51,7 +55,7 @@ BEGIN c.socialName, IFNULL(c.street, ''), c.accountingAccount, - TRIM(IF(cu.code = LEFT(c.fi, 2), MID(c.fi, 3, LENGTH(c.fi)-1), c.fi)), + TRIM(IF(c.isVies, CONCAT(cu.code,c.fi), c.fi)), IF(n.NacionCEE,TRIM(IF(cu.code = LEFT(c.fi, 2), c.fi, CONCAT(cu.code,c.fi))) , ''), IFNULL(c.postcode, ''), IFNULL(c.city, ''), @@ -89,7 +93,7 @@ BEGIN s.name, IFNULL(s.street, ''), s.account, - TRIM(IF(co.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif) - 1), s.nif)), + TRIM(IF(s.isVies, CONCAT(co.code,c.fi), s.nif)), IF(n.NacionCEE, TRIM(CONCAT(co.code, IF(co.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif) - 1), s.nif))), ''), IFNULL(s.postCode,''), IFNULL(s.city, ''), @@ -98,9 +102,7 @@ BEGIN n.CodigoNacion, n.SiglaNacion COLLATE utf8mb3_unicode_ci, IF((s.nif REGEXP '^([[:blank:]]|[[:digit:]])'),'J','F'), - IF(co.code IN('ES','EX'), - 1, - IF((co.isUeeMember AND s.isVies), 2, 4)), + IF(co.country IN ('España', 'España exento'), 1,IF(co.isUeeMember = 1, 2, 4)), IFNULL(s.taxTypeSageFk, 0), n.Nacion, IFNULL(sc.phone, ''), @@ -121,4 +123,5 @@ BEGIN s.isActive AND s.nif <> '' GROUP BY pl.supplierFk, pl.companyFk; -END +END$$ +DELIMITER ; From 4228c1e49c2e2bd9279d051a58bd2fb2240f9850 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 24 Jan 2023 08:02:42 +0100 Subject: [PATCH 3/6] change c.fi to s.nif --- db/changes/10503-november/01-sage_supplierAdd.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/10503-november/01-sage_supplierAdd.sql b/db/changes/10503-november/01-sage_supplierAdd.sql index cd68ebfcb..66cb0aff1 100644 --- a/db/changes/10503-november/01-sage_supplierAdd.sql +++ b/db/changes/10503-november/01-sage_supplierAdd.sql @@ -93,7 +93,7 @@ BEGIN s.name, IFNULL(s.street, ''), s.account, - TRIM(IF(s.isVies, CONCAT(co.code,c.fi), s.nif)), + TRIM(IF(s.isVies, CONCAT(co.code,s.nif), s.nif)), IF(n.NacionCEE, TRIM(CONCAT(co.code, IF(co.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif) - 1), s.nif))), ''), IFNULL(s.postCode,''), IFNULL(s.city, ''), From 5ecf55a1e7be056f9398019b19c1ea09806bd901 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 15 Feb 2023 09:51:27 +0100 Subject: [PATCH 4/6] movida sql a carpeta changes actual --- db/changes/{224903 => 230401}/00-supplierIsVies.sql | 0 db/changes/{224903 => 230401}/01-sage_supplierAdd.sql | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename db/changes/{224903 => 230401}/00-supplierIsVies.sql (100%) rename db/changes/{224903 => 230401}/01-sage_supplierAdd.sql (100%) diff --git a/db/changes/224903/00-supplierIsVies.sql b/db/changes/230401/00-supplierIsVies.sql similarity index 100% rename from db/changes/224903/00-supplierIsVies.sql rename to db/changes/230401/00-supplierIsVies.sql diff --git a/db/changes/224903/01-sage_supplierAdd.sql b/db/changes/230401/01-sage_supplierAdd.sql similarity index 100% rename from db/changes/224903/01-sage_supplierAdd.sql rename to db/changes/230401/01-sage_supplierAdd.sql From fda428d73e9b1e28d09cb25ee700453ef901de50 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 15 Feb 2023 09:52:35 +0100 Subject: [PATCH 5/6] refactor: change user --- db/changes/230401/00-supplierIsVies.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/230401/00-supplierIsVies.sql b/db/changes/230401/00-supplierIsVies.sql index 0af1a61ab..5861e7615 100644 --- a/db/changes/230401/00-supplierIsVies.sql +++ b/db/changes/230401/00-supplierIsVies.sql @@ -7,7 +7,7 @@ WHERE s.nif <> TRIM(IF(c.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif)-1), INSERT IGNORE INTO `vn`.`chat` (senderFk, recipient, checkUserStatus, message, status, attempts) -VALUES(19294, '#informatica-cau', 0, ' +VALUES(19263, '#informatica-cau', 0, ' ``` UPDATE `vn`.`supplier` s JOIN vn.country c ON c.id = s.countryFk From 77c454f95330a836c2593ff9839d96fd8b925f61 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 17 Feb 2023 10:45:08 +0100 Subject: [PATCH 6/6] move sql changes and add changelog --- CHANGELOG.md | 2 +- db/changes/{230401 => 230801}/00-supplierIsVies.sql | 0 db/changes/{230401 => 230801}/01-sage_supplierAdd.sql | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename db/changes/{230401 => 230801}/00-supplierIsVies.sql (100%) rename db/changes/{230401 => 230801}/01-sage_supplierAdd.sql (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80fa1fb95..53779316a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2308.01] - 2023-03-09 ### Added -- +- (Proveedores -> Datos fiscales) Añadido checkbox 'Vies' ### Changed - diff --git a/db/changes/230401/00-supplierIsVies.sql b/db/changes/230801/00-supplierIsVies.sql similarity index 100% rename from db/changes/230401/00-supplierIsVies.sql rename to db/changes/230801/00-supplierIsVies.sql diff --git a/db/changes/230401/01-sage_supplierAdd.sql b/db/changes/230801/01-sage_supplierAdd.sql similarity index 100% rename from db/changes/230401/01-sage_supplierAdd.sql rename to db/changes/230801/01-sage_supplierAdd.sql