Compiere 3.1

org.compiere.model
Class MCost

java.lang.Object
  extended by org.compiere.framework.PO
      extended by org.compiere.model.X_M_Cost
          extended by org.compiere.model.MCost
All Implemented Interfaces:
Serializable, Cloneable, Comparator<PO>, 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
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.compiere.model.X_M_Cost
accessLevel, COSTINGMETHOD__, COSTINGMETHOD_AD_Reference_ID, COSTINGMETHOD_AverageInvoice, COSTINGMETHOD_AveragePO, COSTINGMETHOD_FiFo, COSTINGMETHOD_LastInvoice, COSTINGMETHOD_LastPOPrice, COSTINGMETHOD_LiFo, COSTINGMETHOD_StandardCosting, COSTINGMETHOD_UserDefined, Model, Table_ID, Table_Name, updatedMS
 
Fields inherited from class org.compiere.framework.PO
ACCESSLEVEL_ALL, ACCESSLEVEL_CLIENT, ACCESSLEVEL_CLIENTORG, ACCESSLEVEL_ORG, ACCESSLEVEL_SYSTEM, ACCESSLEVEL_SYSTEMCLIENT, ENTITYTYPE_Dictionary, ENTITYTYPE_UserMaintained, I_ZERO, log, p_changeVO, p_info, XML_ATTRIBUTE_AD_Table_ID, XML_ATTRIBUTE_Record_ID
 
Constructor Summary
MCost(Ctx ctx, int ignored, String trxName)
          Standard Constructor
MCost(Ctx ctx, ResultSet rs, String trxName)
          Load Constructor
MCost(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID)
          Parent 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, MOrg createForOrg)
          Create standard Costing records for Product
static void createForOrg(MProduct product, MOrg org)
           
static MCost get(Ctx 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(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID)
          Get/Create Cost Record.
 MCostElement getCostElement()
          Get Cost Element
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, getCostingMethod, getCumulatedAmt, getCumulatedQty, getCurrentCostPrice, getCurrentQty, getDescription, getFutureCostPrice, getLastCostPrice, getM_AttributeSetInstance_ID, getM_CostElement_ID, getM_CostType_ID, getM_Product_ID, getPercentCost, initPO, isCostingMethodValid, isProcessed, setC_AcctSchema_ID, setCostingMethod, setCumulatedAmt, setCumulatedQty, setCurrentQty, setDescription, setFutureCostPrice, setLastCostPrice, setM_AttributeSetInstance_ID, setM_CostElement_ID, setM_CostType_ID, setM_Product_ID, setPercentCost, setProcessed
 
Methods inherited from class org.compiere.framework.PO
addAttachment, addAttachment, addError, afterDelete, afterSave, compare, convertToBigDecimal, convertToBoolean, convertToInt, convertToTimestamp, copy, copyValues, copyValues, createAttachment, delete_Accounting, delete, delete, dump, dump, equals, get_ChangeVO, get_ColumnCount, get_ColumnDescription, get_ColumnDisplayType, get_ColumnIndex, get_ColumnLabel, get_ColumnLookup, get_ColumnName, get_DisplayValue, get_EntityType, get_HashMap, get_ID, get_IDOld, get_Info, get_KeyColumns, get_Logger, get_Table_ID, get_Table_ID, get_TableName, get_Translation, get_TrxName, get_Value, get_Value, get_ValueAsInt, get_ValueAsInt, get_ValueAsString, get_ValueDifference, get_ValueDifference, get_ValueOfColumn, get_ValueOld, get_ValueOld, get_ValueOldAsInt, get_ValuesAsString, get_WhereClause, get_xmlDocument, get_xmlString, get_xmlString, getAD_Client_ID, getAD_Org_ID, getAllIDs, getAttachment, getAttachment, getAttachmentData, getCreated, getCreatedBy, getCtx, getFindParameter, getPdfAttachment, getUpdated, getUpdatedBy, getVO, hashCode, insert_Accounting, is_Changed, is_KeyColumn, is_new, is_ValueChanged, is_ValueChanged, isActive, isAttachment, isColumnMandatory, isColumnUpdateable, isMandatoryOK, isPdfAttachment, load, load, load, load, loadComplete, loadDefaults, loadSpecial, lock, save, save, saveNew_getID, saveNewInsertSQL, saveNewSpecial, saveUpdate, set_ChangeVO, set_ColumnUpdateable, set_CustomColumn, set_TrxName, set_Value, set_Value, set_ValueE, set_ValueNoCheck, set_ValueNoCheckE, set_ValueOfColumn, set_ValueString, setAD_Client_ID, setAD_Org_ID, setClientOrg, setClientOrg, setContext, setCtx, setDocWorkflowMgr, setIsActive, setStandardDefaults, setUpdateable, setUpdatedBy, toStringX, unlock, update
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MCost

public MCost(Ctx ctx,
             int ignored,
             String trxName)
Standard Constructor

Parameters:
ctx - context
ignored - multi-key
trxName - trx

MCost

public MCost(Ctx 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

createForOrg

public static void createForOrg(MProduct product,
                                MOrg org)

create

protected static void create(MProduct product,
                             MOrg createForOrg)
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(Ctx 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

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

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

Compiere 3.1

Compiere® is a registered trademark of ComPiere, Inc. ©2004-2008 HumanFlash.com All rights reserved.