Search in sources :

Example 16 with Expense

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

the class ExpenseController method editExpense.

public void editExpense(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    Company activeCompany = user.getActiveCompany();
    List<Expense> expenseList = Beans.get(ExpenseRepository.class).all().filter("self.user = ?1 AND self.company = ?2 AND self.statusSelect = 1 AND (self.multipleUsers is false OR self.multipleUsers is null)", user, activeCompany).fetch();
    if (expenseList.isEmpty()) {
        response.setView(ActionView.define(I18n.get("Expense")).model(Expense.class.getName()).add("form", "expense-form").context("_payCompany", Beans.get(UserHrService.class).getPayCompany(user)).map());
    } else if (expenseList.size() == 1) {
        response.setView(ActionView.define(I18n.get("Expense")).model(Expense.class.getName()).add("form", "expense-form").param("forceEdit", "true").context("_showRecord", String.valueOf(expenseList.get(0).getId())).map());
    } else {
        response.setView(ActionView.define(I18n.get("Expense")).model(Wizard.class.getName()).add("form", "popup-expense-form").param("forceEdit", "true").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("forceEdit", "true").param("popup-save", "false").map());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) User(com.axelor.auth.db.User) Expense(com.axelor.apps.hr.db.Expense) ExpenseRepository(com.axelor.apps.hr.db.repo.ExpenseRepository) Wizard(com.axelor.apps.base.db.Wizard)

Example 17 with Expense

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

the class ExpenseController method cancelPayment.

/**
 * Called on clicking cancelPaymentButton, call {@link ExpenseService#cancelPayment(Expense)}.
 *
 * @param request
 * @param response
 */
public void cancelPayment(ActionRequest request, ActionResponse response) {
    Expense expense = request.getContext().asType(Expense.class);
    expense = Beans.get(ExpenseRepository.class).find(expense.getId());
    try {
        Beans.get(ExpenseService.class).cancelPayment(expense);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Expense(com.axelor.apps.hr.db.Expense) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) AxelorException(com.axelor.exception.AxelorException)

Example 18 with Expense

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

the class ExpenseController method computeKilometricExpense.

public void computeKilometricExpense(ActionRequest request, ActionResponse response) throws AxelorException {
    ExpenseLine expenseLine = request.getContext().asType(ExpenseLine.class);
    if (expenseLine.getKilometricAllowParam() == null || expenseLine.getDistance().compareTo(BigDecimal.ZERO) == 0 || expenseLine.getExpenseDate() == null) {
        return;
    }
    String userId;
    String userName;
    if (expenseLine.getExpense() != null) {
        setExpense(request, expenseLine);
    }
    Expense expense = expenseLine.getExpense();
    if (expense != null && expenseLine.getUser() != null) {
        userId = expense.getUser().getId().toString();
        userName = expense.getUser().getFullName();
    } else {
        userId = request.getContext().getParent().asType(Expense.class).getUser().getId().toString();
        userName = request.getContext().getParent().asType(Expense.class).getUser().getFullName();
    }
    Employee employee = Beans.get(EmployeeRepository.class).all().filter("self.user.id = ?1", userId).fetchOne();
    if (employee == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), userName);
    }
    BigDecimal amount = BigDecimal.ZERO;
    try {
        amount = Beans.get(KilometricService.class).computeKilometricExpense(expenseLine, employee);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
    response.setValue("totalAmount", amount);
    response.setValue("untaxedAmount", amount);
}
Also used : EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) Expense(com.axelor.apps.hr.db.Expense) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 19 with Expense

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

the class ExpenseController method addPayment.

public void addPayment(ActionRequest request, ActionResponse response) {
    Expense expense = request.getContext().asType(Expense.class);
    expense = Beans.get(ExpenseRepository.class).find(expense.getId());
    try {
        Beans.get(ExpenseService.class).addPayment(expense);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Expense(com.axelor.apps.hr.db.Expense) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) AxelorException(com.axelor.exception.AxelorException)

Example 20 with Expense

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

the class ExpenseController method updateMoveDateAndPeriod.

public void updateMoveDateAndPeriod(ActionRequest request, ActionResponse response) {
    Expense expense = request.getContext().asType(Expense.class);
    expense = Beans.get(ExpenseService.class).updateMoveDateAndPeriod(expense);
    response.setValue("moveDate", expense.getMoveDate());
    response.setValue("period", expense.getPeriod());
}
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