Search in sources :

Example 1 with ExpenseService

use of com.axelor.apps.hr.service.expense.ExpenseService 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 2 with ExpenseService

use of com.axelor.apps.hr.service.expense.ExpenseService 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 ExpenseService

use of com.axelor.apps.hr.service.expense.ExpenseService 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 4 with ExpenseService

use of com.axelor.apps.hr.service.expense.ExpenseService 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 5 with ExpenseService

use of com.axelor.apps.hr.service.expense.ExpenseService 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)

Aggregations

Expense (com.axelor.apps.hr.db.Expense)8 ExpenseService (com.axelor.apps.hr.service.expense.ExpenseService)8 AxelorException (com.axelor.exception.AxelorException)7 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 ExpenseLine (com.axelor.apps.hr.db.ExpenseLine)3 Product (com.axelor.apps.base.db.Product)2 ExpenseRepository (com.axelor.apps.hr.db.repo.ExpenseRepository)2 User (com.axelor.auth.db.User)2 Transactional (com.google.inject.persist.Transactional)2 BigDecimal (java.math.BigDecimal)2 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)1 Employee (com.axelor.apps.hr.db.Employee)1 HRConfig (com.axelor.apps.hr.db.HRConfig)1 KilometricAllowParamRepository (com.axelor.apps.hr.db.repo.KilometricAllowParamRepository)1 HRConfigService (com.axelor.apps.hr.service.config.HRConfigService)1 Project (com.axelor.apps.project.db.Project)1 ProjectRepository (com.axelor.apps.project.db.repo.ProjectRepository)1 MetaFiles (com.axelor.meta.MetaFiles)1