feat: refs #6500 procRefactor8 #2131
|
@ -17,15 +17,15 @@ BEGIN
|
|||
|
||||
SET vEnded = util.dayEnd(IFNULL(vDate, util.VN_CURDATE()));
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tClientRisk
|
||||
CREATE OR REPLACE TEMPORARY TABLE tClientRisk
|
||||
ENGINE = MEMORY
|
||||
SELECT cr.clientFk, SUM(cr.amount) amount
|
||||
SELECT cr.clientFk, SUM(cr.amount) amount
|
||||
FROM clientRisk cr
|
||||
JOIN tmp.clientGetDebt c ON c.clientFk = cr.clientFk
|
||||
GROUP BY cr.clientFk;
|
||||
|
||||
INSERT INTO tClientRisk
|
||||
SELECT c.clientFk, SUM(r.amountPaid)
|
||||
SELECT c.clientFk, SUM(r.amountPaid)
|
||||
FROM receipt r
|
||||
JOIN tmp.clientGetDebt c ON c.clientFk = r.clientFk
|
||||
WHERE r.payed > vEnded
|
||||
|
|
|
@ -40,7 +40,7 @@ BEGIN
|
|||
|
||||
UPDATE client c
|
||||
JOIN tCreditClients cc ON cc.clientFk = c.clientFk
|
||||
robert marked this conversation as resolved
Outdated
|
||||
SET Clientes.Credito = newCredit;
|
||||
SET c.credit = newCredit;
|
||||
|
||||
DROP TEMPORARY TABLE tCreditClients;
|
||||
COMMIT;
|
||||
|
|
|
@ -2,28 +2,28 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`riskAllClients`(maxRiskDate DATE)
|
||||
BEGIN
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
||||
CREATE TEMPORARY TABLE tmp.client_list
|
||||
(PRIMARY KEY (Id_Cliente))
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
|
||||
CREATE TEMPORARY TABLE tmp.clientGetDebt
|
||||
(PRIMARY KEY (clientFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT id Id_Cliente, null grade FROM vn.client;
|
||||
SELECT id clientFk, null grade FROM client;
|
||||
|
||||
CALL client_getDebt (maxRiskDate);
|
||||
|
||||
SELECT
|
||||
c.RazonSocial,
|
||||
c.Id_Cliente,
|
||||
c.Credito,
|
||||
CAST(r.risk as DECIMAL (10,2)) risk,
|
||||
CAST(c.Credito - r.risk as DECIMAL (10,2)) Diferencia,
|
||||
c.Id_Pais
|
||||
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
|
||||
GROUP BY c.Id_cliente;
|
||||
c.RazonSocial,
|
||||
c.Id_Cliente,
|
||||
c.Credito,
|
||||
CAST(r.risk as DECIMAL (10,2)) risk,
|
||||
CAST(c.Credito - r.risk as DECIMAL (10,2)) Diferencia,
|
||||
c.Id_Pais
|
||||
FROM
|
||||
vn2008.Clientes c
|
||||
JOIN tmp.risk r ON r.clientFk = c.Id_Cliente
|
||||
JOIN tmp.clientGetDebt ci ON c.Id_Cliente = ci.clientFk
|
||||
GROUP BY c.Id_cliente;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -2,15 +2,18 @@ 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))
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
|
||||
CREATE TEMPORARY TABLE tmp.clientGetDebt
|
||||
(PRIMARY KEY (clientFk))
|
||||
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;
|
||||
SELECT *
|
||||
FROM (SELECT cc.client clientFk, 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 clientFk;
|
||||
|
||||
CALL client_getDebt (util.VN_CURDATE());
|
||||
|
||||
|
@ -20,12 +23,12 @@ BEGIN
|
|||
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 tmp.risk r ON r.clientFk = c.Id_Cliente
|
||||
JOIN tmp.clientGetDebt ci ON c.Id_Cliente = ci.clientFk
|
||||
JOIN bi.facturacion_media_anual f ON c.Id_Cliente = f.Id_Cliente
|
||||
GROUP BY Id_cliente;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
Loading…
Reference in New Issue
tabulación JOIN y SET