IDEMPIERE-117 Add cost history table and cost movement view

This commit is contained in:
Heng Sin Low 2012-03-09 08:02:42 +08:00
parent f9d7dd29ce
commit e16e2e2525
5 changed files with 3264 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,296 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. *
* This program is free software, you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY, without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program, if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.adempiere.model;
import java.math.BigDecimal;
import java.sql.Timestamp;
import org.compiere.model.*;
import org.compiere.util.KeyNamePair;
/** Generated Interface for M_CostHistory
* @author Adempiere (generated)
* @version Release 3.6.0LTS
*/
public interface I_M_CostHistory
{
/** TableName=M_CostHistory */
public static final String Table_Name = "M_CostHistory";
/** AD_Table_ID=200001 */
public static final int Table_ID = 200001;
KeyNamePair Model = new KeyNamePair(Table_ID, Table_Name);
/** AccessLevel = 3 - Client - Org
*/
BigDecimal accessLevel = BigDecimal.valueOf(3);
/** Load Meta Data */
/** Column name AD_Client_ID */
public static final String COLUMNNAME_AD_Client_ID = "AD_Client_ID";
/** Get Client.
* Client/Tenant for this installation.
*/
public int getAD_Client_ID();
/** Column name AD_Org_ID */
public static final String COLUMNNAME_AD_Org_ID = "AD_Org_ID";
/** Set Organization.
* Organizational entity within client
*/
public void setAD_Org_ID (int AD_Org_ID);
/** Get Organization.
* Organizational entity within client
*/
public int getAD_Org_ID();
/** Column name Created */
public static final String COLUMNNAME_Created = "Created";
/** Get Created.
* Date this record was created
*/
public Timestamp getCreated();
/** Column name CreatedBy */
public static final String COLUMNNAME_CreatedBy = "CreatedBy";
/** Get Created By.
* User who created this records
*/
public int getCreatedBy();
/** Column name IsActive */
public static final String COLUMNNAME_IsActive = "IsActive";
/** Set Active.
* The record is active in the system
*/
public void setIsActive (boolean IsActive);
/** Get Active.
* The record is active in the system
*/
public boolean isActive();
/** Column name M_AttributeSetInstance_ID */
public static final String COLUMNNAME_M_AttributeSetInstance_ID = "M_AttributeSetInstance_ID";
/** Set Attribute Set Instance.
* Product Attribute Set Instance
*/
public void setM_AttributeSetInstance_ID (int M_AttributeSetInstance_ID);
/** Get Attribute Set Instance.
* Product Attribute Set Instance
*/
public int getM_AttributeSetInstance_ID();
public I_M_AttributeSetInstance getM_AttributeSetInstance() throws RuntimeException;
/** Column name M_CostDetail_ID */
public static final String COLUMNNAME_M_CostDetail_ID = "M_CostDetail_ID";
/** Set Cost Detail.
* Cost Detail Information
*/
public void setM_CostDetail_ID (int M_CostDetail_ID);
/** Get Cost Detail.
* Cost Detail Information
*/
public int getM_CostDetail_ID();
public org.compiere.model.I_M_CostDetail getM_CostDetail() throws RuntimeException;
/** Column name M_CostElement_ID */
public static final String COLUMNNAME_M_CostElement_ID = "M_CostElement_ID";
/** Set Cost Element.
* Product Cost Element
*/
public void setM_CostElement_ID (int M_CostElement_ID);
/** Get Cost Element.
* Product Cost Element
*/
public int getM_CostElement_ID();
public org.compiere.model.I_M_CostElement getM_CostElement() throws RuntimeException;
/** Column name M_CostHistory_ID */
public static final String COLUMNNAME_M_CostHistory_ID = "M_CostHistory_ID";
/** Set Cost History.
* Movement history for M_Cost
*/
public void setM_CostHistory_ID (int M_CostHistory_ID);
/** Get Cost History.
* Movement history for M_Cost
*/
public int getM_CostHistory_ID();
/** Column name M_CostHistory_UU */
public static final String COLUMNNAME_M_CostHistory_UU = "M_CostHistory_UU";
/** Set Cost History UUID */
public void setM_CostHistory_UU (String M_CostHistory_UU);
/** Get Cost History UUID */
public String getM_CostHistory_UU();
/** Column name M_CostType_ID */
public static final String COLUMNNAME_M_CostType_ID = "M_CostType_ID";
/** Set Cost Type.
* Type of Cost (e.g. Current, Plan, Future)
*/
public void setM_CostType_ID (int M_CostType_ID);
/** Get Cost Type.
* Type of Cost (e.g. Current, Plan, Future)
*/
public int getM_CostType_ID();
public org.compiere.model.I_M_CostType getM_CostType() throws RuntimeException;
/** Column name NewCAmt */
public static final String COLUMNNAME_NewCAmt = "NewCAmt";
/** Set New Accumulated Amt.
* Accumulated Amt after processing of M_CostDetail
*/
public void setNewCAmt (BigDecimal NewCAmt);
/** Get New Accumulated Amt.
* Accumulated Amt after processing of M_CostDetail
*/
public BigDecimal getNewCAmt();
/** Column name NewCostPrice */
public static final String COLUMNNAME_NewCostPrice = "NewCostPrice";
/** Set New Cost Price.
* New current cost price after processing of M_CostDetail
*/
public void setNewCostPrice (BigDecimal NewCostPrice);
/** Get New Cost Price.
* New current cost price after processing of M_CostDetail
*/
public BigDecimal getNewCostPrice();
/** Column name NewCQty */
public static final String COLUMNNAME_NewCQty = "NewCQty";
/** Set New Accumulated Qty.
* New Accumulated Qty after processing of M_CostDetail
*/
public void setNewCQty (BigDecimal NewCQty);
/** Get New Accumulated Qty.
* New Accumulated Qty after processing of M_CostDetail
*/
public BigDecimal getNewCQty();
/** Column name NewQty */
public static final String COLUMNNAME_NewQty = "NewQty";
/** Set New Current Quantity.
* New current quantity after processing of M_CostDetail
*/
public void setNewQty (BigDecimal NewQty);
/** Get New Current Quantity.
* New current quantity after processing of M_CostDetail
*/
public BigDecimal getNewQty();
/** Column name OldCAmt */
public static final String COLUMNNAME_OldCAmt = "OldCAmt";
/** Set Old Accumulated Amt.
* Old accumulated amt before the processing of M_CostDetail
*/
public void setOldCAmt (BigDecimal OldCAmt);
/** Get Old Accumulated Amt.
* Old accumulated amt before the processing of M_CostDetail
*/
public BigDecimal getOldCAmt();
/** Column name OldCostPrice */
public static final String COLUMNNAME_OldCostPrice = "OldCostPrice";
/** Set Old Current Cost Price.
* Old current cost price before the processing of M_CostDetail
*/
public void setOldCostPrice (BigDecimal OldCostPrice);
/** Get Old Current Cost Price.
* Old current cost price before the processing of M_CostDetail
*/
public BigDecimal getOldCostPrice();
/** Column name OldCQty */
public static final String COLUMNNAME_OldCQty = "OldCQty";
/** Set Old Accumulated Qty.
* Old accumulated qty before the processing of M_CostDetail
*/
public void setOldCQty (BigDecimal OldCQty);
/** Get Old Accumulated Qty.
* Old accumulated qty before the processing of M_CostDetail
*/
public BigDecimal getOldCQty();
/** Column name OldQty */
public static final String COLUMNNAME_OldQty = "OldQty";
/** Set Old Current Quantity.
* Old current quantity before the processing of M_CostDetail
*/
public void setOldQty (BigDecimal OldQty);
/** Get Old Current Quantity.
* Old current quantity before the processing of M_CostDetail
*/
public BigDecimal getOldQty();
/** Column name Updated */
public static final String COLUMNNAME_Updated = "Updated";
/** Get Updated.
* Date this record was updated
*/
public Timestamp getUpdated();
/** Column name UpdatedBy */
public static final String COLUMNNAME_UpdatedBy = "UpdatedBy";
/** Get Updated By.
* User who updated this records
*/
public int getUpdatedBy();
}

