feat: refs #8139 Added if is campaign #3206
|
@ -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
|
||||
|
@ -97,19 +97,19 @@ BEGIN
|
|||
JOIN workerTimeControlConfig wc
|
||||
WHERE b.workerFk = vWorkerFk
|
||||
AND vDated BETWEEN b.started AND IFNULL(b.ended, vDated);
|
||||
|
||||
|
||||
-- CONTRATO EN VIGOR
|
||||
IF vDayBreak IS NULL THEN
|
||||
SET vErrorCode = 'INACTIVE_BUSINESS';
|
||||
CALL util.throw(vErrorCode);
|
||||
END IF;
|
||||
|
||||
|
||||
-- FICHADAS A FUTURO
|
||||
IF vTimed > util.VN_NOW() + INTERVAL 1 MINUTE THEN
|
||||
SET vErrorCode = 'IS_NOT_ALLOWED_FUTURE';
|
||||
CALL util.throw(vErrorCode);
|
||||
END IF;
|
||||
|
||||
|
||||
-- VERIFICAR SI ESTÁ PERMITIDO TRABAJAR
|
||||
CALL timeBusiness_calculateByWorker(vWorkerFk, vDated, vDated);
|
||||
SELECT isAllowedToWork INTO vIsAllowedToWork
|
||||
|
@ -121,7 +121,6 @@ BEGIN
|
|||
CALL util.throw(vErrorCode);
|
||||
END IF;
|
||||
|
||||
|
||||
-- DIRECCION CORRECTA
|
||||
CALL workerTimeControl_direction(vWorkerFk, vTimed);
|
||||
IF (SELECT
|
||||
|
@ -138,8 +137,7 @@ BEGIN
|
|||
) THEN
|
||||
SET vIsError = TRUE;
|
||||
END IF;
|
||||
|
||||
|
||||
|
||||
IF vIsError THEN
|
||||
SET vErrorCode = 'WRONG_DIRECTION';
|
||||
IF(SELECT option1 IS NULL AND option2 IS NULL
|
||||
|
@ -150,6 +148,7 @@ BEGIN
|
|||
CALL util.throw(vErrorCode);
|
||||
END IF;
|
||||
DROP TEMPORARY TABLE tmp.workerTimeControlDirection;
|
||||
|
||||
-- FICHADAS IMPARES
|
||||
SELECT timed INTO vLastIn
|
||||
FROM workerTimeControl
|
||||
|
@ -158,7 +157,7 @@ BEGIN
|
|||
AND timed < vTimed
|
||||
ORDER BY timed DESC
|
||||
LIMIT 1;
|
||||
|
||||
|
||||
IF (SELECT IF(vDirection = 'in',
|
||||
MOD(COUNT(*), 2) ,
|
||||
IF (vDirection = 'out', NOT MOD(COUNT(*), 2), FALSE))
|
||||
|
@ -169,7 +168,7 @@ BEGIN
|
|||
SET vErrorCode = 'ODD_WORKERTIMECONTROL';
|
||||
CALL util.throw(vErrorCode);
|
||||
END IF;
|
||||
|
||||
|
||||
-- DESCANSO DIARIO
|
||||
SELECT timed INTO vLastOut
|
||||
FROM workerTimeControl
|
||||
|
@ -178,7 +177,7 @@ BEGIN
|
|||
AND timed < vTimed
|
||||
ORDER BY timed DESC
|
||||
LIMIT 1;
|
||||
|
||||
|
||||
SELECT timed INTO vNextIn
|
||||
FROM workerTimeControl
|
||||
WHERE userFk = vWorkerFk
|
||||
|
@ -186,7 +185,7 @@ BEGIN
|
|||
AND timed > vTimed
|
||||
ORDER BY timed ASC
|
||||
LIMIT 1;
|
||||
|
||||
|
||||
CASE vDirection
|
||||
WHEN 'in' THEN
|
||||
IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) <= vDayBreak THEN
|
||||
|
@ -204,11 +203,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
|
||||
|
@ -216,7 +212,7 @@ BEGIN
|
|||
AND timed > vTimed
|
||||
ORDER BY timed ASC
|
||||
LIMIT 1;
|
||||
|
||||
|
||||
SELECT direction INTO vNextDirection
|
||||
FROM workerTimeControl
|
||||
WHERE userFk = vWorkerFk
|
||||
|
@ -224,7 +220,7 @@ BEGIN
|
|||
AND timed > vTimed
|
||||
ORDER BY timed ASC
|
||||
LIMIT 1;
|
||||
|
||||
|
||||
SELECT direction INTO vLastDirection
|
||||
FROM workerTimeControl
|
||||
WHERE userFk = vWorkerFk
|
||||
|
@ -232,7 +228,7 @@ BEGIN
|
|||
AND timed < vTimed
|
||||
ORDER BY timed ASC
|
||||
LIMIT 1;
|
||||
|
||||
|
||||
IF (vDirection ='in'
|
||||
AND vNextDirection = 'out'
|
||||
AND UNIX_TIMESTAMP(vNextOut) - UNIX_TIMESTAMP(vTimed) > vDayMaxTime) OR
|
||||
|
@ -242,9 +238,13 @@ BEGIN
|
|||
SET vErrorCode = 'DAY_MAX_TIME';
|
||||
CALL util.throw(vErrorCode);
|
||||
END IF;
|
||||
|
||||
|
||||
SELECT EXISTS (
|
||||
SELECT id FROM campaign
|
||||
WHERE vTimed BETWEEN dated - INTERVAL scopeDays DAY AND dated
|
||||
) INTO vIsCampaing;
|
||||
|
||||
-- VERIFICA DESCANSO SEMANAL
|
||||
|
||||
WITH wtc AS(
|
||||
(SELECT timed
|
||||
FROM vn.workerTimeControl
|
||||
|
@ -262,7 +262,7 @@ BEGIN
|
|||
), wtcBreak AS(
|
||||
SELECT timed,
|
||||
IF(IFNULL(gap, 0) > vShortWeekBreak, TRUE, FALSE) hasShortBreak,
|
||||
IF(IFNULL(gap, 0) > vLongWeekBreak, TRUE, FALSE) hasLongBreak
|
||||
IF(IFNULL(gap, 0) > vLongWeekBreak AND NOT vIsCampaing, TRUE, FALSE) hasLongBreak
|
||||
FROM wtcGap
|
||||
ORDER BY timed
|
||||
), wtcBreakCounter AS(
|
||||
|
@ -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