Search in sources :

Example 11 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine in project axelor-open-suite by axelor.

the class BatchBankPaymentServiceImpl method createBankOrderFromPaymentScheduleLines.

@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder createBankOrderFromPaymentScheduleLines(Batch batch) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    List<PaymentScheduleLine> paymentScheduleLineList;
    int offset = 0;
    while (!(paymentScheduleLineList = fetchPaymentScheduleLineDoneList(batch, offset)).isEmpty()) {
        createBankOrders(batch, paymentScheduleLineList);
        offset += paymentScheduleLineList.size();
        JPA.clear();
        batch = batchRepo.find(batch.getId());
    }
    List<BankOrder> bankOrderList;
    while ((bankOrderList = fetchLimitedBankOrderList(batch)).size() > 1) {
        bankOrderMergeService.mergeBankOrders(bankOrderList);
        JPA.clear();
        batch = batchRepo.find(batch.getId());
    }
    if (bankOrderList.isEmpty()) {
        throw new AxelorException(batch, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_MERGE_NO_BANK_ORDERS));
    }
    BankOrder bankOrder = bankOrderRepo.find(bankOrderList.iterator().next().getId());
    batch.setBankOrder(bankOrder);
    return bankOrder;
}
Also used : AxelorException(com.axelor.exception.AxelorException) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Transactional(com.google.inject.persist.Transactional)

Example 12 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine in project axelor-open-suite by axelor.

the class BatchBankPaymentServiceImpl method createBankOrders.

@Transactional(rollbackOn = { Exception.class })
protected void createBankOrders(Batch batch, Collection<PaymentScheduleLine> paymentScheduleLines) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLines) {
        PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
        MoveLine creditMoveLine = paymentScheduleLine.getAdvanceMoveLine();
        for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
            MoveLine debitMoveLine = moveService.getMoveLineService().getDebitCustomerMoveLine(invoice);
            Reconcile reconcile = reconcileRepo.findByMoveLines(debitMoveLine, creditMoveLine);
            if (reconcile == null) {
                continue;
            }
            createBankOrders(batch, reconcile);
        }
    }
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) MoveLine(com.axelor.apps.account.db.MoveLine) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 13 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine in project axelor-open-suite by axelor.

the class BatchDirectDebitPaymentSchedule method processPaymentScheduleLines.

protected void processPaymentScheduleLines(int paymentScheduleType) {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    if (generateBankOrderFlag) {
        Preconditions.checkNotNull(accountingBatch.getCompany(), I18n.get("Company is missing."));
        Preconditions.checkNotNull(accountingBatch.getPaymentMode(), I18n.get("Payment method is missing."));
        BankDetails companyBankDetails = getCompanyBankDetails(accountingBatch);
        AccountManagement accountManagement = Beans.get(PaymentModeService.class).getAccountManagement(accountingBatch.getPaymentMode(), accountingBatch.getCompany(), companyBankDetails);
        Preconditions.checkNotNull(accountManagement, I18n.get("Account management is missing."));
        Preconditions.checkNotNull(accountManagement.getBankDetails(), I18n.get("Bank details in account management is missing."));
        Preconditions.checkNotNull(companyBankDetails.getCurrency(), I18n.get("Currency in company bank details is missing."));
        String bankOrderExportPath = accountingBatch.getPaymentMode().getBankOrderExportFolderPath();
        String dataExpotDir;
        try {
            dataExpotDir = appBaseService.getDataExportDir();
            BankPaymentConfigService bankPaymentConfigService = Beans.get(BankPaymentConfigService.class);
            BankPaymentConfig bankPaymentConfig = bankPaymentConfigService.getBankPaymentConfig(accountingBatch.getCompany());
            bankPaymentConfigService.getIcsNumber(bankPaymentConfig);
        } catch (AxelorException e) {
            throw new RuntimeException(e);
        }
        Preconditions.checkArgument(bankOrderExportPath != null && new File(dataExpotDir + bankOrderExportPath).exists(), String.format(I18n.get("Bank order export folder does not exist: %s"), dataExpotDir + bankOrderExportPath));
    }
    QueryBuilder<PaymentScheduleLine> queryBuilder = QueryBuilder.of(PaymentScheduleLine.class);
    queryBuilder.add("self.paymentSchedule.statusSelect = :paymentScheduleStatusSelect");
    queryBuilder.bind("paymentScheduleStatusSelect", PaymentScheduleRepository.STATUS_CONFIRMED);
    queryBuilder.add("self.paymentSchedule.typeSelect = :paymentScheduleTypeSelect");
    queryBuilder.bind("paymentScheduleTypeSelect", paymentScheduleType);
    queryBuilder.add("self.statusSelect = :statusSelect");
    queryBuilder.bind("statusSelect", PaymentScheduleLineRepository.STATUS_IN_PROGRESS);
    LocalDate dueDate = accountingBatch.getDueDate() != null ? accountingBatch.getDueDate() : Beans.get(AppBaseService.class).getTodayDate(accountingBatch.getCompany());
    queryBuilder.add("self.scheduleDate <= :dueDate");
    queryBuilder.bind("dueDate", dueDate);
    if (accountingBatch.getCompany() != null) {
        queryBuilder.add("self.paymentSchedule.company IS NULL OR self.paymentSchedule.company = :company");
        queryBuilder.bind("company", accountingBatch.getCompany());
    }
    queryBuilder.add("self.paymentSchedule.partner.id NOT IN (SELECT DISTINCT partner.id FROM Partner partner LEFT JOIN partner.blockingList blocking WHERE blocking.blockingSelect = :blockingSelect AND blocking.blockingToDate >= :blockingToDate)");
    queryBuilder.bind("blockingSelect", BlockingRepository.DEBIT_BLOCKING);
    queryBuilder.bind("blockingToDate", Beans.get(AppBaseService.class).getTodayDate(accountingBatch.getCompany()));
    if (accountingBatch.getBankDetails() != null) {
        Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
        if (accountingBatch.getIncludeOtherBankAccounts() && appBaseService.getAppBase().getManageMultiBanks()) {
            bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
        }
        queryBuilder.add("self.paymentSchedule.companyBankDetails IS NULL OR self.paymentSchedule.companyBankDetails IN (:bankDetailsSet)");
        queryBuilder.bind("bankDetailsSet", bankDetailsSet);
    }
    if (accountingBatch.getPaymentMode() != null) {
        queryBuilder.add("self.paymentSchedule.paymentMode IS NULL OR self.paymentSchedule.paymentMode = :paymentMode");
        queryBuilder.bind("paymentMode", accountingBatch.getPaymentMode());
    }
    queryBuilder.add(":batch NOT MEMBER OF self.batchSet");
    queryBuilder.bind("batch", batch);
    processQuery(queryBuilder);
}
Also used : AxelorException(com.axelor.exception.AxelorException) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) BankDetails(com.axelor.apps.base.db.BankDetails) LocalDate(java.time.LocalDate) BankPaymentConfig(com.axelor.apps.bankpayment.db.BankPaymentConfig) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) BankPaymentConfigService(com.axelor.apps.bankpayment.service.config.BankPaymentConfigService) File(java.io.File) AccountManagement(com.axelor.apps.account.db.AccountManagement)

