Search in sources :

Example 21 with Employee

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

the class LeaveServiceImpl method manageValidateLeaves.

@Override
@Transactional(rollbackOn = { Exception.class })
public void manageValidateLeaves(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.setQuantity(leaveLine.getQuantity().subtract(leave.getDuration()));
        if (leaveLine.getQuantity().signum() == -1 && !employee.getNegativeValueLeave()) {
            throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_ALLOW_NEGATIVE_VALUE_EMPLOYEE), employee.getName());
        }
        if (leaveLine.getQuantity().signum() == -1 && !leave.getLeaveReason().getAllowNegativeValue()) {
            throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_ALLOW_NEGATIVE_VALUE_REASON), leave.getLeaveReason().getName());
        }
        leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().subtract(leave.getDuration()));
        leaveLine.setDaysValidated(leaveLine.getDaysValidated().add(leave.getDuration()));
    } else {
        leaveLine.setQuantity(leaveLine.getQuantity().add(leave.getDuration()));
        leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().add(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 22 with Employee

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

the class HumanResourceMobileController method insertLeave.

/*
   * 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:insertLeave
   * Content-Type: application/json
   *
   * URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave
   * fields: leaveReason, fromDateT, startOn, toDateT, endOn, comment
   *
   * payload:
   * { "data": {
   * 		"action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave",
   * 		"leaveReason": 10,
   * 		"fromDateT": "2018-02-22T10:30:00",
   * 		"startOn": 1,
   * 		"toDateT": "2018-02-24T:19:30:00",
   *	 	"endOn": 1,
   * 		"comment": "no"
   * } }
   */
@Transactional(rollbackOn = { Exception.class })
public void insertLeave(ActionRequest request, ActionResponse response) throws AxelorException {
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    User user = AuthUtils.getUser();
    Map<String, Object> requestData = request.getData();
    LeaveReason leaveReason = Beans.get(LeaveReasonRepository.class).find(Long.valueOf(requestData.get("leaveReason").toString()));
    Employee employee = user.getEmployee();
    if (employee == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), user.getName());
    }
    if (leaveReason != null) {
        LeaveRequest leave = new LeaveRequest();
        leave.setUser(user);
        Company company = null;
        if (employee.getMainEmploymentContract() != null) {
            company = employee.getMainEmploymentContract().getPayCompany();
        }
        leave.setCompany(company);
        LeaveLine leaveLine = Beans.get(LeaveLineRepository.class).all().filter("self.employee = ?1 AND self.leaveReason = ?2", employee, leaveReason).fetchOne();
        if (leaveLine == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_LINE), employee.getName(), leaveReason.getName());
        }
        leave.setLeaveReason(leaveReason);
        leave.setRequestDate(appBaseService.getTodayDate(company));
        if (requestData.get("fromDateT") != null) {
            leave.setFromDateT(LocalDateTime.parse(requestData.get("fromDateT").toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        }
        leave.setStartOnSelect(new Integer(requestData.get("startOn").toString()));
        if (requestData.get("toDateT") != null) {
            leave.setToDateT(LocalDateTime.parse(requestData.get("toDateT").toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        }
        leave.setEndOnSelect(new Integer(requestData.get("endOn").toString()));
        leave.setDuration(Beans.get(LeaveService.class).computeDuration(leave));
        leave.setStatusSelect(LeaveRequestRepository.STATUS_AWAITING_VALIDATION);
        if (requestData.get("comments") != null) {
            leave.setComments(requestData.get("comments").toString());
        }
        leave = Beans.get(LeaveRequestRepository.class).save(leave);
        response.setTotal(1);
        response.setValue("id", leave.getId());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) LeaveReasonRepository(com.axelor.apps.hr.db.repo.LeaveReasonRepository) Company(com.axelor.apps.base.db.Company) User(com.axelor.auth.db.User) LeaveReason(com.axelor.apps.hr.db.LeaveReason) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) Employee(com.axelor.apps.hr.db.Employee) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) LeaveLine(com.axelor.apps.hr.db.LeaveLine) LeaveLineRepository(com.axelor.apps.hr.db.repo.LeaveLineRepository) Transactional(com.google.inject.persist.Transactional)

Example 23 with Employee

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

the class BatchLeaveManagement method generateLeaveManagementLines.

public void generateLeaveManagementLines(List<Employee> employeeList) {
    for (Employee employee : employeeList.stream().filter(Objects::nonNull).collect(Collectors.toList())) {
        employee = employeeRepository.find(employee.getId());
        if (EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
            continue;
        }
        try {
            createLeaveManagement(employee);
        } catch (AxelorException e) {
            TraceBackService.trace(e, ExceptionOriginRepository.LEAVE_MANAGEMENT, batch.getId());
            incrementAnomaly();
            if (e.getCategory() == TraceBackRepository.CATEGORY_NO_VALUE) {
                noValueAnomaly++;
            }
            if (e.getCategory() == TraceBackRepository.CATEGORY_CONFIGURATION_ERROR) {
                confAnomaly++;
            }
        } finally {
            total++;
            JPA.clear();
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee)

Example 24 with Employee

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

the class BatchPayrollPreparationGeneration method generatePayrollPreparations.

public void generatePayrollPreparations(List<Employee> employeeList) {
    for (Employee employee : employeeList.stream().filter(Objects::nonNull).collect(Collectors.toList())) {
        employee = employeeRepository.find(employee.getId());
        if (EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
            continue;
        }
        try {
            hrBatch = hrBatchRepository.find(batch.getHrBatch().getId());
            if (hrBatch.getCompany() != null) {
                company = companyRepository.find(hrBatch.getCompany().getId());
            }
            if (employee.getMainEmploymentContract() != null && employee.getMainEmploymentContract().getStatus() != EmploymentContractRepository.STATUS_CLOSED) {
                createPayrollPreparation(employee);
            }
        } catch (AxelorException e) {
            TraceBackService.trace(e, ExceptionOriginRepository.LEAVE_MANAGEMENT, batch.getId());
            incrementAnomaly();
            if (e.getCategory() == TraceBackRepository.CATEGORY_NO_UNIQUE_KEY) {
                duplicateAnomaly++;
            } else if (e.getCategory() == TraceBackRepository.CATEGORY_CONFIGURATION_ERROR) {
                configurationAnomaly++;
            }
        } finally {
            total++;
            JPA.clear();
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee)

Example 25 with Employee

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

the class BatchSeniorityLeaveManagement method generateLeaveManagementLines.

public void generateLeaveManagementLines(List<Employee> employeeList) {
    for (Employee employee : employeeList.stream().filter(Objects::nonNull).collect(Collectors.toList())) {
        employee = employeeRepository.find(employee.getId());
        if (EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
            continue;
        }
        try {
            createLeaveManagement(employee);
        } catch (AxelorException e) {
            TraceBackService.trace(e, ExceptionOriginRepository.LEAVE_MANAGEMENT, batch.getId());
            incrementAnomaly();
            if (e.getCategory() == TraceBackRepository.CATEGORY_NO_VALUE) {
                noValueAnomaly++;
            }
            if (e.getCategory() == TraceBackRepository.CATEGORY_CONFIGURATION_ERROR) {
                confAnomaly++;
            }
        } finally {
            total++;
            JPA.clear();
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee)

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