remove unused previous asset classes

transplanted from https://bitbucket.org/edwin_ang/adempiere361-mbd/changeset/8d660c3
This commit is contained in:
Carlos Ruiz 2012-10-24 19:46:31 -05:00
parent f75aeb5aba
commit c44b10969e
15 changed files with 0 additions and 6451 deletions

View File

@ -1,221 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.compiere.model.MAssetChange;
import org.compiere.model.MRefList;
import org.compiere.model.X_A_Asset_Disposed;
import org.compiere.model.X_A_Depreciation_Exp;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Dispose Asset
*
* @author Rob klein
* @version $Id: AssetDisposed.java,v 1.0$
*/
public class AssetDisposed extends SvrProcess
{
/** Record ID */
private int p_Asset_Disposed_ID = 0;
private boolean m_DeleteOld = false;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else if (name.equals("DeleteOld"))
m_DeleteOld = "Y".equals(para[i].getParameter());
else
log.info("prepare - Unknown Parameter: " + name);
}
p_Asset_Disposed_ID = getRecord_ID();
} // prepare
/**
* Build Depreciation Workfile
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("doIt - Asset_Disposed_ID=" + p_Asset_Disposed_ID);
if (p_Asset_Disposed_ID == 0)
throw new IllegalArgumentException("No Record");
String sql = null;
//
int no = 0;
BigDecimal v_Balance = new BigDecimal("0.0");
X_A_Asset_Disposed AssetDisposed = new X_A_Asset_Disposed (getCtx(), p_Asset_Disposed_ID, null);
String clientCheck = " AND AD_Client_ID=" + AssetDisposed.getAD_Client_ID();
if (m_DeleteOld)
{
sql = "DELETE A_DEPRECIATION_EXP "
+ "WHERE Processed='Y'"
+ " AND A_Entry_Type = 'DIS'" + clientCheck;
no = DB.executeUpdate (sql,null);
log.info ("doIt - Delete old processed entries =" + no);
}
sql = null;
log.info("doIt - Starting Disposal = " + no);
sql = "SELECT A.A_ASSET_ID, A.POSTINGTYPE, A.A_DEPRECIATION_ACCT, "
+ " A.A_ACCUMDEPRECIATION_ACCT, A.A_DISPOSAL_LOSS, A.A_DISPOSAL_REVENUE, "
+ " A.A_ASSET_ACCT, A.A_SPLIT_PERCENT, A.AD_ORG_ID, A.AD_CLIENT_ID, "
+ " B.A_ASSET_COST, B.A_ACCUMULATED_DEPR "
+ " FROM A_ASSET_ACCT A, A_DEPRECIATION_WORKFILE B "
+ " WHERE A.A_ASSET_ID = " + AssetDisposed.getA_Asset_ID()
+ " and B.A_ASSET_ID = " + AssetDisposed.getA_Asset_ID()
+ " and A.POSTINGTYPE = B.POSTINGTYPE"
+ " and A.AD_CLIENT_ID = B.AD_CLIENT_ID";
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql,null);
log.info("doIt - SQL=" + sql);
String v_PostingType = null;
//X_A_Depreciation_Exp depexp = new X_A_Depreciation_Exp (getCtx(), 0, null);
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
while (rs.next()){
if (v_PostingType != null && (!v_PostingType.equals(rs.getString("PostingType"))))
{
sql = "UPDATE A_DEPRECIATION_WORKFILE "
+ "SET A_ACCUMULATED_DEPR = " + v_Balance
+ "WHERE A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + AssetDisposed.getA_Asset_ID()
+ "AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '" + v_PostingType + "'";
DB.executeUpdate(sql,null);
v_Balance = new BigDecimal("0.0");
v_PostingType = rs.getString("PostingType");
}
else if (v_PostingType == null)
{
v_PostingType = rs.getString("PostingType");
}
// Create JV for the asset disposal - remove cost of asset on balance sheet
X_A_Depreciation_Exp depexp0 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp0.setPostingType(rs.getString("PostingType"));
depexp0.setA_Asset_ID(AssetDisposed.getA_Asset_ID());
depexp0.setExpense(rs.getBigDecimal("A_Asset_Cost").multiply(new BigDecimal(-1)).multiply(rs.getBigDecimal("A_Split_Percent")));
depexp0.setDateAcct(AssetDisposed.getDateAcct());
depexp0.setA_Account_Number(rs.getInt("A_Asset_Acct"));
depexp0.setDescription("Asset Disposed - Cost of Asset");
depexp0.setIsDepreciated(true);
depexp0.setA_Period(AssetDisposed.getC_Period_ID());
depexp0.setA_Entry_Type("DIS");
depexp0.saveEx();
X_A_Depreciation_Exp depexp1 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp1.setPostingType(rs.getString("PostingType"));
depexp1.setA_Asset_ID(AssetDisposed.getA_Asset_ID());
depexp1.setExpense(rs.getBigDecimal("A_Asset_Cost").multiply(rs.getBigDecimal("A_Split_Percent")));
depexp1.setDateAcct(AssetDisposed.getDateAcct());
depexp1.setA_Account_Number(rs.getInt("A_Disposal_Loss"));
depexp1.setDescription("Asset Disposed - Cost of Asset");
depexp1.setIsDepreciated(false);
depexp1.setA_Period(AssetDisposed.getC_Period_ID());
depexp1.setA_Entry_Type("DIS");
depexp1.saveEx();
v_Balance = v_Balance.add(rs.getBigDecimal("A_Asset_Cost").multiply(rs.getBigDecimal("A_Split_Percent")));
// Create JV for the asset disposal - remove accumulated depreciation of the asset on balance sheet
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp2.setPostingType(rs.getString("PostingType"));
depexp2.setA_Asset_ID(AssetDisposed.getA_Asset_ID());
depexp2.setExpense(rs.getBigDecimal("A_Accumulated_Depr").multiply(rs.getBigDecimal("A_Split_Percent")));
depexp2.setDateAcct(AssetDisposed.getDateAcct());
depexp2.setA_Account_Number(rs.getInt("A_Accumdepreciation_Acct"));
depexp2.setDescription("Asset Disposed - Accum Depr");
depexp2.setIsDepreciated(true);
depexp2.setA_Period(AssetDisposed.getC_Period_ID());
depexp2.setA_Entry_Type("DIS");
depexp2.saveEx();
X_A_Depreciation_Exp depexp3 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp3.setPostingType(rs.getString("PostingType"));
depexp3.setA_Asset_ID(AssetDisposed.getA_Asset_ID());
depexp3.setExpense(rs.getBigDecimal("A_Accumulated_Depr").multiply(new BigDecimal(-1)).multiply(rs.getBigDecimal("A_Split_Percent")));
depexp3.setDateAcct(AssetDisposed.getDateAcct());
depexp3.setA_Account_Number(rs.getInt("A_Disposal_Loss"));
depexp3.setDescription("Asset Disposed - Accum Depr");
depexp3.setIsDepreciated(false);
depexp3.setA_Period(AssetDisposed.getC_Period_ID());
depexp3.setA_Entry_Type("DIS");
depexp3.saveEx();
}
sql = "UPDATE A_ASSET "
+ "SET ISDISPOSED = 'Y',"
+ " ASSETDISPOSALDATE = " + DB.TO_DATE(AssetDisposed.getA_Disposed_Date())
+ " WHERE A_ASSET_ID = " + AssetDisposed.getA_Asset_ID();
DB.executeUpdate(sql,null);
sql = "UPDATE A_DEPRECIATION_WORKFILE "
+ "SET A_ACCUMULATED_DEPR = " + v_Balance
+ "WHERE A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + AssetDisposed.getA_Asset_ID()
+ "AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '" + v_PostingType + "'";
DB.executeUpdate(sql,null);
MAssetChange change = new MAssetChange (getCtx(), 0, null);
change.setA_Asset_ID(AssetDisposed.getA_Asset_ID());
change.setChangeType("DIS");
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "DIS"));
change.setAssetDisposalDate(AssetDisposed.getA_Disposed_Date());
change.setAssetAccumDepreciationAmt(v_Balance);
change.setIsFullyDepreciated(true);
change.setIsDisposed(true);
change.saveEx();
}
catch (Exception e)
{
log.info("getDeliveries"+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
} // doIt
} // AssetDisposed

View File

@ -1,410 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.compiere.model.MAsset;
import org.compiere.model.X_A_Asset_Reval_Entry;
import org.compiere.model.X_A_Asset_Reval_Index;
import org.compiere.model.X_A_Depreciation_Exp;
import org.compiere.model.X_C_Period;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Asset Revaluation Entry
*
* @author Rob Klein
* @version $Id: AssetRevalEntry.java,v 1.0$
*/
public class AssetRevalEntry extends SvrProcess
{
/** Record ID */
private int p_Asset_Reval_Entry_ID = 0;
private boolean m_DeleteOld = false;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else if (name.equals("DeleteOld"))
m_DeleteOld = "Y".equals(para[i].getParameter());
else
log.info("prepare - Unknown Parameter: " + name);
}
p_Asset_Reval_Entry_ID = getRecord_ID();
} // prepare
/**
* Build Depreciation Workfile
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("doIt - Asset_Reval_Entry_ID=" + p_Asset_Reval_Entry_ID);
if (p_Asset_Reval_Entry_ID == 0)
throw new IllegalArgumentException("No Record");
//
int no = 0;
BigDecimal v_Cost_reval = new BigDecimal("0.0");
BigDecimal v_Cost_reval_pior = new BigDecimal("0.0");
BigDecimal v_Accum_reval = new BigDecimal("0.0");
BigDecimal v_Accum_reval_prior = new BigDecimal("0.0");
BigDecimal v_Current_exp_reval = new BigDecimal("0.0");
BigDecimal v_Multipler = new BigDecimal("0.0");
BigDecimal v_Dep_Exp_reval = new BigDecimal("0.0");
X_A_Asset_Reval_Entry AssetReval = new X_A_Asset_Reval_Entry (getCtx(), p_Asset_Reval_Entry_ID, null);
X_C_Period Period = new X_C_Period (getCtx(), AssetReval.getC_Period_ID(), null);
String sql = null;
log.info("doIt - Starting Transfer = " + no);
String clientCheck = " AND AD_Client_ID=" + AssetReval.getAD_Client_ID();
sql = "SELECT A.A_REVAL_COST_OFFSET, A.A_REVAL_ACCUMDEP_OFFSET_CUR, A.A_REVAL_DEPEXP_OFFSET "
+ " A.A_ACCUMDEPRECIATION_ACCT, A.A_ASSET_ACCT, A.A_DEPRECIATION_ACCT, "
+ " A.A_REVAL_ACCUMDEP_OFFSET_PRIOR, A.A_REVAL_COST_OFFSET_PRIOR "
+ " B.A_ASSET_ID, B.A_ASSET_COST, B.A_ACCUMULATED_DEPR, B.A_ASSET_COST_REVAL, B.A_ACCUMULATED_DEPR_REVAL"
+ " FROM A_ASSET_ACCT A, A_DEPRECIATION_WORKFILE B"
+ " WHERE A.POSTINGTYPE = '" + AssetReval.getPostingType()
+ " AND B.POSTINGTYPE = '" + AssetReval.getPostingType()
+ " AND A.AD_Client_ID=" + AssetReval.getAD_Client_ID()
+ " AND B.AD_Client_ID=" + AssetReval.getAD_Client_ID()
+ " AND A.AD_Asset_ID = A.AD_Asset_ID";
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql,null);
log.info("doIt - SQL=" + sql);
ResultSet rs = null;
X_A_Depreciation_Exp depexp = new X_A_Depreciation_Exp (getCtx(), 0, null);
if (m_DeleteOld)
{
sql = "DELETE A_DEPRECIATION_EXP "
+ "WHERE Processed='Y'"
+ " AND A_Entry_Type = 'RVL'" + clientCheck;
no = DB.executeUpdate (sql,null);
log.info ("doIt - Delete old processed entries =" + no);
}
try {
rs = pstmt.executeQuery();
while (rs.next()){
String sql2 = "select A_ASSET_REVAL_INDEX_ID from A_ASSET_REVAL_INDEX where A_REVAL_CODE = " + AssetReval.getA_Rev_Code()
+ " and A_EFFECTIVE_DATE = (select MAX(A_EFFECTIVE_DATE) from A_ASSET_REVAL_INDEX where A_EFFECTIVE_DATE < "
+ AssetReval.getA_Effective_Date()
+ ")";
X_A_Asset_Reval_Index ARevalIndex = new X_A_Asset_Reval_Index (getCtx(), DB.getSQLValue(null ,sql), null);
MAsset Asset = new MAsset (getCtx(), rs.getInt("A_Asset_ID"), null);
if (AssetReval.getA_Reval_Multiplier().equals(X_A_Asset_Reval_Entry.A_REVAL_MULTIPLIER_Index))
{
if (AssetReval.getA_Reval_Effective_Date().equals(X_A_Asset_Reval_Entry.A_REVAL_EFFECTIVE_DATE_DateAquired)){
sql2 = "Select A_REVAL_MULTIPLIER from A_ASSET_REVAL_INDEX where A_REVAL_CODE = " + AssetReval.getA_Rev_Code()
+ " and A_EFFECTIVE_DATE = (select MAX(A_EFFECTIVE_DATE) from A_ASSET_REVAL_INDEX where A_EFFECTIVE_DATE < "
+ Asset.getA_Asset_CreateDate()
+ ")";
}
else if (AssetReval.getA_Reval_Effective_Date().equals(X_A_Asset_Reval_Entry.A_REVAL_EFFECTIVE_DATE_RevaluationDate)){
sql2 = "Select A_REVAL_MULTIPLIER from A_ASSET_REVAL_INDEX where A_REVAL_CODE = " + AssetReval.getA_Rev_Code()
+ " and A_EFFECTIVE_DATE = (select MAX(A_EFFECTIVE_DATE) from A_ASSET_REVAL_INDEX where A_EFFECTIVE_DATE < "
+ Asset.getA_Asset_RevalDate()
+ ")";
}
else if (AssetReval.getA_Reval_Effective_Date().equals(X_A_Asset_Reval_Entry.A_REVAL_EFFECTIVE_DATE_DateDepreciationStarted)){
sql2 = "Select A_REVAL_MULTIPLIER from A_ASSET_REVAL_INDEX where A_REVAL_CODE = " + AssetReval.getA_Rev_Code()
+ " and A_EFFECTIVE_DATE = (select MAX(A_EFFECTIVE_DATE) from A_ASSET_REVAL_INDEX where A_EFFECTIVE_DATE < "
+ Asset.getAssetServiceDate()
+ ")";
}
PreparedStatement pstmt2 = null;
pstmt2 = DB.prepareStatement (sql2,null);
ResultSet rs2 = null;
log.info("doIt - SQL2=" + sql2);
try {
rs2 = pstmt2.executeQuery();
while (rs2.next()){
v_Multipler = ARevalIndex.getA_Reval_Rate().divide(rs2.getBigDecimal("A_REVAL_MULTIPLIER"),8);
}
v_Cost_reval = ((rs.getBigDecimal("A_Asset_Cost").subtract(rs.getBigDecimal("A_ASSET_COST_REVAL"))).multiply( v_Multipler)).subtract(rs.getBigDecimal("A_Asset_Cost"));
v_Accum_reval = ((rs.getBigDecimal("A_ACCUMULATED_DEPR").subtract(rs.getBigDecimal("A_ACCUMULATED_DEPR_REVAL"))).multiply( v_Multipler)).subtract(rs.getBigDecimal("A_ACCUMULATED_DEPR"));
sql2 = "SELECT SUM(CHANGEAMT) AS SUM_CHANGEAMT FROM A_ASSET_CHANGE WHERE A_ASSET_ID = "
+ rs.getInt("A_Asset_ID")+ " AND CHANGETYPE = 'D'";
pstmt2 = DB.prepareStatement (sql2,null);
log.info("doIt - SQL2=" + sql2);
try {
rs2 = pstmt2.executeQuery();
while (rs2.next()){
v_Dep_Exp_reval = (rs2.getBigDecimal("SUM_CHANGEAMT").multiply( v_Multipler)).subtract(rs.getBigDecimal("SUM_CHANGEAMT"));
}
}
catch (Exception e)
{
log.info("getDeliveries"+ e);
}
finally
{
DB.close(rs, pstmt2);
rs2 = null; pstmt2 = null;
}
// Create JV for the Reval Cost Amounts
X_A_Depreciation_Exp depexp0 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp0.setPostingType(AssetReval.getPostingType());
depexp0.setA_Asset_ID(Asset.getA_Asset_ID());
depexp0.setExpense(v_Cost_reval);
depexp0.setDateAcct(AssetReval.getDateAcct());
depexp0.setA_Account_Number(rs.getInt("A_ASSET_ACCT"));
depexp0.setDescription("Asset Revaluation");
depexp0.setIsDepreciated(false);
depexp0.setA_Period(AssetReval.getC_Period_ID());
depexp0.setA_Entry_Type("RVL");
depexp0.saveEx();
X_A_Depreciation_Exp depexp1 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp1.setPostingType(AssetReval.getPostingType());
depexp1.setA_Asset_ID(Asset.getA_Asset_ID());
depexp1.setExpense(v_Cost_reval.multiply(new BigDecimal(-1)));
depexp1.setDateAcct(AssetReval.getDateAcct());
depexp1.setA_Account_Number(rs.getInt("A_REVAL_COST_OFFSET"));
depexp1.setDescription("Asset Revaluation");
depexp1.setIsDepreciated(false);
depexp1.setA_Period(AssetReval.getC_Period_ID());
depexp1.setA_Entry_Type("RVL");
depexp1.saveEx();
// Create JV for the Reval Accum Depr Amounts
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp2.setPostingType(AssetReval.getPostingType());
depexp2.setA_Asset_ID(Asset.getA_Asset_ID());
depexp2.setExpense(v_Accum_reval);
depexp2.setDateAcct(AssetReval.getDateAcct());
depexp2.setA_Account_Number(rs.getInt("A_ACCUMDEPRECIATION_ACCT"));
depexp2.setDescription("Asset Revaluation");
depexp2.setIsDepreciated(false);
depexp2.setA_Period(AssetReval.getC_Period_ID());
depexp2.setA_Entry_Type("RVL");
depexp2.saveEx();
X_A_Depreciation_Exp depexp3 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp3.setPostingType(AssetReval.getPostingType());
depexp3.setA_Asset_ID(Asset.getA_Asset_ID());
depexp3.setExpense(v_Accum_reval.multiply(new BigDecimal(-1)));
depexp3.setDateAcct(AssetReval.getDateAcct());
depexp3.setA_Account_Number(rs.getInt("A_ACCUMULATED_DEPR_REVAL"));
depexp3.setDescription("Asset Revaluation");
depexp3.setIsDepreciated(false);
depexp3.setA_Period(AssetReval.getC_Period_ID());
depexp3.setA_Entry_Type("RVL");
depexp3.saveEx();
// Create JV for the Reval Depreciation Expense Amounts
X_A_Depreciation_Exp depexp4 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp4.setPostingType(AssetReval.getPostingType());
depexp4.setA_Asset_ID(Asset.getA_Asset_ID());
depexp4.setExpense(v_Dep_Exp_reval);
depexp4.setDateAcct(AssetReval.getDateAcct());
depexp4.setA_Account_Number(rs.getInt("A_DEPRECIATION_ACCT"));
depexp4.setDescription("Asset Revaluation");
depexp4.setIsDepreciated(false);
depexp4.setA_Period(AssetReval.getC_Period_ID());
depexp4.setA_Entry_Type("RVL");
depexp4.saveEx();
X_A_Depreciation_Exp depexp5 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp5.setPostingType(AssetReval.getPostingType());
depexp5.setA_Asset_ID(Asset.getA_Asset_ID());
depexp5.setExpense(v_Dep_Exp_reval.multiply(new BigDecimal(-1)));
depexp5.setDateAcct(AssetReval.getDateAcct());
depexp5.setA_Account_Number(rs.getInt("A_REVAL_DEPEXP_OFFSET"));
depexp5.setDescription("Asset Revaluation");
depexp5.setIsDepreciated(false);
depexp5.setA_Period(AssetReval.getC_Period_ID());
depexp5.setA_Entry_Type("RVL");
depexp5.saveEx();
}
catch (Exception e)
{
log.info("getDeliveries"+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
} }
else if (AssetReval.getA_Reval_Multiplier().equals(X_A_Asset_Reval_Entry.A_REVAL_MULTIPLIER_Factor))
{
if (AssetReval.getA_Reval_Effective_Date().equals(X_A_Asset_Reval_Entry.A_REVAL_EFFECTIVE_DATE_DateAquired)){
sql2 = "Select A_REVAL_MULTIPLIER from A_ASSET_REVAL_INDEX where A_REVAL_CODE = " + AssetReval.getA_Rev_Code()
+ " and A_EFFECTIVE_DATE = (select MAX(A_EFFECTIVE_DATE) from A_ASSET_REVAL_INDEX where A_EFFECTIVE_DATE < "
+ Asset.getA_Asset_CreateDate()
+ ")";
}
else if (AssetReval.getA_Reval_Effective_Date().equals(X_A_Asset_Reval_Entry.A_REVAL_EFFECTIVE_DATE_RevaluationDate)){
sql2 = "Select A_REVAL_MULTIPLIER from A_ASSET_REVAL_INDEX where A_REVAL_CODE = " + AssetReval.getA_Rev_Code()
+ " and A_EFFECTIVE_DATE = (select MAX(A_EFFECTIVE_DATE) from A_ASSET_REVAL_INDEX where A_EFFECTIVE_DATE < "
+ Asset.getA_Asset_RevalDate()
+ ")";
}
else if (AssetReval.getA_Reval_Effective_Date().equals(X_A_Asset_Reval_Entry.A_REVAL_EFFECTIVE_DATE_DateDepreciationStarted)){
sql2 = "Select A_REVAL_MULTIPLIER from A_ASSET_REVAL_INDEX where A_REVAL_CODE = " + AssetReval.getA_Rev_Code()
+ " and A_EFFECTIVE_DATE = (select MAX(A_EFFECTIVE_DATE) from A_ASSET_REVAL_INDEX where A_EFFECTIVE_DATE < "
+ Asset.getAssetServiceDate()
+ ")";
}
PreparedStatement pstmt2 = null;
pstmt2 = DB.prepareStatement (sql2,null);
log.info("doIt - SQL2=" + sql2);
try {
ResultSet rs2 = pstmt2.executeQuery();
while (rs2.next()){
v_Multipler = rs2.getBigDecimal("A_REVAL_MULTIPLIER");
}
v_Cost_reval = ((rs.getBigDecimal("A_Asset_Cost").subtract(rs.getBigDecimal("A_ASSET_COST_REVAL"))).multiply( v_Multipler)).subtract(rs.getBigDecimal("A_Asset_Cost"));
v_Accum_reval = ((rs.getBigDecimal("A_ACCUMULATED_DEPR").subtract(rs.getBigDecimal("A_ACCUMULATED_DEPR_REVAL"))).multiply( v_Multipler)).subtract(rs.getBigDecimal("A_ACCUMULATED_DEPR"));
}
catch (Exception e)
{
log.info("getDeliveries"+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
} }
v_Cost_reval = ((rs.getBigDecimal("A_Asset_Cost").subtract(rs.getBigDecimal("A_ASSET_COST_REVAL"))).multiply( v_Multipler)).subtract(rs.getBigDecimal("A_Asset_Cost"));
v_Accum_reval = ((rs.getBigDecimal("A_ACCUMULATED_DEPR").subtract(rs.getBigDecimal("A_ACCUMULATED_DEPR_REVAL"))).multiply( v_Multipler)).subtract(rs.getBigDecimal("A_ACCUMULATED_DEPR"));
// Create JV for the Reval Cost Amounts
X_A_Depreciation_Exp depexp0 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp0.setPostingType(AssetReval.getPostingType());
depexp0.setA_Asset_ID(Asset.getA_Asset_ID());
depexp0.setExpense(v_Cost_reval);
depexp0.setDateAcct(AssetReval.getDateAcct());
depexp0.setA_Account_Number(rs.getInt("A_ASSET_ACCT"));
depexp0.setDescription("Asset Revaluation");
depexp0.setIsDepreciated(false);
depexp0.setA_Period(AssetReval.getC_Period_ID());
depexp0.setA_Entry_Type("RVL");
depexp0.saveEx();
X_A_Depreciation_Exp depexp1 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp1.setPostingType(AssetReval.getPostingType());
depexp1.setA_Asset_ID(Asset.getA_Asset_ID());
depexp1.setExpense(v_Cost_reval.multiply(new BigDecimal(-1)));
depexp1.setDateAcct(AssetReval.getDateAcct());
depexp1.setA_Account_Number(rs.getInt("A_REVAL_COST_OFFSET"));
depexp1.setDescription("Asset Revaluation");
depexp1.setIsDepreciated(false);
depexp1.setA_Period(AssetReval.getC_Period_ID());
depexp1.setA_Entry_Type("RVL");
depexp1.saveEx();
// Create JV for the Reval Accum Depr Amounts
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp2.setPostingType(AssetReval.getPostingType());
depexp2.setA_Asset_ID(Asset.getA_Asset_ID());
depexp2.setExpense(v_Accum_reval);
depexp2.setDateAcct(AssetReval.getDateAcct());
depexp2.setA_Account_Number(rs.getInt("A_ACCUMDEPRECIATION_ACCT"));
depexp2.setDescription("Asset Revaluation");
depexp2.setIsDepreciated(false);
depexp2.setA_Period(AssetReval.getC_Period_ID());
depexp2.setA_Entry_Type("RVL");
depexp2.saveEx();
X_A_Depreciation_Exp depexp3 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp3.setPostingType(AssetReval.getPostingType());
depexp3.setA_Asset_ID(Asset.getA_Asset_ID());
depexp3.setExpense(v_Accum_reval.multiply(new BigDecimal(-1)));
depexp3.setDateAcct(AssetReval.getDateAcct());
depexp3.setA_Account_Number(rs.getInt("A_ACCUMULATED_DEPR_REVAL"));
depexp3.setDescription("Asset Revaluation");
depexp3.setIsDepreciated(false);
depexp3.setA_Period(AssetReval.getC_Period_ID());
depexp3.setA_Entry_Type("RVL");
depexp3.saveEx();
// Create JV for the Reval Depreciation Expense Amounts
X_A_Depreciation_Exp depexp4 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp4.setPostingType(AssetReval.getPostingType());
depexp4.setA_Asset_ID(Asset.getA_Asset_ID());
depexp4.setExpense(v_Accum_reval);
depexp4.setDateAcct(AssetReval.getDateAcct());
depexp4.setA_Account_Number(rs.getInt("A_DEPRECIATION_ACCT"));
depexp4.setDescription("Asset Revaluation");
depexp4.setIsDepreciated(false);
depexp4.setA_Period(AssetReval.getC_Period_ID());
depexp4.setA_Entry_Type("RVL");
depexp4.saveEx();
X_A_Depreciation_Exp depexp5 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp5.setPostingType(AssetReval.getPostingType());
depexp5.setA_Asset_ID(Asset.getA_Asset_ID());
depexp5.setExpense(v_Accum_reval.multiply(new BigDecimal(-1)));
depexp5.setDateAcct(AssetReval.getDateAcct());
depexp5.setA_Account_Number(rs.getInt("A_REVAL_DEPEXP_OFFSET"));
depexp5.setDescription("Asset Revaluation");
depexp5.setIsDepreciated(false);
depexp5.setA_Period(AssetReval.getC_Period_ID());
depexp5.setA_Entry_Type("RVL");
depexp5.saveEx();
}
}
catch (Exception e)
{
log.info("getDeliveries"+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
} // doIt
} // AssetRevalEntry

View File

@ -1,601 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.compiere.model.MAsset;
import org.compiere.model.MAssetAcct;
import org.compiere.model.MAssetAddition;
import org.compiere.model.MAssetChange;
import org.compiere.model.MDepreciationWorkfile;
import org.compiere.model.MRefList;
import org.compiere.model.X_A_Asset_Split;
import org.compiere.model.X_A_Depreciation_Exp;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Split an Asset
*
* @author Rob Klein
* @version $Id: AssetSplit,v 1.0 $
*/
public class AssetSplit extends SvrProcess
{
/** Record ID */
private int p_Asset_Split_ID = 0;
//private boolean m_DeleteOld = false;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
//ProcessInfoParameter[] para = getParameter();
p_Asset_Split_ID = getRecord_ID();
} // prepare
/**
* Transfer Asset
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("doIt - Asset_Split_ID=" + p_Asset_Split_ID);
if (p_Asset_Split_ID == 0)
throw new IllegalArgumentException("No Record");
//
int no = 0;
BigDecimal v_AccumBalance_New = new BigDecimal("0.0");
BigDecimal v_CostBalance_New = new BigDecimal("0.0");
BigDecimal v_QTY_New = new BigDecimal("0.0");
BigDecimal v_SalvageValue_New = new BigDecimal("0.0");
BigDecimal v_AccumBalance_Org = new BigDecimal("0.0");
BigDecimal v_CostBalance_Org = new BigDecimal("0.0");
BigDecimal v_QTY_Org = new BigDecimal("0.0");
BigDecimal v_SalvageValue_Org = new BigDecimal("0.0");
BigDecimal v_multiplier_New = new BigDecimal("0.0");
BigDecimal v_ManDep_Org = new BigDecimal("0.0");
BigDecimal v_ManDep_New = new BigDecimal("0.0");
int v_AssetNumber = 0, A_Accumdepreciation_Acct = 0;
int A_Cost_Acct = 0, A_DepExp_Acct = 0;
log.info("doIt - Starting Split = " + no);
X_A_Asset_Split AssetSplit = new X_A_Asset_Split (getCtx(), p_Asset_Split_ID, null);
MAsset Asset = new MAsset (getCtx(), AssetSplit.getA_Asset_ID(), null);
MDepreciationWorkfile assetwk = new MDepreciationWorkfile (getCtx(), AssetSplit.getA_Depreciation_Workfile_ID(), null);
MAssetAcct assetacct = new MAssetAcct (getCtx(), AssetSplit.getA_Asset_Acct_ID(), null);
v_AccumBalance_Org = assetwk.getA_Accumulated_Depr();
v_SalvageValue_Org = assetwk.getA_Salvage_Value();
v_CostBalance_Org = assetwk.getA_Asset_Cost();
v_QTY_Org = AssetSplit.getA_QTY_Current();
v_ManDep_Org = assetacct.getA_Depreciation_Manual_Amount();
if (AssetSplit.getA_Split_Type().compareTo("PER") == 0){
v_multiplier_New = AssetSplit.getA_Percent_Split();
v_AccumBalance_New = v_AccumBalance_Org.multiply(AssetSplit.getA_Percent_Split());
v_CostBalance_New = v_CostBalance_Org.multiply(AssetSplit.getA_Percent_Split());
v_QTY_New = v_QTY_Org.multiply(AssetSplit.getA_Percent_Split());
v_SalvageValue_New = v_SalvageValue_Org.multiply(AssetSplit.getA_Percent_Split());
v_AccumBalance_Org = v_AccumBalance_Org.subtract(v_AccumBalance_New);
v_CostBalance_Org = v_CostBalance_Org.subtract(v_CostBalance_New);
v_QTY_Org = v_QTY_Org.subtract(v_QTY_New);
v_SalvageValue_Org = v_SalvageValue_Org.subtract(v_SalvageValue_New);
v_ManDep_New = v_ManDep_Org.multiply(AssetSplit.getA_Percent_Split());
v_ManDep_Org =v_ManDep_Org.subtract(v_ManDep_New);
}
else if (AssetSplit.getA_Split_Type().compareTo("QTY")==0) {
v_multiplier_New = AssetSplit.getA_QTY_Split().setScale(5, BigDecimal.ROUND_HALF_UP).divide(v_QTY_Org.setScale(5, BigDecimal.ROUND_HALF_UP), 0);
v_AccumBalance_New = v_AccumBalance_Org .multiply(v_multiplier_New);
v_CostBalance_New = v_CostBalance_Org .multiply(v_multiplier_New);
v_QTY_New = AssetSplit.getA_QTY_Split();
v_SalvageValue_New = v_SalvageValue_Org.multiply(v_multiplier_New);
v_AccumBalance_Org = v_AccumBalance_Org.subtract(v_AccumBalance_New);
v_CostBalance_Org = v_CostBalance_Org .subtract(v_CostBalance_New);
v_QTY_Org = v_QTY_Org .subtract(v_QTY_New);
v_SalvageValue_Org = v_SalvageValue_Org .subtract(v_SalvageValue_New);
v_ManDep_New = v_ManDep_Org.multiply(v_multiplier_New);
v_ManDep_Org =v_ManDep_Org.subtract(v_ManDep_New);
}
else if (AssetSplit.getA_Split_Type().compareTo("AMT")==0) {
v_multiplier_New = AssetSplit.getA_Amount_Split().setScale(5, BigDecimal.ROUND_HALF_UP).divide(v_CostBalance_Org.setScale(5, BigDecimal.ROUND_HALF_UP), 0);
v_AccumBalance_New = v_AccumBalance_Org .multiply(v_multiplier_New);
v_CostBalance_New = AssetSplit.getA_Amount_Split();
v_QTY_New = v_QTY_Org .multiply(v_multiplier_New);
v_SalvageValue_New = v_SalvageValue_Org.multiply(v_multiplier_New);
v_AccumBalance_Org = v_AccumBalance_Org.subtract(v_AccumBalance_New);
v_CostBalance_Org = v_CostBalance_Org.subtract(v_CostBalance_New);
v_QTY_Org = v_QTY_Org.subtract(v_QTY_New);
v_SalvageValue_Org = v_SalvageValue_Org.subtract(v_SalvageValue_New);
v_ManDep_New = v_ManDep_Org.multiply(v_multiplier_New);
v_ManDep_Org =v_ManDep_Org.subtract(v_ManDep_New);
}
if (AssetSplit.getA_Asset_ID_To() == 0)
{
//Insert New Asset
MAsset AssetNew = new MAsset (getCtx(), 0, null);
AssetNew.setValue(Asset.getValue());
AssetNew.setA_Parent_Asset_ID(Asset.getA_Asset_ID());
AssetNew.setName(Asset.getName());
AssetNew.setDescription(Asset.getDescription());
AssetNew.setHelp(Asset.getHelp());
AssetNew.setA_Asset_Group_ID(Asset.getA_Asset_Group_ID());
AssetNew.setM_Product_ID(Asset.getM_Product_ID());
AssetNew.setSerNo(Asset.getSerNo());
AssetNew.setLot(Asset.getLot());
AssetNew.setVersionNo(Asset.getVersionNo());
AssetNew.setGuaranteeDate(Asset.getGuaranteeDate());
AssetNew.setAssetServiceDate(Asset.getAssetServiceDate());
AssetNew.setUseLifeMonths(Asset.getUseLifeMonths());
AssetNew.setUseLifeYears(Asset.getUseLifeYears());
AssetNew.setUseUnits(Asset.getUseUnits());
AssetNew.setIsOwned(Asset.isOwned());
AssetNew.setIsDepreciated(Asset.isDepreciated());
AssetNew.setAssetDepreciationDate(Asset.getAssetDepreciationDate());
AssetNew.setIsInPosession(Asset.isInPosession());
AssetNew.setLocationComment( "Split from Asset #" +AssetSplit.getA_Asset_ID());
AssetNew.setC_BPartner_ID(Asset.getC_BPartner_ID());
AssetNew.setC_BPartner_Location_ID(Asset.getC_BPartner_Location_ID());
AssetNew.setA_QTY_Current(v_QTY_New);
AssetNew.setA_QTY_Original(v_QTY_New);
AssetNew.saveEx();
v_AssetNumber = AssetNew.getA_Asset_ID();
//Create Asset Addition Record
MAssetAddition assetadd = new MAssetAddition (getCtx(), 0, null);
assetadd.setA_Asset_ID(AssetNew.getA_Asset_ID());
assetadd.setAssetValueAmt(v_CostBalance_New );
assetadd.setDescription("Split from Asset #" + AssetSplit.getA_Asset_ID());
assetadd.setA_CapvsExp("Cap");
assetadd.setA_SourceType("MAN");
assetadd.setA_QTY_Current(v_QTY_New);
assetadd.setPostingType(AssetSplit.getPostingType());
assetadd.setM_InOutLine_ID(1);
assetadd.saveEx();
String sql2 = "SELECT A_Asset_Acct_ID "
+ "FROM A_Asset_Acct "
+ "WHERE A_Asset_ID= " + v_AssetNumber
+ "AND PostingType = '" + AssetSplit.getPostingType() +"'";
int v_NewAssetAcctID = 0;
v_NewAssetAcctID = DB.getSQLValue(null, sql2);
//Insert the New Asset in the Account File
MAssetAcct assetacctnew = new MAssetAcct (getCtx(), v_NewAssetAcctID, null);
assetacctnew.setA_Asset_ID(v_AssetNumber);
assetacctnew.setC_AcctSchema_ID(assetacct.getC_AcctSchema_ID());
assetacctnew.setA_Depreciation_ID(assetacct.getA_Depreciation_ID());
assetacctnew.setA_Depreciation_Acct(assetacct.getA_Depreciation_Acct());
assetacctnew.setA_Accumdepreciation_Acct(assetacct.getA_Accumdepreciation_Acct());
assetacctnew.setA_Disposal_Loss(assetacct.getA_Disposal_Loss());
assetacctnew.setA_Disposal_Revenue(assetacct.getA_Disposal_Revenue());
assetacctnew.setA_Asset_Acct(assetacct.getA_Asset_Acct());
assetacctnew.setA_Asset_Spread_ID(assetacct.getA_Asset_Spread_ID());
assetacctnew.setA_Depreciation_Method_ID(assetacct.getA_Depreciation_Method_ID());
assetacctnew.setA_Period_Start(assetacct.getA_Period_Start());
assetacctnew.setA_Period_End(assetacct.getA_Period_End());
assetacctnew.setA_Split_Percent(assetacct.getA_Split_Percent());
assetacctnew.setA_Reval_Cal_Method(assetacct.getA_Reval_Cal_Method());
assetacctnew.setA_Salvage_Value(v_SalvageValue_New);
assetacctnew.setPostingType(assetacct.getPostingType());
assetacctnew.setA_Depreciation_Conv_ID(assetacct.getA_Depreciation_Conv_ID());
assetacctnew.setA_Depreciation_Manual_Amount(v_ManDep_New);
assetacctnew.setA_Depreciation_Manual_Period(assetacct.getA_Depreciation_Manual_Period());
if (assetacct.getA_Depreciation_Manual_Period() == null)
assetacctnew.setA_Depreciation_Manual_Period(" ");
else
assetacctnew.setA_Depreciation_Manual_Period(assetacct.getA_Depreciation_Manual_Period());
assetacctnew.saveEx();
sql2 = null;
sql2 = "SELECT A_Depreciation_Workfile_ID "
+ "FROM A_Depreciation_Workfile "
+ "WHERE A_Asset_ID= " + v_AssetNumber
+ " AND PostingType = '" + AssetSplit.getPostingType() +"'";
int v_NewWorkfileID = 0;
v_NewWorkfileID = DB.getSQLValue(null, sql2);
//Insert the New Asset in the Deprecation Workfile
MDepreciationWorkfile assetwknew = new MDepreciationWorkfile (getCtx(), v_NewWorkfileID, null);
assetwknew.setA_Asset_ID(v_AssetNumber);
assetwknew.setA_Asset_Cost(assetwknew.getA_Asset_Cost().add(v_CostBalance_New));
assetwknew.setA_Accumulated_Depr(v_AccumBalance_New);
assetwknew.setA_Life_Period(assetwk.getA_Life_Period());
assetwknew.setA_Period_Posted(assetwk.getA_Period_Posted());
assetwknew.setA_Salvage_Value(v_SalvageValue_New);
assetwknew.setA_Asset_Life_Years(assetwk.getA_Asset_Life_Years());
assetwknew.setPostingType(assetwk.getPostingType());
assetwknew.setA_QTY_Current(assetwknew.getA_QTY_Current().add(v_QTY_New));
assetwknew.setIsDepreciated(assetwk.isDepreciated());
assetwknew.setA_Asset_Life_Current_Year(assetwk.getA_Asset_Life_Current_Year());
assetwknew.setA_Curr_Dep_Exp(new BigDecimal (0.0));
assetwknew.saveEx();
//Record transaction in Asset History
MAssetChange change = new MAssetChange (getCtx(), 0, null);
change.setAssetValueAmt(v_CostBalance_New );
change.setPostingType(assetacct.getPostingType());
change.setA_Asset_ID(AssetNew.getA_Asset_ID());
change.setAssetAccumDepreciationAmt(v_AccumBalance_New);
change.setA_Salvage_Value(v_SalvageValue_New);
change.setPostingType(assetacct.getPostingType());
change.setA_Split_Percent(assetacct.getA_Split_Percent());
change.setConventionType(assetacct.getA_Depreciation_Conv_ID());
change.setA_Asset_ID(AssetNew.getA_Asset_ID());
change.setDepreciationType(assetacct.getA_Depreciation_ID());
change.setA_Asset_Spread_Type(assetacct.getA_Asset_Spread_ID());
change.setA_Period_Start(assetacct.getA_Period_Start());
change.setA_Period_End(assetacct.getA_Period_End());
change.setIsInPosession(AssetNew.isOwned());
change.setIsDisposed(AssetNew.isDisposed());
change.setIsDepreciated(AssetNew.isDepreciated());
change.setIsFullyDepreciated(AssetNew.isFullyDepreciated());
change.setA_Depreciation_Calc_Type(assetacct.getA_Depreciation_Method_ID());
change.setA_Asset_Acct(assetacct.getA_Asset_Acct());
change.setC_AcctSchema_ID(assetacct.getC_AcctSchema_ID());
change.setA_Accumdepreciation_Acct(assetacct.getA_Accumdepreciation_Acct());
change.setA_Depreciation_Acct(assetacct.getA_Depreciation_Acct());
change.setA_Disposal_Revenue(assetacct.getA_Disposal_Revenue());
change.setA_Disposal_Loss(assetacct.getA_Disposal_Loss());
change.setA_Reval_Accumdep_Offset_Cur(assetacct.getA_Reval_Accumdep_Offset_Cur());
change.setA_Reval_Accumdep_Offset_Prior(assetacct.getA_Reval_Accumdep_Offset_Prior());
if (assetacct.getA_Reval_Cal_Method() == null)
change.setA_Reval_Cal_Method(" ");
else
change.setA_Reval_Cal_Method(assetacct.getA_Reval_Cal_Method());
change.setA_Reval_Cost_Offset(assetacct.getA_Reval_Cost_Offset());
change.setA_Reval_Cost_Offset_Prior(assetacct.getA_Reval_Cost_Offset_Prior());
change.setA_Reval_Depexp_Offset(assetacct.getA_Reval_Depexp_Offset());
change.setA_Depreciation_Manual_Amount(assetacct.getA_Depreciation_Manual_Amount());
if (assetacct.getA_Depreciation_Manual_Period() == null)
change.setA_Depreciation_Manual_Period(" ");
else
change.setA_Depreciation_Manual_Period(assetacct.getA_Depreciation_Manual_Period());
change.setA_Depreciation_Table_Header_ID(assetacct.getA_Depreciation_Table_Header_ID());
change.setA_Depreciation_Variable_Perc(assetacct.getA_Depreciation_Variable_Perc());
change.setA_Parent_Asset_ID(Asset.getA_Parent_Asset_ID());
change.setChangeType("SPL");
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "SPL"));
change.setLot(AssetNew.getLot());
change.setSerNo(AssetNew.getSerNo());
change.setVersionNo(AssetNew.getVersionNo());
change.setUseLifeMonths(AssetNew.getUseLifeMonths());
change.setUseLifeYears(AssetNew.getUseLifeYears());
change.setLifeUseUnits(AssetNew.getLifeUseUnits());
change.setAssetDisposalDate(AssetNew.getAssetDisposalDate());
change.setAssetServiceDate(AssetNew.getAssetServiceDate());
change.setC_BPartner_Location_ID(AssetNew.getC_BPartner_Location_ID());
change.setC_BPartner_ID(AssetNew.getC_BPartner_ID());
change.setA_QTY_Current(AssetNew.getA_QTY_Current());
change.setA_QTY_Original(AssetNew.getA_QTY_Original());
change.saveEx();
//Record Account Numbers for JE's
A_Accumdepreciation_Acct = assetacctnew.getA_Accumdepreciation_Acct();
A_Cost_Acct = assetacctnew.getA_Asset_Acct();
A_DepExp_Acct = assetacctnew.getA_Depreciation_Acct();
}
else
{
v_AssetNumber = AssetSplit.getA_Asset_ID_To();
//Update Target Asset Record
MAsset AssetNew = new MAsset (getCtx(), v_AssetNumber, null);
AssetNew.setA_QTY_Current(AssetNew.getA_QTY_Current().add(v_QTY_New));
AssetNew.setA_QTY_Original(AssetNew.getA_QTY_Original().add(v_QTY_New));
AssetNew.saveEx();
//Create Asset Addition Record
MAssetAddition assetadd = new MAssetAddition (getCtx(), 0, null);
assetadd.setA_Asset_ID(v_AssetNumber);
assetadd.setAssetValueAmt(v_CostBalance_New );
assetadd.setDescription("Split from Asset #" + AssetSplit.getA_Asset_ID());
assetadd.setA_CapvsExp("Cap");
assetadd.setA_SourceType("MAN");
assetadd.setA_QTY_Current(v_QTY_New);
assetadd.setPostingType(AssetSplit.getPostingType());
assetadd.setM_InOutLine_ID(1);
assetadd.saveEx();
String sql2 = "SELECT A_Asset_Acct_ID "
+ "FROM A_Asset_Acct "
+ "WHERE A_Asset_ID= " + v_AssetNumber
+ "AND PostingType = '" + AssetSplit.getPostingType() +"'";
int v_NewAssetAcctID = 0;
v_NewAssetAcctID = DB.getSQLValue(null, sql2);
//Update Target Asset in the Account File
MAssetAcct assetacctnew = new MAssetAcct (getCtx(), v_NewAssetAcctID, null);
assetacctnew.setA_Salvage_Value(assetacctnew.getA_Salvage_Value().add(v_SalvageValue_New));
assetacctnew.setA_Depreciation_Manual_Amount(assetacctnew.getA_Depreciation_Manual_Amount().add(v_ManDep_New));
assetacctnew.saveEx();
sql2 = null;
sql2 = "SELECT A_Depreciation_Workfile_ID "
+ "FROM A_Depreciation_Workfile "
+ "WHERE A_Asset_ID= " + v_AssetNumber
+ " AND PostingType = '" + AssetSplit.getPostingType() +"'";
int v_NewWorkfileID = 0;
v_NewWorkfileID = DB.getSQLValue(null, sql2);
//Update Target Asset in the Deprecation Workfile
MDepreciationWorkfile assetwknew = new MDepreciationWorkfile (getCtx(), v_NewWorkfileID, null);
assetwknew.setA_Asset_Cost(assetwknew.getA_Asset_Cost().add(v_CostBalance_New));
assetwknew.setA_Accumulated_Depr(assetwknew.getA_Accumulated_Depr().add(v_AccumBalance_New));
assetwknew.setA_Salvage_Value(assetwknew.getA_Salvage_Value().add(v_SalvageValue_New));
assetwknew.setA_QTY_Current(assetwknew.getA_QTY_Current().add(v_QTY_New));
assetwknew.saveEx();
//Record transaction in Asset History
MAssetChange change = new MAssetChange (getCtx(), 0, null);
change.setAssetValueAmt(v_CostBalance_New );
change.setPostingType(assetacct.getPostingType());
change.setA_Asset_ID(AssetNew.getA_Asset_ID());
change.setAssetAccumDepreciationAmt(v_AccumBalance_New);
change.setA_Salvage_Value(v_SalvageValue_New);
change.setPostingType(assetacct.getPostingType());
change.setA_Split_Percent(assetacct.getA_Split_Percent());
change.setConventionType(assetacct.getA_Depreciation_Conv_ID());
change.setA_Asset_ID(AssetNew.getA_Asset_ID());
change.setDepreciationType(assetacct.getA_Depreciation_ID());
change.setA_Asset_Spread_Type(assetacct.getA_Asset_Spread_ID());
change.setA_Period_Start(assetacct.getA_Period_Start());
change.setA_Period_End(assetacct.getA_Period_End());
change.setIsInPosession(AssetNew.isOwned());
change.setIsDisposed(AssetNew.isDisposed());
change.setIsDepreciated(AssetNew.isDepreciated());
change.setIsFullyDepreciated(AssetNew.isFullyDepreciated());
change.setA_Depreciation_Calc_Type(assetacct.getA_Depreciation_Method_ID());
change.setA_Asset_Acct(assetacct.getA_Asset_Acct());
change.setC_AcctSchema_ID(assetacct.getC_AcctSchema_ID());
change.setA_Accumdepreciation_Acct(assetacct.getA_Accumdepreciation_Acct());
change.setA_Depreciation_Acct(assetacct.getA_Depreciation_Acct());
change.setA_Disposal_Revenue(assetacct.getA_Disposal_Revenue());
change.setA_Disposal_Loss(assetacct.getA_Disposal_Loss());
change.setA_Reval_Accumdep_Offset_Cur(assetacct.getA_Reval_Accumdep_Offset_Cur());
change.setA_Reval_Accumdep_Offset_Prior(assetacct.getA_Reval_Accumdep_Offset_Prior());
change.setA_Reval_Cal_Method(assetacct.getA_Reval_Cal_Method());
change.setA_Reval_Cost_Offset(assetacct.getA_Reval_Cost_Offset());
change.setA_Reval_Cost_Offset_Prior(assetacct.getA_Reval_Cost_Offset_Prior());
change.setA_Reval_Depexp_Offset(assetacct.getA_Reval_Depexp_Offset());
change.setA_Depreciation_Manual_Amount(assetacct.getA_Depreciation_Manual_Amount());
if (assetacct.getA_Reval_Cal_Method() == null)
change.setA_Reval_Cal_Method(" ");
else
change.setA_Reval_Cal_Method(assetacct.getA_Reval_Cal_Method());
if (assetacct.getA_Depreciation_Manual_Period() == null)
change.setA_Depreciation_Manual_Period(" ");
else
change.setA_Depreciation_Manual_Period(assetacct.getA_Depreciation_Manual_Period());
change.setA_Depreciation_Table_Header_ID(assetacct.getA_Depreciation_Table_Header_ID());
change.setA_Depreciation_Variable_Perc(assetacct.getA_Depreciation_Variable_Perc());
change.setA_Parent_Asset_ID(Asset.getA_Parent_Asset_ID());
change.setChangeType("SPL");
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "SPL"));
change.setLot(AssetNew.getLot());
change.setSerNo(AssetNew.getSerNo());
change.setVersionNo(AssetNew.getVersionNo());
change.setUseLifeMonths(AssetNew.getUseLifeMonths());
change.setUseLifeYears(AssetNew.getUseLifeYears());
change.setLifeUseUnits(AssetNew.getLifeUseUnits());
change.setAssetDisposalDate(AssetNew.getAssetDisposalDate());
change.setAssetServiceDate(AssetNew.getAssetServiceDate());
change.setC_BPartner_Location_ID(AssetNew.getC_BPartner_Location_ID());
change.setC_BPartner_ID(AssetNew.getC_BPartner_ID());
change.setA_QTY_Current(AssetNew.getA_QTY_Current());
change.setA_QTY_Original(AssetNew.getA_QTY_Original());
change.saveEx();
//Record Account Numbers for JE's
A_Accumdepreciation_Acct = assetacctnew.getA_Accumdepreciation_Acct();
A_Cost_Acct = assetacctnew.getA_Asset_Acct();
A_DepExp_Acct = assetacctnew.getA_Depreciation_Acct();
}
// Update original Asset
Asset.setA_QTY_Current(v_QTY_Org);
Asset.saveEx();
// Update original asset for the split
MAssetAddition assetaddold = new MAssetAddition (getCtx(), 0, null);
assetaddold.setA_Asset_ID(Asset.getA_Asset_ID());
assetaddold.setAssetValueAmt(v_CostBalance_New.multiply( new BigDecimal(-1)));
assetaddold.setDescription("Split to Asset #" + v_AssetNumber);
assetaddold.setA_CapvsExp("Cap");
assetaddold.setA_SourceType("MAN");
assetaddold.setA_QTY_Current(v_QTY_New.multiply( new BigDecimal(-1)));
assetaddold.setPostingType(AssetSplit.getPostingType());
assetaddold.setM_InOutLine_ID(1);
assetaddold.saveEx();
//Update the Original Asset in the Account File
assetacct.setA_Salvage_Value(v_SalvageValue_Org);
assetacct.setA_Depreciation_Manual_Amount(v_ManDep_Org);
assetacct.saveEx();
//Update the Original Asset in the Deprecation Workfile
assetwk.setA_Asset_Cost(v_CostBalance_Org);
assetwk.setA_Accumulated_Depr(v_AccumBalance_Org);
assetwk.setA_Salvage_Value(v_SalvageValue_Org);
assetwk.setA_QTY_Current(v_QTY_Org);
assetwk.saveEx();
MAssetChange change1 = new MAssetChange (getCtx(), 0, null);
change1.setChangeType("SPL");
change1.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "SPL"));
change1.setAssetValueAmt(v_CostBalance_New.multiply(new BigDecimal(-1)));
change1.setPostingType(assetacct.getPostingType());
if (assetacct.getA_Reval_Cal_Method() == null)
change1.setA_Reval_Cal_Method(" ");
else
change1.setA_Reval_Cal_Method(assetacct.getA_Reval_Cal_Method());
if (assetacct.getA_Depreciation_Manual_Period() == null)
change1.setA_Depreciation_Manual_Period(" ");
else
change1.setA_Depreciation_Manual_Period(assetacct.getA_Depreciation_Manual_Period());
change1.setA_Asset_ID(Asset.getA_Asset_ID());
change1.setAssetAccumDepreciationAmt(v_AccumBalance_New.multiply(new BigDecimal(-1)));
change1.setA_Salvage_Value(v_SalvageValue_New.multiply(new BigDecimal(-1)));
change1.setA_QTY_Current(v_QTY_New.multiply(new BigDecimal(-1)));
change1.saveEx();
//Create Journal Entries for the split
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, null);
//Create JV for the accumulated depreciation of the asset
depexp2.setPostingType(AssetSplit.getPostingType());
depexp2.setA_Asset_ID(v_AssetNumber);
depexp2.setExpense(v_AccumBalance_New.multiply(new BigDecimal(-1)));
depexp2.setDateAcct(AssetSplit.getDateAcct());
depexp2.setA_Account_Number(A_Accumdepreciation_Acct);
depexp2.setDescription("Asset Split Accum Dep");
depexp2.setIsDepreciated(false);
depexp2.setA_Period(AssetSplit.getC_Period_ID());
depexp2.setA_Entry_Type("SPL");
depexp2.saveEx();
X_A_Depreciation_Exp depexp3 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp3.setPostingType(AssetSplit.getPostingType());
depexp3.setA_Asset_ID(AssetSplit.getA_Asset_ID());
depexp3.setExpense(v_AccumBalance_New);
depexp3.setDateAcct(AssetSplit.getDateAcct());
depexp3.setA_Account_Number(assetacct.getA_Accumdepreciation_Acct());
depexp3.setDescription("Asset Split Accum Dep");
depexp3.setIsDepreciated(false);
depexp3.setA_Period(AssetSplit.getC_Period_ID());
depexp3.setA_Entry_Type("SPL");
depexp3.saveEx();
X_A_Depreciation_Exp depexp4 = new X_A_Depreciation_Exp (getCtx(), 0, null);
//Create JV for the Cost of the asset
depexp4.setPostingType(AssetSplit.getPostingType());
depexp4.setA_Asset_ID(v_AssetNumber);
depexp4.setExpense(v_CostBalance_New);
depexp4.setDateAcct(AssetSplit.getDateAcct());
depexp4.setA_Account_Number(A_Cost_Acct);
depexp4.setDescription("Asset Split Cost");
depexp4.setIsDepreciated(false);
depexp4.setA_Period(AssetSplit.getC_Period_ID());
depexp4.setA_Entry_Type("SPL");
depexp4.saveEx();
X_A_Depreciation_Exp depexp5 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp5.setPostingType(AssetSplit.getPostingType());
depexp5.setA_Asset_ID(AssetSplit.getA_Asset_ID());
depexp5.setExpense(v_CostBalance_New.multiply(new BigDecimal(-1)));
depexp5.setDateAcct(AssetSplit.getDateAcct());
depexp5.setA_Account_Number(assetacct.getA_Asset_Acct());
depexp5.setDescription("Asset Split Cost");
depexp5.setIsDepreciated(false);
depexp5.setA_Period(AssetSplit.getC_Period_ID());
depexp5.setA_Entry_Type("SPL");
depexp5.saveEx();
String sql = null;
log.info("doIt - Finishing Split = " + no);
sql = "SELECT A_ASSET_ID, CHANGEAMT "
+ "FROM A_ASSET_CHANGE "
+ "WHERE A_ASSET_CHANGE.A_ASSET_ID = " + AssetSplit.getA_Asset_ID()
+ " AND A_ASSET_CHANGE.POSTINGTYPE = '" + AssetSplit.getPostingType()
+ "' AND A_ASSET_CHANGE.CHANGETYPE= 'D' "
+ "AND TRUNC(A_ASSET_CHANGE.DATEACCT, 'YY') = TRUNC( " + DB.TO_DATE(AssetSplit.getDateAcct()) + ", 'YY') "
+ "AND TRUNC(A_ASSET_CHANGE.DATEACCT, 'MM') <= TRUNC( " + DB.TO_DATE(AssetSplit.getDateAcct()) + ", 'MM') "
+ "AND A_ASSET_CHANGE.C_VALIDCOMBINATION_ID = " + assetacct.getA_Depreciation_Acct();
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql,null);
log.info("doIt - SQL=" + sql);
BigDecimal v_Balance = new BigDecimal("0.0");
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
if (AssetSplit.isA_Transfer_Balance_IS()==true)
{
while (rs.next());
v_Balance = v_Balance.add(rs.getBigDecimal("ChangeAmt"));
// Create JV for YTD Depreciation Expense
X_A_Depreciation_Exp depexp0 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp0.setPostingType(AssetSplit.getPostingType());
depexp0.setA_Asset_ID(v_AssetNumber);
depexp0.setExpense(v_Balance.multiply(v_multiplier_New));
depexp0.setDateAcct(AssetSplit.getDateAcct());
depexp0.setA_Account_Number(A_DepExp_Acct);
depexp0.setDescription("Asset Split YTD Depreciation Expense");
depexp0.setIsDepreciated(false);
depexp0.setA_Period(AssetSplit.getC_Period_ID());
depexp0.setA_Entry_Type("SPL");
depexp0.saveEx();
X_A_Depreciation_Exp depexp1 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp1.setPostingType(AssetSplit.getPostingType());
depexp1.setA_Asset_ID(AssetSplit.getA_Asset_ID());
depexp1.setExpense(v_Balance.multiply(new BigDecimal(-1)).multiply(v_multiplier_New));
depexp1.setDateAcct(AssetSplit.getDateAcct());
depexp1.setA_Account_Number(assetacct.getA_Depreciation_Acct());
depexp1.setDescription("Asset Split YTD Depreciation Expense");
depexp1.setIsDepreciated(false);
depexp1.setA_Period(AssetSplit.getC_Period_ID());
depexp1.setA_Entry_Type("SPL");
depexp1.saveEx();
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.info("AssetSplit"+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
} // doIt
} // AssetSplit

View File

@ -1,273 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.compiere.model.MAssetChange;
import org.compiere.model.MAssetTransfer;
import org.compiere.model.MRefList;
import org.compiere.model.X_A_Depreciation_Exp;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Asset Transfer
*
* @author Rob Klein
* @version $Id: AssetTransfer.java,v 1.0 $
*/
public class AssetTransfer extends SvrProcess
{
/** Record ID */
private int p_Asset_Transfer_ID = 0;
private boolean m_DeleteOld = false;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else if (name.equals("DeleteOld"))
m_DeleteOld = "Y".equals(para[i].getParameter());
else
log.info("prepare - Unknown Parameter: " + name);
}
p_Asset_Transfer_ID = getRecord_ID();
} // prepare
/**
* Build Depreciation Workfile
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("doIt - Asset_Transfer_ID=" + p_Asset_Transfer_ID);
if (p_Asset_Transfer_ID == 0)
throw new IllegalArgumentException("No Record");
//
int no = 0;
BigDecimal v_Balance = new BigDecimal("0.0");
MAssetTransfer AssetTransfer = new MAssetTransfer (getCtx(), p_Asset_Transfer_ID, null);
//X_C_Period Period = new X_C_Period (getCtx(), AssetTransfer.getC_Period_ID(), null);
String sql = null;
log.info("doIt - Starting Transfer = " + no);
sql = "SELECT A_ASSET_ID, CHANGEAMT "
+ "FROM A_ASSET_CHANGE "
+ "WHERE A_ASSET_CHANGE.A_ASSET_ID = " + AssetTransfer.getA_Asset_ID()
+ " AND A_ASSET_CHANGE.POSTINGTYPE = '" + AssetTransfer.getPostingType()
+ "' AND A_ASSET_CHANGE.CHANGETYPE= 'D' "
+ "AND TRUNC(A_ASSET_CHANGE.DATEACCT, 'YY') = TRUNC( " + DB.TO_DATE(AssetTransfer.getDateAcct()) + ", 'YY') "
+ "AND TRUNC(A_ASSET_CHANGE.DATEACCT, 'MM') <= TRUNC( " + DB.TO_DATE(AssetTransfer.getDateAcct()) + ", 'MM') "
+ "AND A_ASSET_CHANGE.C_VALIDCOMBINATION_ID = " + AssetTransfer.getA_Depreciation_Acct();
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql,null);
log.info("doIt - SQL=" + sql);
ResultSet rs = null;
//X_A_Depreciation_Exp depexp = new X_A_Depreciation_Exp (getCtx(), 0, null);
String clientCheck = " AND AD_Client_ID=" + AssetTransfer.getAD_Client_ID();
if (m_DeleteOld)
{
sql = "DELETE A_DEPRECIATION_EXP "
+ "WHERE Processed='Y'"
+ " AND A_Entry_Type = 'TRN'" + clientCheck;
no = DB.executeUpdate (sql,null);
log.info ("doIt - Delete old processed entries =" + no);
}
try {
rs = pstmt.executeQuery();
if (AssetTransfer.isA_Transfer_Balance_IS()==true)
{
while (rs.next());
v_Balance = v_Balance.add(rs.getBigDecimal("ChangeAmt"));
// Create JV for the Income Statement Amounts
X_A_Depreciation_Exp depexp0 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp0.setPostingType(AssetTransfer.getPostingType());
depexp0.setA_Asset_ID(AssetTransfer.getA_Asset_ID());
depexp0.setExpense(v_Balance);
depexp0.setDateAcct(AssetTransfer.getDateAcct());
depexp0.setA_Account_Number(AssetTransfer.getA_Depreciation_Acct_New());
depexp0.setDescription("Asset Transfer");
depexp0.setIsDepreciated(false);
depexp0.setA_Period(AssetTransfer.getC_Period_ID());
depexp0.setA_Entry_Type("TRN");
depexp0.saveEx();
X_A_Depreciation_Exp depexp1 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp1.setPostingType(AssetTransfer.getPostingType());
depexp1.setA_Asset_ID(AssetTransfer.getA_Asset_ID());
depexp1.setExpense(v_Balance.multiply(new BigDecimal(-1)));
depexp1.setDateAcct(AssetTransfer.getDateAcct());
depexp1.setA_Account_Number(AssetTransfer.getA_Depreciation_Acct_New());
depexp1.setDescription("Asset Transfer");
depexp1.setIsDepreciated(false);
depexp1.setA_Period(AssetTransfer.getC_Period_ID());
depexp1.setA_Entry_Type("TRN");
depexp1.saveEx();
}
}
catch (Exception e)
{
log.info("getDeliveries"+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
sql = null;
sql = "SELECT A_ASSET_COST, A_ACCUMULATED_DEPR "
+ "FROM A_DEPRECIATION_WORKFILE "
+ "WHERE A_ASSET_ID = " + AssetTransfer.getA_Asset_ID()
+ " AND POSTINGTYPE = '" + AssetTransfer.getPostingType()
+ "' AND AD_CLIENT_ID = " + AssetTransfer.getAD_Client_ID()
+ " AND AD_ORG_ID = " + AssetTransfer.getAD_Org_ID();
pstmt = null;
pstmt = DB.prepareStatement (sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE,null);
try {
rs = pstmt.executeQuery();
rs.first();
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, null);
// Create JV for the accumulated depreciation of the asset
depexp2.setPostingType(AssetTransfer.getPostingType());
depexp2.setA_Asset_ID(AssetTransfer.getA_Asset_ID());
depexp2.setExpense(rs.getBigDecimal("A_ACCUMULATED_DEPR"));
depexp2.setDateAcct(AssetTransfer.getDateAcct());
depexp2.setA_Account_Number(AssetTransfer.getA_Accumdepreciation_Acct_New());
depexp2.setDescription("Asset Transfer Accum Dep");
depexp2.setIsDepreciated(false);
depexp2.setA_Period(AssetTransfer.getC_Period_ID());
depexp2.setA_Entry_Type("TRN");
depexp2.saveEx();
X_A_Depreciation_Exp depexp3 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp3.setPostingType(AssetTransfer.getPostingType());
depexp3.setA_Asset_ID(AssetTransfer.getA_Asset_ID());
depexp3.setExpense(rs.getBigDecimal("A_ACCUMULATED_DEPR").multiply(new BigDecimal(-1)));
depexp3.setDateAcct(AssetTransfer.getDateAcct());
depexp3.setA_Account_Number(AssetTransfer.getA_Accumdepreciation_Acct());
depexp3.setDescription("Asset Transfer Accum Dep");
depexp3.setIsDepreciated(false);
depexp3.setA_Period(AssetTransfer.getC_Period_ID());
depexp3.setA_Entry_Type("TRN");
depexp3.saveEx();
X_A_Depreciation_Exp depexp4 = new X_A_Depreciation_Exp (getCtx(), 0, null);
// Create JV for the Cost of the asset
depexp4.setPostingType(AssetTransfer.getPostingType());
depexp4.setA_Asset_ID(AssetTransfer.getA_Asset_ID());
depexp4.setExpense(rs.getBigDecimal("A_Asset_Cost"));
depexp4.setDateAcct(AssetTransfer.getDateAcct());
depexp4.setA_Account_Number(AssetTransfer.getA_Asset_Acct_New());
depexp4.setDescription("Asset Transfer Cost");
depexp4.setIsDepreciated(false);
depexp4.setA_Period(AssetTransfer.getC_Period_ID());
depexp4.setA_Entry_Type("TRN");
depexp4.saveEx();
X_A_Depreciation_Exp depexp5 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp5.setPostingType(AssetTransfer.getPostingType());
depexp5.setA_Asset_ID(AssetTransfer.getA_Asset_ID());
depexp5.setExpense(rs.getBigDecimal("A_Asset_Cost").multiply(new BigDecimal(-1)));
depexp5.setDateAcct(AssetTransfer.getDateAcct());
depexp5.setA_Account_Number(AssetTransfer.getA_Asset_Acct());
depexp5.setDescription("Asset Transfer Cost");
depexp5.setIsDepreciated(false);
depexp5.setA_Period(AssetTransfer.getC_Period_ID());
depexp5.setA_Entry_Type("TRN");
depexp5.saveEx();
// Update Asset Setup for New Accounts
sql = null;
sql = "UPDATE A_ASSET_ACCT "
+ "SET A_DEPRECIATION_ACCT = " + AssetTransfer.getA_Depreciation_Acct_New()
+ ", A_ACCUMDEPRECIATION_ACCT = " + AssetTransfer.getA_Accumdepreciation_Acct_New()
+ ", A_DISPOSAL_LOSS = " + AssetTransfer.getA_Disposal_Loss_New()
+ ", A_DISPOSAL_REVENUE = " + AssetTransfer.getA_Disposal_Revenue_New()
+ ", A_ASSET_ACCT = "+ AssetTransfer.getA_Asset_Acct_New()
+ " WHERE A_ASSET_ID = " + AssetTransfer.getA_Asset_ID()
+ " AND POSTINGTYPE = '" + AssetTransfer.getPostingType()
+ "' AND A_PERIOD_START = " + AssetTransfer.getA_Period_Start()
+ " AND A_PERIOD_END = " + AssetTransfer.getA_Period_End();
MAssetChange change = new MAssetChange (getCtx(), 0, null);
change.setChangeType("TRN");
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "TRN"));
change.setPostingType(AssetTransfer.getPostingType());
change.setA_Split_Percent(AssetTransfer.getA_Split_Percent());
change.setA_Asset_ID(AssetTransfer.getA_Asset_ID());
change.setA_Period_Start(AssetTransfer.getA_Period_Start());
change.setA_Period_End(AssetTransfer.getA_Period_End());
change.setA_Asset_Acct(AssetTransfer.getA_Asset_Acct_New());
change.setC_AcctSchema_ID(AssetTransfer.getC_AcctSchema_ID());
change.setA_Accumdepreciation_Acct(AssetTransfer.getA_Accumdepreciation_Acct_New());
change.setA_Depreciation_Acct(AssetTransfer.getA_Depreciation_Acct_New());
change.setA_Disposal_Revenue(AssetTransfer.getA_Disposal_Revenue_New());
change.setA_Disposal_Loss(AssetTransfer.getA_Disposal_Loss_New());
change.setAssetAccumDepreciationAmt(rs.getBigDecimal("A_ACCUMULATED_DEPR"));
change.setAssetBookValueAmt(rs.getBigDecimal("A_Asset_Cost"));
change.setChangeAmt(v_Balance);
change.saveEx();
DB.executeUpdate(sql,null);
AssetTransfer.setIsActive(false);
AssetTransfer.saveEx();
// Remove Entry from Processing file
}
catch (Exception e)
{
log.info("TransferAssets"+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
} // doIt
} // AssetTransfer

View File

@ -1,388 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.compiere.model.X_A_Depreciation;
import org.compiere.model.X_A_Depreciation_Convention;
import org.compiere.model.X_A_Depreciation_Exp;
import org.compiere.model.X_A_Depreciation_Forecast;
import org.compiere.model.X_A_Depreciation_Method;
import org.compiere.model.X_A_Depreciation_Workfile;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Build Depreciation Forecast File
*
* @author Rob Klein
* @version $Id: BuildDepForecastFile.java,v 1.0 $
*/
public class BuildDepForecastFile extends SvrProcess
{
/** Record ID */
private int p_Depreciation_Build_ID = 0;
private boolean m_DeleteOld = false;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else if (name.equals("DeleteOld"))
m_DeleteOld = "Y".equals(para[i].getParameter());
else
log.info("prepare - Unknown Parameter: " + name);
}
p_Depreciation_Build_ID = getRecord_ID();
} // prepare
/**
* Build Depreciation Workfile
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("doIt - Depreciation_Build_ID=" + p_Depreciation_Build_ID);
if (p_Depreciation_Build_ID == 0)
throw new IllegalArgumentException("No Record");
String clientCheck = " AND AD_Client_ID=" + getAD_Client_ID();
//
int no = 0;
if (m_DeleteOld)
{
String sql = "DELETE A_DEPRECIATION_EXP "
+ "WHERE A_Entry_Type = 'FOR'" + clientCheck;
no = DB.executeUpdate (sql,null);
log.info ("doIt - Delete old processed entries =" + no);
}
X_A_Depreciation_Forecast DepBuild = new X_A_Depreciation_Forecast (getCtx(), p_Depreciation_Build_ID, null);
String sql = null;
sql = "DELETE FROM A_DEPRECIATION_EXP WHERE PostingType"
+ " = '" + DepBuild.getPostingType() + "' and A_Asset_ID"
+ " >= " + DepBuild.getA_Start_Asset_ID() + " and A_Asset_ID "
+ " <= " + DepBuild.getA_End_Asset_ID()
+ " and A_Entry_Type = 'FOR'"
+ clientCheck;
no = DB.executeUpdate(sql,null);
log.info("doIt - Clear DepExpense = " + no);
sql = null;
sql = "UPDATE A_DEPRECIATION_WORKFILE SET A_CURR_DEP_EXP = 0, A_CURRENT_PERIOD = 0 WHERE POSTINGTYPE"
+ " = '" + DepBuild.getPostingType() + "' and A_Asset_ID"
+ " >= " + DepBuild.getA_Start_Asset_ID() + " and A_Asset_ID "
+ " <= " + DepBuild.getA_End_Asset_ID()
+ clientCheck;
no = DB.executeUpdate(sql,null);
log.info("doIt - DepExpense Reset= " + no);
sql = null;
sql =" SELECT A_ASSET.A_ASSET_ID, A_ASSET.USELIFEYEARS, A_ASSET.USELIFEMONTHS, A_ASSET.LIFEUSEUNITS, "
+" A_ASSET.USEUNITS, A_ASSET.ISOWNED, A_ASSET.ISDISPOSED,A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED, "
+" A_DEPRECIATION_WORKFILE.A_CURR_DEP_EXP, A_ASSET.ASSETDEPRECIATIONDATE, A_ASSET.ISFULLYDEPRECIATED, "
+" A_ASSET.ASSETSERVICEDATE, A_DEPRECIATION_WORKFILE.A_ASSET_ID as v_Asset_ID, A_DEPRECIATION_WORKFILE.POSTINGTYPE, "
+" A_DEPRECIATION_FORECAST.A_START_ASSET_ID, A_DEPRECIATION_FORECAST.A_END_ASSET_ID, A_DEPRECIATION_WORKFILE.A_ACCUMULATED_DEPR,"
+" A_DEPRECIATION_FORECAST.AD_CLIENT_ID, A_DEPRECIATION_FORECAST.AD_ORG_ID, A_DEPRECIATION_WORKFILE.A_SALVAGE_VALUE,"
+" A_DEPRECIATION_FORECAST.CREATEDBY, A_DEPRECIATION_FORECAST.UPDATEDBY, A_DEPRECIATION_FORECAST.POSTINGTYPE as v_PostingType,"
+" A_DEPRECIATION_WORKFILE.A_DEPRECIATION_WORKFILE_ID, A_DEPRECIATION_FORECAST.DATEDOC, A_DEPRECIATION_WORKFILE.A_ASSET_COST"
+" FROM A_DEPRECIATION_WORKFILE, A_ASSET, A_DEPRECIATION_FORECAST "
+" WHERE A_ASSET.A_ASSET_ID = A_DEPRECIATION_WORKFILE.A_ASSET_ID AND A_ASSET.ISOWNED = 'Y' AND A_DEPRECIATION_FORECAST.A_START_ASSET_ID <= A_ASSET.A_ASSET_ID"
+" AND A_DEPRECIATION_FORECAST.A_END_ASSET_ID >= A_ASSET.A_ASSET_ID AND A_ASSET.ISFULLYDEPRECIATED = 'N' AND A_ASSET.ISDEPRECIATED = 'Y'"
+" AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = ? ";
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE,null);
try {
pstmt.setString(1, DepBuild.getPostingType());
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
X_A_Depreciation_Workfile assetwk = new X_A_Depreciation_Workfile (getCtx(), rs.getInt("A_DEPRECIATION_WORKFILE_ID"), null);
String sql2 = null;
sql2 =" SELECT * FROM A_ASSET_ACCT WHERE PostingType"
+ " = '" + DepBuild.getPostingType() + "' and A_Asset_ID"
+ " = " + rs.getInt("A_ASSET_ID");
PreparedStatement pstmt2 = null;
pstmt2 = DB.prepareStatement (sql2, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE,null);
try {
ResultSet rs2 = pstmt2.executeQuery();
//CallableStatement cs;
BigDecimal v_Dep_Exp_Inception = new BigDecimal("0.0");
BigDecimal v_Dep_Exp_Inception2 = new BigDecimal("0.0");
BigDecimal v_HalfYearConv = new BigDecimal("0.0");
BigDecimal v_HalfYearConv_Adj = new BigDecimal("0.0");
BigDecimal v_Dep_Exp_Adjustment = new BigDecimal("0.0");
BigDecimal v_Dep_Exp_Monthly = new BigDecimal("0.0");
BigDecimal v_total_adjustment = new BigDecimal("0.0");
int asset_id_current = 0;
double v_current=0;
BigDecimal v_current_adj = new BigDecimal(0.0);
while (rs2.next()){
//X_A_Asset_Acct assetacct = new X_A_Asset_Acct (getCtx(), rs2.getInt("A_ASSET_ACCT_ID"), null);
X_A_Depreciation depreciation = new X_A_Depreciation (getCtx(), rs2.getInt("A_DEPRECIATION_ID"), null);
X_A_Depreciation_Convention depreciation_conv = new X_A_Depreciation_Convention (getCtx(), rs2.getInt("A_DEPRECIATION_CONV_ID"), null);
X_A_Depreciation_Exp depexp = new X_A_Depreciation_Exp (getCtx(), 0, null);
//Date d1,d2;
//d1 = rs.getDate("ASSETSERVICEDATE");
//d2 = rs.getDate("DATEDOC");
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
int AssetServiceDateYear = calendar.get(Calendar.YEAR);
int AssetServiceDateMonth = calendar.get(Calendar.MONTH);
calendar.setTime(rs.getDate("DATEDOC"));
int DateAcctYear = calendar.get(Calendar.YEAR);
int DateAcctMonth = calendar.get(Calendar.MONTH);
double v_period = (Math.ceil(DateAcctMonth)+ (Math.floor(DateAcctYear) - Math.floor(AssetServiceDateYear))*12 - Math.floor(AssetServiceDateMonth)) ;
//Record booked depreciation expense
if (rs2.getInt("A_ASSET_ID")!=asset_id_current )
{
v_current_adj = new BigDecimal(0.0);
depexp.setPostingType(DepBuild.getPostingType());
depexp.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
depexp.setA_Account_Number(rs2.getInt("A_Depreciation_Acct"));
depexp.setPostingType(rs.getString("PostingType"));
depexp.setExpense(assetwk.getA_Accumulated_Depr().setScale(5, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(rs2.getFloat("A_Split_Percent"))));
depexp.setDescription("Actual Depreciation Expense Booked");
depexp.setA_Period(rs.getInt("A_Period_Posted"));
depexp.setIsDepreciated(true);
depexp.setDateAcct(assetwk.getAssetDepreciationDate());
depexp.setA_Entry_Type("FOR");
depexp.saveEx();
}
else
{
v_current_adj = v_current_adj.subtract(new BigDecimal(0.0));
}
int method = 0;
method = rs2.getInt("A_DEPRECIATION_METHOD_ID");
//Set depreciation date and record in workfile
Calendar cal = GregorianCalendar.getInstance();
Timestamp ts;
ts =(rs.getTimestamp("ASSETSERVICEDATE"));
cal.setTime(ts);
assetwk.setDateAcct(ts);
assetwk.setA_Period_Forecast(new BigDecimal(assetwk.getA_Period_Posted()));
assetwk.saveEx();
//Calculate life to date depreciation
while (v_current < v_period ){
v_Dep_Exp_Inception2 = Depreciation.Dep_Type(depreciation.getDepreciationType(),rs2.getInt("A_Asset_ID"),v_current, rs2.getString("PostingType"), rs2.getInt("A_ASSET_ACCT_ID"), v_Dep_Exp_Inception);
//cs = DB.prepareCall("{ ? = call "+ depreciation.getDepreciationType() + "(" + rs2.getInt("A_Asset_ID") + "," + (v_current) + ",'" + rs2.getString("PostingType") + "'," + rs2.getInt("A_ASSET_ACCT_ID") + "," + v_Dep_Exp_Inception + ")}");
//cs.registerOutParameter(1, java.sql.Types.DECIMAL);
//cs.execute();
//v_Dep_Exp_Inception2 = cs.getBigDecimal(1);
//cs.close();
v_HalfYearConv_Adj = new BigDecimal(Conventions.Dep_Convention(depreciation_conv.getConventionType(),rs2.getInt("A_Asset_ID"), rs2.getString("PostingType"), rs2.getInt("A_ASSET_ACCT_ID"), 1, (v_current -1 )));
//cs = DB.prepareCall("{ ? = call " + depreciation_conv.getConventionType() + "(" + rs2.getInt("A_Asset_ID") + ",'" + rs2.getString("PostingType") + "'," + rs2.getInt("A_ASSET_ACCT_ID") + ", 1 ," + (v_current -1 )+ ")}");
//cs.registerOutParameter(1, java.sql.Types.DECIMAL);
//cs.execute();
//v_HalfYearConv_Adj = cs.getBigDecimal(1);
//cs.close();
v_HalfYearConv = v_HalfYearConv.add(v_HalfYearConv_Adj);
cal.add(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
ts.setTime(cal.getTimeInMillis());
assetwk.setDateAcct(ts);
v_current_adj = v_current_adj.add((v_HalfYearConv_Adj));
assetwk.setA_Period_Forecast(v_current_adj);
assetwk.saveEx();
v_Dep_Exp_Inception = v_Dep_Exp_Inception .add(v_Dep_Exp_Inception2.multiply(v_HalfYearConv_Adj));
v_current = v_current + 1;
}
//log.info("doIt - Booked Expense= "+assetwk.getA_Accumulated_Depr());
//log.info("doIt - Calculated Expense= "+v_Dep_Exp_Inception);
//Calculate necessary adjustment per period
X_A_Depreciation_Method depreciation_method = new X_A_Depreciation_Method (getCtx(), method, null);
if (v_Dep_Exp_Inception.compareTo( assetwk.getA_Accumulated_Depr())!=0)
{
v_Dep_Exp_Adjustment = DepreciationAdj.Dep_Adj(depreciation_method.getDepreciationType(),rs2.getInt("A_Asset_ID") , (v_Dep_Exp_Inception.subtract(assetwk.getA_Accumulated_Depr())) , (Math.floor(DateAcctMonth)), rs2.getString("PostingType") , rs2.getInt("A_ASSET_ACCT_ID"));
//cs = DB.prepareCall("{ ? = call " + depreciation_method.getDepreciationType() + "(" + rs2.getInt("A_Asset_ID") + "," + (v_Dep_Exp_Inception.subtract(assetwk.getA_Accumulated_Depr())) + "," + (Math.floor(d2.getMonth()))+ ",'" + rs2.getString("PostingType") + "'," +rs2.getInt("A_ASSET_ACCT_ID") +")}");
//cs.registerOutParameter(1, java.sql.Types.DECIMAL);
//cs.execute();
//v_Dep_Exp_Adjustment = cs.getBigDecimal(1);
//cs.close();
v_total_adjustment = v_Dep_Exp_Inception.subtract(assetwk.getA_Accumulated_Depr());
}
v_current = v_current+1;
//v_Dep_Exp_Inception = (rs.getBigDecimal("A_ACCUMULATED_DEPR"));
BigDecimal v_period_adj = new BigDecimal(rs2.getInt("A_PERIOD_END"));
int lastdepexp2=0;
while (v_current_adj.compareTo(v_period_adj)<0){
//Calculation depreciation expense
v_Dep_Exp_Monthly = Depreciation.Dep_Type(depreciation.getDepreciationType(),rs2.getInt("A_Asset_ID"),v_current-1, rs2.getString("PostingType"), rs2.getInt("A_ASSET_ACCT_ID"), v_Dep_Exp_Inception);
//cs = DB.prepareCall("{ ? = call " + depreciation.getDepreciationType() + "(" + rs2.getInt("A_Asset_ID") +", "+ (v_current-1) +" ,'" + rs2.getString("PostingType") + "'," + rs2.getInt("A_ASSET_ACCT_ID") + " , " + (v_Dep_Exp_Inception) + ")}");
//cs.registerOutParameter(1, java.sql.Types.DECIMAL);
//cs.execute();
//v_Dep_Exp_Monthly = cs.getBigDecimal(1);
//cs.close();
//Adjust for half year convention
//log.info(depreciation_conv.getConventionType());
//log.info(""+rs2.getInt("A_Asset_ID"));
v_HalfYearConv_Adj = new BigDecimal(Conventions.Dep_Convention(depreciation_conv.getConventionType(),rs2.getInt("A_Asset_ID"), rs2.getString("PostingType"), rs2.getInt("A_ASSET_ACCT_ID"), 0, 1 ));
//log.info(""+v_HalfYearConv_Adj);
//cs = DB.prepareCall("{ ? = call " + depreciation_conv.getConventionType() + "(" + rs2.getInt("A_Asset_ID") +",'" + rs2.getString("PostingType") + "'," + rs2.getInt("A_ASSET_ACCT_ID") + " , 0, 1)}");
//cs.registerOutParameter(1, java.sql.Types.DECIMAL);
//cs.execute();
//v_HalfYearConv_Adj = cs.getBigDecimal(1);
//cs.close();
v_Dep_Exp_Monthly = v_Dep_Exp_Monthly.multiply((v_HalfYearConv_Adj));
v_HalfYearConv = v_HalfYearConv.add( v_HalfYearConv_Adj);
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, null);
if (v_total_adjustment.setScale(2, BigDecimal.ROUND_HALF_UP).compareTo(new BigDecimal (0.00))!=0)
{
//Record necessary adjustments
X_A_Depreciation_Exp depexp1 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp1.setA_Entry_Type("FOR");
depexp1.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
depexp1.setA_Account_Number(rs2.getInt("A_Depreciation_Acct"));
depexp1.setPostingType(rs.getString("PostingType"));
depexp1.setExpense(v_Dep_Exp_Adjustment.setScale(5, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(rs2.getFloat("A_Split_Percent"))));
depexp1.setDescription("Forecasted Depreciation Expense Adj.");
depexp1.setA_Period((int)v_current);
depexp1.setIsDepreciated(true);
depexp1.setDateAcct(ts);
depexp1.saveEx();
v_total_adjustment = v_total_adjustment.setScale(5, BigDecimal.ROUND_HALF_UP).subtract(v_Dep_Exp_Adjustment.setScale(5, BigDecimal.ROUND_HALF_UP));
//Record adjusted expense
depexp2.setPostingType(DepBuild.getPostingType());
depexp2.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
depexp2.setA_Account_Number(rs2.getInt("A_Depreciation_Acct"));
depexp2.setPostingType(rs.getString("PostingType"));
depexp2.setExpense((v_Dep_Exp_Monthly.setScale(2, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(rs2.getFloat("A_Split_Percent"))));
depexp2.setDescription("Forecasted Depreciation Expense");
depexp2.setA_Period((int)v_current);
depexp2.setIsDepreciated(true);
depexp2.setDateAcct(ts);
depexp2.setA_Entry_Type("FOR");
depexp2.saveEx();
v_Dep_Exp_Inception = v_Dep_Exp_Inception.add((v_Dep_Exp_Monthly.setScale(2, BigDecimal.ROUND_HALF_UP))).setScale(2, BigDecimal.ROUND_HALF_UP);
}
else
{
//Record expense
depexp2.setPostingType(DepBuild.getPostingType());
depexp2.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
depexp2.setExpense(v_Dep_Exp_Adjustment.setScale(2, BigDecimal.ROUND_HALF_UP));
depexp2.setA_Account_Number(rs2.getInt("A_Depreciation_Acct"));
depexp2.setPostingType(rs.getString("PostingType"));
depexp2.setExpense(v_Dep_Exp_Monthly.setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(rs2.getFloat("A_Split_Percent"))));
depexp2.setDescription("Forecasted Depreciation Expense");
depexp2.setA_Period((int)v_current);
depexp2.setIsDepreciated(true);
depexp2.setDateAcct(ts);
depexp2.setA_Entry_Type("FOR");
depexp2.saveEx();
v_Dep_Exp_Inception = v_Dep_Exp_Inception.add(v_Dep_Exp_Monthly).setScale(2, BigDecimal.ROUND_HALF_UP);
}
lastdepexp2 = depexp2.get_ID();
//Advance calender
cal.add(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
ts.setTime(cal.getTimeInMillis());
v_current_adj = v_current_adj.add((v_HalfYearConv_Adj)).setScale(2, BigDecimal.ROUND_HALF_UP);
//record in workfile
assetwk.setA_Period_Forecast(v_current_adj);
assetwk.setDateAcct(ts);
assetwk.saveEx();
v_current = v_current + 1;
}
//adjust last entry for rounding errors
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), lastdepexp2, null);
depexp2.setExpense(depexp2.getExpense().add(((rs.getBigDecimal("A_ASSET_COST").subtract(rs.getBigDecimal("A_SALVAGE_VALUE").subtract(v_total_adjustment))).subtract(v_Dep_Exp_Inception)).multiply(new BigDecimal(rs2.getFloat("A_Split_Percent")))));
depexp2.saveEx();
asset_id_current = rs2.getInt("A_ASSET_ID");
log.info("Asset #"+asset_id_current);
}
rs2.close();
pstmt2.close();
pstmt2 = null;
}
catch (Exception e)
{
log.info("getAssets"+ e);
}
finally
{
try
{
if (pstmt2 != null)
pstmt2.close ();
}
catch (Exception e)
{}
pstmt2 = null;
}
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.info("getAssets"+ e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return "";
} // doIt
} // BuildDepForecastFile

View File

@ -1,431 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.compiere.model.X_A_Depreciation;
import org.compiere.model.X_A_Depreciation_Build;
import org.compiere.model.X_A_Depreciation_Convention;
import org.compiere.model.X_A_Depreciation_Exp;
import org.compiere.model.X_A_Depreciation_Method;
import org.compiere.model.X_A_Depreciation_Workfile;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Build Depreciation Work File
*
* @author Rob Klein
* @version $Id: BuildDepWorkFile.java,v 1.0 $
*/
public class BuildDepWorkFile extends SvrProcess
{
/** Record ID */
private int p_Depreciation_Build_ID = 0;
private boolean m_DeleteOld = false;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else if (name.equals("DeleteOld"))
m_DeleteOld = "Y".equals(para[i].getParameter());
else
log.info("prepare - Unknown Parameter: " + name);
}
p_Depreciation_Build_ID = getRecord_ID();
} // prepare
/**
* Build Depreciation Workfile
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("doIt - Depreciation_Build_ID=" + p_Depreciation_Build_ID);
if (p_Depreciation_Build_ID == 0)
throw new IllegalArgumentException("No Record");
String clientCheck = " AND AD_Client_ID=" + getAD_Client_ID();
//
int no = 0;
//if (m_DeleteOld)
//{
// String sql = "DELETE A_DEPRECIATION_EXP "
// + "WHERE A_Entry_Type = 'FOR'" + clientCheck;
//
// no = DB.executeUpdate (sql);
// log.info ("doIt - Delete old processed entries =" + no);
//}
X_A_Depreciation_Build DepBuild = new X_A_Depreciation_Build (getCtx(), p_Depreciation_Build_ID, null);
String sql = null;
sql = "DELETE FROM A_DEPRECIATION_EXP WHERE PostingType"
+ " = '" + DepBuild.getPostingType() + "' and A_Asset_ID"
+ " >= " + DepBuild.getA_Start_Asset_ID() + " and A_Asset_ID "
+ " <= " + DepBuild.getA_End_Asset_ID()
+ " AND A_Entry_Type = 'DEP'"
+ clientCheck;
no = DB.executeUpdate(sql,null);
log.info("doIt - Clear DepExpense = " + no);
sql = null;
sql = "UPDATE A_DEPRECIATION_WORKFILE SET A_CURR_DEP_EXP = 0, A_CURRENT_PERIOD = 0 WHERE POSTINGTYPE"
+ " = '" + DepBuild.getPostingType() + "' and A_Asset_ID"
+ " >= " + DepBuild.getA_Start_Asset_ID() + " and A_Asset_ID "
+ " <= " + DepBuild.getA_End_Asset_ID()
+ clientCheck;
no = DB.executeUpdate(sql,null);
log.info("doIt - DepExpense Reset= " + no);
sql = null;
sql =" SELECT A_ASSET.A_ASSET_ID, A_ASSET.USELIFEYEARS, A_ASSET.USELIFEMONTHS, A_ASSET.LIFEUSEUNITS, "
+ "A_ASSET.USEUNITS, A_ASSET.ISOWNED, A_ASSET.ISDISPOSED,A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED, "
+ " A_DEPRECIATION_WORKFILE.A_CURR_DEP_EXP, A_ASSET.ASSETDEPRECIATIONDATE, A_ASSET.ISFULLYDEPRECIATED, "
+ " A_ASSET.ASSETSERVICEDATE, A_DEPRECIATION_WORKFILE.A_ASSET_ID as v_Asset_ID, A_DEPRECIATION_WORKFILE.POSTINGTYPE, "
+ " A_DEPRECIATION_BUILD.A_START_ASSET_ID, A_DEPRECIATION_BUILD.A_END_ASSET_ID, A_DEPRECIATION_WORKFILE.A_ACCUMULATED_DEPR, "
+ " A_DEPRECIATION_BUILD.PERIODNO, A_DEPRECIATION_BUILD.AD_CLIENT_ID, A_DEPRECIATION_BUILD.AD_ORG_ID, "
+ " A_DEPRECIATION_BUILD.CREATEDBY, A_DEPRECIATION_BUILD.UPDATEDBY, A_DEPRECIATION_BUILD.POSTINGTYPE as v_PostingType, "
+ " A_DEPRECIATION_BUILD.DATEACCT, A_DEPRECIATION_BUILD.C_PERIOD_ID, A_DEPRECIATION_WORKFILE.A_DEPRECIATION_WORKFILE_ID, "
+ " A_DEPRECIATION_BUILD.DATEDOC "
+ " FROM A_DEPRECIATION_WORKFILE, A_ASSET, A_DEPRECIATION_BUILD "
+ " WHERE A_ASSET.A_ASSET_ID = A_DEPRECIATION_WORKFILE.A_ASSET_ID AND A_ASSET.ISOWNED = 'Y' AND "
+ " A_DEPRECIATION_BUILD.DATEACCT >= A_ASSET.ASSETSERVICEDATE AND A_DEPRECIATION_BUILD.A_START_ASSET_ID <= A_ASSET.A_ASSET_ID "
+ " AND A_DEPRECIATION_BUILD.A_END_ASSET_ID >= A_ASSET.A_ASSET_ID AND A_ASSET.ISFULLYDEPRECIATED = 'N' AND A_ASSET.ISDEPRECIATED = 'Y' "
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = ? ";
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE,null);
ResultSet rs = null;
try {
pstmt.setString(1, DepBuild.getPostingType());
rs = pstmt.executeQuery();
while (rs.next()){
X_A_Depreciation_Workfile assetwk = new X_A_Depreciation_Workfile (getCtx(), rs.getInt("A_DEPRECIATION_WORKFILE_ID"), null);
String sql2 = null;
sql2 =" SELECT * FROM A_ASSET_ACCT WHERE PostingType"
+ " = '" + DepBuild.getPostingType() + "' and A_Asset_ID"
+ " = " + rs.getInt("A_ASSET_ID");
PreparedStatement pstmt2 = null;
pstmt2 = DB.prepareStatement (sql2, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE,null);
ResultSet rs2 = null;
try {
rs2 = pstmt2.executeQuery();
//CallableStatement cs;
BigDecimal v_Dep_Exp_Inception = new BigDecimal("0.0");
BigDecimal v_Dep_Exp_Inception2 = new BigDecimal("0.0");
BigDecimal v_HalfYearConv = new BigDecimal("0.0");
BigDecimal v_HalfYearConv_Adj = new BigDecimal("0.0");
BigDecimal v_Dep_Exp_Adjustment = new BigDecimal("0.0");
BigDecimal v_Dep_Exp_Monthly = new BigDecimal("0.0");
BigDecimal v_total_adjustment = new BigDecimal("0.0");
int asset_id_current = 0;
double v_current=0;
BigDecimal v_current_adj = new BigDecimal(0.0);
while (rs2.next()){
//X_A_Asset_Acct assetacct = new X_A_Asset_Acct (getCtx(), rs2.getInt("A_ASSET_ACCT_ID"), null);
X_A_Depreciation depreciation = new X_A_Depreciation (getCtx(), rs2.getInt("A_DEPRECIATION_ID"), null);
X_A_Depreciation_Convention depreciation_conv = new X_A_Depreciation_Convention (getCtx(), rs2.getInt("A_DEPRECIATION_CONV_ID"), null);
//X_A_Depreciation_Exp depexp = new X_A_Depreciation_Exp (getCtx(), 0, null);
//Date d1,d2;
//d1 = rs.getDate("ASSETSERVICEDATE");
//d2 = rs.getDate("DATEACCT");
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
int AssetServiceDateYear = calendar.get(Calendar.YEAR);
int AssetServiceDateMonth = calendar.get(Calendar.MONTH);
calendar.setTime(rs.getDate("DATEACCT"));
int DateAcctYear = calendar.get(Calendar.YEAR);
int DateAcctMonth = calendar.get(Calendar.MONTH);
double v_period = (Math.ceil(DateAcctMonth)+ (Math.floor(DateAcctYear) - Math.floor(AssetServiceDateYear))*12 - Math.floor(AssetServiceDateMonth)) ;
//Record booked depreciation expense
if (rs2.getInt("A_ASSET_ID")!=asset_id_current )
{
v_current_adj = new BigDecimal(0.0);
//depexp.setPostingType(DepBuild.getPostingType());
//depexp.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
//depexp.setA_Account_Number(rs2.getInt("A_Depreciation_Acct"));
//depexp.setPostingType(rs.getString("PostingType"));
//depexp.setExpense(assetwk.getA_Accumulated_Depr().setScale(5, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(rs2.getFloat("A_Split_Percent"))));
//depexp.setDescription("Actual Depreciation Expense Booked");
//depexp.setA_Period(rs.getInt("A_Period_Posted"));
//depexp.setIsDepreciated(true);
//depexp.setDateAcct(assetwk.getAssetDepreciationDate());
//depexp.setA_Entry_Type("DEP");
//depexp.saveEx();
}
else
{
v_current_adj = v_current_adj.subtract(new BigDecimal(0.0));
}
int method = 0;
method = rs2.getInt("A_DEPRECIATION_METHOD_ID");
//Set depreciation date and record in workfile
Calendar cal = GregorianCalendar.getInstance();
Timestamp ts;
ts =(rs.getTimestamp("ASSETSERVICEDATE"));
cal.setTime(ts);
assetwk.setDateAcct(ts);
assetwk.setA_Period_Forecast(new BigDecimal(assetwk.getA_Period_Posted()));
assetwk.saveEx();
//Calculate life to date depreciation
while (v_current < v_period ){
v_Dep_Exp_Inception2 = Depreciation.Dep_Type(depreciation.getDepreciationType(),rs2.getInt("A_Asset_ID"),v_current, rs2.getString("PostingType"), rs2.getInt("A_ASSET_ACCT_ID"), v_Dep_Exp_Inception);
//cs = DB.prepareCall("{ ? = call "+ depreciation.getDepreciationType() + "(" + rs2.getInt("A_Asset_ID") + "," + (v_current) + ",'" + rs2.getString("PostingType") + "'," + rs2.getInt("A_ASSET_ACCT_ID") + "," + v_Dep_Exp_Inception + ")}");
//cs.registerOutParameter(1, java.sql.Types.DECIMAL);
//cs.execute();
//v_Dep_Exp_Inception2 = cs.getBigDecimal(1);
//cs.close();
v_HalfYearConv_Adj = new BigDecimal(Conventions.Dep_Convention(depreciation_conv.getConventionType(),rs2.getInt("A_Asset_ID"), rs2.getString("PostingType"), rs2.getInt("A_ASSET_ACCT_ID"), 1, (v_current -1 )));
//cs = DB.prepareCall("{ ? = call " + depreciation_conv.getConventionType() + "(" + rs2.getInt("A_Asset_ID") + ",'" + rs2.getString("PostingType") + "'," + rs2.getInt("A_ASSET_ACCT_ID") + ", 1 ," + (v_current -1 )+ ")}");
//cs.registerOutParameter(1, java.sql.Types.DECIMAL);
//cs.execute();
//v_HalfYearConv_Adj = cs.getBigDecimal(1);
//cs.close();
v_HalfYearConv = v_HalfYearConv.add(v_HalfYearConv_Adj);
cal.add(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
ts.setTime(cal.getTimeInMillis());
assetwk.setDateAcct(ts);
v_current_adj = v_current_adj.add((v_HalfYearConv_Adj));
assetwk.setA_Period_Forecast(v_current_adj);
assetwk.saveEx();
v_Dep_Exp_Inception = v_Dep_Exp_Inception .add(v_Dep_Exp_Inception2.multiply(v_HalfYearConv_Adj));
v_current = v_current + 1;
}
//log.info("doIt - Booked Expense= "+assetwk.getA_Accumulated_Depr());
//log.info("doIt - Calculated Expense= "+v_Dep_Exp_Inception);
//Calculate necessary adjustment per period
X_A_Depreciation_Method depreciation_method = new X_A_Depreciation_Method (getCtx(), method, null);
if (v_Dep_Exp_Inception.compareTo( assetwk.getA_Accumulated_Depr())!=0)
{
v_Dep_Exp_Adjustment = DepreciationAdj.Dep_Adj(depreciation_method.getDepreciationType(),rs2.getInt("A_Asset_ID") , (v_Dep_Exp_Inception.subtract(assetwk.getA_Accumulated_Depr())) , (Math.floor(DateAcctMonth)), rs2.getString("PostingType") , rs2.getInt("A_ASSET_ACCT_ID"));
//cs = DB.prepareCall("{ ? = call " + depreciation_method.getDepreciationType() + "(" + rs2.getInt("A_Asset_ID") + "," + (v_Dep_Exp_Inception.subtract(assetwk.getA_Accumulated_Depr())) + "," + (Math.floor(d2.getMonth()))+ ",'" + rs2.getString("PostingType") + "'," +rs2.getInt("A_ASSET_ACCT_ID") +")}");
//cs.registerOutParameter(1, java.sql.Types.DECIMAL);
//cs.execute();
//v_Dep_Exp_Adjustment = cs.getBigDecimal(1);
//cs.close();
//log.info("doIt - callable statement #3= "+v_Dep_Exp_Adjustment);
v_total_adjustment = v_Dep_Exp_Inception.subtract(assetwk.getA_Accumulated_Depr());
}
//Record necessary adjustments
if (v_Dep_Exp_Adjustment.setScale(2, BigDecimal.ROUND_HALF_UP).compareTo(new BigDecimal (0.00))!=0)
{
X_A_Depreciation_Exp depexp1 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp1.setA_Entry_Type("DEP");
depexp1.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
depexp1.setA_Account_Number(rs2.getInt("A_Depreciation_Acct"));
depexp1.setPostingType(rs.getString("PostingType"));
depexp1.setExpense(v_Dep_Exp_Adjustment.setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(rs2.getFloat("A_Split_Percent"))));
depexp1.setDescription("Depreciation Expense Adj.");
depexp1.setA_Period(rs.getInt("C_Period_ID"));
depexp1.setIsDepreciated(true);
depexp1.setDateAcct(rs.getTimestamp("DateAcct"));
depexp1.saveEx();
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp2.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
depexp2.setA_Account_Number(rs2.getInt("A_AccumDepreciation_Acct"));
depexp2.setPostingType(rs.getString("PostingType"));
depexp2.setExpense(v_Dep_Exp_Adjustment.setScale(2, BigDecimal.ROUND_HALF_UP).multiply( new BigDecimal(-1 * rs2.getFloat("A_Split_Percent"))));
depexp2.setDescription("Depreciation Expense Adj.");
depexp2.setA_Period(rs.getInt("C_Period_ID"));
depexp2.setIsDepreciated(false);
depexp2.setDateAcct(rs.getTimestamp("DateAcct"));
depexp2.setA_Entry_Type("DEP");
depexp2.saveEx();
v_total_adjustment = v_total_adjustment.setScale(5, BigDecimal.ROUND_HALF_UP).subtract(v_Dep_Exp_Adjustment.setScale(5, BigDecimal.ROUND_HALF_UP));
}
v_current = v_current+1;
//v_Dep_Exp_Inception = (rs.getBigDecimal("A_ACCUMULATED_DEPR"));
//BigDecimal v_period_adj = new BigDecimal(rs2.getInt("A_PERIOD_END"));
int lastdepexp2=0;
//Calculation depreciation expense
v_Dep_Exp_Monthly = Depreciation.Dep_Type(depreciation.getDepreciationType(),rs2.getInt("A_Asset_ID"),v_current-1, rs2.getString("PostingType"), rs2.getInt("A_ASSET_ACCT_ID"), v_Dep_Exp_Inception);
//cs = DB.prepareCall("{ ? = call " + depreciation.getDepreciationType() + "(" + rs2.getInt("A_Asset_ID") +", "+ (v_current-1) +" ,'" + rs2.getString("PostingType") + "'," + rs2.getInt("A_ASSET_ACCT_ID") + " , " + (v_Dep_Exp_Inception) + ")}");
//cs.registerOutParameter(1, java.sql.Types.DECIMAL);
//cs.execute();
//v_Dep_Exp_Monthly = cs.getBigDecimal(1);
//cs.close();
//log.info("This is v_Dep_Exp_Monthly "+v_Dep_Exp_Monthly);
//Adjust for half year convention
v_HalfYearConv_Adj = new BigDecimal(Conventions.Dep_Convention(depreciation_conv.getConventionType(),rs2.getInt("A_Asset_ID"), rs2.getString("PostingType"), rs2.getInt("A_ASSET_ACCT_ID"), 0, 1 ));
//cs = DB.prepareCall("{ ? = call " + depreciation_conv.getConventionType() + "(" + rs2.getInt("A_Asset_ID") +",'" + rs2.getString("PostingType") + "'," + rs2.getInt("A_ASSET_ACCT_ID") + " , 0, 1)}");
//cs.registerOutParameter(1, java.sql.Types.DECIMAL);
//cs.execute();
//v_HalfYearConv_Adj = cs.getBigDecimal(1);
//cs.close();
//log.info("This is v_HalfYearConv_Adj "+v_HalfYearConv_Adj);
v_Dep_Exp_Monthly = v_Dep_Exp_Monthly.multiply((v_HalfYearConv_Adj));
//log.info("This is v_Dep_Exp_Monthly "+v_Dep_Exp_Monthly);
v_HalfYearConv = v_HalfYearConv.add( v_HalfYearConv_Adj);
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, null);
if (v_total_adjustment.setScale(2, BigDecimal.ROUND_HALF_UP).compareTo(new BigDecimal (0.00))!=0)
{
//Record necessary adjustments
//X_A_Depreciation_Exp depexp1 = new X_A_Depreciation_Exp (getCtx(), 0, null);
//depexp1.setA_Entry_Type("FOR");
//depexp1.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
//depexp1.setA_Account_Number(rs2.getInt("A_Depreciation_Acct"));
//depexp1.setPostingType(rs.getString("PostingType"));
//depexp1.setExpense(v_Dep_Exp_Adjustment.setScale(5, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(rs2.getFloat("A_Split_Percent"))));
//depexp1.setDescription("Forecasted Depreciation Expense Adj.");
//depexp1.setA_Period((int)v_current);
//depexp1.setIsDepreciated(true);
//depexp1.setDateAcct(ts);
//depexp1.saveEx();
v_total_adjustment = v_total_adjustment.setScale(5, BigDecimal.ROUND_HALF_UP).subtract(v_Dep_Exp_Adjustment.setScale(5, BigDecimal.ROUND_HALF_UP));
//Record adjusted expense
depexp2.setPostingType(DepBuild.getPostingType());
depexp2.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
depexp2.setA_Account_Number(rs2.getInt("A_Depreciation_Acct"));
depexp2.setPostingType(rs.getString("PostingType"));
depexp2.setExpense((v_Dep_Exp_Monthly.setScale(2, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(rs2.getFloat("A_Split_Percent"))));
depexp2.setDescription("Depreciation Expense");
depexp2.setA_Period(rs.getInt("C_Period_ID"));
depexp2.setIsDepreciated(true);
depexp2.setDateAcct(rs.getTimestamp("DateAcct"));
depexp2.setA_Entry_Type("DEP");
depexp2.saveEx();
X_A_Depreciation_Exp depexp3 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp3.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
depexp3.setA_Account_Number(rs2.getInt("A_AccumDepreciation_Acct"));
depexp3.setPostingType(rs.getString("PostingType"));
depexp3.setExpense(v_Dep_Exp_Monthly.setScale(2, BigDecimal.ROUND_HALF_UP).multiply( new BigDecimal(-1 * rs2.getFloat("A_Split_Percent"))));
depexp3.setDescription("Depreciation Expense");
depexp3.setA_Period(rs.getInt("C_Period_ID"));
depexp3.setIsDepreciated(false);
depexp3.setDateAcct(rs.getTimestamp("DateAcct"));
depexp3.setA_Entry_Type("DEP");
depexp3.saveEx();
v_Dep_Exp_Inception = v_Dep_Exp_Inception.add((v_Dep_Exp_Monthly.setScale(2, BigDecimal.ROUND_HALF_UP))).setScale(2, BigDecimal.ROUND_HALF_UP);
}
else
{
//Record expense
depexp2.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
depexp2.setA_Account_Number(rs2.getInt("A_Depreciation_Acct"));
depexp2.setPostingType(rs.getString("PostingType"));
depexp2.setExpense(v_Dep_Exp_Monthly.setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(rs2.getFloat("A_Split_Percent"))));
depexp2.setDescription("Depreciation Expense");
depexp2.setA_Period(rs.getInt("C_Period_ID"));
depexp2.setIsDepreciated(true);
depexp2.setDateAcct(rs.getTimestamp("DateAcct"));
depexp2.setA_Entry_Type("DEP");
depexp2.saveEx();
X_A_Depreciation_Exp depexp3 = new X_A_Depreciation_Exp (getCtx(), 0, null);
depexp3.setA_Asset_ID(rs.getInt("A_ASSET_ID"));
depexp3.setA_Account_Number(rs2.getInt("A_AccumDepreciation_Acct"));
depexp3.setPostingType(rs.getString("PostingType"));
depexp3.setExpense(v_Dep_Exp_Monthly.setScale(2, BigDecimal.ROUND_HALF_UP).multiply( new BigDecimal(-1 * rs2.getFloat("A_Split_Percent"))));
depexp3.setDescription("Depreciation Expense");
depexp3.setA_Period(rs.getInt("C_Period_ID"));
depexp3.setIsDepreciated(false);
depexp3.setDateAcct(rs.getTimestamp("DateAcct"));
depexp3.setA_Entry_Type("DEP");
depexp3.saveEx();
v_Dep_Exp_Inception = v_Dep_Exp_Inception.add(v_Dep_Exp_Monthly).setScale(2, BigDecimal.ROUND_HALF_UP);
}
lastdepexp2 = depexp2.get_ID();
//Advance calender
cal.add(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
ts.setTime(cal.getTimeInMillis());
v_current_adj = v_current_adj.add((v_HalfYearConv_Adj)).setScale(2, BigDecimal.ROUND_HALF_UP);
//record in workfile
assetwk.setA_Period_Forecast(v_current_adj);
assetwk.setDateAcct(ts);
assetwk.setA_Current_Period((int)v_current);
assetwk.saveEx();
asset_id_current = rs2.getInt("A_ASSET_ID");
log.info(""+asset_id_current);
}
}
catch (Exception e)
{
log.info("getAssets"+ e);
}
finally
{
DB.close(rs, pstmt);
rs2 = null; pstmt2 = null;
}
}
}
catch (Exception e)
{
log.info("getAssets"+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
} // doIt
} // InvoiceCreateInOut

View File

@ -1,145 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import org.compiere.model.CalloutEngine;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.util.DB;
import org.compiere.util.Env;
/**
* FA Callout.
*
* @author Rob Klein
* @version $Id: CalloutFA.java,v 1.0 $
*/
public class CalloutFA extends CalloutEngine
{
/**
* Table_Period. Used to set the Manual Period Field. This allows
* the Spread Field to be displayed when there is a code that
* has been setup as Yearly.
* The string in the Callout field is:
* <code>com.compiere.custom.CalloutEngine.Table_Period</code>
*
* @param ctx Context
* @param WindowNo current Window No
* @param mTab Model Tab
* @param mField Model Field
* @param value The new value
* @param oldValue The old value
* @return error message or "" if OK
*/
public String Table_Period (Properties ctx, int WindowNo,
GridTab mTab, GridField mField, Object value, Object oldValue)
{
Integer A_Depreciation_Table_Header_ID = (Integer)value;
try
{
if (A_Depreciation_Table_Header_ID != null){
String SQL = "SELECT A_Term "
+ "FROM A_Depreciation_Table_Header "
+ "WHERE A_Depreciation_Table_Header_ID='"
+A_Depreciation_Table_Header_ID
+"'";
PreparedStatement pstmt = DB.prepareStatement(SQL,null);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
// Charges - Set Context
Env.setContext(ctx, WindowNo, "A_DEPRECIATION_MANUAL_PERIOD", rs.getString("A_Term"));
mTab.setValue ("A_DEPRECIATION_MANUAL_PERIOD", rs.getString("A_Term"));
}
rs.close();
pstmt.close();
}
}
catch (SQLException e)
{
log.info("PeriodType "+ e);
return e.getLocalizedMessage();
}
return "";
} // Period Type
/**
* Field_Clear. Used to set the Manual Period Field. This allows
* the Spread Field to be displayed when there is a code that
* has been setup as Yearly.
* The string in the Callout field is:
* <code>com.compiere.custom.CalloutEngine.Table_Period</code>
*
* @param ctx Context
* @param WindowNo current Window No
* @param mTab Model Tab
* @param mField Model Field
* @param value The new value
* @param oldValue The old value
* @return error message or "" if OK
*/
public String Field_Clear (Properties ctx, int WindowNo,
GridTab mTab, GridField mField, Object value, Object oldValue)
{
Object A_Depreciation_ID = value;
try
{
String SQL = "SELECT DepreciationType "
+ "FROM A_Depreciation "
+ "WHERE A_Depreciation_ID="
+ A_Depreciation_ID;
PreparedStatement pstmt = DB.prepareStatement(SQL,null);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
// Charges - Set Context
if ( (!rs.getString("DepreciationType").equals("TAB")) || (!rs.getString("DepreciationType").equals("MAN")) )
{
Env.setContext(ctx, WindowNo, "A_DEPRECIATION_MANUAL_PERIOD", "");
//mTab.setValue ("A_Depreciation_Manual_Period", null);
mTab.setValue ("A_Depreciation_Manual_Amount", null);
mTab.setValue ("A_Depreciation_Table_Header_ID", null);
}
if (rs.getString("DepreciationType").equals("TAB"))
{
mTab.setValue ("A_Depreciation_Manual_Amount", null);
}
if (rs.getString("DepreciationType").equals("MAN"))
{
mTab.setValue ("A_Depreciation_Table_Header_ID", null);
}
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.info("PeriodType "+ e);
return e.getLocalizedMessage();
}
return "";
} // Period Type
} // CalloutFA

