Search in sources :

Example 6 with MCost

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

the class CostResult method assertCostPhisicalInventory.

/**
	 * assert Cost Receipt
	 * @param product
	 * @param receiptLine
	 * @param as
	 * @param trxName
	 */
private void assertCostPhisicalInventory(CostResult costResult, int M_InventoryLine_ID, MAcctSchema as, String trxName) {
    MCost cost = assertCost(costResult);
    String whereClause = "M_Product_ID=? AND M_CostElement_ID=? AND M_CostType_ID=? AND M_InventoryLine_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_InventoryLine_ID);
    assertCostDetail(costResult, whereClause, parameters);
}
Also used : MCost(org.compiere.model.MCost) ArrayList(java.util.ArrayList)

Example 7 with MCost

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

the class CostResult method assertCostShipment.

/**
	 * assert Cost Receipt
	 * @param product
	 * @param receiptLine
	 * @param as
	 * @param trxName
	 */
private void assertCostShipment(CostResult costResult, int C_OrderLine_ID, MAcctSchema as, String trxName) {
    MCost cost = assertCost(costResult);
    String whereClause = "M_Product_ID=? AND M_CostElement_ID=? AND M_CostType_ID=? AND M_InOutLine_ID IN (SELECT M_InOutLine_ID FROM M_InOutLine iol WHERE iol.C_OrderLine_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(C_OrderLine_ID);
    assertCostDetail(costResult, whereClause, parameters);
}
Also used : MCost(org.compiere.model.MCost) ArrayList(java.util.ArrayList)

Example 8 with MCost

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

the class CostResult method assertCostReceipt.

/**
	 * assert Cost Receipt
	 * @param product
	 * @param receiptLine
	 * @param as
	 * @param trxName
	 */
private void assertCostReceipt(CostResult costResult, int M_InOutLine_ID, MAcctSchema as, String trxName) {
    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 9 with MCost

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

the class CostEngine method createCostDetail.

/**
	 * Create Cost Detail
	 * @param accountSchema Account Schema
	 * @param transaction Material Transaction
	 * @param model IDocumentLine
	 * @param costType Cost Type
	 * @param costElement Cost Element
	 */
public void createCostDetail(MAcctSchema accountSchema, MCostType costType, MCostElement costElement, MTransaction transaction, IDocumentLine model, boolean force) {
    if (!force)
        return;
    BigDecimal costThisLevel = Env.ZERO;
    BigDecimal costLowLevel = Env.ZERO;
    String costingLevel = MProduct.get(transaction.getCtx(), transaction.getM_Product_ID()).getCostingLevel(accountSchema, transaction.getAD_Org_ID());
    // adjustment for Average PO Costing method
    if (model instanceof MMatchInv && MCostType.COSTINGMETHOD_AveragePO.equals(costType.getCostingMethod()))
        return;
    // adjustment for Average PO Costing method
    if (model instanceof MMatchPO && MCostType.COSTINGMETHOD_AverageInvoice.equals(costType.getCostingMethod()))
        return;
    if (model instanceof MLandedCostAllocation) {
        MLandedCostAllocation allocation = (MLandedCostAllocation) model;
        costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
    }
    MCost cost = MCost.validateCostForCostType(accountSchema, costType, costElement, transaction.getM_Product_ID(), transaction.getAD_Org_ID(), transaction.getM_Warehouse_ID(), transaction.getM_AttributeSetInstance_ID(), transaction.get_TrxName());
    // get the cost for positive transaction
    if ((MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType()) || MCostElement.COSTELEMENTTYPE_LandedCost.equals(costElement.getCostElementType())) && transaction.getMovementType().contains("+") && !MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
        if (model instanceof MMovementLine || model instanceof MInventoryLine || (model instanceof MInOutLine && MTransaction.MOVEMENTTYPE_CustomerReturns.equals(transaction.getMovementType()))) {
            costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
            if (model instanceof MInventoryLine) {
                MInventoryLine inventoryLine = (MInventoryLine) model;
                // try get cost from physical inventory
                if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                    // Use the current cost only for Physical Inventory
                    if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPrice() != null && inventoryLine.getCurrentCostPrice().signum() > 0) {
                        costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
                    }
                    if (costThisLevel.signum() == 0)
                        costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
                }
                costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
                // try get cost low level from physical inventory
                if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                    // Use the current cost only for Physical Inventory
                    if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPriceLL() != null && inventoryLine.getCurrentCostPriceLL().signum() > 0) {
                        costLowLevel = convertCostToSchemaCurrency(accountSchema, model, inventoryLine.getCurrentCostPriceLL());
                    }
                    if (costLowLevel.signum() == 0)
                        costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
                }
            }
            //Get cost from movement from if it > that zero replace cost This Level
            if (model instanceof MMovementLine) {
                MTransaction transactionFrom = MTransaction.getByDocumentLine(model, MTransaction.MOVEMENTTYPE_MovementFrom);
                BigDecimal costMovementFrom = getCostThisLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
                if (costMovementFrom.signum() > 0)
                    costThisLevel = costMovementFrom;
                BigDecimal costMovementFromLL = getCostLowLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
                if (costMovementFromLL.signum() > 0)
                    costLowLevel = costMovementFromLL;
            }
        } else if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
            costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
        }
    }
    if (!MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
        if (model instanceof MPPCostCollector) {
            MPPCostCollector costCollector = (MPPCostCollector) model;
            if (MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt.equals(costCollector.getCostCollectorType())) {
                // get Actual Cost for Cost Type and Cost Element
                costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
                costLowLevel = CostEngine.getParentActualCostByCostType(accountSchema, costType.getM_CostType_ID(), costElement.getM_CostElement_ID(), costCollector);
            }
        }
        if (model instanceof MProductionLine) {
            MProductionLine productionLine = (MProductionLine) model;
            if (productionLine.isParent())
                costThisLevel = CostEngine.getParentActualCostByCostType(accountSchema, costType, costElement, productionLine.getM_Production());
            if (costThisLevel.signum() == 0)
                costThisLevel = cost.getCurrentCostPrice();
            if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType()))
                costThisLevel = getSeedCost(transaction.getCtx(), transaction.getM_Product_ID(), transaction.get_TrxName());
            // Material Receipt for Production light
            if (productionLine.isParent()) {
                // if the product is purchase then no use low level 
                if (!productionLine.getM_Product().isPurchased()) {
                    costLowLevel = costThisLevel;
                    costThisLevel = Env.ZERO;
                }
            } else if (productionLine.getMovementQty().signum() < 0)
                costLowLevel = Env.ZERO;
        }
    } else if (MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
        costThisLevel = cost.getCurrentCostPrice();
        costLowLevel = cost.getCurrentCostPriceLL();
        //Define Cost Inventory Line
        if (model instanceof MInventoryLine) {
            MInventoryLine inventoryLine = (MInventoryLine) model;
            //Define Current Cost Level
            if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                // Use the current cost only for Physical Inventory
                if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPrice() != null && inventoryLine.getCurrentCostPrice().signum() > 0) {
                    costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
                    cost.setCurrentCostPrice(costThisLevel);
                    cost.saveEx();
                }
                if (costThisLevel.signum() == 0)
                    costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
            }
            //Define Current Cost Low Level
            if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                // Use the cost only for Physical Inventory
                if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPriceLL() != null && inventoryLine.getCurrentCostPriceLL().signum() > 0) {
                    costLowLevel = convertCostToSchemaCurrency(accountSchema, model, inventoryLine.getCurrentCostPriceLL());
                    cost.setCurrentCostPriceLL(costLowLevel);
                    cost.saveEx();
                }
                if (costLowLevel.signum() == 0)
                    costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
            }
        }
        if (model instanceof MMovementLine) {
            MTransaction transactionFrom = MTransaction.getByDocumentLine(model, MTransaction.MOVEMENTTYPE_MovementFrom);
            BigDecimal costMovementFrom = getCostThisLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
            if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                if (costMovementFrom.signum() > 0)
                    costThisLevel = costMovementFrom;
            }
            if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
                BigDecimal costMovementFromLL = getCostLowLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
                if (costMovementFromLL.signum() > 0)
                    costLowLevel = costMovementFromLL;
            }
        }
        if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
            costThisLevel = getSeedCost(transaction.getCtx(), transaction.getM_Product_ID(), transaction.get_TrxName());
            if (costThisLevel.signum() == 0)
                if (model instanceof MInOutLine && !model.isSOTrx()) {
                    costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
                }
            if (costThisLevel.signum() != 0) {
                cost.setCurrentCostPrice(costThisLevel);
                cost.saveEx();
            }
        }
        if (costLowLevel.signum() != 0) {
            cost.setCurrentCostPriceLL(costLowLevel);
            cost.saveEx();
        }
    }
    final ICostingMethod method = CostingMethodFactory.get().getCostingMethod(costType.getCostingMethod());
    method.setCostingMethod(accountSchema, transaction, model, cost, costThisLevel, costLowLevel, model.isSOTrx());
    method.process();
}
Also used : MLandedCostAllocation(org.compiere.model.MLandedCostAllocation) MMatchPO(org.compiere.model.MMatchPO) MInventoryLine(org.compiere.model.MInventoryLine) MInOutLine(org.compiere.model.MInOutLine) MCost(org.compiere.model.MCost) MProductionLine(org.compiere.model.MProductionLine) MTransaction(org.compiere.model.MTransaction) BigDecimal(java.math.BigDecimal) MMatchInv(org.compiere.model.MMatchInv) MPPCostCollector(org.eevolution.model.MPPCostCollector) MMovementLine(org.compiere.model.MMovementLine)

Example 10 with MCost

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

the class AverageInvoiceCostingMethod method createUpdateAverageCostDetail.

public void createUpdateAverageCostDetail(MPPCostCollector costCollectorVariance, BigDecimal costVarianceThisLevel, BigDecimal costVarianceLowLevel, MProduct product, MAcctSchema acctSchema, MCostType costType, MCostElement costElement) {
    String whereClause = " exists (select 1 from pp_cost_collector pc" + " where pc.pp_cost_collector_ID=m_transaction.pp_Cost_collector_ID and costcollectortype =? " + " and pc.pp_order_ID=?)";
    MTransaction mtrx = new Query(costCollectorVariance.getCtx(), MTransaction.Table_Name, whereClause, costCollectorVariance.get_TrxName()).setParameters(MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt, costCollectorVariance.getPP_Order_ID()).setOrderBy("M_Transaction_ID desc").first();
    BigDecimal costThisLevel = Env.ZERO;
    BigDecimal costLowLevel = Env.ZERO;
    String costingLevel = MProduct.get(mtrx.getCtx(), mtrx.getM_Product_ID()).getCostingLevel(acctSchema, mtrx.getAD_Org_ID());
    costCollectorVariance.set_ValueOfColumn("Cost", costVarianceThisLevel.compareTo(Env.ZERO) != 0 ? costVarianceThisLevel : costVarianceLowLevel);
    costCollectorVariance.saveEx();
    IDocumentLine model = costCollectorVariance;
    MCost cost = MCost.validateCostForCostType(acctSchema, costType, costElement, product.getM_Product_ID(), 0, 0, 0, mtrx.get_TrxName());
    final ICostingMethod method = CostingMethodFactory.get().getCostingMethod(costType.getCostingMethod());
    method.setCostingMethod(acctSchema, mtrx, model, cost, costThisLevel, costLowLevel, model.isSOTrx());
    method.process();
}
Also used : Query(org.compiere.model.Query) MCost(org.compiere.model.MCost) MTransaction(org.compiere.model.MTransaction) BigDecimal(java.math.BigDecimal)

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