Search in sources :

Example 1 with ExpenseLine

use of com.axelor.apps.hr.db.ExpenseLine 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 ExpenseLine

use of com.axelor.apps.hr.db.ExpenseLine 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 3 with ExpenseLine

use of com.axelor.apps.hr.db.ExpenseLine 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);
    }
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) AppHumanResourceService(com.axelor.apps.hr.service.app.AppHumanResourceService) Expense(com.axelor.apps.hr.db.Expense) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) KilometricService(com.axelor.apps.hr.service.KilometricService) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 4 with ExpenseLine

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

the class ExpenseController method createAnalyticDistributionWithTemplate.

public void createAnalyticDistributionWithTemplate(ActionRequest request, ActionResponse response) throws AxelorException {
    ExpenseLine expenseLine = request.getContext().asType(ExpenseLine.class);
    expenseLine = Beans.get(ExpenseService.class).createAnalyticDistributionWithTemplate(expenseLine);
    response.setValue("analyticMoveLineList", expenseLine.getAnalyticMoveLineList());
}
Also used : ExpenseLine(com.axelor.apps.hr.db.ExpenseLine)

Example 5 with ExpenseLine

use of com.axelor.apps.hr.db.ExpenseLine 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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) EmployeeAdvanceService(com.axelor.apps.hr.service.EmployeeAdvanceService) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) KilometricService(com.axelor.apps.hr.service.KilometricService) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Aggregations

ExpenseLine (com.axelor.apps.hr.db.ExpenseLine)21 AxelorException (com.axelor.exception.AxelorException)9 Expense (com.axelor.apps.hr.db.Expense)7 Transactional (com.google.inject.persist.Transactional)7 BigDecimal (java.math.BigDecimal)7 ExpenseService (com.axelor.apps.hr.service.expense.ExpenseService)6 ArrayList (java.util.ArrayList)5 Employee (com.axelor.apps.hr.db.Employee)4 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)3 Product (com.axelor.apps.base.db.Product)3 User (com.axelor.auth.db.User)3 KilometricAllowParam (com.axelor.apps.hr.db.KilometricAllowParam)2 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)2 ExpenseLineRepository (com.axelor.apps.hr.db.repo.ExpenseLineRepository)2 ExpenseRepository (com.axelor.apps.hr.db.repo.ExpenseRepository)2 KilometricService (com.axelor.apps.hr.service.KilometricService)2 Project (com.axelor.apps.project.db.Project)2 ProjectTask (com.axelor.apps.project.db.ProjectTask)2 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)2 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)2