feat: refs #8139 Added if is campaign #3206

Open
guillermo wants to merge 2 commits from 8139-clockInCampaign into dev
1 changed files with 26 additions and 27 deletions

View File

@ -7,7 +7,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`workerTimeControl_clo
) )
BEGIN BEGIN
/** /**
* Verifica si el empleado puede fichar * Verifica si el empleado puede fichar, en caso de que ficha.
* @param vWorkerFk Identificador del trabajador * @param vWorkerFk Identificador del trabajador
* @param vTimed Balor de la fichada, IF vTimed IS NULL vTimed = NOW * @param vTimed Balor de la fichada, IF vTimed IS NULL vTimed = NOW
* @param vDirection Solo se pueden pasa los valores del campo * @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á * Solo retorna el primer problema, en caso de no ocurrir ningún error se añadirá
* fichada a la tabla vn.workerTimeControl * fichada a la tabla vn.workerTimeControl
*/ */
DECLARE vLastIn DATETIME; DECLARE vLastIn DATETIME;
DECLARE vLastOut DATETIME; DECLARE vLastOut DATETIME;
DECLARE vNextIn DATETIME; DECLARE vNextIn DATETIME;
@ -40,6 +39,7 @@ BEGIN
DECLARE vIsManual BOOLEAN DEFAULT TRUE; DECLARE vIsManual BOOLEAN DEFAULT TRUE;
DECLARE vMaxWorkShortCycle INT; DECLARE vMaxWorkShortCycle INT;
DECLARE vMaxWorkLongCycle INT; DECLARE vMaxWorkLongCycle INT;
DECLARE vIsCampaing BOOL;
DECLARE EXIT HANDLER FOR SQLSTATE '45000' DECLARE EXIT HANDLER FOR SQLSTATE '45000'
BEGIN BEGIN
@ -121,7 +121,6 @@ BEGIN
CALL util.throw(vErrorCode); CALL util.throw(vErrorCode);
END IF; END IF;
-- DIRECCION CORRECTA -- DIRECCION CORRECTA
CALL workerTimeControl_direction(vWorkerFk, vTimed); CALL workerTimeControl_direction(vWorkerFk, vTimed);
IF (SELECT IF (SELECT
@ -139,7 +138,6 @@ BEGIN
SET vIsError = TRUE; SET vIsError = TRUE;
END IF; END IF;
IF vIsError THEN IF vIsError THEN
SET vErrorCode = 'WRONG_DIRECTION'; SET vErrorCode = 'WRONG_DIRECTION';
IF(SELECT option1 IS NULL AND option2 IS NULL IF(SELECT option1 IS NULL AND option2 IS NULL
@ -150,6 +148,7 @@ BEGIN
CALL util.throw(vErrorCode); CALL util.throw(vErrorCode);
END IF; END IF;
DROP TEMPORARY TABLE tmp.workerTimeControlDirection; DROP TEMPORARY TABLE tmp.workerTimeControlDirection;
-- FICHADAS IMPARES -- FICHADAS IMPARES
SELECT timed INTO vLastIn SELECT timed INTO vLastIn
FROM workerTimeControl FROM workerTimeControl
@ -204,11 +203,8 @@ BEGIN
CALL util.throw(vErrorCode); CALL util.throw(vErrorCode);
END IF; END IF;
IF (vDirection IN('in', 'out')) THEN IF (vDirection IN('in', 'out')) THEN
-- VERIFICA MAXIMO TIEMPO DESDE ENTRADA HASTA LA SALIDA -- VERIFICA MAXIMO TIEMPO DESDE ENTRADA HASTA LA SALIDA
SELECT timed INTO vNextOut SELECT timed INTO vNextOut
FROM workerTimeControl FROM workerTimeControl
WHERE userFk = vWorkerFk WHERE userFk = vWorkerFk
@ -243,8 +239,12 @@ BEGIN
CALL util.throw(vErrorCode); CALL util.throw(vErrorCode);
END IF; END IF;
-- VERIFICA DESCANSO SEMANAL SELECT EXISTS (
SELECT id FROM campaign
WHERE vTimed BETWEEN dated - INTERVAL scopeDays DAY AND dated
) INTO vIsCampaing;
-- VERIFICA DESCANSO SEMANAL
WITH wtc AS( WITH wtc AS(
(SELECT timed (SELECT timed
FROM vn.workerTimeControl FROM vn.workerTimeControl
@ -262,7 +262,7 @@ BEGIN
), wtcBreak AS( ), wtcBreak AS(
SELECT timed, SELECT timed,
IF(IFNULL(gap, 0) > vShortWeekBreak, TRUE, FALSE) hasShortBreak, 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 FROM wtcGap
ORDER BY timed ORDER BY timed
), wtcBreakCounter AS( ), wtcBreakCounter AS(
@ -290,6 +290,5 @@ BEGIN
VALUES(vWorkerFk, vTimed, vDirection, vDevice, vIsManual); VALUES(vWorkerFk, vTimed, vDirection, vDevice, vIsManual);
SELECT LAST_INSERT_ID() id; SELECT LAST_INSERT_ID() id;
END$$ END$$
DELIMITER ; DELIMITER ;