Hi @acumaticapm182 I have modified the code. Please verify with the below code.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PX.Common;
using PX.Data;
using PX.Objects.GL;
using PX.Objects.CM;
using PX.Objects.CS;
using PX.Objects.CR;
using PX.Objects.TX;
using PX.Objects.IN;
using PX.Objects.EP;
using PX.Objects.AP;
using PX.Objects.AR;
using PX.Objects.SO;
using PX.TM;
using SOOrder = PX.Objects.SO.SOOrder;
using SOLine = PX.Objects.SO.SOLine;
using PX.Objects.PM;
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Objects.AP.MigrationMode;
using PX.Objects.Common;
using PX.Objects;
using PX.Objects.PO;
namespace PX.Objects.PO
{
public class POOrderEntry_Extension : PXGraphExtension<POOrderEntry>
{
#region Event Handlers
public PXSelect<POVendorInventory, Where<POVendorInventory.inventoryID, Equal<Required<POVendorInventory.inventoryID>>,
And<POVendorInventory.vendorID, Equal<Required<POVendorInventory.vendorID>>>>> POVendorInventoryView;
public PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>> InventoryView;
protected void POLine_OrderQty_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (POLine)e.Row;
CalcMultLevelDisc(cache, row);
}
protected void POLine_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (POLine)e.Row;
POLineExt polinxt = row.GetExtension<POLineExt>();
POVendorInventory _povendorinv = POVendorInventoryView.SelectSingle(row.InventoryID, Base.Document.Current.VendorID);
if (_povendorinv != null)
{
POVendorInventory povendorinvCache = POVendorInventoryView.Select(row.InventoryID, row.VendorID);
if (povendorinvCache != null)
{
POVendorInventoryExt _povendorinvext = povendorinvCache.GetExtension<POVendorInventoryExt>();
row.GetExtension<POLineExt>().UsrMultilevelDisc = row.GetExtension<POLineExt>().UsrMultilevelDisc;
}
}
else
row.GetExtension<POLineExt>().UsrMultilevelDisc = null;
InventoryItem _stockitem = InventoryView.SelectSingle(row.InventoryID);
PXCache itemCache = InventoryView.Cache;
if (_stockitem.GetExtension<InventoryItemExt>().UsrIsPhyCountRequired != null)
{
if (_stockitem.GetExtension<InventoryItemExt>().UsrIsPhyCountRequired == true)
cache.RaiseExceptionHandling<POLine.inventoryID>(e.Row, ((POLine)e.Row).InventoryID, new PXSetPropertyException("Physical count must be done prior to replenishment", PXErrorLevel.Warning));
}
}
protected void POLine_UsrMultilevelDisc_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (POLine)e.Row;
CalcMultLevelDisc(cache, row);
}
protected void CalcMultLevelDisc(PXCache cache, POLine row)
{
if (row.CuryLineAmt == 0)
return;
if (String.IsNullOrEmpty(row.GetExtension<POLineExt>().UsrMultilevelDisc))
return;
string[] _colstr = row.GetExtension<POLineExt>().UsrMultilevelDisc.Split(',');
decimal? _runamt = row.CuryLineAmt;
foreach (string str in _colstr)
{
_runamt = _runamt - (_runamt * (Convert.ToDecimal(str) / 100M));
}
cache.SetValueExt<POLine.discPct>(row, (((row.CuryLineAmt - _runamt) / row.CuryLineAmt) * 100M));
}
#endregion
}
}