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

30 lines
847 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`buy_checkItem`()
BEGIN
/**
* Checks if the item has weightByPiece or size null on any buy.
*
* @param tmp.buysToCheck(id as INT).
*/
DECLARE vHasVolumetricAgency INT;
DECLARE vItemFk INT;
SELECT a.hasWeightVolumetric, i.id INTO vHasVolumetricAgency, vItemFk
FROM entry e
JOIN travel t ON t.id = e.travelFk
JOIN agencyMode a ON a.id = t.agencyModeFk
JOIN buy b ON b.entryFk = e.id
JOIN item i ON i.id = b.itemFk
JOIN tmp.buysToCheck bt ON bt.id = b.id
WHERE (i.weightByPiece IS NULL OR i.`size` IS NULL)
AND a.hasWeightVolumetric
LIMIT 1;
DROP TEMPORARY TABLE tmp.buysToCheck;
IF vHasVolumetricAgency THEN
CALL util.throw(CONCAT('Missing size/weight in buy line at agency, item: ', vItemFk));
END IF;
END$$
DELIMITER ;