View File

@ -0,0 +1,392 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. *
* This program is free software, you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY, without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program, if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
/** Generated Model - DO NOT CHANGE */
package org.adempiere.model;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.model.*;
import org.compiere.util.Env;
/** Generated Model for M_CostHistory
* @author Adempiere (generated)
* @version Release 3.6.0LTS - $Id$ */
public class X_M_CostHistory extends PO implements I_M_CostHistory, I_Persistent
{
/**
*
*/
private static final long serialVersionUID = 20120308L;
/** Standard Constructor */
public X_M_CostHistory (Properties ctx, int M_CostHistory_ID, String trxName)
{
super (ctx, M_CostHistory_ID, trxName);
/** if (M_CostHistory_ID == 0)
{
setM_AttributeSetInstance_ID (0);
setM_CostDetail_ID (0);
setM_CostElement_ID (0);
setM_CostHistory_ID (0);
setM_CostHistory_UU (null);
setM_CostType_ID (0);
setNewCostPrice (Env.ZERO);
setNewQty (Env.ZERO);
setOldCostPrice (Env.ZERO);
setOldQty (Env.ZERO);
} */
}
/** Load Constructor */
public X_M_CostHistory (Properties ctx, ResultSet rs, String trxName)
{
super (ctx, rs, trxName);
}
/** AccessLevel
* @return 3 - Client - Org
*/
protected int get_AccessLevel()
{
return accessLevel.intValue();
}
/** Load Meta Data */
protected POInfo initPO (Properties ctx)
{
POInfo poi = POInfo.getPOInfo (ctx, Table_ID, get_TrxName());
return poi;
}
public String toString()
{
StringBuffer sb = new StringBuffer ("X_M_CostHistory[")
.append(get_ID()).append("]");
return sb.toString();
}
public I_M_AttributeSetInstance getM_AttributeSetInstance() throws RuntimeException
{
return (I_M_AttributeSetInstance)MTable.get(getCtx(), I_M_AttributeSetInstance.Table_Name)
.getPO(getM_AttributeSetInstance_ID(), get_TrxName()); }
/** Set Attribute Set Instance.
@param M_AttributeSetInstance_ID
Product Attribute Set Instance
*/
public void setM_AttributeSetInstance_ID (int M_AttributeSetInstance_ID)
{
if (M_AttributeSetInstance_ID < 0)
set_ValueNoCheck (COLUMNNAME_M_AttributeSetInstance_ID, null);
else
set_ValueNoCheck (COLUMNNAME_M_AttributeSetInstance_ID, Integer.valueOf(M_AttributeSetInstance_ID));
}
/** Get Attribute Set Instance.
@return Product Attribute Set Instance
*/
public int getM_AttributeSetInstance_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_M_AttributeSetInstance_ID);
if (ii == null)
return 0;
return ii.intValue();
}
public org.compiere.model.I_M_CostDetail getM_CostDetail() throws RuntimeException
{
return (org.compiere.model.I_M_CostDetail)MTable.get(getCtx(), org.compiere.model.I_M_CostDetail.Table_Name)
.getPO(getM_CostDetail_ID(), get_TrxName()); }
/** Set Cost Detail.
@param M_CostDetail_ID
Cost Detail Information
*/
public void setM_CostDetail_ID (int M_CostDetail_ID)
{
if (M_CostDetail_ID < 1)
set_ValueNoCheck (COLUMNNAME_M_CostDetail_ID, null);
else
set_ValueNoCheck (COLUMNNAME_M_CostDetail_ID, Integer.valueOf(M_CostDetail_ID));
}
/** Get Cost Detail.
@return Cost Detail Information
*/
public int getM_CostDetail_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_M_CostDetail_ID);
if (ii == null)
return 0;
return ii.intValue();
}
public org.compiere.model.I_M_CostElement getM_CostElement() throws RuntimeException
{
return (org.compiere.model.I_M_CostElement)MTable.get(getCtx(), org.compiere.model.I_M_CostElement.Table_Name)
.getPO(getM_CostElement_ID(), get_TrxName()); }
/** Set Cost Element.
@param M_CostElement_ID
Product Cost Element
*/
public void setM_CostElement_ID (int M_CostElement_ID)
{
if (M_CostElement_ID < 1)
set_ValueNoCheck (COLUMNNAME_M_CostElement_ID, null);
else
set_ValueNoCheck (COLUMNNAME_M_CostElement_ID, Integer.valueOf(M_CostElement_ID));
}
/** Get Cost Element.
@return Product Cost Element
*/
public int getM_CostElement_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_M_CostElement_ID);
if (ii == null)
return 0;
return ii.intValue();
}
/** Set Cost History.
@param M_CostHistory_ID
Movement history for M_Cost
*/
public void setM_CostHistory_ID (int M_CostHistory_ID)
{
if (M_CostHistory_ID < 1)
set_ValueNoCheck (COLUMNNAME_M_CostHistory_ID, null);
else
set_ValueNoCheck (COLUMNNAME_M_CostHistory_ID, Integer.valueOf(M_CostHistory_ID));
}
/** Get Cost History.
@return Movement history for M_Cost
*/
public int getM_CostHistory_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_M_CostHistory_ID);
if (ii == null)
return 0;
return ii.intValue();
}
/** Set Cost History UUID.
@param M_CostHistory_UU Cost History UUID */
public void setM_CostHistory_UU (String M_CostHistory_UU)
{
set_ValueNoCheck (COLUMNNAME_M_CostHistory_UU, M_CostHistory_UU);
}
/** Get Cost History UUID.
@return Cost History UUID */
public String getM_CostHistory_UU ()
{
return (String)get_Value(COLUMNNAME_M_CostHistory_UU);
}
public org.compiere.model.I_M_CostType getM_CostType() throws RuntimeException
{
return (org.compiere.model.I_M_CostType)MTable.get(getCtx(), org.compiere.model.I_M_CostType.Table_Name)
.getPO(getM_CostType_ID(), get_TrxName()); }
/** Set Cost Type.
@param M_CostType_ID
Type of Cost (e.g. Current, Plan, Future)
*/
public void setM_CostType_ID (int M_CostType_ID)
{
if (M_CostType_ID < 1)
set_ValueNoCheck (COLUMNNAME_M_CostType_ID, null);
else
set_ValueNoCheck (COLUMNNAME_M_CostType_ID, Integer.valueOf(M_CostType_ID));
}
/** Get Cost Type.
@return Type of Cost (e.g. Current, Plan, Future)
*/
public int getM_CostType_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_M_CostType_ID);
if (ii == null)
return 0;
return ii.intValue();
}
/** Set New Accumulated Amt.
@param NewCAmt
Accumulated Amt after processing of M_CostDetail
*/
public void setNewCAmt (BigDecimal NewCAmt)
{
set_ValueNoCheck (COLUMNNAME_NewCAmt, NewCAmt);
}
/** Get New Accumulated Amt.
@return Accumulated Amt after processing of M_CostDetail
*/
public BigDecimal getNewCAmt ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_NewCAmt);
if (bd == null)
return Env.ZERO;
return bd;
}
/** Set New Cost Price.
@param NewCostPrice
New current cost price after processing of M_CostDetail
*/
public void setNewCostPrice (BigDecimal NewCostPrice)
{
set_ValueNoCheck (COLUMNNAME_NewCostPrice, NewCostPrice);
}
/** Get New Cost Price.
@return New current cost price after processing of M_CostDetail
*/
public BigDecimal getNewCostPrice ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_NewCostPrice);
if (bd == null)
return Env.ZERO;
return bd;
}
/** Set New Accumulated Qty.
@param NewCQty
New Accumulated Qty after processing of M_CostDetail
*/
public void setNewCQty (BigDecimal NewCQty)
{
set_ValueNoCheck (COLUMNNAME_NewCQty, NewCQty);
}
/** Get New Accumulated Qty.
@return New Accumulated Qty after processing of M_CostDetail
*/
public BigDecimal getNewCQty ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_NewCQty);
if (bd == null)
return Env.ZERO;
return bd;
}
/** Set New Current Quantity.
@param NewQty
New current quantity after processing of M_CostDetail
*/
public void setNewQty (BigDecimal NewQty)
{
set_ValueNoCheck (COLUMNNAME_NewQty, NewQty);
}
/** Get New Current Quantity.
@return New current quantity after processing of M_CostDetail
*/
public BigDecimal getNewQty ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_NewQty);
if (bd == null)
return Env.ZERO;
return bd;
}
/** Set Old Accumulated Amt.
@param OldCAmt
Old accumulated amt before the processing of M_CostDetail
*/
public void setOldCAmt (BigDecimal OldCAmt)
{
set_ValueNoCheck (COLUMNNAME_OldCAmt, OldCAmt);
}
/** Get Old Accumulated Amt.
@return Old accumulated amt before the processing of M_CostDetail
*/
public BigDecimal getOldCAmt ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_OldCAmt);
if (bd == null)
return Env.ZERO;
return bd;
}
/** Set Old Current Cost Price.
@param OldCostPrice
Old current cost price before the processing of M_CostDetail
*/
public void setOldCostPrice (BigDecimal OldCostPrice)
{
set_ValueNoCheck (COLUMNNAME_OldCostPrice, OldCostPrice);
}
/** Get Old Current Cost Price.
@return Old current cost price before the processing of M_CostDetail
*/
public BigDecimal getOldCostPrice ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_OldCostPrice);
if (bd == null)
return Env.ZERO;
return bd;
}
/** Set Old Accumulated Qty.
@param OldCQty
Old accumulated qty before the processing of M_CostDetail
*/
public void setOldCQty (BigDecimal OldCQty)
{
set_ValueNoCheck (COLUMNNAME_OldCQty, OldCQty);
}
/** Get Old Accumulated Qty.
@return Old accumulated qty before the processing of M_CostDetail
*/
public BigDecimal getOldCQty ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_OldCQty);
if (bd == null)
return Env.ZERO;
return bd;
}
/** Set Old Current Quantity.
@param OldQty
Old current quantity before the processing of M_CostDetail
*/
public void setOldQty (BigDecimal OldQty)
{
set_ValueNoCheck (COLUMNNAME_OldQty, OldQty);
}
/** Get Old Current Quantity.
@return Old current quantity before the processing of M_CostDetail
*/
public BigDecimal getOldQty ()
{
BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_OldQty);
if (bd == null)
return Env.ZERO;
return bd;
}
}

