use of com.axelor.apps.hr.service.KilometricService in project axelor-open-suite by axelor.
the class ExpenseController method computeDistanceAndKilometricExpense.
public void computeDistanceAndKilometricExpense(ActionRequest request, ActionResponse response) throws AxelorException {
// Compute distance.
try {
if (!Beans.get(AppHumanResourceService.class).getAppExpense().getComputeDistanceWithWebService()) {
return;
}
Context context = request.getContext();
ExpenseLine expenseLine = context.asType(ExpenseLine.class);
if (Strings.isNullOrEmpty(expenseLine.getFromCity()) || Strings.isNullOrEmpty(expenseLine.getToCity())) {
return;
}
KilometricService kilometricService = Beans.get(KilometricService.class);
BigDecimal distance = kilometricService.computeDistance(expenseLine);
expenseLine.setDistance(distance);
response.setValue("distance", distance);
if (expenseLine.getKilometricAllowParam() == null || expenseLine.getExpenseDate() == null || expenseLine.getKilometricTypeSelect() == 0) {
return;
}
Expense expense = expenseLine.getExpense();
if (expense == null) {
expense = context.getParent().asType(Expense.class);
}
Employee employee = expense.getUser().getEmployee();
if (employee == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), expense.getUser().getName());
}
BigDecimal amount = kilometricService.computeKilometricExpense(expenseLine, employee);
response.setValue("totalAmount", amount);
response.setValue("untaxedAmount", amount);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.service.KilometricService in project axelor-open-suite by axelor.
the class ExpenseServiceImpl method validate.
@Override
@Transactional(rollbackOn = { Exception.class })
public void validate(Expense expense) throws AxelorException {
Employee employee = expense.getUser().getEmployee();
if (employee == null) {
throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), expense.getUser().getFullName());
}
if (expense.getPeriod() == null) {
throw new AxelorException(expense, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.EXPENSE_MISSING_PERIOD));
}
List<ExpenseLine> kilometricExpenseLineList = expense.getKilometricExpenseLineList();
KilometricService kilometricService = Beans.get(KilometricService.class);
if (ObjectUtils.notEmpty(kilometricExpenseLineList)) {
for (ExpenseLine line : kilometricExpenseLineList) {
BigDecimal amount = kilometricService.computeKilometricExpense(line, employee);
line.setTotalAmount(amount);
line.setUntaxedAmount(amount);
kilometricService.updateKilometricLog(line, employee);
}
compute(expense);
}
Beans.get(EmployeeAdvanceService.class).fillExpenseWithAdvances(expense);
expense.setStatusSelect(ExpenseRepository.STATUS_VALIDATED);
expense.setValidatedBy(AuthUtils.getUser());
expense.setValidationDate(appAccountService.getTodayDate(expense.getCompany()));
if (expense.getUser().getPartner() != null) {
PaymentMode paymentMode = expense.getUser().getPartner().getOutPaymentMode();
expense.setPaymentMode(paymentMode);
}
expenseRepository.save(expense);
}
Aggregations