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:
    Serialized Form
    • Field Detail

      • m_manual

        protected boolean m_manual
        Data is entered Manually
    • Constructor Detail

      • 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 Detail

      • 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 - real asi
        as - accounting schema
        AD_Org_ID - real org
        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)
        Get Current Cost Price for Costing Level
        Parameters:
        product - product
        M_ASI_ID - costing level asi
        Org_ID - costing level org
        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 level asi
        as - accounting schema
        Org_ID - costing level org
        costingMethod - costing method
        C_OrderLine_ID - optional order line
        Returns:
        price or null
      • getLastInvoicePrice

        public static BigDecimal getLastInvoicePrice​(MProduct product,
                                                     int M_ASI_ID,
                                                     int AD_Org_ID,
                                                     int C_Currency_ID)
        Get Last 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:
        last PO price in currency or null
      • create

        public static void create​(MClient client)
        Create 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 standard Costing records for Product
        Parameters:
        product - product
      • calculateAverageInv

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

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

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

        public static BigDecimal calculateLiFo​(MProduct product,
                                               int M_AttributeSetInstance_ID,
                                               MAcctSchema as,
                                               int AD_Org_ID)
        Calculate LiFo costs
        Parameters:
        product - product
        M_AttributeSetInstance_ID - asi
        as - acct schema
        AD_Org_ID - org
        Returns:
        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

        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:
        cost 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 Cumulative Amt/Qty and Current Qty
        Parameters:
        amt - amt
        qty - qty
      • setWeightedAverage

        public void setWeightedAverage​(BigDecimal amt,
                                       BigDecimal qty)
        Add Amt/Qty and calculate weighted average. ((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)
      • 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)
        Before Save
        Overrides:
        beforeSave in class PO
        Parameters:
        newRecord - new
        Returns:
        true if can be saved
      • beforeDelete

        protected boolean beforeDelete()
        Before Delete
        Overrides:
        beforeDelete in class PO
        Returns:
        true
      • main

        public static void main​(String[] args)
        Test
        Parameters:
        args - ignored