2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`client_getRisk`(
|
2024-04-10 12:23:24 +00:00
|
|
|
vDate DATE
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
2024-04-10 12:23:24 +00:00
|
|
|
/**
|
|
|
|
* Retorna el riesgo de los clientes activos.
|
|
|
|
*
|
|
|
|
* @param vDate Fecha a calcular
|
|
|
|
*/
|
2024-04-10 12:17:03 +00:00
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt
|
|
|
|
(PRIMARY KEY (clientFk))
|
2024-01-15 11:31:03 +00:00
|
|
|
ENGINE = MEMORY
|
2024-04-10 12:17:03 +00:00
|
|
|
SELECT id clientFk
|
|
|
|
FROM client
|
|
|
|
WHERE isActive;
|
|
|
|
|
2024-04-10 12:23:24 +00:00
|
|
|
CALL client_getDebt(vDate);
|
2024-04-10 12:17:03 +00:00
|
|
|
|
|
|
|
SELECT c.socialName,
|
|
|
|
r.clientFk,
|
|
|
|
c.credit,
|
|
|
|
CAST(r.risk AS DECIMAL (10,2)) risk,
|
|
|
|
CAST(c.credit - r.risk AS DECIMAL (10,2)) difference,
|
2024-04-24 07:05:29 +00:00
|
|
|
co.name country
|
2024-04-10 12:17:03 +00:00
|
|
|
FROM client c
|
|
|
|
JOIN tmp.risk r ON r.clientFk = c.id
|
|
|
|
JOIN country co ON co.id = c.countryFk
|
|
|
|
GROUP BY c.id;
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE
|
|
|
|
tmp.risk,
|
|
|
|
tmp.clientGetDebt;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|