This commit is contained in:
parent
cd7ed6987a
commit
2d3ae5ce9e
|
@ -1,13 +1,13 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`workerTimeControl_clockIn`(
|
||||
vWorkerFk INT,
|
||||
vTimed DATETIME,
|
||||
vDirection VARCHAR(10),
|
||||
vDevice VARCHAR(255)
|
||||
vWorkerFk INT,
|
||||
vTimed DATETIME,
|
||||
vDirection VARCHAR(10),
|
||||
vDevice VARCHAR(255)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Verifica si el empleado puede fichar
|
||||
* Verifica si el empleado puede fichar, en caso de que sí ficha.
|
||||
* @param vWorkerFk Identificador del trabajador
|
||||
* @param vTimed Balor de la fichada, IF vTimed IS NULL vTimed = NOW
|
||||
* @param vDirection Solo se pueden pasa los valores del campo
|
||||
|
@ -18,7 +18,6 @@ BEGIN
|
|||
* Solo retorna el primer problema, en caso de no ocurrir ningún error se añadirá
|
||||
* fichada a la tabla vn.workerTimeControl
|
||||
*/
|
||||
|
||||
DECLARE vLastIn DATETIME;
|
||||
DECLARE vLastOut DATETIME;
|
||||
DECLARE vNextIn DATETIME;
|
||||
|
@ -40,6 +39,7 @@ BEGIN
|
|||
DECLARE vIsManual BOOLEAN DEFAULT TRUE;
|
||||
DECLARE vMaxWorkShortCycle INT;
|
||||
DECLARE vMaxWorkLongCycle INT;
|
||||
DECLARE vIsCampaing BOOL;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLSTATE '45000'
|
||||
BEGIN
|
||||
|
@ -75,11 +75,16 @@ BEGIN
|
|||
|
||||
SET vDated = DATE(vTimed);
|
||||
|
||||
SELECT EXISTS (
|
||||
SELECT TRUE FROM campaign
|
||||
WHERE vTimed BETWEEN dated - INTERVAL scopeDays DAY AND dated
|
||||
) INTO vIsCampaing;
|
||||
|
||||
SELECT IF(pc.code = 'driverCE',
|
||||
wc.dayBreakDriver,
|
||||
wc.dayBreak),
|
||||
wc.shortWeekBreak,
|
||||
wc.longWeekBreak,
|
||||
IF(vIsCampaing, NULL, wc.longWeekBreak),
|
||||
wc.weekScope,
|
||||
wc.dayMaxTime,
|
||||
wc.maxWorkShortCycle,
|
||||
|
@ -121,7 +126,6 @@ BEGIN
|
|||
CALL util.throw(vErrorCode);
|
||||
END IF;
|
||||
|
||||
|
||||
-- DIRECCION CORRECTA
|
||||
CALL workerTimeControl_direction(vWorkerFk, vTimed);
|
||||
IF (SELECT
|
||||
|
@ -139,7 +143,6 @@ BEGIN
|
|||
SET vIsError = TRUE;
|
||||
END IF;
|
||||
|
||||
|
||||
IF vIsError THEN
|
||||
SET vErrorCode = 'WRONG_DIRECTION';
|
||||
IF(SELECT option1 IS NULL AND option2 IS NULL
|
||||
|
@ -150,6 +153,7 @@ BEGIN
|
|||
CALL util.throw(vErrorCode);
|
||||
END IF;
|
||||
DROP TEMPORARY TABLE tmp.workerTimeControlDirection;
|
||||
|
||||
-- FICHADAS IMPARES
|
||||
SELECT timed INTO vLastIn
|
||||
FROM workerTimeControl
|
||||
|
@ -204,11 +208,8 @@ BEGIN
|
|||
CALL util.throw(vErrorCode);
|
||||
END IF;
|
||||
|
||||
|
||||
|
||||
IF (vDirection IN('in', 'out')) THEN
|
||||
-- VERIFICA MAXIMO TIEMPO DESDE ENTRADA HASTA LA SALIDA
|
||||
|
||||
SELECT timed INTO vNextOut
|
||||
FROM workerTimeControl
|
||||
WHERE userFk = vWorkerFk
|
||||
|
@ -244,7 +245,6 @@ BEGIN
|
|||
END IF;
|
||||
|
||||
-- VERIFICA DESCANSO SEMANAL
|
||||
|
||||
WITH wtc AS(
|
||||
(SELECT timed
|
||||
FROM vn.workerTimeControl
|
||||
|
@ -271,7 +271,7 @@ BEGIN
|
|||
LEAD(hasLongBreak) OVER (ORDER BY timed) nextHasLongBreak
|
||||
FROM wtcBreak
|
||||
)SELECT TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed)) > vMaxWorkLongCycle OR
|
||||
(TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed))> vMaxWorkShortCycle
|
||||
(TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed)) > vMaxWorkShortCycle
|
||||
AND NOT SUM(IFNULL(nextHasLongBreak, 1)))
|
||||
hasError INTO vIsError
|
||||
FROM wtcBreakCounter
|
||||
|
@ -290,6 +290,5 @@ BEGIN
|
|||
VALUES(vWorkerFk, vTimed, vDirection, vDevice, vIsManual);
|
||||
|
||||
SELECT LAST_INSERT_ID() id;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
Loading…
Reference in New Issue