1361 - Añadir filtro por año #348

Merged
joan merged 16 commits from 1361-calendar_date_filter into dev 2020-08-18 12:18:41 +00:00
22 changed files with 73 additions and 75 deletions
Showing only changes of commit d17f289af9 - Show all commits

View File

@ -0,0 +1,2 @@
UPDATE `salix`.`ACL` SET `model` = 'Calendar' WHERE (`id` = '155');
UPDATE `salix`.`ACL` SET `model` = 'Calendar' WHERE (`id` = '157');

View File

@ -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`;

View File

@ -135,7 +135,10 @@ export default class Calendar extends FormInput {
$days: [day],
$type: 'day'
});
// this.repaint();
// Repaint only if 'selection' event is not listening
if (!this.$events || this.$events && !this.$events['selection'])
this.repaint();
}
/*

View File

@ -189,7 +189,7 @@ export default class Searchbar extends Component {
}
doSearch(filter, source) {
if (filter === this.filter) return;
if (filter === this.filter && source != 'state') return;
let promise = this.onSearch({$params: filter});
promise = promise || this.$q.resolve();
promise.then(data => this.onFilter(filter, source, data));

View File

@ -45,34 +45,6 @@ module.exports = Self => {
const calendar = {totalHolidays: 0, holidaysEnjoyed: 0};
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
const year = yearStarted.getFullYear();
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
let workedDays = 0;
contracts.forEach(contract => {

View File

@ -17,7 +17,7 @@ xdescribe('Worker absences()', () => {
ended.setMonth(monthIndex + 1);
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 absences = result[1];
@ -54,7 +54,7 @@ xdescribe('Worker absences()', () => {
ended.setMonth(monthIndex + 1);
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 absences = result[1];
@ -128,7 +128,7 @@ xdescribe('Worker absences()', () => {
let ctx = {req: {accessToken: {userId: 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 absences = result[1];

View File

@ -49,9 +49,9 @@ module.exports = Self => {
}
});
return models.WorkerCalendar.create({
return models.Calendar.create({
businessFk: labour.businessFk,
absenceTypeFk: absenceTypeId,
dayOffTypeFk: absenceTypeId,
dated: dated
});
};

View File

@ -30,7 +30,7 @@ module.exports = Self => {
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
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();
};

View File

@ -5,7 +5,7 @@ describe('Worker createAbsence()', () => {
let createdAbsence;
afterAll(async() => {
const absence = await app.models.WorkerCalendar.findById(createdAbsence.id);
const absence = await app.models.Calendar.findById(createdAbsence.id);
await absence.destroy();
});
@ -34,6 +34,6 @@ describe('Worker createAbsence()', () => {
const expectedAbsenceTypeId = 1;
expect(createdAbsence.businessFk).toEqual(expectedBusinessId);
expect(createdAbsence.absenceTypeFk).toEqual(expectedAbsenceTypeId);
expect(createdAbsence.dayOffTypeFk).toEqual(expectedAbsenceTypeId);
});
});

View File

@ -7,9 +7,9 @@ describe('Worker deleteAbsence()', () => {
it('should return an error for a user without enough privileges', async() => {
const ctx = {req: {accessToken: {userId: 106}}};
const businessId = 106;
createdAbsence = await app.models.WorkerCalendar.create({
createdAbsence = await app.models.Calendar.create({
businessFk: businessId,
absenceTypeFk: 1,
dayOffTypeFk: 1,
dated: new Date()
});
@ -31,7 +31,7 @@ describe('Worker deleteAbsence()', () => {
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();
});

View File

@ -5,16 +5,16 @@ describe('Worker updateAbsence()', () => {
let createdAbsence;
afterAll(async() => {
const absence = await app.models.WorkerCalendar.findById(createdAbsence.id);
const absence = await app.models.Calendar.findById(createdAbsence.id);
await absence.destroy();
});
it('should return an error for a user without enough privileges', async() => {
const ctx = {req: {accessToken: {userId: 106}}};
const expectedAbsenceTypeId = 2;
createdAbsence = await app.models.WorkerCalendar.create({
createdAbsence = await app.models.Calendar.create({
businessFk: 106,
absenceTypeFk: 1,
dayOffTypeFk: 1,
dated: new Date()
});
@ -33,6 +33,6 @@ describe('Worker updateAbsence()', () => {
const expectedAbsenceTypeId = 2;
const updatedAbsence = await app.models.Worker.updateAbsence(ctx, workerId, createdAbsence.id, expectedAbsenceTypeId);
expect(updatedAbsence.absenceTypeFk).toEqual(expectedAbsenceTypeId);
expect(updatedAbsence.dayOffTypeFk).toEqual(expectedAbsenceTypeId);
});
});

View File

@ -35,8 +35,8 @@ module.exports = Self => {
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
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);
};
};

View File

@ -2,9 +2,9 @@
"AbsenceType": {
"dataSource": "vn"
},
"Department": {
"Calendar": {
"dataSource": "vn"
},
},
"CalendarHoliday": {
"dataSource": "vn"
},
@ -14,6 +14,9 @@
"CalendarHolidaysType": {
"dataSource": "vn"
},
"Department": {
"dataSource": "vn"
},
"WorkCenter": {
"dataSource": "vn"
},
@ -44,9 +47,6 @@
"WorkerDepartment": {
"dataSource": "vn"
},
"WorkerCalendar": {
"dataSource": "vn"
},
"WorkerTimeControl": {
"dataSource": "vn"
},

View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/calendar/absences')(Self);
};

View File

@ -1,9 +1,9 @@
{
"name": "WorkerCalendar",
"name": "Calendar",
"base": "VnModel",
"options": {
"mysql": {
"table": "workerCalendar2"
"table": "calendar"
}
},
"properties": {
@ -22,7 +22,7 @@
"absenceType": {
"type": "belongsTo",
"model": "AbsenceType",
"foreignKey": "absenceTypeFk"
"foreignKey": "dayOffTypeFk"
}
}
}

View File

@ -1,3 +0,0 @@
module.exports = Self => {
require('../methods/worker-calendar/absences')(Self);
};

View File

@ -223,7 +223,7 @@ class Controller extends Section {
started: this.started,
ended: this.ended
};
return this.$http.get(`WorkerCalendars/absences`, {params})
return this.$http.get(`Calendars/absences`, {params})
.then(res => this.onData(res.data));
}
}

View File

@ -59,7 +59,7 @@ describe('Worker', () => {
let yesterday = new Date(today.getTime());
yesterday.setDate(yesterday.getDate() - 1);
$httpBackend.whenRoute('GET', 'WorkerCalendars/absences')
$httpBackend.whenRoute('GET', 'Calendars/absences')
.respond({
holidays: [
{dated: today, detail: {description: 'New year'}},
@ -90,7 +90,7 @@ describe('Worker', () => {
let today = new Date();
$httpBackend.whenRoute('GET', 'WorkerCalendars/absences')
$httpBackend.whenRoute('GET', 'Calendars/absences')
.respond({
absences: [
{dated: today, absenceType: {name: 'Holiday', rgb: '#000'}}
@ -316,7 +316,7 @@ describe('Worker', () => {
const expecteResponse = [{id: 1}];
const expectedParams = {workerFk: 106, started: started, ended: ended};
const serializedParams = $httpParamSerializer(expectedParams);
$httpBackend.expect('GET', `WorkerCalendars/absences?${serializedParams}`).respond(200, expecteResponse);
$httpBackend.expect('GET', `Calendars/absences?${serializedParams}`).respond(200, expecteResponse);
controller.refresh();
$httpBackend.flush();

View File

@ -95,7 +95,7 @@ class Controller extends Section {
ended: this.ended
};
return this.$http.get(`WorkerCalendars/absences`, {params})
return this.$http.get(`Calendars/absences`, {params})
.then(res => this.onData(res.data));
}