Skip to main content
Question

Updating payment for the order on SO import through sync history processing screen

  • 5 August 2024
  • 4 replies
  • 41 views

Hello Everyone, 

we are trying to associate Credit Memo with sales order, 

I have created an SO extension graph and in persist inserting the credit memo details based on the order total, with this approach if we are creating an order manually and saving, the implementation is working as expected. But when any order is synced from BigCommerce, it is not updating as expected and we observed discrepancies in Credit Memo applied to order total and balance amount.

public class KNBCBRSOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public static bool IsActive() { return true; }
#region Views
public PXSelect<Customer> CustomerUpdate;
#endregion

public delegate void PersistDelegate();
PXOverride]
public void Persist(PersistDelegate del)
{
del();

List<ARInvoice> curyDocBalList = PXSelect<ARInvoice, Where<ARInvoice.docType, Equal<ARDocType.creditMemo>,
And<ARInvoice.status, Equal<ARDocStatus.open>,
And<ARInvoice.customerID, Equal<Required<ARInvoice.customerID>>>>>,
OrderBy<Asc<ARInvoice.createdDateTime>>>
.Select(Base, Base.Document?.Current?.CustomerID).RowCast<ARInvoice>().ToList();
decimal? CuryDocBalSum = 0;
decimal? RemainingAmt = Base.Document.Current.CuryOrderTotal;

foreach (ARInvoice invoiceCM in curyDocBalList)
{
try
{
if (invoiceCM.CuryDocBal < Base.Document.Current.CuryOrderTotal)
{
CuryDocBalSum += invoiceCM.CuryDocBal;
if (CuryDocBalSum <= Base.Document.Current.CuryOrderTotal)
{
SOAdjust sOAdjust = new SOAdjust();
sOAdjust.AdjgDocType = invoiceCM.DocType;
sOAdjust.AdjgRefNbr = invoiceCM.RefNbr;
sOAdjust.CuryAdjdAmt = invoiceCM.CuryDocBal;
Base.Adjustments.Insert(sOAdjust);
RemainingAmt -= invoiceCM.CuryDocBal;
}
else
{
decimal? amountToInsert = RemainingAmt;
if (amountToInsert > 0)
{
SOAdjust sOAdjust = new SOAdjust();
sOAdjust.AdjgDocType = invoiceCM.DocType;
sOAdjust.AdjgRefNbr = invoiceCM.RefNbr;
sOAdjust.CuryAdjdAmt = amountToInsert;
Base.Adjustments.Insert(sOAdjust);
RemainingAmt = 0;
break;
}
}
}
else
{
SOAdjust sOAdjust = new SOAdjust();
if (RemainingAmt > 0)
{
sOAdjust.AdjgDocType = invoiceCM.DocType;
sOAdjust.AdjgRefNbr = invoiceCM.RefNbr;
sOAdjust.CuryAdjdAmt = RemainingAmt;
Base.Adjustments.Insert(sOAdjust);
RemainingAmt = 0;
break;
}
}

}
catch (Exception ex)
{
throw new PXException(ex.Message);
}
}
del();
}
}

 

Hi @rakeshe45 Please share screenshots of Sales Order and Credit Memo highlighting clearly explain about the discrepancies in Credit Memo applied to order total and balance amount.


Hi @rakeshe45 Meanwhile, please also add some comment the code that is being shared, so that we can review the reason for each section in the code.


Hi @ChandraM

Thank you for the response.

In invoices and memos screen creating a credit memo document with detailed amount as 10.


We are importing a sales order from BigCommerce.
On importing the sales order, we are associating credit memo documents with the order.

We overridden Persist method to associate credit memo documents with the order.

Below is the screenshot of the sales order payment tab after importing order.

The Order Total is: 25.26

Credit Memo Balance: 10

While applying Credit Memo document to Order record, ‘Applied to Order’ should be 10 and ‘Balance’ should be zero. (When we save manually it working in the same way, as expected)

But in above example ‘Applied to Order’ is 0 and ‘Balance’ is showing as 13.27, that is not correct because the actual Credit Memo balance is 10 only.

Please find below sample code for reference:

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public static bool IsActive() { return true; }

public delegate void PersistDelegate();
ePXOverride]
public void Persist(PersistDelegate del)
{
del();

// Fetch List of Credit Memo documents belongs to the current customer
List<ARInvoice> curyDocBalList = PXSelect<ARInvoice, Where<ARInvoice.docType, Equal<ARDocType.creditMemo>,
And<ARInvoice.status, Equal<ARDocStatus.open>,
And<ARInvoice.customerID, Equal<Required<ARInvoice.customerID>>>>>,
OrderBy<Asc<ARInvoice.createdDateTime>>>
.Select(Base, Base.Document?.Current?.CustomerID).RowCast<ARInvoice>().ToList();
decimal? CuryDocBalSum = 0;
decimal? RemainingAmt = Base.Document.Current.CuryOrderTotal;
foreach (ARInvoice invoiceCM in curyDocBalList)
{
try
{
if (invoiceCM.CuryDocBal < Base.Document.Current.CuryOrderTotal)
{
CuryDocBalSum += invoiceCM.CuryDocBal;
if (CuryDocBalSum <= Base.Document.Current.CuryOrderTotal)
{
SOAdjust sOAdjust = new SOAdjust();
sOAdjust.AdjgDocType = invoiceCM.DocType;
sOAdjust.AdjgRefNbr = invoiceCM.RefNbr;
sOAdjust.CuryOrigDocAmt = invoiceCM.CuryDocBal;
Base.Adjustments.Insert(sOAdjust);
RemainingAmt -= invoiceCM.CuryDocBal;
}
else
{
decimal? amountToInsert = RemainingAmt;
if (amountToInsert > 0)
{
SOAdjust sOAdjust = new SOAdjust();
sOAdjust.AdjgDocType = invoiceCM.DocType;
sOAdjust.AdjgRefNbr = invoiceCM.RefNbr;
sOAdjust.CuryOrigDocAmt = amountToInsert;
Base.Adjustments.Insert(sOAdjust);
RemainingAmt = 0;
break;
}
}
}
else
{
SOAdjust sOAdjust = new SOAdjust();
if (RemainingAmt > 0)
{
sOAdjust.AdjgDocType = invoiceCM.DocType;
sOAdjust.AdjgRefNbr = invoiceCM.RefNbr;
sOAdjust.CuryOrigDocAmt = RemainingAmt;
Base.Adjustments.Insert(sOAdjust);
RemainingAmt = 0;
break;
}
}
}
catch (Exception ex)
{
throw new PXException(ex.Message);
}
}
del();
}
}

Please let us know, if you need any additional details from our side.


Hi @rakeshe45 were you able to find a solution? Thank you!


Reply