Search in sources :

Example 6 with LeaveService

use of com.axelor.apps.hr.service.leave.LeaveService in project axelor-open-suite by axelor.

the class LeaveController method cancel.

public void cancel(ActionRequest request, ActionResponse response) {
    try {
        LeaveRequest leave = request.getContext().asType(LeaveRequest.class);
        leave = Beans.get(LeaveRequestRepository.class).find(leave.getId());
        LeaveService leaveService = Beans.get(LeaveService.class);
        leaveService.cancel(leave);
        Message message = leaveService.sendCancellationEmail(leave);
        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 7 with LeaveService

use of com.axelor.apps.hr.service.leave.LeaveService in project axelor-open-suite by axelor.

the class LeaveController method validate.

/**
 * Validates leave request and sends an email to the applicant.
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void validate(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());
        leaveService.validate(leaveRequest);
        Message message = leaveService.sendValidationEmail(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)));
        }
        Beans.get(PeriodService.class).checkPeriod(leaveRequest.getCompany(), leaveRequest.getToDateT().toLocalDate(), leaveRequest.getFromDateT().toLocalDate());
    } 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) PeriodService(com.axelor.apps.base.service.PeriodService) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) AxelorException(com.axelor.exception.AxelorException)

Aggregations

LeaveService (com.axelor.apps.hr.service.leave.LeaveService)7 AxelorException (com.axelor.exception.AxelorException)6 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)5 MessageServiceBaseImpl (com.axelor.apps.base.service.message.MessageServiceBaseImpl)4 IExceptionMessage (com.axelor.apps.hr.exception.IExceptionMessage)4 Message (com.axelor.apps.message.db.Message)4 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)3 Employee (com.axelor.apps.hr.db.Employee)3 User (com.axelor.auth.db.User)3 LocalDate (java.time.LocalDate)3 DayPlanning (com.axelor.apps.base.db.DayPlanning)2 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)2 PublicHolidayHrService (com.axelor.apps.hr.service.publicHoliday.PublicHolidayHrService)2 AppTimesheet (com.axelor.apps.base.db.AppTimesheet)1 EventsPlanning (com.axelor.apps.base.db.EventsPlanning)1 PriceList (com.axelor.apps.base.db.PriceList)1 PeriodService (com.axelor.apps.base.service.PeriodService)1 PublicHolidayService (com.axelor.apps.base.service.publicHoliday.PublicHolidayService)1 WeeklyPlanningService (com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService)1 HRConfig (com.axelor.apps.hr.db.HRConfig)1