7167-testToMaster_2414 #2244
|
@ -30,6 +30,7 @@ BEGIN
|
||||||
DELETE IGNORE FROM expedition WHERE created < v26Months;
|
DELETE IGNORE FROM expedition WHERE created < v26Months;
|
||||||
DELETE FROM sms WHERE created < v18Months;
|
DELETE FROM sms WHERE created < v18Months;
|
||||||
DELETE FROM saleTracking WHERE created < v1Years;
|
DELETE FROM saleTracking WHERE created < v1Years;
|
||||||
|
DELETE FROM productionError WHERE dated < v1Years;
|
||||||
DELETE FROM ticketTracking WHERE created < v18Months;
|
DELETE FROM ticketTracking WHERE created < v18Months;
|
||||||
DELETE tobs FROM ticketObservation tobs
|
DELETE tobs FROM ticketObservation tobs
|
||||||
JOIN ticket t ON tobs.ticketFk = t.id
|
JOIN ticket t ON tobs.ticketFk = t.id
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
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,31 +0,0 @@
|
||||||
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))
|
|
||||||
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;
|
|
||||||
|
|
||||||
CALL vn2008.risk_vs_client_list(util.VN_CURDATE());
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
c.Id_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo,
|
|
||||||
cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo,
|
|
||||||
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 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;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
Loading…
Reference in New Issue