首页 > 解决方案 > 如何更新销售订单屏幕中的外部价格字段

问题描述

我在销售订单屏幕上发现了一个小细节,当添加两个自定义字段时会生成一个新价格,如图所示。但是在以单价生成新值的那一刻,我很惊讶 ext 价格将不会更新,并且其他标有绿色的字段。我附上了我的代码,我希望他们告诉我我失败了什么或我需要做什么,以便在更新单价时其他字段会自动更新,因为我只是在修改单价。除此之外,我还使用了 commit change = true,但它对我不起作用。

我感谢你的支持,

namespace PX.Objects.SO
{
    public class PESKSOOrderEntry6_Extension : PXGraphExtension<SOOrderEntry>
    {
        #region Event Handlers

        public const string PMBudgetType = "I";
        //STATE
        public const string eNY = "NY";
        public const string ePA = "PA";
        //UOM
        public const string uTN = "TN";
        public const string uGL = "GL";

        protected virtual void SOLine_CuryUnitPrice_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            sender.SetValuePending<SOLine.curyDiscPrice>(e.Row, PXCache.NotSetValue);
        }

        protected void _(Events.RowUpdated<SOLine> e)
        {
            var row = (SOLine)e.Row;
            var row1 = (SOLine)e.OldRow;
            SOOrder soOrder = Base.Document.Current;

            if (row == null) return;
            var rowExt = row.GetExtension<SOLineExt>();
            var rowExt1 = row1.GetExtension<SOLineExt>();

            PMRevenueBudget pmBudget = GetPMRevenueBudget(row.ProjectID, row.TaskID, row.InventoryID, PMBudgetType, row.UOM);
            var pmBudgetExt = pmBudget.GetExtension<PMBudgetExt>();

            if (row.InventoryID != null && row.OrderQty != 0 && row.TaskID != null && pmBudget != null && (rowExt.UsrSPriceIndex == false || rowExt.UsrSPriceIndex == null))
            {
                rowExt.UsrSPriceIndex = pmBudgetExt.UsrSPriceIndex;
                rowExt.UsrQuoteUnitPrice = pmBudget.Rate;

                row.CuryUnitPrice = pmBudget.Rate;
                //row.CuryExtPrice = row.OrderQty * row.CuryUnitPrice;
                //row.CuryDiscPrice = row.CuryExtPrice;
                //row.CuryLineAmt = row.CuryExtPrice;
                //row.CuryUnbilledAmt = row.CuryExtPrice;
            }
            else
            {
                rowExt.UsrSPriceIndex = false;
            }

            if (row.InventoryID != null && row.OrderQty != 0 && row.TaskID != null && pmBudget != null && rowExt.UsrSPriceIndex == true)
            {
                rowExt.UsrQuoteUnitPrice = pmBudget.Rate;

                PESKPriceIndexCat pricecat = GetPESKPriceIndexCat(row.InventoryID);

                decimal? nempriceIndex = 0, baseIndex = 0, aPercent = 0;
                nempriceIndex = NewEfecctiveMPriceIndex(soOrder, pricecat, nempriceIndex);
                baseIndex = BaseIndex(pmBudgetExt, baseIndex);
                aPercent = AsphaltPercent(row, pricecat, aPercent);

                if (pricecat != null && pricecat.State == eNY)
                {

                    if (row.UOM == uTN)
                    {
                        //((New Effective Monthly Price Index) – (Base Index)) x Asphalt Percent                             
                        rowExt.UsrIndexAdj = (((nempriceIndex) - (baseIndex)) * (aPercent / 100));
                        row.CuryUnitPrice = rowExt.UsrQuoteUnitPrice + rowExt.UsrIndexAdj;
                        //row.CuryExtPrice = row.OrderQty * row.CuryUnitPrice;
                        //row.CuryDiscPrice = row.CuryExtPrice;
                        //row.CuryLineAmt = row.CuryExtPrice;
                        //row.CuryUnbilledAmt = row.CuryExtPrice;
                    }

                    if (row.UOM == uGL)
                    {
                        //(((New Effective Monthly Index Price) – (Base Index))/ 235) x Asphalt Percent
                        decimal? num = 235;
                        rowExt.UsrIndexAdj = ((((nempriceIndex) - (baseIndex)) / num) * (aPercent / 100));
                        row.CuryUnitPrice = rowExt.UsrQuoteUnitPrice + rowExt.UsrIndexAdj;
                        //row.CuryExtPrice = row.OrderQty * row.CuryUnitPrice;
                        //row.CuryDiscPrice = row.CuryExtPrice;
                        //row.CuryLineAmt = row.CuryExtPrice;
                        //row.CuryUnbilledAmt = row.CuryExtPrice;
                    }
                }


                if (pricecat != null && pricecat.State == ePA)
                {
                    if (row.UOM == uTN)
                    {
                        var resul = (((nempriceIndex) - (baseIndex)) * (aPercent / 100));
                        var diff = resul - baseIndex;
                        decimal? diff1 = baseIndex * Convert.ToDecimal(0.1);

                        if (diff == diff1)
                        {
                            //((New Effective Monthly Price Index) – (Base Index)) x Asphalt Percent
                            rowExt.UsrIndexAdj = resul;
                            row.CuryUnitPrice = rowExt.UsrQuoteUnitPrice + rowExt.UsrIndexAdj;
                            //row.CuryExtPrice = row.OrderQty * row.CuryUnitPrice;
                            //row.CuryDiscPrice = row.CuryExtPrice;
                            //row.CuryLineAmt = row.CuryExtPrice;
                            //row.CuryUnbilledAmt = row.CuryExtPrice;

                        }

                    }
                    if (row.UOM == uGL)
                    {
                        decimal? num = 235;
                        var resul = ((((nempriceIndex) - (baseIndex)) / num) * (aPercent / 100));
                        var diff = resul - baseIndex;
                        decimal? diff1 = baseIndex * Convert.ToDecimal(0.1);

                        if (diff == diff1)
                        {
                            //(((New Effective Monthly Index Price) – (Base Index))/ 235) x Asphalt Percent   
                            rowExt.UsrIndexAdj = resul;
                            row.CuryUnitPrice = rowExt.UsrQuoteUnitPrice + rowExt.UsrIndexAdj;
                            //row.CuryExtPrice = row.OrderQty * row.CuryUnitPrice;
                            //row.CuryDiscPrice = row.CuryExtPrice;
                            //row.CuryLineAmt = row.CuryExtPrice;
                            //row.CuryUnbilledAmt = row.CuryExtPrice;
                        }
                    }

                }

            }


        }


