2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`item_getVolume`(vSelf INT, vPackaging VARCHAR(10))
|
2024-01-15 11:31:03 +00:00
|
|
|
RETURNS int(11)
|
|
|
|
DETERMINISTIC
|
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Calculates the volume occupied by an item together
|
|
|
|
* with its packaging.
|
|
|
|
*
|
|
|
|
* @param vSelf The item id
|
|
|
|
* @param vPackaging The packaging id
|
|
|
|
* @return The volume in cubic centimeters
|
|
|
|
*/
|
|
|
|
DECLARE vVolume INT;
|
|
|
|
|
|
|
|
SELECT SUM(IF(p.volume > 0,
|
|
|
|
p.volume,
|
|
|
|
p.width * p.depth * IF(IFNULL(p.height,0), p.height, IFNULL(i.size,60) + 10)
|
|
|
|
)) INTO vVolume
|
|
|
|
FROM packaging p
|
|
|
|
JOIN item i ON i.id = vSelf
|
|
|
|
WHERE p.id = vPackaging;
|
|
|
|
|
|
|
|
RETURN vVolume;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|