dbtest workerTimeControCheck
This commit is contained in:
parent
9d513878a1
commit
5e86f67b37
|
@ -0,0 +1,182 @@
|
|||
|
||||
DROP procedure IF EXISTS `vn`.`workerTimeControl_check`;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`workerTimeControl_check`(vUserFk INT, vTabletFk VARCHAR(100), vTimed DATETIME)
|
||||
BEGIN
|
||||
|
||||
/**
|
||||
* Verifica si el empleado puede fichar en el momento actual, si puede fichar llama a vn.workerTimeControlAdd
|
||||
* @param vUserFk Identificador del trabajador
|
||||
* @return Retorna si encuentra un problema 'odd','maxTimeWork','breakDay','breakWeek' ;
|
||||
* En caso de tener algun problema retorna el primero que encuentra
|
||||
*/
|
||||
DECLARE vLastIn DATETIME ;
|
||||
DECLARE vLastOut DATETIME ;
|
||||
DECLARE vDayWorkMax INT;
|
||||
DECLARE vDayBreak INT;
|
||||
DECLARE vWeekBreak INT ;
|
||||
DECLARE vWeekMaxBreak INT;
|
||||
DECLARE vWeekScope INT;
|
||||
DECLARE vWeekMaxScope INT;
|
||||
DECLARE vDayStayMax INT;
|
||||
DECLARE vAskInOut INT;
|
||||
DECLARE vTimedWorked INT;
|
||||
DECLARE vCalendarStateType VARCHAR(20) DEFAULT NULL;
|
||||
DECLARE vDepartmentFk INT;
|
||||
DECLARE vTo VARCHAR(50) DEFAULT NULL;
|
||||
DECLARE vUserName VARCHAR(50) DEFAULT NULL;
|
||||
DECLARE vBody VARCHAR(255) DEFAULT NULL;
|
||||
|
||||
IF (vTimed IS NULL) THEN
|
||||
SET vTimed = NOW();
|
||||
END IF;
|
||||
|
||||
SELECT dayBreak, weekBreak, weekScope, dayWorkMax, dayStayMax, weekMaxBreak, weekMaxScope, askInOut
|
||||
INTO vDayBreak, vWeekBreak, vWeekScope, vDayWorkMax, vDayStayMax, vWeekMaxBreak, vWeekMaxScope, vAskInOut
|
||||
FROM vn.workerTimeControlParams;
|
||||
|
||||
SELECT MAX(timed) INTO vLastIn
|
||||
FROM vn.workerTimeControl
|
||||
WHERE userFk = vUserFk AND
|
||||
direction = 'in';
|
||||
|
||||
SELECT MAX(timed) INTO vLastOut
|
||||
FROM vn.workerTimeControl
|
||||
WHERE userFk = vUserFk AND
|
||||
direction = 'out';
|
||||
|
||||
SELECT email INTO vTo
|
||||
FROM vn.worker w
|
||||
WHERE w.id = (SELECT bossFk FROM vn.worker WHERE id = vUserFk);
|
||||
|
||||
SELECT CONCAT(firstName,' ',lastName) INTO vUserName
|
||||
FROM vn.worker w
|
||||
WHERE w.id = vUserFk;
|
||||
|
||||
-- VERIFICAR CONTRATO EN VIGOR
|
||||
IF (SELECT COUNT(*)
|
||||
FROM postgresql.business b
|
||||
JOIN postgresql.profile pr ON pr.profile_id = b.client_id
|
||||
JOIN postgresql.person p ON p.person_id = pr.person_id
|
||||
JOIN vn.worker w ON w.id = p.id_trabajador
|
||||
WHERE w.userFk = vUserFk AND
|
||||
b.date_start <= CURDATE() AND
|
||||
IFNULL(b.date_end,CURDATE()) >= CURDATE()
|
||||
) = 0 THEN
|
||||
-- ENVIAMOS CORREO AL BOSSFK
|
||||
SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"No hay un contrato en vigor") INTO vBody;
|
||||
CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody);
|
||||
CALL util.throw("No hay un contrato en vigor");
|
||||
END IF;
|
||||
|
||||
-- VERIFICAR DEPARTAMENTO
|
||||
IF vTabletFk IS NOT NULL THEN
|
||||
IF ( SELECT COUNT(*)
|
||||
FROM vn.tabletDepartment td
|
||||
JOIN vn.workerTimeControlUserInfo wtcu ON wtcu.departmentFk = td.departmentFk
|
||||
WHERE td.tabletFk = vTabletFk AND wtcu.userFk = vUserFk
|
||||
) = 0 THEN
|
||||
-- ENVIAMOS CORREO AL BOSSFK
|
||||
SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"No perteneces a este departamento.") INTO vBody;
|
||||
CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody);
|
||||
CALL util.throw("No perteneces a este departamento.");
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
SELECT IFNULL(dayBreak, vDayBreak) INTO vDayBreak
|
||||
FROM postgresql.business b
|
||||
JOIN postgresql.profile pr ON pr.profile_id = b.client_id
|
||||
JOIN postgresql.person p ON p.person_id = pr.person_id
|
||||
JOIN postgresql. business_labour bl ON b.business_id = bl.business_id
|
||||
JOIN postgresql.professional_category pc ON bl.professional_category_id = pc.professional_category_id
|
||||
WHERE p.id_trabajador = vUserFk AND
|
||||
b.date_start <= DATE(vTimed) AND
|
||||
IFNULL(b.date_end, DATE(vTimed)) >= DATE(vTimed);
|
||||
-- VERIFICAR DESCANSO DIARIO
|
||||
-- 12 / 9 horas dependiendo del valor de vDayBreak
|
||||
IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN
|
||||
-- ENVIAMOS CORREO AL BOSSFK
|
||||
SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos ", FORMAT(vDayBreak/3600,0) ," h") INTO vBody;
|
||||
CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody);
|
||||
CALL util.throw(CONCAT("Descansos ", FORMAT(vDayBreak/3600,0) ," h"));
|
||||
END IF;
|
||||
|
||||
-- VERIFICAR FICHADAS IMPARES DEL ÚLTIMO DÃÂÂA QUE SE FICHÓ
|
||||
IF (SELECT MOD(COUNT(*),2) -- <>0
|
||||
FROM vn.workerTimeControl
|
||||
WHERE userFk = vUserFk AND
|
||||
timed >= vLastIn
|
||||
) THEN
|
||||
-- ENVIAMOS CORREO AL BOSSFK
|
||||
SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Dias con fichadas impares") INTO vBody;
|
||||
CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody);
|
||||
CALL util.throw("Dias con fichadas impares");
|
||||
END IF;
|
||||
-- VERIFICAR VACACIONES
|
||||
SELECT cs.type INTO vCalendarStateType
|
||||
FROM postgresql.calendar_employee ce
|
||||
JOIN postgresql.business b USING(business_id)
|
||||
JOIN postgresql.profile pr ON pr.profile_id = b.client_id
|
||||
JOIN postgresql.person p ON p.person_id = pr.person_id
|
||||
JOIN postgresql.calendar_state cs USING(calendar_state_id)
|
||||
JOIN vn.worker w ON w.id = p.id_trabajador
|
||||
WHERE ce.date = CURDATE() AND
|
||||
cs.isAllowedToWork = FALSE AND
|
||||
w.userFk = vUserFk
|
||||
LIMIT 1;
|
||||
|
||||
IF(LENGTH(vCalendarStateType)) THEN
|
||||
-- ENVIAMOS CORREO AL BOSSFK
|
||||
SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Vacaciones") INTO vBody;
|
||||
CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody);
|
||||
CALL util.throw(vCalendarStateType);
|
||||
END IF;
|
||||
|
||||
-- VERIFICAR DESCANSO SEMANAL
|
||||
SET @vHasBreakWeek:= FALSE;
|
||||
SET @vLastTimed:= UNIX_TIMESTAMP((vTimed - INTERVAL vWeekScope SECOND));
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.trash;
|
||||
CREATE TEMPORARY TABLE tmp.trash
|
||||
SELECT IF(vWeekBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias,
|
||||
@vLastTimed:= UNIX_TIMESTAMP(timed)
|
||||
FROM workerTimeControl
|
||||
WHERE timed>= (vTimed - INTERVAL vWeekScope SECOND) AND
|
||||
userFk= vUserFk AND
|
||||
direction IN ('in','out')
|
||||
ORDER BY timed ASC;
|
||||
|
||||
IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA
|
||||
SET @vHasBreakWeek:= FALSE;
|
||||
SET @vLastTimed:= UNIX_TIMESTAMP((vTimed - INTERVAL vWeekMaxScope SECOND));
|
||||
DROP TEMPORARY TABLE tmp.trash;
|
||||
CREATE TEMPORARY TABLE tmp.trash
|
||||
SELECT IF(vWeekMaxBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias,
|
||||
@vLastTimed:= UNIX_TIMESTAMP(timed)
|
||||
FROM workerTimeControl
|
||||
WHERE timed>= (vTimed - INTERVAL vWeekMaxScope SECOND) AND
|
||||
userFk= vUserFk AND
|
||||
direction IN ('in','out')
|
||||
ORDER BY timed ASC;
|
||||
IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) < vWeekMaxBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA
|
||||
-- ENVIAMOS CORREO AL BOSSFK
|
||||
SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos ", FORMAT(vWeekMaxBreak/3600,0) ," h") INTO vBody;
|
||||
CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody);
|
||||
CALL util.throw(CONCAT( "Descansos ", FORMAT(vWeekMaxBreak/3600,0) ," h"));
|
||||
END IF;
|
||||
-- ENVIAMOS CORREO AL BOSSFK
|
||||
SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos ", FORMAT(vWeekBreak/3600,0) ," h") INTO vBody;
|
||||
CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody);
|
||||
CALL util.warn(CONCAT( "Descansos ", FORMAT(vWeekBreak/3600,0) ," h"));
|
||||
END IF;
|
||||
DROP TEMPORARY TABLE tmp.trash;
|
||||
|
||||
-- Preguntar dirección de la fichada
|
||||
IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastIn) >= vAskInOut AND (SELECT MOD(COUNT(*),2)
|
||||
FROM vn.workerTimeControl WHERE userFk = vUserFk AND timed >= vLastIn) THEN
|
||||
CALL util.warn("AskInOut");
|
||||
END IF ;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,2 +0,0 @@
|
|||
ALTER TABLE `vn`.`zoneEvent`
|
||||
ADD COLUMN m3Max DECIMAL(10,2) UNSIGNED NULL DEFAULT NULL AFTER bonus;
|
File diff suppressed because one or more lines are too long
|
@ -39,8 +39,8 @@ INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `password`,`role`,`active`
|
|||
FROM `account`.`role` WHERE id <> 20
|
||||
ORDER BY id;
|
||||
|
||||
INSERT INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `userFk`, `bossFk`)
|
||||
SELECT id,UPPER(LPAD(role, 3, '0')), name, name, id, 9
|
||||
INSERT INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `userFk`, `bossFk`, `email`)
|
||||
SELECT id,UPPER(LPAD(role, 3, '0')), name, name, id, 9, 'test@nightmare.es'
|
||||
FROM `vn`.`user`;
|
||||
|
||||
UPDATE `vn`.`worker` SET bossFk = NULL WHERE id = 20;
|
||||
|
@ -68,13 +68,13 @@ INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `password`,`role`,`active`,
|
|||
(111, 'Missing', 'Missing', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'en'),
|
||||
(112, 'Trash', 'Trash', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'en');
|
||||
|
||||
INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`, `userFk`,`bossFk`, `phone`)
|
||||
INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`, `userFk`,`bossFk`, `phone`, `email`)
|
||||
VALUES
|
||||
(106, 'LGN', 'David Charles', 'Haller', 106, 19, 432978106),
|
||||
(107, 'ANT', 'Hank' , 'Pym' , 107, 19, 432978107),
|
||||
(108, 'DCX', 'Charles' , 'Xavier', 108, 19, 432978108),
|
||||
(109, 'HLK', 'Bruce' , 'Banner', 109, 19, 432978109),
|
||||
(110, 'JJJ', 'Jessica' , 'Jones' , 110, 19, 432978110);
|
||||
(106, 'LGN', 'David Charles', 'Haller', 106, 19, 432978106, 'test@nightmare.es'),
|
||||
(107, 'ANT', 'Hank' , 'Pym' , 107, 19, 432978107, 'test@nightmare.es'),
|
||||
(108, 'DCX', 'Charles' , 'Xavier', 108, 19, 432978108, 'test@nightmare.es'),
|
||||
(109, 'HLK', 'Bruce' , 'Banner', 109, 19, 432978109, 'test@nightmare.es'),
|
||||
(110, 'JJJ', 'Jessica' , 'Jones' , 110, 19, 432978110, 'test@nightmare.es');
|
||||
|
||||
INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`, `ibanLength`)
|
||||
VALUES
|
||||
|
@ -1580,6 +1580,13 @@ INSERT INTO `postgresql`.`business_labour`(`business_id`, `notes`, `department_i
|
|||
SELECT b.business_id, NULL, 23, 1, 0, 1, 1, 1, 1
|
||||
FROM `postgresql`.`business` `b`;
|
||||
|
||||
UPDATE `postgresql`.`business_labour` bl
|
||||
JOIN `postgresql`.`business` b ON b.business_id = bl.business_id
|
||||
JOIN `postgresql`.`profile` pr ON pr.profile_id = b.client_id
|
||||
JOIN `postgresql`.`person` p ON p.person_id = pr.person_id
|
||||
SET bl.`professional_category_id` = 31
|
||||
WHERE p.`Id_trabajador` = 110;
|
||||
|
||||
INSERT INTO `postgresql`.`media`(`media_id`, `media_type_id`, `value`, `sort`)
|
||||
VALUES
|
||||
(1, 10, 600123321, 0),
|
||||
|
@ -1951,9 +1958,9 @@ INSERT INTO `vn`.`queuePriority`(`id`, `priority`)
|
|||
(2, 'Normal'),
|
||||
(3, 'Baja');
|
||||
|
||||
INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `weekScope`, `dayWorkMax`, `dayStayMax`)
|
||||
INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `weekScope`, `dayWorkMax`, `dayStayMax`, `weekMaxBreak`, `weekMaxScope`, `askInOut`)
|
||||
VALUES
|
||||
(1, 43200, 129600, 734400, 43200, 50400);
|
||||
(1, 43200, 129600, 734400, 43200, 50400, 259200, 1296000, 36000);
|
||||
|
||||
INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11');
|
||||
|
||||
|
@ -1981,3 +1988,13 @@ REPLACE INTO `vn`.`customsAgent` (`id`, `fiscalName`, `street`, `nif`, `phone`,
|
|||
VALUES
|
||||
(1, 'Agent one', '1007 Mountain Drive, Gotham', 'N1111111111', '111111111', 'agentone@gotham.com'),
|
||||
(2, 'Agent two', '1007 Mountain Drive, Gotham', 'N2222222222', '222222222', 'agenttwo@gotham.com');
|
||||
|
||||
INSERT INTO `vn`.`tabletDepartment`(`tabletFk`, `departmentFk`)
|
||||
VALUES
|
||||
(1, 23),
|
||||
(2, 1);
|
||||
|
||||
INSERT INTO `vn`.`tablet`(`uuid`, `name`, `place`, `macwifi`)
|
||||
VALUES
|
||||
('1', 'TEST', 'ON THE FIXTURES', '0'),
|
||||
('2', 'DEV', 'OTHER TABLET', '0');
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,398 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
fdescribe('worker workerTimeControl_check()', () => {
|
||||
it('should throw an error if the worker does not belong to this department', async() => {
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
const workerId = 110;
|
||||
const tabletId = 2;
|
||||
let err;
|
||||
stmts.push('START TRANSACTION');
|
||||
try {
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerId,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmts.push('ROLLBACK');
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err.sqlMessage).toEqual('No perteneces a este departamento.');
|
||||
});
|
||||
|
||||
it('should EL TRABAJDOR ESTA EN EL DEPARTAMENTO Y TABLET CORRECTO', async() => {
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
const workerId = 110;
|
||||
const tabletId = 1;
|
||||
let err;
|
||||
stmts.push('START TRANSACTION');
|
||||
try {
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerId,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmts.push('ROLLBACK');
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('should throw an error if the worker NO HA CUMPLIDO EL DESCANSO DE 9h', async() => {
|
||||
const workerIdBreak9Hours = 110;
|
||||
const tabletId = 1;
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
let sql;
|
||||
let error;
|
||||
|
||||
stmts.push('START TRANSACTION');
|
||||
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
||||
VALUES
|
||||
(?,TIMESTAMPADD(HOUR,-17,NOW()),0,"in"),
|
||||
(?,TIMESTAMPADD(SECOND,-32399,NOW()),0,"out")`, [
|
||||
workerIdBreak9Hours,
|
||||
workerIdBreak9Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerIdBreak9Hours,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmts.push('ROLLBACK');
|
||||
sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
||||
try {
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
await app.models.Worker.rawSql('ROLLBACK');
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.sqlMessage).toEqual('Descansos 9 h');
|
||||
});
|
||||
|
||||
it('should throw an error if the worker HA CUMPLIDO EL DESCANSO de 9h', async() => {
|
||||
const workerIdBreak9Hours = 110;
|
||||
const tabletId = 1;
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
let err;
|
||||
stmts.push('START TRANSACTION');
|
||||
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
||||
VALUES
|
||||
(?,TIMESTAMPADD(HOUR,-17,NOW()),0,"in"),
|
||||
(?,TIMESTAMPADD(SECOND,-32401,NOW()),0,"out")`, [
|
||||
workerIdBreak9Hours,
|
||||
workerIdBreak9Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerIdBreak9Hours,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmts.push('ROLLBACK');
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
||||
try {
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
await app.models.Worker.rawSql('ROLLBACK');
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('should throw an error if the worker NO HA CUMPLIDO EL DESCANSO DE 12h', async() => {
|
||||
const workerIdBreak12Hours = 109;
|
||||
const tabletId = 1;
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
let sql;
|
||||
let error;
|
||||
|
||||
stmts.push('START TRANSACTION');
|
||||
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
||||
VALUES
|
||||
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"in"),
|
||||
(?,TIMESTAMPADD(SECOND,-43199,NOW()),0,"out")`, [
|
||||
workerIdBreak12Hours,
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerIdBreak12Hours,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmts.push('ROLLBACK');
|
||||
sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
||||
try {
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
await app.models.Worker.rawSql('ROLLBACK');
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error.sqlMessage).toEqual('Descansos 12 h');
|
||||
});
|
||||
|
||||
it('should throw an error if the worker HA CUMPLIDO EL DESCANSO de 12h', async() => {
|
||||
const workerIdBreak12Hours = 109;
|
||||
const tabletId = 1;
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
let err;
|
||||
stmts.push('START TRANSACTION');
|
||||
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
||||
VALUES
|
||||
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"in"),
|
||||
(?,TIMESTAMPADD(SECOND,-43201,NOW()),0,"out")`, [
|
||||
workerIdBreak12Hours,
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerIdBreak12Hours,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmts.push('ROLLBACK');
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
||||
try {
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
await app.models.Worker.rawSql('ROLLBACK');
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('should throw an error if FICHADAS IMPARES', async() => {
|
||||
const workerIdBreak12Hours = 109;
|
||||
const tabletId = 1;
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
let err;
|
||||
stmts.push('START TRANSACTION');
|
||||
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
||||
VALUES
|
||||
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in")`, [
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerIdBreak12Hours,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmts.push('ROLLBACK');
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
||||
try {
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
await app.models.Worker.rawSql('ROLLBACK');
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err.sqlMessage).toEqual('Dias con fichadas impares');
|
||||
});
|
||||
|
||||
it('should throw an error if ESTA DE VACACIONES', async() => {
|
||||
const workerIdBreak12Hours = 109;
|
||||
const tabletId = 1;
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
let err;
|
||||
|
||||
stmts.push('START TRANSACTION');
|
||||
|
||||
stmt = new ParameterizedSQL(`INSERT INTO postgresql.calendar_employee(business_id,calendar_state_id,date)
|
||||
VALUES
|
||||
(?,1,CURDATE())`, [
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
||||
VALUES
|
||||
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in"),
|
||||
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"out")`, [
|
||||
workerIdBreak12Hours,
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerIdBreak12Hours,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmts.push('ROLLBACK');
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
||||
try {
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
await app.models.Worker.rawSql('ROLLBACK');
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err.sqlMessage).toEqual('Holidays');
|
||||
});
|
||||
|
||||
it('should throw an error if EL CONTRATO NO ESTA EN VIGOR', async() => {
|
||||
const workerIdBreak12Hours = 109;
|
||||
const tabletId = 1;
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
let err;
|
||||
|
||||
stmts.push('START TRANSACTION');
|
||||
|
||||
stmt = new ParameterizedSQL(`UPDATE postgresql.business SET date_end=DATE_ADD(CURDATE(), INTERVAL -1 DAY) WHERE business_id=?`, [
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
||||
VALUES
|
||||
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in"),
|
||||
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"out")`, [
|
||||
workerIdBreak12Hours,
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerIdBreak12Hours,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmts.push('ROLLBACK');
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
||||
try {
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
await app.models.Worker.rawSql('ROLLBACK');
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err.sqlMessage).toEqual('No hay un contrato en vigor');
|
||||
});
|
||||
|
||||
it('should throw an error if NO TIENE DESCANSO SEMANAL', async() => {
|
||||
const workerIdBreak12Hours = 109;
|
||||
const tabletId = 1;
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
let err;
|
||||
|
||||
stmts.push('START TRANSACTION');
|
||||
|
||||
stmt = new ParameterizedSQL(`UPDATE postgresql.business SET date_end=DATE_ADD(CURDATE(), INTERVAL -1 DAY) WHERE business_id=?`, [
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
||||
VALUES
|
||||
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in"),
|
||||
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"out")`, [
|
||||
workerIdBreak12Hours,
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerIdBreak12Hours,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmts.push('ROLLBACK');
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
||||
try {
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
await app.models.Worker.rawSql('ROLLBACK');
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err.sqlMessage).toEqual('No hay un contrato en vigor');
|
||||
});
|
||||
|
||||
it('should DESCANSO 32h', async() => {
|
||||
const workerIdBreak12Hours = 109;
|
||||
const tabletId = 1;
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
let err;
|
||||
|
||||
stmts.push('START TRANSACTION');
|
||||
|
||||
stmt = new ParameterizedSQL(`UPDATE postgresql.business SET date_end=DATE_ADD(CURDATE(), INTERVAL -1 DAY) WHERE business_id=?`, [
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
||||
VALUES
|
||||
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in"),
|
||||
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"out")`, [
|
||||
workerIdBreak12Hours,
|
||||
workerIdBreak12Hours
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||||
workerIdBreak12Hours,
|
||||
tabletId
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmts.push('ROLLBACK');
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
|
||||
try {
|
||||
await app.models.Worker.rawStmt(sql);
|
||||
} catch (e) {
|
||||
await app.models.Worker.rawSql('ROLLBACK');
|
||||
err = e;
|
||||
}
|
||||
|
||||
expect(err.sqlMessage).toEqual('No hay un contrato en vigor');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue