Search in sources :

Example 26 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class BatchTimesheetReminder method sendReminderUsingEmployees.

protected void sendReminderUsingEmployees(Template template) throws AxelorException, MessagingException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    for (Employee employee : getEmployeesWithoutRecentTimesheet(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null)).stream().filter(Objects::nonNull).collect(Collectors.toList())) {
        Message message = templateMessageService.generateMessage(employee, template);
        messageService.sendByEmail(message);
        incrementDone();
    }
}
Also used : Employee(com.axelor.apps.hr.db.Employee) IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message)

Example 27 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class BatchTimesheetReminder method sendReminderUsingTimesheets.

protected void sendReminderUsingTimesheets(Template template) throws AxelorException, MessagingException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    for (Employee employee : getEmployeesWithoutRecentTimesheet(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null)).stream().filter(Objects::nonNull).collect(Collectors.toList())) {
        if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
            continue;
        }
        Timesheet timeSheet = getRecentEmployeeTimesheet(employee);
        if (timeSheet != null) {
            Message message = templateMessageService.generateMessage(timeSheet, template);
            messageService.sendByEmail(message);
        } else {
            throw new AxelorException(Timesheet.class, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.NO_TIMESHEET_FOUND_FOR_EMPLOYEE), employee.getName());
        }
        incrementDone();
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) Timesheet(com.axelor.apps.hr.db.Timesheet)

Example 28 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class BatchTimesheetValidationReminder method generateEmail.

public void generateEmail() {
    List<Timesheet> timesheetList = Beans.get(CompanyRepository.class).all().count() > 1 ? Beans.get(TimesheetRepository.class).all().filter("self.company.id = ?1 AND self.statusSelect = 1 AND self.user.employee.timesheetReminder = true", batch.getMailBatch().getCompany().getId()).fetch() : Beans.get(TimesheetRepository.class).all().filter("self.statusSelect = 1 AND self.user.employee.timesheetReminder = true").fetch();
    for (Timesheet timesheet : timesheetList) {
        try {
            Employee employee = timesheet.getUser().getEmployee();
            if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
                continue;
            }
            generateAndSendMessage(employee);
            incrementDone();
        } catch (Exception e) {
            incrementAnomaly();
            TraceBackService.trace(new Exception(e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
        }
    }
}
Also used : Employee(com.axelor.apps.hr.db.Employee) Timesheet(com.axelor.apps.hr.db.Timesheet) MessagingException(javax.mail.MessagingException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 29 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class BatchTimesheetValidationReminder method generateAllEmail.

public void generateAllEmail() {
    List<Employee> employeeList = Beans.get(EmployeeRepository.class).all().filter("self.timesheetReminder = true").fetch();
    for (Employee employee : employeeList) {
        if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
            continue;
        }
        try {
            generateAndSendMessage(employee);
            incrementDone();
        } catch (Exception e) {
            incrementAnomaly();
            TraceBackService.trace(new Exception(e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
        }
    }
}
Also used : EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Employee(com.axelor.apps.hr.db.Employee) MessagingException(javax.mail.MessagingException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 30 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class PayrollPreparationService method fillInLeaves.

public List<PayrollLeave> fillInLeaves(PayrollPreparation payrollPreparation) throws AxelorException {
    List<PayrollLeave> payrollLeaveList = new ArrayList<>();
    LocalDate fromDate = payrollPreparation.getPeriod().getFromDate();
    LocalDate toDate = payrollPreparation.getPeriod().getToDate();
    Employee employee = payrollPreparation.getEmployee();
    if (employee.getWeeklyPlanning() == null) {
        throw new AxelorException(payrollPreparation, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), employee.getName());
    }
    List<LeaveRequest> leaveRequestList = leaveRequestRepo.all().filter("self.statusSelect = ?4 AND self.user.employee = ?3 AND ((self.fromDateT BETWEEN ?2 AND ?1 OR self.toDateT BETWEEN ?2 AND ?1) OR (?1 BETWEEN self.fromDateT AND self.toDateT OR ?2 BETWEEN self.fromDateT AND self.toDateT))", toDate, fromDate, employee, LeaveRequestRepository.STATUS_VALIDATED).fetch();
    for (LeaveRequest leaveRequest : leaveRequestList) {
        PayrollLeave payrollLeave = new PayrollLeave();
        if (leaveRequest.getFromDateT().toLocalDate().isBefore(fromDate)) {
            payrollLeave.setFromDate(fromDate);
        } else {
            payrollLeave.setFromDate(leaveRequest.getFromDateT().toLocalDate());
        }
        if (leaveRequest.getToDateT().toLocalDate().isAfter(toDate)) {
            payrollLeave.setToDate(toDate);
        } else {
            payrollLeave.setToDate(leaveRequest.getToDateT().toLocalDate());
        }
        payrollLeave.setDuration(leaveService.computeLeaveDaysByLeaveRequest(fromDate, toDate, leaveRequest, employee));
        payrollLeave.setLeaveReason(leaveRequest.getLeaveReason());
        payrollLeave.setLeaveRequest(leaveRequest);
        payrollLeaveList.add(payrollLeave);
    }
    return payrollLeaveList;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) ArrayList(java.util.ArrayList) PayrollLeave(com.axelor.apps.hr.db.PayrollLeave) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) LocalDate(java.time.LocalDate)

Aggregations

Employee (com.axelor.apps.hr.db.Employee)71 AxelorException (com.axelor.exception.AxelorException)34 User (com.axelor.auth.db.User)28 Transactional (com.google.inject.persist.Transactional)21 BigDecimal (java.math.BigDecimal)18 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)14 LocalDate (java.time.LocalDate)13 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)9 EmployeeRepository (com.axelor.apps.hr.db.repo.EmployeeRepository)9 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)8 Message (com.axelor.apps.message.db.Message)8 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)7 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 DayPlanning (com.axelor.apps.base.db.DayPlanning)6 LeaveLine (com.axelor.apps.hr.db.LeaveLine)6 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Company (com.axelor.apps.base.db.Company)5