Acumatica 从项目级别的任务更新收入预算字段
Acumatica Update Revenue Budget Fields from Tasks on Project level
在 Acumatica(内部版本 2020.5.2.368)中,我们对项目任务(DAC:PMTask)进行了大量自定义,当我们点击“保存”按钮时,它会正确保存。当我们想要将某些更改推送到“收入预算”选项卡(DAC:PMRevenueBudget)时 - 我们使用以下代码:
// Task updated
protected void PMTask_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
{
var row = (PMTask)e.Row;
PMTaskExt TaskExt = row.GetExtension<PMTaskExt>();
// Check Qty
if (TaskExt.UsrQuantity == 0)
{
TaskExt.UsrQuantity = 1;
}
if (TaskExt.UsrCostPrice != 0 && TaskExt.UsrMarginPerc != 0)
{
// do custom calculations here -- I removed the part of the code as it was useless for the purpose of posting here.
// Set custom fields
// These fields all have values greater than 0 --> Double Checked this
TaskExt.UsrMarkupPerc = TaskExt.UsrCostPrice * TaskExt.UsrQuantity / 100;
TaskExt.UsrLineCost = TaskExt.UsrCostPrice * TaskExt.UsrQuantity;
TaskExt.UsrSellPrice = TaskExt.UsrUnitPrice * TaskExt.UsrQuantity;
TaskExt.UsrTotalRevenue = TaskExt.UsrSellPrice - TaskExt.UsrLineCost;
TaskExt.UsrCostPriceCalculation = Convert.ToDecimal(12.00);
TaskExt.UsrUnitPriceCalculation = Convert.ToDecimal(88.99);
}
else
{
// More calculations
}
int revAccountID = 0;
int costAccountID = 0;
foreach (PMAccountGroup pmag in AccountInfo.Select())
{
if (pmag.GroupCD.Trim().Equals("INCOME"))
{
revAccountID = (int)pmag.GroupID; // 898
}
if (pmag.GroupCD.Trim().Equals("EXPENSES"))
{
costAccountID = (int)pmag.GroupID;
}
}
// Find the Inventory Type
InventoryItem inventory = InvetoryInfo.Search<InventoryItem.inventoryID>(TaskExt.UsrInventoryID);
string invUOM = "";
if (inventory != null)
{
invUOM = inventory.BaseUnit;
}
// Task --> Revenue Budget
PMRevenueBudget revbudgetItem = Base.RevenueBudget.Search<PMRevenueBudget.projectTaskID>(thisTask.TaskID);
if (revbudgetItem != null)
{
revbudgetItem.AccountGroupID = revAccountID;
revbudgetItem.InventoryID = thiskExt.UsrInventoryID;
revbudgetItem.CuryUnitRate = thiskExt.UsrUnitPrice;
revbudgetItem.Qty = thiskExt.UsrQuantity;
revbudgetItem.CuryAmount = thiskExt.UsrSellPrice;
revbudgetItem.UOM = invUOM;
revbudgetItem.RevisedQty = revbudgetItem.Qty;
revbudgetItem.CuryRevisedAmount = revbudgetItem.CuryAmount;
// --> Base.RevenueBudget.Update(revbudgetItem); <-- This works to update the cahce, but as soon as the user hits save, it reverts the changes back to 0.
}
}
我已经在行持久化和持久化事件中尝试过,但随后得到
"Another process has added/updated record"
还原所有内容的错误。当我点击“保存”按钮时,如何获取这些值并将其保存到 table?
如有任何帮助,我们将不胜感激。
因此,到目前为止我们找到的最佳解决方案是更新保留行中的图表。
protected void PMProject_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
{
var row = (PMProject)e.Row;
if (e.TranStatus == PXTranStatus.Completed)
{
var target = PXGraph.CreateInstance<ProjectTaskEntry>();
var target2 = PXGraph.CreateInstance<ProjectEntry>();
//var target = PXGraph.CreateInstance<ProjectEntry>();
foreach (PMTask taskitem in Base.Tasks.Select())
{
PMTaskExt TaskExt = taskitem.GetExtension<PMTaskExt>();
target.Task.Update(taskitem);
foreach (PMRevenueBudget revbudgetItem in Base.RevenueBudget.Search<PMRevenueBudget.projectTaskID>(taskitem.TaskID))
{
revbudgetItem.Qty = TaskExt.UsrQuantity;
target2.RevenueBudget.Update(revbudgetItem);
}
}
target2.Save.PressButton();
}
}
在 Acumatica(内部版本 2020.5.2.368)中,我们对项目任务(DAC:PMTask)进行了大量自定义,当我们点击“保存”按钮时,它会正确保存。当我们想要将某些更改推送到“收入预算”选项卡(DAC:PMRevenueBudget)时 - 我们使用以下代码:
// Task updated
protected void PMTask_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
{
var row = (PMTask)e.Row;
PMTaskExt TaskExt = row.GetExtension<PMTaskExt>();
// Check Qty
if (TaskExt.UsrQuantity == 0)
{
TaskExt.UsrQuantity = 1;
}
if (TaskExt.UsrCostPrice != 0 && TaskExt.UsrMarginPerc != 0)
{
// do custom calculations here -- I removed the part of the code as it was useless for the purpose of posting here.
// Set custom fields
// These fields all have values greater than 0 --> Double Checked this
TaskExt.UsrMarkupPerc = TaskExt.UsrCostPrice * TaskExt.UsrQuantity / 100;
TaskExt.UsrLineCost = TaskExt.UsrCostPrice * TaskExt.UsrQuantity;
TaskExt.UsrSellPrice = TaskExt.UsrUnitPrice * TaskExt.UsrQuantity;
TaskExt.UsrTotalRevenue = TaskExt.UsrSellPrice - TaskExt.UsrLineCost;
TaskExt.UsrCostPriceCalculation = Convert.ToDecimal(12.00);
TaskExt.UsrUnitPriceCalculation = Convert.ToDecimal(88.99);
}
else
{
// More calculations
}
int revAccountID = 0;
int costAccountID = 0;
foreach (PMAccountGroup pmag in AccountInfo.Select())
{
if (pmag.GroupCD.Trim().Equals("INCOME"))
{
revAccountID = (int)pmag.GroupID; // 898
}
if (pmag.GroupCD.Trim().Equals("EXPENSES"))
{
costAccountID = (int)pmag.GroupID;
}
}
// Find the Inventory Type
InventoryItem inventory = InvetoryInfo.Search<InventoryItem.inventoryID>(TaskExt.UsrInventoryID);
string invUOM = "";
if (inventory != null)
{
invUOM = inventory.BaseUnit;
}
// Task --> Revenue Budget
PMRevenueBudget revbudgetItem = Base.RevenueBudget.Search<PMRevenueBudget.projectTaskID>(thisTask.TaskID);
if (revbudgetItem != null)
{
revbudgetItem.AccountGroupID = revAccountID;
revbudgetItem.InventoryID = thiskExt.UsrInventoryID;
revbudgetItem.CuryUnitRate = thiskExt.UsrUnitPrice;
revbudgetItem.Qty = thiskExt.UsrQuantity;
revbudgetItem.CuryAmount = thiskExt.UsrSellPrice;
revbudgetItem.UOM = invUOM;
revbudgetItem.RevisedQty = revbudgetItem.Qty;
revbudgetItem.CuryRevisedAmount = revbudgetItem.CuryAmount;
// --> Base.RevenueBudget.Update(revbudgetItem); <-- This works to update the cahce, but as soon as the user hits save, it reverts the changes back to 0.
}
}
我已经在行持久化和持久化事件中尝试过,但随后得到
"Another process has added/updated record"
还原所有内容的错误。当我点击“保存”按钮时,如何获取这些值并将其保存到 table?
如有任何帮助,我们将不胜感激。
因此,到目前为止我们找到的最佳解决方案是更新保留行中的图表。
protected void PMProject_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
{
var row = (PMProject)e.Row;
if (e.TranStatus == PXTranStatus.Completed)
{
var target = PXGraph.CreateInstance<ProjectTaskEntry>();
var target2 = PXGraph.CreateInstance<ProjectEntry>();
//var target = PXGraph.CreateInstance<ProjectEntry>();
foreach (PMTask taskitem in Base.Tasks.Select())
{
PMTaskExt TaskExt = taskitem.GetExtension<PMTaskExt>();
target.Task.Update(taskitem);
foreach (PMRevenueBudget revbudgetItem in Base.RevenueBudget.Search<PMRevenueBudget.projectTaskID>(taskitem.TaskID))
{
revbudgetItem.Qty = TaskExt.UsrQuantity;
target2.RevenueBudget.Update(revbudgetItem);
}
}
target2.Save.PressButton();
}
}