Search in sources :

Example 1 with EventsPlanning

use of com.axelor.apps.base.db.EventsPlanning in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method prefillLines.

@Override
public void prefillLines(Timesheet timesheet) throws AxelorException {
    PublicHolidayService holidayService = Beans.get(PublicHolidayService.class);
    LeaveService leaveService = Beans.get(LeaveService.class);
    WeeklyPlanningService weeklyPlanningService = Beans.get(WeeklyPlanningService.class);
    AppTimesheet appTimesheet = appHumanResourceService.getAppTimesheet();
    LocalDate fromDate = timesheet.getFromDate();
    LocalDate toDate = timesheet.getToDate();
    User user = timesheet.getUser();
    Employee employee = user.getEmployee();
    HRConfig config = timesheet.getCompany().getHrConfig();
    WeeklyPlanning weeklyPlanning = employee != null ? employee.getWeeklyPlanning() : config.getWeeklyPlanning();
    EventsPlanning holidayPlanning = employee != null ? employee.getPublicHolidayEventsPlanning() : config.getPublicHolidayEventsPlanning();
    for (LocalDate date = fromDate; !date.isAfter(toDate); date = date.plusDays(1)) {
        BigDecimal dayValueInHours = weeklyPlanningService.getWorkingDayValueInHours(weeklyPlanning, date, LocalTime.MIN, LocalTime.MAX);
        if (appTimesheet.getCreateLinesForHolidays() && holidayService.checkPublicHolidayDay(date, holidayPlanning)) {
            timesheetLineService.createTimesheetLine(user, date, timesheet, dayValueInHours, I18n.get(IExceptionMessage.TIMESHEET_HOLIDAY));
        } else if (appTimesheet.getCreateLinesForLeaves()) {
            List<LeaveRequest> leaveList = leaveService.getLeaves(user, date);
            BigDecimal totalLeaveHours = BigDecimal.ZERO;
            if (ObjectUtils.notEmpty(leaveList)) {
                for (LeaveRequest leave : leaveList) {
                    BigDecimal leaveHours = leaveService.computeDuration(leave, date, date);
                    if (leave.getLeaveReason().getUnitSelect() == LeaveReasonRepository.UNIT_SELECT_DAYS) {
                        leaveHours = leaveHours.multiply(dayValueInHours);
                    }
                    totalLeaveHours = totalLeaveHours.add(leaveHours);
                }
                timesheetLineService.createTimesheetLine(user, date, timesheet, totalLeaveHours, I18n.get(IExceptionMessage.TIMESHEET_DAY_LEAVE));
            }
        }
    }
}
Also used : User(com.axelor.auth.db.User) EventsPlanning(com.axelor.apps.base.db.EventsPlanning) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AppTimesheet(com.axelor.apps.base.db.AppTimesheet) Employee(com.axelor.apps.hr.db.Employee) HRConfig(com.axelor.apps.hr.db.HRConfig) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) PublicHolidayService(com.axelor.apps.base.service.publicHoliday.PublicHolidayService)

Example 2 with EventsPlanning

use of com.axelor.apps.base.db.EventsPlanning in project axelor-open-suite by axelor.

the class LeaveServiceImpl method computeDurationInHours.

/**
 * Computes the duration in hours of a leave, according to the weekly and the holiday plannings.
 *
 * @param leave
 * @param employee
 * @param fromDateT
 * @param toDateT
 * @return
 * @throws AxelorException
 */
protected BigDecimal computeDurationInHours(LeaveRequest leave, Employee employee, LocalDateTime fromDateT, LocalDateTime toDateT) throws AxelorException {
    BigDecimal duration = BigDecimal.ZERO;
    WeeklyPlanning weeklyPlanning = getWeeklyPlanning(leave, employee);
    EventsPlanning holidayPlanning = getPublicHolidayEventsPlanning(leave, employee);
    LocalDate fromDate = fromDateT.toLocalDate();
    LocalDate toDate = toDateT.toLocalDate();
    if (toDate.equals(fromDate) && !publicHolidayHrService.checkPublicHolidayDay(fromDate, holidayPlanning)) {
        duration = duration.add(weeklyPlanningService.getWorkingDayValueInHours(weeklyPlanning, fromDate, fromDateT.toLocalTime(), toDateT.toLocalTime()));
    } else {
        // First day of leave
        if (!publicHolidayHrService.checkPublicHolidayDay(fromDate, holidayPlanning)) {
            duration = duration.add(weeklyPlanningService.getWorkingDayValueInHours(weeklyPlanning, fromDate, fromDateT.toLocalTime(), null));
        }
        fromDate = fromDate.plusDays(1);
        // Last day of leave
        if (!publicHolidayHrService.checkPublicHolidayDay(toDate, holidayPlanning)) {
            duration = duration.add(weeklyPlanningService.getWorkingDayValueInHours(weeklyPlanning, toDate, null, toDateT.toLocalTime()));
        }
        // Daily leave duration of the other days between from and to date
        for (LocalDate date = fromDate; date.isBefore(toDate); date = date.plusDays(1)) {
            if (!publicHolidayHrService.checkPublicHolidayDay(date, holidayPlanning)) {
                duration = duration.add(weeklyPlanningService.getWorkingDayValueInHours(weeklyPlanning, date, null, null));
            }
        }
    }
    return duration;
}
Also used : EventsPlanning(com.axelor.apps.base.db.EventsPlanning) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 3 with EventsPlanning

