Merge branch 'dev' into 5586-optimizeNegativeBases
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Guillermo Bonet 2024-02-15 06:50:03 +00:00
commit 46a1ad35b5
59 changed files with 720 additions and 825 deletions

View File

@ -87,6 +87,6 @@ module.exports = Self => {
await fs.access(file.path);
const stream = fs.createReadStream(file.path);
return [stream, file.contentType, `filename="${file.name}"`];
return [stream, file.contentType, `filename="${fileName}"`];
};
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,41 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_check`()
BEGIN
/**
* Realiza la revisión diaria de los asientos contables,
* identificando y notificando los asientos descuadrados
* y ajustando los saldos en caso necesario.
*/
INSERT INTO mail (receiver, subject, body)
SELECT 'cau@verdnatura.es',
'Asientos descuadrados',
GROUP_CONCAT(CONCAT(' Asiento: ', ASIEN, ' - Importe:', recon) SEPARATOR ' | \n')
FROM (
SELECT ASIEN,
SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon
FROM XDiario
WHERE NOT enlazado
GROUP BY ASIEN
HAVING ABS(SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0))) > 0.01
) sub
HAVING COUNT(*);
UPDATE XDiario xd
JOIN (
SELECT xd.id, SUBCTA, recon
FROM XDiario xd
JOIN (
SELECT ASIEN,
SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon
FROM XDiario
WHERE NOT enlazado
GROUP BY ASIEN
HAVING recon
) sub ON sub.ASIEN = xd.ASIEN
WHERE xd.SUBCTA > '5999999999'
GROUP BY xd.ASIEN
) sub ON sub.id = xd.id
SET xd.Eurohaber = IF(IFNULL(xd.Eurohaber, 0) = 0, xd.Eurohaber, xd.Eurohaber + sub.recon),
xd.Eurodebe = IF(IFNULL(xd.Eurodebe, 0) = 0, xd.Eurodebe, xd.Eurodebe - sub.recon);
END$$
DELIMITER ;

View File

@ -0,0 +1,211 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_getTransfer`(
vSelf INT
)
BEGIN
/**
* Retorna los artículos trasladables a partir de una entrada.
*
* @param vSelf Id de entrada
*/
DECLARE vDateShipped DATE;
DECLARE vDateLanded DATE;
DECLARE vWarehouseIn INT;
DECLARE vWarehouseOut INT;
DECLARE vCalcVisible INT;
DECLARE vInventoryDate DATE DEFAULT vn.getInventoryDate();
SELECT shipped, landed, warehouseInFk, warehouseOutFk
INTO vDateShipped, vDateLanded, vWarehouseIn, vWarehouseOut
FROM vn.travel t
JOIN vn.entry e ON e.travelFk = t.id
WHERE e.id = vSelf;
CALL vn.rate_getPrices(vDateShipped, vWarehouseIn);
-- Traslado en almacen origen
CREATE OR REPLACE TEMPORARY TABLE tBuy
(PRIMARY KEY (itemFk), INDEX(buyFk))
ENGINE = MEMORY
SELECT *
FROM (
SELECT b.itemFk, b.id buyFk
FROM buy b
JOIN entry e ON e.id = b.entryFk
JOIN travel t ON t.id = e.travelFk
WHERE t.landed BETWEEN vInventoryDate AND vDateShipped
AND NOT b.isIgnored
AND b.price2 >= 0
ORDER BY (vWarehouseOut = t.warehouseInFk) DESC, t.landed DESC
LIMIT 10000000000000000000
) sub
GROUP BY itemFk;
IF vDateShipped >= util.VN_CURDATE() THEN
CALL `cache`.visible_refresh(vCalcVisible, TRUE, vWarehouseOut);
CREATE OR REPLACE TEMPORARY TABLE tItem (
`itemFk` int(10) unsigned NOT NULL,
`visible` int(11) NOT NULL DEFAULT 0,
`available` int(11) NOT NULL DEFAULT 0,
`visibleLanding` int(11) NOT NULL DEFAULT 0,
`availableLanding` int(11) NOT NULL DEFAULT 0,
UNIQUE INDEX i USING HASH (itemFk)
) ENGINE = MEMORY;
INSERT INTO tItem(itemFk, visible)
SELECT item_id itemFk, visible
FROM `cache`.visible
WHERE calc_id = vCalcVisible
AND visible;
CALL `cache`.visible_refresh(vCalcVisible, TRUE, vWarehouseIn);
INSERT INTO tItem(itemFk, visibleLanding)
SELECT item_id, `visible`
FROM `cache`.`visible` v
WHERE v.calc_id = vCalcVisible
AND v.`visible`
ON DUPLICATE KEY UPDATE visibleLanding = v.`visible`;
CALL vn2008.availableTraslate(vWarehouseOut, vDateShipped, NULL);
INSERT INTO tItem(itemFk, available)
SELECT a.item_id, a.available
FROM vn2008.availableTraslate a
WHERE a.available
ON DUPLICATE KEY UPDATE available = a.available;
CALL vn2008.availableTraslate(vWarehouseIn, vDateLanded, vWarehouseOut);
INSERT INTO tItem(itemFk, availableLanding)
SELECT a.item_id, a.available
FROM vn2008.availableTraslate a
WHERE a.available
ON DUPLICATE KEY UPDATE availableLanding = a.available;
ELSE
CALL vn.item_getStock(vWarehouseOut, vDateShipped, NULL);
CREATE OR REPLACE TEMPORARY TABLE tItem
(UNIQUE INDEX i USING HASH (itemFk))
ENGINE = MEMORY
SELECT itemFk,
`visible`,
available,
0 visibleLanding,
0 availableLanding
FROM tmp.itemList;
END IF;
CALL vn.buyUltimateFromInterval(vWarehouseIn,vInventoryDate, vDateLanded);
CREATE OR REPLACE TEMPORARY TABLE tTransfer
ENGINE = MEMORY
SELECT it.code `type`,
it.categoryFk,
i.typeFk,
i.id itemFk,
i.name item,
i.`size`,
i.category,
i.inkFk,
o.code originCode,
b2.quantity,
i.stems,
CAST(ti.visible AS DECIMAL(10,0)) vis1,
CAST(ti.available AS DECIMAL(10,0)) ava1,
CAST(ti.visibleLanding AS DECIMAL(10,0)) vis2,
CAST(ti.availableLanding AS DECIMAL(10,0)) ava2,
COALESCE(b2.`grouping`, b.`grouping`) `grouping`,
COALESCE(b2.packing, b.packing) packing,
COALESCE(b3.groupingMode, b2.groupingMode, b.groupingMode) package,
IFNULL(p.name, s.nickname) productor,
TRUE tinta,
b.packagingFk,
b2.id buyFk,
b2.stickers,
b.ektFk,
it.workerFk,
pa.volume,
IFNULL(pa.width, 0) width,
IFNULL(pa.`depth`, 0) `depth`,
IFNULL(pa.height, 0) height,
IFNULL(b.buyingValue, 0) buyingValue,
IFNULL(b.comissionValue, 0) comissionValue,
IFNULL(b.freightValue, 0) freightValue,
am.m3,
e.commission,
pa.isPackageReturnable,
IFNULL(pa2.value, pa.value) `value`,
r.rate3 r3,
r.rate2 r2,
it.promo,
b.`grouping` groupingOrigin,
b.packing packingOrigin,
b.id buyFkOrigin,
pa.returnCost,
b.weight
FROM vn.item i
JOIN tItem ti ON ti.itemFk = i.id
LEFT JOIN vn.producer p ON p.id = i.producerFk
LEFT JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.itemCategory ic ON ic.id = it.categoryFk
LEFT JOIN vn.origin o ON o.id = i.originFk
LEFT JOIN tBuy lb ON lb.itemFk = i.id
LEFT JOIN vn.buy b ON b.id = lb.buyFk
LEFT JOIN vn.packaging pa ON pa.id = b.packagingFk
LEFT JOIN vn.entry e2 ON e2.id = b.entryFk
LEFT JOIN vn.supplier s ON s.id = e2.supplierFk
LEFT JOIN vn.entry e ON e.id = vSelf
LEFT JOIN vn.travel tr ON tr.id = e.travelFk
LEFT JOIN vn.agencyMode am ON am.id = tr.agencyModeFk
LEFT JOIN vn.buy b2 ON b2.itemFk = i.id
AND b2.entryFk = vSelf
LEFT JOIN vn.packaging pa2 ON pa2.id = b.packagingFk
LEFT JOIN tmp.rate r ON TRUE
LEFT JOIN tmp.buyUltimateFromInterval bufi ON bufi.itemFk = i.id
LEFT JOIN vn.buy b3 ON b3.id = bufi.buyFk
WHERE ic.display
AND NOT e.isRaid
AND (ti.visible OR ti.available)
ORDER BY i.typeFk, i.name, i.id, i.size, i.category, o.name;
CREATE INDEX tIndex USING HASH ON tTransfer (itemFk);
SET @carriage := 0;
SET @comission := 0;
SET @packaging := 0;
SET @rate3 := 0;
SET @cost := 0;
SELECT *,
quantity - MOD(quantity , `grouping`) subQuantity,
MOD(quantity, `grouping`) soll,
ROUND((IF(volume > 0,volume, width * `depth` *
IF(height = 0, `size` + 10, height))) /
packing, 0) cm3,
buyingValue + comissionValue + freightValue cost,
@carriage := ROUND((IF(volume > 0, volume, width * `depth` *
IF(height = 0, `size` + 10, height))) *
m3 / 1000000 / Packing, 3) carriage,
@comission := ROUND((buyingValue + comissionValue + freightValue) *
commission / 100, 3) commission,
ROUND(@packaging := (returnCost + IF(isPackageReturnable, 0, value))
/ packing, 3) packaging,
@cost := IFNULL((buyingValue + comissionValue + freightValue), 0) +
IFNULL(@packaging, 0) +
IFNULL(@carriage, 0) +
IFNULL(@comission, 0) expense,
@rate3 := ROUND(@cost / ( (100 - r3 - promo) / 100), 2) rate3,
ROUND(@rate3 * (1 + ((r2 - r3)/100)), 2) rate2,
FALSE selected
FROM tTransfer;
DROP TEMPORARY TABLE IF EXISTS
tTransfer,
tItem,
tBuy,
tmp.buyUltimateFromInterval,
tmp.rate,
tmp.itemList;
END$$
DELIMITER ;

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,139 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplier_statement`(
vSupplierFk INT,
vCurrencyFk INT,
vCompanyFk INT,
vOrderBy VARCHAR(15),
vIsConciliated BOOL
)
BEGIN
/**
* Crea un estado de cuenta de proveedores calculando
* los saldos en euros y en la moneda especificada.
*
* @param vSupplierFk Id del proveedor
* @param vCurrencyFk Id de la moneda
* @param vCompanyFk Id de la empresa
* @param vOrderBy Criterio de ordenación
* @param vIsConciliated Indica si está conciliado o no
* @return tmp.supplierStatement
*/
SET @euroBalance:= 0;
SET @currencyBalance:= 0;
CREATE OR REPLACE TEMPORARY TABLE tmp.supplierStatement
ENGINE = MEMORY
SELECT *,
@euroBalance:= ROUND(
@euroBalance + IFNULL(paymentEuros, 0) -
IFNULL(invoiceEuros, 0), 2
) euroBalance,
@currencyBalance:= ROUND(
@currencyBalance + IFNULL(paymentCurrency, 0) -
IFNULL(invoiceCurrency, 0), 2
) currencyBalance
FROM (
SELECT * FROM
(
SELECT NULL bankFk,
ii.companyFk,
ii.serial,
ii.id,
CASE
WHEN vOrderBy = 'issued' THEN ii.issued
WHEN vOrderBy = 'bookEntried' THEN ii.bookEntried
WHEN vOrderBy = 'booked' THEN ii.booked
WHEN vOrderBy = 'dueDate' THEN iid.dueDated
END dated,
CONCAT('S/Fra ', ii.supplierRef) sref,
IF(ii.currencyFk > 1,
ROUND(SUM(iid.foreignValue) / SUM(iid.amount), 3),
NULL
) changeValue,
CAST(SUM(iid.amount) AS DECIMAL(10,2)) invoiceEuros,
CAST(SUM(iid.foreignValue) AS DECIMAL(10,2)) invoiceCurrency,
NULL paymentEuros,
NULL paymentCurrency,
ii.currencyFk,
ii.isBooked,
c.code,
'invoiceIn' statementType
FROM invoiceIn ii
JOIN invoiceInDueDay iid ON iid.invoiceInFk = ii.id
JOIN currency c ON c.id = ii.currencyFk
WHERE ii.issued > '2014-12-31'
AND ii.supplierFk = vSupplierFk
AND vCurrencyFk IN (ii.currencyFk, 0)
AND vCompanyFk IN (ii.companyFk, 0)
AND (vIsConciliated = ii.isBooked OR NOT vIsConciliated)
GROUP BY iid.id
UNION ALL
SELECT p.bankFk,
p.companyFk,
NULL,
p.id,
CASE
WHEN vOrderBy = 'issued' THEN p.received
WHEN vOrderBy = 'bookEntried' THEN p.received
WHEN vOrderBy = 'booked' THEN p.received
WHEN vOrderBy = 'dueDate' THEN p.dueDated
END,
CONCAT(IFNULL(pm.name, ''),
IF(pn.concept <> '',
CONCAT(' : ', pn.concept),
'')
),
IF(p.currencyFk > 1, p.divisa / p.amount, NULL),
NULL,
NULL,
p.amount,
p.divisa,
p.currencyFk,
p.isConciliated,
c.code,
'payment'
FROM payment p
LEFT JOIN currency c ON c.id = p.currencyFk
LEFT JOIN bank b ON b.id = p.bankFk
LEFT JOIN payMethod pm ON pm.id = p.payMethodFk
LEFT JOIN promissoryNote pn ON pn.paymentFk = p.id
WHERE p.received > '2014-12-31'
AND p.supplierFk = vSupplierFk
AND vCurrencyFk IN (p.currencyFk, 0)
AND vCompanyFk IN (p.companyFk, 0)
AND (vIsConciliated = p.isConciliated OR NOT vIsConciliated)
UNION ALL
SELECT NULL,
companyFk,
NULL,
se.id,
CASE
WHEN vOrderBy = 'issued' THEN se.dated
WHEN vOrderBy = 'bookEntried' THEN se.dated
WHEN vOrderBy = 'booked' THEN se.dated
WHEN vOrderBy = 'dueDate' THEN se.dueDated
END,
se.description,
1,
amount,
NULL,
NULL,
NULL,
currencyFk,
isConciliated,
c.`code`,
'expense'
FROM supplierExpense se
JOIN currency c ON c.id = se.currencyFk
WHERE se.supplierFk = vSupplierFk
AND vCurrencyFk IN (se.currencyFk,0)
AND vCompanyFk IN (se.companyFk,0)
AND (vIsConciliated = se.isConciliated OR NOT vIsConciliated)
) sub
ORDER BY (dated IS NULL AND NOT isBooked),
dated,
IF(vOrderBy = 'dueDate', id, NULL)
LIMIT 10000000000000000000
) t;
END$$
DELIMITER ;

View File

@ -0,0 +1,109 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_getDetailFromContinent`(
vContinentFk INT
)
BEGIN
/**
* Devuelve los detalles de los vuelos que tienen
* un almacén de salida de un continente.
*
* @param vContinentFk Id de continente
*/
DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK;
SELECT IFNULL(CONCAT(" ", entryFk), travelFk) travelAndEntry,
sub.*
FROM (
SELECT tr.id travelFk,
NULL entryFk,
TRUE isTravel,
am.name agency,
tr.ref,
tr.shipped,
wOut.name originBoxes,
tr.landed,
wIn.name destination,
SUM(b.stickers) stickers,
NULL evaNotes,
tr.kg,
CAST(SUM(b.weight * b.stickers) AS INT) loadedkg,
CAST(
SUM(vc.aerealVolumetricDensity *
b.stickers *
IF(p.volume,
p.volume,
p.width * p.depth * p.height
) / 1000000
) AS INT
) volumeKg,
NULL loadPriority,
NULL invoiceAmount,
s.nickname freighter,
NULL reference
FROM travel tr
LEFT JOIN supplier s ON s.id = tr.cargoSupplierFk
LEFT JOIN entry e ON e.travelFk = tr.id
LEFT JOIN buy b ON b.entryFk = e.id
LEFT JOIN packaging p ON p.id = b.packagingFk
LEFT JOIN item i ON i.id = b.itemFk
LEFT JOIN itemType it ON it.id = i.typeFk
JOIN warehouse wIn ON wIn.id = tr.warehouseInFk
JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk
JOIN country co ON co.id = wOut.countryFk
JOIN agencyMode am ON am.id = tr.agencyModeFk
JOIN volumeConfig vc
WHERE tr.landed >= vDateFrom
AND co.continentFk = vContinentFk
GROUP BY tr.id
UNION ALL
SELECT e.travelFk,
e.id,
FALSE,
s.name,
e.invoiceNumber,
tr.shipped,
wOut.name,
tr.landed,
wIn.name,
SUM(b.stickers),
e.evaNotes,
NULL,
CAST(SUM(b.weight * b.stickers) AS INT),
CAST(
SUM(vc.aerealVolumetricDensity *
b.stickers *
IF(p.volume,
p.volume,
p.width * p.depth * p.height
) / 1000000
) AS INT
),
loadPriority,
e.invoiceAmount,
s2.nickname,
e.reference
FROM entry e
JOIN buy b ON b.entryFk = e.id
JOIN packaging p ON p.id = b.packagingFk
JOIN item i ON i.id = b.itemFk
JOIN itemType it ON it.id = i.typeFk
JOIN supplier s ON s.id = e.supplierFk
JOIN travel tr ON tr.id = e.travelFk
LEFT JOIN supplier s2 ON s2.id = tr.cargoSupplierFk
JOIN warehouse wIn ON wIn.id = tr.warehouseInFk
JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk
JOIN country co ON co.id = wOut.countryFk
JOIN volumeConfig vc
WHERE tr.landed >= vDateFrom
AND co.continentFk = vContinentFk
GROUP BY e.id
) sub
ORDER BY landed ASC,
shipped ASC,
travelFk,
isTravel DESC,
(loadPriority > 0) DESC,
loadPriority,
agency,
evaNotes;
END$$
DELIMITER ;

