Search in sources :

Example 6 with Expense

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

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

the class ExpenseController method refuse.

// refusing expense and sending mail to applicant
public void refuse(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.refuse(expense);
        Message message = expenseService.sendRefusalEmail(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 8 with Expense

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

the class ExpenseController method send.

// sending expense and sending mail to manager
public void send(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.confirm(expense);
        Message message = expenseService.sendConfirmationEmail(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 9 with Expense

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

the class ExpenseController method valid.

// validating expense and sending mail to applicant
public void valid(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.validate(expense);
        Message message = expenseService.sendValidationEmail(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 10 with Expense

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

the class BankOrderServiceHRImpl method validatePayment.

@Override
@Transactional(rollbackOn = { Exception.class })
public void validatePayment(BankOrder bankOrder) throws AxelorException {
    super.validatePayment(bankOrder);
    if (!Beans.get(AppService.class).isApp("employee")) {
        return;
    }
    List<Expense> expenseList = Beans.get(ExpenseRepository.class).all().filter("self.bankOrder.id = ?", bankOrder.getId()).fetch();
    for (Expense expense : expenseList) {
        if (expense != null && expense.getStatusSelect() != ExpenseRepository.STATUS_REIMBURSED) {
            expense.setStatusSelect(ExpenseRepository.STATUS_REIMBURSED);
            expense.setPaymentStatusSelect(InvoicePaymentRepository.STATUS_VALIDATED);
            expenseService.createMoveForExpensePayment(expense);
        }
    }
}
Also used : Expense(com.axelor.apps.hr.db.Expense) ExpenseRepository(com.axelor.apps.hr.db.repo.ExpenseRepository) Transactional(com.google.inject.persist.Transactional)

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