Search in sources :

Example 11 with Expense

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

the class BatchCreditTransferExpensePaymentHR method processExpenses.

/**
 * Process expenses that need to be paid.
 *
 * @return
 */
protected List<Expense> processExpenses() {
    List<Expense> doneList = new ArrayList<>();
    // Can't pass an empty collection to the query
    List<Long> anomalyList = Lists.newArrayList(0L);
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    boolean manageMultiBanks = appAccountService.getAppBase().getManageMultiBanks();
    String filter = "self.ventilated = true " + "AND self.paymentStatusSelect = :paymentStatusSelect " + "AND self.company = :company " + "AND self.user.partner.outPaymentMode = :paymentMode " + "AND self.id NOT IN (:anomalyList)";
    if (manageMultiBanks) {
        filter += " AND self.bankDetails IN (:bankDetailsSet)";
    }
    Query<Expense> query = expenseRepo.all().filter(filter).bind("paymentStatusSelect", InvoicePaymentRepository.STATUS_DRAFT).bind("company", accountingBatch.getCompany()).bind("paymentMode", accountingBatch.getPaymentMode()).bind("anomalyList", anomalyList);
    if (manageMultiBanks) {
        Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
        if (accountingBatch.getIncludeOtherBankAccounts()) {
            bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
        }
        query.bind("bankDetailsSet", bankDetailsSet);
    }
    for (List<Expense> expenseList; !(expenseList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
        for (Expense expense : expenseList) {
            try {
                addPayment(expense, accountingBatch.getBankDetails());
                doneList.add(expense);
                incrementDone();
            } catch (Exception ex) {
                incrementAnomaly();
                anomalyList.add(expense.getId());
                query.bind("anomalyList", anomalyList);
                TraceBackService.trace(ex, ExceptionOriginRepository.CREDIT_TRANSFER, batch.getId());
                ex.printStackTrace();
                log.error(String.format("Credit transfer batch for expense payment: anomaly for expense %s", expense.getExpenseSeq()));
                break;
            }
        }
    }
    return doneList;
}
Also used : Expense(com.axelor.apps.hr.db.Expense) BankDetails(com.axelor.apps.base.db.BankDetails) ArrayList(java.util.ArrayList) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) AxelorException(com.axelor.exception.AxelorException)

Example 12 with Expense

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

the class BatchCreditTransferExpensePaymentHR method mergeBankOrders.

/**
 * Merge bank orders.
 *
 * @param doneList
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
protected void mergeBankOrders(List<Expense> doneList) throws AxelorException {
    List<Expense> expenseList = new ArrayList<>();
    List<BankOrder> bankOrderList = new ArrayList<>();
    for (Expense expense : doneList) {
        BankOrder bankOrder = expense.getBankOrder();
        if (bankOrder != null) {
            expenseList.add(expense);
            bankOrderList.add(bankOrder);
        }
    }
    if (bankOrderList.size() > 1) {
        BankOrder mergedBankOrder = bankOrderMergeService.mergeBankOrders(bankOrderList);
        for (Expense expense : expenseList) {
            expense.setBankOrder(mergedBankOrder);
        }
    }
}
Also used : Expense(com.axelor.apps.hr.db.Expense) ArrayList(java.util.ArrayList) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Transactional(com.google.inject.persist.Transactional)

Example 13 with Expense

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

the class ExpenseServiceImpl method getListOfKilometricAllowParamVehicleFilter.

@Override
public List<KilometricAllowParam> getListOfKilometricAllowParamVehicleFilter(ExpenseLine expenseLine) throws AxelorException {
    List<KilometricAllowParam> kilometricAllowParamList = new ArrayList<>();
    Expense expense = expenseLine.getExpense();
    if (expense == null) {
        return kilometricAllowParamList;
    }
    if (expense.getId() != null) {
        expense = expenseRepository.find(expense.getId());
    }
    LocalDate expenseDate = expenseLine.getExpenseDate();
    if (expense.getUser() == null || expense.getUser().getEmployee() == null || expenseDate == null) {
        return kilometricAllowParamList;
    }
    List<EmployeeVehicle> vehicleList = expense.getUser().getEmployee().getEmployeeVehicleList();
    for (EmployeeVehicle vehicle : vehicleList) {
        LocalDate startDate = vehicle.getStartDate();
        LocalDate endDate = vehicle.getEndDate();
        if (startDate == null) {
            if (endDate == null || expenseDate.compareTo(endDate) <= 0) {
                kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
            }
        } else if (endDate == null) {
            if (expenseDate.compareTo(startDate) >= 0) {
                kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
            }
        } else if (expenseDate.compareTo(startDate) >= 0 && expenseDate.compareTo(endDate) <= 0) {
            kilometricAllowParamList.add(vehicle.getKilometricAllowParam());
        }
    }
    return kilometricAllowParamList;
}
Also used : Expense(com.axelor.apps.hr.db.Expense) EmployeeVehicle(com.axelor.apps.hr.db.EmployeeVehicle) ArrayList(java.util.ArrayList) KilometricAllowParam(com.axelor.apps.hr.db.KilometricAllowParam) LocalDate(java.time.LocalDate)

Example 14 with Expense

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

the class ExpenseServiceImpl method getOrCreateExpense.

@Override
public Expense getOrCreateExpense(User user) {
    Expense expense = Beans.get(ExpenseRepository.class).all().filter("self.statusSelect = ?1 AND self.user.id = ?2", ExpenseRepository.STATUS_DRAFT, user.getId()).order("-id").fetchOne();
    if (expense == null) {
        expense = new Expense();
        expense.setUser(user);
        Company company = null;
        if (user.getEmployee() != null && user.getEmployee().getMainEmploymentContract() != null) {
            company = user.getEmployee().getMainEmploymentContract().getPayCompany();
        } else {
            company = user.getActiveCompany();
        }
        Period period = Beans.get(PeriodRepository.class).all().filter("self.fromDate <= ?1 AND self.toDate >= ?1 AND self.allowExpenseCreation = true AND self.year.company = ?2 AND self.year.typeSelect = ?3", Beans.get(AppBaseService.class).getTodayDate(company), company, YearBaseRepository.STATUS_OPENED).fetchOne();
        expense.setCompany(company);
        expense.setPeriod(period);
        expense.setStatusSelect(ExpenseRepository.STATUS_DRAFT);
    }
    return expense;
}
Also used : Company(com.axelor.apps.base.db.Company) Expense(com.axelor.apps.hr.db.Expense) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) PeriodRepository(com.axelor.apps.base.db.repo.PeriodRepository) Period(com.axelor.apps.base.db.Period)

Example 15 with Expense

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

the class ExpenseController method printExpense.

public void printExpense(ActionRequest request, ActionResponse response) throws AxelorException {
    Expense expense = request.getContext().asType(Expense.class);
    String name = I18n.get("Expense") + " " + expense.getFullName().replace("/", "-");
    String fileLink = ReportFactory.createReport(IReport.EXPENSE, name).addParam("ExpenseId", expense.getId()).addParam("Timezone", expense.getCompany() != null ? expense.getCompany().getTimezone() : null).addParam("Locale", ReportSettings.getPrintingLocale(null)).toAttach(expense).generate().getFileLink();
    logger.debug("Printing {}", name);
    response.setView(ActionView.define(name).add("html", fileLink).map());
}
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