use of com.axelor.apps.base.db.AppTimesheet 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.AppTimesheet in project axelor-open-suite by axelor.
the class AppTimesheetController method switchTimesheetEditors.
public void switchTimesheetEditors(ActionRequest request, ActionResponse response) {
try {
AppTimesheet appTimesheet = request.getContext().asType(AppTimesheet.class);
Beans.get(AppTimesheetService.class).switchTimesheetEditors(appTimesheet.getTimesheetEditor());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations