From 18c10e2dd750d9314de6bcf1a11866446868f4b9 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 14 Feb 2024 11:39:15 +0100 Subject: [PATCH] refactor: refs #6778 Requested changes --- .../bi/procedures/Greuge_Evolution_Add.sql | 2 +- .../bs/procedures/comercialesCompleto.sql | 4 +-- .../bs/procedures/ventas_contables_add.sql | 6 ++-- .../ventas_contables_por_cliente.sql | 6 ++-- db/routines/bs/procedures/vivosMuertos.sql | 28 +++++++++---------- .../vn2008/procedures/CalculoRemesas.sql | 10 +++---- .../procedures/customerDebtEvolution.sql | 8 +++--- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/db/routines/bi/procedures/Greuge_Evolution_Add.sql b/db/routines/bi/procedures/Greuge_Evolution_Add.sql index b29be6b49..1d4bf4355 100644 --- a/db/routines/bi/procedures/Greuge_Evolution_Add.sql +++ b/db/routines/bi/procedures/Greuge_Evolution_Add.sql @@ -54,7 +54,7 @@ BEGIN SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas, 0 FROM ( SELECT clientFk Id_Cliente, sum(amount) as Greuge - FROM vn2.greuge + FROM vn.greuge where shipped <= datFEC group by clientFk ) sub diff --git a/db/routines/bs/procedures/comercialesCompleto.sql b/db/routines/bs/procedures/comercialesCompleto.sql index b0c33e7f0..311b5fe2a 100644 --- a/db/routines/bs/procedures/comercialesCompleto.sql +++ b/db/routines/bs/procedures/comercialesCompleto.sql @@ -99,8 +99,8 @@ BEGIN LEFT JOIN (SELECT c.Id_Cliente, IF(MAX(Fecha) < DATE_FORMAT(TIMESTAMPADD(MONTH, - 1, vDate), '%Y- %m-01'), TRUE, FALSE) muerto - FROM vn.invoiceOut f - JOIN vn2008.Clientes c ON c.Id_cliente = f.clientFk + FROM vn.invoiceOut io + JOIN vn2008.Clientes c ON c.Id_cliente = io.clientFk LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador WHERE (c.Id_Trabajador = vWorker OR tr.boss = vWorker) GROUP BY Id_Cliente) dead ON dead.Id_Cliente = c.Id_Cliente diff --git a/db/routines/bs/procedures/ventas_contables_add.sql b/db/routines/bs/procedures/ventas_contables_add.sql index 6cca2ff7f..9988c8b29 100644 --- a/db/routines/bs/procedures/ventas_contables_add.sql +++ b/db/routines/bs/procedures/ventas_contables_add.sql @@ -23,9 +23,9 @@ BEGIN ENGINE = MEMORY SELECT Id_Ticket FROM vn2008.Tickets t - JOIN vn.invoiceOut f ON f.id = t.Factura - WHERE year(f.issued) = vYear - AND month(f.issued) = vMonth; + JOIN vn.invoiceOut io ON io.id = t.Factura + WHERE year(io.issued) = vYear + AND month(io.issued) = vMonth; INSERT INTO bs.ventas_contables(year , month diff --git a/db/routines/bs/procedures/ventas_contables_por_cliente.sql b/db/routines/bs/procedures/ventas_contables_por_cliente.sql index b5b7a39d5..931653e6e 100644 --- a/db/routines/bs/procedures/ventas_contables_por_cliente.sql +++ b/db/routines/bs/procedures/ventas_contables_por_cliente.sql @@ -13,9 +13,9 @@ BEGIN (PRIMARY KEY (Id_Ticket)) SELECT Id_Ticket FROM vn2008.Tickets t - JOIN vn.invoiceOut f ON f.id = t.Factura - WHERE year(f.issued) = vYear - AND month(f.issued) = vMonth; + JOIN vn.invoiceOut io ON io.id = t.Factura + WHERE year(io.issued) = vYear + AND month(io.issued) = vMonth; SELECT vYear Año, vMonth Mes, diff --git a/db/routines/bs/procedures/vivosMuertos.sql b/db/routines/bs/procedures/vivosMuertos.sql index 9cd0e3605..c07570603 100644 --- a/db/routines/bs/procedures/vivosMuertos.sql +++ b/db/routines/bs/procedures/vivosMuertos.sql @@ -24,20 +24,20 @@ BEGIN WHERE date BETWEEN @datSTART AND @datEND ) tm LEFT JOIN - (SELECT DISTINCT tm.yearMonth, f.clientFk Id_Cliente , 1 as Compra - FROM vn.invoiceOut f - JOIN vn2008.time tm ON tm.date = f.issued - WHERE Fecha BETWEEN @datSTART + (SELECT DISTINCT tm.yearMonth, io.clientFk Id_Cliente , 1 as Compra + FROM vn.invoiceOut io + JOIN vn2008.time tm ON tm.date = io.issued + WHERE io.issued BETWEEN @datSTART AND @datEND) f ON f.yearMonth = tm.yearMonth AND f.Id_Cliente = c.Id_Cliente; UPDATE tmp.VivosMuertos vm JOIN - (SELECT MIN(tm.yearMonth) firstMonth, f.clientFk Id_Cliente - FROM vn.invoiceOut f - JOIN vn2008.time tm ON tm.date = f.issued - WHERE Fecha BETWEEN @datSTART AND @datEND - GROUP BY f.clientFk) fm ON fm.firstMonth = vm.yearMonth + (SELECT MIN(tm.yearMonth) firstMonth, io.clientFk Id_Cliente + FROM vn.invoiceOut io + JOIN vn2008.time tm ON tm.date = io.issued + WHERE io.issued BETWEEN @datSTART AND @datEND + GROUP BY io.clientFk) fm ON fm.firstMonth = vm.yearMonth AND fm.Id_Cliente = vm.Id_Cliente SET Nuevo = 1; @@ -46,11 +46,11 @@ BEGIN UPDATE tmp.VivosMuertos vm JOIN ( - SELECT MAX(tm.yearMonth) firstMonth, f.clientFk Id_Cliente - FROM vn.invoiceOut f - JOIN vn2008.time tm ON tm.date = f.issued - WHERE Fecha BETWEEN @datSTART AND @datEND - GROUP BY f.clientFk) fm ON fm.firstMonth = vm.yearMonth + SELECT MAX(tm.yearMonth) firstMonth, io.clientFk Id_Cliente + FROM vn.invoiceOut io + JOIN vn2008.time tm ON tm.date = io.issued + WHERE io.issued BETWEEN @datSTART AND @datEND + GROUP BY io.clientFk) fm ON fm.firstMonth = vm.yearMonth AND fm.Id_Cliente = vm.Id_Cliente SET Muerto = 1 diff --git a/db/routines/vn2008/procedures/CalculoRemesas.sql b/db/routines/vn2008/procedures/CalculoRemesas.sql index e7d1ae22c..3819130ee 100644 --- a/db/routines/vn2008/procedures/CalculoRemesas.sql +++ b/db/routines/vn2008/procedures/CalculoRemesas.sql @@ -47,13 +47,13 @@ BEGIN UNION ALL - SELECT d.companyFk, f.clientFk Id_Cliente, - f.amount - FROM vn.invoiceOut f - JOIN Clientes c ON c.Id_Cliente = f.clientFk + SELECT d.companyFk, io.clientFk Id_Cliente, - io.amount + FROM vn.invoiceOut io + JOIN Clientes c ON c.Id_Cliente = io.clientFk JOIN pay_met pm on pm.id = pay_met_id - WHERE f.dued > vFechaRemesa + WHERE io.dued > vFechaRemesa AND pay_met_id = 4 AND pm.deudaviva - AND f.amount > 0 + AND io.amount > 0 ) risk ON c.Id_Cliente = risk.clientFk GROUP BY risk.companyFk, Id_Cliente diff --git a/db/routines/vn2008/procedures/customerDebtEvolution.sql b/db/routines/vn2008/procedures/customerDebtEvolution.sql index 20ed75d8f..df857462c 100644 --- a/db/routines/vn2008/procedures/customerDebtEvolution.sql +++ b/db/routines/vn2008/procedures/customerDebtEvolution.sql @@ -18,10 +18,10 @@ SELECT * FROM WHERE Id_Cliente = vCustomer AND Fechacobro >= '2017-01-01' UNION ALL - SELECT vn.getDueDate(f.issued,c.Vencimiento), - Importe - FROM vn.invoiceOut f - JOIN Clientes c ON f.clientFk = c.Id_Cliente - WHERE f.clientFk = vCustomer + SELECT vn.getDueDate(io.issued,c.Vencimiento), - Importe + FROM vn.invoiceOut io + JOIN Clientes c ON io.clientFk = c.Id_Cliente + WHERE io.clientFk = vCustomer AND Fecha >= '2017-01-01' UNION ALL SELECT '2016-12-31', Debt