View File

@ -1,407 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* _____________________________________________
*****************************************************************************/
package org.compiere.FA;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.compiere.util.DB;
/**
* Fixed Asset Conventions
*
* @author Rob Klein
* @version $Id: Conventions.java,v 1.0 $
*
*/
public class Conventions {
/**
*
*
*/
static public double Dep_Convention(String Type,int p_A_ASSET_ID, String p_POSTINGTYPE, int p_A_ASSET_ACCT_ID, int p_Flag, double p_Period)
{
if(Type.compareTo("FMCON")==0)
return FMCON(p_A_ASSET_ID, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Flag, p_Period);
else if(Type.compareTo("FYCON")==0)
return FYCON(p_A_ASSET_ID, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Flag, p_Period);
else if(Type.compareTo("DYCON")==0)
return DYCON(p_A_ASSET_ID, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Flag, p_Period);
else if(Type.compareTo("MMCON")==0)
return MMCON(p_A_ASSET_ID, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Flag, p_Period);
else if(Type.compareTo("MQCON")==0)
return MQCON(p_A_ASSET_ID, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Flag, p_Period);
else if(Type.compareTo("HYCON")==0)
return HYCON(p_A_ASSET_ID, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Flag, p_Period);
else
return 0.0;
}
/**
*
*
*/
static public double FMCON(int p_A_ASSET_ID, String p_POSTINGTYPE, int p_A_ASSET_ACCT_ID, int p_Flag, double p_Period)
{
return 1.0;
}
static public double HYCON(int p_A_ASSET_ID, String p_POSTINGTYPE, int p_A_ASSET_ACCT_ID, int p_Flag, double p_Period)
{
int v_adj=0;
StringBuffer sqlB = new StringBuffer ("SELECT A_ASSET.ASSETSERVICEDATE, A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED,"
+ " A_DEPRECIATION_WORKFILE.A_ASSET_LIFE_YEARS, A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD,"
+ " A_DEPRECIATION_WORKFILE.DATEACCT"
+ " FROM A_DEPRECIATION_WORKFILE, A_ASSET"
+ " WHERE A_ASSET.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '" + p_POSTINGTYPE+"'");
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
while (rs.next()){
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
int AssetServiceDateYear = calendar.get(Calendar.YEAR);
int AssetServiceDateMonth = calendar.get(Calendar.MONTH);
calendar.setTime(rs.getDate("DATEACCT"));
int DateAcctYear = calendar.get(Calendar.YEAR);
int v_Months_of_Half_Year = (12-(AssetServiceDateMonth)+1);
//ADJUST PERIOD FOR MID-MONTH CONVENTION
if(DateAcctYear == AssetServiceDateYear)
v_adj = 6/v_Months_of_Half_Year;
else
v_adj = 1;
if(p_Flag == 2){
//ADJUST COST CORRECTIONS FOR HALF-YEAR CONVENTION
if (p_Period == AssetServiceDateYear)
v_adj = 6/v_Months_of_Half_Year;
else
v_adj = 1;
}
}
}
catch (Exception e)
{
System.out.println("HYCON"+e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return v_adj;
}
static public double FYCON(int p_A_ASSET_ID, String p_POSTINGTYPE, int p_A_ASSET_ACCT_ID, int p_Flag, double p_Period)
{
int v_adj=0;
StringBuffer sqlB = new StringBuffer ("SELECT A_ASSET.ASSETSERVICEDATE,"
+ " A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED,"
+ " A_DEPRECIATION_WORKFILE.A_ASSET_LIFE_YEARS, A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD,"
+ " A_DEPRECIATION_WORKFILE.DATEACCT"
+ " FROM A_DEPRECIATION_WORKFILE, A_ASSET"
+ " WHERE A_ASSET.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '" + p_POSTINGTYPE+"'");
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
int AssetServiceDateYear = calendar.get(Calendar.YEAR);
int AssetServiceDateMonth = calendar.get(Calendar.MONTH);
calendar.setTime(rs.getDate("DATEACCT"));
int DateAcctYear = calendar.get(Calendar.YEAR);
int v_Months_of_Full_Year = 12 - AssetServiceDateMonth;
if(p_Flag < 2){
//ADJUST PERIOD FOR FULL-YEAR CONVENTION
if(DateAcctYear == AssetServiceDateYear)
v_adj = 12/v_Months_of_Full_Year;
else
v_adj = 1;
}
if(p_Flag == 2){
//ADJUST COST CORRECTIONS FOR FULL-YEAR CONVENTION
v_adj = 12/v_Months_of_Full_Year;
}
}
}
catch (Exception e)
{
System.out.println("FYCON"+e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return v_adj;
}
static public double DYCON(int p_A_ASSET_ID, String p_POSTINGTYPE, int p_A_ASSET_ACCT_ID, int p_Flag, double p_Period)
{
int v_adj=0;
StringBuffer sqlB = new StringBuffer ("SELECT A_ASSET.ASSETSERVICEDATE,"
+ " A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED,"
+ " A_DEPRECIATION_WORKFILE.A_ASSET_LIFE_YEARS, A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD,"
+ " A_DEPRECIATION_WORKFILE.DATEACCT"
+ " FROM A_DEPRECIATION_WORKFILE, A_ASSET"
+ " WHERE A_ASSET.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '" + p_POSTINGTYPE+"'");
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
int AssetServiceDateYear = calendar.get(Calendar.YEAR);
int AssetServiceDateMonth = calendar.get(Calendar.MONTH);
int AssetServiceDateDay = calendar.get(Calendar.DAY_OF_YEAR);
calendar.setTime(rs.getDate("DATEACCT"));
int DateAcctYear = calendar.get(Calendar.YEAR);
int DateAcctMonth = calendar.get(Calendar.MONTH);
if(p_Flag ==0){
//ADJUST PERIOD FOR DAY CONVENTION
if(DateAcctYear == AssetServiceDateYear){
return ((365-(double)AssetServiceDateDay)/365);
}
else if ((DateAcctYear*12 + DateAcctMonth) == (AssetServiceDateYear+rs.getInt("A_ASSET_LIFE_YEARS"))*12 + AssetServiceDateMonth)
return ((double)AssetServiceDateDay/365);
else if ((DateAcctYear*12 + DateAcctMonth) > (AssetServiceDateYear+rs.getInt("A_ASSET_LIFE_YEARS"))*12 + AssetServiceDateMonth)
return ((double)AssetServiceDateDay/365);
else
return 1;
}
if(p_Flag ==1){
//ADJUST PERIOD FOR DAY CONVENTION
if(DateAcctYear == AssetServiceDateYear){
return ((365-(double)AssetServiceDateDay)/365);
}
if(DateAcctYear == (AssetServiceDateYear+rs.getInt("A_ASSET_LIFE_YEARS")+1))
return ((double)AssetServiceDateDay/365);
else
return 1;
}
if(p_Flag == 2){
//ADJUST PERIOD FOR DAY CONVENTION
return ((365-(double)AssetServiceDateDay)/365);
}
}
}
catch (Exception e)
{
System.out.println("DYCON"+e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return v_adj;
}
static public double MMCON(int p_A_ASSET_ID, String p_POSTINGTYPE, int p_A_ASSET_ACCT_ID, int p_Flag, double p_Period)
{
int v_adj=0;
StringBuffer sqlB = new StringBuffer ("SELECT A_ASSET.ASSETSERVICEDATE,"
+ " A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED,"
+ " A_DEPRECIATION_WORKFILE.A_ASSET_LIFE_YEARS, A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD,"
+ " A_DEPRECIATION_WORKFILE.DATEACCT"
+ " FROM A_DEPRECIATION_WORKFILE, A_ASSET"
+ " WHERE A_ASSET.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '" + p_POSTINGTYPE+"'");
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
int AssetServiceDateMonth = calendar.get(Calendar.MONTH);
calendar.setTime(rs.getDate("DATEACCT"));
int DateAcctMonth = calendar.get(Calendar.MONTH);
if(p_Flag ==0){
if(DateAcctMonth - AssetServiceDateMonth >1)
return 1;
else
return .5;
}
if(p_Flag ==1){
if(p_Period == 0)
return .5;
else
return 1;
}
if(p_Flag == 2){
if (p_Period - AssetServiceDateMonth >1)
return 1;
else
return .5;
}
}
}
catch (Exception e)
{
System.out.println("MMCON"+e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return v_adj;
}
static public double MQCON(int p_A_ASSET_ID, String p_POSTINGTYPE, int p_A_ASSET_ACCT_ID, int p_Flag, double p_Period)
{
int v_adj=0;
StringBuffer sqlB = new StringBuffer ("SELECT A_ASSET.ASSETSERVICEDATE,"
+ " A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED,"
+ " A_DEPRECIATION_WORKFILE.A_ASSET_LIFE_YEARS, A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD,"
+ " A_DEPRECIATION_WORKFILE.DATEACCT"
+ " FROM A_DEPRECIATION_WORKFILE, A_ASSET"
+ " WHERE A_ASSET.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '" + p_POSTINGTYPE+"'");
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
int AssetServiceDateYear = calendar.get(Calendar.YEAR);
int AssetServiceDateMonth = calendar.get(Calendar.MONTH);
calendar.setTime(rs.getDate("DATEACCT"));
int DateAcctYear = calendar.get(Calendar.YEAR);
int DateAcctMonth = calendar.get(Calendar.MONTH);
if(p_Flag <2){
//ADJUST PERIOD FOR MID-QUARTER CONVENTION
if(DateAcctYear == AssetServiceDateYear){
if(AssetServiceDateMonth < 4 )
return .875;
else if (AssetServiceDateMonth < 7 )
return .625;
else if (AssetServiceDateMonth < 10 )
return .375;
else if (AssetServiceDateMonth > 9 )
return .125;
}
else if(DateAcctYear*12 + DateAcctMonth >= ((AssetServiceDateYear+rs.getInt("A_ASSET_LIFE_YEARS"))*12 + AssetServiceDateMonth)){
if(AssetServiceDateMonth < 4 )
return .125;
else if (AssetServiceDateMonth < 7 )
return .375;
else if (AssetServiceDateMonth < 10 )
return .625;
else if (AssetServiceDateMonth > 9 )
return .875;
}
else
return 1;
}
if(p_Flag == 2){
if(AssetServiceDateMonth< 4 )
return .875;
else if (AssetServiceDateMonth < 7 )
return .625;
else if (AssetServiceDateMonth < 10 )
return .375;
else if (AssetServiceDateMonth > 9 )
return .125;
}
}
}
catch (Exception e)
{
System.out.println("MQCON"+e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return v_adj;
}
}// Conventions

View File

@ -1,383 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.compiere.model.MAssetAcct;
import org.compiere.model.MAssetChange;
import org.compiere.model.MRefList;
import org.compiere.model.X_A_Asset;
import org.compiere.model.X_A_Asset_Addition;
import org.compiere.model.X_A_Asset_Group_Acct;
import org.compiere.model.X_A_Depreciation_Workfile;
import org.compiere.model.X_GL_JournalLine;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Create Asset from FA GL Process
*
* @author Rob Klein
* @version $Id: CreateGLAsset.java,v 1.0 $
*/
public class CreateGLAsset extends SvrProcess
{
private int p_client = 0;
//private int p_org = 0;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else if (name.equals("AD_Client_ID"))
p_client = para[i].getParameterAsInt();
else
log.info("prepare - Unknown Parameter: " + name);
}
} // prepare
/**
* Process Invoices
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("Starting inbound invoice process");
// int uselifemonths = 0;
// int uselifeyears = 0;
String sql =" SELECT * FROM GL_JOURNALLINE WHERE A_Processed <> 'Y' and AD_Client_ID = ?"
+ " and A_CreateAsset = 'Y' and Processed = 'Y'";
log.info(sql);
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql,get_TrxName());
ResultSet rs = null;
try {
pstmt.setInt(1, p_client);
rs = pstmt.executeQuery();
while (rs.next()){
X_A_Asset asset = new X_A_Asset (getCtx(), rs.getInt("A_Asset_ID"), get_TrxName());
X_GL_JournalLine JVLine = new X_GL_JournalLine (getCtx(), rs.getInt("GL_JournalLine_ID"), get_TrxName());
String sql2 ="SELECT C.AccountType FROM GL_JournalLine A, C_ValidCombination B, C_ElementValue C WHERE A.GL_JournalLine_ID = ?" +
" and A.C_ValidCombination_ID = B.C_ValidCombination_ID and B.Account_ID = C.C_ElementValue_ID";
String acctType = DB.getSQLValueString(get_TrxName(),sql2, JVLine.getGL_JournalLine_ID());
if (acctType.equals("A")){
sql ="SELECT * FROM A_Asset_Group_Acct WHERE A_Asset_Group_ID = ? AND IsActive='Y'";
log.info("yes");
pstmt = null;
pstmt = DB.prepareStatement(sql,get_TrxName());
if(asset.getA_Asset_ID()==0) {
int groupId = JVLine.getA_Asset_Group_ID();
pstmt.setInt(1, groupId);
} else
pstmt.setInt(1, asset.getA_Asset_Group_ID());
ResultSet rs2 = pstmt.executeQuery();
while (rs2.next()){
X_A_Asset_Group_Acct assetgrpacct = new X_A_Asset_Group_Acct (getCtx(), rs2,get_TrxName());
MAssetAcct assetacct = new MAssetAcct (getCtx(), 0, get_TrxName());
if (assetgrpacct.isProcessing()== true){
sql2 = "SELECT COUNT(*) FROM A_Depreciation_Workfile WHERE A_Asset_ID=? and"
+ " PostingType = '"+assetgrpacct.getPostingType()+"'";
if (DB.getSQLValue(get_TrxName(),sql2, asset.getA_Asset_ID())== 0)
{
asset.setIsOwned(true);
asset.setIsDepreciated(assetgrpacct.isProcessing());
asset.setA_Asset_CreateDate(JVLine.getDateAcct());
asset.setIsInPosession(true);
if(JVLine.getDescription()!= null)
asset.setName(JVLine.getDescription());
else
asset.setName("Asset created from JV");
asset.setHelp("Created from JV #" + JVLine.getGL_Journal_ID() + " on line #" + JVLine.getLine());
asset.setDescription(JVLine.getDescription());
asset.setUseLifeMonths(assetgrpacct.getUseLifeMonths());
asset.setUseLifeYears(assetgrpacct.getUseLifeYears());
asset.setA_Asset_Group_ID(assetgrpacct.getA_Asset_Group_ID());
asset.setA_QTY_Current(JVLine.getQty());
asset.setA_QTY_Original(JVLine.getQty());
asset.saveEx();
asset.setA_Parent_Asset_ID(asset.getA_Asset_ID());
asset.saveEx();
boolean isdepreciate = assetgrpacct.isProcessing();
if (isdepreciate == true)
{
assetacct.setPostingType(assetgrpacct.getPostingType());
assetacct.setA_Split_Percent(assetgrpacct.getA_Split_Percent());
assetacct.setA_Depreciation_Conv_ID(assetgrpacct.getConventionType());
assetacct.setA_Asset_ID(asset.getA_Asset_ID());
assetacct.setA_Depreciation_ID(assetgrpacct.getDepreciationType());
assetacct.setA_Asset_Spread_ID(assetgrpacct.getA_Asset_Spread_Type());
assetacct.setA_Period_Start(1);
if (asset.getUseLifeMonths() == 0 & asset.getUseLifeYears() == 0){
assetacct.setA_Period_End(assetgrpacct.getUseLifeMonths());
asset.setUseLifeYears(assetgrpacct.getUseLifeYears());
asset.setUseLifeMonths(assetgrpacct.getUseLifeMonths());
asset.setIsDepreciated(true);
asset.setIsOwned(true);
asset.saveEx();
// uselifemonths = assetgrpacct.getUseLifeMonths();
// uselifeyears = assetgrpacct.getUseLifeYears();
}
else if(asset.getUseLifeMonths() == 0){
assetacct.setA_Period_End(asset.getUseLifeYears()*12);
asset.setUseLifeMonths(asset.getUseLifeYears()*12);
asset.setIsDepreciated(true);
asset.setIsOwned(true);
asset.saveEx();
// uselifemonths = asset.getUseLifeYears()*12;
// uselifeyears = asset.getUseLifeYears();
}
else{
assetacct.setA_Period_End(asset.getUseLifeMonths());
// uselifemonths = asset.getUseLifeMonths();
// uselifeyears = asset.getUseLifeYears();
}
assetacct.setA_Depreciation_Method_ID(assetgrpacct.getA_Depreciation_Calc_Type());
assetacct.setA_Asset_Acct(assetgrpacct.getA_Asset_Acct());
assetacct.setC_AcctSchema_ID(assetgrpacct.getC_AcctSchema_ID());
assetacct.setA_Salvage_Value(new BigDecimal (0.0));
assetacct.setA_Accumdepreciation_Acct(assetgrpacct.getA_Accumdepreciation_Acct());
assetacct.setA_Depreciation_Acct(assetgrpacct.getA_Depreciation_Acct());
assetacct.setA_Disposal_Revenue(assetgrpacct.getA_Disposal_Revenue());
assetacct.setA_Disposal_Loss(assetgrpacct.getA_Disposal_Loss());
assetacct.setA_Reval_Accumdep_Offset_Cur(assetgrpacct.getA_Reval_Accumdep_Offset_Cur());
assetacct.setA_Reval_Accumdep_Offset_Prior(assetgrpacct.getA_Reval_Accumdep_Offset_Prior());
assetacct.setA_Reval_Cal_Method(assetgrpacct.getA_Reval_Cal_Method());
assetacct.setA_Reval_Cost_Offset(assetgrpacct.getA_Reval_Cost_Offset());
assetacct.setA_Reval_Cost_Offset_Prior(assetgrpacct.getA_Reval_Cost_Offset_Prior());
assetacct.setA_Reval_Depexp_Offset(assetgrpacct.getA_Reval_Depexp_Offset());
assetacct.setA_Depreciation_Manual_Amount(assetgrpacct.getA_Depreciation_Manual_Amount());
assetacct.setA_Depreciation_Manual_Period(assetgrpacct.getA_Depreciation_Manual_Period());
assetacct.setA_Depreciation_Table_Header_ID(assetgrpacct.getA_Depreciation_Table_Header_ID());
assetacct.setA_Depreciation_Variable_Perc(assetgrpacct.getA_Depreciation_Variable_Perc());
assetacct.setProcessing(false);
assetacct.saveEx();
MAssetChange change = new MAssetChange (getCtx(), 0, get_TrxName());
change.setPostingType(assetacct.getPostingType());
change.setA_Split_Percent(assetacct.getA_Split_Percent());
change.setConventionType(assetacct.getA_Depreciation_Conv_ID());
change.setA_Asset_ID(asset.getA_Asset_ID());
change.setDepreciationType(assetacct.getA_Depreciation_ID());
change.setA_Asset_Spread_Type(assetacct.getA_Asset_Spread_ID());
change.setA_Period_Start(assetacct.getA_Period_Start());
change.setA_Period_End(assetacct.getA_Period_End());
change.setIsInPosession(asset.isOwned());
change.setIsDisposed(asset.isDisposed());
change.setIsDepreciated(asset.isDepreciated());
change.setIsFullyDepreciated(asset.isFullyDepreciated());
change.setA_Depreciation_Calc_Type(assetacct.getA_Depreciation_Method_ID());
change.setA_Asset_Acct(assetacct.getA_Asset_Acct());
change.setC_AcctSchema_ID(assetacct.getC_AcctSchema_ID());
change.setA_Accumdepreciation_Acct(assetacct.getA_Accumdepreciation_Acct());
change.setA_Depreciation_Acct(assetacct.getA_Depreciation_Acct());
change.setA_Disposal_Revenue(assetacct.getA_Disposal_Revenue());
change.setA_Disposal_Loss(assetacct.getA_Disposal_Loss());
change.setA_Reval_Accumdep_Offset_Cur(assetacct.getA_Reval_Accumdep_Offset_Cur());
change.setA_Reval_Accumdep_Offset_Prior(assetacct.getA_Reval_Accumdep_Offset_Prior());
change.setA_Reval_Cal_Method(assetacct.getA_Reval_Cal_Method());
change.setA_Reval_Cost_Offset(assetacct.getA_Reval_Cost_Offset());
change.setA_Reval_Cost_Offset_Prior(assetacct.getA_Reval_Cost_Offset_Prior());
change.setA_Reval_Depexp_Offset(assetacct.getA_Reval_Depexp_Offset());
change.setA_Depreciation_Manual_Amount(assetacct.getA_Depreciation_Manual_Amount());
change.setA_Depreciation_Manual_Period(assetacct.getA_Depreciation_Manual_Period());
change.setA_Depreciation_Table_Header_ID(assetacct.getA_Depreciation_Table_Header_ID());
change.setA_Depreciation_Variable_Perc(assetacct.getA_Depreciation_Variable_Perc());
change.setA_Parent_Asset_ID(asset.getA_Parent_Asset_ID());
change.setChangeType("CRT");
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "CRT"));
change.setIsInPosession(asset.isOwned());
change.setIsDisposed(asset.isDisposed());
change.setIsDepreciated(asset.isDepreciated());
change.setIsFullyDepreciated(asset.isFullyDepreciated());
change.setLot(asset.getLot());
change.setSerNo(asset.getSerNo());
change.setVersionNo(asset.getVersionNo());
change.setUseLifeMonths(asset.getUseLifeMonths());
change.setUseLifeYears(asset.getUseLifeYears());
change.setLifeUseUnits(asset.getLifeUseUnits());
change.setAssetDisposalDate(asset.getAssetDisposalDate());
change.setAssetServiceDate(asset.getAssetServiceDate());
change.setC_BPartner_Location_ID(asset.getC_BPartner_Location_ID());
change.setC_BPartner_ID(asset.getC_BPartner_ID());
change.setAssetValueAmt(JVLine.getAmtAcctDr().subtract(JVLine.getAmtAcctCr()));
change.setA_Asset_CreateDate(asset.getA_Asset_CreateDate());
change.setAD_User_ID(asset.getAD_User_ID());
change.setC_Location_ID(asset.getC_Location_ID());
change.saveEx();
}
X_A_Depreciation_Workfile assetwk = new X_A_Depreciation_Workfile (getCtx(), 0, get_TrxName());
assetwk.setA_Asset_ID(asset.getA_Asset_ID());
assetwk.setA_Life_Period(assetgrpacct.getUseLifeMonths());
assetwk.setA_Asset_Life_Years(assetgrpacct.getUseLifeYears());
assetwk.setA_Asset_Cost(assetwk.getA_Asset_Cost().add(JVLine.getAmtAcctDr().subtract(JVLine.getAmtAcctCr())));
assetwk.setA_Accumulated_Depr(new BigDecimal (0.0));
assetwk.setA_Salvage_Value(new BigDecimal (0.0));
assetwk.setA_Period_Posted(0);
assetwk.setA_Asset_Life_Current_Year(new BigDecimal (0.0));
assetwk.setA_Curr_Dep_Exp(new BigDecimal (0.0));
assetwk.setA_QTY_Current(JVLine.getQty());
assetwk.setIsDepreciated(assetgrpacct.isProcessing());
assetwk.setPostingType(assetgrpacct.getPostingType());
assetwk.saveEx();
X_A_Asset_Addition assetadd = new X_A_Asset_Addition (getCtx(), 0, get_TrxName());
assetadd.setA_Asset_ID(asset.getA_Asset_ID());
assetadd.setAssetValueAmt(JVLine.getAmtAcctDr().subtract(JVLine.getAmtAcctCr()));
assetadd.setA_SourceType("JRN");
assetadd.setA_CapvsExp("Cap");
assetadd.setA_QTY_Current(JVLine.getQty());
assetadd.setDocumentNo(""+JVLine.getGL_Journal_ID());
assetadd.setGL_JournalBatch_ID(JVLine.getGL_Journal_ID());
assetadd.setLine(JVLine.getLine());
assetadd.setDescription(JVLine.getDescription());
assetadd.setPostingType(assetwk.getPostingType());
assetadd.saveEx();
}
else
{
sql2 ="SELECT * FROM A_Depreciation_Workfile WHERE A_Asset_ID = ? and PostingType = ?";
PreparedStatement pstmt2 = null;
pstmt2 = DB.prepareStatement(sql2,get_TrxName());
ResultSet rs3 = null;
log.info("no");
try {
pstmt2.setInt(1, asset.getA_Asset_ID());
pstmt2.setString(2, assetgrpacct.getPostingType());
rs3 = pstmt2.executeQuery();
while (rs3.next()){
X_A_Depreciation_Workfile assetwk = new X_A_Depreciation_Workfile (getCtx(), rs3, get_TrxName());
assetwk.setA_Asset_ID(asset.getA_Asset_ID());
assetwk.setA_Life_Period(assetgrpacct.getUseLifeMonths());
assetwk.setA_Asset_Life_Years(assetgrpacct.getUseLifeYears());
assetwk.setA_Asset_Cost(assetwk.getA_Asset_Cost().add(JVLine.getAmtAcctDr().subtract(JVLine.getAmtAcctCr())));
assetwk.setA_QTY_Current(assetwk.getA_QTY_Current().add(JVLine.getQty()));
assetwk.setIsDepreciated(assetgrpacct.isProcessing());
assetwk.saveEx();
X_A_Asset_Addition assetadd = new X_A_Asset_Addition (getCtx(), 0, get_TrxName());
assetadd.setA_Asset_ID(asset.getA_Asset_ID());
assetadd.setAssetValueAmt((JVLine.getAmtAcctDr().subtract(JVLine.getAmtAcctCr())));
assetadd.setA_SourceType("JRN");
assetadd.setA_CapvsExp("Cap");
assetadd.setA_QTY_Current(JVLine.getQty());
assetadd.setDocumentNo(""+JVLine.getGL_Journal_ID());
assetadd.setGL_JournalBatch_ID(JVLine.getGL_Journal_ID());
assetadd.setLine(JVLine.getLine());
assetadd.setDescription(JVLine.getDescription());
assetadd.setPostingType(assetwk.getPostingType());
assetadd.saveEx();
asset.setA_QTY_Original(assetadd.getA_QTY_Current().add(asset.getA_QTY_Original()));
asset.setA_QTY_Current(assetadd.getA_QTY_Current().add(asset.getA_QTY_Current()));
asset.saveEx();
MAssetChange change = new MAssetChange (getCtx(), 0, get_TrxName());
change.setA_Asset_ID(asset.getA_Asset_ID());
change.setChangeType("ADD");
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "ADD"));
change.setPostingType(assetwk.getPostingType());
change.setAssetValueAmt(assetadd.getAssetValueAmt());
change.setA_QTY_Current(assetadd.getA_QTY_Current());
change.saveEx();
}
}
catch (Exception e)
{
log.info("getAssets "+ e);
}
finally
{
DB.close(rs3, pstmt2);
rs3 = null; pstmt2 = null;
}
}
}
}
}
else if (acctType.equals("E"))
{
X_A_Asset_Addition assetadd = new X_A_Asset_Addition (getCtx(), 0, get_TrxName());
assetadd.setA_Asset_ID(asset.getA_Asset_ID());
assetadd.setAssetValueAmt((JVLine.getAmtAcctDr().subtract(JVLine.getAmtAcctCr())));
assetadd.setA_SourceType("JRN");
assetadd.setA_CapvsExp("Exp");
assetadd.setA_QTY_Current(JVLine.getQty());
assetadd.setDocumentNo(""+JVLine.getGL_Journal_ID());
assetadd.setGL_JournalBatch_ID(JVLine.getGL_Journal_ID());
assetadd.setLine(JVLine.getLine());
assetadd.setDescription(JVLine.getDescription());
assetadd.setPostingType("A");
assetadd.saveEx();
MAssetChange change = new MAssetChange (getCtx(), 0, get_TrxName());
change.setA_Asset_ID(asset.getA_Asset_ID());
change.setA_QTY_Current(assetadd.getA_QTY_Current());
change.setChangeType("EXP");
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "EXP"));
assetadd.setPostingType("A");
change.setAssetValueAmt(assetadd.getAssetValueAmt());
change.setA_QTY_Current(assetadd.getA_QTY_Current());
change.saveEx();
}
JVLine.set_ValueOfColumn(I_CustomColumn.A_Processed, Boolean.TRUE);
JVLine.saveEx();
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.info("getAssets "+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
} // doIt
} // CreateGLAsset

View File

@ -1,648 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2004 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import org.compiere.model.MAssetAcct;
import org.compiere.model.MAssetChange;
import org.compiere.model.MRefList;
import org.compiere.model.X_A_Asset;
import org.compiere.model.X_A_Asset_Addition;
import org.compiere.model.X_A_Asset_Group_Acct;
import org.compiere.model.X_A_Depreciation_Exp;
import org.compiere.model.X_A_Depreciation_Workfile;
import org.compiere.model.X_C_BPartner;
import org.compiere.model.X_C_Invoice;
import org.compiere.model.X_C_InvoiceLine;
import org.compiere.model.X_M_Product;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Create Asset from Invoice Process
*
* @author Rob Klein
*
*/
public class CreateInvoicedAsset extends SvrProcess
{
private int p_client = 0;
//private int p_org = 0;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (para[i].getParameter() == null)
;
else if (name.equals("AD_Client_ID"))
p_client = para[i].getParameterAsInt();
else
log.info("prepare - Unknown Parameter: " + name);
}
} // prepare
/**
* Process Invoices
* @return info
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("Starting inbound invoice process");
int uselifemonths = 0;
int uselifeyears = 0;
int C_Period_ID=0;
int invoiceAcct=0;
//Yvonne: add in recordInsertedCount
int recordInsertedCount = 0;
//Yvonne: changed A_Processed is null to A_Processed='N'
String sql =" SELECT * FROM C_InvoiceLine WHERE A_Processed='N' and AD_Client_ID = ?"
+ " and A_CreateAsset = 'Y' and Processed = 'Y'";
log.info("sql"+sql+p_client);
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement(sql,get_TrxName());
ResultSet rs = null;
try {
pstmt.setInt(1, p_client);
rs = pstmt.executeQuery();
int i=0;
while (rs.next()){
i=i+1;
log.info("here is the counter "+i);
X_A_Asset asset = new X_A_Asset (getCtx(), rs.getInt("A_Asset_ID"), get_TrxName());
X_C_Invoice Invoice = new X_C_Invoice (getCtx(), rs.getInt("C_Invoice_ID"), get_TrxName());
X_C_InvoiceLine InvoiceLine = new X_C_InvoiceLine (getCtx(), rs, get_TrxName());
X_M_Product product = new X_M_Product (getCtx(), InvoiceLine.getM_Product_ID(), get_TrxName());
//X_M_Product_Category productcat = new X_M_Product_Category (getCtx(), product.getM_Product_Category_ID(), get_TrxName());
//X_A_Asset_Addition assetadd = new X_A_Asset_Addition (getCtx(), 0);
X_C_BPartner business = new X_C_BPartner (getCtx(), Invoice.getC_BPartner_ID(), get_TrxName());
if (rs.getString("A_CapvsExp").equals("Cap")){
String sqla ="SELECT * FROM A_Asset_Group_Acct WHERE A_Asset_Group_ID = ? AND IsActive='Y'";
PreparedStatement pstmt1 = null;
pstmt1 = DB.prepareStatement(sqla,get_TrxName());
if(asset.getA_Asset_ID()==0) {
int groupId = InvoiceLine.getA_Asset_Group_ID();
pstmt1.setInt(1, groupId);
} else
pstmt1.setInt(1, asset.getA_Asset_Group_ID());
ResultSet rs2 = pstmt1.executeQuery();
while (rs2.next()){
X_A_Asset_Group_Acct assetgrpacct = new X_A_Asset_Group_Acct (getCtx(), rs2,get_TrxName());
MAssetAcct assetacct = new MAssetAcct (getCtx(), 0, get_TrxName());
if (assetgrpacct.isProcessing()== true){
String sql2 = "SELECT COUNT(*) FROM A_Depreciation_Workfile WHERE A_Asset_ID=? and"
+ " PostingType = '"+assetgrpacct.getPostingType()+"'";
if (DB.getSQLValue(get_TrxName(),sql2, asset.getA_Asset_ID())== 0)
{
asset.setIsOwned(true);
asset.setIsDepreciated(assetgrpacct.isProcessing());
asset.setA_Asset_CreateDate(Invoice.getDateInvoiced());
asset.setIsInPosession(true);
if (InvoiceLine.getM_Product_ID()>0)
asset.setName(product.getName()+"-"+business.getName()+"-"+Invoice.getDocumentNo());
else
asset.setName(business.getName()+"-"+Invoice.getDocumentNo());
asset.setHelp("Created from Invoice #" + rs.getInt("C_Invoice_ID") + " on line #" + InvoiceLine.getLine());
asset.setDescription(InvoiceLine.getDescription());
asset.setUseLifeMonths(assetgrpacct.getUseLifeMonths());
asset.setUseLifeYears(assetgrpacct.getUseLifeYears());
asset.setA_Asset_Group_ID(assetgrpacct.getA_Asset_Group_ID());
asset.setA_QTY_Current(InvoiceLine.getQtyEntered());
asset.setA_QTY_Original(InvoiceLine.getQtyEntered());
asset.saveEx();
asset.setA_Parent_Asset_ID(asset.getA_Asset_ID());
asset.saveEx();
boolean isdepreciate = assetgrpacct.isProcessing();
if (isdepreciate == true)
{
assetacct.setPostingType(assetgrpacct.getPostingType());
assetacct.setA_Split_Percent(assetgrpacct.getA_Split_Percent());
assetacct.setA_Depreciation_Conv_ID(assetgrpacct.getConventionType());
assetacct.setA_Asset_ID(asset.getA_Asset_ID());
assetacct.setA_Depreciation_ID(assetgrpacct.getDepreciationType());
assetacct.setA_Asset_Spread_ID(assetgrpacct.getA_Asset_Spread_Type());
assetacct.setA_Period_Start(1);
if (asset.getUseLifeMonths() == 0 & asset.getUseLifeYears() == 0){
assetacct.setA_Period_End(assetgrpacct.getUseLifeMonths());
asset.setUseLifeYears(assetgrpacct.getUseLifeYears());
asset.setUseLifeMonths(assetgrpacct.getUseLifeMonths());
asset.setIsDepreciated(true);
asset.setIsOwned(true);
asset.saveEx();
uselifemonths = assetgrpacct.getUseLifeMonths();
uselifeyears = assetgrpacct.getUseLifeYears();
}
else if(asset.getUseLifeMonths() == 0){
assetacct.setA_Period_End(asset.getUseLifeYears()*12);
asset.setUseLifeMonths(asset.getUseLifeYears()*12);
asset.setIsDepreciated(true);
asset.setIsOwned(true);
asset.saveEx();
uselifemonths = asset.getUseLifeYears()*12;
uselifeyears = asset.getUseLifeYears();
}
else{
assetacct.setA_Period_End(asset.getUseLifeMonths());
uselifemonths = asset.getUseLifeMonths();
uselifeyears = asset.getUseLifeYears();}
assetacct.setA_Depreciation_Method_ID(assetgrpacct.getA_Depreciation_Calc_Type());
assetacct.setA_Asset_Acct(assetgrpacct.getA_Asset_Acct());
assetacct.setC_AcctSchema_ID(assetgrpacct.getC_AcctSchema_ID());
assetacct.setA_Accumdepreciation_Acct(assetgrpacct.getA_Accumdepreciation_Acct());
assetacct.setA_Depreciation_Acct(assetgrpacct.getA_Depreciation_Acct());
assetacct.setA_Disposal_Revenue(assetgrpacct.getA_Disposal_Revenue());
assetacct.setA_Disposal_Loss(assetgrpacct.getA_Disposal_Loss());
assetacct.setA_Salvage_Value(new BigDecimal(0.0));
assetacct.setA_Reval_Accumdep_Offset_Cur(assetgrpacct.getA_Reval_Accumdep_Offset_Cur());
assetacct.setA_Reval_Accumdep_Offset_Prior(assetgrpacct.getA_Reval_Accumdep_Offset_Prior());
assetacct.setA_Reval_Cal_Method(assetgrpacct.getA_Reval_Cal_Method());
assetacct.setA_Reval_Cost_Offset(assetgrpacct.getA_Reval_Cost_Offset());
assetacct.setA_Reval_Cost_Offset_Prior(assetgrpacct.getA_Reval_Cost_Offset_Prior());
assetacct.setA_Reval_Depexp_Offset(assetgrpacct.getA_Reval_Depexp_Offset());
assetacct.setA_Depreciation_Manual_Amount(assetgrpacct.getA_Depreciation_Manual_Amount());
assetacct.setA_Depreciation_Manual_Period(assetgrpacct.getA_Depreciation_Manual_Period());
assetacct.setA_Depreciation_Table_Header_ID(assetgrpacct.getA_Depreciation_Table_Header_ID());
assetacct.setA_Depreciation_Variable_Perc(assetgrpacct.getA_Depreciation_Variable_Perc());
assetacct.setProcessing(false);
assetacct.getAD_Client_ID();
assetacct.saveEx();
MAssetChange change = new MAssetChange (getCtx(), 0, get_TrxName());
change.setPostingType(assetacct.getPostingType());
change.setA_Split_Percent(assetacct.getA_Split_Percent());
change.setConventionType(assetacct.getA_Depreciation_Conv_ID());
change.setA_Asset_ID(asset.getA_Asset_ID());
change.setDepreciationType(assetacct.getA_Depreciation_ID());
change.setA_Asset_Spread_Type(assetacct.getA_Asset_Spread_ID());
change.setA_Period_Start(assetacct.getA_Period_Start());
change.setA_Period_End(assetacct.getA_Period_End());
change.setIsInPosession(asset.isOwned());
change.setIsDisposed(asset.isDisposed());
change.setIsDepreciated(asset.isDepreciated());
change.setIsFullyDepreciated(asset.isFullyDepreciated());
change.setA_Depreciation_Calc_Type(assetacct.getA_Depreciation_Method_ID());
change.setA_Asset_Acct(assetacct.getA_Asset_Acct());
change.setC_AcctSchema_ID(assetacct.getC_AcctSchema_ID());
change.setA_Accumdepreciation_Acct(assetacct.getA_Accumdepreciation_Acct());
change.setA_Depreciation_Acct(assetacct.getA_Depreciation_Acct());
change.setA_Disposal_Revenue(assetacct.getA_Disposal_Revenue());
change.setA_Disposal_Loss(assetacct.getA_Disposal_Loss());
change.setA_Reval_Accumdep_Offset_Cur(assetacct.getA_Reval_Accumdep_Offset_Cur());
change.setA_Reval_Accumdep_Offset_Prior(assetacct.getA_Reval_Accumdep_Offset_Prior());
change.setA_Reval_Cal_Method(assetacct.getA_Reval_Cal_Method());
change.setA_Reval_Cost_Offset(assetacct.getA_Reval_Cost_Offset());
change.setA_Reval_Cost_Offset_Prior(assetacct.getA_Reval_Cost_Offset_Prior());
change.setA_Reval_Depexp_Offset(assetacct.getA_Reval_Depexp_Offset());
change.setA_Depreciation_Manual_Amount(assetacct.getA_Depreciation_Manual_Amount());
change.setA_Depreciation_Manual_Period(assetacct.getA_Depreciation_Manual_Period());
change.setA_Depreciation_Table_Header_ID(assetacct.getA_Depreciation_Table_Header_ID());
change.setA_Depreciation_Variable_Perc(assetacct.getA_Depreciation_Variable_Perc());
change.setA_Parent_Asset_ID(asset.getA_Parent_Asset_ID());
change.setChangeType("CRT");
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "CRT"));
change.setIsInPosession(asset.isOwned());
change.setIsDisposed(asset.isDisposed());
change.setIsDepreciated(asset.isDepreciated());
change.setIsFullyDepreciated(asset.isFullyDepreciated());
change.setLot(asset.getLot());
change.setSerNo(asset.getSerNo());
change.setVersionNo(asset.getVersionNo());
change.setUseLifeMonths(asset.getUseLifeMonths());
change.setUseLifeYears(asset.getUseLifeYears());
change.setLifeUseUnits(asset.getLifeUseUnits());
change.setAssetDisposalDate(asset.getAssetDisposalDate());
change.setAssetServiceDate(asset.getAssetServiceDate());
change.setC_BPartner_Location_ID(asset.getC_BPartner_Location_ID());
change.setC_BPartner_ID(asset.getC_BPartner_ID());
change.setAssetValueAmt(InvoiceLine.getLineTotalAmt());
change.setA_QTY_Current(InvoiceLine.getQtyEntered());
change.setA_QTY_Original(InvoiceLine.getQtyEntered());
change.setA_Asset_CreateDate(asset.getA_Asset_CreateDate());
change.setAD_User_ID(asset.getAD_User_ID());
change.setC_Location_ID(asset.getC_Location_ID());
change.saveEx();
}
X_A_Depreciation_Workfile assetwk = new X_A_Depreciation_Workfile (getCtx(), 0, get_TrxName());
assetwk.setA_Asset_ID(asset.getA_Asset_ID());
assetwk.setA_Life_Period(assetgrpacct.getUseLifeMonths());
assetwk.setA_Asset_Life_Years(assetgrpacct.getUseLifeYears());
assetwk.setA_Asset_Cost(assetwk.getA_Asset_Cost().add(InvoiceLine.getLineTotalAmt()));
assetwk.setA_QTY_Current(InvoiceLine.getQtyEntered());
assetwk.setIsDepreciated(assetgrpacct.isProcessing());
assetwk.setPostingType(assetgrpacct.getPostingType());
assetwk.setA_Accumulated_Depr(new BigDecimal (0.0));
assetwk.setA_Period_Posted(0);
assetwk.setA_Asset_Life_Current_Year(new BigDecimal (0.0));
assetwk.setA_Curr_Dep_Exp(new BigDecimal (0.0));
assetwk.saveEx();
X_A_Asset_Addition assetadd = new X_A_Asset_Addition (getCtx(), 0, get_TrxName());
assetadd.setA_Asset_ID(asset.getA_Asset_ID());
assetadd.setAssetValueAmt(InvoiceLine.getLineTotalAmt());
assetadd.setA_SourceType("INV");
assetadd.setA_CapvsExp("Cap");
assetadd.setM_InOutLine_ID(rs.getInt("C_Invoice_ID"));
assetadd.setC_Invoice_ID(rs.getInt("C_Invoice_ID"));
assetadd.setDocumentNo(Invoice.getDocumentNo());
assetadd.setLine(InvoiceLine.getLine());
assetadd.setDescription(InvoiceLine.getDescription());
assetadd.setA_QTY_Current(InvoiceLine.getQtyEntered());
assetadd.setPostingType(assetwk.getPostingType());
assetadd.saveEx();
String sql1 = "SELECT C_Period_ID "
+ "FROM C_Period "
+ "WHERE C_Year_ID IN "
+ " (SELECT C_Year_ID FROM C_Year WHERE C_Calendar_ID ="
+ " (SELECT C_Calendar_ID FROM AD_ClientInfo WHERE AD_Client_ID=?))"
+ " AND ? BETWEEN StartDate AND EndDate"
+ " AND PeriodType='S'";
try
{
PreparedStatement pstmt4 = DB.prepareStatement(sql1,get_TrxName());
pstmt4.setInt(1, asset.getAD_Client_ID());
pstmt4.setTimestamp(2, Invoice.getDateAcct());
ResultSet rs4 = pstmt4.executeQuery();
if (rs4.next())
C_Period_ID = rs4.getInt(1);
DB.close(rs4, pstmt4);
pstmt4 = null;
}
catch (SQLException e)
{
log.log(Level.SEVERE, "Journal_Period - DateAcct", e);
return e.getLocalizedMessage();
}
/**Code below is for future functionality
int DocumentNo = MSequence.getNextID (Env.getAD_Client_ID(Env.getCtx()), "DocumentNo_M_InOut", get_TrxName());
//Adjust Inventory Quantity
X_M_InOut mInOut = new X_M_InOut (getCtx(), 0, get_TrxName());
mInOut.setC_BPartner_ID (Invoice.getC_BPartner_ID());
mInOut.setC_BPartner_Location_ID (Invoice.getC_BPartner_Location_ID());
mInOut.setC_DocType_ID (Invoice.getC_DocType_ID());
mInOut.setDateAcct (new Timestamp(System.currentTimeMillis())); // @#Date@
mInOut.setDeliveryRule ("A"); // A
mInOut.setDeliveryViaRule ("P"); // P
mInOut.setDocAction ("CO"); // CO
mInOut.setDocStatus ("DR"); // DR
mInOut.setDescription("Invoice transfered to assets");
mInOut.setDocumentNo (""+DocumentNo);
mInOut.setFreightCostRule ("I"); // I
mInOut.setPriorityRule("5");
mInOut.setIsApproved (false);
mInOut.setIsInDispute (false);
mInOut.setIsInTransit (false);
mInOut.setIsPrinted (false);
mInOut.setIsSOTrx (false); // @IsSOTrx@
mInOut.setM_InOut_ID (0);
mInOut.setM_Warehouse_ID (0);
mInOut.setMovementDate (new Timestamp(System.currentTimeMillis())); // @#Date@
mInOut.setMovementType ("V-");
mInOut.setPosted (false);
mInOut.setProcessed (false);
mInOut.setSendEMail (false);
mInOut.saveEx();
X_M_InOutLine mInOutLine = new X_M_InOutLine (getCtx(), 0, get_TrxName());
mInOutLine.setC_UOM_ID (InvoiceLine.getC_UOM_ID()); // @#C_UOM_ID@
mInOutLine.setIsDescription (false); // N
mInOutLine.setIsInvoiced (false);
mInOutLine.setLine (10); // @SQL=SELECT NVL(MAX(Line),0)+10 AS DefaultValue FROM M_InOutLine WHERE M_InOut_ID=@M_InOut_ID@
mInOutLine.setM_AttributeSetInstance_ID (InvoiceLine.getM_AttributeSetInstance_ID());
mInOutLine.setM_InOut_ID (mInOut.getM_InOut_ID());
mInOutLine.setM_Locator_ID (0); // @M_Locator_ID@
mInOutLine.setM_Product_ID (InvoiceLine.getM_Product_ID());
mInOutLine.setMovementQty (InvoiceLine.getQtyInvoiced()); // 1
mInOutLine.setProcessed (false);
mInOutLine.setQtyEntered (Env.ZERO); // 1
**/
//Determine non tax accounts to credit
invoiceAcct = determineAcct (assetacct.getC_AcctSchema_ID(), InvoiceLine.getM_Product_ID(), InvoiceLine.getC_Charge_ID(), InvoiceLine.getLineNetAmt());
//Create Journal Entries for the new asset
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, get_TrxName());
depexp2.setPostingType(assetacct.getPostingType());
depexp2.setA_Asset_ID(asset.getA_Asset_ID());
depexp2.setExpense(InvoiceLine.getLineTotalAmt());
depexp2.setDateAcct(Invoice.getDateAcct());
depexp2.setA_Account_Number(assetacct.getA_Asset_Acct());
depexp2.setDescription("Create Asset from Invoice");
depexp2.setIsDepreciated(false);
depexp2.setA_Period(C_Period_ID);
depexp2.setA_Entry_Type("NEW");
depexp2.saveEx();
recordInsertedCount++;
X_A_Depreciation_Exp depexp3 = new X_A_Depreciation_Exp (getCtx(), 0, get_TrxName());
depexp3.setPostingType(assetacct.getPostingType());
depexp3.setA_Asset_ID(asset.getA_Asset_ID());
depexp3.setExpense(InvoiceLine.getLineNetAmt().multiply(new BigDecimal (-1)));
depexp3.setDateAcct(Invoice.getDateAcct());
depexp3.setA_Account_Number(invoiceAcct);
depexp3.setDescription("Create Asset from Invoice");
depexp3.setIsDepreciated(false);
depexp3.setA_Period(C_Period_ID);
depexp3.setA_Entry_Type("NEW");
depexp3.saveEx();
recordInsertedCount++;
//Determine if tax adjustment is necessary
if (InvoiceLine.getTaxAmt().compareTo(new BigDecimal (0))!=0){
invoiceAcct = determineTaxAcct (assetacct.getC_AcctSchema_ID(), InvoiceLine.getC_Tax_ID());
X_A_Depreciation_Exp depexp4 = new X_A_Depreciation_Exp (getCtx(), 0, get_TrxName());
depexp4.setPostingType(assetacct.getPostingType());
depexp4.setA_Asset_ID(asset.getA_Asset_ID());
depexp4.setExpense(InvoiceLine.getTaxAmt().multiply(new BigDecimal (-1)));
depexp4.setDateAcct(Invoice.getDateAcct());
depexp4.setA_Account_Number(invoiceAcct);
depexp4.setDescription("Create Asset from Invoice");
depexp4.setIsDepreciated(false);
depexp4.setA_Period(C_Period_ID);
depexp4.setA_Entry_Type("NEW");
depexp4.saveEx();
recordInsertedCount++;
}
}
else
{
sql2 ="SELECT * FROM A_Depreciation_Workfile WHERE A_Asset_ID = ? and PostingType = ?";
PreparedStatement pstmt2 = null;
pstmt2 = DB.prepareStatement(sql2,get_TrxName());
ResultSet rs3 = null;
try {
pstmt2.setInt(1, asset.getA_Asset_ID());
pstmt2.setString(2, assetgrpacct.getPostingType());
rs3 = pstmt2.executeQuery();
while (rs3.next()){
X_A_Depreciation_Workfile assetwk = new X_A_Depreciation_Workfile (getCtx(), rs3, get_TrxName());
assetwk.setA_Asset_ID(asset.getA_Asset_ID());
assetwk.setA_Life_Period(assetgrpacct.getUseLifeMonths());
assetwk.setA_Asset_Life_Years(assetgrpacct.getUseLifeYears());
assetwk.setA_Asset_Cost(assetwk.getA_Asset_Cost().add(InvoiceLine.getLineTotalAmt()));
assetwk.setIsDepreciated(assetgrpacct.isProcessing());
assetwk.setA_QTY_Current(InvoiceLine.getQtyEntered());
assetwk.saveEx();
X_A_Asset_Addition assetadd = new X_A_Asset_Addition (getCtx(), 0, get_TrxName());
assetadd.setA_Asset_ID(asset.getA_Asset_ID());
assetadd.setAssetValueAmt(InvoiceLine.getLineTotalAmt());
assetadd.setA_SourceType("INV");
assetadd.setA_CapvsExp("Cap");
assetadd.setM_InOutLine_ID(rs.getInt("C_Invoice_ID"));
assetadd.setC_Invoice_ID(rs.getInt("C_Invoice_ID"));
assetadd.setDocumentNo(Invoice.getDocumentNo());
assetadd.setLine(InvoiceLine.getLine());
assetadd.setDescription(InvoiceLine.getDescription());
assetadd.setA_QTY_Current(InvoiceLine.getQtyEntered());
assetadd.setPostingType(assetwk.getPostingType());
assetadd.saveEx();
asset.setA_QTY_Original(assetadd.getA_QTY_Current().add(asset.getA_QTY_Original()));
asset.setA_QTY_Current(assetadd.getA_QTY_Current().add(asset.getA_QTY_Current()));
asset.saveEx();
MAssetChange change = new MAssetChange (getCtx(), 0, get_TrxName());
change.setA_Asset_ID(asset.getA_Asset_ID());
change.setA_QTY_Current(assetadd.getA_QTY_Current());
change.setChangeType("ADD");
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "ADD"));
change.setPostingType(assetwk.getPostingType());
change.setAssetValueAmt(assetadd.getAssetValueAmt());
change.setA_QTY_Current(assetadd.getA_QTY_Current());
change.saveEx();
//Determine non tax accounts to credit
invoiceAcct = determineAcct (assetacct.getC_AcctSchema_ID(), InvoiceLine.getM_Product_ID(), InvoiceLine.getC_Charge_ID(), InvoiceLine.getLineNetAmt());
//Create Journal Entries for the new asset
X_A_Depreciation_Exp depexp2 = new X_A_Depreciation_Exp (getCtx(), 0, get_TrxName());
depexp2.setPostingType(assetacct.getPostingType());
depexp2.setA_Asset_ID(asset.getA_Asset_ID());
depexp2.setExpense(InvoiceLine.getLineTotalAmt());
depexp2.setDateAcct(Invoice.getDateAcct());
depexp2.setA_Account_Number(assetacct.getA_Asset_Acct());
depexp2.setDescription("Create Asset from Invoice");
depexp2.setIsDepreciated(false);
depexp2.setA_Period(C_Period_ID);
depexp2.setA_Entry_Type("NEW");
depexp2.saveEx();
recordInsertedCount++;
X_A_Depreciation_Exp depexp3 = new X_A_Depreciation_Exp (getCtx(), 0, get_TrxName());
depexp3.setPostingType(assetacct.getPostingType());
depexp3.setA_Asset_ID(asset.getA_Asset_ID());
depexp3.setExpense(InvoiceLine.getLineNetAmt().multiply(new BigDecimal (-1)));
depexp3.setDateAcct(Invoice.getDateAcct());
depexp3.setA_Account_Number(invoiceAcct);
depexp3.setDescription("Create Asset from Invoice");
depexp3.setIsDepreciated(false);
depexp3.setA_Period(C_Period_ID);
depexp3.setA_Entry_Type("NEW");
depexp3.saveEx();
recordInsertedCount++;
//Determine if tax adjustment is necessary
if (InvoiceLine.getTaxAmt().compareTo(new BigDecimal (0))!=0){
invoiceAcct = determineTaxAcct (assetacct.getC_AcctSchema_ID(), InvoiceLine.getC_Tax_ID());
X_A_Depreciation_Exp depexp4 = new X_A_Depreciation_Exp (getCtx(), 0, get_TrxName());
depexp4.setPostingType(assetacct.getPostingType());
depexp4.setA_Asset_ID(asset.getA_Asset_ID());
depexp4.setExpense(InvoiceLine.getTaxAmt().multiply(new BigDecimal (-1)));
depexp4.setDateAcct(Invoice.getDateAcct());
depexp4.setA_Account_Number(invoiceAcct);
depexp4.setDescription("Create Asset from Invoice");
depexp4.setIsDepreciated(false);
depexp4.setA_Period(C_Period_ID);
depexp4.setA_Entry_Type("NEW");
depexp4.saveEx();
recordInsertedCount++;
}
}
}
catch (Exception e)
{
log.info("getAssets "+ e);
}
finally
{
DB.close(rs3, pstmt2);
pstmt2 = null;
}
}
}
}
DB.close(rs2, pstmt1);
pstmt1 = null;
}
else if (rs.getString("A_CapvsExp").equals("Exp"))
{
X_A_Asset_Addition assetadd = new X_A_Asset_Addition (getCtx(), 0, get_TrxName());
assetadd.setA_Asset_ID(asset.getA_Asset_ID());
assetadd.setAssetValueAmt(InvoiceLine.getLineTotalAmt());
assetadd.setA_SourceType("INV");
assetadd.setA_CapvsExp("Exp");
assetadd.setM_InOutLine_ID(rs.getInt("C_Invoice_ID"));
assetadd.setC_Invoice_ID(rs.getInt("C_Invoice_ID"));
assetadd.setDocumentNo(Invoice.getDocumentNo());
assetadd.setLine(InvoiceLine.getLine());
assetadd.setDescription(InvoiceLine.getDescription());
assetadd.setA_QTY_Current(InvoiceLine.getQtyEntered());
assetadd.setPostingType("A");
assetadd.saveEx();
MAssetChange change = new MAssetChange (getCtx(), 0, get_TrxName());
change.setA_Asset_ID(asset.getA_Asset_ID());
change.setA_QTY_Current(assetadd.getA_QTY_Current());
change.setChangeType("EXP");
change.setTextDetails(MRefList.getListDescription (getCtx(),"A_Update_Type" , "EXP"));
assetadd.setPostingType("A");
change.setAssetValueAmt(assetadd.getAssetValueAmt());
change.setA_QTY_Current(assetadd.getA_QTY_Current());
change.saveEx();
}
InvoiceLine.set_ValueOfColumn(I_CustomColumn.A_Processed, Boolean.TRUE);
InvoiceLine.saveEx();
}
}
catch (Exception e)
{
log.info("getAssets "+ e);
}
finally
{
DB.close(rs, pstmt);
pstmt = null;
}
if (recordInsertedCount > 0)
{
return recordInsertedCount + " record(s) inserted.";
}
else
{
return "Zero record inserted.";
}
} // doIt
/**
* Get non tax posting accounts for invoice.
*
*
*/
private int determineAcct (int C_AcctSchema_ID, int M_Product_ID, int C_Charge_ID, BigDecimal lineAmt)
{
int invoiceAcct =0;
if (M_Product_ID == 0 && C_Charge_ID != 0)
{
String sqlb = "SELECT CH_Expense_Acct FROM C_Charge_Acct WHERE C_Charge_ID=? and C_AcctSchema_ID=?";
invoiceAcct = DB.getSQLValue(get_TrxName(),sqlb,C_Charge_ID,C_AcctSchema_ID);
}
else if(M_Product_ID != 0){
if(lineAmt.signum() > 0){
String sqlb = "SELECT P_Expense_Acct FROM M_Product_Acct WHERE M_Product_ID=? and C_AcctSchema_ID=?";
invoiceAcct = DB.getSQLValue(get_TrxName(),sqlb,M_Product_ID,C_AcctSchema_ID);
}
else{
String sqlb = "SELECT P_Revenue_Acct FROM M_Product_Acct WHERE M_Product_ID=? and C_AcctSchema_ID=?";
invoiceAcct = DB.getSQLValue(get_TrxName(),sqlb,M_Product_ID,C_AcctSchema_ID);
}
}
else{
if(lineAmt.signum() > 0){
String sqlb = "SELECT P_Expense_Acct "
+ "FROM M_Product_Category pc, M_Product_Category_Acct pca "
+ "WHERE pc.M_Product_Category_ID=pca.M_Product_Category_ID"
+ " AND pca.C_AcctSchema_ID=? "
+ "ORDER BY pc.IsDefault DESC, pc.Created";
invoiceAcct = DB.getSQLValue(get_TrxName(),sqlb,C_AcctSchema_ID);
}
else{
String sqlb = "SELECT P_Revenue_Acct "
+ "FROM M_Product_Category pc, M_Product_Category_Acct pca "
+ "WHERE pc.M_Product_Category_ID=pca.M_Product_Category_ID"
+ " AND pca.C_AcctSchema_ID=? "
+ "ORDER BY pc.IsDefault DESC, pc.Created";
invoiceAcct = DB.getSQLValue(get_TrxName(),sqlb,C_AcctSchema_ID);
}
}
return invoiceAcct;
}
/**
* Get tax posting accounts for invoice.
*
*
*/
private int determineTaxAcct (int C_AcctSchema_ID, int C_Tax_ID)
{
int invoiceAcct =0;
String sqlb = "SELECT T_Expense_Acct FROM C_Tax_Acct WHERE C_AcctSchema_ID=? and C_Tax_ID=?";
invoiceAcct = DB.getSQLValue(get_TrxName(),sqlb,C_AcctSchema_ID,C_Tax_ID);
return invoiceAcct;
}
} // InvoiceCreateInOut

