Search in sources :

Example 26 with PaymentScheduleLine

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

the class PaymentScheduleServiceImpl method validatePaymentSchedule.

/**
 * Permet de valider un échéancier.
 *
 * @param paymentSchedule
 * @throws AxelorException
 */
@Override
@Transactional(rollbackOn = { Exception.class })
public void validatePaymentSchedule(PaymentSchedule paymentSchedule) throws AxelorException {
    log.debug("Validation de l'échéancier {}", paymentSchedule.getPaymentScheduleSeq());
    if (paymentSchedule.getPaymentScheduleLineList() == null || paymentSchedule.getPaymentScheduleLineList().isEmpty()) {
        throw new AxelorException(paymentSchedule, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PAYMENT_SCHEDULE_6), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), paymentSchedule.getPaymentScheduleSeq());
    }
    checkTotalLineAmount(paymentSchedule);
    for (PaymentScheduleLine paymentScheduleLine : paymentSchedule.getPaymentScheduleLineList()) {
        paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_IN_PROGRESS);
    }
    this.updateInvoices(paymentSchedule);
    paymentSchedule.setStatusSelect(PaymentScheduleRepository.STATUS_CONFIRMED);
}
Also used : AxelorException(com.axelor.exception.AxelorException) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) Transactional(com.google.inject.persist.Transactional)

Example 27 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine 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 28 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine 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 29 with PaymentScheduleLine

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

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