Search in sources :

Example 6 with EventsPlanning

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) HRConfig(com.axelor.apps.hr.db.HRConfig) EventsPlanning(com.axelor.apps.base.db.EventsPlanning) PublicHolidayHrService(com.axelor.apps.hr.service.publicHoliday.PublicHolidayHrService) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Aggregations

EventsPlanning (com.axelor.apps.base.db.EventsPlanning)6 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)4 BigDecimal (java.math.BigDecimal)4 LocalDate (java.time.LocalDate)4 HRConfig (com.axelor.apps.hr.db.HRConfig)3 Company (com.axelor.apps.base.db.Company)2 Employee (com.axelor.apps.hr.db.Employee)2 AppBase (com.axelor.apps.base.db.AppBase)1 AppLeave (com.axelor.apps.base.db.AppLeave)1 AppTimesheet (com.axelor.apps.base.db.AppTimesheet)1 EventsPlanningLine (com.axelor.apps.base.db.EventsPlanningLine)1 PriceList (com.axelor.apps.base.db.PriceList)1 PublicHolidayService (com.axelor.apps.base.service.publicHoliday.PublicHolidayService)1 UserService (com.axelor.apps.base.service.user.UserService)1 WeeklyPlanningService (com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService)1 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)1 EmployeeRepository (com.axelor.apps.hr.db.repo.EmployeeRepository)1 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)1 PublicHolidayHrService (com.axelor.apps.hr.service.publicHoliday.PublicHolidayHrService)1 User (com.axelor.auth.db.User)1