salix/db/routines/vn/procedures/itemPlacementSupplyStockGet...

35 lines
1.1 KiB
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyStockGetTargetList`(vItemFk INT,vSectorFk INT)
BEGIN
/**
* Devuelve la lista de ubicaciones para itemFk en ese sector. Se utiliza en la preparación previa.
* Este proc se llama a continuacion de ticketToPrePrepare
*
* @param vItemFk Identificador de vn.item
* @param vSectorFk Identificador de vn.sector
*/
DECLARE vWarehouseAliasFk INT;
SELECT w.aliasFk INTO vWarehouseAliasFk
FROM vn.sector s
JOIN vn.warehouse w ON w.id = s.warehouseFk
WHERE s.id = vSectorFk;
SELECT ish.shelvingFk shelving,
p.code parking,
sum(ish.visible) as stockTotal,
ish.created,
p.pickingOrder
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 sc ON sc.id = p.sectorFk
JOIN vn.warehouse w ON w.id = sc.warehouseFk
WHERE w.aliasFk = vWarehouseAliasFk
AND ish.visible > 0
AND ish.itemFk = vItemFk
GROUP BY ish.id
ORDER BY (sc.id = vSectorFk) DESC, sh.priority DESC, ish.created, p.pickingOrder;
END$$
DELIMITER ;