salix/db/routines/vn/procedures/itemPlacementSupplyGetOrder...

44 lines
1.2 KiB
MySQL
Raw Normal View History

DELIMITER $$
2024-11-13 08:03:44 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyGetOrder`(
vSectorFk INT
)
BEGIN
DECLARE vId INT;
DECLARE vLastParkingFk INT;
DECLARE vNextParkingFk INT;
SELECT sh.parkingFk INTO vLastParkingFk
2024-11-13 08:03:44 +00:00
FROM itemShelvingPlacementSupply isps
JOIN itemShelving ish ON ish.id = isps.itemShelvingFk
JOIN shelving sh ON sh.id = ish.shelvingFk
WHERE isps.userFk = getUser()
ORDER BY isps.created DESC
LIMIT 1;
2024-11-13 08:03:44 +00:00
SET vNextParkingFk = itemShelvingPlacementSupply_ClosestGet(vLastParkingFk);
SELECT ipsl.id INTO vId
2024-11-13 08:03:44 +00:00
FROM itemPlacementSupplyList ipsl
JOIN itemShelvingPlacementSupplyStock ispss ON ispss.itemFk = ipsl.itemFk
WHERE ipsl.saldo > 0
AND (ipsl.repoUserFk is NULL OR ipsl.repoUserFk = getUser())
2024-11-13 08:03:44 +00:00
AND ipsl.sectorFk = vSectorFk
ORDER BY ipsl.repoUserFk DESC,
ipsl.priority DESC,
(ispss.parkingFk = vNextParkingFk) DESC,
ispss.parking DESC,
ipsl.created
LIMIT 1;
2024-11-13 08:03:44 +00:00
UPDATE itemPlacementSupply
SET repoUserFk = getUser()
WHERE id = vId;
2024-11-13 08:03:44 +00:00
SELECT * FROM itemPlacementSupplyList
WHERE id = vId
2024-11-13 08:03:44 +00:00
AND sectorFk = vSectorFk;
END$$
DELIMITER ;