commit modified asset classes
add workaround for customer service asset (not fixed assets) transplanted from https://bitbucket.org/edwin_ang/adempiere361-mbd/changeset/b421d5c https://bitbucket.org/edwin_ang/adempiere361-mbd/changeset/83eeb45
This commit is contained in:
parent
02c508d425
commit
f75aeb5aba
|
@ -299,7 +299,7 @@ public class AssetDelivery extends SvrProcess
|
||||||
//
|
//
|
||||||
log.fine((System.currentTimeMillis()-start) + " ms");
|
log.fine((System.currentTimeMillis()-start) + " ms");
|
||||||
// success
|
// success
|
||||||
StringBuilder msgreturn = new StringBuilder().append(user.getEMail()).append(" - ").append(asset.getProductVersionNo());
|
StringBuilder msgreturn = new StringBuilder().append(user.getEMail()).append(" - ").append(asset.getVersionNo());
|
||||||
return msgreturn.toString();
|
return msgreturn.toString();
|
||||||
} // deliverIt
|
} // deliverIt
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,168 +1,184 @@
|
||||||
/******************************************************************************
|
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
|
||||||
* Copyright (C) 1999-2006 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.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.math.BigDecimal;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.compiere.util.DB;
|
import org.apache.commons.collections.keyvalue.MultiKey;
|
||||||
|
import org.compiere.model.MAccount;
|
||||||
|
import org.compiere.model.MAcctSchema;
|
||||||
|
import org.compiere.model.ProductCost;
|
||||||
|
import org.compiere.model.Query;
|
||||||
|
import org.compiere.util.CCache;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.TimeUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asset Addition Model
|
* Asset Acct Model
|
||||||
*
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class MAssetAcct extends X_A_Asset_Acct {
|
public class MAssetAcct extends X_A_Asset_Acct
|
||||||
/**
|
{
|
||||||
*
|
private static final long serialVersionUID = 1L;
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 4779953750434068382L;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default ConstructorX_A_Asset_Group_Acct
|
* DO NOT USE DIRECTLY
|
||||||
*
|
|
||||||
* @param ctx
|
|
||||||
* context
|
|
||||||
* @param M_InventoryLine_ID
|
|
||||||
* line
|
|
||||||
*/
|
*/
|
||||||
public MAssetAcct(Properties ctx, int X_A_Asset_Acct_ID, String trxName) {
|
public MAssetAcct (Properties ctx, int X_A_Asset_Acct_ID, String trxName)
|
||||||
super(ctx, X_A_Asset_Acct_ID, trxName);
|
{
|
||||||
if (X_A_Asset_Acct_ID == 0) {
|
super (ctx,X_A_Asset_Acct_ID, trxName);
|
||||||
//
|
if (X_A_Asset_Acct_ID == 0)
|
||||||
|
{
|
||||||
|
setA_Salvage_Value(Env.ZERO);
|
||||||
}
|
}
|
||||||
} // MAssetAddition
|
}
|
||||||
|
|
||||||
|
public MAssetAcct (Properties ctx, ResultSet rs, String trxName)
|
||||||
|
{
|
||||||
|
super (ctx, rs, trxName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Static Cache: A_Asset_Acct_ID -> MAssetAcct */
|
||||||
|
private static CCache<Integer,MAssetAcct> s_cache = new CCache<Integer,MAssetAcct>(Table_Name, 5);
|
||||||
|
/** Static Cache: Asset,PostingType,DateAcct -> MAssetAcct */
|
||||||
|
private static CCache<MultiKey,MAssetAcct> s_cacheAsset = new CCache<MultiKey,MAssetAcct>(Table_Name+"_Asset", 5);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load Constructor
|
* Get Asset Accounting (from cache)
|
||||||
*
|
* @param ctx context
|
||||||
* @param ctx
|
* @param A_Asset_Acct_ID asset accounting id
|
||||||
* context
|
* @return asset accounting or null if not found
|
||||||
* @param rs
|
|
||||||
* result set
|
|
||||||
*/
|
*/
|
||||||
public MAssetAcct(Properties ctx, ResultSet rs, String trxName) {
|
public static MAssetAcct get (Properties ctx, int A_Asset_Acct_ID)
|
||||||
super(ctx, rs, trxName);
|
{
|
||||||
} // MInventoryLine
|
MAssetAcct acct = s_cache.get(A_Asset_Acct_ID);
|
||||||
|
if (acct != null)
|
||||||
protected boolean afterSave(boolean newRecord, boolean success) {
|
{
|
||||||
log.info("afterSave");
|
return acct;
|
||||||
int p_actasset_ID = getA_Asset_Acct_ID();
|
}
|
||||||
int p_A_Asset_ID = getA_Asset_ID();
|
acct = new MAssetAcct(ctx, A_Asset_Acct_ID, null);
|
||||||
|
if (acct.get_ID() > 0)
|
||||||
if (isProcessing() == true) {
|
{
|
||||||
MAssetChange change = new MAssetChange(getCtx(), 0, null);
|
addToCache(acct, null);
|
||||||
change.setChangeType("SET");
|
}
|
||||||
change.setTextDetails(MRefList.getListDescription(getCtx(),
|
else
|
||||||
"A_Update_Type", "SET"));
|
{
|
||||||
change.setPostingType(getPostingType());
|
acct = null;
|
||||||
change.setA_Split_Percent(getA_Split_Percent());
|
}
|
||||||
change.setConventionType(getA_Depreciation_Conv_ID());
|
return acct;
|
||||||
change.setA_Salvage_Value(getA_Salvage_Value());
|
}
|
||||||
change.setA_Asset_ID(getA_Asset_ID());
|
|
||||||
change.setDepreciationType(getA_Depreciation_ID());
|
/**
|
||||||
change.setA_Asset_Spread_Type(getA_Asset_Spread_ID());
|
* Get asset accounting.
|
||||||
change.setA_Period_Start(getA_Period_Start());
|
* @param ctx context
|
||||||
change.setA_Period_End(getA_Period_End());
|
* @param A_Asset_ID asset
|
||||||
change.setA_Depreciation_Calc_Type(getA_Depreciation_Method_ID());
|
* @param postingType Posting type
|
||||||
change.setA_Asset_Acct(getA_Asset_Acct());
|
* @param dateAcct check ValidFrom
|
||||||
change.setC_AcctSchema_ID(getC_AcctSchema_ID());
|
* @return asset accounting for the given asset
|
||||||
change.setA_Accumdepreciation_Acct(getA_Accumdepreciation_Acct());
|
*/
|
||||||
change.setA_Depreciation_Acct(getA_Depreciation_Acct());
|
public static MAssetAcct forA_Asset_ID (Properties ctx, int A_Asset_ID, String postingType, Timestamp dateAcct, String trxName)
|
||||||
change.setA_Disposal_Revenue(getA_Disposal_Revenue());
|
{
|
||||||
change.setA_Disposal_Loss(getA_Disposal_Loss());
|
MultiKey key = new MultiKey(A_Asset_ID, postingType, dateAcct);
|
||||||
change.setA_Reval_Accumdep_Offset_Cur(getA_Reval_Accumdep_Offset_Cur());
|
MAssetAcct acct = null;
|
||||||
change.setA_Reval_Accumdep_Offset_Prior(getA_Reval_Accumdep_Offset_Prior());
|
if (trxName == null)
|
||||||
if (getA_Reval_Cal_Method() == null)
|
{
|
||||||
change.setA_Reval_Cal_Method("DFT");
|
// do not use cache
|
||||||
else
|
//acct = s_cacheAsset.get(key);
|
||||||
change.setA_Reval_Cal_Method(getA_Reval_Cal_Method());
|
}
|
||||||
change.setA_Reval_Cost_Offset(getA_Reval_Cost_Offset());
|
if (acct != null)
|
||||||
change.setA_Reval_Cost_Offset_Prior(getA_Reval_Cost_Offset_Prior());
|
{
|
||||||
change.setA_Reval_Depexp_Offset(getA_Reval_Depexp_Offset());
|
return acct;
|
||||||
change.setA_Depreciation_Manual_Amount(getA_Depreciation_Manual_Amount());
|
}
|
||||||
change.setA_Depreciation_Manual_Period(getA_Depreciation_Manual_Period());
|
//
|
||||||
change.setA_Depreciation_Table_Header_ID(getA_Depreciation_Table_Header_ID());
|
ArrayList<Object> params = new ArrayList<Object>();
|
||||||
change.setA_Depreciation_Variable_Perc(getA_Depreciation_Variable_Perc());
|
StringBuffer whereClause = new StringBuffer(COLUMNNAME_A_Asset_ID+"=? AND "+COLUMNNAME_PostingType+"=?");
|
||||||
change.saveEx();
|
params.add(A_Asset_ID);
|
||||||
|
params.add(postingType);
|
||||||
String sql = "SELECT * FROM A_Depreciation_Workfile WHERE A_Asset_ID=? AND IsActive='Y'";
|
if (dateAcct != null)
|
||||||
PreparedStatement pstmt = null;
|
{
|
||||||
try {
|
whereClause.append(" AND " + COLUMNNAME_ValidFrom).append("<=?");
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
params.add(dateAcct);
|
||||||
pstmt.setInt(1, p_A_Asset_ID);
|
}
|
||||||
ResultSet rs = pstmt.executeQuery();
|
acct = new Query(ctx, Table_Name, whereClause.toString(), trxName)
|
||||||
|
.setParameters(params)
|
||||||
while (rs.next()) {
|
.setOrderBy(COLUMNNAME_ValidFrom+" DESC NULLS LAST")
|
||||||
// MADepreciationWorkfile asset = new MADepreciationWorkfile
|
.first();
|
||||||
// (getCtx(), rs.getInt("A_Depreciation_Workfile_ID"));
|
if (trxName == null)
|
||||||
X_A_Depreciation_Workfile assetwk = new X_A_Depreciation_Workfile(
|
{
|
||||||
getCtx(), rs, null);
|
addToCache(acct, key);
|
||||||
assetwk.setA_Salvage_Value(getA_Salvage_Value());
|
}
|
||||||
assetwk.saveEx();
|
return acct;
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
private static void addToCache(MAssetAcct acct, MultiKey keyAsset)
|
||||||
pstmt = null;
|
{
|
||||||
} catch (Exception e) {
|
if (acct == null || acct.get_ID() <= 0)
|
||||||
log.info("getAssets" + e);
|
{
|
||||||
} finally {
|
return;
|
||||||
try {
|
}
|
||||||
if (pstmt != null)
|
s_cache.put(acct.get_ID(), acct);
|
||||||
pstmt.close();
|
if (keyAsset != null)
|
||||||
} catch (Exception e) {
|
{
|
||||||
}
|
s_cacheAsset.put(keyAsset, acct);
|
||||||
pstmt = null;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
/**
|
||||||
X_A_Asset_Acct assetacct = new X_A_Asset_Acct(getCtx(),
|
* Create new asset accounting from asset group accounting
|
||||||
p_actasset_ID, this.get_TrxName());
|
* @param asset asset
|
||||||
assetacct.setPostingType(getPostingType());
|
* @param assetgrpacct asset group accounting
|
||||||
assetacct.setA_Split_Percent(getA_Split_Percent());
|
*/
|
||||||
assetacct.setA_Depreciation_Conv_ID(getA_Depreciation_Conv_ID());
|
public MAssetAcct(MAsset asset, MAssetGroupAcct assetgrpacct)
|
||||||
assetacct.setA_Salvage_Value(getA_Salvage_Value());
|
{
|
||||||
assetacct.setA_Asset_ID(getA_Asset_ID());
|
this(assetgrpacct.getCtx(), 0, asset.get_TrxName());
|
||||||
assetacct.setA_Depreciation_ID(getA_Depreciation_ID());
|
|
||||||
assetacct.setA_Asset_Spread_ID(getA_Asset_Spread_ID());
|
SetGetUtil.copyValues(this, assetgrpacct, null, null);
|
||||||
assetacct.setA_Period_Start(getA_Period_Start());
|
setA_Asset_ID(asset.getA_Asset_ID());
|
||||||
assetacct.setA_Depreciation_Method_ID(getA_Depreciation_Method_ID());
|
if (asset.getA_Depreciation_ID() > 0)
|
||||||
assetacct.setA_Asset_Acct(getA_Asset_Acct());
|
{
|
||||||
assetacct.setC_AcctSchema_ID(getC_AcctSchema_ID());
|
setA_Depreciation_ID(asset.getA_Depreciation_ID());
|
||||||
assetacct.setA_Accumdepreciation_Acct(getA_Accumdepreciation_Acct());
|
}
|
||||||
assetacct.setA_Depreciation_Acct(getA_Depreciation_Acct());
|
if (asset.getA_Depreciation_F_ID() > 0)
|
||||||
assetacct.setA_Disposal_Revenue(getA_Disposal_Revenue());
|
{
|
||||||
assetacct.setA_Disposal_Loss(getA_Disposal_Loss());
|
setA_Depreciation_F_ID(asset.getA_Depreciation_F_ID());
|
||||||
assetacct.setA_Reval_Accumdep_Offset_Cur(getA_Reval_Accumdep_Offset_Cur());
|
}
|
||||||
assetacct.setA_Reval_Accumdep_Offset_Prior(getA_Reval_Accumdep_Offset_Prior());
|
setA_Period_Start(1);
|
||||||
assetacct.setA_Reval_Cal_Method(getA_Reval_Cal_Method());
|
setA_Period_End(asset.getUseLifeMonths());
|
||||||
assetacct.setA_Reval_Cost_Offset(getA_Reval_Cost_Offset());
|
//~ setProcessing(false);
|
||||||
assetacct.setA_Reval_Cost_Offset_Prior(getA_Reval_Cost_Offset_Prior());
|
dump();
|
||||||
assetacct.setA_Reval_Depexp_Offset(getA_Reval_Depexp_Offset());
|
}
|
||||||
assetacct.setA_Depreciation_Manual_Amount(getA_Depreciation_Manual_Amount());
|
|
||||||
assetacct.setA_Depreciation_Manual_Period(getA_Depreciation_Manual_Period());
|
/**
|
||||||
assetacct.setA_Depreciation_Table_Header_ID(getA_Depreciation_Table_Header_ID());
|
*
|
||||||
assetacct.setA_Depreciation_Variable_Perc(getA_Depreciation_Variable_Perc());
|
*/
|
||||||
assetacct.setProcessing(true);
|
public BigDecimal getA_Depreciation_Variable_Perc(boolean fiscal)
|
||||||
assetacct.saveEx();
|
{
|
||||||
|
return fiscal ? getA_Depreciation_Variable_Perc_F() : getA_Depreciation_Variable_Perc();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public MAcctSchema getC_AcctSchema()
|
||||||
|
{
|
||||||
|
return MAcctSchema.get(getCtx(), getC_AcctSchema_ID());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MAccount getP_Asset_Acct(int M_Product_ID)
|
||||||
|
{
|
||||||
|
MAcctSchema as = getC_AcctSchema();
|
||||||
|
ProductCost pc = new ProductCost(getCtx(), M_Product_ID, 0, null);
|
||||||
|
return pc.getAccount(ProductCost.ACCTTYPE_P_Asset, as);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean beforeSave(boolean newRecord) {
|
||||||
|
if (getValidFrom() == null && newRecord)
|
||||||
|
{
|
||||||
|
setValidFrom(TimeUtil.getDay(1970, 01, 01)); // FIXME
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // MAssetAddition
|
|
||||||
|
} // class MAssetAcct
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,36 +1,38 @@
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
* The contents of this file are subject to the Compiere License Version 1.1
|
||||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
* ("License"); You may not use this file except in compliance with the License
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
* You may obtain a copy of the License at http://www.compiere.org/license.html
|
||||||
* under the terms version 2 of the GNU General Public License as published *
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
* by the Free Software Foundation. This program is distributed in the hope *
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
||||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
* the specific language governing rights and limitations under the License.
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
* The Original Code is Compiere ERP & CRM Smart Business Solution
|
||||||
* See the GNU General Public License for more details. *
|
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
|
||||||
* You should have received a copy of the GNU General Public License along *
|
* Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
* Contributor(s): ______________________________________.
|
||||||
* 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.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.compiere.model.MRefList;
|
||||||
|
import org.compiere.model.PO;
|
||||||
|
import org.compiere.util.CLogMgt;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asset Addition Model
|
* Asset Addition Model
|
||||||
*
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MAssetChange extends X_A_Asset_Change
|
public class MAssetChange extends X_A_Asset_Change
|
||||||
{
|
{
|
||||||
/**
|
private static final long serialVersionUID = 1L;
|
||||||
*
|
|
||||||
*/
|
/** Static Logger */
|
||||||
private static final long serialVersionUID = 5906751299228645904L;
|
private static CLogger s_log = CLogger.getCLogger(MAssetChange.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -39,12 +41,8 @@ public class MAssetChange extends X_A_Asset_Change
|
||||||
public MAssetChange (Properties ctx, int A_Asset_Change_ID, String trxName)
|
public MAssetChange (Properties ctx, int A_Asset_Change_ID, String trxName)
|
||||||
{
|
{
|
||||||
super (ctx, A_Asset_Change_ID, trxName);
|
super (ctx, A_Asset_Change_ID, trxName);
|
||||||
if (A_Asset_Change_ID == 0)
|
} // MAssetChange
|
||||||
{
|
|
||||||
//
|
|
||||||
|
|
||||||
}
|
|
||||||
} // MAssetAddition
|
|
||||||
/**
|
/**
|
||||||
* Load Constructor
|
* Load Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -61,11 +59,94 @@ public class MAssetChange extends X_A_Asset_Change
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
protected boolean beforeSave (boolean newRecord)
|
protected boolean beforeSave (boolean newRecord)
|
||||||
{
|
{
|
||||||
if (getA_Reval_Cal_Method() == null)
|
String textDetails = getTextDetails();
|
||||||
setA_Reval_Cal_Method("DFT");
|
if (textDetails == null || textDetails.length() == 0) {
|
||||||
|
setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , getChangeType()));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} // beforeSave
|
} // beforeSave
|
||||||
|
|
||||||
|
/** ARHIPAC: TEO: BEGIN ------------------------------------------------------------------ */
|
||||||
} // MAssetAddition
|
public void setSerno(String value) { setSerNo(value); }
|
||||||
|
public void setVersionno(String value) { setVersionNo(value); }
|
||||||
|
public void setAd_User_ID(int value) { setAD_User_ID(value); }
|
||||||
|
|
||||||
|
public static MAssetChange createAddition(MAssetAddition assetAdd, MDepreciationWorkfile assetwk) {
|
||||||
|
MAssetChange change = new MAssetChange (assetAdd.getCtx(), 0, assetAdd.get_TrxName());
|
||||||
|
change.setAD_Org_ID(assetAdd.getAD_Org_ID()); //@win added
|
||||||
|
change.setA_Asset_ID(assetAdd.getA_Asset_ID());
|
||||||
|
change.setA_QTY_Current(assetAdd.getA_QTY_Current());
|
||||||
|
change.setChangeType("ADD");
|
||||||
|
change.setTextDetails(MRefList.getListDescription (assetAdd.getCtx(),"A_Update_Type" , "ADD"));
|
||||||
|
change.setPostingType(assetwk.getPostingType());
|
||||||
|
change.setAssetValueAmt(assetAdd.getAssetValueAmt());
|
||||||
|
change.setA_QTY_Current(assetAdd.getA_QTY_Current());
|
||||||
|
change.saveEx();
|
||||||
|
|
||||||
|
return change;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MAssetChange create(Properties ctx, String changeType, PO[] pos, String trxName) {
|
||||||
|
return create(ctx, changeType, pos, false, trxName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
* @param ctx
|
||||||
|
* @param changeType
|
||||||
|
* @param pos
|
||||||
|
* @param trxName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static MAssetChange createAndSave(Properties ctx, String changeType, PO[] pos, String trxName) {
|
||||||
|
return null;
|
||||||
|
//~ return create(ctx, changeType, pos, true, trxName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MAssetChange create(Properties ctx, String changeType, PO[] pos, boolean save, String trxName) {
|
||||||
|
s_log.fine("Entering: changeType=" + changeType);
|
||||||
|
if (pos == null || pos.length == 0) {
|
||||||
|
s_log.fine("Entering/Leaving: POs is empty");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MAssetChange change = new MAssetChange (ctx, 0, trxName);
|
||||||
|
change.setChangeType(changeType);
|
||||||
|
for (PO po : pos) {
|
||||||
|
change.addChanges(po);
|
||||||
|
}
|
||||||
|
if (save) {
|
||||||
|
change.saveEx();
|
||||||
|
}
|
||||||
|
//
|
||||||
|
s_log.fine("Leaving: change=" + change);
|
||||||
|
return change;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChanges(PO po) {
|
||||||
|
if(CLogMgt.isLevelFine()) log.fine("Entering: po=" + po);
|
||||||
|
if (po == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* arhipac: teo_sarca: TODO need to integrate
|
||||||
|
for(int idx = 0; idx < po.get_ColumnCount_P(); idx++) {
|
||||||
|
//~ if(!po.is_ValueChanged(idx)) {
|
||||||
|
//~ continue;
|
||||||
|
//~ }
|
||||||
|
String colName = po.get_ColumnName_P(idx);
|
||||||
|
int idx2 = get_ColumnIndex(colName);
|
||||||
|
if(idx2 < 0) {
|
||||||
|
if(CLogMgt.isLevelFine()) log.fine("Setting " + colName + ": SKIP (idx2 < 0)");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object value = po.get_Value(idx2);
|
||||||
|
set_Value(colName, value);
|
||||||
|
if(CLogMgt.isLevelFine()) log.fine("Setting " + colName + "=" + value + " (from " + po.getClass() + ", idx=" + idx + ", idx2=" + idx2 + ")");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
//
|
||||||
|
if(CLogMgt.isLevelFine()) log.fine("Leaving: po=" + po);
|
||||||
|
}
|
||||||
|
/** ARHIPAC: TEO: END ------------------------------------------------------------------ */
|
||||||
|
} // MAssetChange
|
|
@ -1,86 +1,169 @@
|
||||||
/******************************************************************************
|
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
|
||||||
* Copyright (C) 1999-2006 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.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.compiere.util.CCache;
|
import org.compiere.util.CCache;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asset Group Model
|
* Asset Group Model
|
||||||
*
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
* @author Jorg Janke
|
|
||||||
* @version $Id: MAssetGroup.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
|
|
||||||
*/
|
*/
|
||||||
public class MAssetGroup extends X_A_Asset_Group
|
public class MAssetGroup extends X_A_Asset_Group
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** Cache: ID -> MAssetGroup */
|
||||||
|
private static CCache<Integer, MAssetGroup> s_cache = new CCache<Integer, MAssetGroup>(Table_Name, 10, 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Default Constructor
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1364948077775028283L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get from Cache
|
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param A_Asset_Group_ID id
|
* @param A_Asset_Group_ID
|
||||||
* @return category
|
|
||||||
*/
|
|
||||||
public static MAssetGroup get (Properties ctx, int A_Asset_Group_ID)
|
|
||||||
{
|
|
||||||
Integer ii = new Integer (A_Asset_Group_ID);
|
|
||||||
MAssetGroup pc = (MAssetGroup)s_cache.get(ii);
|
|
||||||
if (pc == null)
|
|
||||||
pc = new MAssetGroup (ctx, A_Asset_Group_ID, null);
|
|
||||||
return pc;
|
|
||||||
} // get
|
|
||||||
|
|
||||||
/** Categopry Cache */
|
|
||||||
private static CCache<MAssetGroup, Object> s_cache = new CCache<MAssetGroup, Object> ("A_Asset_Group", 10);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Standard Constructor
|
|
||||||
* @param ctx context
|
|
||||||
* @param A_Asset_Group_ID id
|
|
||||||
* @param trxName trx
|
|
||||||
*/
|
*/
|
||||||
public MAssetGroup (Properties ctx, int A_Asset_Group_ID, String trxName)
|
public MAssetGroup (Properties ctx, int A_Asset_Group_ID, String trxName)
|
||||||
{
|
{
|
||||||
super (ctx, A_Asset_Group_ID, trxName);
|
super (ctx,A_Asset_Group_ID, trxName);
|
||||||
if (A_Asset_Group_ID == 0)
|
|
||||||
{
|
|
||||||
// setName (null);
|
|
||||||
setIsDepreciated (false);
|
|
||||||
setIsOneAssetPerUOM (false);
|
|
||||||
setIsOwned (false);
|
|
||||||
setIsCreateAsActive(true);
|
|
||||||
setIsTrackIssues(false);
|
|
||||||
}
|
|
||||||
} // MAssetGroup
|
} // MAssetGroup
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load Cosntructor
|
* Load Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param rs result set
|
* @param rs result set
|
||||||
* @param trxName trx
|
|
||||||
*/
|
*/
|
||||||
public MAssetGroup (Properties ctx, ResultSet rs, String trxName)
|
public MAssetGroup (Properties ctx, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ctx, rs, trxName);
|
super (ctx, rs, trxName);
|
||||||
} // MAssetGroup
|
} // MAssetGroup
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Asset Group [CACHE]
|
||||||
|
* @param ctx context
|
||||||
|
* @param A_Asset_Group_ID asset group id
|
||||||
|
* @return asset group or null
|
||||||
|
*/
|
||||||
|
public static MAssetGroup get(Properties ctx, int A_Asset_Group_ID)
|
||||||
|
{
|
||||||
|
if (A_Asset_Group_ID <= 0)
|
||||||
|
return null;
|
||||||
|
// Try cache
|
||||||
|
MAssetGroup ag = s_cache.get(A_Asset_Group_ID);
|
||||||
|
if (ag != null)
|
||||||
|
return ag;
|
||||||
|
// Load
|
||||||
|
ag = new MAssetGroup(ctx, A_Asset_Group_ID, null);
|
||||||
|
if (ag != null && ag.get_ID() != A_Asset_Group_ID)
|
||||||
|
ag = null;
|
||||||
|
//
|
||||||
|
return ag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default asset group ID for given model.
|
||||||
|
* WARNING: trxName = null.
|
||||||
|
* @param m reference model (used to get AD_Client_ID)
|
||||||
|
* @return default asset group ID or 0 if not found
|
||||||
|
*/
|
||||||
|
public static int getDefault_ID(SetGetModel m)
|
||||||
|
{
|
||||||
|
int AD_Client_ID = SetGetUtil.get_AttrValueAsInt(m, "AD_Client_ID");
|
||||||
|
/* commented by @win
|
||||||
|
int A_AssetType_ID = SetGetUtil.get_AttrValueAsInt(m, MAssetType.COLUMNNAME_A_Asset_Type_ID);
|
||||||
|
*/
|
||||||
|
final String sql = "SELECT "+COLUMNNAME_A_Asset_Group_ID
|
||||||
|
+ " FROM "+Table_Name
|
||||||
|
+ " WHERE AD_Client_ID=?"
|
||||||
|
// + " AND NVL("+COLUMNNAME_A_Asset_Type_ID+",0) IN (0,?)" //commented by @win
|
||||||
|
+ " ORDER BY "+COLUMNNAME_IsDefault+" DESC"
|
||||||
|
+", "+COLUMNNAME_A_Asset_Group_ID+" ASC" // default first, older first
|
||||||
|
;
|
||||||
|
/* modify by @win
|
||||||
|
int id = DB.getSQLValueEx(null, sql, AD_Client_ID, A_AssetType_ID);
|
||||||
|
*/
|
||||||
|
int id = DB.getSQLValueEx(null, sql, AD_Client_ID);
|
||||||
|
// modify by @win
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Asset
|
||||||
|
* - updates asset M_AssetGroup_ID if is null
|
||||||
|
*/
|
||||||
|
public static void updateAsset(SetGetModel m, int A_Asset_Group_ID)
|
||||||
|
{
|
||||||
|
/* commented by @win
|
||||||
|
int i = (Integer) m.get_AttrValue(MAsset.COLUMNNAME_A_Asset_Type_ID);
|
||||||
|
MAssetType type = MAssetType.get(m.getCtx(), m.get_AttrValue(MAsset.COLUMNNAME_A_Asset_Type_ID));
|
||||||
|
if (type == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (A_Asset_Group_ID > 0)
|
||||||
|
{
|
||||||
|
if (!type.isFixedAsset())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MAssetGroup assetGrp = MAssetGroup.get(m.getCtx(), A_Asset_Group_ID);
|
||||||
|
int A_Asset_Class_ID = assetGrp.getA_Asset_Class_ID();
|
||||||
|
if (A_Asset_Class_ID > 0)
|
||||||
|
{
|
||||||
|
m.set_AttrValue(MAsset.COLUMNNAME_A_Asset_Class_ID, A_Asset_Class_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
A_Asset_Group_ID = MAssetGroup.getDefault_ID(SetGetUtil.wrap(m));
|
||||||
|
m.set_AttrValue(MAsset.COLUMNNAME_A_Asset_Group_ID, A_Asset_Group_ID);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if (A_Asset_Group_ID < 0) {
|
||||||
|
A_Asset_Group_ID = MAssetGroup.getDefault_ID(SetGetUtil.wrap(m));
|
||||||
|
m.set_AttrValue(MAsset.COLUMNNAME_A_Asset_Group_ID, A_Asset_Group_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
//end modify by @win
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected boolean beforeSave (boolean newRecord)
|
||||||
|
{
|
||||||
|
/* commented by @win
|
||||||
|
MAssetType type = MAssetType.get(getCtx(), getA_Asset_Type_ID());
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
type.update(SetGetUtil.wrap(this), newRecord == true);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
//end commented by @win
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected boolean afterSave (boolean newRecord, boolean success)
|
||||||
|
{
|
||||||
|
if(!success)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
if (newRecord)
|
||||||
|
{
|
||||||
|
// If this is not the default group, then copy accounting settings from default group
|
||||||
|
int default_id = getDefault_ID(SetGetUtil.wrap(this));
|
||||||
|
if (default_id > 0 && default_id != get_ID())
|
||||||
|
{
|
||||||
|
for (MAssetGroupAcct acct : MAssetGroupAcct.forA_Asset_Group_ID(getCtx(), default_id))
|
||||||
|
{
|
||||||
|
MAssetGroupAcct newAcct = acct.copy(this);
|
||||||
|
newAcct.saveEx(get_TrxName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} // MAssetGroup
|
} // MAssetGroup
|
||||||
|
|
||||||
|
|
|
@ -1,48 +1,54 @@
|
||||||
/******************************************************************************
|
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
|
||||||
* Copyright (C) 1999-2006 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.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.compiere.model.Query;
|
||||||
|
import org.idempiere.fa.feature.UseLife;
|
||||||
|
import org.idempiere.fa.feature.UseLifeImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asset Addition Model
|
* Asset Group Accounting Model
|
||||||
*
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class MAssetGroupAcct extends X_A_Asset_Group_Acct
|
public class MAssetGroupAcct extends X_A_Asset_Group_Acct
|
||||||
|
implements UseLife
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Get Asset Group Accountings for given group
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1097065220838511473L;
|
public static List<MAssetGroupAcct> forA_Asset_Group_ID(Properties ctx, int A_Asset_Group_ID)
|
||||||
|
{
|
||||||
|
return new Query(ctx, Table_Name, COLUMNNAME_A_Asset_Group_ID+"=?", null)
|
||||||
|
.setParameters(new Object[]{A_Asset_Group_ID})
|
||||||
|
.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Asset Group Accountings for given group
|
||||||
|
*/
|
||||||
|
public static MAssetGroupAcct forA_Asset_Group_ID(Properties ctx, int A_Asset_Group_ID, String postingType)
|
||||||
|
{
|
||||||
|
final String whereClause = COLUMNNAME_A_Asset_Group_ID+"=? AND "+COLUMNNAME_PostingType+"=?";
|
||||||
|
return new Query(ctx, Table_Name, whereClause, null)
|
||||||
|
.setParameters(new Object[]{A_Asset_Group_ID, postingType})
|
||||||
|
.firstOnly();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default ConstructorX_A_Asset_Group_Acct
|
* Default ConstructorX_A_Asset_Group_Acct
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param M_InventoryLine_ID line
|
* @param X_A_Asset_Group_Acct_ID id
|
||||||
*/
|
*/
|
||||||
public MAssetGroupAcct (Properties ctx, int X_A_Asset_Group_Acct_ID, String trxName)
|
public MAssetGroupAcct (Properties ctx, int X_A_Asset_Group_Acct_ID, String trxName)
|
||||||
{
|
{
|
||||||
super (ctx,X_A_Asset_Group_Acct_ID, trxName);
|
super (ctx,X_A_Asset_Group_Acct_ID, trxName);
|
||||||
if (X_A_Asset_Group_Acct_ID == 0)
|
} // MAssetGroupAcct
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
} // MAssetAddition
|
|
||||||
/**
|
/**
|
||||||
* Load Constructor
|
* Load Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -51,9 +57,81 @@ public class MAssetGroupAcct extends X_A_Asset_Group_Acct
|
||||||
public MAssetGroupAcct (Properties ctx, ResultSet rs, String trxName)
|
public MAssetGroupAcct (Properties ctx, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ctx, rs, trxName);
|
super (ctx, rs, trxName);
|
||||||
} // MInventoryLine
|
} // MAssetGroupAcct
|
||||||
|
|
||||||
|
/** Asset Group */
|
||||||
|
private MAssetGroup m_parent = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Asset Group
|
||||||
|
*/
|
||||||
|
public MAssetGroup getParent()
|
||||||
|
{
|
||||||
|
if (m_parent == null)
|
||||||
|
{
|
||||||
|
int A_Asset_Group_ID = getA_Asset_Group_ID();
|
||||||
|
if (is_new())
|
||||||
|
{
|
||||||
|
m_parent = new MAssetGroup(getCtx(), A_Asset_Group_ID, get_TrxName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_parent = MAssetGroup.get(getCtx(), A_Asset_Group_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* commented by @win
|
||||||
|
public int getA_Asset_Class_ID()
|
||||||
|
{
|
||||||
|
return getParent().getA_Asset_Class_ID();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Timestamp getAssetServiceDate()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone this object, using specified group
|
||||||
|
* @param grp the new asset group
|
||||||
|
* @return new asset group accounting (NOTE: it's not saved)
|
||||||
|
*/
|
||||||
|
public MAssetGroupAcct copy(MAssetGroup grp)
|
||||||
|
{
|
||||||
|
MAssetGroupAcct newAcct = new MAssetGroupAcct(grp.getCtx(), 0, grp.get_TrxName());
|
||||||
|
copyValues(this, newAcct, grp.getAD_Client_ID(), grp.getAD_Org_ID());
|
||||||
|
newAcct.setA_Asset_Group_ID(grp.getA_Asset_Group_ID());
|
||||||
|
return newAcct;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean beforeSave(boolean newRecord)
|
||||||
|
{
|
||||||
|
if (! UseLifeImpl.get(this).validate())
|
||||||
} // MAssetAddition
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean set_AttrValue(String ColumnName, Object value) {
|
||||||
|
int index = get_ColumnIndex(ColumnName);
|
||||||
|
if (index < 0)
|
||||||
|
return false;
|
||||||
|
return set_ValueNoCheck(ColumnName, value);
|
||||||
|
}
|
||||||
|
public Object get_AttrValue(String ColumnName) {
|
||||||
|
int index = get_ColumnIndex(ColumnName);
|
||||||
|
if (index < 0)
|
||||||
|
return null;
|
||||||
|
return get_Value(index);
|
||||||
|
}
|
||||||
|
public boolean is_AttrValueChanged(String ColumnName) {
|
||||||
|
int index = get_ColumnIndex(ColumnName);
|
||||||
|
if (index < 0)
|
||||||
|
return false;
|
||||||
|
return is_ValueChanged(index);
|
||||||
|
}
|
||||||
|
} // MAssetGroupAcct
|
||||||
|
|
|
@ -1,60 +1,267 @@
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
* The contents of this file are subject to the Compiere License Version 1.1
|
||||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
* ("License"); You may not use this file except in compliance with the License
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
* You may obtain a copy of the License at http://www.compiere.org/license.html
|
||||||
* under the terms version 2 of the GNU General Public License as published *
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
* by the Free Software Foundation. This program is distributed in the hope *
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
||||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
* the specific language governing rights and limitations under the License.
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
* The Original Code is Compiere ERP & CRM Smart Business Solution
|
||||||
* See the GNU General Public License for more details. *
|
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
|
||||||
* You should have received a copy of the GNU General Public License along *
|
* Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
* Contributor(s): ______________________________________.
|
||||||
* 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.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
|
import org.compiere.model.MDocType;
|
||||||
|
import org.compiere.model.MPeriod;
|
||||||
|
import org.compiere.model.ModelValidationEngine;
|
||||||
|
import org.compiere.model.ModelValidator;
|
||||||
|
import org.compiere.model.PO;
|
||||||
|
import org.compiere.process.DocAction;
|
||||||
|
import org.compiere.process.DocumentEngine;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.idempiere.fa.exceptions.AssetAlreadyDepreciatedException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asset Trnasfer Model
|
* Asset Transfer Model
|
||||||
*
|
* @author www.arhipac.ro
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MAssetTransfer extends X_A_Asset_Transfer
|
public class MAssetTransfer extends X_A_Asset_Transfer
|
||||||
|
implements DocAction
|
||||||
{
|
{
|
||||||
/**
|
private static final long serialVersionUID = 1L;
|
||||||
*
|
/** Just Prepared Flag */
|
||||||
*/
|
private boolean m_justPrepared = false;
|
||||||
private static final long serialVersionUID = 6542200284709386238L;
|
|
||||||
/**
|
|
||||||
* Default ConstructorX_A_Asset_Group_Acct
|
|
||||||
* @param ctx context
|
|
||||||
* @param M_InventoryLine_ID line
|
|
||||||
*/
|
|
||||||
public MAssetTransfer (Properties ctx, int X_A_Asset_Transfer_ID, String trxName)
|
public MAssetTransfer (Properties ctx, int X_A_Asset_Transfer_ID, String trxName)
|
||||||
{
|
{
|
||||||
super (ctx,X_A_Asset_Transfer_ID, trxName);
|
super (ctx,X_A_Asset_Transfer_ID, trxName);
|
||||||
if (X_A_Asset_Transfer_ID == 0)
|
if (X_A_Asset_Transfer_ID == 0)
|
||||||
{
|
{
|
||||||
//
|
setDocStatus(DOCSTATUS_Drafted);
|
||||||
|
setDocAction(DOCACTION_Complete);
|
||||||
|
setProcessed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // MAssetAddition
|
}
|
||||||
/**
|
|
||||||
* Load Constructor
|
|
||||||
* @param ctx context
|
|
||||||
* @param rs result set
|
|
||||||
*/
|
|
||||||
public MAssetTransfer (Properties ctx, ResultSet rs, String trxName)
|
public MAssetTransfer (Properties ctx, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ctx, rs, trxName);
|
super (ctx, rs, trxName);
|
||||||
} // MInventoryLine
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected boolean beforeSave(boolean newRecord)
|
||||||
|
{
|
||||||
|
setC_Period_ID();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setC_Period_ID()
|
||||||
|
{
|
||||||
|
MPeriod period = MPeriod.get(getCtx(), getDateAcct(), getAD_Org_ID());
|
||||||
|
if (period == null)
|
||||||
|
{
|
||||||
|
throw new AdempiereException("@NotFound@ @C_Period_ID@");
|
||||||
|
}
|
||||||
|
setC_Period_ID(period.get_ID());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean approveIt() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean closeIt() {
|
||||||
|
setDocAction(DOCACTION_None);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File createPDF() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getApprovalAmt() {
|
||||||
|
return Env.ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getC_Currency_ID() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDoc_User_ID() {
|
||||||
|
return getCreatedBy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDocumentInfo() {
|
||||||
|
return getDocumentNo() + "/" + getDateAcct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProcessMsg() {
|
||||||
|
return m_processMsg;
|
||||||
|
}
|
||||||
|
private String m_processMsg = null;
|
||||||
|
|
||||||
|
|
||||||
|
public String getSummary() {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append("@DocumentNo@ #").append(getDocumentNo());
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean invalidateIt() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String prepareIt()
|
||||||
|
{
|
||||||
|
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
|
||||||
|
if (m_processMsg != null)
|
||||||
|
{
|
||||||
|
return DocAction.STATUS_Invalid;
|
||||||
|
}
|
||||||
|
// test if period is open
|
||||||
|
MPeriod.testPeriodOpen(getCtx(), getDateAcct(), MDocType.DOCBASETYPE_GLJournal, getAD_Org_ID());
|
||||||
|
|
||||||
|
MDepreciationWorkfile assetwk = MDepreciationWorkfile.get(getCtx(), getA_Asset_ID(), getPostingType());
|
||||||
|
if (assetwk.isDepreciated(getDateAcct()))
|
||||||
|
{
|
||||||
|
throw new AssetAlreadyDepreciatedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the accounts have changed in the meantime
|
||||||
|
MAssetAcct assetAcct = MAssetAcct.forA_Asset_ID(getCtx(), getA_Asset_ID(), getPostingType(), getDateAcct(), get_TrxName());
|
||||||
|
if (assetAcct.getA_Asset_Acct() != getA_Asset_Acct()
|
||||||
|
|| assetAcct.getA_Accumdepreciation_Acct() != getA_Accumdepreciation_Acct()
|
||||||
|
|| assetAcct.getA_Depreciation_Acct() != getA_Depreciation_Acct()
|
||||||
|
|| assetAcct.getA_Disposal_Revenue_Acct() != getA_Disposal_Revenue_Acct()
|
||||||
|
|| assetAcct.getA_Disposal_Loss_Acct() != getA_Disposal_Loss_Acct()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
throw new AdempiereException("The accounts have been changed");
|
||||||
|
}
|
||||||
|
//Check that at least one account is changed
|
||||||
|
{
|
||||||
|
MAssetAcct acct = MAssetAcct.forA_Asset_ID(getCtx(), getA_Asset_ID(), getPostingType(), getDateAcct(), get_TrxName());
|
||||||
|
if (acct.getA_Asset_Acct() == getA_Asset_New_Acct()
|
||||||
|
&& acct.getA_Accumdepreciation_Acct() == getA_Accumdepreciation_New_Acct()
|
||||||
|
&& acct.getA_Depreciation_Acct() == getA_Depreciation_New_Acct()
|
||||||
|
&& acct.getA_Disposal_Revenue_Acct() == getA_Disposal_Revenue_New_Acct()
|
||||||
|
&& acct.getA_Disposal_Loss_Acct() == getA_Disposal_Loss_New_Acct()
|
||||||
|
)
|
||||||
|
{
|
||||||
|
throw new AdempiereException("An account has been changed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//doc check if the date is equal to its accounting for the expense table
|
||||||
|
if (assetwk.getDateAcct().equals(getDateAcct()))
|
||||||
|
{
|
||||||
|
throw new AdempiereException("Last day of month. Accounts will be changed next month");
|
||||||
|
}
|
||||||
|
|
||||||
|
//check if they are unprocessed records
|
||||||
|
MDepreciationExp.checkExistsNotProcessedEntries(getCtx(), getA_Asset_ID(), getDateAcct(), getPostingType(), get_TrxName());
|
||||||
|
|
||||||
|
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
|
||||||
|
if (m_processMsg != null)
|
||||||
|
return DocAction.STATUS_Invalid;
|
||||||
|
|
||||||
|
m_justPrepared = true;
|
||||||
|
if (!DOCACTION_Complete.equals(getDocAction()))
|
||||||
|
setDocAction(DOCACTION_Complete);
|
||||||
|
return DocAction.STATUS_InProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String completeIt()
|
||||||
|
{
|
||||||
|
// Re-Check
|
||||||
|
if (!m_justPrepared)
|
||||||
|
{
|
||||||
|
String status = prepareIt();
|
||||||
|
if (!DocAction.STATUS_InProgress.equals(status))
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE);
|
||||||
|
if (m_processMsg != null)
|
||||||
|
return DocAction.STATUS_Invalid;
|
||||||
|
|
||||||
|
|
||||||
|
// create new MAssetAcct
|
||||||
|
MAssetAcct assetAcctPrev = MAssetAcct.forA_Asset_ID(getCtx(), getA_Asset_ID(), getPostingType(), getDateAcct(), get_TrxName());
|
||||||
|
MAssetAcct assetAcct = new MAssetAcct(getCtx(), 0, get_TrxName());
|
||||||
|
PO.copyValues(assetAcctPrev, assetAcct);
|
||||||
|
assetAcct.setA_Asset_Acct(getA_Asset_New_Acct());
|
||||||
|
assetAcct.setA_Accumdepreciation_Acct(getA_Accumdepreciation_New_Acct());
|
||||||
|
assetAcct.setValidFrom(getDateAcct());
|
||||||
|
assetAcct.saveEx();
|
||||||
|
|
||||||
|
MDepreciationWorkfile wk = MDepreciationWorkfile.get(getCtx(), getA_Asset_ID(), getPostingType(), get_TrxName());
|
||||||
|
/* commented out by @win, deprecating existing design
|
||||||
|
wk.buildDepreciation();
|
||||||
|
*/
|
||||||
|
|
||||||
|
// User Validation
|
||||||
|
String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
|
||||||
|
if (valid != null)
|
||||||
|
{
|
||||||
|
m_processMsg = valid;
|
||||||
|
return DocAction.STATUS_Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the definite document number after completed (if needed)
|
||||||
|
//setDefiniteDocumentNo();
|
||||||
|
|
||||||
|
setProcessed(true);
|
||||||
|
setDocAction(DOCACTION_Close);
|
||||||
|
return DocAction.STATUS_Completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean processIt(String action) throws Exception {
|
||||||
|
m_processMsg = null;
|
||||||
|
DocumentEngine engine = new DocumentEngine (this, getDocStatus());
|
||||||
|
return engine.processIt (action, getDocAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean reActivateIt() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean rejectIt() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean reverseAccrualIt() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean reverseCorrectIt() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean unlockIt() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean voidIt() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // MAssetAddition
|
|
||||||
|
public String getDocumentNo() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} // MAssetTransfer
|
||||||
|
|
|
@ -1,36 +1,14 @@
|
||||||
/******************************************************************************
|
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
|
||||||
* Copyright (C) 1999-2006 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 *
|
|
||||||
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
|
|
||||||
* Contributor(s): ______________________________________.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.compiere.model.MRefList;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
/** Generated Model for A_Asset_Use
|
/** Generated Model for A_Asset_Use
|
||||||
** @version $Id: X_A_Asset.java,v 1.88 2004/08/27 21:26:37 jjanke Exp $ */
|
** @version $Id: X_A_Asset.java,v 1.88 2004/08/27 21:26:37 jjanke Exp $ */
|
||||||
public class MAssetUse extends X_A_Asset_Use
|
public class MAssetUse extends X_A_Asset_Use
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = -1247516669047870893L;
|
|
||||||
|
|
||||||
public MAssetUse (Properties ctx, int A_Asset_Use_ID, String trxName)
|
public MAssetUse (Properties ctx, int A_Asset_Use_ID, String trxName)
|
||||||
{
|
{
|
||||||
super (ctx, A_Asset_Use_ID, trxName);
|
super (ctx, A_Asset_Use_ID, trxName);
|
||||||
|
@ -65,9 +43,9 @@ protected boolean afterSave (boolean newRecord,boolean success)
|
||||||
|
|
||||||
|
|
||||||
String sql = "SELECT SUM(USEUNITS) FROM A_Asset_use WHERE A_Asset_ID=? and usedate <= SYSDATE";
|
String sql = "SELECT SUM(USEUNITS) FROM A_Asset_use WHERE A_Asset_ID=? and usedate <= SYSDATE";
|
||||||
total_unitsused = DB.getSQLValue(null, sql, getA_Asset_ID());
|
total_unitsused = DB.getSQLValueEx(null, sql, getA_Asset_ID());
|
||||||
|
|
||||||
MAsset asset = new MAsset (getCtx(), p_A_Asset_ID, null);
|
MAsset asset = MAsset.get(getCtx(), p_A_Asset_ID, null);
|
||||||
asset.setUseUnits(total_unitsused);
|
asset.setUseUnits(total_unitsused);
|
||||||
asset.setProcessing(false);
|
asset.setProcessing(false);
|
||||||
asset.saveEx();
|
asset.saveEx();
|
||||||
|
|
|
@ -1,38 +1,39 @@
|
||||||
/******************************************************************************
|
|
||||||
* The contents of this file are subject to the Compiere License Version 1.1
|
|
||||||
* ("License"); You may not use this file except in compliance with the License
|
|
||||||
* You may obtain a copy of the License at http://www.compiere.org/license.html
|
|
||||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
||||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
||||||
* the specific language governing rights and limitations under the License.
|
|
||||||
* The Original Code is Compiere ERP & CRM Smart Business Solution
|
|
||||||
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
|
|
||||||
* Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
|
|
||||||
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
|
|
||||||
* Contributor(s): ______________________________________.
|
|
||||||
*****************************************************************************/
|
|
||||||
package org.compiere.model;
|
package org.compiere.model;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
|
import org.apache.commons.collections.keyvalue.MultiKey;
|
||||||
|
import org.compiere.model.Query;
|
||||||
|
import org.compiere.util.CCache;
|
||||||
|
import org.compiere.util.CLogMgt;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.TimeUtil;
|
||||||
|
import org.idempiere.fa.feature.UseLife;
|
||||||
|
import org.idempiere.fa.feature.UseLifeImpl;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Depreciation Workfile Model
|
* Depreciation Workfile Model
|
||||||
*
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class MDepreciationWorkfile extends X_A_Depreciation_Workfile
|
public class MDepreciationWorkfile extends X_A_Depreciation_Workfile
|
||||||
|
implements UseLife
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 9075233803956474274L;
|
private static final long serialVersionUID = -3814417671427820714L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor X_A_Depreciation_Workfile
|
* Default Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param M_InventoryLine_ID line
|
* @param M_InventoryLine_ID line
|
||||||
*/
|
*/
|
||||||
|
@ -41,9 +42,15 @@ public class MDepreciationWorkfile extends X_A_Depreciation_Workfile
|
||||||
super (ctx,A_Depreciation_Workfile_ID, trxName);
|
super (ctx,A_Depreciation_Workfile_ID, trxName);
|
||||||
if (A_Depreciation_Workfile_ID == 0)
|
if (A_Depreciation_Workfile_ID == 0)
|
||||||
{
|
{
|
||||||
//
|
setPostingType(POSTINGTYPE_Actual);
|
||||||
|
setA_QTY_Current(Env.ZERO);
|
||||||
|
setA_Asset_Cost(Env.ZERO);
|
||||||
|
setA_Accumulated_Depr(Env.ZERO);
|
||||||
|
setA_Period_Posted(0);
|
||||||
|
setA_Current_Period(0);
|
||||||
}
|
}
|
||||||
} // MAssetAddition
|
} // MDepreciationWorkfile
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load Constructor
|
* Load Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -52,71 +59,733 @@ public class MDepreciationWorkfile extends X_A_Depreciation_Workfile
|
||||||
public MDepreciationWorkfile (Properties ctx, ResultSet rs, String trxName)
|
public MDepreciationWorkfile (Properties ctx, ResultSet rs, String trxName)
|
||||||
{
|
{
|
||||||
super (ctx, rs, trxName);
|
super (ctx, rs, trxName);
|
||||||
} // MInventoryLine
|
} // MDepreciationWorkfile
|
||||||
|
|
||||||
|
|
||||||
|
/** Asset (parent) */
|
||||||
|
private MAsset m_asset = null;
|
||||||
|
|
||||||
|
/** Get Asset */
|
||||||
|
public MAsset getAsset() {
|
||||||
|
return getAsset(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get asset using this trxName
|
||||||
|
* @param requery requery asset
|
||||||
|
* @return parent asset
|
||||||
|
*/
|
||||||
|
public MAsset getAsset(boolean requery)
|
||||||
|
{
|
||||||
|
if (m_asset == null || requery) {
|
||||||
|
m_asset = MAsset.get(getCtx(), getA_Asset_ID(), get_TrxName());
|
||||||
|
}
|
||||||
|
if (m_asset.get_ID() <= 0) {
|
||||||
|
m_asset = null;
|
||||||
|
}
|
||||||
|
return m_asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set asset
|
||||||
|
* @param asset
|
||||||
|
*/
|
||||||
|
public void setAsset(MAsset asset)
|
||||||
|
{
|
||||||
|
setA_Asset_ID(asset.get_ID());
|
||||||
|
m_asset = asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets asset's service date (commissioning)
|
||||||
|
* @return asset service date
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Timestamp getAssetServiceDate()
|
||||||
|
{
|
||||||
|
MAsset asset = getAsset();
|
||||||
|
if (asset == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return asset.getAssetServiceDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Gets asset's class
|
||||||
|
* @return asset class id
|
||||||
|
*/
|
||||||
|
/* commented out by @win
|
||||||
|
public int getA_Asset_Class_ID()
|
||||||
|
{
|
||||||
|
MAsset asset = getAsset();
|
||||||
|
if (asset == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return asset.getA_Asset_Class_ID();
|
||||||
|
}
|
||||||
|
*/ // end comment by @win
|
||||||
|
|
||||||
|
/** After save
|
||||||
|
* @param newRecord
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
protected boolean afterSave (boolean newRecord)
|
protected boolean afterSave (boolean newRecord)
|
||||||
{
|
{
|
||||||
|
if(m_buildDepreciation)
|
||||||
log.info ("beforeSave");
|
{
|
||||||
//int p_A_Asset_ID = 0;
|
buildDepreciation();
|
||||||
int p_wkasset_ID = 0;
|
}
|
||||||
//p_A_Asset_ID = getA_Asset_ID();
|
|
||||||
p_wkasset_ID = getA_Depreciation_Workfile_ID();
|
|
||||||
StringBuilder sqlB = new StringBuilder ("UPDATE A_Depreciation_Workfile ")
|
|
||||||
.append("SET Processing = 'Y'")
|
|
||||||
.append(" WHERE A_Depreciation_Workfile_ID = " ).append(p_wkasset_ID );
|
|
||||||
|
|
||||||
int no = DB.executeUpdate (sqlB.toString(),null);
|
|
||||||
if (no == -1)
|
|
||||||
log.info("Update to Deprecaition Workfile failed");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* after Save
|
|
||||||
* @param newRecord new
|
|
||||||
* @return true
|
|
||||||
*/
|
|
||||||
protected boolean beforeSave (boolean newRecord)
|
protected boolean beforeSave (boolean newRecord)
|
||||||
{
|
{
|
||||||
|
log.info ("Entering: trxName=" + get_TrxName());
|
||||||
|
|
||||||
log.info ("beforeSave");
|
// copy UseLife to A_Life
|
||||||
int p_A_Asset_ID = 0;
|
if (newRecord) { //@win: should only update only if newrecord
|
||||||
//int p_wkasset_ID = 0;
|
setA_Life_Period(getUseLifeMonths());
|
||||||
p_A_Asset_ID = getA_Asset_ID();
|
setA_Asset_Life_Years(getUseLifeYears());
|
||||||
//p_wkasset_ID = getA_Depreciation_Workfile_ID();
|
setA_Life_Period_F(getUseLifeMonths_F());
|
||||||
|
setA_Asset_Life_Years_F(getUseLifeYears_F());
|
||||||
|
}
|
||||||
|
|
||||||
log.info ("afterSave");
|
// If it is fully amortized, change the state's FA
|
||||||
X_A_Asset asset = new X_A_Asset (getCtx(), p_A_Asset_ID, null);
|
MAsset asset = getAsset(true);
|
||||||
asset.setA_QTY_Current(getA_QTY_Current());
|
if (MAsset.A_ASSET_STATUS_Activated.equals(asset.getA_Asset_Status())
|
||||||
asset.setA_QTY_Original(getA_QTY_Current());
|
&& isFullyDepreciated())
|
||||||
asset.saveEx();
|
|
||||||
|
|
||||||
if (getA_Accumulated_Depr().equals(null))
|
|
||||||
setA_Accumulated_Depr(new BigDecimal(0.0));
|
|
||||||
|
|
||||||
if (new BigDecimal(getA_Period_Posted()).equals(null))
|
|
||||||
setA_Period_Posted(0);
|
|
||||||
|
|
||||||
|
|
||||||
MAssetChange change = new MAssetChange (getCtx(), 0,null);
|
|
||||||
log.info("0");
|
|
||||||
String sql2 = "SELECT COUNT(*) FROM A_Depreciation_Workfile WHERE A_Asset_ID=? AND PostingType = ?";
|
|
||||||
if (DB.getSQLValue(null, sql2, p_A_Asset_ID,getPostingType())!= 0)
|
|
||||||
{
|
{
|
||||||
change.setA_Asset_ID(p_A_Asset_ID);
|
asset.changeStatus(MAsset.A_ASSET_STATUS_Depreciated, null);
|
||||||
change.setChangeType("BAL");
|
asset.saveEx();
|
||||||
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "BAL"));
|
}
|
||||||
change.setPostingType(getPostingType());
|
|
||||||
change.setAssetValueAmt(getA_Asset_Cost());
|
// Fix DateAcct
|
||||||
change.setA_QTY_Current(getA_QTY_Current());
|
if(is_ValueChanged(COLUMNNAME_DateAcct))
|
||||||
change.setA_QTY_Original(getA_QTY_Current());
|
{
|
||||||
change.setAssetAccumDepreciationAmt(getA_Accumulated_Depr());
|
setDateAcct(TimeUtil.getMonthLastDay(getDateAcct()));
|
||||||
change.saveEx();
|
}
|
||||||
}
|
|
||||||
return true;
|
//
|
||||||
|
BigDecimal cost = getA_Asset_Cost();
|
||||||
|
BigDecimal accumDep_C = getA_Accumulated_Depr();
|
||||||
|
setA_Asset_Remaining(cost.subtract(accumDep_C));
|
||||||
|
BigDecimal accumDep_F = getA_Accumulated_Depr_F();
|
||||||
|
setA_Asset_Remaining_F(cost.subtract(accumDep_F));
|
||||||
|
|
||||||
|
// Financing
|
||||||
|
{
|
||||||
|
String mainColumnName = null;
|
||||||
|
if (newRecord || is_ValueChanged(COLUMNNAME_A_Asset_Cost))
|
||||||
|
{
|
||||||
|
mainColumnName = COLUMNNAME_A_Asset_Cost;
|
||||||
|
}
|
||||||
|
else if (is_ValueChanged(COLUMNNAME_A_Valoare_Cofinantare))
|
||||||
|
{
|
||||||
|
mainColumnName = COLUMNNAME_A_Valoare_Cofinantare;
|
||||||
|
}
|
||||||
|
else if (is_ValueChanged(COLUMNNAME_A_Valoare_Tert))
|
||||||
|
{
|
||||||
|
mainColumnName = COLUMNNAME_A_Valoare_Tert;
|
||||||
|
}
|
||||||
|
updateFinantare(this, mainColumnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
log.info("Leaving: trxName=" + get_TrxName() + " [RETURN TRUE]");
|
||||||
|
return true;
|
||||||
} // beforeSave
|
} // beforeSave
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asset is fully depreciated
|
||||||
|
* <ul>
|
||||||
|
* <li>If PostingType != ACTUAL then return false
|
||||||
|
* <li>Do not check your current asset
|
||||||
|
* </ul>
|
||||||
|
* @return true if the asset is fully depreciated, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean isFullyDepreciated()
|
||||||
|
{
|
||||||
|
if(!getPostingType().equals(POSTINGTYPE_Actual))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if is fully depreciated
|
||||||
|
BigDecimal remainingAmt_C = getRemainingCost(null, false);
|
||||||
|
BigDecimal remainingAmt_F = getRemainingCost(null, true);
|
||||||
|
if(remainingAmt_C.signum() == 0 && remainingAmt_F.signum() == 0)
|
||||||
|
{
|
||||||
|
//if A_Asset_Cost is 0 have a voided addition, in this case asset is not full depreciated
|
||||||
|
if (getA_Asset_Cost().signum() == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public MDepreciationWorkfile(MAsset asset, String postingType, MAssetGroupAcct assetgrpacct)
|
||||||
|
{
|
||||||
|
this(asset.getCtx(), 0, asset.get_TrxName());
|
||||||
|
setA_Asset_ID(asset.getA_Asset_ID());
|
||||||
|
setAD_Org_ID(asset.getAD_Org_ID()); //@win added
|
||||||
|
setA_Asset_Cost(asset.getA_Asset_Cost());
|
||||||
|
setA_Accumulated_Depr(asset.getA_Accumulated_Depr());
|
||||||
|
setA_Accumulated_Depr_F(asset.getA_Accumulated_Depr_F());
|
||||||
|
setA_Current_Period(asset.getA_Current_Period());
|
||||||
|
|
||||||
|
setIsDepreciated(asset.isDepreciated());
|
||||||
|
setPostingType(postingType);
|
||||||
|
//
|
||||||
|
// Copy UseLife values from asset group to workfile
|
||||||
|
if (assetgrpacct == null)
|
||||||
|
{
|
||||||
|
assetgrpacct = MAssetGroupAcct.forA_Asset_Group_ID(asset.getCtx(), asset.getA_Asset_Group_ID(), postingType);
|
||||||
|
}
|
||||||
|
UseLifeImpl.copyValues(this, assetgrpacct);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Date Acct from Asset
|
||||||
|
Timestamp dateAcct = asset.getDateAcct();
|
||||||
|
if (dateAcct != null)
|
||||||
|
{
|
||||||
|
dateAcct = TimeUtil.addMonths(dateAcct, 1);
|
||||||
|
setDateAcct(dateAcct);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Set UseLife values from asset (if any)
|
||||||
|
if (asset.getUseLifeMonths() > 0)
|
||||||
|
{
|
||||||
|
UseLifeImpl.get(this, false).setUseLifeMonths(asset.getUseLifeMonths());
|
||||||
|
}
|
||||||
|
if (asset.getUseLifeMonths_F() > 0)
|
||||||
|
{
|
||||||
|
UseLifeImpl.get(this, true).setUseLifeMonths(asset.getUseLifeMonths_F());
|
||||||
|
}
|
||||||
|
//
|
||||||
|
dump();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Logger */
|
||||||
|
private CLogger log = CLogger.getCLogger(getClass());
|
||||||
|
|
||||||
|
public static Collection<MDepreciationWorkfile> forA_Asset_ID(Properties ctx, int asset_id, String trxName)
|
||||||
|
{
|
||||||
|
return new Query(ctx, Table_Name, MDepreciationWorkfile.COLUMNNAME_A_Asset_ID+"=?", trxName)
|
||||||
|
.setParameters(new Object[]{asset_id})
|
||||||
|
.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param ctx
|
||||||
|
* @param A_Asset_ID
|
||||||
|
* @param postingType
|
||||||
|
* @return workfile
|
||||||
|
* @see #get(Properties, int, String, String)
|
||||||
|
*/
|
||||||
|
public static MDepreciationWorkfile get (Properties ctx, int A_Asset_ID, String postingType)
|
||||||
|
{
|
||||||
|
return get(ctx, A_Asset_ID, postingType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get/load workfile from cache (if trxName is null)
|
||||||
|
* @param ctx
|
||||||
|
* @param A_Asset_ID
|
||||||
|
* @param postingType
|
||||||
|
* @param trxName
|
||||||
|
* @return workfile
|
||||||
|
*/
|
||||||
|
public static MDepreciationWorkfile get (Properties ctx, int A_Asset_ID, String postingType, String trxName)
|
||||||
|
{
|
||||||
|
if (A_Asset_ID <= 0 || postingType == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final MultiKey key = new MultiKey(A_Asset_ID, postingType);
|
||||||
|
if (trxName == null)
|
||||||
|
{
|
||||||
|
MDepreciationWorkfile wk = s_cacheAsset.get(key);
|
||||||
|
if (wk != null)
|
||||||
|
return wk;
|
||||||
|
}
|
||||||
|
/* @win temporary change as this code is causing duplicate create MDepreciationWorkfile on asset addition
|
||||||
|
final String whereClause = COLUMNNAME_A_Asset_ID+"=?"
|
||||||
|
+" AND "+COLUMNNAME_PostingType+"=? AND "+COLUMNNAME_A_QTY_Current+">?";
|
||||||
|
MDepreciationWorkfile wk = new Query(ctx, MDepreciationWorkfile.Table_Name, whereClause, trxName)
|
||||||
|
.setParameters(new Object[]{A_Asset_ID, postingType, 0})
|
||||||
|
.firstOnly();
|
||||||
|
*/
|
||||||
|
final String whereClause = COLUMNNAME_A_Asset_ID+"=?"
|
||||||
|
+" AND "+COLUMNNAME_PostingType+"=? ";
|
||||||
|
MDepreciationWorkfile wk = new Query(ctx, MDepreciationWorkfile.Table_Name, whereClause, trxName)
|
||||||
|
.setParameters(new Object[]{A_Asset_ID, postingType})
|
||||||
|
.firstOnly();
|
||||||
|
|
||||||
|
|
||||||
|
if (trxName == null && wk != null)
|
||||||
|
{
|
||||||
|
s_cacheAsset.put(key, wk);
|
||||||
|
}
|
||||||
|
return wk;
|
||||||
|
}
|
||||||
|
/** Static cache: Asset/PostingType -> Workfile */
|
||||||
|
private static CCache<MultiKey, MDepreciationWorkfile>
|
||||||
|
s_cacheAsset = new CCache<MultiKey, MDepreciationWorkfile>(Table_Name+"_Asset", 10);
|
||||||
|
|
||||||
|
/** Returns the date of the last action
|
||||||
|
*/
|
||||||
|
public Timestamp getLastActionDate()
|
||||||
|
{
|
||||||
|
return TimeUtil.getMonthLastDay(TimeUtil.addMonths(getDateAcct(), -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check if the asset is depreciated at the specified date
|
||||||
|
* @param date
|
||||||
|
* @return true if you amortized until the specified date, otherwise false
|
||||||
|
*/
|
||||||
|
public boolean isDepreciated(Timestamp date)
|
||||||
|
{
|
||||||
|
Timestamp lastActionDate = getLastActionDate();
|
||||||
|
boolean isDepr = !date.after(lastActionDate); // date <= lastActionDate
|
||||||
|
|
||||||
|
log.fine("LastActionDate=" + lastActionDate + ", GivenDate=" + date + " => isDepreciated=" + isDepr);
|
||||||
|
return isDepr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Asset Accounting for this workfile
|
||||||
|
* @return asset accounting model
|
||||||
|
*/
|
||||||
|
public MAssetAcct getA_AssetAcct(Timestamp dateAcct, String trxName)
|
||||||
|
{
|
||||||
|
return MAssetAcct.forA_Asset_ID(getCtx(), getA_Asset_ID(), getPostingType(), dateAcct, trxName);
|
||||||
|
}
|
||||||
|
|
||||||
} // MAssetAddition
|
/** Returns the current cost of FAs. It is calculated as the difference between acquisition value and the value that you (A_Salvage_Value)
|
||||||
|
* @return the current cost of FAs
|
||||||
|
*/
|
||||||
|
public BigDecimal getActualCost()
|
||||||
|
{
|
||||||
|
return getActualCost(getA_Asset_Cost());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
public BigDecimal getActualCost(BigDecimal assetCost)
|
||||||
|
{
|
||||||
|
return assetCost.subtract(getA_Salvage_Value());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param deltaAmt
|
||||||
|
* @param deltaQty
|
||||||
|
* @param reset
|
||||||
|
*/
|
||||||
|
public void adjustCost(BigDecimal deltaAmt, BigDecimal deltaQty, boolean reset)
|
||||||
|
{
|
||||||
|
BigDecimal newCost = Env.ZERO;
|
||||||
|
BigDecimal newQty = Env.ZERO;
|
||||||
|
if (!reset)
|
||||||
|
{
|
||||||
|
newCost = getA_Asset_Cost();
|
||||||
|
newQty = getA_QTY_Current();
|
||||||
|
}
|
||||||
|
newCost = newCost.add(deltaAmt);
|
||||||
|
newQty = newQty.add(deltaQty);
|
||||||
|
|
||||||
|
// TODO: crashes if I cancel an Issue:
|
||||||
|
// if (newQty.signum() < 0) {
|
||||||
|
// throw new ArhRuntimeException(getCtx(), "@A_QTY_Current@ < 0");
|
||||||
|
// }
|
||||||
|
|
||||||
|
//
|
||||||
|
// There must be verified that the remaining value to be greater than the amount diminished
|
||||||
|
// total devaluation because if the entire asset value (A_Asset_Cost) must be brought to 0.
|
||||||
|
// if (deltaAmt.signum() < 0)
|
||||||
|
// {
|
||||||
|
// BigDecimal remainingAmt_C = getRemainingCost(null, false);
|
||||||
|
// if (remainingAmt_C.compareTo(deltaAmt.negate()) < 0)
|
||||||
|
// {
|
||||||
|
// throw new ArhRuntimeException(getCtx(), "@A_Asset_Remaining@ < @DeltaAmt@")
|
||||||
|
// .addInfo("@A_Asset_Cost@=", getA_Asset_Cost())
|
||||||
|
// .addInfo("@A_Accumulated_Depr@=", getA_Accumulated_Depr());
|
||||||
|
// }
|
||||||
|
// BigDecimal remainingAmt_F = getRemainingCost(null, true);
|
||||||
|
// if (remainingAmt_F.compareTo(deltaAmt.negate()) < 0)
|
||||||
|
// {
|
||||||
|
// throw new ArhRuntimeException(getCtx(), "@A_Asset_Remaining_F@ < @DeltaAmt@")
|
||||||
|
// .addInfo("@A_Asset_Cost=@", getA_Asset_Cost())
|
||||||
|
// .addInfo("@A_Accumulated_Depr@=", getA_Accumulated_Depr_F());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
setA_Asset_Cost(newCost);
|
||||||
|
setA_QTY_Current(newQty);
|
||||||
|
|
||||||
|
if(CLogMgt.isLevelFine()) log.fine("adjustCost(" + deltaAmt + ", " + deltaQty + ", reset=" + reset + ") => amt=" + getA_Asset_Cost() + ", qty=" + getA_QTY_Current());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adjust Accumulated depreciation
|
||||||
|
* @param amt
|
||||||
|
* @param amt_F
|
||||||
|
* @param reset
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean adjustAccumulatedDepr(BigDecimal amt, BigDecimal amt_F, boolean reset)
|
||||||
|
{
|
||||||
|
if (amt == null)
|
||||||
|
{
|
||||||
|
amt = Env.ZERO;
|
||||||
|
}
|
||||||
|
if (amt_F == null)
|
||||||
|
{
|
||||||
|
amt_F = Env.ZERO;
|
||||||
|
}
|
||||||
|
setA_Accumulated_Depr(amt.add(reset ? Env.ZERO : getA_Accumulated_Depr()));
|
||||||
|
setA_Accumulated_Depr_F(amt_F.add(reset ? Env.ZERO : getA_Accumulated_Depr_F()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adjust use life years
|
||||||
|
*/
|
||||||
|
public void adjustUseLife(int deltaUseLifeYears, int deltaUseLifeYears_F, boolean reset)
|
||||||
|
{
|
||||||
|
if(CLogMgt.isLevelFine()) log.fine("Entering: deltaUseLifeYears=" + deltaUseLifeYears + ", deltaUseLifeYears_F=" + deltaUseLifeYears_F);
|
||||||
|
//
|
||||||
|
UseLifeImpl.get(this, false).adjustUseLifeYears(deltaUseLifeYears, reset);
|
||||||
|
UseLifeImpl.get(this, true).adjustUseLifeYears(deltaUseLifeYears_F, reset);
|
||||||
|
//
|
||||||
|
if(CLogMgt.isLevelFine()) log.fine("Leaving");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
public int getUseLifeMonths(boolean fiscal)
|
||||||
|
{
|
||||||
|
return fiscal ? getUseLifeMonths_F() : getUseLifeMonths();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
public BigDecimal getA_Accumulated_Depr(boolean fiscal)
|
||||||
|
{
|
||||||
|
return fiscal ? getA_Accumulated_Depr_F() : getA_Accumulated_Depr();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
public BigDecimal getAccumulatedCost()
|
||||||
|
{
|
||||||
|
return getA_Accumulated_Depr(isFiscal());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
public BigDecimal getReevaluationCost()
|
||||||
|
{
|
||||||
|
return Env.ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the residual (remaining) value
|
||||||
|
*/
|
||||||
|
public BigDecimal getRemainingCost(BigDecimal accumAmt, boolean fiscal)
|
||||||
|
{
|
||||||
|
BigDecimal cost = getActualCost();
|
||||||
|
if (accumAmt == null) {
|
||||||
|
accumAmt = getA_Accumulated_Depr(fiscal);
|
||||||
|
}
|
||||||
|
return cost.subtract(accumAmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the residual (remaining) value
|
||||||
|
*/
|
||||||
|
public BigDecimal getRemainingCost(BigDecimal accumAmt)
|
||||||
|
{
|
||||||
|
return getRemainingCost(accumAmt, isFiscal());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
public int getRemainingPeriods(int A_Current_Period, MDepreciation method)
|
||||||
|
{
|
||||||
|
int useLifePeriods = getUseLifeMonths(isFiscal());
|
||||||
|
if (method != null) {
|
||||||
|
useLifePeriods += method.getFixMonthOffset();
|
||||||
|
}
|
||||||
|
int currentPeriod = (A_Current_Period >= 0 ? A_Current_Period : getA_Current_Period());
|
||||||
|
return useLifePeriods - currentPeriod;
|
||||||
|
}
|
||||||
|
/** */
|
||||||
|
public int getRemainingPeriods(int A_Current_Period)
|
||||||
|
{
|
||||||
|
return getRemainingPeriods(A_Current_Period, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
private boolean m_isFiscal = false;
|
||||||
|
/** */
|
||||||
|
public boolean isFiscal()
|
||||||
|
{
|
||||||
|
return m_isFiscal;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Set fiscal flag (temporary - is not modifing the workfile)
|
||||||
|
* @param fiscal
|
||||||
|
*/
|
||||||
|
public void setFiscal(boolean fiscal)
|
||||||
|
{
|
||||||
|
m_isFiscal = fiscal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Increment the current period (A_Current_Period) 1, and a month DateAcct */
|
||||||
|
public void incA_Current_Period()
|
||||||
|
{
|
||||||
|
int old_period = getA_Current_Period();
|
||||||
|
Timestamp old_date = getDateAcct();
|
||||||
|
int new_period = old_period + 1;
|
||||||
|
Timestamp new_date = TimeUtil.addMonths(getDateAcct(), 1);
|
||||||
|
setA_Current_Period(new_period);
|
||||||
|
setDateAcct(new_date);
|
||||||
|
//
|
||||||
|
if(CLogMgt.isLevelFine()) log.fine("(A_Current_Period, DateAcct)=(" + old_period + ", " + old_date + ")->(" + new_period + ", " + new_date + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set A Current Period (and Data Act) processed just after the last expense.
|
||||||
|
* Do not save.
|
||||||
|
*/
|
||||||
|
public void setA_Current_Period()
|
||||||
|
{
|
||||||
|
String whereClause = MDepreciationExp.COLUMNNAME_A_Asset_ID+"=?"
|
||||||
|
+" AND "+MDepreciationExp.COLUMNNAME_PostingType+"=?"
|
||||||
|
+" AND "+MDepreciationExp.COLUMNNAME_Processed+"=? AND IsActive=?"
|
||||||
|
;
|
||||||
|
//
|
||||||
|
MDepreciationExp depexp = new Query(getCtx(), MDepreciationExp.Table_Name, whereClause, get_TrxName())
|
||||||
|
.setParameters(new Object[]{getA_Asset_ID(), getPostingType(), true, true})
|
||||||
|
.setOrderBy(MDepreciationExp.COLUMNNAME_A_Period+" DESC"
|
||||||
|
+","+MDepreciationExp.COLUMNNAME_DateAcct+" DESC")
|
||||||
|
.first();
|
||||||
|
if (depexp != null)
|
||||||
|
{
|
||||||
|
setA_Current_Period(depexp.getA_Period());
|
||||||
|
setDateAcct(depexp.getDateAcct());
|
||||||
|
incA_Current_Period();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log.info("There are no records from which to infer its");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Build depreciation flag - if true, the depreciation should be built after save */
|
||||||
|
private boolean m_buildDepreciation = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build depreciation (A_Depreciation_Exp) entries. More exactly, is deleting not Processed entries.
|
||||||
|
* and create new ones again.
|
||||||
|
* WARNING: IS NOT modifying workfile (this)
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void buildDepreciation()
|
||||||
|
{
|
||||||
|
if (!isDepreciated())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
load(get_TrxName()); // reload workfile
|
||||||
|
MAssetAcct assetacct = getA_AssetAcct(null, get_TrxName());
|
||||||
|
// TODO: teo_sarca: need to evaluate what happens when we change Depreciation method !!!
|
||||||
|
MDepreciation depreciation_C = MDepreciation.get(getCtx(), assetacct.getA_Depreciation_ID());
|
||||||
|
MDepreciation depreciation_F = MDepreciation.get(getCtx(), assetacct.getA_Depreciation_F_ID());
|
||||||
|
//~ int offset_C = depreciation_C.getFixMonthOffset();
|
||||||
|
//~ int offset_F = depreciation_F.getFixMonthOffset();
|
||||||
|
int offset_C = 0, offset_F = 0;
|
||||||
|
|
||||||
|
BigDecimal assetCost = getActualCost();
|
||||||
|
BigDecimal accumDep_C = getA_Accumulated_Depr(false);
|
||||||
|
BigDecimal accumDep_F = getA_Accumulated_Depr(true);
|
||||||
|
int lifePeriods_C = getUseLifeMonths(false) + offset_C;
|
||||||
|
int lifePeriods_F = getUseLifeMonths(true) + offset_F;
|
||||||
|
int lifePeriods = (lifePeriods_C > lifePeriods_F ? lifePeriods_C : lifePeriods_F);
|
||||||
|
BigDecimal exp_C = Env.ZERO;
|
||||||
|
BigDecimal exp_F = Env.ZERO;
|
||||||
|
|
||||||
|
//logging
|
||||||
|
if(CLogMgt.isLevelFine())
|
||||||
|
{
|
||||||
|
sb.append("currentPeriod=" + getA_Current_Period() + ", AssetServiceDate=" + getAssetDepreciationDate() + "\n");
|
||||||
|
sb.append("offset: C|F=" + offset_C + "|" + offset_F + "\n");
|
||||||
|
sb.append("life: C|F=" + lifePeriods_C + "|" + lifePeriods_F + " + offset =" + lifePeriods + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
truncDepreciation();
|
||||||
|
int A_Current_Period = getA_Current_Period();
|
||||||
|
for (int currentPeriod = A_Current_Period, cnt = 1; currentPeriod <= lifePeriods; currentPeriod++, cnt++)
|
||||||
|
{
|
||||||
|
exp_C = Env.ZERO;
|
||||||
|
exp_F = Env.ZERO;
|
||||||
|
|
||||||
|
String help = "" + accumDep_C + "|" + accumDep_F + " + ";
|
||||||
|
|
||||||
|
if (lifePeriods_C > currentPeriod || !depreciation_C.requireLastPeriodAdjustment())
|
||||||
|
{
|
||||||
|
setFiscal(false);
|
||||||
|
exp_C = depreciation_C.invoke(this, assetacct, currentPeriod, accumDep_C);
|
||||||
|
accumDep_C = accumDep_C.add(exp_C);
|
||||||
|
}
|
||||||
|
else if (lifePeriods_C == currentPeriod)
|
||||||
|
{ // last period
|
||||||
|
exp_C = assetCost.subtract(accumDep_C);
|
||||||
|
accumDep_C = assetCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lifePeriods_F > currentPeriod || !depreciation_F.requireLastPeriodAdjustment())
|
||||||
|
{
|
||||||
|
setFiscal(true);
|
||||||
|
exp_F = depreciation_F.invoke(this, assetacct, currentPeriod, accumDep_F);
|
||||||
|
accumDep_F = accumDep_F.add(exp_F);
|
||||||
|
}
|
||||||
|
else if (lifePeriods_F == currentPeriod)
|
||||||
|
{ // last period (fiscal)
|
||||||
|
exp_F = assetCost.subtract(accumDep_F);
|
||||||
|
accumDep_F = assetCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
help += "" + exp_C + "|" + exp_F + " = " + accumDep_C + "|" + accumDep_F;
|
||||||
|
|
||||||
|
// added by zuhri
|
||||||
|
int months = 0;
|
||||||
|
|
||||||
|
months = months + (currentPeriod - A_Current_Period);
|
||||||
|
Timestamp dateAcct = TimeUtil.getMonthLastDay(TimeUtil.addMonths(getDateAcct(), months));
|
||||||
|
|
||||||
|
MDepreciationExp.createDepreciation (this, currentPeriod, dateAcct,
|
||||||
|
exp_C, exp_F,
|
||||||
|
accumDep_C, accumDep_F,
|
||||||
|
help, get_TrxName());
|
||||||
|
if(CLogMgt.isLevelFine())
|
||||||
|
{
|
||||||
|
String info = "" + cnt + ": period=" + currentPeriod + "/" + lifePeriods_C + "|" + lifePeriods_F
|
||||||
|
+ ", exp=" + exp_C + "|" + exp_F + ", accumDep=" + accumDep_C + "|" + accumDep_F
|
||||||
|
+ ", DateAcct=" + dateAcct;
|
||||||
|
log.fine("=> " + info + Env.NL + Env.NL);
|
||||||
|
sb.append(info + Env.NL);
|
||||||
|
}
|
||||||
|
} // for
|
||||||
|
log.fine(sb.toString());
|
||||||
|
|
||||||
|
m_buildDepreciation = false;
|
||||||
|
} // buildDepreciation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Truncate not processed depreciation entries.
|
||||||
|
* IS NOT modifying workfile.
|
||||||
|
*/
|
||||||
|
public void truncDepreciation()
|
||||||
|
{
|
||||||
|
String trxName = get_TrxName();
|
||||||
|
|
||||||
|
int A_Current_Period = getA_Current_Period();
|
||||||
|
final String sql = "DELETE FROM "+MDepreciationExp.Table_Name
|
||||||
|
+" WHERE "
|
||||||
|
+MDepreciationExp.COLUMNNAME_Processed+"=?"
|
||||||
|
+" AND "+MDepreciationExp.COLUMNNAME_A_Period+">=?"
|
||||||
|
+" AND "+MDepreciationExp.COLUMNNAME_A_Asset_ID+"=?"
|
||||||
|
+" AND "+MDepreciationExp.COLUMNNAME_PostingType+"=?"
|
||||||
|
;
|
||||||
|
Object[] params = new Object[]{false, A_Current_Period, getA_Asset_ID(), getPostingType()};
|
||||||
|
int no = DB.executeUpdateEx(sql, params, trxName);
|
||||||
|
log.fine("sql=" + sql + "\nDeleted #" + no);
|
||||||
|
} // truncDepreciation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Founding Mode related fields
|
||||||
|
* @param m model
|
||||||
|
* @param changedColumnName column name that has been changed
|
||||||
|
*/
|
||||||
|
public static void updateFinantare(SetGetModel m, String changedColumnName)
|
||||||
|
{
|
||||||
|
//Own contribution:
|
||||||
|
BigDecimal valCofinantare = SetGetUtil.get_AttrValueAsBigDecimal(m, COLUMNNAME_A_Valoare_Cofinantare);
|
||||||
|
// Asset Value:
|
||||||
|
BigDecimal assetCost = SetGetUtil.get_AttrValueAsBigDecimal(m, COLUMNNAME_A_Asset_Cost);
|
||||||
|
// Third value:
|
||||||
|
BigDecimal valTert = SetGetUtil.get_AttrValueAsBigDecimal(m, COLUMNNAME_A_Valoare_Tert);
|
||||||
|
|
||||||
|
// Calculate values
|
||||||
|
if (valCofinantare.signum() == 0 && valTert.signum() == 0)
|
||||||
|
{
|
||||||
|
// Values have never been set, so put everything on their own financing
|
||||||
|
valCofinantare = assetCost;
|
||||||
|
valTert = Env.ZERO;
|
||||||
|
}
|
||||||
|
else if (COLUMNNAME_A_Asset_Cost.equals(changedColumnName))
|
||||||
|
{
|
||||||
|
valCofinantare = assetCost.subtract(valTert);
|
||||||
|
}
|
||||||
|
else if (COLUMNNAME_A_Valoare_Cofinantare.equals(changedColumnName))
|
||||||
|
{
|
||||||
|
valTert = assetCost.subtract(valCofinantare);
|
||||||
|
}
|
||||||
|
else if (COLUMNNAME_A_Valoare_Tert.equals(changedColumnName))
|
||||||
|
{
|
||||||
|
valCofinantare = assetCost.subtract(valTert);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
valTert = assetCost.subtract(valCofinantare);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Financing Type
|
||||||
|
String tipFinantare = A_TIP_FINANTARE_Cofinantare;
|
||||||
|
if (valTert.signum() == 0)
|
||||||
|
{
|
||||||
|
tipFinantare = A_TIP_FINANTARE_Proprie;
|
||||||
|
}
|
||||||
|
else if (valCofinantare.signum() == 0)
|
||||||
|
{
|
||||||
|
tipFinantare = A_TIP_FINANTARE_Terti;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Set values
|
||||||
|
m.set_AttrValue(COLUMNNAME_A_Tip_Finantare, tipFinantare);
|
||||||
|
m.set_AttrValue(COLUMNNAME_A_Valoare_Cofinantare, valCofinantare);
|
||||||
|
m.set_AttrValue(COLUMNNAME_A_Valoare_Tert, valTert);
|
||||||
|
//
|
||||||
|
// If the method is invoked for a persistent object when reset mode of financing
|
||||||
|
if (A_TIP_FINANTARE_Proprie.equals(tipFinantare) && SetGetUtil.isPersistent(m))
|
||||||
|
{
|
||||||
|
m.set_AttrValue(COLUMNNAME_A_FundingMode_ID, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean set_AttrValue(String ColumnName, Object value) {
|
||||||
|
int index = get_ColumnIndex(ColumnName);
|
||||||
|
if (index < 0)
|
||||||
|
return false;
|
||||||
|
return set_ValueNoCheck(ColumnName, value);
|
||||||
|
}
|
||||||
|
public Object get_AttrValue(String ColumnName) {
|
||||||
|
int index = get_ColumnIndex(ColumnName);
|
||||||
|
if (index < 0)
|
||||||
|
return null;
|
||||||
|
return get_Value(index);
|
||||||
|
}
|
||||||
|
public boolean is_AttrValueChanged(String ColumnName) {
|
||||||
|
int index = get_ColumnIndex(ColumnName);
|
||||||
|
if (index < 0)
|
||||||
|
return false;
|
||||||
|
return is_ValueChanged(index);
|
||||||
|
}
|
||||||
|
} // MDepreciationWorkfile
|
||||||
|
|
|
@ -2105,8 +2105,7 @@ public class MInOut extends X_M_InOut implements DocAction
|
||||||
if (asset != null)
|
if (asset != null)
|
||||||
{
|
{
|
||||||
asset.setIsActive(false);
|
asset.setIsActive(false);
|
||||||
StringBuilder msgadd = new StringBuilder("(").append(reversal.getDocumentNo()).append(" #").append(rLine.getLine()).append("<-)");
|
asset.setDescription(asset.getDescription() + " (" + reversal.getDocumentNo() + " #" + rLine.getLine() + "<-)");
|
||||||
asset.addDescription(msgadd.toString());
|
|
||||||
asset.saveEx();
|
asset.saveEx();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,83 +1,78 @@
|
||||||
/******************************************************************************
|
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
|
||||||
* Copyright (C) 1999-2006 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.compiere.model;
|
package org.compiere.model;
|
||||||
|
import java.util.*;
|
||||||
import java.math.BigDecimal;
|
import java.sql.*;
|
||||||
import java.sql.ResultSet;
|
import java.math.*;
|
||||||
import java.util.Properties;
|
import org.compiere.model.*;
|
||||||
|
import org.compiere.util.*;
|
||||||
import org.compiere.util.Env;
|
/** Generated Model for A_Asset
|
||||||
|
** @version $Id: X_A_Asset.java,v 1.88 2004/08/27 21:26:37 jjanke Exp $ */
|
||||||
/*******************************************************************************
|
public class MXIFAJournal extends X_I_FAJournal
|
||||||
* Generated Model for A_Asset
|
{
|
||||||
*
|
public MXIFAJournal (Properties ctx, int I_FAJournal_ID, String trxName)
|
||||||
* @version $Id: X_A_Asset.java,v 1.88 2004/08/27 21:26:37 jjanke Exp $ *
|
{
|
||||||
******************************************************************************/
|
super (ctx, I_FAJournal_ID, trxName);
|
||||||
public class MXIFAJournal extends X_I_FAJournal {
|
// if (I_FAJournal_ID == 0)
|
||||||
/**
|
// {
|
||||||
*
|
// setIsDepreciated (false);
|
||||||
*/
|
// setIsFullyDepreciated (false);
|
||||||
private static final long serialVersionUID = -3922040740843729868L;
|
// setValue (null);
|
||||||
|
// setName (null);
|
||||||
public MXIFAJournal(Properties ctx, int I_FAJournal_ID, String trxName) {
|
// setIsInPosession (false);
|
||||||
super(ctx, I_FAJournal_ID, trxName);
|
// setIsOwned (false);
|
||||||
if (I_FAJournal_ID == 0) {
|
// setA_Asset_Group_ID (0);
|
||||||
// setIsDepreciated (false);
|
// setIsDisposed (false);
|
||||||
// setIsFullyDepreciated (false);
|
// setM_AttributeSetInstance_ID(0);
|
||||||
// setValue (null);
|
// }
|
||||||
// setName (null);
|
} // MXIFAJournal
|
||||||
// setIsInPosession (false);
|
|
||||||
// setIsOwned (false);
|
|
||||||
// setA_Asset_Group_ID (0);
|
|
||||||
// setIsDisposed (false);
|
|
||||||
// setM_AttributeSetInstance_ID(0);
|
|
||||||
}
|
|
||||||
} // MAsset
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load Constructor
|
* Load Constructor
|
||||||
*
|
* @param ctx context
|
||||||
* @param ctx
|
* @param rs result set record
|
||||||
* context
|
|
||||||
* @param rs
|
|
||||||
* result set record
|
|
||||||
*/
|
*/
|
||||||
public MXIFAJournal(Properties ctx, ResultSet rs, String trxName) {
|
public MXIFAJournal (Properties ctx, ResultSet rs, String trxName)
|
||||||
super(ctx, rs, trxName);
|
{
|
||||||
} // MAsset
|
super (ctx, rs, trxName);
|
||||||
|
} // MAsset
|
||||||
|
|
||||||
public BigDecimal getExpenseDr() {
|
|
||||||
BigDecimal bd = getAmtAcctDr();
|
public BigDecimal getExpenseDr()
|
||||||
return bd;
|
{
|
||||||
|
BigDecimal bd = getAmtAcctDr();
|
||||||
|
return bd;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getExpenseCr() {
|
public BigDecimal getExpenseCr()
|
||||||
BigDecimal bd = getAmtAcctCr();
|
{
|
||||||
return bd;
|
BigDecimal bd = getAmtAcctCr();
|
||||||
|
return bd;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getAmtAcctTotal() {
|
public BigDecimal getAmtAcctTotal()
|
||||||
BigDecimal dr = getAmtAcctDr();
|
{
|
||||||
BigDecimal cr = getAmtAcctCr();
|
BigDecimal dr = getAmtAcctDr();
|
||||||
BigDecimal bd = (dr).subtract(cr);
|
BigDecimal cr = getAmtAcctCr();
|
||||||
if (bd == null)
|
BigDecimal bd = (dr).subtract(cr);
|
||||||
return Env.ZERO;
|
if (bd == null) return Env.ZERO;
|
||||||
return bd;
|
return bd;
|
||||||
}
|
}
|
||||||
|
/** Set Currency Type.
|
||||||
|
Currency Conversion Rate Type */
|
||||||
|
public void setC_ConversionType_ID (int C_ConversionType_ID)
|
||||||
|
{
|
||||||
|
if (C_ConversionType_ID == 0) set_Value ("C_ConversionType_ID", null);
|
||||||
|
else
|
||||||
|
set_Value ("C_ConversionType_ID", Integer.valueOf(C_ConversionType_ID));
|
||||||
|
}
|
||||||
|
/** Get Currency Type.
|
||||||
|
Currency Conversion Rate Type */
|
||||||
|
public int getC_ConversionType_ID()
|
||||||
|
{
|
||||||
|
Integer ii = (Integer)get_Value("C_ConversionType_ID");
|
||||||
|
if (ii == null) return 0;
|
||||||
|
return ii.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||||
* This program is free software; you can redistribute it and/or modify it *
|
* 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 *
|
* under the terms version 2 of the GNU General Public License as published *
|
||||||
|
@ -728,4 +728,72 @@ public class TimeUtil
|
||||||
System.out.println(isSameDay(t3, t5) + " == false");
|
System.out.println(isSameDay(t3, t5) + " == false");
|
||||||
} // main
|
} // main
|
||||||
|
|
||||||
|
// ARHIPAC: TEO: ADDITION ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* [ ARHIPAC ] Gets calendar instance of given date
|
||||||
|
* @param date calendar initialization date; if null, the current date is used
|
||||||
|
* @return calendar
|
||||||
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
|
*/
|
||||||
|
static public Calendar getCalendar(Timestamp date)
|
||||||
|
{
|
||||||
|
GregorianCalendar cal = new GregorianCalendar(Language.getLoginLanguage().getLocale());
|
||||||
|
if (date != null) {
|
||||||
|
cal.setTimeInMillis(date.getTime());
|
||||||
|
}
|
||||||
|
return cal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ ARHIPAC ] Get first date in month
|
||||||
|
* @param day day; if null current time will be used
|
||||||
|
* @return first day of the month (time will be 00:00)
|
||||||
|
*/
|
||||||
|
static public Timestamp getMonthFirstDay (Timestamp day)
|
||||||
|
{
|
||||||
|
if (day == null)
|
||||||
|
day = new Timestamp(System.currentTimeMillis());
|
||||||
|
Calendar cal = getCalendar(day);
|
||||||
|
cal.setTimeInMillis(day.getTime());
|
||||||
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
cal.set(Calendar.MINUTE, 0);
|
||||||
|
cal.set(Calendar.SECOND, 0);
|
||||||
|
cal.set(Calendar.MILLISECOND, 0);
|
||||||
|
//
|
||||||
|
cal.set(Calendar.DAY_OF_MONTH, 1); // first
|
||||||
|
return new Timestamp (cal.getTimeInMillis());
|
||||||
|
} // getMonthFirstDay
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ ARHIPAC ] Return Day + offset (truncates)
|
||||||
|
* @param day Day; if null current time will be used
|
||||||
|
* @param offset months offset
|
||||||
|
* @return Day + offset (time will be 00:00)
|
||||||
|
* @return Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
|
*/
|
||||||
|
static public Timestamp addMonths (Timestamp day, int offset)
|
||||||
|
{
|
||||||
|
if (day == null)
|
||||||
|
day = new Timestamp(System.currentTimeMillis());
|
||||||
|
//
|
||||||
|
GregorianCalendar cal = new GregorianCalendar();
|
||||||
|
cal.setTime(day);
|
||||||
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
cal.set(Calendar.MINUTE, 0);
|
||||||
|
cal.set(Calendar.SECOND, 0);
|
||||||
|
cal.set(Calendar.MILLISECOND, 0);
|
||||||
|
if (offset == 0)
|
||||||
|
return new Timestamp (cal.getTimeInMillis());
|
||||||
|
cal.add(Calendar.MONTH, offset);
|
||||||
|
return new Timestamp (cal.getTimeInMillis());
|
||||||
|
} // addMonths
|
||||||
|
|
||||||
|
public static int getMonthsBetween (Timestamp start, Timestamp end)
|
||||||
|
{
|
||||||
|
Calendar startCal = getCalendar(start);
|
||||||
|
Calendar endCal = getCalendar(end);
|
||||||
|
//
|
||||||
|
return endCal.get(Calendar.YEAR) * 12 + endCal.get(Calendar.MONTH)
|
||||||
|
- (startCal.get(Calendar.YEAR) * 12 + startCal.get(Calendar.MONTH));
|
||||||
|
}
|
||||||
} // TimeUtil
|
} // TimeUtil
|
||||||
|
|
Loading…
Reference in New Issue