From 9aad1dd6e843cfb20f3d7494937e1cebe4aae41a Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 5 Mar 2024 12:41:54 +0100 Subject: [PATCH 01/16] feat: refs #6500 procRefactor8 --- db/routines/vn/events/raidUpdate.sql | 8 ++++ db/routines/vn/procedures/creditRecovery.sql | 49 ++++++++++++++++++++ db/routines/vn/procedures/raidUpdate.sql | 30 ++++++++++++ db/routines/vn/procedures/rateView.sql | 42 +++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 db/routines/vn/events/raidUpdate.sql create mode 100644 db/routines/vn/procedures/creditRecovery.sql create mode 100644 db/routines/vn/procedures/raidUpdate.sql create mode 100644 db/routines/vn/procedures/rateView.sql diff --git a/db/routines/vn/events/raidUpdate.sql b/db/routines/vn/events/raidUpdate.sql new file mode 100644 index 000000000..619dadb48 --- /dev/null +++ b/db/routines/vn/events/raidUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`raidUpdate` + ON SCHEDULE EVERY 1 DAY + STARTS '2017-12-29 00:05:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL raidUpdate$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/creditRecovery.sql b/db/routines/vn/procedures/creditRecovery.sql new file mode 100644 index 000000000..5a32a87f8 --- /dev/null +++ b/db/routines/vn/procedures/creditRecovery.sql @@ -0,0 +1,49 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditRecovery`() +BEGIN + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + UPDATE `client` c + JOIN payMethod pm ON pm.id = c.payMethodFk + SET c.credit = 0 + WHERE pm.`code` = 'card'; + + DROP TEMPORARY TABLE IF EXISTS tCreditClients; + CREATE TEMPORARY TABLE tCreditClients + SELECT clientFk, IF (credit > recovery ,credit - recovery,0) newCredit + FROM ( + SELECT r.clientFk, + r.amount recovery, + timestampadd(DAY, r.period, sub2.created) deadLine, + sub2.amount credit + FROM recovery r + JOIN ( + SELECT clientFk, amount , created + FROM ( + SELECT * FROM clientCredit + ORDER BY created DESC + LIMIT 10000000000000000000 + ) sub + GROUP BY clientFk + ) sub2 ON sub2.clientFk = r.clientFk + WHERE r.finished IS NULL OR r.finished >= util.VN_CURDATE() + GROUP BY r.clientFk + HAVING deadLine <= util.VN_CURDATE() + ) sub3 + WHERE credit > 0; + + UPDATE client c + JOIN tCreditClients cc ON cc.clientFk = c.clientFk + SET Clientes.Credito = newCredit; + + DROP TEMPORARY TABLE tCreditClients; + COMMIT; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/raidUpdate.sql b/db/routines/vn/procedures/raidUpdate.sql new file mode 100644 index 000000000..214974350 --- /dev/null +++ b/db/routines/vn/procedures/raidUpdate.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`raidUpdate`() +BEGIN + + UPDATE entry e + JOIN entryVirtual ev ON ev.entryFk = e.id + JOIN travel t ON t.id = e.travelFk + JOIN ( + SELECT * + FROM ( + SELECT id, landed, tt.warehouseInFk, tt.warehouseOutFk + FROM travel t + JOIN ( + SELECT t.warehouseInFk, t.warehouseOutFk + FROM entryVirtual ev + JOIN entry e ON e.id = ev.entryFk + JOIN travel t ON t.id = e.travelFk + GROUP BY t.warehouseInFk, t.warehouseOutFk + ) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk + + WHERE shipped > util.VN_CURDATE() AND isDelivered = FALSE + ORDER BY t.landed + LIMIT 10000000000000000000 + ) t + GROUP BY warehouseInFk, warehouseOutFk + ) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk + SET e.travelFk = t.id; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/rateView.sql b/db/routines/vn/procedures/rateView.sql new file mode 100644 index 000000000..6da1ea017 --- /dev/null +++ b/db/routines/vn/procedures/rateView.sql @@ -0,0 +1,42 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`rateView`() +BEGIN + + DECLARE v10Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 10 YEAR; + + SELECT + t.year, + t.month, + pagos.dollars, + pagos.changePractical, + CAST(SUM(iit.foreignValue ) / SUM(iit.taxableBase) AS DECIMAL(5,4)) cambioTeorico, + pagos.changeOfficial + FROM invoiceIn ii + JOIN time t ON t.dated = ii.issued + JOIN invoiceInTax iit ON ii.id = iit.invoiceInFk + JOIN + ( + SELECT + t.year, + t.month, + CAST(SUM(divisa) AS DECIMAL(10,2)) dollars, + CAST(SUM(divisa) / SUM(amount) AS DECIMAL(5,4)) changePractical, + CAST(rr.value * 0.998 AS DECIMAL(5,4)) changeOfficial + FROM payment p + JOIN time t ON t.dated = p.received + JOIN referenceRate rr ON rr.dated = p.received + JOIN currency c ON c.id = rr.currencyFk + WHERE divisa + AND p.received >= v10Years + AND c.code = 'USD' + GROUP BY t.year, t.month + ) pagos ON t.year = pagos.year AND t.month = pagos.MONTH + JOIN currency c ON c.id = ii.currencyFk + WHERE c.code = 'USD' + AND ii.issued >= v10Years + AND iit.foreignValue + AND iit.taxableBase + GROUP BY t.year, t.month; + +END$$ +DELIMITER ; From e83b0622cfb893c8294a042ee7dc37e0211a4b96 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 5 Mar 2024 13:21:53 +0100 Subject: [PATCH 02/16] refs 6500 rateView --- db/routines/vn/procedures/rateView.sql | 34 +++++++++++--------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/db/routines/vn/procedures/rateView.sql b/db/routines/vn/procedures/rateView.sql index 6da1ea017..fb03c192a 100644 --- a/db/routines/vn/procedures/rateView.sql +++ b/db/routines/vn/procedures/rateView.sql @@ -2,9 +2,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`rateView`() BEGIN - DECLARE v10Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 10 YEAR; - - SELECT + SELECT t.year, t.month, pagos.dollars, @@ -15,28 +13,24 @@ BEGIN JOIN time t ON t.dated = ii.issued JOIN invoiceInTax iit ON ii.id = iit.invoiceInFk JOIN - ( - SELECT - t.year, - t.month, - CAST(SUM(divisa) AS DECIMAL(10,2)) dollars, - CAST(SUM(divisa) / SUM(amount) AS DECIMAL(5,4)) changePractical, - CAST(rr.value * 0.998 AS DECIMAL(5,4)) changeOfficial - FROM payment p - JOIN time t ON t.dated = p.received - JOIN referenceRate rr ON rr.dated = p.received - JOIN currency c ON c.id = rr.currencyFk - WHERE divisa - AND p.received >= v10Years - AND c.code = 'USD' - GROUP BY t.year, t.month + ( SELECT + t.year, + t.month, + CAST(SUM(divisa) AS DECIMAL(10,2)) dollars, + CAST(SUM(divisa) / SUM(amount) AS DECIMAL(5,4)) changePractical, + CAST(rr.value * 0.998 AS DECIMAL(5,4)) changeOfficial + FROM payment p + JOIN time t ON t.dated = p.received + JOIN referenceRate rr ON rr.dated = p.received + JOIN currency c ON c.id = rr.currencyFk + WHERE divisa + AND c.code = 'USD' + GROUP BY t.year, t.month ) pagos ON t.year = pagos.year AND t.month = pagos.MONTH JOIN currency c ON c.id = ii.currencyFk WHERE c.code = 'USD' - AND ii.issued >= v10Years AND iit.foreignValue AND iit.taxableBase GROUP BY t.year, t.month; - END$$ DELIMITER ; From 2f0c1612c2770fd300090e45fe84ff7446c911e7 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 6 Mar 2024 12:02:34 +0100 Subject: [PATCH 03/16] feat: refs #6500 delete procedure --- db/routines/vn/procedures/riskAllClients.sql | 24 +++--- .../vn/procedures/solunionRiskRequest.sql | 16 ++-- db/routines/vn2008/events/raidUpdate.sql | 8 -- db/routines/vn2008/procedures/raidUpdate.sql | 28 ------- db/routines/vn2008/procedures/rateView.sql | 37 -------- .../vn2008/procedures/recobro_credito.sql | 45 ---------- .../vn2008/procedures/risk_vs_client_list.sql | 84 ------------------- 7 files changed, 20 insertions(+), 222 deletions(-) delete mode 100644 db/routines/vn2008/events/raidUpdate.sql delete mode 100644 db/routines/vn2008/procedures/raidUpdate.sql delete mode 100644 db/routines/vn2008/procedures/rateView.sql delete mode 100644 db/routines/vn2008/procedures/recobro_credito.sql delete mode 100644 db/routines/vn2008/procedures/risk_vs_client_list.sql diff --git a/db/routines/vn/procedures/riskAllClients.sql b/db/routines/vn/procedures/riskAllClients.sql index 66c0a0dd5..621d047ae 100644 --- a/db/routines/vn/procedures/riskAllClients.sql +++ b/db/routines/vn/procedures/riskAllClients.sql @@ -3,27 +3,27 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`riskAllClients`(max BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.client_list; - CREATE TEMPORARY TABLE tmp.client_list - (PRIMARY KEY (Id_Cliente)) + CREATE TEMPORARY TABLE tmp.client_list + (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY SELECT id Id_Cliente, null grade FROM vn.client; - - CALL vn2008.risk_vs_client_list(maxRiskDate); - + + 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 + 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; - + DROP TEMPORARY TABLE IF EXISTS tmp.risk; - DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/solunionRiskRequest.sql b/db/routines/vn/procedures/solunionRiskRequest.sql index b735bea33..7a7102782 100644 --- a/db/routines/vn/procedures/solunionRiskRequest.sql +++ b/db/routines/vn/procedures/solunionRiskRequest.sql @@ -8,15 +8,15 @@ BEGIN 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 + 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()); - + + CALL client_getDebt (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, + cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo, f.Consumo consumo_anual, c.Vencimiento, ci.grade FROM vn2008.Clientes c @@ -24,8 +24,8 @@ BEGIN 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; + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END$$ DELIMITER ; diff --git a/db/routines/vn2008/events/raidUpdate.sql b/db/routines/vn2008/events/raidUpdate.sql deleted file mode 100644 index aacfd6dcd..000000000 --- a/db/routines/vn2008/events/raidUpdate.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn2008`.`raidUpdate` - ON SCHEDULE EVERY 1 DAY - STARTS '2017-12-29 00:05:00.000' - ON COMPLETION PRESERVE - ENABLE -DO CALL raidUpdate$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/raidUpdate.sql b/db/routines/vn2008/procedures/raidUpdate.sql deleted file mode 100644 index 9746f3cf9..000000000 --- a/db/routines/vn2008/procedures/raidUpdate.sql +++ /dev/null @@ -1,28 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`raidUpdate`() -BEGIN - - UPDATE Entradas e - JOIN Entradas_Auto ea USING (Id_Entrada) - JOIN travel t ON t.id = e.travel_id - JOIN ( - SELECT * - FROM ( - SELECT id, landing, warehouse_id, warehouse_id_out - FROM travel - JOIN ( - SELECT warehouse_id, warehouse_id_out - FROM Entradas_Auto ea - JOIN Entradas e USING(Id_Entrada) - JOIN travel t ON t.id = e.travel_id - GROUP BY warehouse_id, warehouse_id_out - ) t USING (warehouse_id, warehouse_id_out) - WHERE shipment > util.VN_CURDATE() AND delivered = FALSE - ORDER BY landing - LIMIT 10000000000000000000 - ) t - GROUP BY warehouse_id, warehouse_id_out - ) t USING (warehouse_id, warehouse_id_out) - SET e.travel_id = t.id; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/rateView.sql b/db/routines/vn2008/procedures/rateView.sql deleted file mode 100644 index 91e317be6..000000000 --- a/db/routines/vn2008/procedures/rateView.sql +++ /dev/null @@ -1,37 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`rateView`() -BEGIN - - SELECT - t.year as año, - t.month as mes, - pagos.dolares, - pagos.cambioPractico, - CAST(sum(divisa) / sum(bi) as DECIMAL(5,4)) as cambioTeorico, - pagos.cambioOficial - FROM recibida r - JOIN time t ON t.date = r.fecha - JOIN recibida_iva ri ON r.id = ri.recibida_id - JOIN - ( - SELECT - t.year as Año, - t.month as Mes, - cast(sum(divisa) as DECIMAL(10,2)) as dolares, - cast(sum(divisa) / sum(importe) as DECIMAL(5,4)) as cambioPractico, - cast(rr.rate * 0.998 as DECIMAL(5,4)) as cambioOficial - FROM pago p - JOIN time t ON t.date = p.fecha - JOIN reference_rate rr ON rr.date = p.fecha AND moneda_id = 2 - WHERE divisa - AND fecha >= '2015-01-11' - GROUP BY t.year, t.month - ) pagos ON t.year = pagos.Año AND t.month = pagos.Mes - WHERE moneda_id = 2 - AND fecha >= '2015-01-01' - AND divisa - AND bi - GROUP BY t.year, t.month; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/recobro_credito.sql b/db/routines/vn2008/procedures/recobro_credito.sql deleted file mode 100644 index 3657f2b9b..000000000 --- a/db/routines/vn2008/procedures/recobro_credito.sql +++ /dev/null @@ -1,45 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`recobro_credito`() -BEGIN - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - UPDATE vn.`client` c - JOIN vn.payMethod pm ON pm.id = c.payMethodFk - SET credit = 0 - WHERE pm.`code` = 'card'; - - DROP TEMPORARY TABLE IF EXISTS clientes_credit; - CREATE TEMPORARY TABLE clientes_credit - SELECT Id_Cliente, if (Credito > Recobro ,Credito - Recobro,0) AS newCredit - FROM ( - SELECT r.Id_Cliente, r.amount AS Recobro, - timestampadd(DAY, period, UltimaFecha) AS Deadline, sub2.amount AS Credito - FROM vn2008.recovery r - JOIN ( - SELECT Id_Cliente, amount , odbc_date AS UltimaFecha - FROM ( - SELECT * FROM credit - ORDER BY odbc_date DESC - LIMIT 10000000000000000000 - ) sub - GROUP BY Id_Cliente - ) sub2 USING(Id_Cliente) - WHERE dend IS NULL or dend >= util.VN_CURDATE() - GROUP BY Id_Cliente - HAVING Deadline <= util.VN_CURDATE() - ) sub3 - WHERE Credito > 0; - - UPDATE Clientes - JOIN clientes_credit USING(Id_Cliente) - SET Clientes.Credito = newCredit; - - DROP TEMPORARY TABLE clientes_credit; - COMMIT; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/risk_vs_client_list.sql b/db/routines/vn2008/procedures/risk_vs_client_list.sql deleted file mode 100644 index 92f94eb9f..000000000 --- a/db/routines/vn2008/procedures/risk_vs_client_list.sql +++ /dev/null @@ -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 ; From 194947dc9a0cf3dccd0bb9ed69acd357e6fb41a4 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 6 Mar 2024 14:11:07 +0100 Subject: [PATCH 04/16] feat: refs #6500 procRefactor8 --- db/routines/vn/procedures/client_getDebt.sql | 6 ++-- db/routines/vn/procedures/creditRecovery.sql | 2 +- db/routines/vn/procedures/riskAllClients.sql | 32 +++++++++---------- .../vn/procedures/solunionRiskRequest.sql | 25 ++++++++------- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/db/routines/vn/procedures/client_getDebt.sql b/db/routines/vn/procedures/client_getDebt.sql index ad7b5b7d2..3eaace4e9 100644 --- a/db/routines/vn/procedures/client_getDebt.sql +++ b/db/routines/vn/procedures/client_getDebt.sql @@ -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 diff --git a/db/routines/vn/procedures/creditRecovery.sql b/db/routines/vn/procedures/creditRecovery.sql index 5a32a87f8..e598661af 100644 --- a/db/routines/vn/procedures/creditRecovery.sql +++ b/db/routines/vn/procedures/creditRecovery.sql @@ -40,7 +40,7 @@ BEGIN UPDATE client c JOIN tCreditClients cc ON cc.clientFk = c.clientFk - SET Clientes.Credito = newCredit; + SET c.credit = newCredit; DROP TEMPORARY TABLE tCreditClients; COMMIT; diff --git a/db/routines/vn/procedures/riskAllClients.sql b/db/routines/vn/procedures/riskAllClients.sql index 621d047ae..c818c715c 100644 --- a/db/routines/vn/procedures/riskAllClients.sql +++ b/db/routines/vn/procedures/riskAllClients.sql @@ -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 ; diff --git a/db/routines/vn/procedures/solunionRiskRequest.sql b/db/routines/vn/procedures/solunionRiskRequest.sql index 7a7102782..f5af4d0ad 100644 --- a/db/routines/vn/procedures/solunionRiskRequest.sql +++ b/db/routines/vn/procedures/solunionRiskRequest.sql @@ -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 ; From dddcacee7a417fddb9dd712d4b02e3b9424b9668 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 8 Apr 2024 12:01:27 +0200 Subject: [PATCH 05/16] feat: refs #6500 --- db/routines/vn/procedures/riskAllClients.sql | 34 ++++---- .../vn2008/procedures/risk_vs_client_list.sql | 84 +++++++++++++++++++ 2 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 db/routines/vn2008/procedures/risk_vs_client_list.sql diff --git a/db/routines/vn/procedures/riskAllClients.sql b/db/routines/vn/procedures/riskAllClients.sql index c818c715c..f007247f3 100644 --- a/db/routines/vn/procedures/riskAllClients.sql +++ b/db/routines/vn/procedures/riskAllClients.sql @@ -2,28 +2,28 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`riskAllClients`(maxRiskDate DATE) BEGIN - DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; - CREATE TEMPORARY TABLE tmp.clientGetDebt - (PRIMARY KEY (clientFk)) + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + CREATE TEMPORARY TABLE tmp.client_list + (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY - SELECT id clientFk, null grade FROM client; + SELECT id Id_Cliente, null grade FROM vn.client; - CALL client_getDebt (maxRiskDate); + CALL vn2008.risk_vs_client_list(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.clientFk = c.Id_Cliente - JOIN tmp.clientGetDebt ci ON c.Id_Cliente = ci.clientFk - 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.Id_Cliente = c.Id_Cliente + JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente + GROUP BY c.Id_cliente; DROP TEMPORARY TABLE IF EXISTS tmp.risk; - DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END$$ DELIMITER ; diff --git a/db/routines/vn2008/procedures/risk_vs_client_list.sql b/db/routines/vn2008/procedures/risk_vs_client_list.sql new file mode 100644 index 000000000..92f94eb9f --- /dev/null +++ b/db/routines/vn2008/procedures/risk_vs_client_list.sql @@ -0,0 +1,84 @@ +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 ; From 2d18f01a15be29e49d7382ba7f15bea77c2bd385 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 8 Apr 2024 12:18:13 +0200 Subject: [PATCH 06/16] feat: refs #6500 --- db/routines/vn/procedures/creditRecovery.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/creditRecovery.sql b/db/routines/vn/procedures/creditRecovery.sql index e598661af..a57e08063 100644 --- a/db/routines/vn/procedures/creditRecovery.sql +++ b/db/routines/vn/procedures/creditRecovery.sql @@ -39,7 +39,7 @@ BEGIN WHERE credit > 0; UPDATE client c - JOIN tCreditClients cc ON cc.clientFk = c.clientFk + JOIN tCreditClients cc ON cc.clientFk = c.id SET c.credit = newCredit; DROP TEMPORARY TABLE tCreditClients; From d595a7b2fabc01b6f0dd86df99fe908114c467e0 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 8 Apr 2024 12:22:15 +0200 Subject: [PATCH 07/16] feat: refs #6500 --- db/versions/10984-navyDendro/00-firstScript.sql | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 db/versions/10984-navyDendro/00-firstScript.sql diff --git a/db/versions/10984-navyDendro/00-firstScript.sql b/db/versions/10984-navyDendro/00-firstScript.sql new file mode 100644 index 000000000..136625a34 --- /dev/null +++ b/db/versions/10984-navyDendro/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +UPDATE bs.nightTask SET `schema`='vn' WHERE id=22; + +UPDATE bs.nightTask SET `schema`='vn',`procedure`='creditRecovery' WHERE id=30; \ No newline at end of file From 2c0c346a7bebf58566274751d5067cd5ca33c560 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Apr 2024 07:34:43 +0200 Subject: [PATCH 08/16] feat: refs #6500 --- db/routines/vn/procedures/creditRecovery.sql | 23 ++++++++++--------- .../10984-navyDendro/00-firstScript.sql | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/db/routines/vn/procedures/creditRecovery.sql b/db/routines/vn/procedures/creditRecovery.sql index a57e08063..0a02f611f 100644 --- a/db/routines/vn/procedures/creditRecovery.sql +++ b/db/routines/vn/procedures/creditRecovery.sql @@ -16,31 +16,32 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tCreditClients; CREATE TEMPORARY TABLE tCreditClients - SELECT clientFk, IF (credit > recovery ,credit - recovery,0) newCredit + SELECT clientFk, IF(credit > recovery, credit - recovery, 0) newCredit FROM ( SELECT r.clientFk, r.amount recovery, - timestampadd(DAY, r.period, sub2.created) deadLine, + (sub2.created + INTERVAL r.period DAY) deadLine, sub2.amount credit FROM recovery r JOIN ( - SELECT clientFk, amount , created - FROM ( - SELECT * FROM clientCredit - ORDER BY created DESC - LIMIT 10000000000000000000 - ) sub + SELECT clientFk, amount, created + FROM ( + SELECT clientFk, amount, created + FROM clientCredit + ORDER BY created DESC + LIMIT 10000000000000000000 + ) sub GROUP BY clientFk ) sub2 ON sub2.clientFk = r.clientFk WHERE r.finished IS NULL OR r.finished >= util.VN_CURDATE() GROUP BY r.clientFk - HAVING deadLine <= util.VN_CURDATE() + HAVING deadLine <= util.VN_CURDATE() ) sub3 WHERE credit > 0; UPDATE client c - JOIN tCreditClients cc ON cc.clientFk = c.id - SET c.credit = newCredit; + JOIN tCreditClients cc ON cc.clientFk = c.id + SET c.credit = newCredit; DROP TEMPORARY TABLE tCreditClients; COMMIT; diff --git a/db/versions/10984-navyDendro/00-firstScript.sql b/db/versions/10984-navyDendro/00-firstScript.sql index 136625a34..c08462d75 100644 --- a/db/versions/10984-navyDendro/00-firstScript.sql +++ b/db/versions/10984-navyDendro/00-firstScript.sql @@ -1,4 +1,4 @@ -- Place your SQL code here -UPDATE bs.nightTask SET `schema`='vn' WHERE id=22; +UPDATE bs.nightTask SET `schema`='vn' WHERE `procedure`='raidUpdate'; -UPDATE bs.nightTask SET `schema`='vn',`procedure`='creditRecovery' WHERE id=30; \ No newline at end of file +UPDATE bs.nightTask SET `schema`='vn',`procedure`='creditRecovery' WHERE `procedure` ='recobro_credito'; \ No newline at end of file From c6ece4619fc37d0ac1270f4c225e29ad448fc324 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Apr 2024 11:40:12 +0200 Subject: [PATCH 09/16] feat: refs #6500 --- db/routines/vn/procedures/creditRecovery.sql | 42 ++++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/db/routines/vn/procedures/creditRecovery.sql b/db/routines/vn/procedures/creditRecovery.sql index 0a02f611f..f61b1499a 100644 --- a/db/routines/vn/procedures/creditRecovery.sql +++ b/db/routines/vn/procedures/creditRecovery.sql @@ -17,27 +17,27 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tCreditClients; CREATE TEMPORARY TABLE tCreditClients SELECT clientFk, IF(credit > recovery, credit - recovery, 0) newCredit - FROM ( - SELECT r.clientFk, - r.amount recovery, - (sub2.created + INTERVAL r.period DAY) deadLine, - sub2.amount credit - FROM recovery r - JOIN ( - SELECT clientFk, amount, created - FROM ( - SELECT clientFk, amount, created - FROM clientCredit - ORDER BY created DESC - LIMIT 10000000000000000000 - ) sub - GROUP BY clientFk - ) sub2 ON sub2.clientFk = r.clientFk - WHERE r.finished IS NULL OR r.finished >= util.VN_CURDATE() - GROUP BY r.clientFk - HAVING deadLine <= util.VN_CURDATE() - ) sub3 - WHERE credit > 0; + FROM ( + SELECT r.clientFk, + r.amount recovery, + (sub2.created + INTERVAL r.period DAY) deadLine, + sub2.amount credit + FROM recovery r + JOIN ( + SELECT clientFk, amount, created + FROM ( + SELECT clientFk, amount, created + FROM clientCredit + ORDER BY created DESC + LIMIT 10000000000000000000 + ) sub + GROUP BY clientFk + ) sub2 ON sub2.clientFk = r.clientFk + WHERE r.finished IS NULL OR r.finished >= util.VN_CURDATE() + GROUP BY r.clientFk + HAVING deadLine <= util.VN_CURDATE() + ) sub3 + WHERE credit > 0; UPDATE client c JOIN tCreditClients cc ON cc.clientFk = c.id From f545a57c9fe91f07d9c775a32e4d6bc9e36a3257 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 12 Apr 2024 07:58:18 +0200 Subject: [PATCH 10/16] feat: refs #6500 --- db/routines/vn/procedures/creditRecovery.sql | 4 ++++ db/routines/vn/procedures/raidUpdate.sql | 5 +++-- db/routines/vn/procedures/rateView.sql | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/creditRecovery.sql b/db/routines/vn/procedures/creditRecovery.sql index f61b1499a..687d652dd 100644 --- a/db/routines/vn/procedures/creditRecovery.sql +++ b/db/routines/vn/procedures/creditRecovery.sql @@ -1,6 +1,10 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditRecovery`() BEGIN +/** + * Actualiza el crédito de los clientes + */ + DECLARE EXIT HANDLER FOR SQLSTATE '45000' BEGIN ROLLBACK; diff --git a/db/routines/vn/procedures/raidUpdate.sql b/db/routines/vn/procedures/raidUpdate.sql index 214974350..abdf44ddc 100644 --- a/db/routines/vn/procedures/raidUpdate.sql +++ b/db/routines/vn/procedures/raidUpdate.sql @@ -1,7 +1,9 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`raidUpdate`() BEGIN - +/** + * Actualiza el travel de las entradas de redadas + */ UPDATE entry e JOIN entryVirtual ev ON ev.entryFk = e.id JOIN travel t ON t.id = e.travelFk @@ -17,7 +19,6 @@ BEGIN JOIN travel t ON t.id = e.travelFk GROUP BY t.warehouseInFk, t.warehouseOutFk ) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk - WHERE shipped > util.VN_CURDATE() AND isDelivered = FALSE ORDER BY t.landed LIMIT 10000000000000000000 diff --git a/db/routines/vn/procedures/rateView.sql b/db/routines/vn/procedures/rateView.sql index fb03c192a..8a6c1305d 100644 --- a/db/routines/vn/procedures/rateView.sql +++ b/db/routines/vn/procedures/rateView.sql @@ -1,7 +1,9 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`rateView`() BEGIN - +/** + * Muestra información sobre tasas de cambio de Dolares + */ SELECT t.year, t.month, From adadf70f1e18dea2961bbbb821ac6a0e8678f492 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 12 Apr 2024 08:44:06 +0200 Subject: [PATCH 11/16] feat: refs #6500 --- db/routines/vn/procedures/raidUpdate.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/raidUpdate.sql b/db/routines/vn/procedures/raidUpdate.sql index abdf44ddc..99a30ed04 100644 --- a/db/routines/vn/procedures/raidUpdate.sql +++ b/db/routines/vn/procedures/raidUpdate.sql @@ -22,7 +22,7 @@ BEGIN WHERE shipped > util.VN_CURDATE() AND isDelivered = FALSE ORDER BY t.landed LIMIT 10000000000000000000 - ) t + ) t GROUP BY warehouseInFk, warehouseOutFk ) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk SET e.travelFk = t.id; From f30f907d8e6fe0d0da52058f379bbc34d02fa73c Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 12 Apr 2024 12:13:07 +0200 Subject: [PATCH 12/16] feat: refs #6500 cambios solicitados --- db/routines/vn/procedures/raidUpdate.sql | 6 +++--- db/routines/vn/procedures/rateView.sql | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/raidUpdate.sql b/db/routines/vn/procedures/raidUpdate.sql index 99a30ed04..703c14e5c 100644 --- a/db/routines/vn/procedures/raidUpdate.sql +++ b/db/routines/vn/procedures/raidUpdate.sql @@ -10,7 +10,7 @@ BEGIN JOIN ( SELECT * FROM ( - SELECT id, landed, tt.warehouseInFk, tt.warehouseOutFk + SELECT t.id, t.landed, tt.warehouseInFk, tt.warehouseOutFk FROM travel t JOIN ( SELECT t.warehouseInFk, t.warehouseOutFk @@ -19,11 +19,11 @@ BEGIN JOIN travel t ON t.id = e.travelFk GROUP BY t.warehouseInFk, t.warehouseOutFk ) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk - WHERE shipped > util.VN_CURDATE() AND isDelivered = FALSE + WHERE shipped > util.VN_CURDATE() AND NOT isDelivered ORDER BY t.landed LIMIT 10000000000000000000 ) t - GROUP BY warehouseInFk, warehouseOutFk + GROUP BY t.warehouseInFk, t.warehouseOutFk ) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk SET e.travelFk = t.id; diff --git a/db/routines/vn/procedures/rateView.sql b/db/routines/vn/procedures/rateView.sql index 8a6c1305d..153e3584a 100644 --- a/db/routines/vn/procedures/rateView.sql +++ b/db/routines/vn/procedures/rateView.sql @@ -18,14 +18,14 @@ BEGIN ( SELECT t.year, t.month, - CAST(SUM(divisa) AS DECIMAL(10,2)) dollars, - CAST(SUM(divisa) / SUM(amount) AS DECIMAL(5,4)) changePractical, + CAST(SUM(p.divisa) AS DECIMAL(10,2)) dollars, + CAST(SUM(p.divisa) / SUM(p.amount) AS DECIMAL(5,4)) changePractical, CAST(rr.value * 0.998 AS DECIMAL(5,4)) changeOfficial FROM payment p JOIN time t ON t.dated = p.received JOIN referenceRate rr ON rr.dated = p.received JOIN currency c ON c.id = rr.currencyFk - WHERE divisa + WHERE p.divisa AND c.code = 'USD' GROUP BY t.year, t.month ) pagos ON t.year = pagos.year AND t.month = pagos.MONTH From 8ca278b5a9c64572234178a459b35d35d827fc42 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 17 Apr 2024 11:00:00 +0200 Subject: [PATCH 13/16] feat: refs #6500 cambios solicitados --- db/routines/vn/procedures/rateView.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/rateView.sql b/db/routines/vn/procedures/rateView.sql index 153e3584a..69e429c37 100644 --- a/db/routines/vn/procedures/rateView.sql +++ b/db/routines/vn/procedures/rateView.sql @@ -7,10 +7,10 @@ BEGIN SELECT t.year, t.month, - pagos.dollars, - pagos.changePractical, + pay.dollars, + pay.changePractical, CAST(SUM(iit.foreignValue ) / SUM(iit.taxableBase) AS DECIMAL(5,4)) cambioTeorico, - pagos.changeOfficial + pay.changeOfficial FROM invoiceIn ii JOIN time t ON t.dated = ii.issued JOIN invoiceInTax iit ON ii.id = iit.invoiceInFk @@ -28,7 +28,7 @@ BEGIN WHERE p.divisa AND c.code = 'USD' GROUP BY t.year, t.month - ) pagos ON t.year = pagos.year AND t.month = pagos.MONTH + ) pay ON t.year = pay.year AND t.month = pay.month JOIN currency c ON c.id = ii.currencyFk WHERE c.code = 'USD' AND iit.foreignValue From d93dc287286dc60b51b5cc705c9a33c98fe432e6 Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 17 Apr 2024 12:32:33 +0200 Subject: [PATCH 14/16] fix(view): refs #6372 fix --- db/routines/vn2008/views/gastos_resumen.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/routines/vn2008/views/gastos_resumen.sql b/db/routines/vn2008/views/gastos_resumen.sql index 02231bcbf..d40d6d229 100644 --- a/db/routines/vn2008/views/gastos_resumen.sql +++ b/db/routines/vn2008/views/gastos_resumen.sql @@ -2,6 +2,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn2008`.`gastos_resumen` AS SELECT + `es`.`id` AS `id`, `es`.`expenseFk` AS `Id_Gasto`, `es`.`year` AS `year`, `es`.`month` AS `month`, From e769081a7469ebe9985dd89adceea693c2720fe5 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 17 Apr 2024 13:11:28 +0200 Subject: [PATCH 15/16] feat: refs #6500 --- db/routines/vn/procedures/rateView.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/rateView.sql b/db/routines/vn/procedures/rateView.sql index 69e429c37..d840aa9d5 100644 --- a/db/routines/vn/procedures/rateView.sql +++ b/db/routines/vn/procedures/rateView.sql @@ -5,12 +5,12 @@ BEGIN * Muestra información sobre tasas de cambio de Dolares */ SELECT - t.year, - t.month, - pay.dollars, - pay.changePractical, - CAST(SUM(iit.foreignValue ) / SUM(iit.taxableBase) AS DECIMAL(5,4)) cambioTeorico, - pay.changeOfficial + t.year año, + t.month mes, + pay.dollars dolares, + pay.changePractical cambioPractico, + CAST(SUM(iit.foreignValue ) / SUM(iit.taxableBase) AS DECIMAL(5,4))cambioTeorico, + pay.changeOfficial cambioOficial FROM invoiceIn ii JOIN time t ON t.dated = ii.issued JOIN invoiceInTax iit ON ii.id = iit.invoiceInFk From b83e0a4ae21e1c72711a0a6e1315fdef5a66977d Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 17 Apr 2024 16:43:17 +0200 Subject: [PATCH 16/16] fix: refs #6492 castToInt --- .../accountReconciliation_beforeInsert.sql | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/triggers/accountReconciliation_beforeInsert.sql b/db/routines/vn/triggers/accountReconciliation_beforeInsert.sql index c586dc57e..4fedd62b8 100644 --- a/db/routines/vn/triggers/accountReconciliation_beforeInsert.sql +++ b/db/routines/vn/triggers/accountReconciliation_beforeInsert.sql @@ -3,13 +3,13 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`accountReconciliation BEFORE INSERT ON `accountReconciliation` FOR EACH ROW - SET NEW.calculatedCode = REPLACE( - REPLACE( - REPLACE( - REPLACE( - CONCAT(NEW.supplierAccountFk,NEW.operationDated,NEW.amount,NEW.concept,NEW.debitCredit) - ,' ','') - ,":",'') - ,'-','') - ,'.','')$$ -DELIMITER ; + SET NEW.calculatedCode = REGEXP_REPLACE( + CONCAT(NEW.supplierAccountFk, + NEW.operationDated, + NEW.amount, + NEW.concept, + CAST(NEW.debitCredit AS UNSIGNED) + ), + '[ :\\-.]', '' + )$$ +DELIMITER ; \ No newline at end of file