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));
}
}
}
}
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;
}
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();
}
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;
}
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);
}
Aggregations