2024-09-05 12:45:17 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_updateItem`(
|
|
|
|
`vItem` INT,
|
|
|
|
`vWarehouse` INT,
|
|
|
|
`vDated` DATE,
|
|
|
|
`vQuantity` INT
|
|
|
|
)
|
|
|
|
BEGIN
|
2024-09-06 07:06:00 +00:00
|
|
|
/**
|
|
|
|
* Immediately deduct/add an amount from the available cache (if exists).
|
|
|
|
*
|
|
|
|
* @param vItem The item id
|
|
|
|
* @param vWarehouse The warehouse id
|
|
|
|
* @param vDated Available cache date
|
|
|
|
* @param vQuantity The amount to be deducted from the cache
|
|
|
|
*/
|
2024-09-05 12:45:17 +00:00
|
|
|
DECLARE vCalc INT;
|
|
|
|
|
2024-09-06 07:06:00 +00:00
|
|
|
SELECT id INTO vCalc
|
|
|
|
FROM cache_calc
|
2024-09-05 12:45:17 +00:00
|
|
|
WHERE cacheName = 'available'
|
2024-09-06 07:06:00 +00:00
|
|
|
AND params = CONCAT_WS('/', vWarehouse, vDated);
|
2024-09-05 12:45:17 +00:00
|
|
|
|
|
|
|
IF vCalc IS NOT NULL THEN
|
|
|
|
UPDATE available
|
|
|
|
SET available = available - vQuantity
|
|
|
|
WHERE calc_id = vCalc
|
|
|
|
AND item_id = vItem;
|
|
|
|
END IF;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|