use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method computeAnalyticDistribution.
public void computeAnalyticDistribution(ActionRequest request, ActionResponse response) throws AxelorException {
ExpenseLine expenseLine = request.getContext().asType(ExpenseLine.class);
Expense expense = expenseLine.getExpense();
if (expense == null) {
setExpense(request, expenseLine);
}
if (Beans.get(AppAccountService.class).getAppAccount().getManageAnalyticAccounting()) {
expenseLine = Beans.get(ExpenseService.class).computeAnalyticDistribution(expenseLine);
response.setValue("analyticMoveLineList", expenseLine.getAnalyticMoveLineList());
}
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method fillKilometricExpenseProduct.
public void fillKilometricExpenseProduct(ActionRequest request, ActionResponse response) throws AxelorException {
try {
Expense expense = request.getContext().getParent().asType(Expense.class);
Product expenseProduct = Beans.get(ExpenseService.class).getKilometricExpenseProduct(expense);
logger.debug("Get Kilometric expense product : {}", expenseProduct);
response.setValue("expenseProduct", expenseProduct);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method cancel.
public void cancel(ActionRequest request, ActionResponse response) throws AxelorException {
try {
Expense expense = request.getContext().asType(Expense.class);
expense = Beans.get(ExpenseRepository.class).find(expense.getId());
ExpenseService expenseService = Beans.get(ExpenseService.class);
expenseService.cancel(expense);
Message message = expenseService.sendCancellationEmail(expense);
if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method validateAndCompute.
public void validateAndCompute(ActionRequest request, ActionResponse response) {
Expense expense = request.getContext().asType(Expense.class);
ExpenseService expenseService = Beans.get(ExpenseService.class);
List<Integer> expenseLineListId = new ArrayList<>();
int compt = 0;
for (ExpenseLine expenseLine : expenseService.getExpenseLineList(expense)) {
compt++;
if (expenseLine.getExpenseDate().isAfter(Beans.get(AppBaseService.class).getTodayDate(expense.getCompany()))) {
expenseLineListId.add(compt);
}
}
try {
if (!expenseLineListId.isEmpty()) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get("Date can't be in the future for line(s) : %s"), expenseLineListId.stream().map(id -> id.toString()).collect(Collectors.joining(",")));
}
} catch (AxelorException e) {
TraceBackService.trace(response, e, ResponseMessageType.ERROR);
}
response.setValue("personalExpenseAmount", expenseService.computePersonalExpenseAmount(expense));
response.setValue("advanceAmount", expenseService.computeAdvanceAmount(expense));
if (expense.getKilometricExpenseLineList() != null && !expense.getKilometricExpenseLineList().isEmpty()) {
response.setValue("kilometricExpenseLineList", expense.getKilometricExpenseLineList());
}
compute(request, response);
}
use of com.axelor.apps.hr.db.Expense in project axelor-open-suite by axelor.
the class ExpenseController method compute.
/**
* Called from expense form, on expense lines change. Call {@link ExpenseService#compute(Expense)}
*
* @param request
* @param response
*/
public void compute(ActionRequest request, ActionResponse response) {
Expense expense = request.getContext().asType(Expense.class);
expense = Beans.get(ExpenseService.class).compute(expense);
response.setValues(expense);
}
Aggregations