refactor: refs #6778 Migrated views of vn2008 to vn #1996

Merged
guillermo merged 14 commits from 6778-changeViewDependencesVn2008 into dev 2024-02-14 13:17:47 +00:00
7 changed files with 32 additions and 32 deletions
Showing only changes of commit 18c10e2dd7 - Show all commits

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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