Search in sources :

Example 21 with MCost

use of org.compiere.model.MCost in project adempiere by adempiere.

the class AverageInvoiceCostingMethod method getProductFutureCostPrice.

public BigDecimal getProductFutureCostPrice(MPPCostCollector costCollector, MProduct product, MAcctSchema acctSchema, MCostElement costElement, String trxName) {
    String CostingLevel = product.getCostingLevel(acctSchema);
    // Org Element
    int orgId = 0;
    int warehouseId = 0;
    if (product.getS_Resource_ID() != 0) {
        orgId = product.getS_Resource().getAD_Org_ID();
        warehouseId = product.getS_Resource().getM_Warehouse_ID();
    } else {
        orgId = (costCollector == null) ? costElement.getAD_Org_ID() : costCollector.getAD_Org_ID();
        warehouseId = (costCollector == null) ? 0 : costCollector.getM_Warehouse_ID();
    }
    int attributeSetInstanceId = (costCollector == null) ? 0 : costCollector.getM_AttributeSetInstance_ID();
    if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) {
        orgId = 0;
        attributeSetInstanceId = 0;
        warehouseId = 0;
    } else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel))
        attributeSetInstanceId = 0;
    else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel))
        orgId = 0;
    CostDimension d = new CostDimension(product, acctSchema, acctSchema.getM_CostType_ID(), orgId, attributeSetInstanceId, //warehouse
    warehouseId, costElement.getM_CostElement_ID());
    MCost cost = d.toQuery(MCost.class, trxName).firstOnly();
    if (cost == null)
        return Env.ZERO;
    BigDecimal price = cost.getFutureCostPrice().add(cost.getFutureCostPriceLL());
    return roundCost(price, acctSchema.getC_AcctSchema_ID());
}
Also used : MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal)

Example 22 with MCost

use of org.compiere.model.MCost in project adempiere by adempiere.

the class AverageInvoiceCostingMethod method getProductActualCostPrice.

public BigDecimal getProductActualCostPrice(MPPCostCollector costCollector, MProduct product, MAcctSchema acctSchema, MCostElement costElement, String trxName) {
    String CostingLevel = product.getCostingLevel(acctSchema);
    // Org Element
    int orgId = 0;
    int warehouseId = 0;
    if (product.getS_Resource_ID() != 0) {
        orgId = product.getS_Resource().getAD_Org_ID();
        warehouseId = product.getS_Resource().getM_Warehouse_ID();
    } else {
        orgId = (costCollector == null) ? costElement.getAD_Org_ID() : costCollector.getAD_Org_ID();
        warehouseId = (costCollector == null) ? 0 : costCollector.getM_Warehouse_ID();
    }
    int attributeSetInstanceId = (costCollector == null) ? 0 : costCollector.getM_AttributeSetInstance_ID();
    if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) {
        orgId = 0;
        attributeSetInstanceId = 0;
        warehouseId = 0;
    } else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel))
        attributeSetInstanceId = 0;
    else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel))
        orgId = 0;
    CostDimension costDimension = new CostDimension(product, acctSchema, acctSchema.getM_CostType_ID(), orgId, attributeSetInstanceId, //warehouse
    warehouseId, costElement.getM_CostElement_ID());
    MCost cost = costDimension.toQuery(MCost.class, trxName).firstOnly();
    if (cost == null)
        return Env.ZERO;
    BigDecimal price = cost.getCurrentCostPrice().add(cost.getCurrentCostPriceLL());
    return roundCost(price, acctSchema.getC_AcctSchema_ID());
}
Also used : MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal)

Example 23 with MCost

use of org.compiere.model.MCost in project adempiere by adempiere.

the class MPPOrder method createStandardCosts.

/**
	 * Save standard costs records into PP_Order_Cost.
	 * This will be usefull for calculating standard costs variances
	 */
public final void createStandardCosts() {
    MAcctSchema as = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema();
    log.info("Cost_Group_ID" + as.getM_CostType_ID());
    final TreeSet<Integer> productsAdded = new TreeSet<Integer>();
    //
    // Create Standard Costs for Order Header (resulting product)
    {
        final MProduct product = getM_Product();
        productsAdded.add(product.getM_Product_ID());
        final CostDimension d = new CostDimension(product, as, as.getM_CostType_ID(), getAD_Org_ID(), getM_Warehouse_ID(), getM_AttributeSetInstance_ID(), CostDimension.ANY);
        Collection<MCost> costs = d.toQuery(MCost.class, get_TrxName()).list();
        for (MCost cost : costs) {
            //Create or Update the Order Cost dimension
            MPPOrderCost.createOrderCostDimension(get_ID(), cost);
        }
    }
    // Create Standard Costs for Order BOM Line
    for (MPPOrderBOMLine line : getLines()) {
        final MProduct product = line.getM_Product();
        // Check if we already added this product
        if (productsAdded.contains(product.getM_Product_ID()))
            continue;
        productsAdded.add(product.getM_Product_ID());
        //
        CostDimension d = new CostDimension(line.getM_Product(), as, as.getM_CostType_ID(), line.getAD_Org_ID(), getM_Warehouse_ID(), line.getM_AttributeSetInstance_ID(), CostDimension.ANY);
        Collection<MCost> costs = d.toQuery(MCost.class, get_TrxName()).list();
        for (MCost cost : costs) {
            //Create or Update the Order Cost dimension
            MPPOrderCost.createOrderCostDimension(get_ID(), cost);
        }
    }
    // Create Standard Costs from Activity Resources
    for (MPPOrderNode node : getMPPOrderWorkflow().getNodes(true)) {
        final int S_Resource_ID = node.getS_Resource_ID();
        if (S_Resource_ID <= 0)
            continue;
        final MProduct resourceProduct = MProduct.forS_Resource_ID(getCtx(), S_Resource_ID, null);
        // Check if we already added this product
        if (productsAdded.contains(resourceProduct.getM_Product_ID()))
            continue;
        productsAdded.add(resourceProduct.getM_Product_ID());
        CostDimension d = new CostDimension(resourceProduct, as, as.getM_CostType_ID(), node.getAD_Org_ID(), getM_Warehouse_ID(), // ASI
        0, CostDimension.ANY);
        Collection<MCost> costs = d.toQuery(MCost.class, get_TrxName()).list();
        for (MCost cost : costs) {
            //Create or Update the Order Cost dimension
            MPPOrderCost.createOrderCostDimension(get_ID(), cost);
        }
    }
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) MProduct(org.compiere.model.MProduct) TreeSet(java.util.TreeSet) MCost(org.compiere.model.MCost) Collection(java.util.Collection) CostDimension(org.adempiere.engine.CostDimension)

