2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-11-13 08:03:44 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyGetOrder`(
|
|
|
|
vSectorFk INT
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
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
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE isps.userFk = getUser()
|
|
|
|
ORDER BY isps.created DESC
|
|
|
|
LIMIT 1;
|
|
|
|
|
2024-11-13 08:03:44 +00:00
|
|
|
SET vNextParkingFk = itemShelvingPlacementSupply_ClosestGet(vLastParkingFk);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
SELECT ipsl.id INTO vId
|
2024-11-13 08:03:44 +00:00
|
|
|
FROM itemPlacementSupplyList ipsl
|
|
|
|
JOIN itemShelvingPlacementSupplyStock ispss ON ispss.itemFk = ipsl.itemFk
|
2024-01-15 11:31:03 +00:00
|
|
|
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
|
2024-01-15 11:31:03 +00:00
|
|
|
LIMIT 1;
|
|
|
|
|
2024-11-13 08:03:44 +00:00
|
|
|
UPDATE itemPlacementSupply
|
2024-01-15 11:31:03 +00:00
|
|
|
SET repoUserFk = getUser()
|
|
|
|
WHERE id = vId;
|
|
|
|
|
2024-11-13 08:03:44 +00:00
|
|
|
SELECT * FROM itemPlacementSupplyList
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE id = vId
|
2024-11-13 08:03:44 +00:00
|
|
|
AND sectorFk = vSectorFk;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|