if (to.equals(TO_AverageInvoice))
{
MCostElement ce = getCostElement(TO_AverageInvoice);
if (ce == null)
throw new AdempiereSystemError("CostElement not found: " + TO_AverageInvoice);
MCost xCost = MCost.get(getCtx(), cost.getAD_Client_ID(), cost.getAD_Org_ID(), cost.getM_Product_ID(), cost.getM_CostType_ID(), cost.getC_AcctSchema_ID(), ce.getM_CostElement_ID(), cost.getM_AttributeSetInstance_ID());
if (xCost != null)
retValue = xCost.getCurrentCostPrice();
}
// Average Invoice History
else if (to.equals(TO_AverageInvoiceHistory))
{
MCostElement ce = getCostElement(TO_AverageInvoice);
if (ce == null)
throw new AdempiereSystemError("CostElement not found: " + TO_AverageInvoice);
MCost xCost = MCost.get(getCtx(), cost.getAD_Client_ID(), cost.getAD_Org_ID(), cost.getM_Product_ID(), cost.getM_CostType_ID(), cost.getC_AcctSchema_ID(), ce.getM_CostElement_ID(), cost.getM_AttributeSetInstance_ID());
if (xCost != null)
retValue = xCost.getHistoryAverage();
}
// Average PO
else if (to.equals(TO_AveragePO))
{
MCostElement ce = getCostElement(TO_AveragePO);
if (ce == null)
throw new AdempiereSystemError("CostElement not found: " + TO_AveragePO);
MCost xCost = MCost.get(getCtx(), cost.getAD_Client_ID(), cost.getAD_Org_ID(), cost.getM_Product_ID(), cost.getM_CostType_ID(), cost.getC_AcctSchema_ID(), ce.getM_CostElement_ID(), cost.getM_AttributeSetInstance_ID());
if (xCost != null)
retValue = xCost.getCurrentCostPrice();
}
// Average PO History
else if (to.equals(TO_AveragePOHistory))
{
MCostElement ce = getCostElement(TO_AveragePO);
if (ce == null)
throw new AdempiereSystemError("CostElement not found: " + TO_AveragePO);
MCost xCost = MCost.get(getCtx(), cost.getAD_Client_ID(), cost.getAD_Org_ID(), cost.getM_Product_ID(), cost.getM_CostType_ID(), cost.getC_AcctSchema_ID(), ce.getM_CostElement_ID(), cost.getM_AttributeSetInstance_ID());
if (xCost != null)
retValue = xCost.getHistoryAverage();
}
// FiFo
else if (to.equals(TO_FiFo))
{
MCostElement ce = getCostElement(TO_FiFo);
if (ce == null)
throw new AdempiereSystemError("CostElement not found: " + TO_FiFo);
MCost xCost = MCost.get(getCtx(), cost.getAD_Client_ID(), cost.getAD_Org_ID(), cost.getM_Product_ID(), cost.getM_CostType_ID(), cost.getC_AcctSchema_ID(), ce.getM_CostElement_ID(), cost.getM_AttributeSetInstance_ID());
if (xCost != null)
retValue = xCost.getCurrentCostPrice();
}
// Future Std Costs
else if (to.equals(TO_FutureStandardCost))
retValue = cost.getFutureCostPrice();
// Last Inv Price
else if (to.equals(TO_LastInvoicePrice))
{
MCostElement ce = getCostElement(TO_LastInvoicePrice);
if (ce != null)
{
MCost xCost = MCost.get(getCtx(), cost.getAD_Client_ID(), cost.getAD_Org_ID(), cost.getM_Product_ID(), cost.getM_CostType_ID(), cost.getC_AcctSchema_ID(), ce.getM_CostElement_ID(), cost.getM_AttributeSetInstance_ID());
if (xCost != null)
retValue = xCost.getCurrentCostPrice();
}
if (retValue == null)
{
MProduct product = MProduct.get(getCtx(), cost.getM_Product_ID());
MAcctSchema as = MAcctSchema.get(getCtx(), cost.getC_AcctSchema_ID());
retValue = MCost.getLastInvoicePrice(product,
cost.getM_AttributeSetInstance_ID(), cost.getAD_Org_ID(), as.getC_Currency_ID());
}
}
// Last PO Price
else if (to.equals(TO_LastPOPrice))
{
MCostElement ce = getCostElement(TO_LastPOPrice);
if (ce != null)
{
MCost xCost = MCost.get(getCtx(), cost.getAD_Client_ID(), cost.getAD_Org_ID(), cost.getM_Product_ID(), cost.getM_CostType_ID(), cost.getC_AcctSchema_ID(), ce.getM_CostElement_ID(), cost.getM_AttributeSetInstance_ID());
if (xCost != null)
retValue = xCost.getCurrentCostPrice();
}
if (retValue == null)
{
MProduct product = MProduct.get(getCtx(), cost.getM_Product_ID());
MAcctSchema as = MAcctSchema.get(getCtx(), cost.getC_AcctSchema_ID());
retValue = MCost.getLastPOPrice(product,
cost.getM_AttributeSetInstance_ID(), cost.getAD_Org_ID(), as.getC_Currency_ID());
}
}
// FiFo
else if (to.equals(TO_LiFo))
{
MCostElement ce = getCostElement(TO_LiFo);
if (ce == null)
throw new AdempiereSystemError("CostElement not found: " + TO_LiFo);
MCost xCost = MCost.get(getCtx(), cost.getAD_Client_ID(), cost.getAD_Org_ID(), cost.getM_Product_ID(), cost.getM_CostType_ID(), cost.getC_AcctSchema_ID(), ce.getM_CostElement_ID(), cost.getM_AttributeSetInstance_ID());
if (xCost != null)
retValue = xCost.getCurrentCostPrice();
}
// Old Std Costs
else if (to.equals(TO_OldStandardCost))
retValue = getOldCurrentCostPrice(cost);