Adempiere 3.5.2a

org.compiere.model
Class MCost

java.lang.Object
  extended by org.compiere.model.PO
      extended by org.compiere.model.X_M_Cost
          extended by org.compiere.model.MCost
All Implemented Interfaces:
Serializable, Comparator, 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 $ Carlos Ruiz - globalqss - integrate bug fix from Teo Sarca [ 1619112 ] Posible problem for LastPO costing, Batch/Lot level
Author:
Jorg Janke
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.compiere.model.X_M_Cost
COSTINGMETHOD__, COSTINGMETHOD_AD_Reference_ID, COSTINGMETHOD_AverageInvoice, COSTINGMETHOD_AveragePO, COSTINGMETHOD_Fifo, COSTINGMETHOD_LastInvoice, COSTINGMETHOD_LastPOPrice, COSTINGMETHOD_Lifo, COSTINGMETHOD_StandardCosting, COSTINGMETHOD_UserDefined
 
Fields inherited from class org.compiere.model.PO
ACCESSLEVEL_ALL, ACCESSLEVEL_CLIENT, ACCESSLEVEL_CLIENTORG, ACCESSLEVEL_ORG, ACCESSLEVEL_SYSTEM, ACCESSLEVEL_SYSTEMCLIENT, ENTITYTYPE_Dictionary, ENTITYTYPE_UserMaintained, I_ZERO, log, p_ctx, p_info, XML_ATTRIBUTE_AD_Table_ID, XML_ATTRIBUTE_Record_ID
 
Fields inherited from interface org.compiere.model.I_M_Cost
accessLevel, COLUMNNAME_C_AcctSchema_ID, COLUMNNAME_CostingMethod, COLUMNNAME_CumulatedAmt, COLUMNNAME_CumulatedQty, COLUMNNAME_CurrentCostPrice, COLUMNNAME_CurrentCostPriceLL, COLUMNNAME_CurrentQty, COLUMNNAME_Description, COLUMNNAME_FutureCostPrice, COLUMNNAME_M_AttributeSetInstance_ID, COLUMNNAME_M_CostElement_ID, COLUMNNAME_M_CostType_ID, COLUMNNAME_M_Product_ID, COLUMNNAME_Percent, COLUMNNAME_Processed, Model, Table_ID, Table_Name
 
Constructor Summary
MCost(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID)
          Parent Constructor
MCost(Properties ctx, int ignored, String trxName)
          Standard Constructor
MCost(Properties ctx, ResultSet rs, String trxName)
          Load Constructor
 
Method Summary
 void add(BigDecimal amt, BigDecimal qty)
          Add Cumulative Amt/Qty and Current Qty
protected  boolean beforeDelete()
          Before Delete
protected  boolean beforeSave(boolean newRecord)
          Before Save
static BigDecimal calculateAverageInv(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
          Calculate Average Invoice from Trx
static BigDecimal calculateAveragePO(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
          Calculate Average PO
static BigDecimal calculateFiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
          Calculate FiFo Cost
static BigDecimal calculateLiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
          Calculate LiFo costs
static void create(MClient client)
          Create costing for client.
protected static void create(MProduct product)
          Create standard Costing records for Product
static MCost get(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID)
          Get/Create Cost Record.
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)
          Get Costs
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, String trxName)
          Get Costs Record for a Cost Type
 MCostElement getCostElement()
          Get Cost Element
static MCost[] getCosts(Properties ctx, int AD_Client_ID, int AD_Org_ID, int M_Product_ID, int M_CostType_ID, int C_AcctSchema_ID, String trxName)
          Get Costs Record for a Cost Type
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
 BigDecimal getHistoryAverage()
          Get History Average (Amt/Qty)
static BigDecimal getLastInvoicePrice(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID)
          Get Last Invoice Price in currency
static BigDecimal getLastPOPrice(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID)
          Get Last PO Price in currency
static BigDecimal getPOPrice(MProduct product, int C_OrderLine_ID, int C_Currency_ID)
          Get PO Price in currency
static BigDecimal getSeedCosts(MProduct product, int M_ASI_ID, MAcctSchema as, int Org_ID, String costingMethod, int C_OrderLine_ID)
          Get Seed Costs
