cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving the open amount of an invoice with AccountsReceivablePayableLedgerAccount.DueItem

Former Member
0 Kudos

Hello experts.

Today, I was wondering how is it possible to retrieve the open amount of a invoice. By open amount, I mean the remaining amount that a customer (account) needs to pay on an invoice.

I discovered a Business Object named AccountsReceivablePayableLedgerAccount. It has the sub object DueItem, that offers few methods such as DueItemHistory.SetOfBooksClearingInformation. Apparently, it makes it possible to check the history on an invoice. Unfortunately, I have no information on these methods (even from the repository that could list them, but display no data). So, I was wondering if this method is reliable for retrieving the open amount of an invoice.

Here's a part of my code:

id = "FA-555-2017";
invoice = CustomerInvoice.Retrieve(id);
if (!invoice.IsSet()) { continue; }
var node = this.CustomerInvoices.Create();
node.ID = id.content;
node.TotalAmount = invoice.TotalGrossAmount;
node.OpenAmount = invoice.TotalGrossAmount;

// look for account
var accountParams = accountQuery.CreateSelectionParams();
accountParams.Add(accountQuery.BusinessPartnerID, "I", "EQ", invoice.BuyerParty.PartyKey.PartyID.content);
accountParams.Add(accountQuery.PartyRoleCategoryCode, "I", "EQ", "4");
var results = accountQuery.Execute(accountParams);
if (results.Count() == 0) { continue; }
account = results.GetFirst();

// look for due item
dueitems = account.DueItem.Where(n => n.Key.OrderReference.FormattedID == invoice.ID.content);
if (dueitems.Count() == 0) { continue; }
dueitem = dueitems.GetFirst();

// look for open amount
if (!dueitem.DueItemHistory.IsSet()) { continue; }
if (dueitem.DueItemHistory.SetOfBooksClearingInformation.Count() == 0) { continue; }
node.OpenAmount = dueitem.DueItemHistory.SetOfBooksClearingInformation.GetFirst().OpenLocalCurrencyAmount;

Thank you a lot for your help. 🙂

Best regards,

Frédéric

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member

What you are looking for is actually in the TradeReceivablesPayablesRegister

import ABSL;
import AP.DueItemManagement.Global; 

var query = TradeReceivablesPayablesRegister.ItemOverview.QueryByElements; 

var selectionParams = query.CreateSelectionParams(); 

selectionParams.Add(query.BaseBusinessTransactionDocumentReference.ID.content, "I", "EQ", "INV-1234"); 

var resultData = query.Execute(selectionParams);

The amount will be in the OpenItemAmount

Former Member
0 Kudos

I tested with an unpaid invoice. It works. I can see my Open Amount = Total Amount. However, I realized that if I pay that invoice in ByD and check again on my Web Service, I still get the same answer : Open Amount = Total Amount, while it should be Open Amount = 0.

So, maybe it doesn't work either.

Former Member
0 Kudos

Thank you for your help.

I tested with an unpaid invoice. It works. I can see my Open Amount = Total Amount. However, I realized that if I pay that invoice in ByD and check again on my Web Service, I still get the same answer : Open Amount = Total Amount, while it should be Open Amount = 0.

So, maybe it doesn't work either.