View File

@ -1,918 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* _____________________________________________
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.compiere.util.DB;
/**
* Fixed Asset Depreciation
*
* @author Rob Klein
* @version $Id: Conventions.java,v 1.0 $
*
*/
public class Depreciation {
/**
*
*
*/
static public BigDecimal Dep_Type(String Type,int p_A_ASSET_ID, double p_A_CURRENT_PERIOD, String p_POSTINGTYPE,
int p_A_ASSET_ACCT_ID, BigDecimal p_Accum_Dep)
{
BigDecimal A_Period_Exp = new BigDecimal(0.0);
if(Type.compareTo("DB150")==0){
A_Period_Exp = DB150( 0, p_A_ASSET_ID, p_A_CURRENT_PERIOD, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Accum_Dep);
//System.out.println("DB150 Main: "+A_Period_Exp);
return A_Period_Exp;
}
else if(Type.compareTo("DB1SL")==0){
A_Period_Exp = DB150( 1, p_A_ASSET_ID, p_A_CURRENT_PERIOD, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Accum_Dep);
//System.out.println("DB1SL Main: "+A_Period_Exp);
return A_Period_Exp;
}
else if(Type.compareTo("DB200")==0){
A_Period_Exp = DB200( 0, p_A_ASSET_ID, p_A_CURRENT_PERIOD, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Accum_Dep);
//System.out.println("DB200 Main: "+A_Period_Exp);
return A_Period_Exp;
}
else if(Type.compareTo("DB2SL")==0){
A_Period_Exp = DB200( 1, p_A_ASSET_ID, p_A_CURRENT_PERIOD, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Accum_Dep);
//System.out.println("DB2SL Main: "+A_Period_Exp);
return A_Period_Exp;
}
else if(Type.compareTo("VAR")==0){
A_Period_Exp = DBVAR( 0, p_A_ASSET_ID, p_A_CURRENT_PERIOD, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Accum_Dep);
//System.out.println("VAR Main: "+A_Period_Exp);
return A_Period_Exp;
}
else if(Type.compareTo("VARSL")==0){
A_Period_Exp = DBVAR( 1, p_A_ASSET_ID, p_A_CURRENT_PERIOD, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Accum_Dep);
//System.out.println("VARSL Main: "+A_Period_Exp);
return A_Period_Exp;
}
else if(Type.compareTo("MAN")==0){
A_Period_Exp = MAN( 1, p_A_ASSET_ID, p_A_CURRENT_PERIOD, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Accum_Dep);
//System.out.println("MAN Main: "+A_Period_Exp);
return A_Period_Exp;
}
else if(Type.compareTo("SL")==0){
A_Period_Exp = SL( 1, p_A_ASSET_ID, p_A_CURRENT_PERIOD, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Accum_Dep);
//System.out.println("SL Main: "+A_Period_Exp);
return A_Period_Exp;
}
else if(Type.compareTo("SYD")==0){
A_Period_Exp = SYD( 1, p_A_ASSET_ID, p_A_CURRENT_PERIOD, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Accum_Dep);
//System.out.println("SYD Main: "+A_Period_Exp);
return A_Period_Exp;
}
else if(Type.compareTo("TAB")==0){
A_Period_Exp = TAB( 1, p_A_ASSET_ID, p_A_CURRENT_PERIOD, p_POSTINGTYPE, p_A_ASSET_ACCT_ID, p_Accum_Dep);
//System.out.println("TAB Main: "+A_Period_Exp);
return A_Period_Exp;
}
else
return new BigDecimal(0.0);
}
static public BigDecimal DB150(int p_SL, int p_A_ASSET_ID, double p_A_CURRENT_PERIOD, String p_POSTINGTYPE,
int p_A_ASSET_ACCT_ID, BigDecimal p_Accum_Dep)
{
BigDecimal v_DB = new BigDecimal(0.0);
BigDecimal v_Accum_Dep = new BigDecimal(0.0);
BigDecimal v_SL = new BigDecimal(0.0);
BigDecimal A_Period_Exp = new BigDecimal(0.0);
int v_counter = 0;
double v_months = 0;
int v_firstyr = 0;
double v_monthadj = 0;
BigDecimal v_adj = new BigDecimal(0.0);
BigDecimal v_Base_Amount = new BigDecimal(0.0);
BigDecimal v_Salvage_Amount = new BigDecimal(0.0);
double v_Life_Periods = 0;
double v_Life_Years = 0;
String v_con_type = null;
StringBuffer sqlB = new StringBuffer ("SELECT A.A_ASSET_COST, A.A_SALVAGE_VALUE, A.A_LIFE_PERIOD, A.A_ASSET_LIFE_YEARS, A.DATEACCT,"
+ " D.ASSETSERVICEDATE, C.CONVENTIONTYPE "
+ " FROM A_DEPRECIATION_WORKFILE A, A_ASSET_ACCT B,A_ASSET D,A_DEPRECIATION_CONVENTION C "
+ " WHERE A.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND B.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_PERIOD_POSTED+1 >= A_PERIOD_START AND A_PERIOD_POSTED+1 <= A_PERIOD_END "
+ " AND A.POSTINGTYPE = '" + p_POSTINGTYPE
+ "' AND B.POSTINGTYPE = '" + p_POSTINGTYPE
+ "' AND B.A_ASSET_ACCT_ID = " + p_A_ASSET_ACCT_ID
+ " AND D.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND B.A_DEPRECIATION_CONV_ID = C.A_DEPRECIATION_CONVENTION_ID");
//System.out.println("DB150: "+sqlB.toString());
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
int AssetServiceDateYear = calendar.get(Calendar.YEAR);
int AssetServiceDateMonth = calendar.get(Calendar.MONTH);
calendar.setTime(rs.getDate("DATEACCT"));
int DateAcctYear = calendar.get(Calendar.YEAR);
v_Base_Amount = rs.getBigDecimal("A_ASSET_COST");
v_Salvage_Amount = rs.getBigDecimal("A_SALVAGE_VALUE");
v_Life_Periods = rs.getDouble("A_LIFE_PERIOD");
v_Life_Years = rs.getDouble("A_ASSET_LIFE_YEARS");
v_con_type = rs.getString("CONVENTIONTYPE");
double v_period = DateAcctYear - AssetServiceDateYear;
while (v_counter <= v_period){
if(v_firstyr == 0){
v_DB = (v_Base_Amount.subtract(v_Accum_Dep).subtract(v_Salvage_Amount)).multiply(new BigDecimal(1.5/v_Life_Years));
v_months = 12 - AssetServiceDateMonth +1;
if (v_con_type.compareTo("HYCON") ==0){
v_adj = new BigDecimal(Conventions.HYCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj).multiply(new BigDecimal(v_months)));
v_monthadj = 6-v_months;
}
else if (v_con_type.compareTo("FYCON") ==0){
v_adj = new BigDecimal(Conventions.FYCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,0,AssetServiceDateYear));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj).multiply(new BigDecimal(v_months)));
v_monthadj = 12-v_months;
}
else if (v_con_type.compareTo("DYCON") ==0){
v_adj = new BigDecimal(Conventions.DYCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_monthadj = 0;
}
else if (v_con_type.compareTo("MQCON") ==0){
v_adj = new BigDecimal(Conventions.MQCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj));
v_DB =(v_DB.divide(new BigDecimal(v_months),2, BigDecimal.ROUND_HALF_UP));
v_monthadj = 0;
}
else if (v_con_type.compareTo("FMCON") ==0){
v_adj = new BigDecimal(Conventions.FMCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(new BigDecimal(v_months)));
v_monthadj = 0;
}
else if (v_con_type.compareTo("MMCON") ==0){
v_Accum_Dep = v_Accum_Dep.add(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(.5)).add(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(v_months-1));
v_adj = new BigDecimal(Conventions.MMCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateMonth+1));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP)).multiply(v_adj);
v_monthadj = 0;
}
v_firstyr = 1;
}
else{
v_DB = (v_Base_Amount.subtract(v_Accum_Dep).subtract(v_Salvage_Amount)).multiply(new BigDecimal(1.5/v_Life_Years));
v_Accum_Dep = v_Accum_Dep.add(v_DB);
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
}
v_counter = v_counter+1;
}
A_Period_Exp = v_DB;
if (p_SL ==1 ){
if (v_Life_Periods-(p_A_CURRENT_PERIOD+v_monthadj)>0 )
v_SL = ((v_Base_Amount.subtract(v_Salvage_Amount).subtract(p_Accum_Dep)).divide(new BigDecimal(v_Life_Periods-(p_A_CURRENT_PERIOD+v_monthadj)),2, BigDecimal.ROUND_HALF_UP));
if (A_Period_Exp.compareTo(v_SL)==-1)
A_Period_Exp = v_SL;
if (v_Base_Amount.subtract(p_Accum_Dep).subtract(A_Period_Exp).compareTo(v_Salvage_Amount)==-1 )
A_Period_Exp =v_Base_Amount.subtract(p_Accum_Dep).subtract(v_Salvage_Amount);
}
}
//System.out.println("DB150: "+A_Period_Exp);
return A_Period_Exp;
}
catch (Exception e)
{
System.out.println("DB150: "+e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return A_Period_Exp;
}
static public BigDecimal DB200(int p_SL,int p_A_ASSET_ID, double p_A_CURRENT_PERIOD, String p_POSTINGTYPE,
int p_A_ASSET_ACCT_ID, BigDecimal p_Accum_Dep)
{
BigDecimal v_DB = new BigDecimal(0.0);
BigDecimal v_Accum_Dep = new BigDecimal(0.0);
BigDecimal v_SL = new BigDecimal(0.0);
BigDecimal A_Period_Exp = new BigDecimal(0.0);
int v_counter = 0;
double v_months = 0;
int v_firstyr = 0;
double v_monthadj = 0;
BigDecimal v_adj = new BigDecimal(0.0);
BigDecimal v_Base_Amount = new BigDecimal(0.0);
BigDecimal v_Salvage_Amount = new BigDecimal(0.0);
double v_Life_Periods = 0;
double v_Life_Years = 0;
String v_con_type = null;
StringBuffer sqlB = new StringBuffer ("SELECT A.A_ASSET_COST, A.A_SALVAGE_VALUE, A.A_LIFE_PERIOD, A.A_ASSET_LIFE_YEARS, A.DATEACCT,"
+ " D.ASSETSERVICEDATE, C.CONVENTIONTYPE "
+ " FROM A_DEPRECIATION_WORKFILE A, A_ASSET_ACCT B,A_ASSET D,A_DEPRECIATION_CONVENTION C "
+ " WHERE A.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND B.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_PERIOD_POSTED+1 >= A_PERIOD_START AND A_PERIOD_POSTED+1 <= A_PERIOD_END "
+ " AND A.POSTINGTYPE = '" + p_POSTINGTYPE
+ "' AND B.POSTINGTYPE = '" + p_POSTINGTYPE
+ "' AND B.A_ASSET_ACCT_ID = " + p_A_ASSET_ACCT_ID
+ " AND D.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND B.A_DEPRECIATION_CONV_ID = C.A_DEPRECIATION_CONVENTION_ID");
//System.out.println("DB200: "+sqlB.toString());
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
while (rs.next()){
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
int AssetServiceDateYear = calendar.get(Calendar.YEAR);
int AssetServiceDateMonth = calendar.get(Calendar.MONTH);
calendar.setTime(rs.getDate("DATEACCT"));
int DateAcctYear = calendar.get(Calendar.YEAR);
v_counter = 0;
v_months = 0;
v_firstyr = 0;
v_monthadj = 0;
v_adj = new BigDecimal(0.0);
v_Base_Amount = rs.getBigDecimal("A_ASSET_COST");
v_Salvage_Amount = rs.getBigDecimal("A_SALVAGE_VALUE");
v_Life_Periods = rs.getDouble("A_LIFE_PERIOD");
v_Life_Years = rs.getDouble("A_ASSET_LIFE_YEARS");
v_con_type = rs.getString("CONVENTIONTYPE");
double v_period = DateAcctYear - AssetServiceDateYear;
while (v_counter <= v_period){
if(v_firstyr == 0){
v_DB = (v_Base_Amount.subtract(v_Accum_Dep).subtract(v_Salvage_Amount)).multiply(new BigDecimal(2/v_Life_Years));
v_months = 12 - AssetServiceDateMonth +1;
if (v_con_type.compareTo("HYCON") ==0){
v_adj = new BigDecimal(Conventions.HYCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj).multiply(new BigDecimal(v_months)));
v_monthadj = 6-v_months;
}
else if (v_con_type.compareTo("FYCON") ==0){
v_adj = new BigDecimal(Conventions.FYCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,0,AssetServiceDateYear));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj).multiply(new BigDecimal(v_months)));
v_monthadj = 12-v_months;
}
else if (v_con_type.compareTo("DYCON") ==0){
v_adj = new BigDecimal(Conventions.DYCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_monthadj = 0;
}
else if (v_con_type.compareTo("MQCON") ==0){
v_adj = new BigDecimal(Conventions.MQCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj));
v_DB =(v_DB.divide(new BigDecimal(v_months),2, BigDecimal.ROUND_HALF_UP));
v_monthadj = 0;
}
else if (v_con_type.compareTo("FMCON") ==0){
v_adj = new BigDecimal(Conventions.FMCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(new BigDecimal(v_months)));
v_monthadj = 0;
}
else if (v_con_type.compareTo("MMCON") ==0){
v_Accum_Dep = v_Accum_Dep.add(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(.5)).add(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(v_months-1));
v_adj = new BigDecimal(Conventions.MMCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateMonth+1));
v_DB = (v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP)).multiply(v_adj);
v_monthadj = 0;
}
v_firstyr = 1;
}
else{
v_DB = (v_Base_Amount.subtract(v_Accum_Dep).subtract(v_Salvage_Amount)).multiply(new BigDecimal(2/v_Life_Years));
v_Accum_Dep = v_Accum_Dep.add(v_DB);
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
}
v_counter = v_counter+1;
}
A_Period_Exp = v_DB;
if (p_SL ==1 ){
if (v_Life_Periods-(p_A_CURRENT_PERIOD+v_monthadj)>0 )
v_SL = ((v_Base_Amount.subtract(v_Salvage_Amount).subtract(p_Accum_Dep)).divide(new BigDecimal(v_Life_Periods-(p_A_CURRENT_PERIOD+v_monthadj)),2, BigDecimal.ROUND_HALF_UP));
if (A_Period_Exp.compareTo(v_SL)==-1)
A_Period_Exp = v_SL;
if (v_Base_Amount.subtract(p_Accum_Dep).subtract(A_Period_Exp).compareTo(v_Salvage_Amount)==-1 )
A_Period_Exp =v_Base_Amount.subtract(p_Accum_Dep).subtract(v_Salvage_Amount);
}
}
//System.out.println("DB200: "+A_Period_Exp);
return A_Period_Exp;
}
catch (Exception e)
{
System.out.println("DB200: "+e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return A_Period_Exp;
}
static public BigDecimal DBVAR(int p_SL,int p_A_ASSET_ID, double p_A_CURRENT_PERIOD, String p_POSTINGTYPE,
int p_A_ASSET_ACCT_ID, BigDecimal p_Accum_Dep)
{
BigDecimal v_DB = new BigDecimal(0.0);
BigDecimal v_Accum_Dep = new BigDecimal(0.0);
BigDecimal v_SL = new BigDecimal(0.0);
BigDecimal A_Period_Exp = new BigDecimal(0.0);
double v_Var = 0.0;
int v_counter = 0;
double v_months = 0;
int v_firstyr = 0;
double v_monthadj = 0;
BigDecimal v_adj = new BigDecimal(0.0);
BigDecimal v_Base_Amount = new BigDecimal(0.0);
BigDecimal v_Salvage_Amount = new BigDecimal(0.0);
double v_Life_Periods = 0;
double v_Life_Years = 0;
String v_con_type = null;
StringBuffer sqlB = new StringBuffer ("SELECT A.A_ASSET_COST, A.A_SALVAGE_VALUE, A.A_LIFE_PERIOD, A.A_ASSET_LIFE_YEARS, A.DATEACCT,"
+ " D.ASSETSERVICEDATE, C.CONVENTIONTYPE, A_DEPRECIATION_VARIABLE_PERC "
+ " FROM A_DEPRECIATION_WORKFILE A, A_ASSET_ACCT B,A_ASSET D,A_DEPRECIATION_CONVENTION C "
+ " WHERE A.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND B.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_PERIOD_POSTED+1 >= A_PERIOD_START AND A_PERIOD_POSTED+1 <= A_PERIOD_END "
+ " AND A.POSTINGTYPE = '" + p_POSTINGTYPE
+ "' AND B.POSTINGTYPE = '" + p_POSTINGTYPE
+ "' AND B.A_ASSET_ACCT_ID = " + p_A_ASSET_ACCT_ID
+ " AND D.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND B.A_DEPRECIATION_CONV_ID = C.A_DEPRECIATION_CONVENTION_ID");
//System.out.println("DBVAR: "+sqlB.toString());
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
while (rs.next()){
v_counter = 0;
v_months = 0;
v_firstyr = 0;
v_monthadj = 0;
v_Var=rs.getDouble("A_DEPRECIATION_VARIABLE_PERC");
v_adj = new BigDecimal(0.0);
v_Base_Amount = rs.getBigDecimal("A_ASSET_COST");
v_Salvage_Amount = rs.getBigDecimal("A_SALVAGE_VALUE");
v_Life_Periods = rs.getDouble("A_LIFE_PERIOD");
v_Life_Years = rs.getDouble("A_ASSET_LIFE_YEARS");
v_con_type = rs.getString("CONVENTIONTYPE");
Calendar calendar = new GregorianCalendar();
calendar.setTime(rs.getDate("ASSETSERVICEDATE"));
int AssetServiceDateYear = calendar.get(Calendar.YEAR);
int AssetServiceDateMonth = calendar.get(Calendar.MONTH);
calendar.setTime(rs.getDate("DATEACCT"));
int DateAcctYear = calendar.get(Calendar.YEAR);
double v_period = DateAcctYear - AssetServiceDateYear;
while (v_counter <= v_period){
if(v_firstyr == 0){
v_DB = (v_Base_Amount.subtract(v_Accum_Dep).subtract(v_Salvage_Amount)).multiply(new BigDecimal(v_Var/v_Life_Years));
v_months = 12 - AssetServiceDateMonth +1;
if (v_con_type.compareTo("HYCON") ==0){
v_adj = new BigDecimal(Conventions.HYCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj).multiply(new BigDecimal(v_months)));
v_monthadj = 6-v_months;
}
else if (v_con_type.compareTo("FYCON") ==0){
v_adj = new BigDecimal(Conventions.FYCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,0,AssetServiceDateYear));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj).multiply(new BigDecimal(v_months)));
v_monthadj = 12-v_months;
}
else if (v_con_type.compareTo("DYCON") ==0){
v_adj = new BigDecimal(Conventions.DYCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_monthadj = 0;
}
else if (v_con_type.compareTo("MQCON") ==0){
v_adj = new BigDecimal(Conventions.MQCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(v_adj));
v_DB =(v_DB.divide(new BigDecimal(v_months),2, BigDecimal.ROUND_HALF_UP));
v_monthadj = 0;
}
else if (v_con_type.compareTo("FMCON") ==0){
v_adj = new BigDecimal(Conventions.FMCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateYear));
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
v_Accum_Dep = v_Accum_Dep.add(v_DB.multiply(new BigDecimal(v_months)));
v_monthadj = 0;
}
else if (v_con_type.compareTo("MMCON") ==0){
v_Accum_Dep = v_Accum_Dep.add(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(.5)).add(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(v_months-1));
v_adj = new BigDecimal(Conventions.MMCON(p_A_ASSET_ID,p_POSTINGTYPE,p_A_ASSET_ACCT_ID,2,AssetServiceDateMonth+1));
v_DB = (v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP).multiply(v_adj));
v_monthadj = 0;
}
v_firstyr = 1;
}
else{
v_DB = (v_Base_Amount.subtract(v_Accum_Dep).subtract(v_Salvage_Amount)).multiply(new BigDecimal(v_Var/v_Life_Years));
v_Accum_Dep = v_Accum_Dep.add(v_DB);
v_DB =(v_DB.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP));
}
v_counter = v_counter+1;
}
A_Period_Exp = v_DB;
if (p_SL ==1 ){
if (v_Life_Periods-(p_A_CURRENT_PERIOD+v_monthadj)>0 )
v_SL = ((v_Base_Amount.subtract(v_Salvage_Amount).subtract(p_Accum_Dep)).divide(new BigDecimal(v_Life_Periods-(p_A_CURRENT_PERIOD+v_monthadj)),2, BigDecimal.ROUND_HALF_UP));
if (A_Period_Exp.compareTo(v_SL)==-1)
A_Period_Exp = v_SL;
if (v_Base_Amount.subtract(p_Accum_Dep).subtract(A_Period_Exp).compareTo(v_Salvage_Amount)==-1 )
A_Period_Exp =v_Base_Amount.subtract(p_Accum_Dep).subtract(v_Salvage_Amount);
}
}
//System.out.println("DBVAR: "+A_Period_Exp);
return A_Period_Exp;
}
catch (Exception e)
{
System.out.println("DBVAR: "+e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return A_Period_Exp;
}
static public BigDecimal MAN(int p_SL,int p_A_ASSET_ID, double p_A_CURRENT_PERIOD, String p_POSTINGTYPE,
int p_A_ASSET_ACCT_ID, BigDecimal p_Accum_Dep)
{
int v_Dep_Mon = 0;
BigDecimal v_Dep_Sprd = new BigDecimal(0.0);
BigDecimal A_Period_Exp = new BigDecimal(0.0);
StringBuffer sqlB = new StringBuffer ("SELECT B.A_ASSET_COST, B.A_SALVAGE_VALUE, B.A_LIFE_PERIOD, "
+ " A_ASSET_LIFE_YEARS, A_ASSET_LIFE_CURRENT_YEAR,A_ACCUMULATED_DEPR, A_DEPRECIATION_MANUAL_AMOUNT, "
+ " A_ASSET_SPREAD_ID, A_DEPRECIATION_MANUAL_PERIOD, A.AD_Client_ID "
+ " FROM A_DEPRECIATION_WORKFILE B, A_ASSET_ACCT A "
+ " WHERE B.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND B.POSTINGTYPE = '"+p_POSTINGTYPE
+ "' AND A.POSTINGTYPE = '"+p_POSTINGTYPE
+ "' AND A.A_ASSET_ACCT_ID = " + p_A_ASSET_ACCT_ID);
//System.out.println("MAN: "+sqlB.toString());
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
while (rs.next()){
if (rs.getString("A_DEPRECIATION_MANUAL_PERIOD").compareTo("PR")==0)
A_Period_Exp = rs.getBigDecimal("A_DEPRECIATION_MANUAL_AMOUNT");
else if (rs.getString("A_DEPRECIATION_MANUAL_PERIOD").compareTo("YR")==0){
if (p_A_CURRENT_PERIOD == -1){
//System.out.println("MAN YR - A_CURRENT_PERIOD = -1 ");
StringBuffer sql3 = new StringBuffer("SELECT PeriodNo"
+ " FROM C_Period WHERE C_Period_ID = 183 "
+ " AND AD_Client_ID = ? ");
v_Dep_Mon = DB.getSQLValue(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else{
//System.out.println("MAN YR - A_CURRENT_PERIOD = " + p_A_CURRENT_PERIOD);
v_Dep_Mon = (int)p_A_CURRENT_PERIOD - (int)(Math.ceil((double)p_A_CURRENT_PERIOD/12)*12-12) ;
}
//System.out.println("MAN v_Dep_Mon: "+v_Dep_Mon);
if (v_Dep_Mon==1){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_1"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==2){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_2"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==3){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_3"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==4){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_4"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==5){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_5"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==6){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_6"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==7){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_7"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==8){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_8"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==9){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_9"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==10){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_10"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==11)
{
StringBuffer sql3 = new StringBuffer("SELECT A_Period_11"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==12){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_12"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else if (v_Dep_Mon==13){
StringBuffer sql3 = new StringBuffer("SELECT A_Period_13"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
else
{
StringBuffer sql3 = new StringBuffer("SELECT A_Period_14"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("A_ASSET_SPREAD_ID"));
//System.out.println("MAN YR - SpreadAmnt = " + sql3.toString());
}
//System.out.println("MAN v_Dep_Sprd: "+v_Dep_Sprd);
A_Period_Exp = rs.getBigDecimal("A_DEPRECIATION_MANUAL_AMOUNT").multiply(v_Dep_Sprd);
}
}
//System.out.println("MAN: "+A_Period_Exp);
return A_Period_Exp;
}
catch (Exception e)
{
System.out.println("MAN: "+e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return A_Period_Exp;
}
static public BigDecimal SL(int p_SL,int p_A_ASSET_ID, double p_A_CURRENT_PERIOD, String p_POSTINGTYPE,
int p_A_ASSET_ACCT_ID, BigDecimal p_Accum_Dep)
{
BigDecimal A_Period_Exp = new BigDecimal(0.0);
StringBuffer sqlB = new StringBuffer ("SELECT A_DEPRECIATION_WORKFILE.A_ASSET_COST, "
+ " A_DEPRECIATION_WORKFILE.A_SALVAGE_VALUE, A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD"
+ " FROM A_DEPRECIATION_WORKFILE, A_ASSET_ACCT"
+ " WHERE A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_ASSET_ACCT.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '"+p_POSTINGTYPE
+ "' AND A_ASSET_ACCT.POSTINGTYPE = '"+p_POSTINGTYPE
+ "' AND A_ASSET_ACCT.A_ASSET_ACCT_ID = " + p_A_ASSET_ACCT_ID);
//System.out.println("SL: "+sqlB.toString());
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
while (rs.next()){
A_Period_Exp = ((rs.getBigDecimal("A_ASSET_COST").subtract(rs.getBigDecimal("A_SALVAGE_VALUE"))).divide( rs.getBigDecimal("A_LIFE_PERIOD"),2, BigDecimal.ROUND_HALF_UP));
}
return A_Period_Exp;
}
catch (Exception e)
{
System.out.println("SL: "+e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return A_Period_Exp;
}
static public BigDecimal UOP(int p_SL,int p_A_ASSET_ID, int p_A_CURRENT_PERIOD, String p_POSTINGTYPE,
int p_A_ASSET_ACCT_ID, BigDecimal p_Accum_Dep)
{
BigDecimal A_Period_Exp = new BigDecimal(0.0);
StringBuffer sqlB = new StringBuffer ("SELECT A_DEPRECIATION_WORKFILE.A_ASSET_COST, "
+ " A_DEPRECIATION_WORKFILE.A_SALVAGE_VALUE, A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD"
+ " A_ASSET.LIFEUSEUNITS, A_ASSET.USEUNITS, A_DEPRECIATION_WORKFILE.A_ACCUMULATED_DEPR"
+ " FROM A_DEPRECIATION_WORKFILE, A_ASSET_ACCT"
+ " WHERE A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_ASSET_ACCT.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '"+p_POSTINGTYPE
+ "' AND A_ASSET_ACCT.POSTINGTYPE = '"+p_POSTINGTYPE
+ "' AND A_ASSET_ACCT.A_ASSET_ACCT_ID = " + p_A_ASSET_ACCT_ID);
//System.out.println("UOP: "+sqlB.toString());
PreparedStatement pstmt = null;
ResultSet rs = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
try {
rs = pstmt.executeQuery();
while (rs.next()){
A_Period_Exp = (rs.getBigDecimal("A_ASSET_COST").subtract(rs.getBigDecimal("A_SALVAGE_VALUE"))
.multiply(new BigDecimal(rs.getDouble("USEUNITS")/rs.getDouble("LIFEUSEUNITS")))
.subtract(rs.getBigDecimal("A_ACCUMULATED_DEPR")));
}
//System.out.println("UOP: "+A_Period_Exp);
return A_Period_Exp;
}
catch (Exception e)
{
System.out.println("UOP: "+e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return A_Period_Exp;
}
static public BigDecimal SYD(int p_SL,int p_A_ASSET_ID, double p_A_CURRENT_PERIOD, String p_POSTINGTYPE, int p_A_ASSET_ACCT_ID, BigDecimal p_Accum_Dep)
{
BigDecimal A_Period_Exp = new BigDecimal(0.0);
StringBuffer sqlB = new StringBuffer ("SELECT A_DEPRECIATION_WORKFILE.A_ASSET_COST, "
+ " A_DEPRECIATION_WORKFILE.A_SALVAGE_VALUE, A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD, "
+ " A_DEPRECIATION_WORKFILE.A_ASSET_LIFE_CURRENT_YEAR, A_DEPRECIATION_WORKFILE.A_ASSET_LIFE_YEARS, "
+ " A_ASSET.ASSETSERVICEDATE, A_DEPRECIATION_BUILD.DATEACCT"
+ " FROM A_DEPRECIATION_WORKFILE, A_ASSET_ACCT, A_ASSET, A_DEPRECIATION_BUILD"
+ " WHERE A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_ASSET_ACCT.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_ASSET.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_PERIOD_POSTED+1 >= A_PERIOD_START AND A_PERIOD_POSTED+1 <= A_PERIOD_END "
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '"+p_POSTINGTYPE
+ "' AND A_ASSET_ACCT.POSTINGTYPE = '"+p_POSTINGTYPE
+ "' AND A_ASSET_ACCT.A_ASSET_ACCT_ID = " + p_A_ASSET_ACCT_ID);
//System.out.println("SYD: "+sqlB.toString());
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
while (rs.next()){
int v_life_current_year = (int)(p_A_CURRENT_PERIOD/(12))+1;
A_Period_Exp = ((rs.getBigDecimal("A_ASSET_COST").subtract(rs.getBigDecimal("A_SALVAGE_VALUE")))
.multiply(new BigDecimal(2*(rs.getInt("A_ASSET_LIFE_YEARS")-v_life_current_year+1)))
.divide(new BigDecimal(rs.getInt("A_ASSET_LIFE_YEARS")*(rs.getInt("A_ASSET_LIFE_YEARS")+1)),2, BigDecimal.ROUND_HALF_UP));
A_Period_Exp = A_Period_Exp.divide(new BigDecimal(12.0),2, BigDecimal.ROUND_HALF_UP);
}
//System.out.println("SYD: "+A_Period_Exp);
return A_Period_Exp;
}
catch (Exception e)
{
System.out.println("SYD: "+e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return A_Period_Exp;
}
static public BigDecimal TAB(int p_SL,int p_A_ASSET_ID, double p_A_CURRENT_PERIOD, String p_POSTINGTYPE,
int p_A_ASSET_ACCT_ID, BigDecimal p_Accum_Dep)
{
BigDecimal A_Period_Exp = new BigDecimal(0.0);
BigDecimal v_Dep_Rate = new BigDecimal(0.0);
BigDecimal v_Dep_Sprd = new BigDecimal(0.0);
int v_Dep_Mon = 0;
int v_Dep_Per = 0;
StringBuffer sqlB = new StringBuffer ("SELECT A.A_ASSET_COST, A.A_SALVAGE_VALUE, A.A_LIFE_PERIOD,"
+ " B.A_DEPRECIATION_TABLE_HEADER_ID, A.AD_Client_ID, C.A_TERM, C.A_Depreciation_Table_Code "
+ " FROM A_DEPRECIATION_WORKFILE A, A_ASSET_ACCT B, A_Depreciation_Table_Header C"
+ " WHERE A.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND B.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A.POSTINGTYPE = '"+p_POSTINGTYPE
+ "' AND B.POSTINGTYPE = '"+p_POSTINGTYPE
+ "' AND B.A_ASSET_ACCT_ID = " + p_A_ASSET_ACCT_ID
+ "' AND C.A_DEPRECIATION_TABLE_HEADER_ID = A_DEPRECIATION_TABLE_HEADER_ID");
//System.out.println("TAB: "+sqlB.toString());
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
while (rs.next()){
if (rs.getString("A_TERM").compareTo("PR")==0){
StringBuffer sql3 = new StringBuffer("SELECT A_Depreciation_Rate"
+ " FROM A_Depreciation_Table_Detail WHERE A_DEPRECIATION_TABLE_CODE = " + rs.getString("A_Depreciation_Table_Code")
+ " AND A_Period = ? ");
v_Dep_Rate = DB.getSQLValueBD(null, sql3.toString(), (int)p_A_CURRENT_PERIOD);
A_Period_Exp = (rs.getBigDecimal("A_ASSET_COST").subtract(rs.getBigDecimal("A_SALVAGE_VALUE")).multiply(v_Dep_Rate));
}
else if (rs.getString("A_TERM").compareTo("YR")==0){
StringBuffer sql3 = new StringBuffer("SELECT A_Depreciation_Rate"
+ " FROM A_Depreciation_Table_Detail WHERE A_DEPRECIATION_TABLE_CODE = " + rs.getString("A_Depreciation_Table_Code")
+ " AND A_Period = ? ");
v_Dep_Rate = DB.getSQLValueBD(null, sql3.toString(), (int)(Math.ceil((double)p_A_CURRENT_PERIOD+1)/12));
sql3 = new StringBuffer("SELECT C_Period_ID"
+ " FROM A_Depreciation_Build ");
v_Dep_Per = DB.getSQLValue(null, sql3.toString());
if (p_A_CURRENT_PERIOD == -1){
sql3 = new StringBuffer("SELECT PeriodNo"
+ " FROM C_Period WHERE C_Period_ID = " + v_Dep_Per
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else
v_Dep_Mon = (int)p_A_CURRENT_PERIOD - (int)(Math.ceil((double)p_A_CURRENT_PERIOD)/12*12-12) ;
if (v_Dep_Mon==1){
sql3 = new StringBuffer("SELECT A_Period_1"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==2){
sql3 = new StringBuffer("SELECT A_Period_2"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==3){
sql3 = new StringBuffer("SELECT A_Period_3"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==4){
sql3 = new StringBuffer("SELECT A_Period_4"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==5){
sql3 = new StringBuffer("SELECT A_Period_5"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==6){
sql3 = new StringBuffer("SELECT A_Period_6"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==7){
sql3 = new StringBuffer("SELECT A_Period_7"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==8){
sql3 = new StringBuffer("SELECT A_Period_8"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==9){
sql3 = new StringBuffer("SELECT A_Period_9"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==10){
sql3 = new StringBuffer("SELECT A_Period_10"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==11){
sql3 = new StringBuffer("SELECT A_Period_11"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==12){
sql3 = new StringBuffer("SELECT A_Period_12"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else if (v_Dep_Mon==13){
sql3 = new StringBuffer("SELECT A_Period_13"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
else{
sql3 = new StringBuffer("SELECT A_Period_14"
+ " FROM A_Asset_Spread WHERE A_Asset_Spread_ID = " + rs.getString("A_Depreciation_Table_Code")
+ " AND AD_Client_ID = ? ");
v_Dep_Sprd = DB.getSQLValueBD(null, sql3.toString(), rs.getInt("AD_Client_ID"));
}
A_Period_Exp = (rs.getBigDecimal("A_ASSET_COST").subtract(rs.getBigDecimal("A_SALVAGE_VALUE")).multiply(v_Dep_Rate).multiply(v_Dep_Sprd));
}
}
//System.out.println("TAB: "+A_Period_Exp);
return A_Period_Exp;
}
catch (Exception e)
{
System.out.println("TAB: "+e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return A_Period_Exp;
}
}// Depreciation

View File

@ -1,149 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert Klein. robeklein@hotmail.com
* _____________________________________________
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.compiere.util.DB;
/**
* Fixed Asset Depreciation
*
* @author Rob Klein
* @version $Id: Conventions.java,v 1.0 $
*
*/
public class DepreciationAdj {
/**
*
*
*/
static public BigDecimal Dep_Adj(String Type, int p_A_ASSET_ID, BigDecimal p_A_ASSET_ADJUSTMENT, double p_A_PERIODNO,
String p_POSTINGTYPE,int p_A_ASSET_ACCT_ID)
{
BigDecimal A_Dep_Adj = new BigDecimal(0.0);
if(Type.compareTo("MDI")==0){
A_Dep_Adj = MDI( p_A_ASSET_ID, p_A_ASSET_ADJUSTMENT, p_A_PERIODNO,
p_POSTINGTYPE, p_A_ASSET_ACCT_ID);
//System.out.println("MDI Main: "+A_Dep_Adj);
return A_Dep_Adj;
}
else if(Type.compareTo("LDI")==0){
A_Dep_Adj = LDI( p_A_ASSET_ID, p_A_ASSET_ADJUSTMENT, p_A_PERIODNO,
p_POSTINGTYPE, p_A_ASSET_ACCT_ID);
//System.out.println("LDI Main: "+A_Dep_Adj);
return A_Dep_Adj;
}
else if(Type.compareTo("YDI")==0){
A_Dep_Adj = YDI( p_A_ASSET_ID, p_A_ASSET_ADJUSTMENT, p_A_PERIODNO,
p_POSTINGTYPE, p_A_ASSET_ACCT_ID);
//System.out.println("YDI Main: "+A_Dep_Adj);
return A_Dep_Adj;
}
else
return new BigDecimal(0.0);
}
static public BigDecimal LDI( int p_A_ASSET_ID, BigDecimal p_A_ASSET_ADJUSTMENT, double p_A_PERIODNO,
String p_POSTINGTYPE,int p_A_ASSET_ACCT_ID)
{
BigDecimal A_Dep_Adj = new BigDecimal(0.0);
StringBuffer sqlB = new StringBuffer ("SELECT A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD, A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED"
+ " FROM A_DEPRECIATION_WORKFILE"
+ " WHERE A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '" + p_POSTINGTYPE +"'");
//System.out.println("LDI: "+sqlB.toString());
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
A_Dep_Adj = p_A_ASSET_ADJUSTMENT.divide(new BigDecimal(rs.getDouble("A_LIFE_PERIOD")-rs.getDouble("A_PERIOD_POSTED")+1),2, BigDecimal.ROUND_HALF_UP);
}
//System.out.println("LDI: "+A_Period_Exp);
return A_Dep_Adj;
}
catch (Exception e)
{
System.out.println("LDI: "+e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return A_Dep_Adj;
}
static public BigDecimal MDI( int p_A_ASSET_ID, BigDecimal p_A_ASSET_ADJUSTMENT, double p_A_PERIODNO,
String p_POSTINGTYPE,int p_A_ASSET_ACCT_ID)
{
return p_A_ASSET_ADJUSTMENT;
}
static public BigDecimal YDI( int p_A_ASSET_ID, BigDecimal p_A_ASSET_ADJUSTMENT, double p_A_PERIODNO,
String p_POSTINGTYPE,int p_A_ASSET_ACCT_ID)
{
BigDecimal A_Dep_Adj = new BigDecimal(0.0);
StringBuffer sqlB = new StringBuffer ("SELECT A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD, A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED"
+ " FROM A_DEPRECIATION_WORKFILE"
+ " WHERE A_DEPRECIATION_WORKFILE.A_ASSET_ID = " + p_A_ASSET_ID
+ " AND A_DEPRECIATION_WORKFILE.POSTINGTYPE = '" + p_POSTINGTYPE +"'");
//System.out.println("DB150: "+sqlB.toString());
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlB.toString(),null);
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()){
A_Dep_Adj = p_A_ASSET_ADJUSTMENT.divide(new BigDecimal(12-p_A_PERIODNO),2, BigDecimal.ROUND_HALF_UP);
}
//System.out.println("LDI: "+A_Period_Exp);
return A_Dep_Adj;
}
catch (Exception e)
{
System.out.println("LDI: "+e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return A_Dep_Adj;
}
}// Depreciation

View File

@ -1,12 +0,0 @@
package org.compiere.FA;
/**
* Column name constant for fixed asset customization to core tables.
* @author Low Heng Sin
*
*/
public interface I_CustomColumn {
public final static String A_Asset_Group_ID = "A_Asset_Group_ID";
public final static String A_Processed = "A_Processed";
}

View File

@ -1,485 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Import Assets
*
* @author Rob Klein
* @version $Id: ImportAsset.java,v 1.0 $
*/
public class ImportAsset extends SvrProcess
{
/**
* Import Asset
*/
public ImportAsset()
{
super();
} // ImportAsset
/** Client to be imported to */
private int m_AD_Client_ID = 0;
/** Delete old Imported */
private boolean m_deleteOldImported = false;
/** Organization to be imported to */
private int m_AD_Org_ID = 0;
/** Effective */
private Timestamp m_DateValue = null;
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
if (name.equals("AD_Client_ID"))
m_AD_Client_ID = (para[i].getParameterAsInt());
else if (name.equals("DeleteOldImported"))
m_deleteOldImported = "Y".equals(para[i].getParameter());
else
log.info("ImportAsset.prepare - Unknown Parameter: " + name);
}
m_DateValue = new Timestamp (System.currentTimeMillis());
//java.util.Date today = new java.util.Date();
//m_DateValue = new java.sql.Date(today.getTime());
} // prepare
/**
* Perform process.
* @return Message
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
StringBuffer sql = null;
int no = 0;
String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID;
// **** Prepare ****
// Delete Old Imported
/**if (m_deleteOldImported)
{
sql = new StringBuffer ("DELETE I_Asset "
+ "WHERE I_IsImported='Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString());
}**/
// Set Client, Org, IaActive, Created/Updated, ProductType
sql = new StringBuffer ("UPDATE I_Asset "
+ "SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),"
+ " AD_Org_ID = COALESCE (AD_Org_ID, 0),"
+ " IsActive = COALESCE (IsActive, 'Y'),"
+ " CreatedBy = COALESCE (CreatedBy, 0),"
+ " UpdatedBy = COALESCE (UpdatedBy, 0),"
+ " I_ErrorMsg = NULL,"
+ " I_IsImported = 'N' "
+ "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
no = DB.executeUpdate(sql.toString(),null);
// Set Currency
/**sql = new StringBuffer ("UPDATE I_Asset i "
+ "SET ISO_Code=(SELECT ISO_Code FROM C_Currency c"
+ " INNER JOIN C_AcctSchema a ON (a.C_Currency_ID=c.C_Currency_ID)"
+ " INNER JOIN AD_ClientInfo ci ON (a.C_AcctSchema_ID=ci.C_AcctSchema1_ID)"
+ " WHERE ci.AD_Client_ID=i.AD_Client_ID) "
+ "WHERE C_Currency_ID IS NULL AND ISO_Code IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString());
Log.trace(Log.l5_DData, "ImportAsset.doIt", "Set Currency Default=" + no);
//
sql = new StringBuffer ("UPDATE I_Asset i "
+ "SET C_Currency_ID=(SELECT C_Currency_ID FROM C_Currency c"
+ " WHERE i.ISO_Code=c.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) "
+ "WHERE C_Currency_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString());
Log.trace(Log.l5_DData, "ImportAsset.doIt", "Set Currency=" + no);
//
sql = new StringBuffer ("UPDATE I_Asset "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Currency,' "
+ "WHERE C_Currency_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString());
Log.trace(Log.l3_Util, "ImportAsset.doIt", "Invalid Currency=" + no);
**/
// -------------------------------------------------------------------
int noInsert = 0;
int noUpdate = 0;
//int noInsertPO = 0;
//int noUpdatePO = 0;
// Go through Records
sql = new StringBuffer ("SELECT I_Asset_ID, A_Asset_ID "
+ "FROM I_Asset WHERE I_IsImported='N'").append(clientCheck).append(" Order By I_Asset_ID");
// Connection conn = DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED);
try
{
// Insert Asset from Import
StringBuffer sqlA = new StringBuffer ("INSERT INTO A_Asset (A_Asset_ID,"
+ "AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,"
+ "Value,Name,Description,Help,"
+ "A_Asset_Group_ID,M_Product_ID,SerNo,LOT,VersionNo,GuaranteeDate,"
+ "AssetServiceDate,IsOwned,AssetDepreciationDate, UseLifeYears, UseLifeMonths,"
+ "LifeUseUnits, UseUnits, Isdisposed, AssetDisposalDate, IsInPosession,"
+ "LocationComment, M_Locator_ID, C_BPartner_ID, C_BPartner_Location_ID,"
+ "C_Location_ID, IsDepreciated, IsFullyDepreciated, AD_User_ID,"
+ "M_AttributeSetInstance_ID, A_Parent_Asset_ID, A_QTY_Original,"
+ "A_QTY_Current) "
+ "SELECT ?,"
+ "AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,"
+ "Value,Name,Description,Help,"
+ "A_Asset_Group_ID,M_Product_ID,SerNo,LOT,VersionNo,GuaranteeDate,"
+ "AssetServiceDate,IsOwned,AssetDepreciationDate, UseLifeYears, UseLifeMonths,"
+ "LifeUseUnits, UseUnits, Isdisposed, AssetDisposalDate, IsInPosession,"
+ "LocationComment, M_Locator_ID, C_BPartner_ID, C_BPartner_Location_ID,"
+ "C_Location_ID, IsDepreciated, IsFullyDepreciated, AD_User_ID,"
+ "M_AttributeSetInstance_ID, A_Parent_Asset_ID, A_QTY_Original,"
+ "A_QTY_Current "
+ "FROM I_Asset "
+ "WHERE I_Asset_ID=?");
PreparedStatement pstmt_insertProduct = DB.prepareStatement(sqlA.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE, null);
// Update Assets from Import
StringBuffer sqlB = new StringBuffer ("UPDATE A_Asset "
+ "SET (A_Asset_ID,"
+ "AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,"
+ "Value,Name,Description,Help,"
+ "A_Asset_Group_ID,M_Product_ID,SerNo,LOT,VersionNo,GuaranteeDate,"
+ "AssetServiceDate,IsOwned,AssetDepreciationDate, UseLifeYears, UseLifeMonths,"
+ "LifeUseUnits, UseUnits, Isdisposed, AssetDisposalDate, IsInPosession,"
+ "LocationComment, M_Locator_ID, C_BPartner_ID, C_BPartner_Location_ID,"
+ "C_Location_ID, IsDepreciated, IsFullyDepreciated, AD_User_ID,"
+ "M_AttributeSetInstance_ID, A_Parent_Asset_ID, A_QTY_Original,"
+ "A_QTY_Current) = "
+ "(SELECT A_Asset_ID,"
+ "AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,"
+ "Value,Name,Description,Help,"
+ "A_Asset_Group_ID,M_Product_ID,SerNo,LOT,VersionNo,GuaranteeDate,"
+ "AssetServiceDate,IsOwned,AssetDepreciationDate, UseLifeYears, UseLifeMonths,"
+ "LifeUseUnits, UseUnits, Isdisposed, AssetDisposalDate, IsInPosession,"
+ "LocationComment, M_Locator_ID, C_BPartner_ID, C_BPartner_Location_ID,"
+ "C_Location_ID, IsDepreciated, IsFullyDepreciated, AD_User_ID,"
+ "M_AttributeSetInstance_ID, A_Parent_Asset_ID, A_QTY_Original,"
+ "A_QTY_Current "
+ "FROM I_Asset "
+ "WHERE I_Asset_ID=?) "
+ "WHERE A_Asset_ID=?");
PreparedStatement pstmt_updateProduct = DB.prepareStatement(sqlB.toString(), ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE, null);
// Insert Asset Accounts from Import
StringBuffer sqlC = new StringBuffer ("INSERT INTO A_Asset_Acct ("
+ "A_ASSET_ID, C_ACCTSCHEMA_ID, AD_CLIENT_ID,"
+ "AD_ORG_ID,ISACTIVE, CREATED, CREATEDBY, UPDATED ,UPDATEDBY,"
+ "A_DEPRECIATION_ID, A_DEPRECIATION_ACCT, A_ACCUMDEPRECIATION_ACCT,"
+ "A_DISPOSAL_LOSS, A_DISPOSAL_REVENUE, A_ASSET_ACCT,A_ASSET_SPREAD_ID,"
+ "A_DEPRECIATION_METHOD_ID,A_PERIOD_START,A_PERIOD_END, A_DEPRECIATION_CONV_ID,"
+ "A_SALVAGE_VALUE, POSTINGTYPE, A_SPLIT_PERCENT, A_DEPRECIATION_MANUAL_AMOUNT, "
+ "A_DEPRECIATION_MANUAL_PERIOD, A_DEPRECIATION_VARIABLE_PERC, A_ASSET_ACCT_ID) "
+ "SELECT ?,C_ACCTSCHEMA_ID,"
+ "AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,"
+ "DEPRECIATIONTYPE, A_DEPRECIATION_ACCT, A_ACCUMDEPRECIATION_ACCT,"
+ "A_DISPOSAL_LOSS, A_DISPOSAL_REVENUE, A_ASSET_ACCT,A_ASSET_SPREAD_TYPE,"
+ "A_DEPRECIATION_CALC_TYPE,A_PERIOD_START,A_PERIOD_END, CONVENTIONTYPE,"
+ "A_SALVAGE_VALUE, POSTINGTYPE, A_SPLIT_PERCENT, A_DEPRECIATION_MANUAL_AMOUNT,"
+ "A_DEPRECIATION_MANUAL_PERIOD, A_DEPRECIATION_VARIABLE_PERC, ? "
+ "FROM I_Asset "
+ "WHERE I_Asset_ID=?");
PreparedStatement pstmt_insertAssetAcct = DB.prepareStatement(sqlC.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE, null);
// Insert Asset Balances from Import
StringBuffer sqlD = new StringBuffer ("INSERT INTO A_DEPRECIATION_WORKFILE ("
+ "A_DEPRECIATION_WORKFILE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,"
+ "CREATED, CREATEDBY, UPDATED, UPDATEDBY, A_ASSET_ID, A_ASSET_COST,"
+ "A_ACCUMULATED_DEPR, A_CALC_ACCUMULATED_DEPR, A_LIFE_PERIOD,"
+ "A_PERIOD_POSTED, A_CURRENT_PERIOD, A_PRIOR_YEAR_ACCUMULATED_DEPR,"
+ "A_BASE_AMOUNT, A_SALVAGE_VALUE, A_CURR_DEP_EXP, A_ASSET_LIFE_YEARS,"
+ "A_ASSET_LIFE_CURRENT_YEAR, ISDEPRECIATED, POSTINGTYPE, A_QTY_CURRENT"
+ ")"
+ "SELECT "
+ "?, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,"
+ "CREATED, CREATEDBY, UPDATED, UPDATEDBY, ?, A_ASSET_COST,"
+ "A_ACCUMULATED_DEPR, A_CALC_ACCUMULATED_DEPR, A_LIFE_PERIOD,"
+ "A_PERIOD_POSTED, A_CURRENT_PERIOD, A_PRIOR_YEAR_ACCUMULATED_DEPR,"
+ "A_BASE_AMOUNT, A_SALVAGE_VALUE, A_CURR_DEP_EXP, A_ASSET_LIFE_YEARS,"
+ "A_ASSET_LIFE_CURRENT_YEAR, ISDEPRECIATED, POSTINGTYPE, A_QTY_CURRENT"
+ " "
+ "FROM I_Asset "
+ "WHERE I_Asset_ID=?");
PreparedStatement pstmt_insertAssetBal = DB.prepareStatement(sqlD.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE, null);
// Insert Asset Additions from Import
StringBuffer sqlE = new StringBuffer ("INSERT INTO A_Asset_Addition ("
+ " A_ASSET_ADDITION_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,"
+ " CREATED, CREATEDBY, UPDATED, UPDATEDBY, A_ASSET_ID,"
+ " ASSETVALUEAMT, DESCRIPTION, M_INOUTLINE_ID, "
+ " POSTINGTYPE, A_QTY_CURRENT, A_SOURCETYPE, A_CAPVSEXP) "
+ "SELECT "
+ " ?, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,"
+ " CREATED, CREATEDBY, UPDATED, UPDATEDBY, ?,"
+ " A_ASSET_COST, 'Imported Asset', '1', "
+ " POSTINGTYPE, A_QTY_CURRENT, 'IMP', 'Cap' "
+ "FROM I_Asset "
+ "WHERE I_Asset_ID=?");
PreparedStatement pstmt_insertAssetAdd = DB.prepareStatement(sqlE.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE, null);
// Insert Asset Additions from Import
StringBuffer sqlF = new StringBuffer ("INSERT INTO A_Asset_Change ("
+ "A_ASSET_CHANGE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, "
+ "CREATED, CREATEDBY, UPDATED, UPDATEDBY, A_ASSET_ID, "
+ "CHANGETYPE, USELIFEYEARS, "
+ "USELIFEMONTHS, LIFEUSEUNITS, ASSETDEPRECIATIONDATE, "
+ "A_ASSET_ADDITION_ID, SERNO,"
+ "LOT, VERSIONNO, ASSETACCUMDEPRECIATIONAMT, TEXTDETAILS, "
+ "ASSETSERVICEDATE, ASSETBOOKVALUEAMT, ASSETMARKETVALUEAMT, "
+ "ASSETVALUEAMT, ASSETDISPOSALDATE, A_PARENT_ASSET_ID, "
+ "C_BPARTNER_ID, C_BPARTNER_LOCATION_ID, C_LOCATION_ID, "
+ "A_DEPRECIATION_ACCT, A_ACCUMDEPRECIATION_ACCT, A_DISPOSAL_LOSS, "
+ "A_DISPOSAL_REVENUE, A_ASSET_ACCT, A_ASSET_SPREAD_TYPE, "
+ "A_DEPRECIATION_CALC_TYPE, A_PERIOD_START, A_PERIOD_END, "
+ "A_SALVAGE_VALUE, POSTINGTYPE, A_ASSET_ACCT_ID, CONVENTIONTYPE, "
+ "A_SPLIT_PERCENT, DEPRECIATIONTYPE, A_QTY_CURRENT, ISDEPRECIATED, "
+ "ISFULLYDEPRECIATED, ISINPOSESSION, ISDISPOSED, ISOWNED) "
+ "SELECT "
+ "?, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, "
+ "CREATED, CREATEDBY, UPDATED, UPDATEDBY, ?, "
+ "'IMP', USELIFEYEARS, "
+ "USELIFEMONTHS, LIFEUSEUNITS, ASSETDEPRECIATIONDATE, "
+ "?, SERNO, "
+ "LOT, VERSIONNO, A_ACCUMULATED_DEPR, 'Imported Fixed Asset', "
+ "ASSETSERVICEDATE, A_BASE_AMOUNT, ASSETMARKETVALUEAMT, "
+ "A_ASSET_COST, ASSETDISPOSALDATE, A_PARENT_ASSET_ID, "
+ "C_BPARTNER_ID, C_BPARTNER_LOCATION_ID, C_LOCATION_ID, "
+ "A_DEPRECIATION_ACCT, A_ACCUMDEPRECIATION_ACCT, A_DISPOSAL_LOSS, "
+ "A_DISPOSAL_REVENUE, A_ASSET_ACCT, A_ASSET_SPREAD_TYPE, "
+ "A_DEPRECIATION_CALC_TYPE, A_PERIOD_START, A_PERIOD_END, "
+ "A_SALVAGE_VALUE, POSTINGTYPE, ?, CONVENTIONTYPE, "
+ "A_SPLIT_PERCENT, DEPRECIATIONTYPE, A_QTY_CURRENT, ISDEPRECIATED, "
+ "ISFULLYDEPRECIATED, ISINPOSESSION, ISDISPOSED, ISOWNED "
+ "FROM I_Asset "
+ "WHERE I_Asset_ID=?");
PreparedStatement pstmt_insertAssetChg = DB.prepareStatement(sqlF.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE, null);
/*
// Update Asset Accounts from Import
PreparedStatement pstmt_updateAssetAcct = conn.prepareStatement
("UPDATE A_Asset_Acct "
+ "SET("
+ "A_ASSET_ID, C_ACCTSCHEMA_ID, AD_CLIENT_ID"
+ "AD_ORG_ID,ISACTIVE, CREATED, CREATEDBY, UPDATED ,UPDATEDBY"
+ "A_DEPRECIATION_ID, A_DEPRECIATION_ACCT, A_ACCUMDEPRECIATION_ACCT"
+ "A_DISPOSAL_LOSS, A_DISPOSAL_REVENUE, A_ASSET_ACCT,A_ASSET_SPREAD_ID"
+ "A_DEPRECIATION_METHOD_ID,A_PERIOD_START,A_PERIOD_END"
+ "A_SALVAGE_VALUE, POSTINGTYPE, A_SPLIT_PERCENT) = "
+ "(SELECT ?,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,"
+ "DEPRECIATIONTYPE, A_DEPRECIATION_ACCT, A_ACCUMDEPRECIATION_ACCT"
+ "A_DISPOSAL_LOSS, A_DISPOSAL_REVENUE, A_ASSET_ACCT,A_ASSET_SPREAD_TYPE"
+ "A_DEPRECIATION_METHOD_ID,A_PERIOD_START,A_PERIOD_END"
+ "A_SALVAGE_VALUE, POSTINGTYPE, A_SPLIT_PERCENT"
+ "FROM I_Asset "
+ "WHERE I_Asset_ID=?) "
+ "WHERE A_Asset_ID=?");
*/
// Set Imported = Y
PreparedStatement pstmt_setImported = DB.prepareStatement
("UPDATE I_Asset SET I_IsImported='Y', "
//+ "Updated= TO_DATE('"+m_DateValue+"','YYYY-MM-DD HH24:MI:SS.FFF') "
+ "Processed='Y' WHERE I_Asset_ID=?",ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE, null);
//
PreparedStatement pstmt = DB.prepareStatement(sql.toString(),ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE, null);
ResultSet rs = pstmt.executeQuery();
int x = 0;
while (rs.next())
{
x=x+1;
int I_Asset_ID = rs.getInt(1);
int A_Asset_ID = rs.getInt(2);
int A_Asset_Acct_ID = 0;
int A_DEPRECIATION_WORKFILE_ID = 0;
int A_ASSET_ADDITION_ID = 0;
int A_ASSET_CHANGE_ID = 0;
boolean newAsset = true;
if (A_Asset_ID == 0)
{
A_Asset_ID = DB.getNextID(m_AD_Client_ID, "A_Asset", null);
A_Asset_Acct_ID = DB.getNextID(m_AD_Client_ID, "A_Asset_Acct", null);
A_DEPRECIATION_WORKFILE_ID = DB.getNextID(m_AD_Client_ID, "A_Depreciation_Workfile", null);
A_ASSET_ADDITION_ID = DB.getNextID(m_AD_Client_ID, "A_Asset_Addition", null);
A_ASSET_CHANGE_ID = DB.getNextID(m_AD_Client_ID, "A_Asset_Change", null);
newAsset = true;
}
else
{
// Check to see if Asset_ID exists
int found = DB.getSQLValue(null,"SELECT COUNT(*) FROM A_ASSET WHERE A_ASSET_ID = " + A_Asset_ID + clientCheck);
if (found == 0)
{
newAsset = true;
A_DEPRECIATION_WORKFILE_ID = DB.getNextID(m_AD_Client_ID, "A_Depreciation_Workfile", null);
A_ASSET_ADDITION_ID = DB.getNextID(m_AD_Client_ID, "A_Asset_Addition", null);
A_ASSET_CHANGE_ID = DB.getNextID(m_AD_Client_ID, "A_Asset_Change", null);
A_Asset_Acct_ID = DB.getNextID(m_AD_Client_ID, "A_Asset_Acct", null);
}
else
{
newAsset = false;
}
}
// Product
if (newAsset) // Insert new Asset
{
pstmt_insertProduct.setInt(1, A_Asset_ID);
pstmt_insertProduct.setInt(2, I_Asset_ID);
pstmt_insertAssetAcct.setInt(1, A_Asset_ID);
pstmt_insertAssetAcct.setInt(2, A_Asset_Acct_ID);
pstmt_insertAssetAcct.setInt(3, I_Asset_ID);
pstmt_insertAssetBal.setInt(1, A_DEPRECIATION_WORKFILE_ID);
pstmt_insertAssetBal.setInt(2, A_Asset_ID);
pstmt_insertAssetBal.setInt(3, I_Asset_ID);
pstmt_insertAssetAdd.setInt(1, A_ASSET_ADDITION_ID);
pstmt_insertAssetAdd.setInt(2, A_Asset_ID);
pstmt_insertAssetAdd.setInt(3, I_Asset_ID);
pstmt_insertAssetChg.setInt(1, A_ASSET_CHANGE_ID);
pstmt_insertAssetChg.setInt(2, A_Asset_ID);
pstmt_insertAssetChg.setInt(3, A_ASSET_ADDITION_ID);
pstmt_insertAssetChg.setInt(4, A_Asset_Acct_ID);
pstmt_insertAssetChg.setInt(5, I_Asset_ID);
try
{
no = pstmt_insertProduct.executeUpdate();
no = pstmt_insertAssetAcct.executeUpdate();
no = pstmt_insertAssetBal.executeUpdate();
no = pstmt_insertAssetAdd.executeUpdate();
no = pstmt_insertAssetChg.executeUpdate();
noInsert++;
}
catch (SQLException ex)
{
sql = new StringBuffer ("UPDATE I_Asset "
+ "SET I_IsImported='E', I_ErrorMsg=").append(DB.TO_STRING("Insert Asset: " + ex.toString()))
.append(" WHERE I_Asset_ID=").append(I_Asset_ID);
DB.executeUpdate(sql.toString(),null);
continue;
}
}
else // Update Asset
{
pstmt_updateProduct.setInt(1, I_Asset_ID);
pstmt_updateProduct.setInt(2, A_Asset_ID);
try
{
//String sqlcall = "UPDATE A_Asset SET(AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Value,Name,Description,Help,A_Asset_Group_ID,M_Product_ID,SerNo,LOT,VersionNo,GuaranteeDate,AssetServiceDate,IsOwned,AssetDepreciationDate, UseLifeYears, UseLifeMonths,LifeUseUnits, UseUnits, Isdisposed, AssetDisposalDate, IsInPosession,LocationComment, M_Locator_ID, C_BPartner_ID, C_BPartner_Location_ID,C_Location_ID, IsDepreciated, IsFullyDepreciated, AD_User_ID,M_AttributeSetInstance_ID, A_Parent_Asset_ID, A_QTY_Original,A_QTY_Current) = (SELECT AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Value,Name,Description,Help,A_Asset_Group_ID,M_Product_ID,SerNo,LOT,VersionNo,GuaranteeDate,AssetServiceDate,IsOwned,AssetDepreciationDate, UseLifeYears, UseLifeMonths,LifeUseUnits, UseUnits, Isdisposed, AssetDisposalDate, IsInPosession,LocationComment, M_Locator_ID, C_BPartner_ID, C_BPartner_Location_ID,C_Location_ID, IsDepreciated, IsFullyDepreciated, AD_User_ID,M_AttributeSetInstance_ID, A_Parent_Asset_ID, A_QTY_Original,A_QTY_Current FROM I_Asset WHERE I_Asset_ID=1000000) WHERE A_Asset_ID=2005000";
//pstmt_updateProduct = prepareStatement(sqlB.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
pstmt_updateProduct.executeUpdate();
noUpdate++;
}
catch (SQLException ex)
{
sql = new StringBuffer ("UPDATE I_Asset "
+ "SET I_IsImported='E', I_ErrorMsg=").append(DB.TO_STRING("Update Asset: " + ex.toString()))
.append(" WHERE I_Asset_ID=").append(I_Asset_ID);
//DB.executeUpdate(sql.toString());
continue;
}
}
pstmt_setImported.setInt(1, I_Asset_ID);
no = pstmt_setImported.executeUpdate();
//conn.commit();
} // for all I_Asset
rs.close();
pstmt.close();
//
pstmt_insertProduct.close();
pstmt_updateProduct.close();
pstmt_setImported.close();
//
//conn.close();
//conn = null;
}
catch (SQLException e)
{
throw new Exception ("ImportAsset3.doIt", e);
}
finally
{
;
}
// Set Error to indicator to not imported
sql = new StringBuffer ("UPDATE I_Asset "
+ "SET I_IsImported='N' "
//+ "Updated= TO_DATE('"+m_DateValue+"','YYYY-MM-DD HH24:MI:SS.FFF') "
+ "WHERE I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(),null);
addLog (0, null, new BigDecimal (no), "@Errors@");
addLog (0, null, new BigDecimal (noInsert), "@A_Asset_ID@: @Inserted@");
addLog (0, null, new BigDecimal (noUpdate), "@A_Asset_ID@: @Updated@");
return "";
} // doIt
} // ImportAsset

View File

@ -1,980 +0,0 @@
/******************************************************************************
* 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
*
* Copyright (C) 2005 Robert KLEIN. robeklein@gmail.com *
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.FA;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import org.compiere.model.MAccount;
import org.compiere.model.MAssetChange;
import org.compiere.model.MJournal;
import org.compiere.model.MJournalBatch;
import org.compiere.model.MJournalLine;
import org.compiere.model.MXIFAJournal;
import org.compiere.model.X_I_FAJournal;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
/**
* Import GL Journal Batch/JournalLine from I_FAJournal
*
* @author Rob Klein
* @version $Id: ImportFAJournal2.java,v 1.0 $
*/
public class ImportFAJournal2 extends SvrProcess
{
/** Client to be imported to */
private int m_AD_Client_ID = 0;
/** Organization to be imported to */
private int m_AD_Org_ID = 0;
/** Acct Schema to be imported to */
private int m_C_AcctSchema_ID = 0;
/** Default Date */
private Timestamp m_DateAcct = null;
/** Delete old Imported */
private boolean m_DeleteOldImported = false;
/** Don't import */
private boolean m_IsValidateOnly = false;
/** Import if no Errors */
private boolean m_IsImportOnlyNoErrors = true;
/** Entry Type */
private String m_EntryType = null;
/** Record ID */
private int p_Depreciation_Entry_ID = 0;
/**
* Prepare - e.g., get Parameters.
*/
/**
* Prepare - e.g., get Parameters.
*/
protected void prepare()
{
ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++)
{
String name = para[i].getParameterName();
p_Depreciation_Entry_ID = getRecord_ID();
if (para[i].getParameter() == null)
;
else if (name.equals("AD_Client_ID"))
m_AD_Client_ID = ((BigDecimal)para[i].getParameter()).intValue();
else if (name.equals("AD_Org_ID"))
m_AD_Org_ID = ((BigDecimal)para[i].getParameter()).intValue();
else if (name.equals("C_AcctSchema_ID"))
m_C_AcctSchema_ID = ((BigDecimal)para[i].getParameter()).intValue();
else if (name.equals("DateAcct"))
m_DateAcct = (Timestamp)para[i].getParameter();
else if (name.equals("IsValidateOnly"))
m_IsValidateOnly = "Y".equals(para[i].getParameter());
else if (name.equals("IsImportOnlyNoErrors"))
m_IsImportOnlyNoErrors = "Y".equals(para[i].getParameter());
else if (name.equals("DeleteOldImported"))
m_DeleteOldImported = "Y".equals(para[i].getParameter());
else
log.info("prepare - Unknown Parameter: " + name);
}
} // prepare
CallableStatement cs;
/**
* Perform process.
* @return Message
* @throws Exception
*/
protected String doIt() throws java.lang.Exception
{
log.info("IsValidateOnly=" + m_IsValidateOnly + ", IsImportOnlyNoErrors=" + m_IsImportOnlyNoErrors);
StringBuffer sql = null;
int no = 0;
String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID;
// Clear imported and processed records
String sqldel = null;
sqldel = "SELECT A_ENTRY_TYPE "
+ "FROM A_DEPRECIATION_ENTRY "
+ "WHERE A_DEPRECIATION_ENTRY.A_DEPRECIATION_ENTRY_ID = ?";
m_EntryType = DB.getSQLValueString(get_TrxName(), sqldel, p_Depreciation_Entry_ID);
if (m_DeleteOldImported)
{
sql = new StringBuffer ("DELETE I_FAJournal "
+ "WHERE I_IsImported='Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Delete Old Impored =" + no);
sql = new StringBuffer ("DELETE A_Depreciation_Exp "
+ "WHERE A_Entry_Type = '"+ m_EntryType + "'"
+ " AND Processed='Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Delete Old Impored =" + no);
}
// **** Copy from Workfile to Entry File ****
log.info("doIt - Depreciation_Build_Entry_ID=" + p_Depreciation_Entry_ID);
if (p_Depreciation_Entry_ID == 0)
throw new IllegalArgumentException("No Record");
//
//X_A_Depreciation_Build DepBuild = new X_A_Depreciation_Build (getCtx(), p_Depreciation_Entry_ID);
String sqlst = null;
sqlst = "SELECT A_DEPRECIATION_EXP.AD_CLIENT_ID, A_DEPRECIATION_EXP.CREATED, A_DEPRECIATION_EXP.CREATEDBY, "
+ "A_DEPRECIATION_EXP.UPDATED, A_DEPRECIATION_EXP.UPDATEDBY, A_DEPRECIATION_EXP.DESCRIPTION, "
+ "A_DEPRECIATION_EXP.AD_ORG_ID, A_DEPRECIATION_EXP.A_ACCOUNT_NUMBER,A_DEPRECIATION_ENTRY.C_CURRENCY_ID, "
+ "A_DEPRECIATION_EXP.EXPENSE, A_DEPRECIATION_EXP.A_ASSET_ID, A_DEPRECIATION_EXP.ISDEPRECIATED, "
+ "A_DEPRECIATION_EXP.PROCESSED, A_DEPRECIATION_EXP.A_DEPRECIATION_EXP_ID, A_DEPRECIATION_EXP.A_Period,"
+ "A_DEPRECIATION_ENTRY.DATEACCT, A_DEPRECIATION_ENTRY.POSTINGTYPE, A_DEPRECIATION_ENTRY.A_ENTRY_TYPE,"
+ "A_DEPRECIATION_ENTRY.PROCESSED AS ENTRY_PROCESS,A_DEPRECIATION_ENTRY.GL_CATEGORY_ID, "
+ "A_DEPRECIATION_ENTRY.C_DOCTYPE_ID,A_DEPRECIATION_ENTRY.C_ACCTSCHEMA_ID, A_DEPRECIATION_ENTRY.A_DEPRECIATION_ENTRY_ID "
+ "FROM A_DEPRECIATION_EXP, A_DEPRECIATION_ENTRY "
+ "WHERE A_DEPRECIATION_EXP.PROCESSED = 'N' AND A_DEPRECIATION_ENTRY.PROCESSED = 'N' AND "
+ "A_DEPRECIATION_EXP.A_PERIOD = A_DEPRECIATION_ENTRY.C_PERIOD_ID "
+ "AND A_DEPRECIATION_ENTRY.POSTINGTYPE = A_DEPRECIATION_EXP.POSTINGTYPE AND "
+ "A_DEPRECIATION_EXP.A_ENTRY_TYPE = A_DEPRECIATION_ENTRY.A_ENTRY_TYPE";
PreparedStatement pstmt = null;
pstmt = DB.prepareStatement (sqlst, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE,get_TrxName());
ResultSet rs = null;
try {
int v_FirstTime = 0;
String v_C_BatchNo = "";
BigDecimal v_AMTSOURCEDR ;
BigDecimal v_AMTSOURCECR ;
int v_ID_START = 10;
rs = pstmt.executeQuery();
while (rs.next())
{
X_I_FAJournal FAInsert = new X_I_FAJournal (getCtx (), 0, get_TrxName());
if (v_FirstTime == 0)
{
v_C_BatchNo = DB.getDocumentNo(rs.getInt("C_DOCTYPE_ID"), get_TrxName(), true, FAInsert);
v_FirstTime = 1;
}
String v_Line_Description = rs.getString("DESCRIPTION") + " - FA # " + rs.getInt("A_ASSET_ID");
if (rs.getBigDecimal("EXPENSE").compareTo(new BigDecimal("0.0"))== 1)
{
v_AMTSOURCEDR = rs.getBigDecimal("EXPENSE") ;
v_AMTSOURCECR = Env.ZERO;
}
else
{
v_AMTSOURCECR = (rs.getBigDecimal("EXPENSE").multiply(new BigDecimal("-1.0")));
v_AMTSOURCEDR = Env.ZERO;
}
FAInsert.setI_IsImported(false);
FAInsert.setProcessed(false);
FAInsert.setBatchDocumentNo(v_C_BatchNo);
FAInsert.setBatchDescription (rs.getString("DESCRIPTION"));
FAInsert.setPostingType(rs.getString("POSTINGTYPE"));
FAInsert.setC_AcctSchema_ID(rs.getInt("C_ACCTSCHEMA_ID"));
FAInsert.setC_DocType_ID( rs.getInt("C_DOCTYPE_ID"));
FAInsert.setGL_Category_ID(rs.getInt("GL_CATEGORY_ID"));
FAInsert.setLine( v_ID_START);
FAInsert.setDateAcct (rs.getTimestamp("DATEACCT"));
FAInsert.setC_Period_ID(rs.getInt("A_Period"));
FAInsert.setDescription ( v_Line_Description);
FAInsert.setAmtSourceDr ( v_AMTSOURCEDR);
FAInsert.setAmtSourceCr ( v_AMTSOURCECR);
FAInsert.setC_Currency_ID ( rs.getInt("C_CURRENCY_ID"));
FAInsert.setQty (Env.ZERO);
FAInsert.setC_ValidCombination_ID ( rs.getInt("A_ACCOUNT_NUMBER"));
FAInsert.setA_Asset_ID ( rs.getInt("A_ASSET_ID"));
FAInsert.setIsDepreciated ( rs.getString("ISDEPRECIATED"));
v_ID_START = v_ID_START+10;
FAInsert.saveEx();
String sql4 = "UPDATE A_DEPRECIATION_EXP SET PROCESSED = 'Y' "
+ " WHERE A_DEPRECIATION_EXP_ID = " + rs.getInt("A_DEPRECIATION_EXP_ID");
no = DB.executeUpdate (sql4,get_TrxName());
sql4 = new String ("UPDATE A_DEPRECIATION_ENTRY SET PROCESSED = 'Y', ISACTIVE = 'N' "
+ " WHERE A_DEPRECIATION_ENTRY_ID = " + rs.getInt("A_DEPRECIATION_ENTRY_ID"));
no = DB.executeUpdate (sql4,get_TrxName());
}
}
catch (Exception e)
{
log.info("ImportFAJournal2"+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Set IsActive, Created/Updated
sql = new StringBuffer ("UPDATE I_FAJournal "
+ "SET IsActive = COALESCE (IsActive, 'Y'),"
+ " Created = COALESCE (Created, SysDate),"
+ " CreatedBy = COALESCE (CreatedBy, 0),"
+ " Updated = COALESCE (Updated, SysDate),"
+ " UpdatedBy = COALESCE (UpdatedBy, 0),"
+ " I_ErrorMsg = NULL,"
+ " I_IsImported = 'N' "
+ "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Reset=" + no);
// Set Client from Name
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET AD_Client_ID=(SELECT c.AD_Client_ID FROM AD_Client c WHERE c.Value=i.ClientValue) "
+ "WHERE (AD_Client_ID IS NULL OR AD_Client_ID=0) AND ClientValue IS NOT NULL"
+ " AND I_IsImported<>'Y'");
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Client from Value=" + no);
// Set Client, Doc Org, AcctSchema, DatAcct
sql = new StringBuffer ("UPDATE I_FAJournal "
+ "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (m_AD_Client_ID).append ("),"
+ " AD_OrgDoc_ID = COALESCE (AD_OrgDoc_ID,").append (m_AD_Org_ID).append ("),");
if (m_C_AcctSchema_ID != 0)
sql.append(" C_AcctSchema_ID = COALESCE (C_AcctSchema_ID,").append (m_C_AcctSchema_ID).append ("),");
if (m_DateAcct != null)
sql.append(" DateAcct = COALESCE (DateAcct,").append (DB.TO_DATE(m_DateAcct)).append ("),");
sql.append(" Updated = COALESCE (Updated, SysDate) "
+ "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Client/DocOrg/Default=" + no);
// Error Doc Org
sql = new StringBuffer ("UPDATE I_FAJournal o "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Doc Org, '"
+ "WHERE (AD_OrgDoc_ID IS NULL OR AD_OrgDoc_ID=0"
+ " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid Doc Org=" + no);
// Set AcctSchema
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET C_AcctSchema_ID=(SELECT a.C_AcctSchema_ID FROM C_AcctSchema a"
+ " WHERE i.AcctSchemaName=a.Name AND i.AD_Client_ID=a.AD_Client_ID) "
+ "WHERE C_AcctSchema_ID IS NULL AND AcctSchemaName IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set AcctSchema from Name=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET C_AcctSchema_ID=(SELECT c.C_AcctSchema1_ID FROM AD_ClientInfo c WHERE c.AD_Client_ID=i.AD_Client_ID) "
+ "WHERE C_AcctSchema_ID IS NULL AND AcctSchemaName IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set AcctSchema from Client=" + no);
// Error AcctSchema
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid AcctSchema, '"
+ "WHERE (C_AcctSchema_ID IS NULL OR C_AcctSchema_ID=0"
+ " OR NOT EXISTS (SELECT * FROM C_AcctSchema a WHERE i.AD_Client_ID=a.AD_Client_ID))"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid AcctSchema=" + no);
// Set DateAcct (mandatory)
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET DateAcct=SysDate "
+ "WHERE DateAcct IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set DateAcct=" + no);
// Document Type
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET C_DocType_ID=(SELECT d.C_DocType_ID FROM C_DocType d"
+ " WHERE d.Name=i.DocTypeName AND d.DocBaseType='GLJ' AND i.AD_Client_ID=d.AD_Client_ID) "
+ "WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set DocType=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocType, '"
+ "WHERE (C_DocType_ID IS NULL OR C_DocType_ID=0"
+ " OR NOT EXISTS (SELECT * FROM C_DocType d WHERE i.AD_Client_ID=d.AD_Client_ID AND d.DocBaseType='GLJ'))"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid DocType=" + no);
// GL Category
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET GL_Category_ID=(SELECT c.GL_Category_ID FROM GL_Category c"
+ " WHERE c.Name=i.CategoryName AND i.AD_Client_ID=c.AD_Client_ID) "
+ "WHERE GL_Category_ID IS NULL AND CategoryName IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set DocType=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Category, '"
+ "WHERE (GL_Category_ID IS NULL OR GL_Category_ID=0)"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid Category=" + no);
// Set Currency
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET C_Currency_ID=(SELECT c.C_Currency_ID FROM C_Currency c"
+ " WHERE c.ISO_Code=i.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) "
+ "WHERE C_Currency_ID IS NULL AND ISO_Code IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Currency from ISO=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET C_Currency_ID=(SELECT a.C_Currency_ID FROM C_AcctSchema a"
+ " WHERE a.C_AcctSchema_ID=i.C_AcctSchema_ID AND a.AD_Client_ID=i.AD_Client_ID)"
+ "WHERE C_Currency_ID IS NULL AND ISO_Code IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Default Currency=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Currency, '"
+ "WHERE (C_Currency_ID IS NULL OR C_Currency_ID=0)"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid Currency=" + no);
// Set Conversion Type
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET ConversionTypeValue='S' "
+ "WHERE C_ConversionType_ID IS NULL AND ConversionTypeValue IS NULL"
+ " AND I_IsImported='N'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set CurrencyType Value to Spot =" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET C_ConversionType_ID=(SELECT c.C_ConversionType_ID FROM C_ConversionType c"
+ " WHERE c.Value=i.ConversionTypeValue AND c.AD_Client_ID IN (0,i.AD_Client_ID)) "
+ "WHERE C_ConversionType_ID IS NULL AND ConversionTypeValue IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set CurrencyType from Value=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid CurrencyType, '"
+ "WHERE (C_ConversionType_ID IS NULL OR C_ConversionType_ID=0) AND ConversionTypeValue IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid CurrencyTypeValue=" + no);
// Set/Overwrite Home Currency Rate
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET CurrencyRate=1"
+ "WHERE EXISTS (SELECT * FROM C_AcctSchema a"
+ " WHERE a.C_AcctSchema_ID=i.C_AcctSchema_ID AND a.C_Currency_ID=i.C_Currency_ID)"
+ " AND C_Currency_ID IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Home CurrencyRate=" + no);
// Set Currency Rate
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET CurrencyRate=(SELECT r.MultiplyRate FROM C_Conversion_Rate r, C_AcctSchema s"
+ " WHERE s.C_AcctSchema_ID=i.C_AcctSchema_ID AND s.AD_Client_ID=i.AD_Client_ID"
+ " AND r.C_Currency_ID=i.C_Currency_ID AND r.C_Currency_ID_TO=s.C_Currency_ID"
+ " AND r.AD_Client_ID=i.AD_Client_ID AND r.AD_Org_ID=i.AD_OrgDoc_ID"
+ " AND r.C_ConversionType_ID=i.C_ConversionType_ID"
+ " AND i.DateAcct BETWEEN r.ValidFrom AND r.ValidTo AND ROWNUM=1"
// ORDER BY ValidFrom DESC
+ ") WHERE CurrencyRate IS NULL OR CurrencyRate=0 AND C_Currency_ID>0"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Org Rate=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET CurrencyRate=(SELECT r.MultiplyRate FROM C_Conversion_Rate r, C_AcctSchema s"
+ " WHERE s.C_AcctSchema_ID=i.C_AcctSchema_ID AND s.AD_Client_ID=i.AD_Client_ID"
+ " AND r.C_Currency_ID=i.C_Currency_ID AND r.C_Currency_ID_TO=s.C_Currency_ID"
+ " AND r.AD_Client_ID=i.AD_Client_ID"
+ " AND r.C_ConversionType_ID=i.C_ConversionType_ID"
+ " AND i.DateAcct BETWEEN r.ValidFrom AND r.ValidTo AND ROWNUM=1"
// ORDER BY ValidFrom DESC
+ ") WHERE CurrencyRate IS NULL OR CurrencyRate=0 AND C_Currency_ID>0"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Client Rate=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Rate, '"
+ "WHERE CurrencyRate IS NULL OR CurrencyRate=0"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - No Rate=" + no);
// Set Period
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET C_Period_ID=(SELECT p.C_Period_ID FROM C_Period p"
+ " INNER JOIN C_Year y ON (y.C_Year_ID=p.C_Year_ID)"
+ " INNER JOIN AD_ClientInfo c ON (c.C_Calendar_ID=y.C_Calendar_ID)"
+ " WHERE c.AD_Client_ID=i.AD_Client_ID"
+ " AND i.DateAcct BETWEEN p.StartDate AND p.EndDate AND p.PeriodType='S' AND ROWNUM=1) "
+ "WHERE C_Period_ID IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Period=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Period, '"
+ "WHERE C_Period_ID IS NULL OR C_Period_ID<>"
+ "(SELECT C_Period_ID FROM C_Period p"
+ " INNER JOIN C_Year y ON (y.C_Year_ID=p.C_Year_ID)"
+ " INNER JOIN AD_ClientInfo c ON (c.C_Calendar_ID=y.C_Calendar_ID) "
+ " WHERE c.AD_Client_ID=i.AD_Client_ID"
+ " AND i.DateAcct BETWEEN p.StartDate AND p.EndDate AND p.PeriodType='S' AND ROWNUM=1)"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid Period=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_ErrorMsg=I_ErrorMsg||'WARN=Period Closed, ' "
+ "WHERE C_Period_ID IS NOT NULL AND NOT EXISTS"
+ " (SELECT * FROM C_PeriodControl pc WHERE pc.C_Period_ID=i.C_Period_ID AND DocBaseType='GLJ' AND PeriodStatus='O') "
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Period Closed=" + no);
// Posting Type
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET PostingType='A' "
+ "WHERE PostingType IS NULL AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Actual PostingType=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid PostingType, ' "
+ "WHERE PostingType IS NULL OR NOT EXISTS"
+ " (SELECT * FROM AD_Ref_List r WHERE r.AD_Reference_ID=125 AND i.PostingType=r.Value)"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid PostingTypee=" + no);
// ** Account Elements (optional) **
// (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0)
// Set Org from Name
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET AD_Org_ID=(SELECT o.AD_Org_ID FROM AD_Org o"
+ " WHERE o.Value=i.OrgValue AND o.IsSummary='N' AND i.AD_Client_ID=o.AD_Client_ID) "
+ "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0) AND OrgValue IS NOT NULL"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'");
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Org from Value=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET AD_Org_ID=AD_OrgDoc_ID "
+ "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0) AND OrgValue IS NULL AND AD_OrgDoc_ID IS NOT NULL AND AD_OrgDoc_ID<>0"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Org from Doc Org=" + no);
// Error Org
sql = new StringBuffer ("UPDATE I_FAJournal o "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '"
+ "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0"
+ " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid Org=" + no);
// Set Account
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET Account_ID=(SELECT ev.C_ElementValue_ID FROM C_ElementValue ev"
+ " INNER JOIN C_Element e ON (e.C_Element_ID=ev.C_Element_ID)"
+ " INNER JOIN C_AcctSchema_Element ase ON (e.C_Element_ID=ase.C_Element_ID AND ase.ElementType='AC')"
+ " WHERE ev.Value=i.AccountValue AND ev.IsSummary='N'"
+ " AND i.C_AcctSchema_ID=ase.C_AcctSchema_ID AND i.AD_Client_ID=ev.AD_Client_ID AND ROWNUM=1) "
+ "WHERE Account_ID IS NULL AND AccountValue IS NOT NULL"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Account from Value=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Account, '"
+ "WHERE (Account_ID IS NULL OR Account_ID=0)"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid Account=" + no);
// Set BPartner
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET C_BPartner_ID=(SELECT bp.C_BPartner_ID FROM C_BPartner bp"
+ " WHERE bp.Value=i.BPartnerValue AND bp.IsSummary='N' AND i.AD_Client_ID=bp.AD_Client_ID) "
+ "WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set BPartner from Value=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid BPartner, '"
+ "WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid BPartner=" + no);
// Set Product
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET M_Product_ID=(SELECT p.M_Product_ID FROM M_Product p"
+ " WHERE (p.Value=i.ProductValue OR p.UPC=i.UPC OR p.SKU=i.SKU)"
+ " AND p.IsSummary='N' AND i.AD_Client_ID=p.AD_Client_ID AND ROWNUM=1) "
+ "WHERE M_Product_ID IS NULL AND (ProductValue IS NOT NULL OR UPC IS NOT NULL OR SKU IS NOT NULL)"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Product from Value=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Product, '"
+ "WHERE M_Product_ID IS NULL AND (ProductValue IS NOT NULL OR UPC IS NOT NULL OR SKU IS NOT NULL)"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid Product=" + no);
// Set Project
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET C_Project_ID=(SELECT p.C_Project_ID FROM C_Project p"
+ " WHERE p.Value=i.ProjectValue AND p.IsSummary='N' AND i.AD_Client_ID=p.AD_Client_ID) "
+ "WHERE C_Project_ID IS NULL AND ProjectValue IS NOT NULL"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set Project from Value=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Project, '"
+ "WHERE C_Project_ID IS NULL AND ProjectValue IS NOT NULL"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid Project=" + no);
// Set TrxOrg
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET AD_OrgTrx_ID=(SELECT o.AD_Org_ID FROM AD_Org o"
+ " WHERE o.Value=i.OrgValue AND o.IsSummary='N' AND i.AD_Client_ID=o.AD_Client_ID) "
+ "WHERE AD_OrgTrx_ID IS NULL AND OrgTrxValue IS NOT NULL"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set OrgTrx from Value=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid OrgTrx, '"
+ "WHERE AD_OrgTrx_ID IS NULL AND OrgTrxValue IS NOT NULL"
+ " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Invalid OrgTrx=" + no);
// Source Amounts
sql = new StringBuffer ("UPDATE I_FAJournal "
+ "SET AmtSourceDr = 0 "
+ "WHERE AmtSourceDr IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),null);
log.info ("doIt - Set 0 Source Dr=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal "
+ "SET AmtSourceCr = 0 "
+ "WHERE AmtSourceCr IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Set 0 Source Cr=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_ErrorMsg=I_ErrorMsg||'WARN=Zero Source Balance, ' "
+ "WHERE (AmtSourceDr-AmtSourceCr)=0"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Zero Source Balance=" + no);
// Accounted Amounts (Only if No Error)
sql = new StringBuffer ("UPDATE I_FAJournal "
+ "SET AmtAcctDr = ROUND(AmtSourceDr * CurrencyRate, 2) " // HARDCODED rounding
+ "WHERE AmtAcctDr IS NULL OR AmtAcctDr=0"
+ " AND I_IsImported='N'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Calculate Acct Dr=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal "
+ "SET AmtAcctCr = ROUND(AmtSourceCr * CurrencyRate, 2) "
+ "WHERE AmtAcctCr IS NULL OR AmtAcctCr=0"
+ " AND I_IsImported='N'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
log.info ("doIt - Calculate Acct Cr=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_ErrorMsg=I_ErrorMsg||'WARN=Zero Acct Balance, ' "
+ "WHERE (AmtSourceDr-AmtSourceCr)<>0 AND (AmtAcctDr-AmtAcctCr)=0"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Zero Acct Balance=" + no);
sql = new StringBuffer ("UPDATE I_FAJournal i "
+ "SET I_ErrorMsg=I_ErrorMsg||'WARN=Check Acct Balance, ' "
+ "WHERE ABS(AmtAcctDr-AmtAcctCr)>100000000" // 100 mio
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate (sql.toString (),get_TrxName());
if (no != 0)
log.info ("doIt - Chack Acct Balance=" + no);
/*********************************************************************/
// Get Balance
sql = new StringBuffer ("SELECT SUM(AmtSourceDr)-SUM(AmtSourceCr), SUM(AmtAcctDr)-SUM(AmtAcctCr) "
+ "FROM I_FAJournal "
+ "WHERE I_IsImported='N'").append (clientCheck);
pstmt = null;
try
{
pstmt = DB.prepareStatement (sql.toString(),get_TrxName());
rs = pstmt.executeQuery ();
if (rs.next ())
{
BigDecimal source = rs.getBigDecimal(1);
BigDecimal acct = rs.getBigDecimal(2);
if (source != null && source.compareTo(Env.ZERO) == 0
&& acct != null && acct.compareTo(Env.ZERO) == 0)
log.info ("doIt - Import Balance = 0");
else
log.info("doIt - Balance Source=" + source + ", Acct=" + acct);
if (source != null)
addLog (0, null, source, "@AmtSourceDr@ - @AmtSourceCr@");
if (acct != null)
addLog (0, null, acct, "@AmtAcctDr@- @AmtAcctCr@");
}
}
catch (SQLException ex)
{
log.info ("doIt - get balance"+ ex);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Count Errors
int errors = DB.getSQLValue(get_TrxName(), "SELECT COUNT(*) FROM I_FAJournal WHERE I_IsImported NOT IN ('Y','N')" + clientCheck);
if (errors != 0)
{
if (m_IsValidateOnly || m_IsImportOnlyNoErrors)
throw new Exception ("@Errors@=" + errors);
}
else if (m_IsValidateOnly)
return "@Errors@=" + errors;
log.info("doIt - Validation Errors=" + errors);
/*********************************************************************/
int noInsert = 0;
int noInsertJournal = 0;
int noInsertLine = 0;
//int oldA_Asset_Id = 0;
MJournalBatch batch = null; // Change Batch per Batch DocumentNo
String BatchDocumentNo = "";
MJournal journal = null;
String JournalDocumentNo = "";
Timestamp DateAcct = null;
// Go through Journal Records
sql = new StringBuffer ("SELECT * FROM I_FAJournal "
+ "WHERE I_IsImported='N'").append (clientCheck)
.append(" ORDER BY BatchDocumentNo, JournalDocumentNo, C_AcctSchema_ID, PostingType, C_DocType_ID, GL_Category_ID, C_Currency_ID, TRUNC(DateAcct), Line, I_FAJournal_ID");
try
{
pstmt = DB.prepareStatement (sql.toString (),get_TrxName());
rs = pstmt.executeQuery ();
//
while (rs.next())
{
MXIFAJournal imp = new MXIFAJournal (getCtx (), rs, get_TrxName());
// Batch
String impBatchDocumentNo = imp.getBatchDocumentNo();
if (impBatchDocumentNo == null)
impBatchDocumentNo = "";
if (batch == null || !BatchDocumentNo.equals(impBatchDocumentNo))
{
BatchDocumentNo = impBatchDocumentNo; // cannot compare real DocumentNo
batch = new MJournalBatch (getCtx(), 0, get_TrxName());
batch.setClientOrg(imp.getAD_Client_ID(), imp.getAD_OrgDoc_ID());
if (imp.getBatchDocumentNo() != null && imp.getBatchDocumentNo().length() > 0)
batch.setDocumentNo (imp.getBatchDocumentNo());
batch.setC_DocType_ID(imp.getC_DocType_ID());
batch.setDateDoc(imp.getDateAcct());
batch.setDateAcct(imp.getDateAcct());
batch.setGL_Category_ID(imp.getGL_Category_ID());
batch.setC_Period_ID(imp.getC_Period_ID());
batch.setC_Currency_ID(imp.getC_Currency_ID());
String description = imp.getBatchDescription();
if (description == null || description.length() == 0)
description = "*Import-";
else
description += " *Import-";
description += new Timestamp(System.currentTimeMillis());
batch.setDescription(description);
if (!batch.save())
{
log.info("doIt - Batch not saved");
break;
}
noInsert++;
journal = null;
}
// Journal
String impJournalDocumentNo = imp.getJournalDocumentNo();
if (impJournalDocumentNo == null)
impJournalDocumentNo = "";
Timestamp impDateAcct = TimeUtil.getDay(imp.getDateAcct());
if (journal == null || !JournalDocumentNo.equals(impJournalDocumentNo)
|| journal.getC_AcctSchema_ID() != imp.getC_AcctSchema_ID()
|| journal.getC_DocType_ID() != imp.getC_DocType_ID()
|| journal.getGL_Category_ID() != imp.getGL_Category_ID()
|| !journal.getPostingType().equals(imp.getPostingType())
|| journal.getC_Currency_ID() != imp.getC_Currency_ID()
|| !impDateAcct.equals(DateAcct)
)
{
JournalDocumentNo = impJournalDocumentNo; // cannot compare real DocumentNo
DateAcct = impDateAcct;
journal = new MJournal (getCtx(), 0, get_TrxName());
journal.setGL_JournalBatch_ID(batch.getGL_JournalBatch_ID());
journal.setClientOrg(imp.getAD_Client_ID(), imp.getAD_OrgDoc_ID());
//
String description = imp.getBatchDescription();
if (description == null || description.length() == 0)
description = "(Import)";
journal.setDescription (description);
if (imp.getJournalDocumentNo() != null && imp.getJournalDocumentNo().length() > 0)
journal.setDocumentNo (imp.getJournalDocumentNo());
//
journal.setC_AcctSchema_ID (imp.getC_AcctSchema_ID());
journal.setC_DocType_ID (imp.getC_DocType_ID());
journal.setGL_Category_ID (imp.getGL_Category_ID());
journal.setPostingType (imp.getPostingType());
journal.setC_ConversionType_ID (imp.getC_ConversionType_ID());
//
journal.setCurrency (imp.getC_Currency_ID(), imp.getC_ConversionType_ID(), imp.getCurrencyRate());
//
journal.setC_Period_ID(imp.getC_Period_ID());
journal.setDateAcct(imp.getDateAcct()); // sets Period if not defined
journal.setDateDoc (imp.getDateAcct());
//
if (!journal.save())
{
log.info("doIt - Journal not saved");
break;
}
noInsertJournal++;
}
// Lines
MJournalLine line = new MJournalLine (journal);
//
line.setDescription(imp.getDescription());
line.setCurrency (imp.getC_Currency_ID(), imp.getC_ConversionType_ID(), imp.getCurrencyRate());
// Set/Get Account Combination
if (imp.getC_ValidCombination_ID() == 0)
{
MAccount acct = MAccount.get(getCtx(), imp.getAD_Client_ID(), imp.getAD_Org_ID(),
imp.getC_AcctSchema_ID(), imp.getAccount_ID(),imp.getC_SubAcct_ID(),
//imp.getC_AcctSchema_ID(), imp.getAccount_ID(),
imp.getM_Product_ID(), imp.getC_BPartner_ID(), imp.getAD_OrgTrx_ID(),
imp.getC_LocFrom_ID(), imp.getC_LocTo_ID(), imp.getC_SalesRegion_ID(),
imp.getC_Project_ID(), imp.getC_Campaign_ID(), imp.getC_Activity_ID(),
imp.getUser1_ID(), imp.getUser2_ID(),imp.getUserElement1_ID(),imp.getUserElement2_ID());
//imp.getUser1_ID(), imp.getUser2_ID());
if (acct != null && acct.get_ID() == 0)
acct.saveEx();
if (acct == null || acct.get_ID() == 0)
{
imp.setI_ErrorMsg("ERROR creating Account");
imp.setI_IsImported(false);
imp.saveEx();
continue;
}
else
{
line.setC_ValidCombination_ID(acct.get_ID());
imp.setC_ValidCombination_ID(acct.get_ID());
}
}
else
line.setC_ValidCombination_ID (imp.getC_ValidCombination_ID());
//
line.setLine (imp.getLine());
line.setAmtSourceCr (imp.getAmtSourceCr());
line.setAmtSourceDr (imp.getAmtSourceDr());
line.setAmtAcct (imp.getAmtAcctDr(), imp.getAmtAcctCr());
line.setDateAcct (imp.getDateAcct());
//
line.setC_UOM_ID(imp.getC_UOM_ID());
line.setQty(imp.getQty());
//
if (line.save())
{
imp.setGL_JournalBatch_ID(batch.getGL_JournalBatch_ID());
imp.setGL_Journal_ID(journal.getGL_Journal_ID());
imp.setGL_JournalLine_ID(line.getGL_JournalLine_ID());
imp.setI_IsImported(true);
imp.setProcessed(true);
sql = new StringBuffer ("UPDATE A_DEPRECIATION_WORKFILE "
+"SET A_ACCUMULATED_DEPR = A_ACCUMULATED_DEPR + ")
.append(imp.getExpenseDr()).append(" - ").append(imp.getExpenseCr())
.append(", A_PERIOD_POSTED = A_CURRENT_PERIOD")
.append(", ASSETDEPRECIATIONDATE = ").append (DB.TO_DATE(imp.getDateAcct()))
.append(" WHERE A_ASSET_ID = ").append(imp.getA_Asset_ID())
.append(" AND ISACTIVE = '").append(imp.getIsDepreciated())
.append("' AND POSTINGTYPE = '").append(imp.getPostingType())
.append("'");
no = DB.executeUpdate(sql.toString(),get_TrxName());
log.info("doIt - SET Accumulated Depreciation =" + no);
// Copy Expense Worktable to Import Worktable
String impgetIsDepreciated = imp.getIsDepreciated();
//impgetIsDepreciated = impgetIsDepreciated + "STOP";
if(impgetIsDepreciated.equals("Y"))
{
cs = DB.prepareCall("{call AD_Sequence_Next(?,?,?)}");
cs.setString(1, "A_Asset_Change");
cs.setInt(2,imp.getAD_Client_ID());
cs.registerOutParameter(3, java.sql.Types.INTEGER);
cs.execute();
MAssetChange assetChange = new MAssetChange (getCtx(), 0, get_TrxName());
assetChange.setA_Asset_Change_ID(cs.getInt(3));
assetChange.set_ValueOfColumn("AD_CLIENT_ID", imp.getAD_Client_ID());
assetChange.setAD_Org_ID(imp.getAD_OrgDoc_ID());
assetChange.set_ValueOfColumn("CREATEDBY", getAD_User_ID());
assetChange.set_ValueOfColumn("UPDATEDBY", getAD_User_ID());
assetChange.setChangeType("DEP");
assetChange.setChangeAmt(imp.getAmtAcctTotal());
assetChange.setA_Asset_ID(imp.getA_Asset_ID());
assetChange.setTextDetails(imp.getDescription());
assetChange.setC_ValidCombination_ID(imp.getC_ValidCombination_ID());
assetChange.setDateAcct(imp.getDateAcct());
assetChange.setPostingType(imp.getPostingType());
assetChange.saveEx();
}
else if(impgetIsDepreciated.equals("B"))
{
cs = DB.prepareCall("{call AD_Sequence_Next(?,?,?)}");
cs.setString(1, "A_Asset_Change");
cs.setInt(2,imp.getAD_Client_ID());
cs.registerOutParameter(3, java.sql.Types.INTEGER);
cs.execute();
MAssetChange assetChange = new MAssetChange (getCtx(), 0, get_TrxName());
assetChange.setA_Asset_Change_ID(cs.getInt(3));
assetChange.set_ValueOfColumn("AD_CLIENT_ID", imp.getAD_Client_ID());
assetChange.setAD_Org_ID(imp.getAD_OrgDoc_ID());
assetChange.set_ValueOfColumn("CREATEDBY", getAD_User_ID());
assetChange.set_ValueOfColumn("UPDATEDBY", getAD_User_ID());
assetChange.setChangeType("BUD");
assetChange.setChangeAmt(imp.getAmtAcctTotal());
assetChange.setA_Asset_ID(imp.getA_Asset_ID());
assetChange.setTextDetails(imp.getDescription());
assetChange.setC_ValidCombination_ID(imp.getC_ValidCombination_ID());
assetChange.setDateAcct(imp.getDateAcct());
assetChange.setPostingType(imp.getPostingType());
assetChange.saveEx();
}
if (imp.save())
noInsertLine++;
}
}
}
catch (Exception e)
{
log.severe("doIt"+ e);
}
// clean up
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Set Error to indicator to not imported
sql = new StringBuffer ("UPDATE I_FAJournal "
+ "SET I_IsImported='N', Updated=SysDate "
+ "WHERE I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(),get_TrxName());
addLog (0, null, new BigDecimal (no), "@Errors@");
//
addLog (0, null, new BigDecimal (noInsert), "@GL_JournalBatch_ID@: @Inserted@");
addLog (0, null, new BigDecimal (noInsertJournal), "@GL_Journal_ID@: @Inserted@");
addLog (0, null, new BigDecimal (noInsertLine), "@GL_JournalLine_ID@: @Inserted@");
//int test = DB.getSQLValue("SELECT 2*2 from dual");
String sql3 = null;
sql3 = "SELECT A_ASSET.A_ASSET_ID, A_ASSET.ISFULLYDEPRECIATED, A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED, "
+ "A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD "
+ "FROM A_DEPRECIATION_WORKFILE,A_ASSET "
+ "WHERE A_ASSET.A_ASSET_ID = A_DEPRECIATION_WORKFILE.A_ASSET_ID "
+ "AND A_DEPRECIATION_WORKFILE.A_PERIOD_POSTED = A_DEPRECIATION_WORKFILE.A_LIFE_PERIOD ";
try
{
pstmt = DB.prepareStatement(sql3,get_TrxName());
rs = pstmt.executeQuery();
while (rs.next()){
String sql4 = "UPDATE A_ASSET SET ISFULLYDEPRECIATED = 'Y' WHERE A_Asset_ID = " + rs.getInt("A_ASSET_ID");
no = DB.executeUpdate (sql4,get_TrxName());
}
}
catch (Exception e)
{
log.info("Post Depreciation"+ e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
} // doIt
} // ImportFAJournal2