        //how to calculate field Index Adj
        protected void _(Events.RowSelected<SOLine> e)
        {
            var row = (SOLine)e.Row;
            SOOrder soOrder = Base.Document.Current;

            if (row == null) return;
            var rowExt = row.GetExtension<SOLineExt>();

            #region Enabled and Disable

            PMRevenueBudget pmBudget = GetPMRevenueBudget(row.ProjectID, row.TaskID, row.InventoryID, PMBudgetType, row.UOM);


            if (row.InventoryID != null && row.OrderQty != 0 && row.TaskID != null && pmBudget != null)
            {
                PXUIFieldAttribute.SetEnabled<SOLineExt.usrQuoteUnitPrice>(e.Cache, e.Row, true);
                PXUIFieldAttribute.SetEnabled<SOLineExt.usrIndexAdj>(e.Cache, e.Row, true);
                rowExt.UsrQuoteUnitPrice = 0;
                rowExt.UsrIndexAdj = 0;
            }
            else
            {
                PXUIFieldAttribute.SetEnabled<SOLineExt.usrQuoteUnitPrice>(e.Cache, e.Row, false);
                PXUIFieldAttribute.SetEnabled<SOLineExt.usrIndexAdj>(e.Cache, e.Row, false);
            }

            if (rowExt.UsrSPriceIndex == true)
            {
                PXUIFieldAttribute.SetEnabled<SOLineExt.usrIndexAdj>(e.Cache, e.Row, true);
            }
            else
            {
                PXUIFieldAttribute.SetEnabled<SOLineExt.usrIndexAdj>(e.Cache, e.Row, false);
                rowExt.UsrQuoteUnitPrice = 0;
                rowExt.UsrIndexAdj = 0;
            }

           

            #endregion           

        }

        #region Method

        private decimal? AsphaltPercent(SOLine row, PESKPriceIndexCat pricecat, decimal? aPercent)
        {
            foreach (PESKStockItem res3 in PXSelect<PESKStockItem,
                                                Where<PESKStockItem.inventoryID, Equal<Required<PESKStockItem.inventoryID>>,
                                                And<PESKStockItem.categoryID, Equal<Required<PESKStockItem.categoryID>>>
                                                >>.Select(Base, row.InventoryID, pricecat.CategoryCD))
            {
                if (res3 != null)
                {
                    //Asphalt Percent
                    aPercent = res3.AsphaltPct;
                }
            }

            return aPercent;
        }

        private decimal? BaseIndex(PMBudgetExt contraExt, decimal? baseIndex)
        {
            PESKPriceIndexDetail res2 = PXSelectJoin<PESKPriceIndexDetail,
                                                InnerJoin<PESKPRC,
                                                On<PESKPRC.priceIndexID, Equal<PESKPriceIndexDetail.priceIndexID>>>,
                                                Where<PESKPRC.recordID, Equal<Required<PESKPRC.recordID>>>>
                                                .Select(Base, contraExt.UsrPRCNumber);

            if (res2 != null)
            {
                //Base Index
                baseIndex = res2.BaseIndex;
            }

            return baseIndex;
        }

