use of com.axelor.apps.base.db.EventsPlanning in project axelor-open-suite by axelor.
the class EmployeeServiceImpl method getDaysWorksInPeriod.
@Override
public BigDecimal getDaysWorksInPeriod(Employee employee, LocalDate fromDate, LocalDate toDate) throws AxelorException {
Company company = employee.getMainEmploymentContract().getPayCompany();
BigDecimal duration = BigDecimal.ZERO;
WeeklyPlanning weeklyPlanning = employee.getWeeklyPlanning();
if (weeklyPlanning == null) {
HRConfig conf = company.getHrConfig();
if (conf != null) {
weeklyPlanning = conf.getWeeklyPlanning();
}
}
if (weeklyPlanning == null) {
throw new AxelorException(employee, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), employee.getName());
}
EventsPlanning publicHolidayPlanning = employee.getPublicHolidayEventsPlanning();
if (publicHolidayPlanning == null) {
HRConfig conf = company.getHrConfig();
if (conf != null) {
publicHolidayPlanning = conf.getPublicHolidayEventsPlanning();
}
}
if (publicHolidayPlanning == null) {
throw new AxelorException(employee, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.EMPLOYEE_PUBLIC_HOLIDAY), employee.getName());
}
LocalDate date = fromDate;
while (!date.isAfter(toDate)) {
duration = duration.add(BigDecimal.valueOf(weeklyPlanningService.getWorkingDayValueInDays(weeklyPlanning, date)));
date = date.plusDays(1);
}
duration = duration.subtract(Beans.get(PublicHolidayHrService.class).computePublicHolidayDays(fromDate, toDate, weeklyPlanning, publicHolidayPlanning));
return duration;
}
Aggregations