feat: #7013 solo muestra clientes asegurados

This commit is contained in:
Javi Gallego 2024-03-21 10:40:30 +01:00
parent 2f87ba03b2
commit c46e7227e7
1 changed files with 33 additions and 23 deletions

View File

@ -1,31 +1,41 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`() CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`()
BEGIN BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp.client_list; DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
CREATE TEMPORARY TABLE tmp.client_list CREATE TEMPORARY TABLE tmp.client_list
(PRIMARY KEY (Id_Cliente)) (PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY ENGINE = MEMORY
SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc SELECT * FROM (
JOIN vn.creditInsurance ci ON cc.id = ci.creditClassification SELECT cc.client, ci.grade
WHERE dateEnd IS NULL FROM creditClassification cc
ORDER BY ci.creationDate DESC JOIN creditInsurance ci ON cc.id = ci.creditClassification
LIMIT 10000000000000000000) t1 GROUP BY Id_Cliente; WHERE dateEnd IS NULL
ORDER BY ci.creationDate DESC
LIMIT 10000000000000000000) t1
GROUP BY client;
CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); CALL vn2008.risk_vs_client_list(util.VN_CURDATE());
SELECT SELECT
c.Id_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo, c.id,
cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo, c.name,
f.Consumo consumo_anual, c.Vencimiento, ci.grade c.credit clientCredit,
FROM c.creditInsurance solunion,
vn2008.Clientes c cast(r.risk as DECIMAL(10,0)) risk,
JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente cast(c.creditInsurance - r.risk as decimal(10,0)) riskAlive,
JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente cac.invoiced billedAnnually,
JOIN bi.facturacion_media_anual f ON c.Id_Cliente = f.Id_Cliente c.dueDay,
GROUP BY Id_cliente; ci.grade,
c2.country
DROP TEMPORARY TABLE IF EXISTS tmp.risk; 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; DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
END$$ END$$
DELIMITER ; DELIMITER ;