Search in sources :

Example 11 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class ExpenseController method valid.

// validating expense and sending mail to applicant
public void valid(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Expense expense = request.getContext().asType(Expense.class);
        expense = Beans.get(ExpenseRepository.class).find(expense.getId());
        ExpenseService expenseService = Beans.get(ExpenseService.class);
        expenseService.validate(expense);
        Message message = expenseService.sendValidationEmail(expense);
        if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
            response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) Expense(com.axelor.apps.hr.db.Expense) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) AxelorException(com.axelor.exception.AxelorException)

Example 12 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class ExtraHoursController method cancel.

// canceling request and sending mail to applicant
public void cancel(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        ExtraHours extraHours = request.getContext().asType(ExtraHours.class);
        extraHours = Beans.get(ExtraHoursRepository.class).find(extraHours.getId());
        Beans.get(ExtraHoursService.class).cancel(extraHours);
        Message message = Beans.get(ExtraHoursService.class).sendCancellationEmail(extraHours);
        if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
            response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : ExtraHours(com.axelor.apps.hr.db.ExtraHours) Message(com.axelor.apps.message.db.Message) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) ExtraHoursService(com.axelor.apps.hr.service.extra.hours.ExtraHoursService) AxelorException(com.axelor.exception.AxelorException)

Example 13 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class ExtraHoursController method refuse.

// refusing request and sending mail to applicant
public void refuse(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        ExtraHours extraHours = request.getContext().asType(ExtraHours.class);
        extraHours = Beans.get(ExtraHoursRepository.class).find(extraHours.getId());
        Beans.get(ExtraHoursService.class).refuse(extraHours);
        Message message = Beans.get(ExtraHoursService.class).sendRefusalEmail(extraHours);
        if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
            response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : ExtraHours(com.axelor.apps.hr.db.ExtraHours) Message(com.axelor.apps.message.db.Message) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) ExtraHoursService(com.axelor.apps.hr.service.extra.hours.ExtraHoursService) AxelorException(com.axelor.exception.AxelorException)

Example 14 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class LeaveController method refuse.

/**
 * Refuses leave request and sends an email to the applicant.
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void refuse(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        LeaveService leaveService = Beans.get(LeaveService.class);
        LeaveRequest leaveRequest = request.getContext().asType(LeaveRequest.class);
        leaveRequest = Beans.get(LeaveRequestRepository.class).find(leaveRequest.getId());
        leaveService.refuse(leaveRequest);
        Message message = leaveService.sendRefusalEmail(leaveRequest);
        if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
            response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) AxelorException(com.axelor.exception.AxelorException)

Example 15 with Message

use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.

the class LeaveController method send.

// sending leave request and an email to the manager
public void send(ActionRequest request, ActionResponse response) {
    try {
        LeaveService leaveService = Beans.get(LeaveService.class);
        LeaveRequest leaveRequest = request.getContext().asType(LeaveRequest.class);
        leaveRequest = Beans.get(LeaveRequestRepository.class).find(leaveRequest.getId());
        if (leaveRequest.getUser().getEmployee().getWeeklyPlanning() == null) {
            response.setAlert(String.format(I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), leaveRequest.getUser().getEmployee().getName()));
            return;
        }
        LeaveLine leaveLine = Beans.get(LeaveLineRepository.class).all().filter("self.leaveReason = :leaveReason AND self.employee = :employee").bind("leaveReason", leaveRequest.getLeaveReason()).bind("employee", leaveRequest.getUser().getEmployee()).fetchOne();
        if (leaveLine != null && leaveLine.getQuantity().subtract(leaveRequest.getDuration()).signum() < 0) {
            if (!leaveRequest.getLeaveReason().getAllowNegativeValue() && !leaveService.willHaveEnoughDays(leaveRequest)) {
                String instruction = leaveRequest.getLeaveReason().getInstruction();
                if (instruction == null) {
                    instruction = "";
                }
                response.setAlert(String.format(I18n.get(IExceptionMessage.LEAVE_ALLOW_NEGATIVE_VALUE_REASON), leaveRequest.getLeaveReason().getName()) + " " + instruction);
                return;
            } else {
                response.setNotify(String.format(I18n.get(IExceptionMessage.LEAVE_ALLOW_NEGATIVE_ALERT), leaveRequest.getLeaveReason().getName()));
            }
        }
        leaveService.confirm(leaveRequest);
        Message message = leaveService.sendConfirmationEmail(leaveRequest);
        if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
            response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) LeaveLine(com.axelor.apps.hr.db.LeaveLine) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) LeaveLineRepository(com.axelor.apps.hr.db.repo.LeaveLineRepository) AxelorException(com.axelor.exception.AxelorException)

Aggregations

Message (com.axelor.apps.message.db.Message)54 AxelorException (com.axelor.exception.AxelorException)25 MessageServiceBaseImpl (com.axelor.apps.base.service.message.MessageServiceBaseImpl)16 IExceptionMessage (com.axelor.apps.message.exception.IExceptionMessage)14 Transactional (com.google.inject.persist.Transactional)13 IExceptionMessage (com.axelor.apps.hr.exception.IExceptionMessage)11 Template (com.axelor.apps.message.db.Template)7 Timesheet (com.axelor.apps.hr.db.Timesheet)6 ArrayList (java.util.ArrayList)6 Employee (com.axelor.apps.hr.db.Employee)5 EmailAddress (com.axelor.apps.message.db.EmailAddress)5 IExceptionMessage (com.axelor.apps.base.exceptions.IExceptionMessage)4 Expense (com.axelor.apps.hr.db.Expense)4 ExtraHours (com.axelor.apps.hr.db.ExtraHours)4 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)4 ExpenseService (com.axelor.apps.hr.service.expense.ExpenseService)4 ExtraHoursService (com.axelor.apps.hr.service.extra.hours.ExtraHoursService)4 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)4 TimesheetService (com.axelor.apps.hr.service.timesheet.TimesheetService)4 User (com.axelor.auth.db.User)4