Search in sources :

Example 6 with BankOrderLine

use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.

the class BankOrderMergeServiceImpl method mergeBankOrders.

@Transactional(rollbackOn = { Exception.class })
public BankOrder mergeBankOrders(Collection<BankOrder> bankOrders) throws AxelorException {
    if (bankOrders == null || bankOrders.size() <= 1) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, IExceptionMessage.BANK_ORDER_MERGE_AT_LEAST_TWO_BANK_ORDERS);
    }
    this.checkSameElements(bankOrders);
    BankOrder bankOrder = bankOrders.iterator().next();
    bankOrders.remove(bankOrder);
    bankOrder.setSenderLabel(null);
    bankOrder.setSenderReference(null);
    bankOrder.setBankOrderDate(Beans.get(AppBaseService.class).getTodayDate(bankOrder.getSenderCompany()));
    bankOrder.setSignatoryUser(null);
    bankOrder.setSignatoryEbicsUser(null);
    PaymentMode paymentMode = bankOrder.getPaymentMode();
    for (BankOrderLine bankOrderLine : this.getAllBankOrderLineList(bankOrders)) {
        bankOrder.addBankOrderLineListItem(bankOrderLine);
    }
    bankOrderRepo.save(bankOrder);
    for (BankOrder bankOrderToRemove : bankOrders) {
        bankOrderToRemove = bankOrderRepo.find(bankOrderToRemove.getId());
        List<InvoicePayment> invoicePaymentList = invoicePaymentRepo.findByBankOrder(bankOrderToRemove).fetch();
        for (InvoicePayment invoicePayment : invoicePaymentList) {
            invoicePayment.setBankOrder(bankOrder);
        }
        bankOrderRepo.remove(bankOrderToRemove);
    }
    if (paymentMode.getConsoBankOrderLinePerPartner()) {
        consolidatePerPartner(bankOrder);
    }
    bankOrderService.updateTotalAmounts(bankOrder);
    return bankOrderRepo.save(bankOrder);
}
Also used : AxelorException(com.axelor.exception.AxelorException) InvoicePayment(com.axelor.apps.account.db.InvoicePayment) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 7 with BankOrderLine

use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.

the class BankOrderMoveServiceImpl method generateMoves.

@Override
public void generateMoves(BankOrder bankOrder) throws AxelorException {
    if (bankOrder.getBankOrderLineList() == null || bankOrder.getBankOrderLineList().isEmpty()) {
        return;
    }
    paymentMode = bankOrder.getPaymentMode();
    if (paymentMode == null || !paymentMode.getGenerateMoveAutoFromBankOrder()) {
        return;
    }
    orderTypeSelect = bankOrder.getOrderTypeSelect();
    senderCompany = bankOrder.getSenderCompany();
    senderBankDetails = bankOrder.getSenderBankDetails();
    partnerTypeSelect = bankOrder.getPartnerTypeSelect();
    journal = paymentModeService.getPaymentModeJournal(paymentMode, senderCompany, senderBankDetails);
    senderBankAccount = paymentModeService.getPaymentModeAccount(paymentMode, senderCompany, senderBankDetails);
    isMultiDate = bankOrder.getIsMultiDate();
    isMultiCurrency = bankOrder.getIsMultiCurrency();
    if (orderTypeSelect == BankOrderRepository.ORDER_TYPE_INTERNATIONAL_CREDIT_TRANSFER || orderTypeSelect == BankOrderRepository.ORDER_TYPE_SEPA_CREDIT_TRANSFER) {
        isDebit = true;
    } else {
        isDebit = false;
    }
    for (BankOrderLine bankOrderLine : bankOrder.getBankOrderLineList()) {
        if (ObjectUtils.isEmpty(bankOrderLine.getBankOrderLineOriginList())) {
            generateMoves(bankOrderLine);
        }
    }
}
Also used : BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine)

Example 8 with BankOrderLine

use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.

the class BankOrderServiceImpl method computeBankOrderTotalAmount.

@Override
public BigDecimal computeBankOrderTotalAmount(BankOrder bankOrder) throws AxelorException {
    BigDecimal bankOrderTotalAmount = BigDecimal.ZERO;
    List<BankOrderLine> bankOrderLines = bankOrder.getBankOrderLineList();
    if (bankOrderLines != null) {
        for (BankOrderLine bankOrderLine : bankOrderLines) {
            BigDecimal amount = bankOrderLine.getBankOrderAmount();
            if (amount != null) {
                bankOrderTotalAmount = bankOrderTotalAmount.add(amount);
            }
        }
    }
    return bankOrderTotalAmount;
}
Also used : BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) BigDecimal(java.math.BigDecimal)

Example 9 with BankOrderLine

use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.

the class BankOrderServiceImpl method resetPartners.

private void resetPartners(BankOrder bankOrder) {
    if (bankOrder.getPartnerTypeSelect() == BankOrderRepository.PARTNER_TYPE_COMPANY) {
        for (BankOrderLine bankOrderLine : bankOrder.getBankOrderLineList()) {
            bankOrderLine.setPartner(null);
        }
        return;
    }
    for (BankOrderLine bankOrderLine : bankOrder.getBankOrderLineList()) {
        bankOrderLine.setReceiverCompany(null);
        Partner partner = bankOrderLine.getPartner();
        if (partner == null) {
            continue;
        }
        boolean keep;
        switch(bankOrder.getPartnerTypeSelect()) {
            case BankOrderRepository.PARTNER_TYPE_SUPPLIER:
                keep = partner.getIsSupplier();
                break;
            case BankOrderRepository.PARTNER_TYPE_EMPLOYEE:
                keep = partner.getIsEmployee();
                break;
            case BankOrderRepository.PARTNER_TYPE_CUSTOMER:
                keep = partner.getIsCustomer();
                break;
            default:
                keep = false;
        }
        if (!keep) {
            bankOrderLine.setPartner(null);
        }
    }
}
Also used : BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) Partner(com.axelor.apps.base.db.Partner) EbicsPartner(com.axelor.apps.bankpayment.db.EbicsPartner)

Example 10 with BankOrderLine

use of com.axelor.apps.bankpayment.db.BankOrderLine in project axelor-open-suite by axelor.

the class BankOrderServiceImpl method validateBankOrderLines.

public void validateBankOrderLines(List<BankOrderLine> bankOrderLines, int orderType, BigDecimal arithmeticTotal) throws AxelorException {
    BigDecimal totalAmount = BigDecimal.ZERO;
    for (BankOrderLine bankOrderLine : bankOrderLines) {
        bankOrderLineService.checkPreconditions(bankOrderLine);
        totalAmount = totalAmount.add(bankOrderLine.getBankOrderAmount());
        bankOrderLineService.checkBankDetails(bankOrderLine.getReceiverBankDetails(), bankOrderLine.getBankOrder());
    }
    if (!totalAmount.equals(arithmeticTotal)) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BANK_ORDER_LINE_TOTAL_AMOUNT_INVALID));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) BigDecimal(java.math.BigDecimal)

Aggregations

BankOrderLine (com.axelor.apps.bankpayment.db.BankOrderLine)23 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)8 BankDetails (com.axelor.apps.base.db.BankDetails)7 AxelorException (com.axelor.exception.AxelorException)6 BigDecimal (java.math.BigDecimal)5 LocalDate (java.time.LocalDate)4 DatatypeFactory (javax.xml.datatype.DatatypeFactory)4 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 Transactional (com.google.inject.persist.Transactional)3 Umr (com.axelor.apps.account.db.Umr)2 BankOrderLineService (com.axelor.apps.bankpayment.service.bankorder.BankOrderLineService)2 Company (com.axelor.apps.base.db.Company)2 Currency (com.axelor.apps.base.db.Currency)2 Partner (com.axelor.apps.base.db.Partner)2 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)1 Invoice (com.axelor.apps.account.db.Invoice)1 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)1 PaymentSchedule (com.axelor.apps.account.db.PaymentSchedule)1 PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)1 Reimbursement (com.axelor.apps.account.db.Reimbursement)1