2024-04-22 11:05:16 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`creditInsurance_getRisk`()
|
2024-04-22 11:05:16 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Devuelve el riesgo de los clientes que estan asegurados
|
|
|
|
*/
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt
|
|
|
|
(PRIMARY KEY (clientFk))
|
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT * FROM (
|
|
|
|
SELECT cc.client clientFk, ci.grade
|
|
|
|
FROM creditClassification cc
|
2024-09-11 11:42:04 +00:00
|
|
|
JOIN creditInsurance ci ON cc.id = ci.creditClassificationFk
|
2024-04-22 11:05:16 +00:00
|
|
|
WHERE dateEnd IS NULL
|
|
|
|
ORDER BY ci.creationDate DESC
|
|
|
|
LIMIT 10000000000000000000) t1
|
|
|
|
GROUP BY clientFk;
|
|
|
|
|
|
|
|
CALL client_getDebt(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,
|
|
|
|
cgd.grade,
|
2024-04-24 07:05:29 +00:00
|
|
|
c2.name country
|
2024-04-22 11:05:16 +00:00
|
|
|
FROM tmp.clientGetDebt cgd
|
|
|
|
LEFT JOIN tmp.risk r ON r.clientFk = cgd.clientFk
|
|
|
|
JOIN client c ON c.id = cgd.clientFk
|
|
|
|
JOIN bs.clientAnnualConsumption cac ON c.id = cac.clientFk
|
|
|
|
JOIN country c2 ON c2.id = c.countryFk
|
|
|
|
GROUP BY c.id;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE
|
|
|
|
tmp.risk,
|
|
|
|
tmp.clientGetDebt;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|