This commit is contained in:
parent
872fbea808
commit
e2c742c893
|
@ -0,0 +1,2 @@
|
||||||
|
UPDATE `salix`.`ACL` SET `model` = 'Calendar' WHERE (`id` = '155');
|
||||||
|
UPDATE `salix`.`ACL` SET `model` = 'Calendar' WHERE (`id` = '157');
|
|
@ -1,12 +0,0 @@
|
||||||
USE `vn`;
|
|
||||||
CREATE
|
|
||||||
OR REPLACE ALGORITHM = UNDEFINED
|
|
||||||
DEFINER = `root`@`%`
|
|
||||||
SQL SECURITY DEFINER
|
|
||||||
VIEW `workerCalendar2` AS
|
|
||||||
SELECT
|
|
||||||
`ce`.`id` AS `id`,
|
|
||||||
`ce`.`business_id` AS `businessFk`,
|
|
||||||
`ce`.`calendar_state_id` AS `absenceTypeFk`,
|
|
||||||
`ce`.`date` AS `dated`
|
|
||||||
FROM `postgresql`.`calendar_employee` `ce`;
|
|
|
@ -135,7 +135,10 @@ export default class Calendar extends FormInput {
|
||||||
$days: [day],
|
$days: [day],
|
||||||
$type: 'day'
|
$type: 'day'
|
||||||
});
|
});
|
||||||
// this.repaint();
|
|
||||||
|
// Repaint only if 'selection' event is not listening
|
||||||
|
if (!this.$events || this.$events && !this.$events['selection'])
|
||||||
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -45,34 +45,6 @@ module.exports = Self => {
|
||||||
const calendar = {totalHolidays: 0, holidaysEnjoyed: 0};
|
const calendar = {totalHolidays: 0, holidaysEnjoyed: 0};
|
||||||
const holidays = [];
|
const holidays = [];
|
||||||
|
|
||||||
// Get absences of year
|
|
||||||
let absences = await Self.find({
|
|
||||||
include: {
|
|
||||||
relation: 'absenceType'
|
|
||||||
},
|
|
||||||
where: {
|
|
||||||
workerFk: workerFk,
|
|
||||||
dated: {between: [yearStarted, yearEnded]}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let entitlementRate = 0;
|
|
||||||
absences.forEach(absence => {
|
|
||||||
const absenceType = absence.absenceType();
|
|
||||||
const isHoliday = absenceType.code === 'holiday';
|
|
||||||
const isHalfHoliday = absenceType.code === 'halfHoliday';
|
|
||||||
|
|
||||||
if (isHoliday)
|
|
||||||
calendar.holidaysEnjoyed += 1;
|
|
||||||
if (isHalfHoliday)
|
|
||||||
calendar.holidaysEnjoyed += 0.5;
|
|
||||||
|
|
||||||
entitlementRate += absenceType.holidayEntitlementRate;
|
|
||||||
|
|
||||||
absence.dated = new Date(absence.dated);
|
|
||||||
absence.dated.setHours(0, 0, 0, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get active contracts on current year
|
// Get active contracts on current year
|
||||||
const year = yearStarted.getFullYear();
|
const year = yearStarted.getFullYear();
|
||||||
const contracts = await models.WorkerLabour.find({
|
const contracts = await models.WorkerLabour.find({
|
||||||
|
@ -112,6 +84,39 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Contracts ids
|
||||||
|
const contractsId = contracts.map(contract => {
|
||||||
|
return contract.businessFk;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get absences of year
|
||||||
|
let absences = await Self.find({
|
||||||
|
include: {
|
||||||
|
relation: 'absenceType'
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
businessFk: {inq: contractsId},
|
||||||
|
dated: {between: [yearStarted, yearEnded]}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let entitlementRate = 0;
|
||||||
|
absences.forEach(absence => {
|
||||||
|
const absenceType = absence.absenceType();
|
||||||
|
const isHoliday = absenceType.code === 'holiday';
|
||||||
|
const isHalfHoliday = absenceType.code === 'halfHoliday';
|
||||||
|
|
||||||
|
if (isHoliday)
|
||||||
|
calendar.holidaysEnjoyed += 1;
|
||||||
|
if (isHalfHoliday)
|
||||||
|
calendar.holidaysEnjoyed += 0.5;
|
||||||
|
|
||||||
|
entitlementRate += absenceType.holidayEntitlementRate;
|
||||||
|
|
||||||
|
absence.dated = new Date(absence.dated);
|
||||||
|
absence.dated.setHours(0, 0, 0, 0);
|
||||||
|
});
|
||||||
|
|
||||||
// Get number of worked days
|
// Get number of worked days
|
||||||
let workedDays = 0;
|
let workedDays = 0;
|
||||||
contracts.forEach(contract => {
|
contracts.forEach(contract => {
|
|
@ -17,7 +17,7 @@ xdescribe('Worker absences()', () => {
|
||||||
ended.setMonth(monthIndex + 1);
|
ended.setMonth(monthIndex + 1);
|
||||||
ended.setDate(0);
|
ended.setDate(0);
|
||||||
|
|
||||||
let result = await app.models.WorkerCalendar.absences(ctx, workerFk, started, ended);
|
let result = await app.models.Calendar.absences(ctx, workerFk, started, ended);
|
||||||
let calendar = result[0];
|
let calendar = result[0];
|
||||||
let absences = result[1];
|
let absences = result[1];
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ xdescribe('Worker absences()', () => {
|
||||||
ended.setMonth(monthIndex + 1);
|
ended.setMonth(monthIndex + 1);
|
||||||
ended.setDate(0);
|
ended.setDate(0);
|
||||||
|
|
||||||
let result = await app.models.WorkerCalendar.absences(ctx, workerFk, started, ended);
|
let result = await app.models.Calendar.absences(ctx, workerFk, started, ended);
|
||||||
let calendar = result[0];
|
let calendar = result[0];
|
||||||
let absences = result[1];
|
let absences = result[1];
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ xdescribe('Worker absences()', () => {
|
||||||
let ctx = {req: {accessToken: {userId: 106}}};
|
let ctx = {req: {accessToken: {userId: 106}}};
|
||||||
let workerFk = 106;
|
let workerFk = 106;
|
||||||
|
|
||||||
let result = await app.models.WorkerCalendar.absences(ctx, workerFk, yearStart, yearEnd);
|
let result = await app.models.Calendar.absences(ctx, workerFk, yearStart, yearEnd);
|
||||||
let calendar = result[0];
|
let calendar = result[0];
|
||||||
let absences = result[1];
|
let absences = result[1];
|
||||||
|
|
|
@ -49,9 +49,9 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return models.WorkerCalendar.create({
|
return models.Calendar.create({
|
||||||
businessFk: labour.businessFk,
|
businessFk: labour.businessFk,
|
||||||
absenceTypeFk: absenceTypeId,
|
dayOffTypeFk: absenceTypeId,
|
||||||
dated: dated
|
dated: dated
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@ module.exports = Self => {
|
||||||
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
|
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
const absence = await models.WorkerCalendar.findById(absenceId);
|
const absence = await models.Calendar.findById(absenceId);
|
||||||
|
|
||||||
return absence.destroy();
|
return absence.destroy();
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@ describe('Worker createAbsence()', () => {
|
||||||
let createdAbsence;
|
let createdAbsence;
|
||||||
|
|
||||||
afterAll(async() => {
|
afterAll(async() => {
|
||||||
const absence = await app.models.WorkerCalendar.findById(createdAbsence.id);
|
const absence = await app.models.Calendar.findById(createdAbsence.id);
|
||||||
await absence.destroy();
|
await absence.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -34,6 +34,6 @@ describe('Worker createAbsence()', () => {
|
||||||
const expectedAbsenceTypeId = 1;
|
const expectedAbsenceTypeId = 1;
|
||||||
|
|
||||||
expect(createdAbsence.businessFk).toEqual(expectedBusinessId);
|
expect(createdAbsence.businessFk).toEqual(expectedBusinessId);
|
||||||
expect(createdAbsence.absenceTypeFk).toEqual(expectedAbsenceTypeId);
|
expect(createdAbsence.dayOffTypeFk).toEqual(expectedAbsenceTypeId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,9 +7,9 @@ describe('Worker deleteAbsence()', () => {
|
||||||
it('should return an error for a user without enough privileges', async() => {
|
it('should return an error for a user without enough privileges', async() => {
|
||||||
const ctx = {req: {accessToken: {userId: 106}}};
|
const ctx = {req: {accessToken: {userId: 106}}};
|
||||||
const businessId = 106;
|
const businessId = 106;
|
||||||
createdAbsence = await app.models.WorkerCalendar.create({
|
createdAbsence = await app.models.Calendar.create({
|
||||||
businessFk: businessId,
|
businessFk: businessId,
|
||||||
absenceTypeFk: 1,
|
dayOffTypeFk: 1,
|
||||||
dated: new Date()
|
dated: new Date()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ describe('Worker deleteAbsence()', () => {
|
||||||
|
|
||||||
await app.models.Worker.deleteAbsence(ctx, workerId, createdAbsence.id);
|
await app.models.Worker.deleteAbsence(ctx, workerId, createdAbsence.id);
|
||||||
|
|
||||||
const deletedAbsence = await app.models.WorkerCalendar.findById(createdAbsence.id);
|
const deletedAbsence = await app.models.Calendar.findById(createdAbsence.id);
|
||||||
|
|
||||||
expect(deletedAbsence).toBeNull();
|
expect(deletedAbsence).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,16 +5,16 @@ describe('Worker updateAbsence()', () => {
|
||||||
let createdAbsence;
|
let createdAbsence;
|
||||||
|
|
||||||
afterAll(async() => {
|
afterAll(async() => {
|
||||||
const absence = await app.models.WorkerCalendar.findById(createdAbsence.id);
|
const absence = await app.models.Calendar.findById(createdAbsence.id);
|
||||||
await absence.destroy();
|
await absence.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return an error for a user without enough privileges', async() => {
|
it('should return an error for a user without enough privileges', async() => {
|
||||||
const ctx = {req: {accessToken: {userId: 106}}};
|
const ctx = {req: {accessToken: {userId: 106}}};
|
||||||
const expectedAbsenceTypeId = 2;
|
const expectedAbsenceTypeId = 2;
|
||||||
createdAbsence = await app.models.WorkerCalendar.create({
|
createdAbsence = await app.models.Calendar.create({
|
||||||
businessFk: 106,
|
businessFk: 106,
|
||||||
absenceTypeFk: 1,
|
dayOffTypeFk: 1,
|
||||||
dated: new Date()
|
dated: new Date()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -33,6 +33,6 @@ describe('Worker updateAbsence()', () => {
|
||||||
const expectedAbsenceTypeId = 2;
|
const expectedAbsenceTypeId = 2;
|
||||||
const updatedAbsence = await app.models.Worker.updateAbsence(ctx, workerId, createdAbsence.id, expectedAbsenceTypeId);
|
const updatedAbsence = await app.models.Worker.updateAbsence(ctx, workerId, createdAbsence.id, expectedAbsenceTypeId);
|
||||||
|
|
||||||
expect(updatedAbsence.absenceTypeFk).toEqual(expectedAbsenceTypeId);
|
expect(updatedAbsence.dayOffTypeFk).toEqual(expectedAbsenceTypeId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -35,8 +35,8 @@ module.exports = Self => {
|
||||||
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
|
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
const absence = await models.WorkerCalendar.findById(absenceId);
|
const absence = await models.Calendar.findById(absenceId);
|
||||||
|
|
||||||
return absence.updateAttribute('absenceTypeFk', absenceTypeId);
|
return absence.updateAttribute('dayOffTypeFk', absenceTypeId);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
"AbsenceType": {
|
"AbsenceType": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
"Department": {
|
"Calendar": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
"CalendarHoliday": {
|
"CalendarHoliday": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
@ -14,6 +14,9 @@
|
||||||
"CalendarHolidaysType": {
|
"CalendarHolidaysType": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"Department": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"WorkCenter": {
|
"WorkCenter": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
@ -44,9 +47,6 @@
|
||||||
"WorkerDepartment": {
|
"WorkerDepartment": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
"WorkerCalendar": {
|
|
||||||
"dataSource": "vn"
|
|
||||||
},
|
|
||||||
"WorkerTimeControl": {
|
"WorkerTimeControl": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/calendar/absences')(Self);
|
||||||
|
};
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"name": "WorkerCalendar",
|
"name": "Calendar",
|
||||||
"base": "VnModel",
|
"base": "VnModel",
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "workerCalendar2"
|
"table": "calendar"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
"absenceType": {
|
"absenceType": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "AbsenceType",
|
"model": "AbsenceType",
|
||||||
"foreignKey": "absenceTypeFk"
|
"foreignKey": "dayOffTypeFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
module.exports = Self => {
|
|
||||||
require('../methods/worker-calendar/absences')(Self);
|
|
||||||
};
|
|
|
@ -200,7 +200,7 @@ class Controller extends Section {
|
||||||
started: this.started,
|
started: this.started,
|
||||||
ended: this.ended
|
ended: this.ended
|
||||||
};
|
};
|
||||||
return this.$http.get(`WorkerCalendars/absences`, {params})
|
return this.$http.get(`Calendars/absences`, {params})
|
||||||
.then(res => this.onData(res.data));
|
.then(res => this.onData(res.data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ describe('Worker', () => {
|
||||||
let yesterday = new Date(today.getTime());
|
let yesterday = new Date(today.getTime());
|
||||||
yesterday.setDate(yesterday.getDate() - 1);
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
|
|
||||||
$httpBackend.whenRoute('GET', 'WorkerCalendars/absences')
|
$httpBackend.whenRoute('GET', 'Calendars/absences')
|
||||||
.respond({
|
.respond({
|
||||||
holidays: [
|
holidays: [
|
||||||
{dated: today, detail: {description: 'New year'}},
|
{dated: today, detail: {description: 'New year'}},
|
||||||
|
@ -90,7 +90,7 @@ describe('Worker', () => {
|
||||||
|
|
||||||
let today = new Date();
|
let today = new Date();
|
||||||
|
|
||||||
$httpBackend.whenRoute('GET', 'WorkerCalendars/absences')
|
$httpBackend.whenRoute('GET', 'Calendars/absences')
|
||||||
.respond({
|
.respond({
|
||||||
absences: [
|
absences: [
|
||||||
{dated: today, absenceType: {name: 'Holiday', rgb: '#000'}}
|
{dated: today, absenceType: {name: 'Holiday', rgb: '#000'}}
|
||||||
|
@ -316,7 +316,7 @@ describe('Worker', () => {
|
||||||
const expecteResponse = [{id: 1}];
|
const expecteResponse = [{id: 1}];
|
||||||
const expectedParams = {workerFk: 106, started: started, ended: ended};
|
const expectedParams = {workerFk: 106, started: started, ended: ended};
|
||||||
const serializedParams = $httpParamSerializer(expectedParams);
|
const serializedParams = $httpParamSerializer(expectedParams);
|
||||||
$httpBackend.expect('GET', `WorkerCalendars/absences?${serializedParams}`).respond(200, expecteResponse);
|
$httpBackend.expect('GET', `Calendars/absences?${serializedParams}`).respond(200, expecteResponse);
|
||||||
controller.refresh();
|
controller.refresh();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ class Controller extends Section {
|
||||||
ended: this.ended
|
ended: this.ended
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.$http.get(`WorkerCalendars/absences`, {params})
|
return this.$http.get(`Calendars/absences`, {params})
|
||||||
.then(res => this.onData(res.data));
|
.then(res => this.onData(res.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue