Search in sources :

Example 1 with KilometricAllowParam

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

the class ExpenseServiceImpl method getListOfKilometricAllowParamVehicleFilter.

@Override
public List<KilometricAllowParam> getListOfKilometricAllowParamVehicleFilter(ExpenseLine expenseLine, Expense expense) throws AxelorException {
    List<KilometricAllowParam> kilometricAllowParamList = new ArrayList<>();
    if (expense == null) {
        return kilometricAllowParamList;
    }
    if (expense.getId() != null) {
        expense = expenseRepository.find(expense.getId());
    }
    if (expense.getUser() != null && expense.getUser().getEmployee() == null) {
        return kilometricAllowParamList;
    }
    List<EmployeeVehicle> vehicleList = expense.getUser().getEmployee().getEmployeeVehicleList();
    LocalDate expenseDate = expenseLine.getExpenseDate();
    if (expenseDate == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.KILOMETRIC_ALLOWANCE_NO_DATE_SELECTED));
    }
    for (EmployeeVehicle vehicle : vehicleList) {
        if (vehicle.getKilometricAllowParam() == null) {
            break;
        }
        LocalDate startDate = vehicle.getStartDate();
        LocalDate endDate = vehicle.getEndDate();
        if ((startDate == null && (endDate == null || expenseDate.compareTo(endDate) <= 0)) || (endDate == null && (expenseDate.compareTo(startDate) >= 0 || (expenseDate.compareTo(startDate) >= 0 && expenseDate.compareTo(endDate) <= 0)))) {
            kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
        }
    }
    return kilometricAllowParamList;
}
Also used : AxelorException(com.axelor.exception.AxelorException) EmployeeVehicle(com.axelor.apps.hr.db.EmployeeVehicle) ArrayList(java.util.ArrayList) KilometricAllowParam(com.axelor.apps.hr.db.KilometricAllowParam) LocalDate(java.time.LocalDate)

Example 2 with KilometricAllowParam

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

the class ExpenseServiceImpl method getListOfKilometricAllowParamVehicleFilter.

@Override
public List<KilometricAllowParam> getListOfKilometricAllowParamVehicleFilter(ExpenseLine expenseLine) throws AxelorException {
    List<KilometricAllowParam> kilometricAllowParamList = new ArrayList<>();
    Expense expense = expenseLine.getExpense();
    if (expense == null) {
        return kilometricAllowParamList;
    }
    if (expense.getId() != null) {
        expense = expenseRepository.find(expense.getId());
    }
    LocalDate expenseDate = expenseLine.getExpenseDate();
    if (expense.getUser() == null || expense.getUser().getEmployee() == null || expenseDate == null) {
        return kilometricAllowParamList;
    }
    List<EmployeeVehicle> vehicleList = expense.getUser().getEmployee().getEmployeeVehicleList();
    for (EmployeeVehicle vehicle : vehicleList) {
        LocalDate startDate = vehicle.getStartDate();
        LocalDate endDate = vehicle.getEndDate();
        if (startDate == null) {
            if (endDate == null || expenseDate.compareTo(endDate) <= 0) {
                kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
            }
        } else if (endDate == null) {
            if (expenseDate.compareTo(startDate) >= 0) {
                kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
            }
        } else if (expenseDate.compareTo(startDate) >= 0 && expenseDate.compareTo(endDate) <= 0) {
            kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
        }
    }
    return kilometricAllowParamList;
}
Also used : Expense(com.axelor.apps.hr.db.Expense) EmployeeVehicle(com.axelor.apps.hr.db.EmployeeVehicle) ArrayList(java.util.ArrayList) KilometricAllowParam(com.axelor.apps.hr.db.KilometricAllowParam) LocalDate(java.time.LocalDate)

Example 3 with KilometricAllowParam

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

the class ExpenseController method domainOnSelectOnKAP.

public void domainOnSelectOnKAP(ActionRequest request, ActionResponse response) throws AxelorException {
    ExpenseLine expenseLine = request.getContext().asType(ExpenseLine.class);
    if (expenseLine.getExpense() == null) {
        setExpense(request, expenseLine);
    }
    try {
        List<KilometricAllowParam> kilometricAllowParamList = Beans.get(ExpenseService.class).getListOfKilometricAllowParamVehicleFilter(expenseLine);
        response.setAttr("kilometricAllowParam", "domain", "self.id IN (" + StringTool.getIdListString(kilometricAllowParamList) + ")");
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) KilometricAllowParam(com.axelor.apps.hr.db.KilometricAllowParam) AxelorException(com.axelor.exception.AxelorException)

Example 4 with KilometricAllowParam

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

the class ExpenseController method updateKAPOfKilometricAllowance.

public void updateKAPOfKilometricAllowance(ActionRequest request, ActionResponse response) throws AxelorException {
    ExpenseLine expenseLine = request.getContext().asType(ExpenseLine.class);
    if (expenseLine.getExpense() == null) {
        setExpense(request, expenseLine);
    }
    try {
        List<KilometricAllowParam> kilometricAllowParamList = Beans.get(ExpenseService.class).getListOfKilometricAllowParamVehicleFilter(expenseLine);
        if (kilometricAllowParamList == null || kilometricAllowParamList.isEmpty()) {
            response.setAttr("kilometricAllowParam", "domain", "self.id IN (0)");
        } else {
            response.setAttr("kilometricAllowParam", "domain", "self.id IN (" + StringTool.getIdListString(kilometricAllowParamList) + ")");
        }
        KilometricAllowParam currentKilometricAllowParam = expenseLine.getKilometricAllowParam();
        boolean vehicleOk = false;
        if (kilometricAllowParamList != null && kilometricAllowParamList.size() == 1) {
            response.setValue("kilometricAllowParam", kilometricAllowParamList.get(0));
        } else if (kilometricAllowParamList != null) {
            for (KilometricAllowParam kilometricAllowParam : kilometricAllowParamList) {
                if (currentKilometricAllowParam != null && currentKilometricAllowParam.equals(kilometricAllowParam)) {
                    expenseLine.setKilometricAllowParam(kilometricAllowParam);
                    vehicleOk = true;
                    break;
                }
            }
            if (!vehicleOk) {
                response.setValue("kilometricAllowParam", null);
            } else {
                response.setValue("kilometricAllowParam", expenseLine.getKilometricAllowParam());
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) KilometricAllowParam(com.axelor.apps.hr.db.KilometricAllowParam) AxelorException(com.axelor.exception.AxelorException)

Aggregations

KilometricAllowParam (com.axelor.apps.hr.db.KilometricAllowParam)4 AxelorException (com.axelor.exception.AxelorException)3 EmployeeVehicle (com.axelor.apps.hr.db.EmployeeVehicle)2 ExpenseLine (com.axelor.apps.hr.db.ExpenseLine)2 ExpenseService (com.axelor.apps.hr.service.expense.ExpenseService)2 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 Expense (com.axelor.apps.hr.db.Expense)1