Example 14 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine in project axelor-open-suite by axelor.

the class PaymentScheduleLineBankPaymentServiceImpl method rejectFromMap.

protected <T> int rejectFromMap(Map<T, InterbankCodeLine> map, boolean represent, Function<T, PaymentScheduleLine> findFunc) {
    int errorCount = 0;
    for (Entry<T, InterbankCodeLine> entry : map.entrySet()) {
        T key = entry.getKey();
        InterbankCodeLine rejectionReason = entry.getValue();
        PaymentScheduleLine paymentScheduleLine = findFunc.apply(key);
        try {
            reject(paymentScheduleLine, rejectionReason, represent);
        } catch (Exception e) {
            TraceBackService.trace(e);
            ++errorCount;
        }
    }
    return errorCount;
}
Also used : PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) InterbankCodeLine(com.axelor.apps.account.db.InterbankCodeLine) AxelorException(com.axelor.exception.AxelorException)

Example 15 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine in project axelor-open-suite by axelor.

the class BankOrderMergeServiceImpl method getLastReferences.

protected Pair<String, LocalDate> getLastReferences(BankOrderLine bankOrderLine) {
    String lastReferenceId = "";
    LocalDate lastReferenceDate = null;
    for (BankOrderLineOrigin bankOrderLineOrigin : bankOrderLine.getBankOrderLineOriginList()) {
        LocalDate originDate = null;
        String originReferenceId = null;
        switch(bankOrderLineOrigin.getRelatedToSelect()) {
            case BankOrderLineOriginRepository.RELATED_TO_INVOICE:
                Invoice invoice = invoiceRepository.find(bankOrderLineOrigin.getRelatedToSelectId());
                if (!Strings.isNullOrEmpty(invoice.getSupplierInvoiceNb())) {
                    originReferenceId = invoice.getSupplierInvoiceNb();
                } else {
                    originReferenceId = invoice.getInvoiceId();
                }
                if (!Strings.isNullOrEmpty(invoice.getSupplierInvoiceNb())) {
                    originDate = invoice.getOriginDate();
                } else {
                    originDate = invoice.getInvoiceDate();
                }
                break;
            case BankOrderLineOriginRepository.RELATED_TO_PAYMENT_SCHEDULE_LINE:
                PaymentScheduleLine paymentScheduleLine = paymentScheduleLineRepository.find(bankOrderLineOrigin.getRelatedToSelectId());
                originReferenceId = paymentScheduleLine.getName();
                originDate = paymentScheduleLine.getScheduleDate();
                break;
            default:
                break;
        }
        if (originDate != null && (lastReferenceDate == null || lastReferenceDate.isBefore(originDate))) {
            lastReferenceDate = originDate;
            lastReferenceId = originReferenceId;
        }
    }
    return Pair.of(lastReferenceId, lastReferenceDate);
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) BankOrderLineOrigin(com.axelor.apps.bankpayment.db.BankOrderLineOrigin) LocalDate(java.time.LocalDate)

Aggregations

PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)29 Transactional (com.google.inject.persist.Transactional)12 Invoice (com.axelor.apps.account.db.Invoice)11 AxelorException (com.axelor.exception.AxelorException)10 ArrayList (java.util.ArrayList)8 PaymentSchedule (com.axelor.apps.account.db.PaymentSchedule)7 BigDecimal (java.math.BigDecimal)6 LocalDate (java.time.LocalDate)5 MoveLine (com.axelor.apps.account.db.MoveLine)4 BankDetails (com.axelor.apps.base.db.BankDetails)4 Company (com.axelor.apps.base.db.Company)4 Partner (com.axelor.apps.base.db.Partner)4 Move (com.axelor.apps.account.db.Move)3 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)2 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)2 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)2 EntityTransaction (javax.persistence.EntityTransaction)2 Account (com.axelor.apps.account.db.Account)1 AccountManagement (com.axelor.apps.account.db.AccountManagement)1