Search in sources :

Example 1 with MCostElement

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;
}
Also used : MCostElement(org.compiere.model.MCostElement) MProduct(org.compiere.model.MProduct) MAcctSchema(org.compiere.model.MAcctSchema) AdempiereSystemError(org.compiere.util.AdempiereSystemError) MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal)

Example 2 with MCostElement

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);
}
Also used : MCostElement(org.compiere.model.MCostElement) X_M_CostElement(org.compiere.model.X_M_CostElement) MClient(org.compiere.model.MClient)

Example 3 with MCostElement

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;
}
Also used : MCostElement(org.compiere.model.MCostElement) MAcctSchema(org.compiere.model.MAcctSchema) MProduct(org.compiere.model.MProduct)

Example 4 with MCostElement

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();
}
Also used : MCostElement(org.compiere.model.MCostElement) Query(org.compiere.model.Query) ArrayList(java.util.ArrayList)

Example 5 with MCostElement

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;
}
Also used : MCostElement(org.compiere.model.MCostElement) MProduct(org.compiere.model.MProduct) MAccount(org.compiere.model.MAccount) ArrayList(java.util.ArrayList) MCostDetail(org.compiere.model.MCostDetail) BigDecimal(java.math.BigDecimal)

Aggregations

MCostElement (org.compiere.model.MCostElement)25 MAcctSchema (org.compiere.model.MAcctSchema)17 MCostType (org.compiere.model.MCostType)16 MProduct (org.compiere.model.MProduct)15 BigDecimal (java.math.BigDecimal)14 ArrayList (java.util.ArrayList)13 MCost (org.compiere.model.MCost)11 List (java.util.List)10 Query (org.compiere.model.Query)9 Arrays (java.util.Arrays)8 Trx (org.compiere.util.Trx)8 CostDimension (org.adempiere.engine.CostDimension)6 MTransaction (org.compiere.model.MTransaction)6 MAccount (org.compiere.model.MAccount)5 MCostDetail (org.compiere.model.MCostDetail)5 Env (org.compiere.util.Env)5 Msg (org.compiere.util.Msg)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 AdempiereException (org.adempiere.exceptions.AdempiereException)4 MInOutLine (org.compiere.model.MInOutLine)4