DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyAiming`(
    vShelvingCode VARCHAR(10),
    vQuantity INT,
    vItemFk INT
)
BEGIN

	SELECT 	ish.itemFk,
			ish.longName,
            ish.size,
            ish.subName,
			ish.itemShelvingFk,
            ish.shelving,
            ish.stock,
            LEAST(ish.stock,vQuantity) total,
            CONCAT(
					CAST(FLOOR(LEAST(ish.stock, vQuantity) / ish.packing) AS DECIMAL(10,0)),
                    ' x ',
                    ish.packing,
                    IF	(	
						LEAST(ish.stock, vQuantity) MOD ish.packing,
						CONCAT(' + ',CAST(LEAST(ish.stock, vQuantity) MOD ish.packing AS DECIMAL(10,0))),
                        ''
                        ),
                    ' = ',
                    LEAST(ish.stock, vQuantity)
				   ) proposal
		FROM itemShelvingPlacementSupplyStock ish
        WHERE ish.shelving = vShelvingCode COLLATE utf8_general_ci
			AND ish.itemFk = vItemFk;

END$$
DELIMITER ;
