Search in sources :

Example 11 with LeaveLine

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

the class LeaveServiceImpl method manageSentLeaves.

@Override
@Transactional(rollbackOn = { Exception.class })
public void manageSentLeaves(LeaveRequest leave) throws AxelorException {
    Employee employee = leave.getUser().getEmployee();
    if (employee == null) {
        throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), leave.getUser().getName());
    }
    LeaveLine leaveLine = leaveLineRepo.all().filter("self.employee = ?1 AND self.leaveReason = ?2", employee, leave.getLeaveReason()).fetchOne();
    if (leaveLine == null) {
        throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_LINE), employee.getName(), leave.getLeaveReason().getName());
    }
    if (leave.getInjectConsumeSelect() == LeaveRequestRepository.SELECT_CONSUME) {
        leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().add(leave.getDuration()));
    } else {
        leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().subtract(leave.getDuration()));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) LeaveLine(com.axelor.apps.hr.db.LeaveLine) Transactional(com.google.inject.persist.Transactional)

Example 12 with LeaveLine

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

the class LeaveServiceImpl method validate.

@Transactional(rollbackOn = { Exception.class })
@Override
public void validate(LeaveRequest leaveRequest) throws AxelorException {
    if (leaveRequest.getLeaveReason().getUnitSelect() == LeaveReasonRepository.UNIT_SELECT_DAYS) {
        isOverlapped(leaveRequest);
    }
    if (leaveRequest.getLeaveReason().getManageAccumulation()) {
        manageValidateLeaves(leaveRequest);
    }
    leaveRequest.setStatusSelect(LeaveRequestRepository.STATUS_VALIDATED);
    leaveRequest.setValidatedBy(AuthUtils.getUser());
    leaveRequest.setValidationDate(appBaseService.getTodayDate(leaveRequest.getCompany()));
    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) {
        leaveRequest.setQuantityBeforeValidation(leaveLine.getQuantity());
    }
    leaveRequestRepo.save(leaveRequest);
    createEvents(leaveRequest);
}
Also used : LeaveLine(com.axelor.apps.hr.db.LeaveLine) LeaveLineRepository(com.axelor.apps.hr.db.repo.LeaveLineRepository) Transactional(com.google.inject.persist.Transactional)

Example 13 with LeaveLine

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

the class HumanResourceMobileController method getLeaveReason.

/*
   * This method is used in mobile application.
   * It was in LeaveServiceImpl
   * @param request
   * @param response
   *
   * POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:getLeaveReason
   * Content-Type: application/json
   *
   * URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:getLeaveReason
   * fields: no field
   *
   * payload:
   * { "data": {
   * 		"action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:getLeaveReason"
   * } }
   */
