Search in sources :

Example 16 with PaymentSchedule

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

the class PaymentScheduleLineBankPaymentServiceImpl method representPaymentScheduleLine.

@Transactional
protected PaymentScheduleLine representPaymentScheduleLine(PaymentScheduleLine paymentScheduleLine) {
    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
    BigDecimal inTaxAmount = paymentScheduleLine.getInTaxAmount();
    int scheduleLineSeq = paymentScheduleService.getNextScheduleLineSeq(paymentSchedule);
    LocalDate scheduleDate = paymentScheduleLine.getScheduleDate();
    PaymentScheduleLine representedPaymentScheduleLine = createPaymentScheduleLine(paymentSchedule, inTaxAmount, scheduleLineSeq, scheduleDate);
    representedPaymentScheduleLine.setFromReject(true);
    representedPaymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_IN_PROGRESS);
    return representedPaymentScheduleLine;
}
Also used : PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 17 with PaymentSchedule

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

the class PaymentScheduleServiceImpl method createPaymentSchedule.

/**
 * Création d'un échéancier sans ces lignes.
 *
 * @param partner Le tiers.
 * @param invoices Collection de factures.
 * @param company La société.
 * @param startDate Date de première échéance.
 * @param nbrTerm Nombre d'échéances.
 * @return L'échéancier créé.
 * @throws AxelorException
 */
@Override
public PaymentSchedule createPaymentSchedule(Partner partner, Company company, Set<Invoice> invoices, LocalDate startDate, int nbrTerm) throws AxelorException {
    Invoice invoice = null;
    PaymentSchedule paymentSchedule = this.createPaymentSchedule(partner, invoice, company, appAccountService.getTodayDate(company), startDate, nbrTerm, partnerService.getDefaultBankDetails(partner), partner.getInPaymentMode());
    paymentSchedule.getInvoiceSet().addAll(invoices);
    return paymentSchedule;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule)

Example 18 with PaymentSchedule

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

the class BatchBankPaymentServiceImpl method createBankOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder createBankOrder(Batch batch) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    PaymentScheduleLine paymentScheduleLine = getPaymentScheduleLineDoneListQuery(batch).fetchOne();
    if (paymentScheduleLine == null) {
        throw new AxelorException(batch, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.BATCH_DIRECT_DEBIT_NO_PROCESSED_PAYMENT_SCHEDULE_LINES));
    }
    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
    switch(paymentSchedule.getTypeSelect()) {
        case PaymentScheduleRepository.TYPE_TERMS:
            return createBankOrderFromPaymentScheduleLines(batch);
        case PaymentScheduleRepository.TYPE_MONTHLY:
            return createBankOrderFromMonthlyPaymentScheduleLines(batch);
        default:
            throw new AxelorException(paymentSchedule, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.BATCH_DIRECT_DEBIT_UNKNOWN_DATA_TYPE));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Transactional(com.google.inject.persist.Transactional)

Example 19 with PaymentSchedule

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

the class BatchBankPaymentServiceImpl method createBankOrderFromMonthlyPaymentScheduleLines.

@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder createBankOrderFromMonthlyPaymentScheduleLines(Batch batch) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    LocalDate bankOrderDate = accountingBatch.getDueDate();
    Company senderCompany = accountingBatch.getCompany();
    BankDetails senderBankDetails = accountingBatch.getBankDetails();
    if (senderBankDetails == null) {
        senderBankDetails = accountingBatch.getCompany().getDefaultBankDetails();
    }
    PaymentMode paymentMode = accountingBatch.getPaymentMode();
    Currency currency = senderCompany.getCurrency();
    int partnerType = BankOrderRepository.PARTNER_TYPE_CUSTOMER;
    String senderReference = "";
    String senderLabel = "";
    if (bankOrderDate == null) {
        bankOrderDate = appBaseService.getTodayDate(senderCompany);
    }
    BankOrder bankOrder = bankOrderCreateService.createBankOrder(paymentMode, partnerType, bankOrderDate, senderCompany, senderBankDetails, currency, senderReference, senderLabel, BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
    bankOrder = JPA.save(bankOrder);
    List<PaymentScheduleLine> paymentScheduleLineList;
    int offset = 0;
    try {
        while (!(paymentScheduleLineList = fetchPaymentScheduleLineDoneList(batch, offset)).isEmpty()) {
            bankOrder = bankOrderRepo.find(bankOrder.getId());
            for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
                PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
                Partner partner = paymentSchedule.getPartner();
                BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
                BigDecimal amount = paymentScheduleLine.getInTaxAmount();
                String receiverReference = paymentScheduleLine.getName();
                String receiverLabel = paymentScheduleLine.getDebitNumber();
                BankOrderLine bankOrderLine = bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), null, partner, bankDetails, amount, currency, bankOrderDate, receiverReference, receiverLabel, paymentScheduleLine);
                bankOrder.addBankOrderLineListItem(bankOrderLine);
            }
            bankOrder = JPA.save(bankOrder);
            offset += paymentScheduleLineList.size();
            JPA.clear();
        }
    } catch (Exception e) {
        bankOrder = bankOrderRepo.find(bankOrder.getId());
        bankOrderRepo.remove(bankOrder);
        throw e;
    }
    bankOrder = bankOrderRepo.find(bankOrder.getId());
    bankOrder = bankOrderRepo.save(bankOrder);
    bankOrderService.confirm(bankOrder);
    batch = batchRepo.find(batch.getId());
    batch.setBankOrder(bankOrder);
    return bankOrder;
}
Also used : Company(com.axelor.apps.base.db.Company) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) BankDetails(com.axelor.apps.base.db.BankDetails) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) Currency(com.axelor.apps.base.db.Currency) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 20 with PaymentSchedule

use of com.axelor.apps.account.db.PaymentSchedule 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)

Aggregations

PaymentSchedule (com.axelor.apps.account.db.PaymentSchedule)20 AxelorException (com.axelor.exception.AxelorException)10 PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)7 Transactional (com.google.inject.persist.Transactional)7 Invoice (com.axelor.apps.account.db.Invoice)6 PaymentScheduleService (com.axelor.apps.account.service.PaymentScheduleService)6 BankDetails (com.axelor.apps.base.db.BankDetails)6 Partner (com.axelor.apps.base.db.Partner)6 MoveLine (com.axelor.apps.account.db.MoveLine)4 PaymentMode (com.axelor.apps.account.db.PaymentMode)4 BigDecimal (java.math.BigDecimal)4 Company (com.axelor.apps.base.db.Company)3 LocalDate (java.time.LocalDate)3 Move (com.axelor.apps.account.db.Move)2 Reconcile (com.axelor.apps.account.db.Reconcile)2 IrrecoverableService (com.axelor.apps.account.service.IrrecoverableService)2 SequenceService (com.axelor.apps.base.service.administration.SequenceService)2 Account (com.axelor.apps.account.db.Account)1 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)1 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)1