use of com.axelor.apps.base.db.WeeklyPlanning 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.WeeklyPlanning 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.WeeklyPlanning in project axelor-open-suite by axelor.
the class LeaveServiceImpl method computeLeaveDaysByLeaveRequest.
@Override
public BigDecimal computeLeaveDaysByLeaveRequest(LocalDate fromDate, LocalDate toDate, LeaveRequest leaveRequest, Employee employee) throws AxelorException {
BigDecimal leaveDays = BigDecimal.ZERO;
WeeklyPlanning weeklyPlanning = employee.getWeeklyPlanning();
LocalDate leaveFrom = leaveRequest.getFromDateT().toLocalDate();
LocalDate leaveTo = leaveRequest.getToDateT().toLocalDate();
LocalDate itDate = fromDate;
if (fromDate.isBefore(leaveFrom) || fromDate.equals(leaveFrom)) {
itDate = leaveFrom;
}
boolean morningHalf = false;
boolean eveningHalf = false;
BigDecimal daysToAdd = BigDecimal.ZERO;
if (leaveTo.equals(leaveFrom) && leaveRequest.getStartOnSelect() == leaveRequest.getEndOnSelect()) {
eveningHalf = leaveRequest.getStartOnSelect() == LeaveRequestRepository.SELECT_AFTERNOON;
morningHalf = leaveRequest.getStartOnSelect() == LeaveRequestRepository.SELECT_MORNING;
}
while (!itDate.isEqual(leaveTo.plusDays(1)) && !itDate.isEqual(toDate.plusDays(1))) {
if (itDate.equals(leaveFrom) && !morningHalf) {
daysToAdd = BigDecimal.valueOf(computeStartDateWithSelect(itDate, leaveRequest.getStartOnSelect(), weeklyPlanning));
} else if (itDate.equals(leaveTo) && !eveningHalf) {
daysToAdd = BigDecimal.valueOf(computeEndDateWithSelect(itDate, leaveRequest.getEndOnSelect(), weeklyPlanning));
} else {
daysToAdd = BigDecimal.valueOf(weeklyPlanningService.getWorkingDayValueInDays(weeklyPlanning, itDate));
}
if (!publicHolidayHrService.checkPublicHolidayDay(itDate, employee)) {
leaveDays = leaveDays.add(daysToAdd);
}
itDate = itDate.plusDays(1);
}
return leaveDays;
}
use of com.axelor.apps.base.db.WeeklyPlanning in project axelor-open-suite by axelor.
the class WeeklyPlanningController method initPlanning.
public void initPlanning(ActionRequest request, ActionResponse response) {
WeeklyPlanning planning = request.getContext().asType(WeeklyPlanning.class);
planning = Beans.get(WeeklyPlanningService.class).initPlanning(planning);
if (request.getContext().containsKey("_typeSelect")) {
response.setValue("typeSelect", request.getContext().get("_typeSelect"));
}
response.setValue("weekDays", planning.getWeekDays());
}
use of com.axelor.apps.base.db.WeeklyPlanning in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method generateLines.
@Override
public Timesheet generateLines(Timesheet timesheet, LocalDate fromGenerationDate, LocalDate toGenerationDate, BigDecimal logTime, Project project, Product product) throws AxelorException {
User user = timesheet.getUser();
Employee employee = user.getEmployee();
if (fromGenerationDate == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_FROM_DATE));
}
if (toGenerationDate == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_TO_DATE));
}
if (product == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_PRODUCT));
}
if (employee == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), user.getName());
}
WeeklyPlanning planning = employee.getWeeklyPlanning();
if (planning == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_DAY_PLANNING), user.getName());
}
List<DayPlanning> dayPlanningList = planning.getWeekDays();
Map<Integer, String> correspMap = getCorresMap();
LocalDate fromDate = fromGenerationDate;
LocalDate toDate = toGenerationDate;
if (employee.getPublicHolidayEventsPlanning() == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_PUBLIC_HOLIDAY_EVENTS_PLANNING), user.getName());
}
LeaveService leaveService = Beans.get(LeaveService.class);
PublicHolidayHrService publicHolidayHrService = Beans.get(PublicHolidayHrService.class);
while (!fromDate.isAfter(toDate)) {
if (isWorkedDay(fromDate, correspMap, dayPlanningList) && !leaveService.isLeaveDay(user, fromDate) && !publicHolidayHrService.checkPublicHolidayDay(fromDate, employee)) {
TimesheetLine timesheetLine = timesheetLineService.createTimesheetLine(project, product, user, fromDate, timesheet, timesheetLineService.computeHoursDuration(timesheet, logTime, true), "");
timesheetLine.setDuration(logTime);
}
fromDate = fromDate.plusDays(1);
}
return timesheet;
}
Aggregations