2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`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 ;
|