Question

RowSelected warning misses the first row.


I’m pulling my hair out a bit. I was helped along on this project by another user and I think I'm missing something here: 

I need each row to show a warning containing the various vendor prices. When I use the RowSelected event the top row value gets cleared out and when I change vendors it no longer updates the price. See images for expected behavior and current result.

(originally I was using RowUpdated (which worked) but then I would have to update the row before the warning would occur)

Any help would be greatly appreciated

using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Objects.AP;
using PX.Objects.PO;
using System;
using System.Text;

namespace PX.Objects.SO
{
public class POCreate_ExtensionAI : PXGraphExtension<POCreate>
{
public static bool IsActive() => true;

#region Event Handlers

protected void _(Events.RowSelected<POFixedDemand> e)
{
var row = (POFixedDemand)e.Row;
if (row == null || row.InventoryID == null || row.OrderQty == null) return;
PXUIFieldAttribute.SetWarning<POFixedDemand.effPrice>(Base.FixedDemand.Cache, row, null);
string msg = GetQtyMessage(row.InventoryID, row.VendorID, row.OrderQty, null);
PXUIFieldAttribute.SetWarning<POFixedDemand.effPrice>(Base.FixedDemand.Cache, row, msg);
}

protected decimal GetItemQtyTotalOnPO(int? inventoryID)
{
decimal retVal = 0;

foreach (POFixedDemand line in Base.FixedDemand.Select())
{
if (line.InventoryID == inventoryID)
{
retVal += line.OrderQty ?? 0;
}
}
return retVal;
}

protected string GetQtyMessage(int? inventoryID, int? vendorID, decimal? lineQty, DateTime? requestedDate)
{
if (inventoryID == null || vendorID == null || lineQty == null) return null;

StringBuilder p = new StringBuilder();
decimal orderQty = GetItemQtyTotalOnPO(inventoryID);
if (requestedDate == null) requestedDate = Base.Accessinfo.BusinessDate;




var prices =
SelectFrom<APVendorPrice>
.Where<APVendorPrice.inventoryID.IsEqual<@P.AsInt>
//.And<APVendorPrice.vendorID.IsEqual<@P.AsInt>>
.And<APVendorPrice.effectiveDate.IsLessEqual<@P.AsDateTime>
.Or<APVendorPrice.effectiveDate.IsNull>>
.And<APVendorPrice.expirationDate.IsGreaterEqual<@P.AsDateTime>
.Or<APVendorPrice.expirationDate.IsNull>>>
.View.ReadOnly.Select(Base, inventoryID, requestedDate, requestedDate);

var vendors =
SelectFrom<Vendor>
.LeftJoin<APVendorPrice>.On<Vendor.bAccountID.IsEqual<APVendorPrice.vendorID>>
.Where<APVendorPrice.inventoryID.IsEqual<@P.AsInt>>
.View.ReadOnly.Select(Base, inventoryID);

if (prices == null) return null;

p.AppendLine("Pricing available:");
foreach (APVendorPrice price in prices)
{

string vendorName = "empty";
foreach (Vendor vendor in vendors)
{
if (vendor.BAccountID == price.VendorID)
vendorName = vendor.AcctName.ToString();
}

p.AppendLine(vendorName + ":");
p.AppendLine($"${price.SalesPrice:n2}");

}
p.AppendLine("");
p.AppendLine($"You have {orderQty:n2} on this Purchase Order");
return p.ToString();
}
#endregion
}
}

 

 

expected behavior:

 

 

 


0 replies

Be the first to reply!

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