2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`inbound_requestQuantity`(
|
|
|
|
vSelf INT,
|
2024-04-08 07:11:40 +00:00
|
|
|
vRequested INT,
|
|
|
|
vDated DATETIME,
|
|
|
|
OUT vSupplied INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Disassociates inbound picks after the given date until the
|
|
|
|
* demanded quantity is satisfied.
|
|
|
|
*
|
|
|
|
* @param vSelf The inbound reference
|
|
|
|
* @param vRequested The requested quantity
|
|
|
|
* @param vDate The starting date for the associated outbounds
|
|
|
|
* @param vSupplied The supplied quantity
|
|
|
|
*/
|
|
|
|
DECLARE vOutboundFk INT;
|
|
|
|
DECLARE vPickQuantity INT;
|
|
|
|
DECLARE vPickGranted INT;
|
|
|
|
DECLARE vDone BOOL;
|
|
|
|
|
|
|
|
DECLARE vPicks CURSOR FOR
|
|
|
|
SELECT p.outboundFk, p.quantity
|
|
|
|
FROM inboundPick p
|
|
|
|
JOIN outbound o ON o.id = p.outboundFk
|
|
|
|
WHERE p.inboundFk = vSelf
|
|
|
|
AND o.dated > vDated
|
|
|
|
ORDER BY o.dated DESC, o.created DESC;
|
|
|
|
|
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
|
|
|
SET vDone = TRUE;
|
2024-04-08 07:11:40 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SET vSupplied = 0;
|
|
|
|
|
|
|
|
OPEN vPicks;
|
|
|
|
|
|
|
|
myLoop: LOOP
|
|
|
|
SET vDone = FALSE;
|
|
|
|
FETCH vPicks INTO vOutboundFk, vPickQuantity;
|
|
|
|
|
|
|
|
IF vDone THEN
|
|
|
|
LEAVE myLoop;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
SET vPickGranted = LEAST(vRequested - vSupplied, vPickQuantity);
|
|
|
|
SET vSupplied = vSupplied + vPickGranted;
|
|
|
|
CALL inbound_removePick(vSelf, vOutboundFk, vPickGranted, vPickQuantity);
|
2024-04-08 07:11:40 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
UPDATE outbound
|
|
|
|
SET isSync = FALSE,
|
|
|
|
lack = lack + vPickGranted
|
|
|
|
WHERE id = vOutboundFk;
|
|
|
|
|
|
|
|
IF vSupplied >= vRequested THEN
|
|
|
|
LEAVE myLoop;
|
|
|
|
END IF;
|
|
|
|
END LOOP;
|
|
|
|
|
|
|
|
CLOSE vPicks;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|