View File

@ -1,5 +1,5 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`budgetNotes_BeforeInsert`
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`budgetNotes_beforeInsert`
BEFORE INSERT ON `budgetNotes`
FOR EACH ROW
BEGIN

View File

@ -1,7 +0,0 @@
CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`agencyWarehouse`
AS SELECT `a`.`agency_id` AS `agencyFk`,
`a`.`warehouse_id` AS `warehouseFk`,
`a`.`Vista` AS `agencyType`
FROM `vn2008`.`agency_warehouse` `a`

View File

@ -1,9 +0,0 @@
CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`clientDefaultCompany`
AS SELECT `t`.`Id_Clientes_empresa` AS `id`,
`t`.`Id_Cliente` AS `clientFk`,
`t`.`empresa_id` AS `companyFk`,
`t`.`fecha_ini` AS `started`,
`t`.`fecha_fin` AS `finished`
FROM `vn2008`.`Clientes_empresa` `t`

View File

@ -1,6 +0,0 @@
CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`coolerPath`
AS SELECT `c`.`cooler_path_id` AS `id`,
`c`.`description` AS `description`
FROM `vn2008`.`cooler_path` `c`

View File

@ -1,7 +0,0 @@
CREATE OR REPLACE DEFINER=`root`@`localhost`
SQL SECURITY DEFINER
VIEW `vn`.`grantGroup`
AS SELECT `vn2008`.`Grupos`.`id` AS `id`,
`vn2008`.`Grupos`.`Grupo` AS `description`,
`vn2008`.`Grupos`.`observation_type_id` AS `observationTypeFk`
FROM `vn2008`.`Grupos`

