Blog: Overriding Credit Verification for Days past Due with a negative balance

  • 29 March 2024
  • 1 reply
  • 22 views

Userlevel 4
Badge +2

Good afternoon! I wanted to share with you a snippet of code that has helped us tremendously with our credit hold process. We have times when a check is created, or a credit memo is left on the account, but not yet applied to documents. These customers would have invoices that trigger credit hold, but a negative or 0 balance, so it should not. Sometimes, there is a lag time in the processing of these credits/payments, so I had to write a modification to assist.

 

Sometimes tracing through the Code Repository and finding the correct functions to extend or events to inject than writing the actual code! The customer credit verification is held in the CustomerCreditExtension graph extension. This extension is overridden by the SOOrderCustomerCreditExtension with custom logic overriding the base logic for the SOOrderEntry screen. The class SOOrderCustomerCredit is an extension that applies the logic to the screen through extending SOOrderEntry.

This uses PXProtectedAccess to access the GetCustomerBalance function, as well as to override ApplyCreditVerificationResult to execute our custom code.

//allow overriding of the protected function ApplyCreditVerificationResult
[PXProtectedAccess(typeof(SOOrderCustomerCredit))]
public abstract class SOOrderCustomerCreditProtectedExt : PXGraphExtension<SOOrderCustomerCreditExt, SOOrderCustomerCredit, SOOrderEntry>
{
[PXProtectedAccess]
protected abstract void ApplyCreditVerificationResult(PXCache sender, SOOrder row, CreditVerificationResult res, PXCache arbalancescache);

}

[PXProtectedAccess]
public abstract class SOOrderCustomerCreditExt : PXGraphExtension<SOOrderCustomerCredit, SOOrderEntry>
{
// always active
public static bool IsActive() { return true; }

//access the protected GetCustomerBalance function
[PXProtectedAccess(typeof(SOOrderCustomerCredit))]
protected abstract void GetCustomerBalance(PXCache cache, Customer customer, out decimal? CustomerBal, out DateTime? OldInvoiceDate);

public delegate void ApplyCreditVerificationResultDelegate(PXCache sender, SOOrder Row, EventArgs e, PX.Objects.AR.Customer customer, CreditVerificationResult res);


//this function takes the credit verification result and applys it to the current SOOrder document.
[PXOverride]
public virtual void ApplyCreditVerificationResult(PXCache sender, SOOrder Row, EventArgs e, PX.Objects.AR.Customer customer, CreditVerificationResult res, ApplyCreditVerificationResultDelegate del)
{
CreditVerificationResult newResult = res;
//check to see the error message sent (warning that goes on the customer field, etc)
if (String.IsNullOrWhiteSpace(res.ErrorMessage) == false)
{

//check to see if the credit verification rule contains days past due
if (customer.CreditRule == CreditRuleTypes.CS_BOTH || customer.CreditRule == CreditRuleTypes.CS_DAYS_PAST_DUE)
{
//check balance
decimal? CustomerBal;
DateTime? OldInvoiceDate;
GetCustomerBalance(sender.Graph.Caches[typeof(ARBalances)], customer, out CustomerBal, out OldInvoiceDate);

//if negative balance, do not apply a credit hold
if (CustomerBal <= 0)
{
newResult = new CreditVerificationResult();
}
}
}
//call the delegate function
del?.Invoke(sender, Row, e, customer, newResult);

}
}

The CreditVerificationResult sent has the previous result. This checks for an error, and if found,then does another level of verification. If it needs to override, it will create a new CreditVerificationResult, which then passes it along. 

I hope this may help someone who may have the same business requirement, or just more insight into where the credit verification is handled!


1 reply

Userlevel 7
Badge

Thank you for sharing this information with the community @Keith Richardson!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved