Search in sources :

Example 31 with InvoicePayment

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

the class InvoiceServiceImpl method removeBecauseOfAmountRemaining.

protected boolean removeBecauseOfAmountRemaining(Invoice invoice, Invoice candidateAdvancePayment) throws AxelorException {
    List<InvoicePayment> invoicePayments = candidateAdvancePayment.getInvoicePaymentList();
    // no payment : remove the candidate invoice
    if (invoicePayments == null || invoicePayments.isEmpty()) {
        return true;
    }
    // imputed
    if (!accountConfigService.getAccountConfig(invoice.getCompany()).getGenerateMoveForInvoicePayment()) {
        for (InvoicePayment invoicePayment : invoicePayments) {
            if (invoicePayment.getImputedBy() == null) {
                return false;
            }
        }
        return true;
    }
    // else we check the remaining amount
    for (InvoicePayment invoicePayment : invoicePayments) {
        Move move = invoicePayment.getMove();
        if (move == null) {
            continue;
        }
        List<MoveLine> moveLineList = move.getMoveLineList();
        if (moveLineList == null || moveLineList.isEmpty()) {
            continue;
        }
        for (MoveLine moveLine : moveLineList) {
            BigDecimal amountRemaining = moveLine.getAmountRemaining();
            if (amountRemaining != null && amountRemaining.compareTo(BigDecimal.ZERO) > 0) {
                return false;
            }
        }
    }
    return true;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) BigDecimal(java.math.BigDecimal)

Aggregations

InvoicePayment (com.axelor.apps.account.db.InvoicePayment)31 Invoice (com.axelor.apps.account.db.Invoice)11 AxelorException (com.axelor.exception.AxelorException)9 Transactional (com.google.inject.persist.Transactional)9 BigDecimal (java.math.BigDecimal)8 ArrayList (java.util.ArrayList)7 MoveLine (com.axelor.apps.account.db.MoveLine)6 BankDetails (com.axelor.apps.base.db.BankDetails)6 Move (com.axelor.apps.account.db.Move)5 InvoicePaymentToolService (com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentToolService)4 LocalDate (java.time.LocalDate)4 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)3 InvoicePaymentCreateService (com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCreateService)3 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)3 Map (java.util.Map)3 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)2 Reconcile (com.axelor.apps.account.db.Reconcile)2 InvoicePaymentRepository (com.axelor.apps.account.db.repo.InvoicePaymentRepository)2 Company (com.axelor.apps.base.db.Company)2