Skip to Content
Dec 21, 2017 at 03:52 PM

Retrieving the open amount of an invoice with AccountsReceivablePayableLedgerAccount.DueItem


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,