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`.`worker_isWorking`(vWorkerFk INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
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 ;
|