Example 24 with MCost

use of org.compiere.model.MCost in project adempiere by adempiere.

the class CostResult method assertCostInvoice.

/**
	 * Assert Cost Invoice 
	 * @param product
	 * @param receiptLine
	 * @param as
	 * @param trxName
	 */
private void assertCostInvoice(CostResult costResult, int M_InOutLine_ID, MAcctSchema as, String trxName) {
    //Evaluate Result
    MCost cost = assertCost(costResult);
    String whereClause = "M_Product_ID=? AND  M_CostElement_ID=? AND M_CostType_ID=? AND M_InOutLine_ID=?";
    ArrayList<Object> parameters = new ArrayList();
    parameters.add(costResult.M_Product_ID);
    parameters.add(cost.getM_CostElement_ID());
    parameters.add(cost.getM_CostType_ID());
    parameters.add(M_InOutLine_ID);
    assertCostDetail(costResult, whereClause, parameters);
}
Also used : MCost(org.compiere.model.MCost) ArrayList(java.util.ArrayList)

Example 25 with MCost

use of org.compiere.model.MCost in project adempiere by adempiere.

the class FrozenUnFrozenCost method doIt.

@Override
protected String doIt() throws Exception {
    //Get account schema
    MAcctSchema accountSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
    //Get cost type
    MCostType costType = MCostType.get(getCtx(), getCostTypeId());
    //Get cost element to process
    final List<MCostElement> costElements = getCostElementId() > 0 ? Arrays.asList(MCostElement.get(getCtx(), getCostElementId())) : MCostElement.getCostElement(getCtx(), get_TrxName());
    //Iterate cost element
    costElements.stream().filter(costElement -> costElement != null).forEach(costElement -> {
        AtomicInteger records = new AtomicInteger(0);
        Arrays.stream(getProductIds()).filter(productId -> productId > 0).forEach(productId -> {
            MProduct product = MProduct.get(getCtx(), productId);
            final CostDimension costDimension = new CostDimension(product, accountSchema, costType.getM_CostType_ID(), getOrganizationId(), getWarehouseId(), 0, costElement.getM_CostElement_ID());
            Trx.run(trxName -> {
                final List<MCost> costs = costDimension.toQuery(MCost.class, trxName).list();
                costs.stream().filter(cost -> cost != null).forEach(cost -> {
                    cost.setIsCostFrozen(isCostFrozen());
                    cost.saveEx();
                    records.updateAndGet(record -> record + 1);
                });
            });
        });
        String message = "@M_CostElement_ID@ " + costElement.getName() + " @Records@ " + records.get() + " @IsCostFrozen@ = " + isCostFrozen();
        addLog(Msg.parseTranslation(getCtx(), message));
    });
    return "@OK@";
}
Also used : Arrays(java.util.Arrays) CostDimension(org.adempiere.engine.CostDimension) MCostType(org.compiere.model.MCostType) MAcctSchema(org.compiere.model.MAcctSchema) ArrayList(java.util.ArrayList) MCost(org.compiere.model.MCost) List(java.util.List) Query(org.compiere.model.Query) Msg(org.compiere.util.Msg) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MCostElement(org.compiere.model.MCostElement) Trx(org.compiere.util.Trx) MProduct(org.compiere.model.MProduct) MCostElement(org.compiere.model.MCostElement) MAcctSchema(org.compiere.model.MAcctSchema) MProduct(org.compiere.model.MProduct) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MCost(org.compiere.model.MCost) MCostType(org.compiere.model.MCostType) CostDimension(org.adempiere.engine.CostDimension)

Aggregations

MCost (org.compiere.model.MCost)29 BigDecimal (java.math.BigDecimal)19 ArrayList (java.util.ArrayList)14 MProduct (org.compiere.model.MProduct)11 MAcctSchema (org.compiere.model.MAcctSchema)9 MCostElement (org.compiere.model.MCostElement)9 Query (org.compiere.model.Query)8 Arrays (java.util.Arrays)6 List (java.util.List)6 MCostType (org.compiere.model.MCostType)6 CostDimension (org.adempiere.engine.CostDimension)5 Trx (org.compiere.util.Trx)5 Env (org.compiere.util.Env)4 Msg (org.compiere.util.Msg)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MTransaction (org.compiere.model.MTransaction)3 TrxRunnable (org.compiere.util.TrxRunnable)3 MWorkflow (org.compiere.wf.MWorkflow)3 MPPProductBOM (org.eevolution.model.MPPProductBOM)3