refactor: refs #6778 Migrated views of vn2008 to vn #1996
|
@ -54,7 +54,7 @@ BEGIN
|
||||||
SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas, 0
|
SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas, 0
|
||||||
FROM (
|
FROM (
|
||||||
SELECT clientFk Id_Cliente, sum(amount) as Greuge
|
SELECT clientFk Id_Cliente, sum(amount) as Greuge
|
||||||
FROM vn2.greuge
|
FROM vn.greuge
|
||||||
where shipped <= datFEC
|
where shipped <= datFEC
|
||||||
group by clientFk
|
group by clientFk
|
||||||
) sub
|
) sub
|
||||||
|
|
|
@ -99,8 +99,8 @@ BEGIN
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
(SELECT c.Id_Cliente,
|
(SELECT c.Id_Cliente,
|
||||||
IF(MAX(Fecha) < DATE_FORMAT(TIMESTAMPADD(MONTH, - 1, vDate), '%Y- %m-01'), TRUE, FALSE) muerto
|
IF(MAX(Fecha) < DATE_FORMAT(TIMESTAMPADD(MONTH, - 1, vDate), '%Y- %m-01'), TRUE, FALSE) muerto
|
||||||
FROM vn.invoiceOut f
|
FROM vn.invoiceOut io
|
||||||
JOIN vn2008.Clientes c ON c.Id_cliente = f.clientFk
|
JOIN vn2008.Clientes c ON c.Id_cliente = io.clientFk
|
||||||
LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
|
LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
|
||||||
WHERE (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
|
WHERE (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
|
||||||
GROUP BY Id_Cliente) dead ON dead.Id_Cliente = c.Id_Cliente
|
GROUP BY Id_Cliente) dead ON dead.Id_Cliente = c.Id_Cliente
|
||||||
|
|
|
@ -23,9 +23,9 @@ BEGIN
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT Id_Ticket
|
SELECT Id_Ticket
|
||||||
FROM vn2008.Tickets t
|
FROM vn2008.Tickets t
|
||||||
JOIN vn.invoiceOut f ON f.id = t.Factura
|
JOIN vn.invoiceOut io ON io.id = t.Factura
|
||||||
WHERE year(f.issued) = vYear
|
WHERE year(io.issued) = vYear
|
||||||
AND month(f.issued) = vMonth;
|
AND month(io.issued) = vMonth;
|
||||||
|
|
||||||
INSERT INTO bs.ventas_contables(year
|
INSERT INTO bs.ventas_contables(year
|
||||||
, month
|
, month
|
||||||
|
|
|
@ -13,9 +13,9 @@ BEGIN
|
||||||
(PRIMARY KEY (Id_Ticket))
|
(PRIMARY KEY (Id_Ticket))
|
||||||
SELECT Id_Ticket
|
SELECT Id_Ticket
|
||||||
FROM vn2008.Tickets t
|
FROM vn2008.Tickets t
|
||||||
JOIN vn.invoiceOut f ON f.id = t.Factura
|
JOIN vn.invoiceOut io ON io.id = t.Factura
|
||||||
WHERE year(f.issued) = vYear
|
WHERE year(io.issued) = vYear
|
||||||
AND month(f.issued) = vMonth;
|
AND month(io.issued) = vMonth;
|
||||||
|
|
||||||
SELECT vYear Año,
|
SELECT vYear Año,
|
||||||
vMonth Mes,
|
vMonth Mes,
|
||||||
|
|
|
@ -24,20 +24,20 @@ BEGIN
|
||||||
WHERE date BETWEEN @datSTART
|
WHERE date BETWEEN @datSTART
|
||||||
AND @datEND ) tm
|
AND @datEND ) tm
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
(SELECT DISTINCT tm.yearMonth, f.clientFk Id_Cliente , 1 as Compra
|
(SELECT DISTINCT tm.yearMonth, io.clientFk Id_Cliente , 1 as Compra
|
||||||
FROM vn.invoiceOut f
|
FROM vn.invoiceOut io
|
||||||
JOIN vn2008.time tm ON tm.date = f.issued
|
JOIN vn2008.time tm ON tm.date = io.issued
|
||||||
WHERE Fecha BETWEEN @datSTART
|
WHERE io.issued BETWEEN @datSTART
|
||||||
AND @datEND) f ON f.yearMonth = tm.yearMonth
|
AND @datEND) f ON f.yearMonth = tm.yearMonth
|
||||||
AND f.Id_Cliente = c.Id_Cliente;
|
AND f.Id_Cliente = c.Id_Cliente;
|
||||||
|
|
||||||
UPDATE tmp.VivosMuertos vm
|
UPDATE tmp.VivosMuertos vm
|
||||||
JOIN
|
JOIN
|
||||||
(SELECT MIN(tm.yearMonth) firstMonth, f.clientFk Id_Cliente
|
(SELECT MIN(tm.yearMonth) firstMonth, io.clientFk Id_Cliente
|
||||||
FROM vn.invoiceOut f
|
FROM vn.invoiceOut io
|
||||||
JOIN vn2008.time tm ON tm.date = f.issued
|
JOIN vn2008.time tm ON tm.date = io.issued
|
||||||
WHERE Fecha BETWEEN @datSTART AND @datEND
|
WHERE io.issued BETWEEN @datSTART AND @datEND
|
||||||
GROUP BY f.clientFk) fm ON fm.firstMonth = vm.yearMonth
|
GROUP BY io.clientFk) fm ON fm.firstMonth = vm.yearMonth
|
||||||
AND fm.Id_Cliente = vm.Id_Cliente
|
AND fm.Id_Cliente = vm.Id_Cliente
|
||||||
|
|
||||||
SET Nuevo = 1;
|
SET Nuevo = 1;
|
||||||
|
@ -46,11 +46,11 @@ BEGIN
|
||||||
|
|
||||||
UPDATE tmp.VivosMuertos vm
|
UPDATE tmp.VivosMuertos vm
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT MAX(tm.yearMonth) firstMonth, f.clientFk Id_Cliente
|
SELECT MAX(tm.yearMonth) firstMonth, io.clientFk Id_Cliente
|
||||||
FROM vn.invoiceOut f
|
FROM vn.invoiceOut io
|
||||||
JOIN vn2008.time tm ON tm.date = f.issued
|
JOIN vn2008.time tm ON tm.date = io.issued
|
||||||
WHERE Fecha BETWEEN @datSTART AND @datEND
|
WHERE io.issued BETWEEN @datSTART AND @datEND
|
||||||
GROUP BY f.clientFk) fm ON fm.firstMonth = vm.yearMonth
|
GROUP BY io.clientFk) fm ON fm.firstMonth = vm.yearMonth
|
||||||
AND fm.Id_Cliente = vm.Id_Cliente
|
AND fm.Id_Cliente = vm.Id_Cliente
|
||||||
|
|
||||||
SET Muerto = 1
|
SET Muerto = 1
|
||||||
|
|
|
@ -47,13 +47,13 @@ BEGIN
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
|
||||||
SELECT d.companyFk, f.clientFk Id_Cliente, - f.amount
|
SELECT d.companyFk, io.clientFk Id_Cliente, - io.amount
|
||||||
FROM vn.invoiceOut f
|
FROM vn.invoiceOut io
|
||||||
JOIN Clientes c ON c.Id_Cliente = f.clientFk
|
JOIN Clientes c ON c.Id_Cliente = io.clientFk
|
||||||
JOIN pay_met pm on pm.id = pay_met_id
|
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 pay_met_id = 4 AND pm.deudaviva
|
||||||
AND f.amount > 0
|
AND io.amount > 0
|
||||||
|
|
||||||
) risk ON c.Id_Cliente = risk.clientFk
|
) risk ON c.Id_Cliente = risk.clientFk
|
||||||
GROUP BY risk.companyFk, Id_Cliente
|
GROUP BY risk.companyFk, Id_Cliente
|
||||||
|
|
|
@ -18,10 +18,10 @@ SELECT * FROM
|
||||||
WHERE Id_Cliente = vCustomer
|
WHERE Id_Cliente = vCustomer
|
||||||
AND Fechacobro >= '2017-01-01'
|
AND Fechacobro >= '2017-01-01'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT vn.getDueDate(f.issued,c.Vencimiento), - Importe
|
SELECT vn.getDueDate(io.issued,c.Vencimiento), - Importe
|
||||||
FROM vn.invoiceOut f
|
FROM vn.invoiceOut io
|
||||||
JOIN Clientes c ON f.clientFk = c.Id_Cliente
|
JOIN Clientes c ON io.clientFk = c.Id_Cliente
|
||||||
WHERE f.clientFk = vCustomer
|
WHERE io.clientFk = vCustomer
|
||||||
AND Fecha >= '2017-01-01'
|
AND Fecha >= '2017-01-01'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT '2016-12-31', Debt
|
SELECT '2016-12-31', Debt
|
||||||
|
|
Loading…
Reference in New Issue