use of com.axelor.apps.base.db.EventsPlanning in project axelor-open-suite by axelor.

the class PublicHolidayHrService method getImposedDayNumber.

public int getImposedDayNumber(Employee employee, LocalDate startDate, LocalDate endDate) {
    EventsPlanning imposedDays = employee.getImposedDayEventsPlanning();
    if (imposedDays == null || imposedDays.getEventsPlanningLineList() == null || imposedDays.getEventsPlanningLineList().isEmpty()) {
        return 0;
    }
    List<EventsPlanningLine> imposedDayList = eventsPlanningLineRepo.all().filter("self.eventsPlanning = ?1 AND self.date BETWEEN ?2 AND ?3", imposedDays, startDate, endDate).fetch();
    return imposedDayList.size();
}
Also used : EventsPlanning(com.axelor.apps.base.db.EventsPlanning) EventsPlanningLine(com.axelor.apps.base.db.EventsPlanningLine)

Example 4 with EventsPlanning

use of com.axelor.apps.base.db.EventsPlanning in project axelor-open-suite by axelor.

the class LeaveServiceImpl method computeDurationInDays.

/**
 * Computes the duration in days of a leave, according to the input planning.
 *
 * @param leave
 * @param employee
 * @param fromDate
 * @param toDate
 * @param startOn
 * @param endOn
 * @return
 * @throws AxelorException
 */
protected BigDecimal computeDurationInDays(LeaveRequest leave, Employee employee, LocalDate fromDate, LocalDate toDate, int startOn, int endOn) throws AxelorException {
    BigDecimal duration = BigDecimal.ZERO;
    WeeklyPlanning weeklyPlanning = getWeeklyPlanning(leave, employee);
    EventsPlanning holidayPlanning = getPublicHolidayEventsPlanning(leave, employee);
    // If the leave request is only for 1 day
    if (fromDate.isEqual(toDate)) {
        if (startOn == endOn) {
            if (startOn == LeaveRequestRepository.SELECT_MORNING) {
                duration = duration.add(BigDecimal.valueOf(weeklyPlanningService.getWorkingDayValueInDaysWithSelect(weeklyPlanning, fromDate, true, false)));
            } else {
                duration = duration.add(BigDecimal.valueOf(weeklyPlanningService.getWorkingDayValueInDaysWithSelect(weeklyPlanning, fromDate, false, true)));
            }
        } else {
            duration = duration.add(BigDecimal.valueOf(weeklyPlanningService.getWorkingDayValueInDaysWithSelect(weeklyPlanning, fromDate, true, true)));
        }
    // Else if it's on several days
    } else {
        duration = duration.add(BigDecimal.valueOf(computeStartDateWithSelect(fromDate, startOn, weeklyPlanning)));
        LocalDate itDate = fromDate.plusDays(1);
        while (!itDate.isEqual(toDate) && !itDate.isAfter(toDate)) {
            duration = duration.add(BigDecimal.valueOf(weeklyPlanningService.getWorkingDayValueInDays(weeklyPlanning, itDate)));
            itDate = itDate.plusDays(1);
        }
        duration = duration.add(BigDecimal.valueOf(computeEndDateWithSelect(toDate, endOn, weeklyPlanning)));
    }
    if (holidayPlanning != null) {
        duration = duration.subtract(publicHolidayHrService.computePublicHolidayDays(fromDate, toDate, weeklyPlanning, holidayPlanning));
    }
    return duration;
}
Also used : EventsPlanning(com.axelor.apps.base.db.EventsPlanning) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 5 with EventsPlanning

use of com.axelor.apps.base.db.EventsPlanning in project axelor-open-suite by axelor.

the class UserHrServiceImpl method createEmployee.

@Transactional
public void createEmployee(User user) {
    if (user.getPartner() == null) {
        Beans.get(UserService.class).createPartner(user);
    }
    AppBase appBase = appHumanResourceService.getAppBase();
    AppLeave appLeave = appHumanResourceService.getAppLeave();
    Employee employee = new Employee();
    employee.setContactPartner(user.getPartner());
    employee.setTimeLoggingPreferenceSelect(appBase.getTimeLoggingPreferenceSelect());
    employee.setDailyWorkHours(appBase.getDailyWorkHours());
    employee.setNegativeValueLeave(appLeave.getAllowNegativeLeaveEmployees());
    EventsPlanning planning = null;
    Company company = user.getActiveCompany();
    if (company != null) {
        HRConfig hrConfig = company.getHrConfig();
        if (hrConfig != null) {
            planning = hrConfig.getPublicHolidayEventsPlanning();
        }
    }
    employee.setPublicHolidayEventsPlanning(planning);
    employee.setUser(user);
    Beans.get(EmployeeRepository.class).save(employee);
    user.setEmployee(employee);
    userRepo.save(user);
}
Also used : EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Company(com.axelor.apps.base.db.Company) Employee(com.axelor.apps.hr.db.Employee) HRConfig(com.axelor.apps.hr.db.HRConfig) UserService(com.axelor.apps.base.service.user.UserService) AppLeave(com.axelor.apps.base.db.AppLeave) EventsPlanning(com.axelor.apps.base.db.EventsPlanning) AppBase(com.axelor.apps.base.db.AppBase) Transactional(com.google.inject.persist.Transactional)

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