salix/db/routines/srt/functions/buffer_isFull.sql

35 lines
713 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`buffer_isFull`(vBufferFk INT)
RETURNS tinyint(1)
NOT DETERMINISTIC
READS SQL DATA
BEGIN
/**
* Comprueba si un buffer está lleno
*
* @param vBufferFk Identificador de vn.buffer
*
*/
DECLARE vBufferStock INT;
DECLARE vIsFull BOOL;
SELECT COUNT(*) INTO vBufferStock
FROM srt.expedition e
LEFT JOIN srt.moving m ON m.expeditionFk = e.id
WHERE e.bufferFk = vBufferFk
AND ISNULL(m.id);
SELECT vBufferStock + COUNT(*) INTO vBufferStock
FROM srt.moving m
WHERE m.bufferToFk = vBufferFk;
SELECT (vBufferStock >= maxBoxesInBuffer) INTO vIsFull
FROM srt.config;
RETURN vIsFull;
END$$
DELIMITER ;