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;
}
Aggregations