#1359 refactor absences
This commit is contained in:
parent
5501ff8f4f
commit
8d5cc93ddb
|
@ -1273,7 +1273,7 @@ INSERT INTO `postgresql`.`profile`(`profile_id`, `person_id`, `profile_type_id`)
|
||||||
FROM `postgresql`.`person` `p`;
|
FROM `postgresql`.`person` `p`;
|
||||||
|
|
||||||
INSERT INTO `postgresql`.`business`(`business_id`, `client_id`, `provider_id`, `date_start`, `date_end`, `workerBusiness`, `reasonEndFk`)
|
INSERT INTO `postgresql`.`business`(`business_id`, `client_id`, `provider_id`, `date_start`, `date_end`, `workerBusiness`, `reasonEndFk`)
|
||||||
SELECT p.profile_id, p.profile_id, 1000, DATE_ADD(CURDATE(), INTERVAL -15 DAY), DATE_ADD(CURDATE(), INTERVAL +6 MONTH), CONCAT('E-46-',RPAD(CONCAT(p.profile_id,9),8,p.profile_id)), NULL
|
SELECT p.profile_id, p.profile_id, 1000, CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR)), '-12-31'), CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL +1 YEAR)), '-01-01'), CONCAT('E-46-',RPAD(CONCAT(p.profile_id,9),8,p.profile_id)), NULL
|
||||||
FROM `postgresql`.`profile` `p`;
|
FROM `postgresql`.`profile` `p`;
|
||||||
|
|
||||||
INSERT INTO `postgresql`.`business_labour`(`business_id`, `notes`, `department_id`, `professional_category_id`, `incentivo`, `calendar_labour_type_id`, `porhoras`, `labour_agreement_id`, `workcenter_id`)
|
INSERT INTO `postgresql`.`business_labour`(`business_id`, `notes`, `department_id`, `professional_category_id`, `incentivo`, `calendar_labour_type_id`, `porhoras`, `labour_agreement_id`, `workcenter_id`)
|
||||||
|
|
|
@ -150,11 +150,11 @@ describe('Ticket descriptor path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Make invoice', () => {
|
describe('Make invoice', () => {
|
||||||
it('should login as Invoicing role then search for a ticket', async() => {
|
it('should login as adminBoss role then search for a ticket', async() => {
|
||||||
const invoiceableTicketId = 11;
|
const invoiceableTicketId = 11;
|
||||||
|
|
||||||
const url = await nightmare
|
const url = await nightmare
|
||||||
.loginAndModule('developer', 'ticket')
|
.loginAndModule('adminBoss', 'ticket')
|
||||||
.accessToSearchResult(invoiceableTicketId)
|
.accessToSearchResult(invoiceableTicketId)
|
||||||
.waitForURL('/summary')
|
.waitForURL('/summary')
|
||||||
.parsedUrl();
|
.parsedUrl();
|
||||||
|
|
|
@ -25,10 +25,12 @@ module.exports = Self => {
|
||||||
arg: 'calendar'
|
arg: 'calendar'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'absences'
|
arg: 'absences',
|
||||||
|
type: 'Number'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'holidays'
|
arg: 'holidays',
|
||||||
|
type: 'Number'
|
||||||
}],
|
}],
|
||||||
http: {
|
http: {
|
||||||
path: `/absences`,
|
path: `/absences`,
|
||||||
|
@ -147,8 +149,16 @@ module.exports = Self => {
|
||||||
const startedTime = started.getTime();
|
const startedTime = started.getTime();
|
||||||
const contractDays = Math.floor((endedTime - startedTime) / dayTimestamp);
|
const contractDays = Math.floor((endedTime - startedTime) / dayTimestamp);
|
||||||
|
|
||||||
if (contractDays < 365)
|
if (contractDays < 365) {
|
||||||
return Math.floor(contract.holidays().days * (contractDays + 1) / 365);
|
let holidays = contract.holidays().days * (contractDays + 1) / 365;
|
||||||
|
let integerPart = parseInt(holidays);
|
||||||
|
let decimalPart = holidays - integerPart;
|
||||||
|
let decimal = decimalPart >= 0.5 ? 0.5 : 0;
|
||||||
|
|
||||||
|
holidays = integerPart + decimal;
|
||||||
|
|
||||||
|
return holidays;
|
||||||
|
}
|
||||||
|
|
||||||
return contract.holidays().days;
|
return contract.holidays().days;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,19 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('Worker absences()', () => {
|
describe('Worker absences()', () => {
|
||||||
|
afterAll(async done => {
|
||||||
|
const hiredWorker = await app.models.WorkerLabour.findById(106);
|
||||||
|
|
||||||
|
const endedDate = new Date();
|
||||||
|
endedDate.setFullYear(endedDate.getFullYear() + 1);
|
||||||
|
endedDate.setHours(0, 0, 0, 0);
|
||||||
|
endedDate.setMonth(0);
|
||||||
|
endedDate.setDate(1);
|
||||||
|
|
||||||
|
await hiredWorker.updateAttributes({ended: endedDate});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
it('should get the absence calendar for the given dates then evaluate the type of absences', async() => {
|
it('should get the absence calendar for the given dates then evaluate the type of absences', async() => {
|
||||||
let ctx = {req: {accessToken: {userId: 106}}};
|
let ctx = {req: {accessToken: {userId: 106}}};
|
||||||
let workerFk = 106;
|
let workerFk = 106;
|
||||||
|
@ -20,7 +33,121 @@ describe('Worker absences()', () => {
|
||||||
let calendar = result[0];
|
let calendar = result[0];
|
||||||
let absences = result[1];
|
let absences = result[1];
|
||||||
|
|
||||||
expect(calendar.totalHolidays).toEqual(21);
|
expect(calendar.totalHolidays).toEqual(27.5);
|
||||||
|
expect(calendar.holidaysEnjoyed).toEqual(5);
|
||||||
|
|
||||||
|
let firstType = absences[0].absenceType().name;
|
||||||
|
let sixthType = absences[5].absenceType().name;
|
||||||
|
|
||||||
|
expect(firstType).toEqual('Leave of absence');
|
||||||
|
expect(sixthType).toEqual('Holidays');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should fire the worker 106 on July and see he/she has 13.75`, async() => {
|
||||||
|
const firedWorker = await app.models.WorkerLabour.findById(106);
|
||||||
|
|
||||||
|
const endedDate = new Date();
|
||||||
|
endedDate.setHours(0, 0, 0, 0);
|
||||||
|
endedDate.setMonth(5);
|
||||||
|
endedDate.setDate(31);
|
||||||
|
|
||||||
|
await firedWorker.updateAttributes({ended: endedDate});
|
||||||
|
|
||||||
|
let ctx = {req: {accessToken: {userId: 106}}};
|
||||||
|
let workerFk = 106;
|
||||||
|
|
||||||
|
const started = new Date();
|
||||||
|
started.setHours(0, 0, 0, 0);
|
||||||
|
started.setMonth(0);
|
||||||
|
started.setDate(1);
|
||||||
|
|
||||||
|
const monthIndex = 11;
|
||||||
|
const ended = new Date();
|
||||||
|
ended.setHours(0, 0, 0, 0);
|
||||||
|
ended.setMonth(monthIndex + 1);
|
||||||
|
ended.setDate(0);
|
||||||
|
|
||||||
|
let result = await app.models.WorkerCalendar.absences(ctx, workerFk, started, ended);
|
||||||
|
let calendar = result[0];
|
||||||
|
let absences = result[1];
|
||||||
|
|
||||||
|
expect(calendar.totalHolidays).toEqual(13.5);
|
||||||
|
expect(calendar.holidaysEnjoyed).toEqual(5);
|
||||||
|
|
||||||
|
let firstType = absences[0].absenceType().name;
|
||||||
|
let sixthType = absences[5].absenceType().name;
|
||||||
|
|
||||||
|
expect(firstType).toEqual('Leave of absence');
|
||||||
|
expect(sixthType).toEqual('Holidays');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should fire the worker 106 on March and see he/she has 6.5`, async() => {
|
||||||
|
const firedWorker = await app.models.WorkerLabour.findById(106);
|
||||||
|
|
||||||
|
const endedDate = new Date();
|
||||||
|
endedDate.setHours(0, 0, 0, 0);
|
||||||
|
endedDate.setMonth(2);
|
||||||
|
endedDate.setDate(31);
|
||||||
|
|
||||||
|
await firedWorker.updateAttributes({ended: endedDate});
|
||||||
|
|
||||||
|
let ctx = {req: {accessToken: {userId: 106}}};
|
||||||
|
let workerFk = 106;
|
||||||
|
|
||||||
|
const started = new Date();
|
||||||
|
started.setHours(0, 0, 0, 0);
|
||||||
|
started.setMonth(0);
|
||||||
|
started.setDate(1);
|
||||||
|
|
||||||
|
const monthIndex = 11;
|
||||||
|
const ended = new Date();
|
||||||
|
ended.setHours(0, 0, 0, 0);
|
||||||
|
ended.setMonth(monthIndex + 1);
|
||||||
|
ended.setDate(0);
|
||||||
|
|
||||||
|
let result = await app.models.WorkerCalendar.absences(ctx, workerFk, started, ended);
|
||||||
|
let calendar = result[0];
|
||||||
|
let absences = result[1];
|
||||||
|
|
||||||
|
expect(calendar.totalHolidays).toEqual(6.5);
|
||||||
|
expect(calendar.holidaysEnjoyed).toEqual(5);
|
||||||
|
|
||||||
|
let firstType = absences[0].absenceType().name;
|
||||||
|
let sixthType = absences[5].absenceType().name;
|
||||||
|
|
||||||
|
expect(firstType).toEqual('Leave of absence');
|
||||||
|
expect(sixthType).toEqual('Holidays');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should fire the worker 106 on january and see he/she has x`, async() => {
|
||||||
|
const firedWorker = await app.models.WorkerLabour.findById(106);
|
||||||
|
|
||||||
|
const endedDate = new Date();
|
||||||
|
endedDate.setHours(0, 0, 0, 0);
|
||||||
|
endedDate.setMonth(0);
|
||||||
|
endedDate.setDate(28);
|
||||||
|
|
||||||
|
await firedWorker.updateAttributes({ended: endedDate});
|
||||||
|
|
||||||
|
let ctx = {req: {accessToken: {userId: 106}}};
|
||||||
|
let workerFk = 106;
|
||||||
|
|
||||||
|
const started = new Date();
|
||||||
|
started.setHours(0, 0, 0, 0);
|
||||||
|
started.setMonth(0);
|
||||||
|
started.setDate(1);
|
||||||
|
|
||||||
|
const monthIndex = 11;
|
||||||
|
const ended = new Date();
|
||||||
|
ended.setHours(0, 0, 0, 0);
|
||||||
|
ended.setMonth(monthIndex + 1);
|
||||||
|
ended.setDate(0);
|
||||||
|
|
||||||
|
let result = await app.models.WorkerCalendar.absences(ctx, workerFk, started, ended);
|
||||||
|
let calendar = result[0];
|
||||||
|
let absences = result[1];
|
||||||
|
|
||||||
|
expect(calendar.totalHolidays).toEqual(2);
|
||||||
expect(calendar.holidaysEnjoyed).toEqual(5);
|
expect(calendar.holidaysEnjoyed).toEqual(5);
|
||||||
|
|
||||||
let firstType = absences[0].absenceType().name;
|
let firstType = absences[0].absenceType().name;
|
||||||
|
|
Loading…
Reference in New Issue