Search in sources :

Example 1 with TimesheetReminder

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;
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) ArrayList(java.util.ArrayList) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) AxelorException(com.axelor.exception.AxelorException)

Example 2 with TimesheetReminder

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);
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LeaveRequestRepository(com.axelor.apps.hr.db.repo.LeaveRequestRepository) Employee(com.axelor.apps.hr.db.Employee) Inject(com.google.inject.Inject) TimesheetReportRepository(com.axelor.apps.hr.db.repo.TimesheetReportRepository) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) LeaveReasonRepository(com.axelor.apps.hr.db.repo.LeaveReasonRepository) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) Duration(java.time.Duration) Map(java.util.Map) EmployeeService(com.axelor.apps.hr.service.employee.EmployeeService) RoundingMode(java.math.RoundingMode) PublicHolidayService(com.axelor.apps.base.service.publicHoliday.PublicHolidayService) Set(java.util.Set) Message(com.axelor.apps.message.db.Message) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Collectors(java.util.stream.Collectors) MessageService(com.axelor.apps.message.service.MessageService) List(java.util.List) Stream(java.util.stream.Stream) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) LocalDate(java.time.LocalDate) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) ExtraHoursRepository(com.axelor.apps.hr.db.repo.ExtraHoursRepository) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) TimesheetReminderLine(com.axelor.apps.hr.db.TimesheetReminderLine) ExtraHoursLineRepository(com.axelor.apps.hr.db.repo.ExtraHoursLineRepository) AppHumanResourceService(com.axelor.apps.hr.service.app.AppHumanResourceService) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) AxelorException(com.axelor.exception.AxelorException) I18n(com.axelor.i18n.I18n) DateTool(com.axelor.apps.tool.date.DateTool) WeekFields(java.time.temporal.WeekFields) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) QueryBuilder(com.axelor.apps.tool.QueryBuilder) TraceBackService(com.axelor.exception.service.TraceBackService) TimesheetReminderRepository(com.axelor.apps.hr.db.repo.TimesheetReminderRepository) Template(com.axelor.apps.message.db.Template) DayPlanning(com.axelor.apps.base.db.DayPlanning) Beans(com.axelor.inject.Beans) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) DayOfWeek(java.time.DayOfWeek) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) User(com.axelor.auth.db.User) TimesheetReminderLine(com.axelor.apps.hr.db.TimesheetReminderLine) User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 3 with TimesheetReminder

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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) Template(com.axelor.apps.message.db.Template) Transactional(com.google.inject.persist.Transactional)

Aggregations

TimesheetReminder (com.axelor.apps.hr.db.TimesheetReminder)3 AxelorException (com.axelor.exception.AxelorException)3 IExceptionMessage (com.axelor.apps.hr.exception.IExceptionMessage)2 Message (com.axelor.apps.message.db.Message)2 Template (com.axelor.apps.message.db.Template)2 Transactional (com.google.inject.persist.Transactional)2 DayPlanning (com.axelor.apps.base.db.DayPlanning)1 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)1 PublicHolidayService (com.axelor.apps.base.service.publicHoliday.PublicHolidayService)1 WeeklyPlanningService (com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService)1 Employee (com.axelor.apps.hr.db.Employee)1 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)1 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)1 TimesheetReminderLine (com.axelor.apps.hr.db.TimesheetReminderLine)1 TimesheetReport (com.axelor.apps.hr.db.TimesheetReport)1 ExtraHoursLineRepository (com.axelor.apps.hr.db.repo.ExtraHoursLineRepository)1 ExtraHoursRepository (com.axelor.apps.hr.db.repo.ExtraHoursRepository)1 LeaveReasonRepository (com.axelor.apps.hr.db.repo.LeaveReasonRepository)1 LeaveRequestRepository (com.axelor.apps.hr.db.repo.LeaveRequestRepository)1 TimesheetLineRepository (com.axelor.apps.hr.db.repo.TimesheetLineRepository)1