@Transactional
public void getLeaveReason(ActionRequest request, ActionResponse response) {
    try {
        User user = AuthUtils.getUser();
        List<Map<String, String>> dataList = new ArrayList<>();
        if (user == null || user.getEmployee() == null) {
            List<LeaveReason> leaveReasonList = Beans.get(LeaveReasonRepository.class).all().fetch();
            for (LeaveReason leaveReason : leaveReasonList) {
                if (leaveReason.getUnitSelect() == LeaveReasonRepository.UNIT_SELECT_DAYS) {
                    Map<String, String> map = new HashMap<>();
                    map.put("name", leaveReason.getName());
                    map.put("id", leaveReason.getId().toString());
                    dataList.add(map);
                }
            }
        } else if (user.getEmployee() != null) {
            List<LeaveLine> leaveLineList = Beans.get(LeaveLineRepository.class).all().filter("self.employee = ?1", user.getEmployee()).order("name").fetch();
            String tmpName = "";
            for (LeaveLine leaveLine : leaveLineList) {
                String name = leaveLine.getName();
                if (tmpName != name) {
                    Map<String, String> map = new HashMap<>();
                    map.put("name", leaveLine.getName());
                    map.put("id", leaveLine.getLeaveReason().getId().toString());
                    map.put("quantity", leaveLine.getQuantity().toString());
                    dataList.add(map);
                }
                tmpName = name;
            }
        }
        response.setData(dataList);
        response.setTotal(dataList.size());
    } catch (Exception e) {
        response.setStatus(-1);
        response.setError(e.getMessage());
    }
}
Also used : User(com.axelor.auth.db.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LeaveReason(com.axelor.apps.hr.db.LeaveReason) AxelorException(com.axelor.exception.AxelorException) LeaveLine(com.axelor.apps.hr.db.LeaveLine) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LeaveLineRepository(com.axelor.apps.hr.db.repo.LeaveLineRepository) Transactional(com.google.inject.persist.Transactional)

Example 14 with LeaveLine

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

the class BatchLeaveManagement method createLeaveManagement.

@Transactional(rollbackOn = { Exception.class })
public void createLeaveManagement(Employee employee) throws AxelorException {
    if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
        return;
    }
    batch = batchRepo.find(batch.getId());
    LeaveLine leaveLine = null;
    LeaveReason leaveReason = batch.getHrBatch().getLeaveReason();
    leaveLine = leaveServiceProvider.get().addLeaveReasonOrCreateIt(employee, leaveReason);
    BigDecimal dayNumber = batch.getHrBatch().getUseWeeklyPlanningCoef() ? batch.getHrBatch().getDayNumber().multiply(employee.getWeeklyPlanning().getLeaveCoef()) : batch.getHrBatch().getDayNumber();
    dayNumber = dayNumber.subtract(new BigDecimal(publicHolidayService.getImposedDayNumber(employee, batch.getHrBatch().getStartDate(), batch.getHrBatch().getEndDate())));
    LeaveManagement leaveManagement = leaveManagementService.createLeaveManagement(leaveLine, AuthUtils.getUser(), batch.getHrBatch().getComments(), null, batch.getHrBatch().getStartDate(), batch.getHrBatch().getEndDate(), dayNumber);
    BigDecimal qty = leaveLine.getQuantity().add(dayNumber);
    BigDecimal totalQty = leaveLine.getTotalQuantity().add(dayNumber);
    try {
        int integer = LeaveLine.class.getDeclaredField("quantity").getAnnotation(Digits.class).integer();
        BigDecimal limit = new BigDecimal((long) Math.pow(10, integer));
        if (qty.compareTo(limit) >= 0 || totalQty.compareTo(limit) >= 0) {
            throw new AxelorException(employee, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.BATCH_LEAVE_MANAGEMENT_QTY_OUT_OF_BOUNDS), limit.longValue());
        }
    } catch (NoSuchFieldException | SecurityException e) {
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
    leaveLine.setQuantity(qty.setScale(4, RoundingMode.HALF_UP));
    leaveLine.setTotalQuantity(totalQty.setScale(4, RoundingMode.HALF_UP));
    leaveManagementRepository.save(leaveManagement);
    leaveLineRepository.save(leaveLine);
    updateEmployee(employee);
}
Also used : AxelorException(com.axelor.exception.AxelorException) LeaveManagement(com.axelor.apps.hr.db.LeaveManagement) Digits(javax.validation.constraints.Digits) LeaveLine(com.axelor.apps.hr.db.LeaveLine) LeaveReason(com.axelor.apps.hr.db.LeaveReason) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Aggregations

LeaveLine (com.axelor.apps.hr.db.LeaveLine)14 AxelorException (com.axelor.exception.AxelorException)10 Transactional (com.google.inject.persist.Transactional)10 Employee (com.axelor.apps.hr.db.Employee)6 LeaveLineRepository (com.axelor.apps.hr.db.repo.LeaveLineRepository)5 LeaveReason (com.axelor.apps.hr.db.LeaveReason)4 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)3 BigDecimal (java.math.BigDecimal)3 Company (com.axelor.apps.base.db.Company)2 LeaveManagement (com.axelor.apps.hr.db.LeaveManagement)2 LeaveReasonRepository (com.axelor.apps.hr.db.repo.LeaveReasonRepository)2 User (com.axelor.auth.db.User)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 MessageServiceBaseImpl (com.axelor.apps.base.service.message.MessageServiceBaseImpl)1 EmploymentContract (com.axelor.apps.hr.db.EmploymentContract)1 LeaveManagementBatchRule (com.axelor.apps.hr.db.LeaveManagementBatchRule)1 IExceptionMessage (com.axelor.apps.hr.exception.IExceptionMessage)1 HRConfigService (com.axelor.apps.hr.service.config.HRConfigService)1 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)1 Message (com.axelor.apps.message.db.Message)1