acumatica - 如何更新销售订单屏幕中的外部价格字段
问题描述
我在销售订单屏幕上发现了一个小细节,当添加两个自定义字段时会生成一个新价格,如图所示。但是在以单价生成新值的那一刻,我很惊讶 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
}
}
解决方案
通过使用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
}
}
我认为这可能会解决您的问题。
推荐阅读
- algorithm - 具有固定截止值的子数组的最大总和
- sorting - 如何在 Latex 中对表格输入进行排序?
- python - Spark Python Pyspark 如何使用字典数组和嵌入式字典来展平列(sparknlp 注释器输出)
- php - 在 Laravel 中从关联数组创建一个数组
- javascript - V8 如何使用隐藏类和内联缓存优化代码
- javascript - 无法使用 Node.js 更新 Mysql 数据库
- javascript - 使用 Netlify 函数加载本地文件
- powershell-2.0 - 文件是自动创建的,脚本应该自动重命名并移动它,但它们不会移动
- algorithm - 在距离矢量路由协议的情况下,什么时候说系统已经收敛?
- rest - Google drive API - 复制文件夹