use of com.axelor.apps.hr.db.TimesheetReminder in project axelor-open-suite by axelor.
the class TimesheetReportServiceImpl method sendEmailMessage.
private List<Message> sendEmailMessage(List<TimesheetReminder> timesheetReminders, Template reminderTemplate) {
List<Message> messages = new ArrayList<>();
for (TimesheetReminder timesheetReminder : timesheetReminders) {
try {
Message message = templateMessageService.generateMessage(timesheetReminder, reminderTemplate);
message = messageService.sendMessage(message);
timesheetReminder.setEmailSentDateT(LocalDateTime.now());
messages.add(message);
} catch (Exception e) {
TraceBackService.trace(e);
}
}
return messages;
}
use of com.axelor.apps.hr.db.TimesheetReminder 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.apps.hr.db.TimesheetReminder in project axelor-open-suite by axelor.
the class TimesheetReportServiceImpl method sendReminders.
@Transactional
public List<Message> sendReminders(TimesheetReport timesheetReport) throws AxelorException {
Template reminderTemplate = Beans.get(AppHumanResourceService.class).getAppTimesheet().getTimesheetReminderTemplate();
if (reminderTemplate == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.EMPLOYEE_TIMESHEET_REMINDER_TEMPLATE));
}
List<TimesheetReminder> timesheetReminders = getTimesheetReminderList(timesheetReport);
return sendEmailMessage(timesheetReminders, reminderTemplate);
}
Aggregations