Search in sources :

Example 1 with Expense

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());
    }
}
Also used : Expense(com.axelor.apps.hr.db.Expense) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine)

Example 2 with Expense

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);
    }
}
Also used : Expense(com.axelor.apps.hr.db.Expense) Product(com.axelor.apps.base.db.Product) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) AxelorException(com.axelor.exception.AxelorException)

Example 3 with Expense

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);
    }
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) Expense(com.axelor.apps.hr.db.Expense) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) AxelorException(com.axelor.exception.AxelorException)

Example 4 with Expense

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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Expense(com.axelor.apps.hr.db.Expense) ArrayList(java.util.ArrayList) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine)

Example 5 with Expense

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);
}
Also used : Expense(com.axelor.apps.hr.db.Expense)

Aggregations

Expense (com.axelor.apps.hr.db.Expense)27 AxelorException (com.axelor.exception.AxelorException)14 ExpenseService (com.axelor.apps.hr.service.expense.ExpenseService)12 ExpenseLine (com.axelor.apps.hr.db.ExpenseLine)7 Transactional (com.google.inject.persist.Transactional)7 ExpenseRepository (com.axelor.apps.hr.db.repo.ExpenseRepository)6 BigDecimal (java.math.BigDecimal)5 MessageServiceBaseImpl (com.axelor.apps.base.service.message.MessageServiceBaseImpl)4 IExceptionMessage (com.axelor.apps.hr.exception.IExceptionMessage)4 Message (com.axelor.apps.message.db.Message)4 User (com.axelor.auth.db.User)4 ArrayList (java.util.ArrayList)4 Product (com.axelor.apps.base.db.Product)3 Employee (com.axelor.apps.hr.db.Employee)3 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)2 Company (com.axelor.apps.base.db.Company)2 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)1 Move (com.axelor.apps.account.db.Move)1 BankDetails (com.axelor.apps.base.db.BankDetails)1 Period (com.axelor.apps.base.db.Period)1