From c46e7227e75f26a6c938b3bd7586bf2c0e4c1a45 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 21 Mar 2024 10:40:30 +0100 Subject: [PATCH 1/7] feat: #7013 solo muestra clientes asegurados --- .../vn/procedures/solunionRiskRequest.sql | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/db/routines/vn/procedures/solunionRiskRequest.sql b/db/routines/vn/procedures/solunionRiskRequest.sql index b735bea33..540f52e18 100644 --- a/db/routines/vn/procedures/solunionRiskRequest.sql +++ b/db/routines/vn/procedures/solunionRiskRequest.sql @@ -1,31 +1,41 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`() BEGIN - - DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; CREATE TEMPORARY TABLE tmp.client_list - (PRIMARY KEY (Id_Cliente)) - ENGINE = MEMORY - SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc - JOIN vn.creditInsurance ci ON cc.id = ci.creditClassification - WHERE dateEnd IS NULL - ORDER BY ci.creationDate DESC - LIMIT 10000000000000000000) t1 GROUP BY Id_Cliente; - + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT * FROM ( + SELECT cc.client, ci.grade + FROM creditClassification cc + JOIN creditInsurance ci ON cc.id = ci.creditClassification + WHERE dateEnd IS NULL + ORDER BY ci.creationDate DESC + LIMIT 10000000000000000000) t1 + GROUP BY client; + CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); - - SELECT - c.Id_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo, - cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo, - f.Consumo consumo_anual, c.Vencimiento, ci.grade - FROM - vn2008.Clientes c - JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente - JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente - JOIN bi.facturacion_media_anual f ON c.Id_Cliente = f.Id_Cliente - GROUP BY Id_cliente; - - DROP TEMPORARY TABLE IF EXISTS tmp.risk; + + SELECT + c.id, + c.name, + c.credit clientCredit, + c.creditInsurance solunion, + cast(r.risk as DECIMAL(10,0)) risk, + cast(c.creditInsurance - r.risk as decimal(10,0)) riskAlive, + cac.invoiced billedAnnually, + c.dueDay, + ci.grade, + c2.country + FROM tmp.client_list ci + LEFT JOIN tmp.risk r ON r.Id_Cliente = ci.client + JOIN client c ON c.id = ci.client + JOIN bs.clientAnnualConsumption cac ON c.id = cac.Id_Cliente + JOIN vn.country c2 ON c2.id = c.countryFk + GROUP BY c.id; + + DROP TEMPORARY TABLE IF EXISTS tmp.risk; DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END$$ DELIMITER ; -- 2.40.1 From a24d38128b255ff8d1a178155dc3c7cc90d15e7a Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 21 Mar 2024 10:48:43 +0100 Subject: [PATCH 2/7] feat: #7013 muestra solo clientes asegurados --- .../vn/procedures/solunionRiskRequest.sql | 63 +++++++++---------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/db/routines/vn/procedures/solunionRiskRequest.sql b/db/routines/vn/procedures/solunionRiskRequest.sql index 540f52e18..6b51c4202 100644 --- a/db/routines/vn/procedures/solunionRiskRequest.sql +++ b/db/routines/vn/procedures/solunionRiskRequest.sql @@ -2,40 +2,39 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`() BEGIN - DROP TEMPORARY TABLE IF EXISTS tmp.client_list; - CREATE TEMPORARY TABLE tmp.client_list - (PRIMARY KEY (Id_Cliente)) - ENGINE = MEMORY - SELECT * FROM ( - SELECT cc.client, ci.grade - FROM creditClassification cc - JOIN creditInsurance ci ON cc.id = ci.creditClassification - WHERE dateEnd IS NULL - ORDER BY ci.creationDate DESC - LIMIT 10000000000000000000) t1 - GROUP BY client; + CREATE OR REPLACE TEMPORARY TABLE tmp.client_list + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT * FROM ( + SELECT cc.client Id_Cliente, ci.grade + FROM creditClassification cc + JOIN creditInsurance ci ON cc.id = ci.creditClassification + WHERE dateEnd IS NULL + ORDER BY ci.creationDate DESC + LIMIT 10000000000000000000) t1 + GROUP BY Id_Cliente; - CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); + CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); - SELECT - c.id, - c.name, - c.credit clientCredit, - c.creditInsurance solunion, - cast(r.risk as DECIMAL(10,0)) risk, - cast(c.creditInsurance - r.risk as decimal(10,0)) riskAlive, - cac.invoiced billedAnnually, - c.dueDay, - ci.grade, - c2.country - FROM tmp.client_list ci - LEFT JOIN tmp.risk r ON r.Id_Cliente = ci.client - JOIN client c ON c.id = ci.client - JOIN bs.clientAnnualConsumption cac ON c.id = cac.Id_Cliente - JOIN vn.country c2 ON c2.id = c.countryFk - GROUP BY c.id; + SELECT + c.id, + c.name, + c.credit clientCredit, + c.creditInsurance solunion, + cast(r.risk as DECIMAL(10,0)) risk, + cast(c.creditInsurance - r.risk as decimal(10,0)) riskAlive, + cac.invoiced billedAnnually, + c.dueDay, + ci.grade, + c2.country + FROM tmp.client_list ci + LEFT JOIN tmp.risk r ON r.Id_Cliente = ci.Id_Cliente + JOIN client c ON c.id = ci.Id_Cliente + JOIN bs.clientAnnualConsumption cac ON c.id = cac.clientFk + JOIN vn.country c2 ON c2.id = c.countryFk + GROUP BY c.id; - DROP TEMPORARY TABLE IF EXISTS tmp.risk; - DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + DROP TEMPORARY TABLE IF EXISTS tmp.risk; + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END$$ DELIMITER ; -- 2.40.1 From 8d258254d0ada153524acdfc51d8a7afa0a3aa8d Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 25 Mar 2024 07:52:40 +0100 Subject: [PATCH 3/7] feat: #7013 change name procedure --- ...solunionRiskRequest.sql => creditInsurance_getRisk.sql} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename db/routines/vn/procedures/{solunionRiskRequest.sql => creditInsurance_getRisk.sql} (88%) diff --git a/db/routines/vn/procedures/solunionRiskRequest.sql b/db/routines/vn/procedures/creditInsurance_getRisk.sql similarity index 88% rename from db/routines/vn/procedures/solunionRiskRequest.sql rename to db/routines/vn/procedures/creditInsurance_getRisk.sql index 6b51c4202..4a54c0f7f 100644 --- a/db/routines/vn/procedures/solunionRiskRequest.sql +++ b/db/routines/vn/procedures/creditInsurance_getRisk.sql @@ -1,7 +1,10 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditInsurance_getRisk`() BEGIN - + /** + * Devuelve el riesgo de los clientes que estan asegurados + * + */ CREATE OR REPLACE TEMPORARY TABLE tmp.client_list (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY -- 2.40.1 From 04117d2c277fa9ac9b6fc1e59433962579d1e284 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 10:13:10 +0100 Subject: [PATCH 4/7] fix: #7013 quito vn. --- db/routines/vn/procedures/creditInsurance_getRisk.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/creditInsurance_getRisk.sql b/db/routines/vn/procedures/creditInsurance_getRisk.sql index 4a54c0f7f..60c272a02 100644 --- a/db/routines/vn/procedures/creditInsurance_getRisk.sql +++ b/db/routines/vn/procedures/creditInsurance_getRisk.sql @@ -34,7 +34,7 @@ BEGIN LEFT JOIN tmp.risk r ON r.Id_Cliente = ci.Id_Cliente JOIN client c ON c.id = ci.Id_Cliente JOIN bs.clientAnnualConsumption cac ON c.id = cac.clientFk - JOIN vn.country c2 ON c2.id = c.countryFk + JOIN country c2 ON c2.id = c.countryFk GROUP BY c.id; DROP TEMPORARY TABLE IF EXISTS tmp.risk; -- 2.40.1 From 587dd8f4d9ec4156831a7493abf42d9213e8d348 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 26 Mar 2024 12:12:27 +0100 Subject: [PATCH 5/7] feat: #7013 sin tabular --- db/routines/vn/procedures/creditInsurance_getRisk.sql | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/creditInsurance_getRisk.sql b/db/routines/vn/procedures/creditInsurance_getRisk.sql index 60c272a02..16d96f577 100644 --- a/db/routines/vn/procedures/creditInsurance_getRisk.sql +++ b/db/routines/vn/procedures/creditInsurance_getRisk.sql @@ -1,10 +1,9 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditInsurance_getRisk`() BEGIN - /** - * Devuelve el riesgo de los clientes que estan asegurados - * - */ +/** +* Devuelve el riesgo de los clientes que estan asegurados +*/ CREATE OR REPLACE TEMPORARY TABLE tmp.client_list (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY -- 2.40.1 From 4b41ac68aa71ea5b39b1197ad08ae99ed19cbde4 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 27 Mar 2024 08:05:33 +0100 Subject: [PATCH 6/7] feat: #7013 en mayusculas y con espacio en comentarios --- db/routines/vn/procedures/creditInsurance_getRisk.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/creditInsurance_getRisk.sql b/db/routines/vn/procedures/creditInsurance_getRisk.sql index 16d96f577..8028dc5fb 100644 --- a/db/routines/vn/procedures/creditInsurance_getRisk.sql +++ b/db/routines/vn/procedures/creditInsurance_getRisk.sql @@ -2,8 +2,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditInsurance_getRisk`() BEGIN /** -* Devuelve el riesgo de los clientes que estan asegurados -*/ + * Devuelve el riesgo de los clientes que estan asegurados + */ CREATE OR REPLACE TEMPORARY TABLE tmp.client_list (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY @@ -23,8 +23,8 @@ BEGIN c.name, c.credit clientCredit, c.creditInsurance solunion, - cast(r.risk as DECIMAL(10,0)) risk, - cast(c.creditInsurance - r.risk as decimal(10,0)) riskAlive, + CAST(r.risk AS DECIMAL(10,0)) risk, + CAST(c.creditInsurance - r.risk AS DECIMAL(10,0)) riskAlive, cac.invoiced billedAnnually, c.dueDay, ci.grade, -- 2.40.1 From fe0a1ad7be715f68de833ddd80d85e10da47ed6c Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 27 Mar 2024 08:12:05 +0100 Subject: [PATCH 7/7] feat: #7013 purge productionError --- db/routines/vn/procedures/clean.sql | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/procedures/clean.sql b/db/routines/vn/procedures/clean.sql index 5ffb03f6d..ed1569935 100644 --- a/db/routines/vn/procedures/clean.sql +++ b/db/routines/vn/procedures/clean.sql @@ -12,7 +12,7 @@ BEGIN DECLARE v1Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 1 YEAR; DECLARE v2Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR; DECLARE v4Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 4 YEAR; - DECLARE v5Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 5 YEAR; + DECLARE v5Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 5 YEAR; DECLARE vTrashId VARCHAR(15); DECLARE vCompanyBlk INT; @@ -30,8 +30,9 @@ BEGIN DELETE IGNORE FROM expedition WHERE created < v26Months; DELETE FROM sms WHERE created < v18Months; DELETE FROM saleTracking WHERE created < v1Years; + DELETE FROM productionError WHERE dated < v1Years; DELETE FROM ticketTracking WHERE created < v18Months; - DELETE tobs FROM ticketObservation tobs + DELETE tobs FROM ticketObservation tobs JOIN ticket t ON tobs.ticketFk = t.id WHERE t.shipped < v5Years; DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < v1Years; @@ -113,12 +114,12 @@ BEGIN FROM travel t LEFT JOIN entry e ON e.travelFk = t.id WHERE t.shipped < v3Months AND e.travelFk IS NULL; - + UPDATE dms d - JOIN dmsType dt ON dt.id = d.dmsTypeFk - SET d.dmsTypeFk = vTrashId + JOIN dmsType dt ON dt.id = d.dmsTypeFk + SET d.dmsTypeFk = vTrashId WHERE created < util.VN_CURDATE() - INTERVAL dt.monthToDelete MONTH; - + -- borrar entradas sin compras CREATE OR REPLACE TEMPORARY TABLE tEntryToDelete SELECT e.* @@ -136,7 +137,7 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tRouteToDelete SELECT * FROM route r - WHERE created < v4Years; + WHERE created < v4Years; UPDATE tRouteToDelete tmp JOIN dms d ON d.id = tmp.gestdocFk @@ -180,7 +181,7 @@ BEGIN DELETE FROM mail WHERE creationDate < v2Months; DELETE FROM split WHERE dated < v18Months; DELETE FROM remittance WHERE dated < v18Months; - + CREATE OR REPLACE TEMPORARY TABLE tTicketDelete SELECT DISTINCT tl.originFk ticketFk FROM ticketLog tl @@ -189,11 +190,11 @@ BEGIN FROM ticket t JOIN ticketLog tl ON tl.originFk = t.id LEFT JOIN ticketWeekly tw ON tw.ticketFk = t.id - WHERE t.shipped BETWEEN '2000-01-01' AND '2000-12-31' + WHERE t.shipped BETWEEN '2000-01-01' AND '2000-12-31' AND t.isDeleted AND tw.ticketFk IS NULL GROUP BY t.id - ) sub ON sub.ids = tl.id + ) sub ON sub.ids = tl.id WHERE tl.creationDate <= v2Months; DELETE t FROM ticket t -- 2.40.1