29 lines
718 B
SQL
29 lines
718 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` FUNCTION `vn`.`worker_isWorking`(vWorkerFk INT)
|
|
RETURNS tinyint(1)
|
|
NOT DETERMINISTIC
|
|
READS SQL DATA
|
|
BEGIN
|
|
/**
|
|
* Comprueba si el trabajador está trabajando en el momento de la consulta
|
|
* @return Devuelve TRUE en caso de que este trabajando. Si se encuentra en un descanso devolverá FALSE
|
|
*/
|
|
DECLARE vLastIn DATETIME ;
|
|
|
|
SELECT MAX(timed) INTO vLastIn
|
|
FROM vn.workerTimeControl
|
|
WHERE userFk = vWorkerFk AND
|
|
direction = 'in';
|
|
|
|
IF (SELECT MOD(COUNT(*),2)
|
|
FROM vn.workerTimeControl
|
|
WHERE userFk = vWorkerFk AND
|
|
timed >= vLastIn
|
|
) THEN
|
|
RETURN TRUE;
|
|
ELSE
|
|
RETURN FALSE;
|
|
END IF;
|
|
END$$
|
|
DELIMITER ;
|