View File

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

View File

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

View File

@ -1,34 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`XDiario_Quadrator`()
BEGIN
INSERT INTO vn.mail (receiver, subject, body)
SELECT 'cau@verdnatura.es',
'asientos descuadrados',
group_concat(CONCAT(' Asiento: ', ASIEN, '- importe:', quadre) SEPARATOR ' \r\n ')
FROM (
SELECT ASIEN, SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) quadre
FROM vn.XDiario
WHERE enlazado = FALSE
GROUP BY ASIEN
HAVING ABS(SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0))) > 0.01
) t
HAVING count(*) > 0;
UPDATE vn.XDiario XD
INNER JOIN(
SELECT XD.id, SUBCTA, Quadre FROM vn.XDiario XD
INNER JOIN (
SELECT ASIEN, SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) as Quadre
FROM vn.XDiario
WHERE enlazado = FALSE
GROUP BY ASIEN
HAVING Quadre != 0
) sub USING(ASIEN)
WHERE SUBCTA > '5999999999'
GROUP BY ASIEN
) sub2 USING(id)
SET Eurohaber = IF(IFNULL(Eurohaber,0) = 0, Eurohaber, Eurohaber + Quadre),
Eurodebe = IF(IFNULL(Eurodebe,0) = 0, Eurodebe, Eurodebe - Quadre);
END$$
DELIMITER ;

View File

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

View File

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

View File

@ -21,18 +21,10 @@ proc: BEGIN
SET vRangeDeleteTicket = 60;
DELETE FROM cdr WHERE calldate < vDate18;
DELETE FROM Monitoring WHERE ODBC_TIME < vDate;
DELETE FROM Conteo WHERE Fecha < vDate;
DELETE FROM mail WHERE DATE_ODBC < vDate;
DELETE FROM expeditions_deleted WHERE odbc_date < vDate26;
DELETE FROM Movimientos_mark WHERE odbc_date < vDate;
DELETE FROM Splits WHERE Fecha < vDate18;
DELETE ts
FROM Tickets_stack ts
JOIN Tickets t ON ts.Id_Ticket = t.Id_Ticket
WHERE t.Fecha < vDate;
DELETE tobs
FROM ticket_observation tobs
JOIN Tickets t ON tobs.Id_Ticket = t.Id_Ticket
@ -64,13 +56,6 @@ proc: BEGIN
JOIN travel t ON t.id = e.travel_id
WHERE t.landing <= vDate;
DELETE co
FROM Compres_ok co JOIN Compres c ON c.Id_Compra = co.Id_Compra
JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada
JOIN travel t ON t.id = e.travel_id
WHERE t.landing <= vDate;
DELETE FROM scan WHERE odbc_date < vDate6 AND id <> 1;
IF v_full THEN
CREATE OR REPLACE TEMPORARY TABLE tTicketDelete
SELECT DISTINCT tl.originFk ticketFk

