use of org.compiere.model.MCostElement in project adempiere by adempiere.
the class CostUpdate method getCosts.
// update
/**
* Get Costs
* @param cost cost
* @param to where to get costs from
* @return costs (could be 0) or null if not found
* @throws Exception
*/
private BigDecimal getCosts(MCost cost, String to) throws Exception {
BigDecimal retValue = null;
MCostElement costElement = MCostElement.getByMaterialCostElementType(cost);
if (costElement == null)
throw new AdempiereSystemError("@M_CostElement_ID@ @NotFound@: ");
// Average Invoice
if (to.equals(TO_AverageInvoice)) {
if (costElement == null)
throw new AdempiereSystemError("CostElement not found: " + TO_AverageInvoice);
MCost costDimension = getDimension(cost, costElement.getM_CostElement_ID());
if (costDimension != null)
retValue = costDimension.getCurrentCostPrice();
} else // Average Invoice History
if (to.equals(TO_AverageInvoiceHistory)) {
if (costElement == null)
throw new AdempiereSystemError("CostElement not found: " + TO_AverageInvoice);
MCost costDimension = getDimension(cost, costElement.getM_CostElement_ID());
if (costDimension != null)
retValue = costDimension.getHistoryAverage();
} else // Average PO
if (to.equals(TO_AveragePO)) {
if (costElement == null)
throw new AdempiereSystemError("CostElement not found: " + TO_AveragePO);
MCost costDimension = getDimension(cost, costElement.getM_CostElement_ID());
if (costDimension != null)
retValue = costDimension.getCurrentCostPrice();
} else // Average PO History
if (to.equals(TO_AveragePOHistory)) {
if (costElement == null)
throw new AdempiereSystemError("CostElement not found: " + TO_AveragePO);
MCost costDimension = getDimension(cost, costElement.getM_CostElement_ID());
if (costDimension != null)
retValue = costDimension.getHistoryAverage();
} else // FiFo
if (to.equals(TO_FiFo)) {
if (costElement == null)
throw new AdempiereSystemError("CostElement not found: " + TO_FiFo);
MCost costDimension = getDimension(cost, costElement.getM_CostElement_ID());
if (costDimension != null)
retValue = costDimension.getCurrentCostPrice();
} else // Future Std Costs
if (to.equals(TO_FutureStandardCost))
retValue = cost.getFutureCostPrice();
else // Last Inv Price
if (to.equals(TO_LastInvoicePrice)) {
if (costElement != null) {
MCost costDimension = getDimension(cost, costElement.getM_CostElement_ID());
if (costDimension != null)
retValue = costDimension.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());
}
} else // Last PO Price
if (to.equals(TO_LastPOPrice)) {
if (costElement != null) {
MCost costDimension = getDimension(cost, costElement.getM_CostElement_ID());
if (costDimension != null)
retValue = costDimension.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());
}
} else // FiFo
if (to.equals(TO_LiFo)) {
if (costElement == null)
throw new AdempiereSystemError("CostElement not found: " + TO_LiFo);
MCost costDimension = getDimension(cost, costElement.getM_CostElement_ID());
if (costDimension != null)
retValue = costDimension.getCurrentCostPrice();
} else // Old Std Costs
if (to.equals(TO_OldStandardCost))
retValue = getOldCurrentCostPrice(cost);
else // Price List
if (to.equals(TO_PriceListLimit))
retValue = getPrice(cost);
else // Standard Costs
if (to.equals(TO_StandardCost))
retValue = cost.getCurrentCostPrice();
return retValue;
}
use of org.compiere.model.MCostElement in project adempiere by adempiere.
the class MCostElementTest method testQuery.
public void testQuery() throws Exception {
X_M_CostElement ce = new X_M_CostElement(getCtx(), 102, null);
MClient client = MClient.get(ce.getCtx());
MCostElement[] retValue5 = MCostElement.getElements(client.getCtx(), null);
assertTrue("getElements returns 8", retValue5.length == 8);
}
use of org.compiere.model.MCostElement in project adempiere by adempiere.
the class CreateCostElement method doIt.
// prepare
protected String doIt() throws Exception {
MAcctSchema as = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID);
int count_costs = 0, count_all = 0;
for (final int org_id : getOrgs(as)) {
for (final int product_id : getProduct_IDs()) {
for (final MCostElement element : getElements()) {
MProduct product = MProduct.get(getCtx(), product_id);
MCost.getOrCreate(product, 0, as, org_id, 0, as.getM_CostType_ID(), element.getM_CostElement_ID());
count_all++;
}
}
}
return "@Created@ #" + count_costs + " / " + count_all;
}
use of org.compiere.model.MCostElement in project adempiere by adempiere.
the class CostResult method getCost.
public MCost getCost(int M_Product_ID) {
MCostElement ce = getMaterialElement(trxName);
String whereClause = "M_Product_ID=? AND M_CostElement_ID=? AND M_CostType_ID=? ";
ArrayList<Object> parameters = new ArrayList();
parameters.add(M_Product_ID);
parameters.add(ce.getM_CostElement_ID());
parameters.add(as.getM_CostType_ID());
return new Query(getCtx(), I_M_Cost.Table_Name, whereClause, trxName).setClient_ID().setParameters(parameters).first();
}
use of org.compiere.model.MCostElement in project adempiere by adempiere.
the class Doc_PPCostCollector method createActivityControl.
/**
* Feedback Labor and Burden absorbed
* Debit Work in Process Account for each Labor or Burden using the current cost rate
* Create a fact line for labor or burden
* Labor(Resources)
* Burden
* Credit Labor Absorbed or Burden Absorbed Account
* Create a fact line for labor or burden
* Labor Absorbed
* Burden Absorbed
*/
protected List<Fact> createActivityControl(MAcctSchema acctSchema) {
final ArrayList<Fact> facts = new ArrayList<Fact>();
final Fact fact = new Fact(this, acctSchema, Fact.POST_Actual);
facts.add(fact);
final MProduct product = costCollector.getM_Product();
MAccount workInProcessAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, acctSchema);
for (MCostDetail costDetail : getCostDetailsActivityControl()) {
BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
if (absoluteCost.signum() == 0)
continue;
BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
MCostElement costElement = MCostElement.get(getCtx(), costDetail.getM_CostElement_ID());
MAccount creditCostAccount = docLineCostCollector.getAccount(acctSchema, costElement);
createLines(costElement, acctSchema, fact, product, workInProcessAccount, creditCostAccount, cost, costCollector.getMovementQty());
}
//
return facts;
}
Aggregations