Search in sources :

Example 11 with LeaveRequest

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

the class LeaveController method editLeave.

public void editLeave(ActionRequest request, ActionResponse response) {
    try {
        User user = AuthUtils.getUser();
        List<LeaveRequest> leaveList = Beans.get(LeaveRequestRepository.class).all().filter("self.user = ?1 AND self.company = ?2 AND self.statusSelect = 1", user, user.getActiveCompany()).fetch();
        if (leaveList.isEmpty()) {
            response.setView(ActionView.define(I18n.get("LeaveRequest")).model(LeaveRequest.class.getName()).add("form", "leave-request-form").map());
        } else if (leaveList.size() == 1) {
            response.setView(ActionView.define(I18n.get("LeaveRequest")).model(LeaveRequest.class.getName()).add("form", "leave-request-form").param("forceEdit", "true").context("_showRecord", String.valueOf(leaveList.get(0).getId())).map());
        } else {
            response.setView(ActionView.define(I18n.get("LeaveRequest")).model(Wizard.class.getName()).add("form", "popup-leave-request-form").param("forceEdit", "true").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("forceEdit", "true").param("popup-save", "false").map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : User(com.axelor.auth.db.User) LeaveRequestRepository(com.axelor.apps.hr.db.repo.LeaveRequestRepository) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) Wizard(com.axelor.apps.base.db.Wizard) AxelorException(com.axelor.exception.AxelorException)

Example 12 with LeaveRequest

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

the class LeaveController method leaveReasonToJustify.

/* Count Tags displayed on the menu items */
@Transactional
public void leaveReasonToJustify(ActionRequest request, ActionResponse response) {
    try {
        LeaveRequest leave = request.getContext().asType(LeaveRequest.class);
        Boolean leaveToJustify = leave.getToJustifyLeaveReason();
        LeaveLine leaveLine = null;
        if (!leaveToJustify) {
            return;
        }
        Company company = leave.getCompany();
        if (leave.getUser() == null) {
            return;
        }
        if (company == null) {
            company = leave.getUser().getActiveCompany();
        }
        if (company == null) {
            return;
        }
        Beans.get(HRConfigService.class).getLeaveReason(company.getHrConfig());
        Employee employee = leave.getUser().getEmployee();
        LeaveReason leaveReason = Beans.get(LeaveReasonRepository.class).find(company.getHrConfig().getToJustifyLeaveReason().getId());
        if (employee != null) {
            employee = Beans.get(EmployeeRepository.class).find(leave.getUser().getEmployee().getId());
            leaveLine = Beans.get(LeaveService.class).addLeaveReasonOrCreateIt(employee, leaveReason);
            response.setValue("leaveLine", leaveLine);
        }
    } catch (AxelorException e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) LeaveReasonRepository(com.axelor.apps.hr.db.repo.LeaveReasonRepository) Employee(com.axelor.apps.hr.db.Employee) LeaveLine(com.axelor.apps.hr.db.LeaveLine) HRConfigService(com.axelor.apps.hr.service.config.HRConfigService) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) LeaveReason(com.axelor.apps.hr.db.LeaveReason) Transactional(com.google.inject.persist.Transactional)

Example 13 with LeaveRequest

use of com.axelor.apps.hr.db.LeaveRequest 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)

Example 14 with LeaveRequest

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

the class EmployeeServiceImpl method getDaysWorkedInPeriod.

@Override
public BigDecimal getDaysWorkedInPeriod(Employee employee, LocalDate fromDate, LocalDate toDate) throws AxelorException {
    BigDecimal daysWorks = getDaysWorksInPeriod(employee, fromDate, toDate);
    BigDecimal daysLeave = BigDecimal.ZERO;
    List<LeaveRequest> leaveRequestList = Beans.get(LeaveRequestRepository.class).all().filter("self.user = ?1 AND self.duration >= 1 AND self.statusSelect = ?2 AND (self.fromDateT BETWEEN ?3 AND ?4 OR self.toDateT BETWEEN ?3 AND ?4 OR ?3 BETWEEN self.fromDateT AND self.toDateT OR ?4 BETWEEN self.fromDateT AND self.toDateT)", employee.getUser(), LeaveRequestRepository.STATUS_VALIDATED, fromDate, toDate).fetch();
    for (LeaveRequest leaveRequest : leaveRequestList) {
        daysLeave = daysLeave.add(Beans.get(LeaveService.class).computeDuration(leaveRequest, fromDate, toDate));
    }
    return daysWorks.subtract(daysLeave);
}
Also used : LeaveService(com.axelor.apps.hr.service.leave.LeaveService) LeaveRequestRepository(com.axelor.apps.hr.db.repo.LeaveRequestRepository) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) BigDecimal(java.math.BigDecimal)

Aggregations

LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)14 AxelorException (com.axelor.exception.AxelorException)10 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)6 MessageServiceBaseImpl (com.axelor.apps.base.service.message.MessageServiceBaseImpl)4 Employee (com.axelor.apps.hr.db.Employee)4 IExceptionMessage (com.axelor.apps.hr.exception.IExceptionMessage)4 Message (com.axelor.apps.message.db.Message)4 LeaveLine (com.axelor.apps.hr.db.LeaveLine)3 User (com.axelor.auth.db.User)3 BigDecimal (java.math.BigDecimal)3 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 Company (com.axelor.apps.base.db.Company)2 LeaveReason (com.axelor.apps.hr.db.LeaveReason)2 LeaveLineRepository (com.axelor.apps.hr.db.repo.LeaveLineRepository)2 LeaveReasonRepository (com.axelor.apps.hr.db.repo.LeaveReasonRepository)2 LeaveRequestRepository (com.axelor.apps.hr.db.repo.LeaveRequestRepository)2 Transactional (com.google.inject.persist.Transactional)2 AppTimesheet (com.axelor.apps.base.db.AppTimesheet)1 EventsPlanning (com.axelor.apps.base.db.EventsPlanning)1