salix/db/routines/vn/procedures/itemPlacementSupplyAiming.sql

31 lines
990 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyAiming`(vShelvingFk VARCHAR(10), quantity INT, vItemFk INT)
BEGIN
SELECT ish.itemFk,
ish.longName,
ish.size,
ish.subName,
ish.itemShelvingFk,
ish.shelving,
ish.stock,
LEAST(ish.stock,quantity) as total,
CONCAT(
CAST(FLOOR(LEAST(ish.stock,quantity) / ish.packing) AS DECIMAL(10,0)),
' x ',
ish.packing,
IF (
LEAST(ish.stock,quantity) MOD ish.packing,
CONCAT(' + ',CAST(LEAST(ish.stock,quantity) MOD ish.packing AS DECIMAL(10,0))),
''
),
' = ',
LEAST(ish.stock,quantity)
) as proposal
FROM vn.itemShelvingPlacementSupplyStock ish
WHERE ish.shelving = vShelvingFk COLLATE utf8_general_ci
AND ish.itemFk = vItemFk;
END$$
DELIMITER ;