Hi @ppowell
The unpaid balance is a calculated field on the soscreen and the value is not stored in DB. We need to write logic and get the unpaid balance.
Please try like below and check the value you are getting correctly. If not working, adjust the code based on your requirement.
#region Event Handlers
protected void SOPackageDetailEx_COD_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e, PXFieldDefaulting InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (SOPackageDetailEx)e.Row;
if (row == null) return;
SOShipLine item = Base.Transactions.Select().FirstOrDefault();
if (item != null)
{
SOOrder order = PXSelect<SOOrder, Where<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>, And<SOOrder.orderType, Equal<Required<SOOrder.orderType>>>>>.Select(Base, item.OrigOrderNbr, item.OrigOrderType);
e.NewValue = GetUnpaidBalance(order);
}
}
public decimal? GetUnpaidBalance( SOOrder order)
{
decimal? creditMemo = 0;
decimal? payment = 0;
foreach (SOAdjust objSoadjust in PXSelectJoin<SOAdjust, InnerJoin<ARPayment, On<ARPayment.docType, Equal<SOAdjust.adjgDocType>, And<ARPayment.refNbr, Equal<SOAdjust.adjgRefNbr>>>>,
Where<SOAdjust.adjdOrderNbr, Equal<Required<SOAdjust.adjdOrderNbr>>, And<SOAdjust.adjdOrderType, Equal<Required<SOAdjust.adjdOrderType>>>>>.Select(Base, order.OrderNbr, order.OrderType))
{
if (objSoadjust.AdjgDocType == ARDocType.Payment)
{
payment += objSoadjust.CuryAdjdAmt + objSoadjust.CuryAdjdBilledAmt;
}
if (objSoadjust.AdjgDocType == ARDocType.CreditMemo)
{
creditMemo += objSoadjust.CuryAdjdAmt + objSoadjust.CuryAdjdBilledAmt;
}
}
foreach (ARAdjust objARAdjust in PXSelectJoin<ARAdjust,
InnerJoin<ARPayment, On<ARPayment.docType, Equal<ARAdjust.adjgDocType>, And<ARPayment.refNbr, Equal<ARAdjust.adjgRefNbr>>>,
InnerJoin<SOOrderShipment, On<SOOrderShipment.invoiceType, Equal<ARAdjust.adjdDocType>, And<SOOrderShipment.invoiceNbr, Equal<ARAdjust.adjdRefNbr>>>>>,
Where<SOOrderShipment.orderNbr, Equal<Required<SOOrderShipment.orderNbr>>, And<SOOrderShipment.orderType, Equal<Required<SOOrderShipment.orderType>>,
And<ARAdjust.adjdOrderNbr, IsNull, And<ARAdjust.adjdOrderType, IsNull>>>>>
.Select(Base, order.OrderNbr, order.OrderType))
{
if (objARAdjust.AdjgDocType == ARDocType.Payment)
{
payment += objARAdjust.CuryAdjdAmt;
}
if (objARAdjust.AdjgDocType == ARDocType.CreditMemo)
{
creditMemo += objARAdjust.CuryAdjdAmt;
}
}
return order.OrderTotal - creditMemo - payment;
}
#endregion
I am trying to get the unpaid balance to automatically be entered by default when adding a new package on the Shipments screen. We need to do this only for records where Payment type is COD. How do I reference SOOrder when modifying the value in SOPackageDetailEx?
I have the following code:
<Code snipped>
Basically we just need the bit where I am inserting 20.0 to be changed to insert the value held in SOOrder.UnpaidBalance instead if SOOrder.PaymentMethodID = ‘COD’. I’m not sure how to reference SOOrder from here. I have been going through the Acumatica training regarding customizations but this is still beyond me.
Thanks for any help,
Phil
Hi @ppowell
The unpaid balance is a calculated field on the soscreen and the value is not stored in DB. We need to write logic and get the unpaid balance.
Please try like below and check the value you are getting correctly. If not working, adjust the code based on your requirement.
#region Event Handlers
protected void SOPackageDetailEx_COD_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e, PXFieldDefaulting InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (SOPackageDetailEx)e.Row;
if (row == null) return;
SOShipLine item = Base.Transactions.Select().FirstOrDefault();
if (item != null)
{
SOOrder order = PXSelect<SOOrder, Where<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>, And<SOOrder.orderType, Equal<Required<SOOrder.orderType>>>>>.Select(Base, item.OrigOrderNbr, item.OrigOrderType);
e.NewValue = GetUnpaidBalance(order);
}
}
public decimal? GetUnpaidBalance( SOOrder order)
{
decimal? creditMemo = 0;
decimal? payment = 0;
foreach (SOAdjust objSoadjust in PXSelectJoin<SOAdjust, InnerJoin<ARPayment, On<ARPayment.docType, Equal<SOAdjust.adjgDocType>, And<ARPayment.refNbr, Equal<SOAdjust.adjgRefNbr>>>>,
Where<SOAdjust.adjdOrderNbr, Equal<Required<SOAdjust.adjdOrderNbr>>, And<SOAdjust.adjdOrderType, Equal<Required<SOAdjust.adjdOrderType>>>>>.Select(Base, order.OrderNbr, order.OrderType))
{
if (objSoadjust.AdjgDocType == ARDocType.Payment)
{
payment += objSoadjust.CuryAdjdAmt + objSoadjust.CuryAdjdBilledAmt;
}
if (objSoadjust.AdjgDocType == ARDocType.CreditMemo)
{
creditMemo += objSoadjust.CuryAdjdAmt + objSoadjust.CuryAdjdBilledAmt;
}
}
foreach (ARAdjust objARAdjust in PXSelectJoin<ARAdjust,
InnerJoin<ARPayment, On<ARPayment.docType, Equal<ARAdjust.adjgDocType>, And<ARPayment.refNbr, Equal<ARAdjust.adjgRefNbr>>>,
InnerJoin<SOOrderShipment, On<SOOrderShipment.invoiceType, Equal<ARAdjust.adjdDocType>, And<SOOrderShipment.invoiceNbr, Equal<ARAdjust.adjdRefNbr>>>>>,
Where<SOOrderShipment.orderNbr, Equal<Required<SOOrderShipment.orderNbr>>, And<SOOrderShipment.orderType, Equal<Required<SOOrderShipment.orderType>>,
And<ARAdjust.adjdOrderNbr, IsNull, And<ARAdjust.adjdOrderType, IsNull>>>>>
.Select(Base, order.OrderNbr, order.OrderType))
{
if (objARAdjust.AdjgDocType == ARDocType.Payment)
{
payment += objARAdjust.CuryAdjdAmt;
}
if (objARAdjust.AdjgDocType == ARDocType.CreditMemo)
{
creditMemo += objARAdjust.CuryAdjdAmt;
}
}
return order.OrderTotal - creditMemo - payment;
}
#endregion
I was struggling to see how to get this to work and didn’t really understand how to use PXSelect but this really clarifies things. It’s really helped to be able to work through the code and break it down to understand how to do this in future.
I really appreciate it,
Phil