View File

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

View File

@ -1,117 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`supplierStatement`(vSupplierFk INT, vCurrencyFk INT, vCompanyFk INT, vOrderBy VARCHAR(15), vOnlyConciliated BIT)
BEGIN
SET @saldo_eur:= 0;
SET @saldo_div:= 0;
select vOnlyConciliated;
DROP TEMPORARY TABLE IF EXISTS tmp.supplierStatement;
CREATE TEMPORARY TABLE tmp.supplierStatement ENGINE = MEMORY
SELECT
*,
@saldo_eur:= round(@saldo_eur + IFNULL(Pago_Euros, 0) - IFNULL(Fac_Euros, 0) ,2 ) AS saldo_eur,
@saldo_div:= round(@saldo_div + IFNULL(Pago_Divisas, 0) - IFNULL(Fac_Divisas, 0) ,2 ) AS saldo_div
FROM
(SELECT * FROM
(SELECT
NULL as banco_id,
r.empresa_id,
r.serie,
r.id,
CASE
WHEN vOrderBy = 'issued' THEN r.fecha
WHEN vOrderBy = 'bookEntried' THEN r.bookEntried
WHEN vOrderBy = 'booked' THEN r.dateBooking
WHEN vOrderBy = 'dueDate' THEN rv.fecha
END AS fecha,
CONCAT('S/Fra ', r.sref) sref,
if(r.moneda_id > 1,round(sum(divisa) / sum(cantidad),3),NULL) val_cambio,
CAST(sum(cantidad) as DECIMAL(10,2)) as Fac_Euros,
CAST(sum(divisa) as DECIMAL(10,2)) as Fac_Divisas,
NULL AS Pago_Euros,
NULL AS Pago_Divisas,
r.moneda_id,
r.contabilizada,
Moneda,
NULL as pago_sdc_id,
'invoiceIn' statementType
FROM
recibida r
JOIN recibida_vencimiento rv on rv.recibida_id = r.id
JOIN Monedas m on m.Id_Moneda = r.moneda_id
WHERE
r.fecha > '2014-12-31'
AND r.proveedor_id = vSupplierFk
AND vCurrencyFk IN (r.moneda_id, 0)
AND vCompanyFk IN (r.empresa_id,0)
AND (vOnlyConciliated = r.contabilizada OR NOT vOnlyConciliated)
GROUP BY rv.id
UNION ALL
SELECT
p.id_banco,
p.empresa_id,
NULL,
p.id,
CASE
WHEN vOrderBy = 'issued' THEN p.Fecha
WHEN vOrderBy = 'bookEntried' THEN p.Fecha
WHEN vOrderBy = 'booked' THEN p.Fecha
WHEN vOrderBy = 'dueDate' THEN p.dueDated
END AS fecha,
CONCAT(IFNULL(name, ''), IF(pre.concepto <> '', CONCAT(' : ', pre.concepto), '')),
if(p.id_moneda > 1, p.divisa / importe, NULL) tip_cambio,
NULL,
NULL,
p.importe,
p.divisa,
p.id_moneda,
p.conciliado,
Moneda,
NULL as pago_sdc_id,
'payment' statementType
FROM
pago p
LEFT JOIN Monedas ON Monedas.Id_Moneda = p.id_moneda
LEFT JOIN Bancos ON p.id_banco = Bancos.Id_banco
LEFT JOIN pay_met pm ON p.pay_met_id = pm.id
LEFT JOIN Pagares pre ON pre.pago_id = p.id
WHERE
Fecha > '2014-12-31'
AND p.Id_Proveedor = vSupplierFk
AND vCurrencyFk IN (p.id_moneda,0)
AND vCompanyFk IN (p.empresa_id,0)
AND (vOnlyConciliated = p.conciliado OR NOT vOnlyConciliated)
UNION ALL
SELECT
NULL,
companyFk,
NULL,
se.id,
CASE
WHEN vOrderBy = 'issued' THEN se.dated
WHEN vOrderBy = 'bookEntried' THEN se.dated
WHEN vOrderBy = 'booked' THEN se.dated
WHEN vOrderBy = 'dueDate' THEN se.dueDated
END AS fecha,
se.description,
1 tip_cambio,
amount,
NULL,
NULL,
NULL,
currencyFk,
isConciliated,
c.`code`,
NULL,
'expense' statementType
FROM vn.supplierExpense se
JOIN vn.currency c on c.id= se.currencyFk
WHERE se.supplierFk = vSupplierFk
AND vCurrencyFk IN (se.currencyFk,0)
AND vCompanyFk IN (se.companyFk,0)
AND (vOnlyConciliated = se.isConciliated OR NOT vOnlyConciliated)
) AS SUB
ORDER BY (fecha is null and NOT contabilizada),fecha, IF(vOrderBy = 'dueDate', id, NULL) LIMIT 10000000000000000000) t;
END$$
DELIMITER ;

