📄 macctschema.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Accounting Schema Model (base)
*
* @author Jorg Janke
* @version $Id: MAcctSchema.java,v 1.30 2005/11/25 21:58:30 jjanke Exp $
*/
public class MAcctSchema extends X_C_AcctSchema
{
/**
* Get AccountSchema of Client
* @param ctx context
* @param C_AcctSchema_ID schema id
* @return Accounting schema
*/
public static MAcctSchema get (Properties ctx, int C_AcctSchema_ID)
{
return get(ctx, C_AcctSchema_ID, null);
} // get
/**
* Get AccountSchema of Client
* @param ctx context
* @param C_AcctSchema_ID schema id
* @param trxName optional trx
* @return Accounting schema
*/
public static MAcctSchema get (Properties ctx, int C_AcctSchema_ID, String trxName)
{
// Check Cache
Integer key = new Integer(C_AcctSchema_ID);
MAcctSchema retValue = (MAcctSchema)s_cache.get(key);
if (retValue != null)
return retValue;
retValue = new MAcctSchema (ctx, C_AcctSchema_ID, trxName);
if (trxName == null)
s_cache.put(key, retValue);
return retValue;
} // get
/**
* Get AccountSchema of Client
* @param ctx context
* @param AD_Client_ID client or 0 for all
* @return Array of AcctSchema of Client
*/
public static MAcctSchema[] getClientAcctSchema (Properties ctx, int AD_Client_ID)
{
return getClientAcctSchema(ctx, AD_Client_ID, null);
} // getClientAcctSchema
/**
* Get AccountSchema of Client
* @param ctx context
* @param AD_Client_ID client or 0 for all
* @param trxName optional trx
* @return Array of AcctSchema of Client
*/
public static MAcctSchema[] getClientAcctSchema (Properties ctx, int AD_Client_ID, String trxName)
{
// Check Cache
Integer key = new Integer(AD_Client_ID);
if (s_schema.containsKey(key))
return (MAcctSchema[])s_schema.get(key);
// Create New
ArrayList<MAcctSchema> list = new ArrayList<MAcctSchema>();
MClientInfo info = MClientInfo.get(ctx, AD_Client_ID, trxName);
MAcctSchema as = MAcctSchema.get (ctx, info.getC_AcctSchema1_ID(), trxName);
if (as.get_ID() != 0 && trxName == null)
list.add(as);
// Other
String sql = "SELECT C_AcctSchema_ID FROM C_AcctSchema acs "
+ "WHERE IsActive='Y'"
+ " AND EXISTS (SELECT * FROM C_AcctSchema_GL gl WHERE acs.C_AcctSchema_ID=gl.C_AcctSchema_ID)"
+ " AND EXISTS (SELECT * FROM C_AcctSchema_Default d WHERE acs.C_AcctSchema_ID=d.C_AcctSchema_ID)";
if (AD_Client_ID != 0)
sql += " AND AD_Client_ID=?";
sql += " ORDER BY C_AcctSchema_ID";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, trxName);
if (AD_Client_ID != 0)
pstmt.setInt(1, AD_Client_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
int id = rs.getInt(1);
if (id != info.getC_AcctSchema1_ID()) // already in list
{
as = MAcctSchema.get (ctx, id, trxName);
if (as.get_ID() != 0 && trxName == null)
list.add(as);
}
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.log(Level.SEVERE, sql, e);
}
// Save
MAcctSchema[] retValue = new MAcctSchema [list.size()];
list.toArray(retValue);
if (trxName == null)
s_schema.put(key, retValue);
return retValue;
} // getClientAcctSchema
/** Cache of Client AcctSchema Arrays **/
private static CCache<Integer,MAcctSchema[]> s_schema = new CCache<Integer,MAcctSchema[]>("AD_ClientInfo", 3); // 3 clients
/** Cache of AcctSchemas **/
private static CCache<Integer,MAcctSchema> s_cache = new CCache<Integer,MAcctSchema>("C_AcctSchema", 3); // 3 accounting schemas
/** Logger */
private static CLogger s_log = CLogger.getCLogger(MAcctSchema.class);
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param C_AcctSchema_ID id
*/
public MAcctSchema (Properties ctx, int C_AcctSchema_ID, String trxName)
{
super (ctx, C_AcctSchema_ID, trxName);
if (C_AcctSchema_ID == 0)
{
// setC_Currency_ID (0);
// setName (null);
setAutoPeriodControl (true);
setPeriod_OpenFuture(2);
setPeriod_OpenHistory(2);
setCostingMethod (COSTINGMETHOD_StandardCosting);
setCostingLevel(COSTINGLEVEL_Client);
setIsAdjustCOGS(false);
setGAAP (GAAP_InternationalGAAP);
setHasAlias (true);
setHasCombination (false);
setIsAccrual (true); // Y
setCommitmentType(COMMITMENTTYPE_None);
setIsDiscountCorrectsTax (false);
setIsTradeDiscountPosted (false);
setIsPostServices(false);
setIsExplicitCostAdjustment(false);
setSeparator ("-"); // -
}
} // MAcctSchema
/**
* Load Constructor
* @param ctx context
* @param rs result set
*/
public MAcctSchema (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MAcctSchema
/**
* Parent Constructor
* @param client client
* @param currency currency
*/
public MAcctSchema (MClient client, KeyNamePair currency)
{
this (client.getCtx(), 0, client.get_TrxName());
setClientOrg(client);
setC_Currency_ID (currency.getKey());
setName (client.getName() + " " + getGAAP() + "/" + get_ColumnCount() + " " + currency.getName());
} // MAcctSchema
/** Element List */
private MAcctSchemaElement[] m_elements = null;
/** GL Info */
private MAcctSchemaGL m_gl = null;
/** Default Info */
private MAcctSchemaDefault m_default = null;
private MAccount m_SuspenseError_Acct = null;
private MAccount m_CurrencyBalancing_Acct = null;
private MAccount m_DueTo_Acct = null;
private MAccount m_DueFrom_Acct = null;
/** Accounting Currency Precision */
private int m_stdPrecision = -1;
/** Costing Currency Precision */
private int m_costPrecision = -1;
/** Only Post Org */
private MOrg m_onlyOrg = null;
/** Only Post Org Childs */
private Integer[] m_onlyOrgs = null;
/**************************************************************************
* AcctSchema Elements
* @return ArrayList of AcctSchemaElement
*/
public MAcctSchemaElement[] getAcctSchemaElements()
{
if (m_elements == null)
m_elements = MAcctSchemaElement.getAcctSchemaElements(this);
return m_elements;
} // getAcctSchemaElements
/**
* Get AcctSchema Element
* @param elementType segment type - AcctSchemaElement.ELEMENTTYPE_
* @return AcctSchemaElement
*/
public MAcctSchemaElement getAcctSchemaElement (String elementType)
{
if (m_elements == null)
getAcctSchemaElements();
for (int i = 0; i < m_elements.length; i++)
{
MAcctSchemaElement ase = m_elements[i];
if (ase.getElementType().equals(elementType))
return ase;
}
return null;
} // getAcctSchemaElement
/**
* Has AcctSchema Element
* @param segmentType segment type - AcctSchemaElement.SEGMENT_
* @return true if schema has segment type
*/
public boolean isAcctSchemaElement (String segmentType)
{
return getAcctSchemaElement(segmentType) != null;
} // isAcctSchemaElement
/**
* Get AcctSchema GL info
* @return GL info
*/
public MAcctSchemaGL getAcctSchemaGL()
{
if (m_gl == null)
m_gl = MAcctSchemaGL.get(getCtx(), getC_AcctSchema_ID());
if (m_gl == null)
throw new IllegalStateException("No GL Definition for C_AcctSchema_ID=" + getC_AcctSchema_ID());
return m_gl;
} // getAcctSchemaGL
/**
* Get AcctSchema Defaults
* @return defaults
*/
public MAcctSchemaDefault getAcctSchemaDefault()
{
if (m_default == null)
m_default = MAcctSchemaDefault.get(getCtx(), getC_AcctSchema_ID());
if (m_default == null)
throw new IllegalStateException("No Default Definition for C_AcctSchema_ID=" + getC_AcctSchema_ID());
return m_default;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -