Search in sources :

Example 1 with InvoicePaymentRepository

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

the class InvoicePaymentCreateServiceImpl method determineIfReconcileFromInvoice.

/**
 * We try to get to the status of the invoice from the reconcile to see if this move was created
 * from a payment for an advance payment invoice.
 *
 * @param move
 * @return the found advance invoice if the move is from a payment that comes from this invoice.
 *     null in other cases
 */
protected Invoice determineIfReconcileFromInvoice(Move move) {
    List<MoveLine> moveLineList = move.getMoveLineList();
    if (moveLineList == null || moveLineList.size() != 2) {
        return null;
    }
    InvoicePaymentRepository invoicePaymentRepo = Beans.get(InvoicePaymentRepository.class);
    for (MoveLine moveLine : moveLineList) {
        // search for the reconcile between the debit line
        if (moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
            Reconcile reconcile = Beans.get(ReconcileRepository.class).all().filter("self.debitMoveLine = ?", moveLine).fetchOne();
            if (reconcile == null) {
                return null;
            }
            // associated payment
            if (reconcile.getCreditMoveLine() == null || reconcile.getCreditMoveLine().getMove() == null) {
                continue;
            }
            Move candidatePaymentMove = reconcile.getCreditMoveLine().getMove();
            InvoicePayment invoicePayment = invoicePaymentRepo.all().filter("self.move = :_move").bind("_move", candidatePaymentMove).fetchOne();
            // payment, then return true.
            if (invoicePayment != null && invoicePayment.getInvoice() != null && invoicePayment.getInvoice().getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
                return invoicePayment.getInvoice();
            }
        }
    }
    return null;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) ReconcileRepository(com.axelor.apps.account.db.repo.ReconcileRepository) InvoicePaymentRepository(com.axelor.apps.account.db.repo.InvoicePaymentRepository) Reconcile(com.axelor.apps.account.db.Reconcile)

Aggregations

InvoicePayment (com.axelor.apps.account.db.InvoicePayment)1 Move (com.axelor.apps.account.db.Move)1 MoveLine (com.axelor.apps.account.db.MoveLine)1 Reconcile (com.axelor.apps.account.db.Reconcile)1 InvoicePaymentRepository (com.axelor.apps.account.db.repo.InvoicePaymentRepository)1 ReconcileRepository (com.axelor.apps.account.db.repo.ReconcileRepository)1