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;
}
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;
}
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);
}
}
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);
}
}
Aggregations