use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.
the class WeeklyPlanningServiceImp method initPlanning.
@Override
@Transactional
public WeeklyPlanning initPlanning(WeeklyPlanning planning) {
String[] dayTab = new String[] { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };
for (int i = 0; i < dayTab.length; i++) {
DayPlanning day = new DayPlanning();
day.setName(dayTab[i]);
planning.addWeekDay(day);
}
return planning;
}
use of com.axelor.apps.base.db.DayPlanning 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;
}
use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method checkEmptyPeriod.
public void checkEmptyPeriod(Timesheet timesheet) throws AxelorException {
LeaveService leaveService = Beans.get(LeaveService.class);
PublicHolidayHrService publicHolidayHrService = Beans.get(PublicHolidayHrService.class);
User user = timesheet.getUser();
Employee employee = user.getEmployee();
if (employee == null) {
return;
}
if (employee.getPublicHolidayEventsPlanning() == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_PUBLIC_HOLIDAY_EVENTS_PLANNING), 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();
List<TimesheetLine> timesheetLines = timesheet.getTimesheetLineList();
timesheetLines.sort(Comparator.comparing(TimesheetLine::getDate));
for (int i = 0; i < timesheetLines.size(); i++) {
if (i + 1 < timesheetLines.size()) {
LocalDate date1 = timesheetLines.get(i).getDate();
LocalDate date2 = timesheetLines.get(i + 1).getDate();
LocalDate missingDay = date1.plusDays(1);
while (ChronoUnit.DAYS.between(date1, date2) > 1) {
if (isWorkedDay(missingDay, correspMap, dayPlanningList) && !leaveService.isLeaveDay(user, missingDay) && !publicHolidayHrService.checkPublicHolidayDay(missingDay, employee)) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "Line for %s is missing.", missingDay);
}
date1 = missingDay;
missingDay = missingDay.plusDays(1);
}
}
}
}
use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.
the class TimesheetReportServiceImpl method getTimesheetReportList.
public List<Map<String, Object>> getTimesheetReportList(String timesheetReportId) {
List<Map<String, Object>> list = new ArrayList<>();
WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 5);
TimesheetReport timesheetReport = timesheetReportRepository.find(Long.parseLong(timesheetReportId.toString()));
int numOfDays = timesheetReport.getFromDate().until(timesheetReport.getToDate()).getDays();
List<LocalDate> daysRange = Stream.iterate(timesheetReport.getFromDate(), date -> date.plusDays(1)).limit(numOfDays + 1).collect(Collectors.toList());
List<User> users = getUsers(timesheetReport);
for (User user : users) {
Employee employee = user.getEmployee();
BigDecimal dailyWorkingHours = employee.getDailyWorkHours();
WeeklyPlanning weeklyPlanning = employee.getWeeklyPlanning();
Integer weekNumber = 1;
int lastDayIndex = -1;
int daysInWeek = 0;
try {
for (LocalDate date : daysRange) {
DayPlanning dayPlanning = weeklyPlanningService.findDayPlanning(weeklyPlanning, date);
if (dayPlanning == null) {
continue;
}
int dayIndex = date.get(weekFields.dayOfWeek()) - 1;
if (lastDayIndex < dayIndex) {
lastDayIndex = dayIndex;
if (weeklyPlanningService.getWorkingDayValueInDays(weeklyPlanning, date) != 0) {
daysInWeek++;
}
} else {
lastDayIndex = -1;
daysInWeek = 1;
weekNumber++;
}
BigDecimal weeklyWorkHours = daysInWeek <= 5 ? employee.getWeeklyWorkHours().multiply(BigDecimal.valueOf(daysInWeek / 5.00)).setScale(2, RoundingMode.HALF_UP) : employee.getWeeklyWorkHours();
Map<String, Object> map = getTimesheetMap(user, date, dailyWorkingHours);
map.put("weeklyWorkHours", weeklyWorkHours);
map.put("weekNumber", weekNumber.toString());
list.add(map);
}
} catch (Exception e) {
System.out.println(e);
}
}
return list;
}
use of com.axelor.apps.base.db.DayPlanning in project axelor-open-suite by axelor.
the class LeaveServiceImpl method getDefaultEnd.
protected LocalDateTime getDefaultEnd(WeeklyPlanning weeklyPlanning, LeaveRequest leave) {
int endTimeHour = 0;
int endTimeMin = 0;
DayPlanning endDay = weeklyPlanningService.findDayPlanning(weeklyPlanning, leave.getToDateT().toLocalDate());
if (leave.getEndOnSelect() == LeaveRequestRepository.SELECT_MORNING) {
if (endDay != null && endDay.getMorningTo() != null) {
endTimeHour = endDay.getMorningTo().getHour();
endTimeMin = endDay.getMorningTo().getMinute();
} else {
endTimeHour = 12;
endTimeMin = 0;
}
} else {
if (endDay != null && endDay.getAfternoonTo() != null) {
endTimeHour = endDay.getAfternoonTo().getHour();
endTimeMin = endDay.getAfternoonTo().getMinute();
} else {
endTimeHour = 18;
endTimeMin = 0;
}
}
return LocalDateTime.of(leave.getToDateT().toLocalDate(), LocalTime.of(endTimeHour, endTimeMin));
}
Aggregations