        private decimal? NewEfecctiveMPriceIndex(SOOrder soOrder, PESKPriceIndexCat pricecat, decimal? nempriceIndex)
        {
            Dictionary<int?, object> Mydict1 = new Dictionary<int?, object>();
            Dictionary<int?, object> Mydict2 = new Dictionary<int?, object>();

            foreach (PESKPriceIndexDetail res in PXSelect<PESKPriceIndexDetail,
            Where<PESKPriceIndexDetail.categoryID, Equal<Required<PESKPriceIndexDetail.categoryID>>>>
            .Select(Base, pricecat.CategoryID))
            {
                if (res != null)
                {
                    if (res.EffDate <= soOrder.OrderDate)
                    {
                        if (!Mydict1.ContainsKey(res.PriceIndexID))
                        {
                            Mydict1.Add(res.PriceIndexID, res.EffDate);
                        }
                    }
                }
            }

            var maxfecha = (from mydic in Mydict1 select mydic.Value).Max();
            nempriceIndex = 0;
            PESKPriceIndexDetail res1 = PXSelect<PESKPriceIndexDetail,
            Where<PESKPriceIndexDetail.categoryID, Equal<Required<PESKPriceIndexDetail.categoryID>>,
            And<PESKPriceIndexDetail.effDate, Equal<Required<PESKPriceIndexDetail.effDate>>>>>
            .Select(Base, pricecat.CategoryID, maxfecha);
            if (res1 != null)
            {
                //New Effective Monthly Price Index
                nempriceIndex = res1.BaseIndex;
            }

            return nempriceIndex;
        }

        #endregion

        #endregion


        #region Metodos Realizados

        public static PXGraph GetGraph(PXGraph graph = null)
        {
            if (graph == null)
            {
                graph = new PXGraph();
            }
            return graph;
        }
        public static List<TDac> PXResultSetToList<TDac>(PXResultset<TDac> resultSet) where TDac : class, IBqlTable, new()
        {
            List<TDac> list = new List<TDac>();
            foreach (PXResult<TDac> item2 in resultSet)
            {
                TDac item = item2;
                list.Add(item);
            }
            return list;
        }

        public static PMRevenueBudget GetPMRevenueBudget(int? ProjectID, int? TaskID, int? InventoryID, string PMBudgetType, string UOM, PXGraph graph = null)
        {
            graph = GetGraph(graph);
            PXResultset<PMRevenueBudget> l = PXSelectBase<
                PMRevenueBudget, PXSelect<
                PMRevenueBudget,
                Where<PMRevenueBudget.projectID, Equal<Required<PMRevenueBudget.projectID>>,
                    And<PMRevenueBudget.projectTaskID, Equal<Required<PMRevenueBudget.projectTaskID>>,
                    And<PMRevenueBudget.inventoryID, Equal<Required<PMRevenueBudget.inventoryID>>,
                    And<PMRevenueBudget.type, Equal<Required<PMRevenueBudget.type>>,
                    And<PMRevenueBudget.uOM, Equal<Required<PMRevenueBudget.uOM>>>>
                    >>>>.Config>
                .Select(graph, ProjectID, TaskID, InventoryID, PMBudgetType, UOM);
            return l;
        }

        public static PESKPriceIndexCat GetPESKPriceIndexCat(int? InventoryID, PXGraph graph = null)
        {
            graph = GetGraph(graph);
            return PXSelectBase<
                PESKPriceIndexCat, PXSelectJoin<
                PESKPriceIndexCat,
                InnerJoin<PESKStockItem,
                    On<PESKStockItem.categoryID,
                Equal<PESKPriceIndexCat.categoryCD>>>,
                Where<PESKStockItem.inventoryID,
                Equal<Required<PESKStockItem.inventoryID>>>>.Config>
                .Select(graph, InventoryID);
        }

        #endregion
    }



}

在此处输入图像描述

标签: acumaticaacumatica-kb

解决方案


通过使用graph.View.SetValueExt<>(),您可以利用字段事件,这是自动更新这些字段的原因。

这将需要一些重新编码,但它看起来像这样:(注意第一行和最后两行)

    protected void _(Events.RowUpdated<SOLine> e)
    {
        var orderGraph = (SOOrderEntry)e.Cache.Graph; // ***NEW***
        var row = (SOLine)e.Row;
        var row1 = (SOLine)e.OldRow;
        SOOrder soOrder = Base.Document.Current;

        if (row == null) return;
        var rowExt = row.GetExtension<SOLineExt>();
        var rowExt1 = row1.GetExtension<SOLineExt>();

        PMRevenueBudget pmBudget = GetPMRevenueBudget(row.ProjectID, row.TaskID, row.InventoryID, PMBudgetType, row.UOM);
        var pmBudgetExt = pmBudget.GetExtension<PMBudgetExt>();

        if (row.InventoryID != null && row.OrderQty != 0 && row.TaskID != null && pmBudget != null && (rowExt.UsrSPriceIndex == false || rowExt.UsrSPriceIndex == null))
        {
            rowExt.UsrSPriceIndex = pmBudgetExt.UsrSPriceIndex;
            rowExt.UsrQuoteUnitPrice = pmBudget.Rate;

            orderGraph.Transactions.SetValueExt<SOLine.curyUnitPrice>(row, pmBudget.Rate); // ***NEW***
            //row.CuryUnitPrice = pmBudget.Rate; ***OLD***

            //.... other code
        }
    }

我认为这可能会解决您的问题。


推荐阅读