#6760 modify transferClient #2035
|
@ -42,9 +42,9 @@ BEGIN
|
|||
CREATE TEMPORARY TABLE maxInvoice
|
||||
(PRIMARY KEY (Id_Cliente))
|
||||
ENGINE = MEMORY
|
||||
SELECT DISTINCT Id_Cliente, max(Fecha) as maxFecha
|
||||
FROM vn2008.Facturas
|
||||
GROUP BY Id_Cliente
|
||||
SELECT DISTINCT clientFk Id_Cliente, max(issued) as maxFecha
|
||||
FROM vn.invoiceOut
|
||||
GROUP BY clientFk
|
||||
HAVING maxFecha < timestampadd(month,-2,datFEC);
|
||||
|
||||
WHILE datFEC < util.VN_CURDATE() DO
|
||||
|
@ -53,10 +53,10 @@ BEGIN
|
|||
|
||||
SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas, 0
|
||||
FROM (
|
||||
SELECT Id_Cliente, sum(Importe) as Greuge
|
||||
FROM vn2008.Greuges
|
||||
where Fecha <= datFEC
|
||||
group by Id_Cliente
|
||||
SELECT clientFk Id_Cliente, sum(amount) as Greuge
|
||||
FROM vn.greuge
|
||||
where shipped <= datFEC
|
||||
group by clientFk
|
||||
) sub
|
||||
RIGHT JOIN
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ BEGIN
|
|||
|
||||
-- Reclamaciones demasiado sensibles
|
||||
|
||||
INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario,
|
||||
Importe, Greuges_type_id,Id_Ticket)
|
||||
INSERT INTO vn.greuge(shipped, clientFk, description,
|
||||
amount, greugeTypeFk, ticketFk)
|
||||
SELECT cm.Fecha
|
||||
, cm.Id_Cliente
|
||||
, concat('Claim ',cm.id,' : ', m.Concepte)
|
||||
|
@ -29,8 +29,8 @@ BEGIN
|
|||
|
||||
-- Reclamaciones que pasan a Maná
|
||||
|
||||
INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario,
|
||||
Importe , Greuges_type_id,Id_Ticket)
|
||||
INSERT INTO vn.greuge(shipped, clientFk, description,
|
||||
amount, greugeTypeFk, ticketFk)
|
||||
SELECT cm.Fecha
|
||||
, cm.Id_Cliente
|
||||
, concat('Claim_mana ',cm.id,' : ', m.Concepte)
|
||||
|
@ -73,12 +73,12 @@ BEGIN
|
|||
AND s.alert_level >= 3;
|
||||
|
||||
DELETE g.*
|
||||
FROM vn2008.Greuges g
|
||||
JOIN tmp.ticket_list t ON g.Id_Ticket = t.Id_Ticket
|
||||
WHERE Greuges_type_id = 2;
|
||||
FROM vn.greuge g
|
||||
JOIN tmp.ticket_list t ON g.ticketFk = t.Id_Ticket
|
||||
WHERE g.greugeTypeFk = 2;
|
||||
|
||||
INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha,
|
||||
Greuges_type_id, Id_Ticket)
|
||||
INSERT INTO vn.greuge(clientFk, description, amount,shipped,
|
||||
greugeTypeFk, ticketFk)
|
||||
SELECT Id_Cliente
|
||||
,concat('recobro ', m.Id_Ticket), - round(SUM(mc.Valor*Cantidad),2)
|
||||
AS dif
|
||||
|
@ -130,10 +130,10 @@ BEGIN
|
|||
-- Calculamos el porcentaje del recobro para añadirlo al precio de venta
|
||||
UPDATE bi.claims_ratio cr
|
||||
JOIN (
|
||||
SELECT Id_Cliente, IFNULL(SUM(Importe), 0) AS Greuge
|
||||
FROM vn2008.Greuges
|
||||
WHERE Fecha <= util.VN_CURDATE()
|
||||
GROUP BY Id_Cliente
|
||||
SELECT clientFk Id_Cliente, IFNULL(SUM(amount), 0) AS Greuge
|
||||
FROM vn.greuge
|
||||
WHERE shipped <= util.VN_CURDATE()
|
||||
GROUP BY clientFk
|
||||
) g ON g.Id_Cliente = cr.Id_Cliente
|
||||
SET recobro = GREATEST(0,round(IFNULL(Greuge, 0) /
|
||||
(IFNULL(Consumo, 0) * vMonthToRefund / 12 ) ,3));
|
||||
|
|
|
@ -14,8 +14,8 @@ BEGIN
|
|||
WHERE hasChanged AND date = vDate;
|
||||
|
||||
DECLARE invoices CURSOR FOR
|
||||
SELECT Vencimiento, importe FROM vn2008.Facturas f
|
||||
WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC;
|
||||
SELECT dued Vencimiento, amount importe FROM vn.invoiceOut
|
||||
WHERE issued >= '2016-01-01' AND clientFk = vClient ORDER BY issued DESC;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ BEGIN
|
|||
FROM
|
||||
vn.ticket t
|
||||
JOIN vn2008.Clientes cli ON cli.Id_cliente = t.clientFk
|
||||
LEFT JOIN vn2008.expeditions e ON e.ticket_id = t.id
|
||||
JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.EsBulto
|
||||
LEFT JOIN vn.expedition e ON e.ticketFk = t.id
|
||||
JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk
|
||||
JOIN vn.zone z ON t.zoneFk = z.id
|
||||
WHERE
|
||||
t.shipped between datSTART AND datEND
|
||||
|
@ -64,17 +64,17 @@ BEGIN
|
|||
CREATE TEMPORARY TABLE tmp.dp_aux
|
||||
(PRIMARY KEY (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT dp.ticketFk, sum(Importe) Importe
|
||||
SELECT dp.ticketFk, sum(g.amount) Importe
|
||||
FROM tmp.dp
|
||||
JOIN vn2008.Greuges g ON g.Id_Ticket = dp.ticketFk
|
||||
WHERE Greuges_type_id = 1 -- dif_porte
|
||||
JOIN vn.greuge g ON g.ticketFk = dp.ticketFk
|
||||
WHERE g.greugeTypeFk = 1 -- dif_porte
|
||||
GROUP BY dp.ticketFk;
|
||||
|
||||
UPDATE tmp.dp
|
||||
JOIN tmp.dp_aux USING(ticketFk)
|
||||
SET greuge = IFNULL(Importe,0);
|
||||
|
||||
INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha, Greuges_type_id, Id_Ticket)
|
||||
INSERT INTO vn.greuge (clientFk,description,amount,shipped,greugeTypeFk,ticketFk)
|
||||
SELECT dp.clientFk
|
||||
, concat('dif_porte ', dp.ticketFk)
|
||||
, round(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0),2) as Importe
|
||||
|
|
|
@ -37,9 +37,9 @@ BEGIN
|
|||
FROM
|
||||
vn2008.Clientes c
|
||||
LEFT JOIN
|
||||
(SELECT g.Id_Cliente, CAST( SUM(Importe) as DECIMAL(12,2)) AS Greuge
|
||||
FROM vn2008.Greuges g
|
||||
JOIN vn.`client` c ON c.id = g.Id_Cliente
|
||||
(SELECT g.clientFk Id_Cliente, CAST( SUM(g.amount) as DECIMAL(12,2)) AS Greuge
|
||||
FROM vn.greuge g
|
||||
JOIN vn.`client` c ON c.id = g.clientFk
|
||||
LEFT JOIN vn.worker w ON c.salesPersonFk = w.id
|
||||
WHERE (c.salesPersonFk = vWorker OR w.bossFk = vWorker)
|
||||
GROUP BY Id_Cliente
|
||||
|
@ -98,9 +98,9 @@ BEGIN
|
|||
GROUP BY c.Id_Cliente) CmLy ON CmLy.Id_Cliente = c.Id_Cliente
|
||||
LEFT JOIN
|
||||
(SELECT c.Id_Cliente,
|
||||
IF(MAX(Fecha) < DATE_FORMAT(TIMESTAMPADD(MONTH, - 1, vDate), '%Y- %m-01'), TRUE, FALSE) muerto
|
||||
FROM vn2008.Facturas f
|
||||
JOIN vn2008.Clientes c ON c.Id_cliente = f.Id_Cliente
|
||||
IF(MAX(io.issued) < DATE_FORMAT(TIMESTAMPADD(MONTH, - 1, vDate), '%Y- %m-01'), TRUE, FALSE) muerto
|
||||
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
|
||||
|
|
|
@ -82,11 +82,11 @@ BEGIN
|
|||
AND Fechacobro > vFromDated
|
||||
AND Fechacobro <= vToDated
|
||||
UNION ALL
|
||||
SELECT g.Id_Cliente, g.Importe
|
||||
FROM vn2008.Greuges g
|
||||
WHERE Greuges_type_id = vManaGreugeTypeId
|
||||
AND Fecha > vFromDated
|
||||
AND Fecha <= vToDated
|
||||
SELECT clientFk, amount
|
||||
FROM vn.greuge
|
||||
WHERE greugeTypeFk = vManaGreugeTypeId
|
||||
AND shipped > vFromDated
|
||||
AND shipped <= vToDated
|
||||
UNION ALL
|
||||
SELECT clientFk, mana
|
||||
FROM vn.clientManaCache
|
||||
|
|
|
@ -23,9 +23,9 @@ BEGIN
|
|||
ENGINE = MEMORY
|
||||
SELECT Id_Ticket
|
||||
FROM vn2008.Tickets t
|
||||
JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura
|
||||
WHERE year(f.Fecha) = vYear
|
||||
AND month(f.Fecha) = 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
|
||||
|
|
|
@ -13,9 +13,9 @@ BEGIN
|
|||
(PRIMARY KEY (Id_Ticket))
|
||||
SELECT Id_Ticket
|
||||
FROM vn2008.Tickets t
|
||||
JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura
|
||||
WHERE year(f.Fecha) = vYear
|
||||
AND month(f.Fecha) = 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,
|
||||
|
|
|
@ -24,20 +24,20 @@ BEGIN
|
|||
WHERE date BETWEEN @datSTART
|
||||
AND @datEND ) tm
|
||||
LEFT JOIN
|
||||
(SELECT DISTINCT tm.yearMonth, f.Id_Cliente , 1 as Compra
|
||||
FROM vn2008.Facturas f
|
||||
JOIN vn2008.time tm ON tm.date = f.Fecha
|
||||
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.Id_Cliente
|
||||
FROM vn2008.Facturas f
|
||||
JOIN vn2008.time tm ON tm.date = f.Fecha
|
||||
WHERE Fecha BETWEEN @datSTART AND @datEND
|
||||
GROUP BY f.Id_Cliente ) 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.Id_Cliente
|
||||
FROM vn2008.Facturas f
|
||||
JOIN vn2008.time tm ON tm.date = f.Fecha
|
||||
WHERE Fecha BETWEEN @datSTART AND @datEND
|
||||
GROUP BY f.Id_Cliente ) 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
|
||||
|
|
|
@ -16,8 +16,8 @@ BEGIN
|
|||
FROM (
|
||||
SELECT DISTINCT t.Id_Ruta
|
||||
FROM vn2008.scan_line sl
|
||||
JOIN vn2008.expeditions e ON e.expeditions_id = sl.code
|
||||
JOIN vn2008.Tickets t ON t.Id_Ticket = e.ticket_id
|
||||
JOIN expedition e ON e.id = sl.code
|
||||
JOIN vn2008.Tickets t ON t.Id_Ticket = e.ticketFk
|
||||
WHERE sl.scan_id = vScanId
|
||||
AND t.Id_Ruta
|
||||
) t1;
|
||||
|
|
|
@ -3,13 +3,13 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`getDayExpeditions`(
|
|||
BEGIN
|
||||
|
||||
SELECT
|
||||
e.expeditions_id as expeditionFk,
|
||||
date_format(e.odbc_date,'%Y-%m-%d') as expeditionDate,
|
||||
e.ticket_id as ticketFk,
|
||||
e.id as expeditionFk,
|
||||
date_format(e.created,'%Y-%m-%d') as expeditionDate,
|
||||
e.ticketFk,
|
||||
t.routeFk as routeFk
|
||||
FROM vn2008.expeditions e
|
||||
INNER JOIN vn.ticket t ON t.id = e.ticket_id
|
||||
WHERE DATE(odbc_date) = util.VN_CURDATE();
|
||||
FROM expedition e
|
||||
INNER JOIN ticket t ON t.id = e.ticketFk
|
||||
WHERE DATE(e.created) = util.VN_CURDATE();
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -50,31 +50,30 @@ BEGIN
|
|||
) alb ON alb.itemFk = i.id
|
||||
LEFT JOIN cache.stock v ON i.id = v.item_id AND v.warehouse_id = vWarehouseFk
|
||||
LEFT JOIN (
|
||||
SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as venta
|
||||
FROM vn2008.item_out
|
||||
WHERE dat BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE()))
|
||||
AND warehouse_id = vWarehouseFk
|
||||
GROUP BY item_id
|
||||
SELECT itemFk item_id, CAST(sum(quantity)AS DECIMAL(10,0)) as venta
|
||||
FROM itemTicketOut
|
||||
WHERE shipped BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE()))
|
||||
AND warehouseFk = vWarehouseFk
|
||||
GROUP BY itemFk
|
||||
) sale ON sale.item_id = i.id
|
||||
LEFT JOIN (
|
||||
SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as compra
|
||||
FROM vn2008.item_entry_in
|
||||
WHERE dat BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE()))
|
||||
AND warehouse_id = vWarehouseFk
|
||||
SELECT itemFk item_id, CAST(sum(quantity)AS DECIMAL(10,0)) as compra
|
||||
FROM itemEntryIn
|
||||
WHERE landed BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE()))
|
||||
AND warehouseInFk = vWarehouseFk
|
||||
AND isVirtualStock = FALSE
|
||||
GROUP BY item_id
|
||||
GROUP BY itemFk
|
||||
) buy ON buy.item_id = i.id
|
||||
LEFT JOIN (
|
||||
SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as traslado
|
||||
FROM vn2008.item_entry_out
|
||||
WHERE dat BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE()))
|
||||
AND warehouse_id = vWarehouseFk
|
||||
GROUP BY item_id
|
||||
SELECT itemFk item_id, CAST(sum(quantity)AS DECIMAL(10,0)) as traslado
|
||||
FROM itemEntryOut
|
||||
WHERE shipped BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE()))
|
||||
AND warehouseOutFk = vWarehouseFk
|
||||
GROUP BY itemFk
|
||||
) mov ON mov.item_id = i.id
|
||||
WHERE (v.amount OR fue.Fuentes OR alb.Albenfruit)
|
||||
AND i.itemPackingTypeFk = 'H'
|
||||
AND ic.shortLife
|
||||
;
|
||||
AND ic.shortLife;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -143,12 +143,12 @@ proc:BEGIN
|
|||
CREATE TEMPORARY TABLE tmp.itemOutTime
|
||||
SELECT *,SUM(amount) quantity
|
||||
FROM
|
||||
(SELECT item_id itemFk,
|
||||
amount,
|
||||
(SELECT io.itemFk,
|
||||
io.quantity amount,
|
||||
IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) as hours,
|
||||
IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) as minutes
|
||||
FROM vn2008.item_out io
|
||||
JOIN tmp.itemShelvingRadar isr ON isr.itemFk = io.item_id
|
||||
FROM itemTicketOut io
|
||||
JOIN tmp.itemShelvingRadar isr ON isr.itemFk = io.itemFk
|
||||
JOIN vn.ticket t on t.id= io.ticketFk
|
||||
JOIN vn.ticketState ts on ts.ticketFk = io.ticketFk
|
||||
JOIN vn.state s ON s.id = ts.stateFk
|
||||
|
@ -160,10 +160,10 @@ proc:BEGIN
|
|||
) stPrevious ON `stPrevious`.`saleFk` = io.saleFk
|
||||
WHERE t.warehouseFk = vWarehouseFk
|
||||
AND s.isPicked = 0
|
||||
AND NOT io.Reservado
|
||||
AND NOT io.reserved
|
||||
AND stPrevious.saleFk IS NULL
|
||||
AND io.dat >= util.VN_CURDATE()
|
||||
AND io.dat < util.VN_CURDATE() + INTERVAL 1 DAY
|
||||
AND io.shipped >= util.VN_CURDATE()
|
||||
AND io.shipped < util.VN_CURDATE() + INTERVAL 1 DAY
|
||||
) sub
|
||||
GROUP BY itemFk, hours, minutes;
|
||||
|
||||
|
|
|
@ -34,26 +34,26 @@ BEGIN
|
|||
) fue ON fue.itemFk = i.id
|
||||
LEFT JOIN cache.stock v ON i.id = v.item_id AND v.warehouse_id = vWarehouseFk
|
||||
LEFT JOIN (
|
||||
SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as venta
|
||||
FROM vn2008.item_out
|
||||
WHERE dat BETWEEN util.VN_CURDATE() AND util.dayend(vDated)
|
||||
AND warehouse_id = vWarehouseFk
|
||||
GROUP BY item_id
|
||||
SELECT itemFk item_id, CAST(sum(quantity)AS DECIMAL(10,0)) as venta
|
||||
FROM itemTicketOut
|
||||
WHERE shipped BETWEEN util.VN_CURDATE() AND util.dayend(vDated)
|
||||
AND warehouseFk = vWarehouseFk
|
||||
GROUP BY itemFk
|
||||
) sale ON sale.item_id = i.id
|
||||
LEFT JOIN (
|
||||
SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as compra
|
||||
FROM vn2008.item_entry_in
|
||||
WHERE dat BETWEEN util.VN_CURDATE() AND util.dayend(vDated)
|
||||
AND warehouse_id = vWarehouseFk
|
||||
SELECT itemFk item_id, CAST(sum(quantity)AS DECIMAL(10,0)) as compra
|
||||
FROM itemEntryIn
|
||||
WHERE landed BETWEEN util.VN_CURDATE() AND util.dayend(vDated)
|
||||
AND warehouseInFk = vWarehouseFk
|
||||
AND isVirtualStock = FALSE
|
||||
GROUP BY item_id
|
||||
GROUP BY itemFk
|
||||
) buy ON buy.item_id = i.id
|
||||
LEFT JOIN (
|
||||
SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as traslado
|
||||
FROM vn2008.item_entry_out
|
||||
WHERE dat BETWEEN util.VN_CURDATE() AND util.dayend(vDated)
|
||||
AND warehouse_id = vWarehouseFk
|
||||
GROUP BY item_id
|
||||
SELECT itemFk item_id, CAST(sum(quantity)AS DECIMAL(10,0)) as traslado
|
||||
FROM itemEntryOut
|
||||
WHERE shipped BETWEEN util.VN_CURDATE() AND util.dayend(vDated)
|
||||
AND warehouseOutFk = vWarehouseFk
|
||||
GROUP BY itemFk
|
||||
) mov ON mov.item_id = i.id
|
||||
WHERE v.amount;
|
||||
|
||||
|
|
|
@ -47,13 +47,13 @@ BEGIN
|
|||
|
||||
UNION ALL
|
||||
|
||||
SELECT empresa_id, Id_Cliente, - Importe
|
||||
FROM Facturas f
|
||||
JOIN Clientes c using(Id_Cliente)
|
||||
SELECT io.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.Vencimiento > vFechaRemesa
|
||||
WHERE io.dued > vFechaRemesa
|
||||
AND pay_met_id = 4 AND pm.deudaviva
|
||||
AND Importe > 0
|
||||
AND io.amount > 0
|
||||
|
||||
) risk ON c.Id_Cliente = risk.clientFk
|
||||
GROUP BY risk.companyFk, Id_Cliente
|
||||
|
|
|
@ -13,9 +13,9 @@ SELECT Agencia,
|
|||
FROM Tickets ti
|
||||
INNER JOIN Consignatarios ON ti.Id_Consigna = Consignatarios.Id_consigna
|
||||
INNER JOIN Agencias ON ti.Id_Agencia = Agencias.Id_Agencia
|
||||
LEFT JOIN (SELECT Ticket_Id,count(*) AS ncajas FROM expeditions WHERE Id_Article=94 GROUP BY ticket_id) sub1 ON ti.Id_Ticket=sub1.Ticket_Id
|
||||
LEFT JOIN (SELECT Ticket_Id,count(*) AS nbultos FROM expeditions WHERE Id_Article IS NULL GROUP BY ticket_id) sub2 ON ti.Id_Ticket=sub2.Ticket_Id
|
||||
LEFT JOIN (SELECT Ticket_Id,count(*) AS notros FROM expeditions WHERE Id_Article >0 GROUP BY ticket_id) sub3 ON ti.Id_Ticket=sub3.Ticket_Id
|
||||
LEFT JOIN (SELECT ticketFk,count(*) AS ncajas FROM vn.expedition WHERE packagingFk=94 GROUP BY ticketFk) sub1 ON ti.Id_Ticket=sub1.ticketFk
|
||||
LEFT JOIN (SELECT ticketFk,count(*) AS nbultos FROM vn.expedition WHERE packagingFk IS NULL GROUP BY ticketFk) sub2 ON ti.Id_Ticket=sub2.ticketFk
|
||||
LEFT JOIN (SELECT ticketFk,count(*) AS notros FROM vn.expedition WHERE packagingFk >0 GROUP BY ticketFk) sub3 ON ti.Id_Ticket=sub3.ticketFk
|
||||
INNER JOIN vn.ticketState ts ON ti.Id_ticket = ts.ticketFk
|
||||
WHERE ti.Fecha=util.VN_CURDATE() AND
|
||||
ts.userFk=intId_Trabajador
|
||||
|
|
|
@ -67,12 +67,12 @@ proc: BEGIN
|
|||
CREATE TEMPORARY TABLE tmp.itemCalc
|
||||
(INDEX (itemFk,warehouseFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT i.item_id itemFk, vWarehouseLanding warehouseFk, i.dat dated, i.amount quantity
|
||||
FROM item_out i
|
||||
JOIN itemRangeLive ir ON ir.itemFK = i.item_id
|
||||
WHERE i.dat >= vDatedFrom
|
||||
AND (ir.dated IS NULL OR i.dat <= ir.dated)
|
||||
AND i.warehouse_id = vWarehouseLanding
|
||||
SELECT i.itemFk, vWarehouseLanding warehouseFk, i.shipped dated, i.quantity
|
||||
FROM vn.itemTicketOut i
|
||||
JOIN itemRangeLive ir ON ir.itemFK = i.itemFk
|
||||
WHERE i.shipped >= vDatedFrom
|
||||
AND (ir.dated IS NULL OR i.shipped <= ir.dated)
|
||||
AND i.warehouseFk = vWarehouseLanding
|
||||
UNION ALL
|
||||
SELECT b.itemFk, vWarehouseLanding, t.landed, b.quantity
|
||||
FROM vn.buy b
|
||||
|
@ -86,12 +86,12 @@ proc: BEGIN
|
|||
AND t.landed >= vDatedFrom
|
||||
AND (ir.dated IS NULL OR t.landed <= ir.dated)
|
||||
UNION ALL
|
||||
SELECT i.item_id, vWarehouseLanding, i.dat, i.amount
|
||||
FROM item_entry_out i
|
||||
JOIN itemRangeLive ir ON ir.itemFk = i.item_id
|
||||
WHERE i.dat >= vDatedFrom
|
||||
AND (ir.dated IS NULL OR i.dat <= ir.dated)
|
||||
AND i.warehouse_id = vWarehouseLanding
|
||||
SELECT i.itemFk, vWarehouseLanding, i.shipped, i.quantity
|
||||
FROM vn.itemEntryOut i
|
||||
JOIN itemRangeLive ir ON ir.itemFk = i.itemFk
|
||||
WHERE i.shipped >= vDatedFrom
|
||||
AND (ir.dated IS NULL OR i.shipped <= ir.dated)
|
||||
AND i.warehouseOutFk = vWarehouseLanding
|
||||
UNION ALL
|
||||
SELECT r.item_id, vWarehouseLanding, r.shipment, -r.amount
|
||||
FROM hedera.order_row r
|
||||
|
|
|
@ -122,9 +122,9 @@ BEGIN
|
|||
-- Añadimos los gastos, para facilitar el formulario
|
||||
UPDATE tmp.balance b
|
||||
JOIN vn2008.balance_nest_tree bnt on bnt.id = b.id
|
||||
JOIN (SELECT Id_Gasto, Gasto
|
||||
FROM vn2008.Gastos
|
||||
GROUP BY Id_Gasto) g ON g.Id_Gasto = bnt.Id_Gasto COLLATE utf8_general_ci
|
||||
JOIN (SELECT id Id_Gasto, name Gasto
|
||||
FROM vn.expense
|
||||
GROUP BY id) g ON g.Id_Gasto = bnt.Id_Gasto COLLATE utf8_general_ci
|
||||
SET b.Id_Gasto = g.Id_Gasto COLLATE utf8_general_ci
|
||||
, b.Gasto = g.Gasto COLLATE utf8_general_ci ;
|
||||
|
||||
|
|
|
@ -18,11 +18,11 @@ SELECT * FROM
|
|||
WHERE Id_Cliente = vCustomer
|
||||
AND Fechacobro >= '2017-01-01'
|
||||
UNION ALL
|
||||
SELECT vn.getDueDate(f.Fecha,c.Vencimiento), - Importe
|
||||
FROM Facturas f
|
||||
JOIN Clientes c ON f.Id_Cliente = c.Id_Cliente
|
||||
WHERE f.Id_Cliente = vCustomer
|
||||
AND Fecha >= '2017-01-01'
|
||||
SELECT vn.getDueDate(io.issued,c.Vencimiento), - io.amount
|
||||
FROM vn.invoiceOut io
|
||||
JOIN Clientes c ON io.clientFk = c.Id_Cliente
|
||||
WHERE io.clientFk = vCustomer
|
||||
AND io.issued >= '2017-01-01'
|
||||
UNION ALL
|
||||
SELECT '2016-12-31', Debt
|
||||
FROM bi.customerDebtInventory
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`Facturas`
|
||||
AS SELECT `io`.`id` AS `factura_id`,
|
||||
`io`.`ref` AS `Id_Factura`,
|
||||
`io`.`serial` AS `Serie`,
|
||||
`io`.`issued` AS `Fecha`,
|
||||
`io`.`amount` AS `Importe`,
|
||||
`io`.`clientFk` AS `Id_Cliente`,
|
||||
`io`.`created` AS `odbc_date`,
|
||||
`io`.`companyFk` AS `empresa_id`,
|
||||
`io`.`dued` AS `Vencimiento`,
|
||||
`io`.`booked` AS `booked`,
|
||||
`io`.`bankFk` AS `Id_Banco`,
|
||||
`io`.`siiTypeInvoiceOutFk` AS `siiTypeInvoiceOutFk`,
|
||||
`io`.`cplusTaxBreakFk` AS `cplusTaxBreakFk`,
|
||||
`io`.`cplusSubjectOpFk` AS `cplusSubjectOpFk`,
|
||||
`io`.`siiTrascendencyInvoiceOutFk` AS `siiTrascendencyInvoiceOutFk`,
|
||||
`io`.`hasPdf` AS `pdf`
|
||||
FROM `vn`.`invoiceOut` `io`
|
|
@ -1,7 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`Gastos`
|
||||
AS SELECT `e`.`id` AS `Id_Gasto`,
|
||||
`e`.`name` AS `Gasto`,
|
||||
`e`.`isWithheld` AS `isWithheld`
|
||||
FROM `vn`.`expense` `e`
|
|
@ -1,12 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`Greuges`
|
||||
AS SELECT `g`.`Id` AS `Id`,
|
||||
`g`.`clientFk` AS `Id_Cliente`,
|
||||
`g`.`description` AS `Comentario`,
|
||||
`g`.`amount` AS `Importe`,
|
||||
`g`.`shipped` AS `Fecha`,
|
||||
`g`.`created` AS `odbc_date`,
|
||||
`g`.`greugeTypeFk` AS `Greuges_type_id`,
|
||||
`g`.`ticketFk` AS `Id_Ticket`
|
||||
FROM `vn`.`greuge` `g`
|
|
@ -1,6 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`Greuges_type`
|
||||
AS SELECT `gt`.`id` AS `Greuges_type_id`,
|
||||
`gt`.`name` AS `name`
|
||||
FROM `vn`.`greugeType` `gt`
|
|
@ -1,8 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`Intrastat`
|
||||
AS SELECT `i`.`id` AS `Codintrastat`,
|
||||
`i`.`description` AS `Definicion`,
|
||||
`i`.`taxClassFk` AS `iva_group_id`,
|
||||
`i`.`taxCodeFk` AS `iva_codigo_id`
|
||||
FROM `vn`.`intrastat` `i`
|
|
@ -1,16 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`expeditions`
|
||||
AS SELECT `e`.`id` AS `expeditions_id`,
|
||||
`e`.`agencyModeFk` AS `agency_id`,
|
||||
`e`.`ticketFk` AS `ticket_id`,
|
||||
`e`.`freightItemFk` AS `EsBulto`,
|
||||
`e`.`created` AS `odbc_date`,
|
||||
`e`.`counter` AS `counter`,
|
||||
`e`.`workerFk` AS `workerFk`,
|
||||
`e`.`externalId` AS `externalId`,
|
||||
`p`.`itemFk` AS `Id_article`
|
||||
FROM (
|
||||
`vn`.`expedition` `e`
|
||||
LEFT JOIN `vn`.`packaging` `p` ON(`p`.`id` = `e`.`packagingFk`)
|
||||
)
|
|
@ -1,16 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`gestdoc`
|
||||
AS SELECT `d`.`id` AS `id`,
|
||||
`d`.`dmsTypeFk` AS `gesttip_id`,
|
||||
`d`.`file` AS `file`,
|
||||
`d`.`contentType` AS `contentType`,
|
||||
`d`.`workerFk` AS `trabajador_id`,
|
||||
`d`.`warehouseFk` AS `warehouse_id`,
|
||||
`d`.`companyFk` AS `emp_id`,
|
||||
`d`.`hardCopyNumber` AS `orden`,
|
||||
`d`.`hasFile` AS `original`,
|
||||
`d`.`reference` AS `sref`,
|
||||
`d`.`description` AS `brief`,
|
||||
`d`.`created` AS `odbc_date`
|
||||
FROM `vn`.`dms` `d`
|
|
@ -1,9 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`gesttip`
|
||||
AS SELECT `g`.`id` AS `id`,
|
||||
`g`.`name` AS `tipo`,
|
||||
`g`.`readRoleFk` AS `readRoleFk`,
|
||||
`g`.`writeRoleFk` AS `writeRoleFk`,
|
||||
`g`.`code` AS `code`
|
||||
FROM `vn`.`dmsType` `g`
|
|
@ -1,13 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`intrastat_data`
|
||||
AS SELECT `ii`.`id` AS `id`,
|
||||
`ii`.`invoiceInFk` AS `recibida_id`,
|
||||
`ii`.`net` AS `neto`,
|
||||
`ii`.`intrastatFk` AS `intrastat_id`,
|
||||
`ii`.`amount` AS `importe`,
|
||||
`ii`.`stems` AS `unidades`,
|
||||
`ii`.`countryFk` AS `Paises_Id`,
|
||||
`ii`.`dated` AS `odbc_date`,
|
||||
`ii`.`statisticalValue` AS `valorestadistico`
|
||||
FROM `vn`.`invoiceInIntrastat` `ii`
|
|
@ -1,9 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`invoiceCorrection`
|
||||
AS SELECT `ic`.`correctingFk` AS `correctingFk`,
|
||||
`ic`.`correctedFk` AS `correctedFk`,
|
||||
`ic`.`cplusRectificationTypeFk` AS `cplusRectificationTypeFk`,
|
||||
`ic`.`siiTypeInvoiceOutFk` AS `siiTypeInvoiceOutFk`,
|
||||
`ic`.`invoiceCorrectionTypeFk` AS `invoiceCorrectionTypeFk`
|
||||
FROM `vn`.`invoiceCorrection` `ic`
|
|
@ -1,9 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`itemTag`
|
||||
AS SELECT `i`.`id` AS `id`,
|
||||
`i`.`itemFk` AS `itemFk`,
|
||||
`i`.`tagFk` AS `tagFk`,
|
||||
`i`.`value` AS `value`,
|
||||
`i`.`priority` AS `priority`
|
||||
FROM `vn`.`itemTag` `i`
|
|
@ -1,20 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`item_entry_in`
|
||||
AS SELECT `t`.`warehouse_id` AS `warehouse_id`,
|
||||
`t`.`warehouse_id_out` AS `warehouse_id_out`,
|
||||
`t`.`landing` AS `dat`,
|
||||
`m`.`Id_Article` AS `item_id`,
|
||||
`m`.`Cantidad` AS `amount`,
|
||||
`t`.`received` AS `received`,
|
||||
`e`.`Redada` AS `isVirtualStock`,
|
||||
`e`.`Id_Entrada` AS `entryFk`
|
||||
FROM (
|
||||
(
|
||||
`vn2008`.`Compres` `m`
|
||||
JOIN `vn2008`.`Entradas` `e` ON(`m`.`Id_Entrada` = `e`.`Id_Entrada`)
|
||||
)
|
||||
JOIN `vn2008`.`travel` `t` ON(`e`.`travel_id` = `t`.`id`)
|
||||
)
|
||||
WHERE `e`.`Inventario` = 0
|
||||
AND `m`.`Cantidad` <> 0
|
|
@ -1,27 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`item_entry_out`
|
||||
AS SELECT `t`.`warehouse_id_out` AS `warehouse_id`,
|
||||
`t`.`shipment` AS `dat`,
|
||||
`m`.`Id_Article` AS `item_id`,
|
||||
- `m`.`Cantidad` AS `amount`,
|
||||
`t`.`delivered` <> 0
|
||||
OR IFNULL(`co`.`valor`, 0) AS `delivered`,
|
||||
`e`.`Id_Entrada` AS `entryFk`
|
||||
FROM (
|
||||
(
|
||||
(
|
||||
`vn2008`.`Compres` `m`
|
||||
JOIN `vn2008`.`Entradas` `e` ON(`m`.`Id_Entrada` = `e`.`Id_Entrada`)
|
||||
)
|
||||
JOIN `vn2008`.`travel` `t` ON(`e`.`travel_id` = `t`.`id`)
|
||||
)
|
||||
LEFT JOIN `vn2008`.`Compres_ok` `co` ON(
|
||||
`co`.`Id_Compra` = `m`.`Id_Compra`
|
||||
AND `co`.`Id_Accion` = 3
|
||||
AND `co`.`valor` <> 0
|
||||
)
|
||||
)
|
||||
WHERE `e`.`Inventario` = 0
|
||||
AND `e`.`Redada` = 0
|
||||
AND `m`.`Cantidad` <> 0
|
|
@ -1,17 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`item_out`
|
||||
AS SELECT `t`.`warehouse_id` AS `warehouse_id`,
|
||||
`t`.`Fecha` AS `dat`,
|
||||
`m`.`Id_Article` AS `item_id`,
|
||||
- `m`.`Cantidad` AS `amount`,
|
||||
`m`.`OK` AS `ok`,
|
||||
`m`.`Reservado` AS `Reservado`,
|
||||
`t`.`Factura` AS `invoice`,
|
||||
`m`.`Id_Movimiento` AS `saleFk`,
|
||||
`m`.`Id_Ticket` AS `ticketFk`
|
||||
FROM (
|
||||
`vn2008`.`Movimientos` `m`
|
||||
JOIN `vn2008`.`Tickets` `t` ON(`m`.`Id_Ticket` = `t`.`Id_Ticket`)
|
||||
)
|
||||
WHERE `m`.`Cantidad` <> 0
|
|
@ -6,9 +6,11 @@ CHANGE COLUMN IF EXISTS `Id_Gasto` `expenseFk` varchar(10) DEFAULT NULL;
|
|||
ALTER TABLE vn.balanceNestTree
|
||||
MODIFY COLUMN IF EXISTS expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL;
|
||||
|
||||
UPDATE vn.balanceNestTree
|
||||
SET expenseFk = NULL
|
||||
WHERE expenseFk ='';
|
||||
UPDATE vn.balanceNestTree b
|
||||
LEFT JOIN vn.expense e ON e.id = b.expenseFk COLLATE utf8mb3_general_ci
|
||||
SET b.expenseFk = NULL
|
||||
WHERE b.expenseFk =''
|
||||
OR (e.id IS NULL AND b.expenseFk IS NOT NULL);
|
||||
|
||||
ALTER TABLE IF EXISTS vn.balanceNestTree ADD CONSTRAINT balanceNestTree_expense_FK
|
||||
FOREIGN KEY (expenseFk) REFERENCES vn.expense(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
REVOKE SELECT ON TABLE vn2008.expeditions FROM employee;
|
||||
REVOKE SELECT, INSERT, UPDATE, DELETE ON TABLE vn2008.Gastos FROM administrative;
|
||||
REVOKE SELECT ON TABLE vn2008.Facturas FROM salesPerson;
|
||||
REVOKE SELECT ON TABLE vn2008.Facturas FROM logistic;
|
||||
REVOKE SELECT ON TABLE vn2008.Facturas FROM palletizer;
|
||||
REVOKE SELECT ON TABLE vn2008.Facturas FROM hr;
|
||||
REVOKE SELECT ON TABLE vn2008.gestdoc FROM employee;
|
||||
REVOKE INSERT, UPDATE ON TABLE vn2008.gestdoc FROM administrative;
|
||||
REVOKE DELETE ON TABLE vn2008.gestdoc FROM hr;
|
||||
REVOKE SELECT ON TABLE vn2008.gesttip FROM employee;
|
||||
REVOKE SELECT ON TABLE vn2008.Greuges FROM employee;
|
||||
REVOKE SELECT ON TABLE vn2008.Greuges_type FROM financial;
|
||||
REVOKE SELECT ON TABLE vn2008.intrastat_data FROM buyer;
|
||||
REVOKE SELECT, INSERT, UPDATE, DELETE ON TABLE vn2008.intrastat_data FROM administrative;
|
||||
REVOKE SELECT, INSERT ON TABLE vn2008.invoiceCorrection FROM administrative;
|
|
@ -0,0 +1,13 @@
|
|||
ALTER TABLE vn.vehicle ADD supplierFk int(10) unsigned NULL COMMENT 'supplier from whom the vehicle was purchased';
|
||||
ALTER TABLE vn.vehicle ADD CONSTRAINT vehicle_supplierFk FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id);
|
||||
|
||||
ALTER TABLE vn.vehicle ADD import decimal(10,2) NULL;
|
||||
|
||||
ALTER TABLE vn.vehicle ADD supplierCoolerFk int(10) unsigned NULL;
|
||||
ALTER TABLE vn.vehicle ADD CONSTRAINT vehicle_supplierCoolerFk FOREIGN KEY (supplierCoolerFk) REFERENCES vn.supplier(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE vn.vehicle ADD vin varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL;
|
||||
|
||||
ALTER TABLE vn.vehicle ADD bankPolicyFk int(11) NULL;
|
||||
ALTER TABLE vn.vehicle ADD CONSTRAINT vehicle_bankPolicyFk FOREIGN KEY (bankPolicyFk) REFERENCES vn.bankPolicy(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
|
@ -22,7 +22,6 @@
|
|||
label="Vehicle"
|
||||
ng-model="$ctrl.route.vehicleFk"
|
||||
url="Vehicles"
|
||||
where="{warehouseFk: $ctrl.vnConfig.warehouseFk}"
|
||||
show-field="numberPlate">
|
||||
</vn-autocomplete>
|
||||
<vn-autocomplete
|
||||
|
|
Loading…
Reference in New Issue