View File

@ -23,6 +23,7 @@ import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.model.X_M_CostHistory;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
@ -826,10 +827,25 @@ public class MCostDetail extends X_M_CostDetail
{
MCost cost = MCost.get(product, M_ASI_ID, as,
Org_ID, ce.getM_CostElement_ID(), get_TrxName());
DB.getDatabase().forUpdate(cost, 120);
// if (cost == null)
// cost = new MCost(product, M_ASI_ID,
// as, Org_ID, ce.getM_CostElement_ID());
//save history for m_cost
X_M_CostHistory history = new X_M_CostHistory(getCtx(), 0, get_TrxName());
history.setM_AttributeSetInstance_ID(cost.getM_AttributeSetInstance_ID());
history.setM_CostDetail_ID(this.getM_CostDetail_ID());
history.setM_CostElement_ID(ce.getM_CostElement_ID());
history.setM_CostType_ID(cost.getM_CostType_ID());
history.setClientOrg(cost.getAD_Client_ID(), cost.getAD_Org_ID());
history.setOldQty(cost.getCurrentQty());
history.setOldCostPrice(cost.getCurrentCostPrice());
history.setOldCAmt(cost.getCumulatedAmt());
history.setOldCQty(cost.getCumulatedQty());
// MZ Goodwill
// used deltaQty and deltaAmt if exist
BigDecimal qty = Env.ZERO;
@ -1169,6 +1185,15 @@ public class MCostDetail extends X_M_CostDetail
setCurrentQty(cost.getCurrentQty());
setCumulatedAmt(cost.getCumulatedAmt());
setCumulatedQty(cost.getCumulatedQty());
//update history
history.setNewQty(cost.getCurrentQty());
history.setNewCostPrice(cost.getCurrentCostPrice());
history.setNewCAmt(cost.getCumulatedAmt());
history.setNewCQty(cost.getCumulatedQty());
if (!history.save())
return false;
return cost.save();
} // process