2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-03-25 06:52:40 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditInsurance_getRisk`()
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
2024-03-26 11:12:27 +00:00
|
|
|
/**
|
2024-03-27 07:05:33 +00:00
|
|
|
* Devuelve el riesgo de los clientes que estan asegurados
|
|
|
|
*/
|
2024-03-21 09:48:43 +00:00
|
|
|
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;
|
2024-03-21 09:40:30 +00:00
|
|
|
|
2024-03-21 09:48:43 +00:00
|
|
|
CALL vn2008.risk_vs_client_list(util.VN_CURDATE());
|
2024-03-21 09:40:30 +00:00
|
|
|
|
2024-03-21 09:48:43 +00:00
|
|
|
SELECT
|
|
|
|
c.id,
|
|
|
|
c.name,
|
|
|
|
c.credit clientCredit,
|
|
|
|
c.creditInsurance solunion,
|
2024-03-27 07:05:33 +00:00
|
|
|
CAST(r.risk AS DECIMAL(10,0)) risk,
|
|
|
|
CAST(c.creditInsurance - r.risk AS DECIMAL(10,0)) riskAlive,
|
2024-03-21 09:48:43 +00:00
|
|
|
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
|
2024-03-26 09:13:10 +00:00
|
|
|
JOIN country c2 ON c2.id = c.countryFk
|
2024-03-21 09:48:43 +00:00
|
|
|
GROUP BY c.id;
|
2024-03-21 09:40:30 +00:00
|
|
|
|
2024-03-21 09:48:43 +00:00
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|