diff --git a/db/routines/bi/procedures/Greuge_Evolution_Add.sql b/db/routines/bi/procedures/Greuge_Evolution_Add.sql index 83033cbf8..1d4bf4355 100644 --- a/db/routines/bi/procedures/Greuge_Evolution_Add.sql +++ b/db/routines/bi/procedures/Greuge_Evolution_Add.sql @@ -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 diff --git a/db/routines/bi/procedures/claim_ratio_routine.sql b/db/routines/bi/procedures/claim_ratio_routine.sql index e5a5310b4..10cb717cf 100644 --- a/db/routines/bi/procedures/claim_ratio_routine.sql +++ b/db/routines/bi/procedures/claim_ratio_routine.sql @@ -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)); diff --git a/db/routines/bi/procedures/defaulting.sql b/db/routines/bi/procedures/defaulting.sql index 50600e554..e8ba5e682 100644 --- a/db/routines/bi/procedures/defaulting.sql +++ b/db/routines/bi/procedures/defaulting.sql @@ -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; diff --git a/db/routines/bi/procedures/greuge_dif_porte_add.sql b/db/routines/bi/procedures/greuge_dif_porte_add.sql index c81e41661..02bd9eae4 100644 --- a/db/routines/bi/procedures/greuge_dif_porte_add.sql +++ b/db/routines/bi/procedures/greuge_dif_porte_add.sql @@ -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 diff --git a/db/routines/bs/procedures/comercialesCompleto.sql b/db/routines/bs/procedures/comercialesCompleto.sql index 2b8019175..101173740 100644 --- a/db/routines/bs/procedures/comercialesCompleto.sql +++ b/db/routines/bs/procedures/comercialesCompleto.sql @@ -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 diff --git a/db/routines/bs/procedures/manaCustomerUpdate.sql b/db/routines/bs/procedures/manaCustomerUpdate.sql index 1e9cb8429..2cb25d135 100644 --- a/db/routines/bs/procedures/manaCustomerUpdate.sql +++ b/db/routines/bs/procedures/manaCustomerUpdate.sql @@ -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 diff --git a/db/routines/bs/procedures/ventas_contables_add.sql b/db/routines/bs/procedures/ventas_contables_add.sql index d8e963e3e..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 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 diff --git a/db/routines/bs/procedures/ventas_contables_por_cliente.sql b/db/routines/bs/procedures/ventas_contables_por_cliente.sql index 9f1399025..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 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, diff --git a/db/routines/bs/procedures/vivosMuertos.sql b/db/routines/bs/procedures/vivosMuertos.sql index 1743eda64..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.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 diff --git a/db/routines/vn/functions/isPalletHomogeneus.sql b/db/routines/vn/functions/isPalletHomogeneus.sql index 39c6461ae..b38fdcc5e 100644 --- a/db/routines/vn/functions/isPalletHomogeneus.sql +++ b/db/routines/vn/functions/isPalletHomogeneus.sql @@ -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; diff --git a/db/routines/vn/procedures/getDayExpeditions.sql b/db/routines/vn/procedures/getDayExpeditions.sql index 949cf4e5b..b708c8b0e 100644 --- a/db/routines/vn/procedures/getDayExpeditions.sql +++ b/db/routines/vn/procedures/getDayExpeditions.sql @@ -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 ; diff --git a/db/routines/vn/procedures/itemFuentesBalance.sql b/db/routines/vn/procedures/itemFuentesBalance.sql index d793841ee..e60273340 100644 --- a/db/routines/vn/procedures/itemFuentesBalance.sql +++ b/db/routines/vn/procedures/itemFuentesBalance.sql @@ -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 ; diff --git a/db/routines/vn/procedures/itemShelvingRadar.sql b/db/routines/vn/procedures/itemShelvingRadar.sql index c860d239e..c89a190ae 100644 --- a/db/routines/vn/procedures/itemShelvingRadar.sql +++ b/db/routines/vn/procedures/itemShelvingRadar.sql @@ -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; diff --git a/db/routines/vn/procedures/shelving_getSpam.sql b/db/routines/vn/procedures/shelving_getSpam.sql index eccbfb9a4..2895470ad 100644 --- a/db/routines/vn/procedures/shelving_getSpam.sql +++ b/db/routines/vn/procedures/shelving_getSpam.sql @@ -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; diff --git a/db/routines/vn2008/procedures/CalculoRemesas.sql b/db/routines/vn2008/procedures/CalculoRemesas.sql index 17a2e7fdd..a4c191a80 100644 --- a/db/routines/vn2008/procedures/CalculoRemesas.sql +++ b/db/routines/vn2008/procedures/CalculoRemesas.sql @@ -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 diff --git a/db/routines/vn2008/procedures/ListaTicketsEncajados.sql b/db/routines/vn2008/procedures/ListaTicketsEncajados.sql index 3d3318c63..ce99916ee 100644 --- a/db/routines/vn2008/procedures/ListaTicketsEncajados.sql +++ b/db/routines/vn2008/procedures/ListaTicketsEncajados.sql @@ -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 diff --git a/db/routines/vn2008/procedures/availableTraslate.sql b/db/routines/vn2008/procedures/availableTraslate.sql index 6328560c8..a3d2c8bea 100644 --- a/db/routines/vn2008/procedures/availableTraslate.sql +++ b/db/routines/vn2008/procedures/availableTraslate.sql @@ -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 diff --git a/db/routines/vn2008/procedures/balance_create.sql b/db/routines/vn2008/procedures/balance_create.sql index 978dae720..2acd26834 100644 --- a/db/routines/vn2008/procedures/balance_create.sql +++ b/db/routines/vn2008/procedures/balance_create.sql @@ -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 ; diff --git a/db/routines/vn2008/procedures/customerDebtEvolution.sql b/db/routines/vn2008/procedures/customerDebtEvolution.sql index e5d23f0ef..b9763b985 100644 --- a/db/routines/vn2008/procedures/customerDebtEvolution.sql +++ b/db/routines/vn2008/procedures/customerDebtEvolution.sql @@ -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 diff --git a/db/routines/vn2008/views/Facturas.sql b/db/routines/vn2008/views/Facturas.sql deleted file mode 100644 index bc99c02d8..000000000 --- a/db/routines/vn2008/views/Facturas.sql +++ /dev/null @@ -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` diff --git a/db/routines/vn2008/views/Gastos.sql b/db/routines/vn2008/views/Gastos.sql deleted file mode 100644 index 2eee445d8..000000000 --- a/db/routines/vn2008/views/Gastos.sql +++ /dev/null @@ -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` diff --git a/db/routines/vn2008/views/Greuges.sql b/db/routines/vn2008/views/Greuges.sql deleted file mode 100644 index 8958ec455..000000000 --- a/db/routines/vn2008/views/Greuges.sql +++ /dev/null @@ -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` diff --git a/db/routines/vn2008/views/Greuges_type.sql b/db/routines/vn2008/views/Greuges_type.sql deleted file mode 100644 index 500a1cc03..000000000 --- a/db/routines/vn2008/views/Greuges_type.sql +++ /dev/null @@ -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` diff --git a/db/routines/vn2008/views/Intrastat.sql b/db/routines/vn2008/views/Intrastat.sql deleted file mode 100644 index 9ed3ef283..000000000 --- a/db/routines/vn2008/views/Intrastat.sql +++ /dev/null @@ -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` diff --git a/db/routines/vn2008/views/expeditions.sql b/db/routines/vn2008/views/expeditions.sql deleted file mode 100644 index d93e2a1c6..000000000 --- a/db/routines/vn2008/views/expeditions.sql +++ /dev/null @@ -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`) - ) diff --git a/db/routines/vn2008/views/gestdoc.sql b/db/routines/vn2008/views/gestdoc.sql deleted file mode 100644 index f9fef2895..000000000 --- a/db/routines/vn2008/views/gestdoc.sql +++ /dev/null @@ -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` diff --git a/db/routines/vn2008/views/gesttip.sql b/db/routines/vn2008/views/gesttip.sql deleted file mode 100644 index 663e70617..000000000 --- a/db/routines/vn2008/views/gesttip.sql +++ /dev/null @@ -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` diff --git a/db/routines/vn2008/views/intrastat_data.sql b/db/routines/vn2008/views/intrastat_data.sql deleted file mode 100644 index 54853b69c..000000000 --- a/db/routines/vn2008/views/intrastat_data.sql +++ /dev/null @@ -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` diff --git a/db/routines/vn2008/views/invoiceCorrection.sql b/db/routines/vn2008/views/invoiceCorrection.sql deleted file mode 100644 index 5ed1d5844..000000000 --- a/db/routines/vn2008/views/invoiceCorrection.sql +++ /dev/null @@ -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` diff --git a/db/routines/vn2008/views/itemTag.sql b/db/routines/vn2008/views/itemTag.sql deleted file mode 100644 index ff247089f..000000000 --- a/db/routines/vn2008/views/itemTag.sql +++ /dev/null @@ -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` diff --git a/db/routines/vn2008/views/item_entry_in.sql b/db/routines/vn2008/views/item_entry_in.sql deleted file mode 100644 index 1cc7d21b1..000000000 --- a/db/routines/vn2008/views/item_entry_in.sql +++ /dev/null @@ -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 diff --git a/db/routines/vn2008/views/item_entry_out.sql b/db/routines/vn2008/views/item_entry_out.sql deleted file mode 100644 index d99672df8..000000000 --- a/db/routines/vn2008/views/item_entry_out.sql +++ /dev/null @@ -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 diff --git a/db/routines/vn2008/views/item_out.sql b/db/routines/vn2008/views/item_out.sql deleted file mode 100644 index 57353a6d6..000000000 --- a/db/routines/vn2008/views/item_out.sql +++ /dev/null @@ -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 diff --git a/db/versions/10868-grayChico/00-firstScript.sql b/db/versions/10868-grayChico/00-firstScript.sql new file mode 100644 index 000000000..d0b98362c --- /dev/null +++ b/db/versions/10868-grayChico/00-firstScript.sql @@ -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;