feat(TPV): refs #7999 new frmLongTermStorage #2998
|
@ -1,79 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemFuentesBalance`(vDaysInFuture INT)
|
||||
BEGIN
|
||||
|
||||
/* Se utiliza para calcular la necesidad de mover mercancia entre el almacén de fuentes y el nuestro
|
||||
*
|
||||
* @param vDaysInFuture Rango de dias para calcular entradas y salidas
|
||||
*
|
||||
*/
|
||||
|
||||
DECLARE vWarehouseFk INT;
|
||||
|
||||
SELECT s.warehouseFk INTO vWarehouseFk
|
||||
FROM vn.sector s
|
||||
WHERE s.code = 'FUENTES_PICASSE';
|
||||
|
||||
CALL cache.stock_refresh(FALSE);
|
||||
|
||||
SELECT i.id itemFk,
|
||||
i.longName,
|
||||
i.size,
|
||||
i.subName,
|
||||
v.amount - IFNULL(fue.Fuentes,0) - IFNULL(alb.albenfruit,0) as visible,
|
||||
fue.Fuentes,
|
||||
alb.Albenfruit,
|
||||
sale.venta,
|
||||
IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra,
|
||||
IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0)
|
||||
- IFNULL(fue.Fuentes,0) - IFNULL(alb.albenfruit,0) as saldo
|
||||
FROM vn.item i
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
JOIN vn.itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN (
|
||||
SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS Fuentes
|
||||
FROM vn.itemShelving ish
|
||||
JOIN vn.shelving sh ON sh.code = ish.shelvingFk
|
||||
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||
JOIN vn.sector s ON s.id = p.sectorFk
|
||||
WHERE s.code = 'FUENTES_PICASSE'
|
||||
GROUP BY ish.itemFk
|
||||
) fue ON fue.itemFk = i.id
|
||||
LEFT JOIN (
|
||||
SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS Albenfruit
|
||||
FROM vn.itemShelving ish
|
||||
JOIN vn.shelving sh ON sh.code = ish.shelvingFk
|
||||
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||
JOIN vn.sector s ON s.id = p.sectorFk
|
||||
WHERE s.code = 'ALBENFRUIT'
|
||||
GROUP BY ish.itemFk
|
||||
) 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 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 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 itemFk
|
||||
) buy ON buy.item_id = i.id
|
||||
LEFT JOIN (
|
||||
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;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,3 @@
|
|||
-- Place your SQL code here
|
||||
ALTER TABLE vn.parking DROP FOREIGN KEY IF EXISTS parking_fk1;
|
||||
ALTER TABLE vn.parking ADD CONSTRAINT parking_fk1 FOREIGN KEY (sectorFk) REFERENCES vn.sector(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
Loading…
Reference in New Issue