Search in sources :

Example 61 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class BatchDirectDebitCustomerInvoice method processQuery.

private List<InvoicePayment> processQuery(List<String> filterList, List<Pair<String, Object>> bindingList) {
    List<InvoicePayment> doneList = new ArrayList<>();
    List<Long> anomalyList = Lists.newArrayList(0L);
    filterList.add("self.id NOT IN (:anomalyList)");
    bindingList.add(Pair.of("anomalyList", (Object) anomalyList));
    String filter = Joiner.on(" AND ").join(Lists.transform(filterList, new Function<String, String>() {

        @Override
        public String apply(String input) {
            return String.format("(%s)", input);
        }
    }));
    Query<Invoice> query = Beans.get(InvoiceRepository.class).all().filter(filter);
    for (Pair<String, Object> binding : bindingList) {
        query.bind(binding.getLeft(), binding.getRight());
    }
    Set<Long> treatedSet = new HashSet<>();
    List<Invoice> invoiceList;
    InvoicePaymentCreateService invoicePaymentCreateService = Beans.get(InvoicePaymentCreateService.class);
    BankDetailsRepository bankDetailsRepo = Beans.get(BankDetailsRepository.class);
    BankDetails companyBankDetails = getCompanyBankDetails(batch.getAccountingBatch());
    while (!(invoiceList = query.fetch(FETCH_LIMIT)).isEmpty()) {
        if (!JPA.em().contains(companyBankDetails)) {
            companyBankDetails = bankDetailsRepo.find(companyBankDetails.getId());
        }
        for (Invoice invoice : invoiceList) {
            if (treatedSet.contains(invoice.getId())) {
                throw new IllegalArgumentException("Invoice payment generation error");
            }
            treatedSet.add(invoice.getId());
            try {
                doneList.add(invoicePaymentCreateService.createInvoicePayment(invoice, companyBankDetails));
                incrementDone();
            } catch (Exception e) {
                incrementAnomaly();
                anomalyList.add(invoice.getId());
                query.bind("anomalyList", anomalyList);
                TraceBackService.trace(e, ExceptionOriginRepository.DIRECT_DEBIT, batch.getId());
                LOG.error(e.getMessage());
                break;
            }
        }
        JPA.clear();
    }
    return doneList;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Invoice(com.axelor.apps.account.db.Invoice) BankDetailsRepository(com.axelor.apps.base.db.repo.BankDetailsRepository) BankDetails(com.axelor.apps.base.db.BankDetails) ArrayList(java.util.ArrayList) AxelorException(com.axelor.exception.AxelorException) Function(com.google.common.base.Function) InvoicePaymentCreateService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCreateService) HashSet(java.util.HashSet)

Example 62 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class BatchDirectDebitPaymentSchedule method processQuery.

private void processQuery(QueryBuilder<PaymentScheduleLine> queryBuilder) {
    Query<PaymentScheduleLine> query = queryBuilder.build();
    List<PaymentScheduleLine> paymentScheduleLineList;
    PaymentScheduleService paymentScheduleService = Beans.get(PaymentScheduleService.class);
    PaymentScheduleLineService paymentScheduleLineService = Beans.get(PaymentScheduleLineService.class);
    BankDetailsRepository bankDetailsRepo = Beans.get(BankDetailsRepository.class);
    BankDetails companyBankDetails = getCompanyBankDetails(batch.getAccountingBatch());
    while (!(paymentScheduleLineList = query.fetch(FETCH_LIMIT)).isEmpty()) {
        findBatch();
        companyBankDetails = bankDetailsRepo.find(companyBankDetails.getId());
        PaymentMode directDebitPaymentMode = batch.getAccountingBatch().getPaymentMode();
        for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
            try {
                if (generateBankOrderFlag) {
                    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
                    BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
                    Preconditions.checkArgument(bankDetails.getActive(), bankDetails.getPartner() != null ? bankDetails.getPartner().getFullName() + " - " + I18n.get("Bank details are inactive.") : I18n.get("Bank details are inactive."));
                    if (directDebitPaymentMode.getOrderTypeSelect() == PaymentModeRepository.ORDER_TYPE_SEPA_DIRECT_DEBIT) {
                        Partner partner = paymentSchedule.getPartner();
                        Preconditions.checkNotNull(partner, I18n.get("Partner is missing."));
                        Preconditions.checkNotNull(partner.getActiveUmr(), I18n.get("Partner active UMR is missing."));
                    }
                }
                paymentScheduleLineService.createPaymentMove(paymentScheduleLine, companyBankDetails, directDebitPaymentMode);
                incrementDone(paymentScheduleLine);
            } catch (Exception e) {
                TraceBackService.trace(e, ExceptionOriginRepository.DIRECT_DEBIT, batch.getId());
                incrementAnomaly(paymentScheduleLine);
                break;
            }
        }
        JPA.clear();
    }
}
Also used : PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) BankDetailsRepository(com.axelor.apps.base.db.repo.BankDetailsRepository) BankDetails(com.axelor.apps.base.db.BankDetails) PaymentScheduleService(com.axelor.apps.account.service.PaymentScheduleService) PaymentScheduleLineService(com.axelor.apps.account.service.PaymentScheduleLineService) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 63 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class BatchCreditTransferInvoice method processInvoices.

/**
 * Process invoices of the specified document type.
 *
 * @param operationTypeSelect
 * @return
 */
protected List<InvoicePayment> processInvoices(int operationTypeSelect) {
    List<InvoicePayment> 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();
    StringBuilder filter = new StringBuilder();
    filter.append("self.operationTypeSelect = :operationTypeSelect " + "AND self.statusSelect = :statusSelect " + "AND self.amountRemaining > 0 " + "AND self.hasPendingPayments = FALSE " + "AND self.company = :company " + "AND self.dueDate <= :dueDate " + "AND self.paymentMode = :paymentMode " + "AND self.id NOT IN (:anomalyList)" + "AND self.pfpValidateStatusSelect != :pfpValidateStatusSelect");
    if (manageMultiBanks) {
        filter.append(" AND self.companyBankDetails IN (:bankDetailsSet)");
    }
    if (accountingBatch.getCurrency() != null) {
        filter.append(" AND self.currency = :currency");
    }
    Query<Invoice> query = invoiceRepo.all().filter(filter.toString()).bind("operationTypeSelect", operationTypeSelect).bind("statusSelect", InvoiceRepository.STATUS_VENTILATED).bind("company", accountingBatch.getCompany()).bind("dueDate", accountingBatch.getDueDate()).bind("paymentMode", accountingBatch.getPaymentMode()).bind("anomalyList", anomalyList).bind("pfpValidateStatusSelect", InvoiceRepository.PFP_STATUS_LITIGATION);
    if (manageMultiBanks) {
        Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
        if (accountingBatch.getIncludeOtherBankAccounts()) {
            bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
        }
        query.bind("bankDetailsSet", bankDetailsSet);
    }
    if (accountingBatch.getCurrency() != null) {
        query.bind("currency", accountingBatch.getCurrency());
    }
    BankDetailsRepository bankDetailsRepo = Beans.get(BankDetailsRepository.class);
    BankDetails companyBankDetails = accountingBatch.getBankDetails();
    for (List<Invoice> invoiceList; !(invoiceList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
        if (!JPA.em().contains(companyBankDetails)) {
            companyBankDetails = bankDetailsRepo.find(companyBankDetails.getId());
        }
        for (Invoice invoice : invoiceList) {
            try {
                doneList.add(invoicePaymentCreateService.createInvoicePayment(invoice, companyBankDetails));
                incrementDone();
            } catch (Exception ex) {
                incrementAnomaly();
                anomalyList.add(invoice.getId());
                query.bind("anomalyList", anomalyList);
                TraceBackService.trace(ex, ExceptionOriginRepository.CREDIT_TRANSFER, batch.getId());
                ex.printStackTrace();
                log.error(String.format("Credit transfer batch for invoices: anomaly for invoice %s", invoice.getInvoiceId()));
                break;
            }
        }
    }
    return doneList;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Invoice(com.axelor.apps.account.db.Invoice) BankDetails(com.axelor.apps.base.db.BankDetails) BankDetailsRepository(com.axelor.apps.base.db.repo.BankDetailsRepository) ArrayList(java.util.ArrayList) AccountingBatch(com.axelor.apps.account.db.AccountingBatch)

Aggregations

BankDetails (com.axelor.apps.base.db.BankDetails)63 Partner (com.axelor.apps.base.db.Partner)26 AxelorException (com.axelor.exception.AxelorException)26 PaymentMode (com.axelor.apps.account.db.PaymentMode)22 Company (com.axelor.apps.base.db.Company)22 BigDecimal (java.math.BigDecimal)14 LocalDate (java.time.LocalDate)13 Transactional (com.google.inject.persist.Transactional)12 ArrayList (java.util.ArrayList)11 Invoice (com.axelor.apps.account.db.Invoice)10 Journal (com.axelor.apps.account.db.Journal)9 BankDetailsService (com.axelor.apps.base.service.BankDetailsService)8 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)7 BankOrderLine (com.axelor.apps.bankpayment.db.BankOrderLine)7 Currency (com.axelor.apps.base.db.Currency)7 Account (com.axelor.apps.account.db.Account)6 AccountConfig (com.axelor.apps.account.db.AccountConfig)6 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)6 Move (com.axelor.apps.account.db.Move)6 MoveLine (com.axelor.apps.account.db.MoveLine)6