Good day,
We are trying to retrieve the unit cost, based on the warehouse selected inline on the sales quote screen.
How would I go about properly filtering in code to get to the right value, currently I have the following code to retrieve the code based on conditions:
We want the process to look as follow:
- First look at valuation method
- If it is standard
- Retrieve the current cost from the item warehouse details screen that links to the chosen warehouse on the sales quote screen
- If the cost is 0, retrieve from the item screen
- If it is average
- Retrieve the average cost from the item warehouse details screen that links to the chosen warehouse on the sales quote screen
- If the cost is 0, retrieve from the item screen
- Else
- Throw exception
- If it is standard
protected void CROpportunityProducts_SiteID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (CROpportunityProducts)e.Row;
InventoryItem temp = new InventoryItem();
temp = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, row.InventoryID);
INItemCost tempCost = new INItemCost();
tempCost = PXSelect<INItemCost, Where<INItemCost.inventoryID, Equal<Required<INItemCost.inventoryID>>>>.Select(Base, row.InventoryID);
INItemSite tempWharehouseCost = new INItemSite();
tempWharehouseCost = PXSelect<INItemSite, Where<INItemSite.inventoryID, Equal<Required<INItemCost.inventoryID>>>>.Select(Base, row.InventoryID);
var wharehouse = row.SiteID;
if (temp.ValMethod == "A")
{
if (tempWharehouseCost.AvgCost != 0)
{
row.CuryUnitCost = tempWharehouseCost.AvgCost;
}
else {
row.CuryUnitCost = tempCost.AvgCost;
}
}
else if (temp.ValMethod == "S")
{
if (tempWharehouseCost.StdCost != 0)
{
row.CuryUnitCost = tempWharehouseCost.StdCost;
}
else
{
row.CuryUnitCost = temp.StdCost;
}
}
else
{
throw new Exception("Please choose correct valuation method");
}
The reason for this is that stock items, can be in mulitple warehouses which in return can have different costs to the item.
Any help would be greatly appreciated