use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class TimesheetReportServiceImpl method getUserToBeReminded.
@Override
public Set<User> getUserToBeReminded(TimesheetReport timesheetReport) {
Set<User> userSet = new HashSet<>();
BigDecimal worksHour = BigDecimal.ZERO, workedHour = BigDecimal.ZERO;
List<User> users = getUsers(timesheetReport);
LocalDate fromDate = timesheetReport.getFromDate();
LocalDate toDate = timesheetReport.getToDate();
for (User user : users) {
Employee employee = user.getEmployee();
try {
worksHour = workedHour = BigDecimal.ZERO;
BigDecimal publicHolidays = publicHolidayService.computePublicHolidayDays(fromDate, toDate, employee.getWeeklyPlanning(), employee.getPublicHolidayEventsPlanning());
worksHour = getTotalWeekWorksHours(user, fromDate, toDate, publicHolidays);
workedHour = getTotalWeekWorkedHours(user, fromDate, toDate, publicHolidays);
if (worksHour.compareTo(workedHour) != 0) {
userSet.add(user);
}
} catch (Exception e) {
TraceBackService.trace(e);
}
}
return userSet;
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class TimesheetReportServiceImpl method addTimesheetReminder.
private void addTimesheetReminder(TimesheetReport timesheetReport, List<User> users, List<TimesheetReminder> timesheetReminders) throws AxelorException {
BigDecimal worksHour = BigDecimal.ZERO, workedHour = BigDecimal.ZERO, missingHour = BigDecimal.ZERO, extraHour = BigDecimal.ZERO;
LocalDate fromDate = timesheetReport.getFromDate();
LocalDate toDate = null;
do {
toDate = fromDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
if (toDate.until(timesheetReport.getToDate()).getDays() < 0) {
toDate = timesheetReport.getToDate();
}
for (User user : users) {
Employee employee = user.getEmployee();
missingHour = BigDecimal.ZERO;
extraHour = BigDecimal.ZERO;
BigDecimal publicHolidays = publicHolidayService.computePublicHolidayDays(fromDate, toDate, employee.getWeeklyPlanning(), employee.getPublicHolidayEventsPlanning());
worksHour = getTotalWeekWorksHours(user, fromDate, toDate, publicHolidays);
workedHour = getTotalWeekWorkedHours(user, fromDate, toDate, publicHolidays);
if (worksHour.compareTo(workedHour) == 1) {
missingHour = worksHour.subtract(workedHour);
} else if (worksHour.compareTo(workedHour) == -1) {
extraHour = workedHour.subtract(worksHour);
}
if (missingHour.compareTo(BigDecimal.ZERO) == 0 && extraHour.compareTo(BigDecimal.ZERO) == 0) {
continue;
}
Optional<TimesheetReminder> optReminder = timesheetReminders.stream().filter(reminder -> reminder.getEmployee().getId().compareTo(employee.getId()) == 0).findFirst();
TimesheetReminder timesheetReminder = null;
if (optReminder.isPresent()) {
timesheetReminder = optReminder.get();
timesheetReminder.addTimesheetReminderLineListItem(createTimesheetReminderLine(fromDate, toDate, worksHour, missingHour, extraHour));
} else {
List<TimesheetReminderLine> timesheetReminderLines = new ArrayList<>();
timesheetReminder = new TimesheetReminder();
timesheetReminder.setEmployee(employee);
timesheetReminder.setTimesheetReminderLineList(timesheetReminderLines);
timesheetReminder.addTimesheetReminderLineListItem(createTimesheetReminderLine(fromDate, toDate, worksHour, missingHour, extraHour));
timesheetReminders.add(timesheetReminder);
}
timesheetReminderRepo.save(timesheetReminder);
}
fromDate = fromDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
} while (toDate.until(timesheetReport.getToDate()).getDays() > 0);
}
use of com.axelor.auth.db.User 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.auth.db.User 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.auth.db.User in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method computeFullName.
@Override
public String computeFullName(Timesheet timesheet) {
User timesheetUser = timesheet.getUser();
LocalDateTime createdOn = timesheet.getCreatedOn();
if (timesheetUser != null && createdOn != null) {
return timesheetUser.getFullName() + " " + createdOn.getDayOfMonth() + "/" + createdOn.getMonthValue() + "/" + timesheet.getCreatedOn().getYear() + " " + createdOn.getHour() + ":" + createdOn.getMinute();
} else if (timesheetUser != null) {
return timesheetUser.getFullName() + " N°" + timesheet.getId();
} else {
return "N°" + timesheet.getId();
}
}
Aggregations