refactor: refs #7181 vn2008.Deleted risk_vs_client_list
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
5558e92b1e
commit
5044cd454d
|
@ -1,42 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditInsurance_getRisk`()
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Devuelve el riesgo de los clientes que estan asegurados
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
|
|
||||||
CALL vn2008.risk_vs_client_list(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,
|
|
||||||
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
|
|
||||||
JOIN 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;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,29 +1,28 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`riskAllClients`(maxRiskDate DATE)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`riskAllClients`(maxRiskDate DATE)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
(PRIMARY KEY (clientFk))
|
||||||
CREATE TEMPORARY TABLE tmp.client_list
|
|
||||||
(PRIMARY KEY (Id_Cliente))
|
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT id Id_Cliente, null grade FROM vn.client;
|
SELECT id clientFk
|
||||||
|
FROM client
|
||||||
CALL vn2008.risk_vs_client_list(maxRiskDate);
|
WHERE isActive;
|
||||||
|
|
||||||
SELECT
|
CALL client_getDebt(maxRiskDate);
|
||||||
c.RazonSocial,
|
|
||||||
c.Id_Cliente,
|
SELECT c.socialName,
|
||||||
c.Credito,
|
r.clientFk,
|
||||||
CAST(r.risk as DECIMAL (10,2)) risk,
|
c.credit,
|
||||||
CAST(c.Credito - r.risk as DECIMAL (10,2)) Diferencia,
|
CAST(r.risk AS DECIMAL (10,2)) risk,
|
||||||
c.Id_Pais
|
CAST(c.credit - r.risk AS DECIMAL (10,2)) difference,
|
||||||
FROM
|
co.country
|
||||||
vn2008.Clientes c
|
FROM client c
|
||||||
JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente
|
JOIN tmp.risk r ON r.clientFk = c.id
|
||||||
JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente
|
JOIN country co ON co.id = c.countryFk
|
||||||
GROUP BY c.Id_cliente;
|
GROUP BY c.id;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
|
DROP TEMPORARY TABLE
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
|
tmp.risk,
|
||||||
|
tmp.clientGetDebt;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`risk_vs_client_list`(maxRiskDate DATE)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Calcula el riesgo para los clientes activos de la tabla temporal tmp.client_list
|
|
||||||
*
|
|
||||||
* @deprecated usar vn.client_getDebt
|
|
||||||
* @param maxRiskDate Fecha maxima de los registros
|
|
||||||
* @return table tmp.risk
|
|
||||||
*/
|
|
||||||
DECLARE startingDate DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(util.VN_CURDATE()) - 60, util.VN_CURDATE());
|
|
||||||
DECLARE endingDate DATETIME;
|
|
||||||
DECLARE MAX_RISK_ALLOWED INT DEFAULT 200;
|
|
||||||
|
|
||||||
SET maxRiskDate = IFNULL(maxRiskDate, util.VN_CURDATE());
|
|
||||||
SET endingDate = TIMESTAMP(maxRiskDate, '23:59:59');
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.client_list_2;
|
|
||||||
CREATE TEMPORARY TABLE tmp.client_list_2
|
|
||||||
(PRIMARY KEY (Id_Cliente))
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT *
|
|
||||||
FROM tmp.client_list;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.client_list_3;
|
|
||||||
CREATE TEMPORARY TABLE tmp.client_list_3
|
|
||||||
(PRIMARY KEY (Id_Cliente))
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT *
|
|
||||||
FROM tmp.client_list;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.tickets_sin_facturar;
|
|
||||||
CREATE TEMPORARY TABLE tmp.tickets_sin_facturar
|
|
||||||
(PRIMARY KEY (Id_Cliente))
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT t.Id_Cliente, floor(IF(cl.isVies, 1, 1.1) * sum(Cantidad * Preu * (100 - Descuento) / 100)) as total
|
|
||||||
FROM Movimientos m
|
|
||||||
JOIN Tickets t on m.Id_Ticket = t.Id_Ticket
|
|
||||||
JOIN tmp.client_list c on c.Id_Cliente = t.Id_Cliente
|
|
||||||
JOIN vn.client cl ON cl.id = t.Id_Cliente
|
|
||||||
WHERE Factura IS NULL
|
|
||||||
AND Fecha BETWEEN startingDate AND endingDate
|
|
||||||
GROUP BY t.Id_Cliente;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
|
|
||||||
CREATE TEMPORARY TABLE tmp.risk
|
|
||||||
(PRIMARY KEY (Id_Cliente))
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT Id_Cliente, SUM(amount) risk, sum(saldo) saldo
|
|
||||||
FROM Clientes c
|
|
||||||
JOIN (
|
|
||||||
SELECT clientFk, SUM(amount) amount,SUM(amount) saldo
|
|
||||||
FROM vn.clientRisk
|
|
||||||
JOIN tmp.client_list on Id_Cliente = clientFk
|
|
||||||
GROUP BY clientFk
|
|
||||||
UNION ALL
|
|
||||||
SELECT Id_Cliente, SUM(Entregado),SUM(Entregado)
|
|
||||||
FROM Recibos
|
|
||||||
JOIN tmp.client_list_2 using(Id_Cliente)
|
|
||||||
WHERE Fechacobro > endingDate
|
|
||||||
GROUP BY Id_Cliente
|
|
||||||
UNION ALL
|
|
||||||
SELECT Id_Cliente, total,0
|
|
||||||
FROM tmp.tickets_sin_facturar
|
|
||||||
UNION ALL
|
|
||||||
SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)), CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
|
|
||||||
FROM hedera.tpvTransaction t
|
|
||||||
JOIN tmp.client_list_3 on Id_Cliente = t.clientFk
|
|
||||||
WHERE t.receiptFk IS NULL
|
|
||||||
AND t.status = 'ok'
|
|
||||||
GROUP BY t.clientFk
|
|
||||||
) t ON c.Id_Cliente = t.clientFk
|
|
||||||
WHERE c.activo != FALSE
|
|
||||||
GROUP BY c.Id_Cliente;
|
|
||||||
|
|
||||||
DELETE r.*
|
|
||||||
FROM tmp.risk r
|
|
||||||
JOIN vn2008.Clientes c on c.Id_Cliente = r.Id_Cliente
|
|
||||||
JOIN vn2008.pay_met pm on pm.id = c.pay_met_id
|
|
||||||
WHERE IFNULL(r.saldo,0) < 10
|
|
||||||
AND r.risk <= MAX_RISK_ALLOWED
|
|
||||||
AND pm.`name` = 'TARJETA';
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
Loading…
Reference in New Issue