static void main(String[] args)
          Test
 void setCurrentCostPrice(BigDecimal currentCostPrice)
          Set Current Cost Price
 void setWeightedAverage(BigDecimal amt, BigDecimal qty)
          Add Amt/Qty and calculate weighted average.
 String toString()
          String Representation
 
Methods inherited from class org.compiere.model.X_M_Cost
get_AccessLevel, getC_AcctSchema_ID, getC_AcctSchema, getCostingMethod, getCumulatedAmt, getCumulatedQty, getCurrentCostPrice, getCurrentCostPriceLL, getCurrentQty, getDescription, getFutureCostPrice, getM_AttributeSetInstance_ID, getM_CostElement_ID, getM_CostElement, getM_CostType_ID, getM_CostType, getM_Product_ID, getM_Product, getPercent, initPO, isProcessed, setC_AcctSchema_ID, setCostingMethod, setCumulatedAmt, setCumulatedQty, setCurrentCostPriceLL, setCurrentQty, setDescription, setFutureCostPrice, setM_AttributeSetInstance_ID, setM_CostElement_ID, setM_CostType_ID, setM_Product_ID, setPercent, setProcessed
 
Methods inherited from class org.compiere.model.PO
afterDelete, afterSave, compare, copyValues, copyValues, createAttachment, delete_Accounting, delete_Tree, delete, delete, deleteEx, deleteEx, dump, dump, equals, get_ColumnCount, get_ColumnDescription, get_ColumnDisplayType, get_ColumnIndex, get_ColumnLabel, get_ColumnLookup, get_ColumnName, get_DisplayValue, get_HashMap, get_ID, get_IDOld, get_KeyColumns, get_Logger, get_Table_ID, get_TableName, get_Translation, get_TrxName, get_Value, get_Value, get_ValueAsInt, get_ValueAsString, get_ValueDifference, get_ValueDifference, get_ValueE, get_ValueOfColumn, get_ValueOld, get_ValueOld, get_ValueOldAsInt, get_WhereClause, get_xmlDocument, get_xmlString, getAD_Client_ID, getAD_Org_ID, getAllIDs, getAttachment, getAttachment, getAttachmentData, getCreated, getCreatedBy, getCtx, getDoc, getFindParameter, getPdfAttachment, getUpdated, getUpdatedBy, insert_Accounting, insert_Tree, insert_Tree, is_Changed, is_new, is_ValueChanged, is_ValueChanged, isActive, isAttachment, isColumnMandatory, isColumnUpdateable, isMandatoryOK, isPdfAttachment, isReplication, load, load, load, load, loadComplete, loadDefaults, loadSpecial, lock, save, save, saveEx, saveEx, saveNew_getID, saveNewSpecial, saveReplica, saveUpdate, set_ColumnUpdateable, set_CustomColumn, set_TrxName, set_TrxName, set_Value, set_Value, set_ValueE, set_ValueNoCheck, set_ValueNoCheckE, set_ValueOfColumn, set_ValueOfColumn, setAD_Client_ID, setAD_Org_ID, setClientOrg, setClientOrg, setDoc, setDocWorkflowMgr, setIsActive, setReplication, setStandardDefaults, setUpdateable, setUpdatedBy, unlock
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.compiere.model.I_Persistent
save
 

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,
                                        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

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

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)
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)
Get Costs

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
Returns:
cost or null

getCosts

public static MCost[] getCosts(Properties ctx,
                               int AD_Client_ID,
                               int AD_Org_ID,
                               int M_Product_ID,
                               int M_CostType_ID,
                               int C_AcctSchema_ID,
                               String trxName)
Get Costs Record for a Cost Type

Parameters:
ctx - context
AD_Client_ID - client
AD_Org_ID - org
M_Product_ID - product
M_CostType_ID - cost type
C_AcctSchema_ID - as
TrxName - transaction name
Returns:
array costs

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,
                        String trxName)
Get Costs Record for a Cost Type

Parameters:
ctx - context
AD_Client_ID - client
AD_Org_ID - org
M_Product_ID - product
M_CostType_ID - cost type
C_AcctSchema_ID - as
TrxName - transaction name
Returns:
array costs

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

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)
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

Adempiere 3.5.2a

Adempiere® is a registered trademark of ADempiere Business Inc. ©2004-2008 HumanFlash.com All rights reserved.