Skip to main content
Solved

Creating a pop up to show various vendor pricing

  • June 23, 2022
  • 1 reply
  • 93 views

I need to create a link on each line item(Inventory Item on a sales order) of the graph on page PO505000 that will pop up a screen showing all of the vendors for that item and the cost from each vendor. Any ideas how to approach this?  

Best answer by JKurtz29

Hello,

We did something similar with a POOrderEntry graph extension that uses the in-field warning to create a hint/message that shows the quantity pricing for the current vendor.  Maybe you could use that as a basis to create what you need to show multiple vendor’s prices?

Here’s the graph extension’s code:

 

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

namespace PX.Objects.PO
{
    public class POOrderEntry_ExtensionAI : PXGraphExtension<POOrderEntry>
    {
        public static bool IsActive() => true;

        #region Event Handlers

        protected void _(Events.RowUpdated<POLine> e)
        {
            var row = (POLine)e.Row;
            if (row == null || row.InventoryID == null || row.OrderQty == null) return;

            PXUIFieldAttribute.SetWarning<POLine.curyUnitCost>(Base.Transactions.Cache, row, null);
            string msg = GetQtyMessage(row.InventoryID, row.VendorID, row.OrderQty, row.RequestedDate);
            PXUIFieldAttribute.SetWarning<POLine.curyUnitCost>(Base.Transactions.Cache, row, msg);
        }

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

            foreach(POLine line in Base.Transactions.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, vendorID, requestedDate, requestedDate);


            if (prices == null) return null;

            p.AppendLine("Quantity pricing available:");
            foreach (APVendorPrice price in prices)
            {
                p.AppendLine($"{price.BreakQty:n2} @ {price.SalesPrice:n2}");
            }
            p.AppendLine("");
            p.AppendLine($"You have {orderQty:n2} on this Purchase Order");
            return p.ToString();
        }
        #endregion
    }
}

 

View original
Did this topic help you find an answer to your question?

1 reply

JKurtz29
Jr Varsity III
Forum|alt.badge.img+1
  • Jr Varsity III
  • 16 replies
  • Answer
  • June 23, 2022

Hello,

We did something similar with a POOrderEntry graph extension that uses the in-field warning to create a hint/message that shows the quantity pricing for the current vendor.  Maybe you could use that as a basis to create what you need to show multiple vendor’s prices?

Here’s the graph extension’s code:

 

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

namespace PX.Objects.PO
{
    public class POOrderEntry_ExtensionAI : PXGraphExtension<POOrderEntry>
    {
        public static bool IsActive() => true;

        #region Event Handlers

        protected void _(Events.RowUpdated<POLine> e)
        {
            var row = (POLine)e.Row;
            if (row == null || row.InventoryID == null || row.OrderQty == null) return;

            PXUIFieldAttribute.SetWarning<POLine.curyUnitCost>(Base.Transactions.Cache, row, null);
            string msg = GetQtyMessage(row.InventoryID, row.VendorID, row.OrderQty, row.RequestedDate);
            PXUIFieldAttribute.SetWarning<POLine.curyUnitCost>(Base.Transactions.Cache, row, msg);
        }

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

            foreach(POLine line in Base.Transactions.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, vendorID, requestedDate, requestedDate);


            if (prices == null) return null;

            p.AppendLine("Quantity pricing available:");
            foreach (APVendorPrice price in prices)
            {
                p.AppendLine($"{price.BreakQty:n2} @ {price.SalesPrice:n2}");
            }
            p.AppendLine("");
            p.AppendLine($"You have {orderQty:n2} on this Purchase Order");
            return p.ToString();
        }
        #endregion
    }
}

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings