Class MCost

All Implemented Interfaces:
Serializable, Cloneable, Comparator<Object>, I_M_Cost, I_Persistent, Evaluatee

public class MCost extends X_M_Cost
Product Cost Model
Version:
$Id: MCost.java,v 1.6 2006/07/30 00:51:02 jjanke Exp $
Author:
Jorg Janke, Carlos Ruiz - globalqss
  • integrate bug fix from Teo Sarca - [ 1619112 ] Posible problem for LastPO costing, Batch/Lot level, Red1
  • FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 (only non-join query), Teo Sarca
  • BF [ 2847648 ] Manufacture and shipment cost errors https://sourceforge.net/p/adempiere/libero/237/
  • See Also:
    • Field Details

      • m_manual

        protected boolean m_manual
        Data is entered Manually
    • Constructor Details

      • MCost

        public MCost(Properties ctx, String M_Cost_UU, String trxName)
        UUID based Constructor
        Parameters:
        ctx - Context
        M_Cost_UU - UUID key
        trxName - Transaction
      • MCost

        public MCost(Properties ctx, int ignored, String trxName)
        Standard Constructor
        Parameters:
        ctx - context
        ignored - multi-key
        trxName - trx
      • MCost

        public MCost(Properties ctx, ResultSet rs, String trxName)
        Load Constructor
        Parameters:
        ctx - context
        rs - result set
        trxName - trx
      • MCost

        public MCost(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID)
        Parent Constructor
        Parameters:
        product - Product
        M_AttributeSetInstance_ID - asi
        as - Acct Schema
        AD_Org_ID - org
        M_CostElement_ID - cost element
    • Method Details

      • getCurrentCost

        public static BigDecimal getCurrentCost(MProduct product, int M_AttributeSetInstance_ID, String trxName)
        Parameters:
        product -
        M_AttributeSetInstance_ID -
        trxName -
        Returns:
        current product cost
      • getCurrentCost

        public static BigDecimal getCurrentCost(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, String costingMethod, BigDecimal qty, int C_OrderLine_ID, boolean zeroCostsOK, String trxName)
        Retrieve/Calculate Current Cost Price
        Parameters:
        product - product
        M_AttributeSetInstance_ID - asi for batchlot costing level
        as - accounting schema
        AD_Org_ID - org for organization costing level
        costingMethod - AcctSchema.COSTINGMETHOD_*
        qty - qty
        C_OrderLine_ID - optional order line
        zeroCostsOK - zero/no costs are OK
        trxName - trx
        Returns:
        current cost price or null
      • getCurrentCost

        protected static BigDecimal getCurrentCost(MProduct product, int M_ASI_ID, MAcctSchema as, int Org_ID, int M_CostType_ID, String costingMethod, BigDecimal qty, int C_OrderLine_ID, boolean zeroCostsOK, String trxName)
        Calculate and Get Current Cost Price for Costing Level
        Parameters:
        product - product
        M_ASI_ID - M_AttributeSetInstance_ID for batchlot costing level
        Org_ID - AD_Org_ID for organization costing level
        M_CostType_ID - cost type
        as - AcctSchema
        costingMethod - method
        qty - quantity
        C_OrderLine_ID - optional order line
        zeroCostsOK - zero/no costs are OK
        trxName - trx
        Returns:
        cost price or null
      • getSeedCosts

        public static BigDecimal getSeedCosts(MProduct product, int M_ASI_ID, MAcctSchema as, int Org_ID, String costingMethod, int C_OrderLine_ID)
        Get Seed Costs
        Parameters:
        product - product
        M_ASI_ID - costing M_AttributeSetInstance_ID for batchlot costing level
        as - accounting schema
        Org_ID - AD_Org_ID for organization costing level
        costingMethod - costing method
        C_OrderLine_ID - optional order line
        Returns:
        seed cost or null
      • getSeedCostFromPriceList

        protected static BigDecimal getSeedCostFromPriceList(MProduct product, MAcctSchema as, int orgID)
        Get seed cost from purchase price list
        Parameters:
        product -
        as -
        orgID -
        Returns:
        seed cost or null
      • getLastInvoicePrice

        public static BigDecimal getLastInvoicePrice(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID)
        Get Last Vendor Invoice Price in currency
        Parameters:
        product - product
        M_ASI_ID - attribute set instance
        AD_Org_ID - org
        C_Currency_ID - accounting currency
        Returns:
        last invoice price in currency
      • getLastPOPrice

        public static BigDecimal getLastPOPrice(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID)
        Get Last PO Price in currency
        Parameters:
        product - product
        M_ASI_ID - attribute set instance
        AD_Org_ID - org
        C_Currency_ID - accounting currency
        Returns:
        last PO price in currency or null
      • getPOPrice

        public static BigDecimal getPOPrice(MProduct product, int C_OrderLine_ID, int C_Currency_ID)
        Get PO Price in currency
        Parameters:
        product - product
        C_OrderLine_ID - order line
        C_Currency_ID - accounting currency
        Returns:
        PO price for order line in currency or null
      • create

        public static void create(MClient client)
        Calculate costing for client. Handles Transaction if not in a transaction.
        Parameters:
        client - client
      • create

        protected static void create(MProduct product)
        Create standard Costing records for Product
        Parameters:
        product - product
      • delete

        protected static void delete(MProduct product)
        Delete costing records for Product (for client and organization costing level)
        Parameters:
        product - product
      • calculateAverageInv

        public static BigDecimal calculateAverageInv(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
        Calculate Average Invoice Cost from M_Transaction
        Parameters:
        product - product
        M_AttributeSetInstance_ID - optional asi
        as - acct schema
        AD_Org_ID - optional org
        Returns:
        average invoice costs or null
      • calculateAveragePO

        public static BigDecimal calculateAveragePO(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
        Calculate Average PO from M_Transaction
        Parameters:
        product - product
        M_AttributeSetInstance_ID - asi
        as - acct schema
        AD_Org_ID - org
        Returns:
        average PO cost or null
      • calculateFiFo

        public static BigDecimal calculateFiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
        Calculate FiFo Cost from M_Transaction
        Parameters:
        product - product
        M_AttributeSetInstance_ID - asi
        as - acct schema
        AD_Org_ID - org
        Returns:
        FIFO costs or null
      • calculateLiFo

        public static BigDecimal calculateLiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
        Calculate LiFo costs from M_Transaction
        Parameters:
        product - product
        M_AttributeSetInstance_ID - asi
        as - acct schema
        AD_Org_ID - org
        Returns:
        LIFO costs or null
      • get

        public static MCost get(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID, String trxName)
        Get/Create Cost Record. CostingLevel is not validated.
        Parameters:
        product - product
        M_AttributeSetInstance_ID - costing level asi
        as - accounting schema
        AD_Org_ID - costing level org
        M_CostElement_ID - element
        Returns:
        cost price or null
      • get

        @Deprecated public static MCost get(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID)
        Deprecated.
      • get

        public static MCost get(Properties ctx, int AD_Client_ID, int AD_Org_ID, int M_Product_ID, int M_CostType_ID, int C_AcctSchema_ID, int M_CostElement_ID, int M_AttributeSetInstance_ID, String trxName)
        Get Cost Record
        Parameters:
        ctx - context
        AD_Client_ID - client
        AD_Org_ID - org
        M_Product_ID - product
        M_CostType_ID - cost type
        C_AcctSchema_ID - as
        M_CostElement_ID - cost element
        M_AttributeSetInstance_ID - asi
        trxName - transaction name
        Returns:
        MCost or null
      • get

        @Deprecated public static MCost get(Properties ctx, int AD_Client_ID, int AD_Org_ID, int M_Product_ID, int M_CostType_ID, int C_AcctSchema_ID, int M_CostElement_ID, int M_AttributeSetInstance_ID)
        Deprecated.
      • add

        public void add(BigDecimal amt, BigDecimal qty)
        Add to Cumulative Amt/Qty and Current Qty
        Parameters:
        amt - amt
        qty - qty
      • setWeightedAverage

        public void setWeightedAverage(BigDecimal amt, BigDecimal qty)
        Add to cumulative Amt/Qty, current qty and calculate new weighted average cost.
        ((OldAvg*OldQty)+(Price*Qty)) / (OldQty+Qty).
        Parameters:
        amt - total amt (price * qty)
        qty - qty
      • setWeightedAverageInitial

        public void setWeightedAverageInitial(BigDecimal amtUnit)
        Parameters:
        amtUnit - unit amt
      • getPrecision

        protected int getPrecision()
        Get Costing Precision
        Returns:
        precision (6)
      • setCurrentCostPrice

        public void setCurrentCostPrice(BigDecimal currentCostPrice)
        Set Current Cost Price
        Specified by:
        setCurrentCostPrice in interface I_M_Cost
        Overrides:
        setCurrentCostPrice in class X_M_Cost
        Parameters:
        currentCostPrice - if null set to 0
      • getHistoryAverage

        public BigDecimal getHistoryAverage()
        Get History Average (Amt/Qty)
        Returns:
        average if amt/aty <> 0 otherwise null
      • toString

        public String toString()
        String Representation
        Overrides:
        toString in class X_M_Cost
        Returns:
        info
      • getCostElement

        public MCostElement getCostElement()
        Get Cost Element
        Returns:
        cost element
      • beforeSave

        protected boolean beforeSave(boolean newRecord)
        Validate costing level configuration. Validate CurrentQty is positive for average costing.
        Overrides:
        beforeSave in class PO
        Parameters:
        newRecord - new
        Returns:
        true if can be saved
      • setCurrentQty

        public void setCurrentQty(BigDecimal CurrentQty)
        Throw AverageCostingNegativeQtyException if cost element is average po or average invoice and currentQty < 0.
        Specified by:
        setCurrentQty in interface I_M_Cost
        Overrides:
        setCurrentQty in class X_M_Cost
        Parameters:
        CurrentQty -