Skip to content

Commit

Permalink
Merge pull request #492 from timeoff-management/tom-xxx-fix-leaves-re…
Browse files Browse the repository at this point in the history
…port

Respect the date range on the Leaves report
  • Loading branch information
vpp authored Aug 30, 2021
2 parents 319091d + d935974 commit a711ad7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
10 changes: 0 additions & 10 deletions lib/model/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,6 @@ const fetchLeavesForLeavesReport = async ({startDate, endDate, departmentId, lea
usersLeaves = usersLeaves.filter(l => `${l.leaveTypeId}` === `${leaveTypeId}`);
}

if (startDate) {
const epoch = startDate.valueOf();
usersLeaves = usersLeaves.filter(l => moment.utc(l.date_start).toDate().valueOf() >= epoch);
}

if (endDate) {
const epoch = endDate.valueOf();
usersLeaves = usersLeaves.filter(l => moment.utc(l.date_end).toDate().valueOf() <= epoch);
}

leavesObjects.push(...usersLeaves);
}

Expand Down
5 changes: 5 additions & 0 deletions lib/model/mixin/user/absence_aware.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ module.exports = function(sequelize){
moment.utc(dateStart).startOf('day').format('YYYY-MM-DD'),
moment.utc(dateEnd).endOf('day').format('YYYY-MM-DD HH:mm'),
]
},
// Case when given data range is within existing leave
$and: {
date_start: {$lte: moment.utc(dateStart).startOf('day').format('YYYY-MM-DD')},
date_end: {$gte: moment.utc(dateEnd).endOf('day').format('YYYY-MM-DD')},
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion views/report/leaves.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</div>
<div class="col-md-3">
<div class="form-group">
<label for="leave_type_id">Leave Type</label>
<label for="leave_type_id">Leave type</label>
<select class="form-control" id="leave_type_id" name="leave_type">
<option>All</option>
{{#each leaveTypes}}
Expand Down

0 comments on commit a711ad7

Please sign in to comment.