View File

@ -1,182 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`traslado`(IN i_entrada INTEGER)
BEGIN
DECLARE dateShipment DATE;
DECLARE dateLanding DATE;
DECLARE warehouseShipment INTEGER;
DECLARE warehouseLanding INTEGER;
DECLARE v_calc_visible INTEGER;
DECLARE vInventoryDate DATE;
SET vInventoryDate := vn.getInventoryDate();
SELECT shipment, landing, warehouse_id_out, warehouse_id
INTO dateShipment, dateLanding, warehouseShipment, warehouseLanding
FROM travel t JOIN Entradas e ON t.id = e.travel_id
WHERE Id_Entrada = i_entrada;
CALL vn.rate_getPrices(dateShipment, warehouseLanding);
-- Traslado en almacen origen
DROP TEMPORARY TABLE IF EXISTS buy_edi_temp;
CREATE TEMPORARY TABLE buy_edi_temp
(KEY (Id_Article), INDEX(Id_Compra)) ENGINE = MEMORY
SELECT *
FROM (SELECT c.Id_Article, c.Id_Compra
FROM Compres c INNER JOIN Entradas e USING(Id_Entrada)
INNER JOIN travel t ON t.id = e.travel_id
WHERE t.landing BETWEEN vInventoryDate AND dateShipment
AND c.Novincular = FALSE
AND c.Tarifa2 >= 0
ORDER BY (warehouseShipment = t.warehouse_id) DESC, t.landing DESC
LIMIT 10000000000000000000) t
GROUP BY Id_Article;
IF dateShipment >= util.VN_CURDATE() THEN
CALL `cache`.visible_refresh(v_calc_visible, TRUE, warehouseShipment);
DROP TEMPORARY TABLE IF EXISTS tmp.item;
CREATE TEMPORARY TABLE tmp.item (
`itemFk` int(10) unsigned NOT NULL,
`visible` int(11) NOT NULL DEFAULT 0,
`available` int(11) NOT NULL DEFAULT 0,
`visibleLanding` int(11) NOT NULL DEFAULT 0,
`availableLanding` int(11) NOT NULL DEFAULT 0,
UNIQUE INDEX i USING HASH (itemFk)
) ENGINE = MEMORY;
INSERT INTO tmp.item(itemFk, visible)
SELECT item_id itemFk, visible
FROM `cache`.visible
WHERE calc_id = v_calc_visible
AND visible;
CALL `cache`.visible_refresh(v_calc_visible, TRUE, warehouseLanding);
INSERT INTO tmp.item(itemFk, visibleLanding)
SELECT item_id, `visible`
FROM `cache`.`visible` v
WHERE v.calc_id = v_calc_visible
AND v.`visible`
ON DUPLICATE KEY UPDATE visibleLanding = v.`visible`;
CALL availableTraslate(warehouseShipment, dateShipment, NULL);
INSERT INTO tmp.item(itemFk, available)
SELECT a.item_id, a.available
FROM availableTraslate a
WHERE a.available
ON DUPLICATE KEY UPDATE available = a.available;
CALL availableTraslate(warehouseLanding, dateLanding, warehouseShipment);
INSERT INTO tmp.item(itemFk, availableLanding)
SELECT a.item_id, a.available
FROM availableTraslate a
WHERE a.available
ON DUPLICATE KEY UPDATE availableLanding = a.available;
ELSE
CALL vn.item_getStock(warehouseShipment, dateShipment, NULL);
DROP TEMPORARY TABLE IF EXISTS tmp.item;
CREATE TEMPORARY TABLE tmp.item (UNIQUE INDEX i USING HASH (itemFk)) ENGINE = MEMORY
SELECT itemFk, `visible`, available , 0 visibleLanding, 0 availableLanding
FROM tmp.itemList;
DROP TEMPORARY TABLE tmp.itemList;
END IF;
CALL vn.buyUltimateFromInterval(warehouseLanding,vInventoryDate, dateLanding);
DROP TEMPORARY TABLE IF EXISTS Traslados;
CREATE TEMPORARY TABLE Traslados ENGINE = MEMORY
SELECT tp.Id_Tipo AS Tipo,
tp.reino_id,
ar.tipo_id,
ar.Id_Article AS article_id,
ar.Article,
ar.Medida,
ar.Categoria,
ar.Color,
Origen.abreviatura as Origen,
CE.Cantidad,
ar.Tallos,
CAST(AIM.visible AS DECIMAL(10,0)) as vis1,
CAST(AIM.available AS DECIMAL(10,0)) as dis1,
CAST(AIM.visibleLanding AS DECIMAL(10,0)) as vis2,
CAST(AIM.availableLanding AS DECIMAL(10,0)) as dis2,
COALESCE(CE.`grouping`, C.`grouping`) as `grouping`,
COALESCE(CE.Packing, C.Packing) as Packing,
COALESCE(cl.caja, CE.caja, C.caja) as caja,
IFNULL(p.name, P2.Alias) AS Productor,
C.Id_Cubo,
1 Tinta,
CE.Id_Compra,
CE.Etiquetas,
C.buy_edi_id,
tp.Id_Trabajador,
CB.Volumen,
IFNULL(CB.x,0) x,
IFNULL(CB.y,0) y,
IFNULL(CB.z,0) z,
IFNULL(C.Costefijo,0) Costefijo,
IFNULL(C.Comisionfija,0) Comisionfija,
IFNULL(C.Portefijo,0) Portefijo,
A.m3,
E.comision,
CB.Retornable,
IFNULL(CEB.Valor,CB.Valor) Valor,
r.rate3 t3, r.rate2 t2, tp.promo,
C.`grouping` groupingOrigin,
C.Packing PackingOrigin,
C.Id_Compra CompraOrigin,
CB.costeRetorno,
C.weight
FROM Articles ar
JOIN tmp.item AIM ON AIM.itemFk = ar.Id_Article
LEFT JOIN producer p ON p.producer_id = ar.producer_id
LEFT JOIN Tipos tp ON tp.tipo_id = ar.tipo_id
JOIN vn.itemCategory ic ON ic.id = tp.reino_id
LEFT JOIN Origen ON Origen.id = ar.id_origen
LEFT JOIN buy_edi_temp lb ON lb.Id_Article = ar.Id_Article
LEFT JOIN Compres C ON C.Id_Compra = lb.Id_Compra
LEFT JOIN Cubos CB ON CB.Id_Cubo = C.Id_Cubo
LEFT JOIN Entradas E2 ON E2.Id_Entrada = C.Id_Entrada
LEFT JOIN Proveedores P2 ON P2.Id_Proveedor = E2.Id_Proveedor
LEFT JOIN Entradas E ON E.Id_Entrada = i_entrada
LEFT JOIN travel TR ON TR.id = E.travel_id
LEFT JOIN Agencias A ON A.Id_Agencia = TR.agency_id
LEFT JOIN Compres CE ON CE.Id_Article = ar.Id_Article AND CE.Id_Entrada = i_entrada
LEFT JOIN Cubos CEB ON CEB.Id_Cubo = CE.Id_Cubo
LEFT JOIN tmp.rate r ON TRUE
LEFT JOIN tmp.buyUltimateFromInterval bufi ON bufi.itemFk = ar.Id_Article
LEFT JOIN Compres cl ON cl.Id_Compra = bufi.buyFk
WHERE ic.display
AND E.Redada = FALSE
AND (AIM.visible != 0 OR AIM.available != 0)
ORDER BY tipo_id, Article, article_id, Medida, Categoria, Origen;
CREATE INDEX tindex USING HASH ON Traslados (article_id);
SELECT t.*,
Cantidad - MOD(Cantidad , `grouping`) as Subcantidad,
MOD(Cantidad , `grouping`) as Soll,
ROUND((IF(Volumen > 0,Volumen,x * y * IF(z = 0, Medida + 10, z))) / Packing,0) as cm3,
Costefijo + Comisionfija + Portefijo AS Cost,
@porte := ROUND((IF(Volumen > 0,Volumen,x * y * IF(z = 0, Medida + 10, z))) * m3 / 1000000 / Packing ,3) AS Porte,
@comision := ROUND((Costefijo + Comisionfija + Portefijo) * comision / 100 ,3) AS Comision,
ROUND(@embalaje := (costeRetorno + IF(Retornable != 0, 0, Valor)) / packing ,3) AS Embalaje,
@coste := IFNULL((Costefijo + Comisionfija + Portefijo),0) + IFNULL(@embalaje,0) + IFNULL(@porte,0) + IFNULL(@comision,0) AS Coste,
@t3 := ROUND(@coste / ( (100 - t3 - t.promo)/100),2) AS Tarifa3,
ROUND(@t3 * (1 + ((t2 - t3)/100)),2) AS Tarifa2,
0 selected
FROM Traslados t;
DROP TEMPORARY TABLE Traslados;
DROP TEMPORARY TABLE tmp.item;
DROP TEMPORARY TABLE buy_edi_temp;
DROP TEMPORARY TABLE tmp.buyUltimateFromInterval;
DROP TEMPORARY TABLE tmp.rate;
END$$
DELIMITER ;

View File

@ -1,119 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`travelDetail`()
BEGIN
/**
* Returns the details of the travels that have a departure warehouse in Ecuador or Colombia.
*/
DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK;
SELECT IFNULL(CONCAT(" ",Entrada),travel) travelAndEntry,
travel,
Entrada,
IsTravel,
Agencia,
ref,
shipment,
OrigenCajas,
landing,
Destino,
Etiquetas,
Notas_Eva,
kg,
loadedKg,
volumeKg,
loadPriority,
invoiceAmount,
Carguera,
reference
FROM
(SELECT TRUE IsTravel,
tr.id travel,
NULL Entrada,
ag.Agencia,
tr.ref,
tr.shipment,
wo.name OrigenCajas,
tr.landing,
w.name Destino,
SUM(c.Etiquetas) Etiquetas,
NULL Notas_Eva,
tr.kg,
CAST(SUM(c.weight * c.Etiquetas) AS INT) loadedkg,
CAST(
SUM(vc.aerealVolumetricDensity *
c.Etiquetas *
IF(cb.Volumen,
cb.Volumen,
cb.X * cb.Y * cb.Z
) / 1000000
) AS INT
) volumeKg,
NULL loadPriority,
NULL invoiceAmount,
pc.Alias Carguera,
NULL reference
FROM travel tr
LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk
LEFT JOIN Entradas e ON e.travel_id = tr.id
LEFT JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
LEFT JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo
LEFT JOIN Articles a ON a.Id_Article = c.Id_Article
LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id
JOIN warehouse w ON w.id = tr.warehouse_id
JOIN warehouse wo ON wo.id = tr.warehouse_id_out
JOIN Agencias ag ON ag.Id_Agencia = tr.agency_id
JOIN vn.volumeConfig vc
WHERE tr.landing >= vDateFrom
AND (wo.name="Colombia" OR wo.name="Ecuador")
GROUP BY tr.id
UNION ALL
SELECT 0 IsTravel,
e.travel_id travel,
e.Id_Entrada,
p.Proveedor,
e.Referencia,
tr.shipment,
wo.name OrigenCajas,
tr.landing,
w.name Destino,
SUM(Etiquetas) Etiquetas,
e.Notas_Eva,
NULL kg,
CAST(SUM(c.weight * c.Etiquetas) AS INT) loadedkg,
CAST(
SUM(vc.aerealVolumetricDensity *
c.Etiquetas *
IF(cb.Volumen,
cb.Volumen,
cb.X * cb.Y * cb.Z
) / 1000000
) AS INT
) volumeKg,
loadPriority,
e.invoiceAmount,
pc.Alias carguera,
e.reference
FROM Entradas e
JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo
JOIN Articles a ON a.Id_Article = c.Id_Article
JOIN Tipos tp ON tp.tipo_id = a.tipo_id
JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor
JOIN travel tr ON tr.id = e.travel_id
LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk
JOIN warehouse w ON w.id = tr.warehouse_id
JOIN warehouse wo ON wo.id = tr.warehouse_id_out
JOIN vn.volumeConfig vc
WHERE tr.landing >= vDateFrom
AND (wo.name="Colombia" OR wo.name="Ecuador")
GROUP BY e.Id_Entrada
) sub
ORDER BY landing ASC,
shipment ASC,
travel,
IsTravel DESC,
(loadPriority > 0) DESC,
loadPriority,
Agencia,
Notas_Eva;
END$$
DELIMITER ;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,17 @@
-- Para la tabla Monitoring
ALTER TABLE IF EXISTS vn2008.Monitoring RENAME vn2008.Monitoring__;
ALTER TABLE IF EXISTS vn2008.Monitoring__ COMMENT='refs #6371 deprecated 2024-01-11';
-- Para la tabla Movimientos_avisar
ALTER TABLE IF EXISTS vn2008.Movimientos_avisar RENAME vn2008.Movimientos_avisar__;
ALTER TABLE IF EXISTS vn2008.Movimientos_avisar__ COMMENT='refs #6371 deprecated 2024-01-11';
-- Para la tabla Movimientos_revisar
ALTER TABLE IF EXISTS vn2008.Movimientos_revisar RENAME vn2008.Movimientos_revisar__;
ALTER TABLE IF EXISTS vn2008.Movimientos_revisar__ COMMENT='refs #6371 deprecated 2024-01-11';
-- Para la tabla Proveedores_escritos
ALTER TABLE IF EXISTS vn2008.Proveedores_escritos RENAME vn2008.Proveedores_escritos__;
ALTER TABLE IF EXISTS vn2008.Proveedores_escritos__ COMMENT='refs #6371 deprecated 2024-01-11';

View File

@ -0,0 +1,35 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplier_statement`()
BEGIN
SELECT 1;
END$$
DELIMITER ;
GRANT EXECUTE ON PROCEDURE vn.supplier_statement TO administrative, buyer, hrBoss;
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_check`()
BEGIN
SELECT 1;
END$$
DELIMITER ;
GRANT EXECUTE ON PROCEDURE vn.XDiario_check TO adminBoss;
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_getDetailFromContinent`()
BEGIN
SELECT 1;
END$$
DELIMITER ;
GRANT EXECUTE ON PROCEDURE vn.travel_getDetailFromContinent TO buyer;
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_getTransfer`()
BEGIN
SELECT 1;
END$$
DELIMITER ;
GRANT EXECUTE ON PROCEDURE vn.entry_getTransfer TO claimManager, buyer;

View File

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

View File

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