📄 msetup.java
字号:
if (no != 1)
Log.error("MSetup.createClient - User Role_OrgAccess NOT created");
// Info - Client Role
m_info.append(Msg.translate(m_lang, "AD_Role_ID")).append("=").append(name).append("\n");
/**
* Create Users
* - Client
* - Org
*/
name = userClient;
if (name == null || name.length() == 0)
name = m_clientName + "Client";
AD_User_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "AD_User");
AD_User_Name = name;
sql = "INSERT INTO AD_User(" + m_stdColumns + ",AD_User_ID,"
+ "Name,Description,Password)"
+ " VALUES (" + m_stdValues + "," + AD_User_ID + ","
+ "'" + name + "','" + name + "','" + name + "')";
no = DB.executeUpdate(sql);
if (no != 1)
{
String err = "MSetup.createClient - Admin User A NOT iserted";
Log.error(err);
m_info.append(err);
return false;
}
// Info
m_info.append(Msg.translate(m_lang, "AD_User_ID")).append("=").append(name).append("/").append(name).append("\n");
name = userOrg;
if (name == null || name.length() == 0)
name = m_clientName + "Org";
AD_User_U_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "AD_User");
AD_User_U_Name = name;
sql = "INSERT INTO AD_User(" + m_stdColumns + ",AD_User_ID,"
+ "Name,Description,Password)"
+ " VALUES (" + m_stdValues + "," + AD_User_U_ID + ","
+ "'" + name + "','" + name + "','" + name + "')";
no = DB.executeUpdate(sql);
if (no != 1)
{
String err = "MSetup.createClient - Org User A NOT iserted";
Log.error(err);
m_info.append(err);
return false;
}
// Info
m_info.append(Msg.translate(m_lang, "AD_User_ID")).append("=").append(name).append("/").append(name).append("\n");
/**
* Create User-Role
*/
// ClientUser - Admin & User
sql = "INSERT INTO AD_User_Roles(" + m_stdColumns + ",AD_User_ID,AD_Role_ID)"
+ " VALUES (" + m_stdValues + "," + AD_User_ID + "," + AD_Role_ID + ")";
no = DB.executeUpdate(sql);
if (no != 1)
Log.error("MSetup.createClient - UserRole ClientUser+Admin NOT iserted");
sql = "INSERT INTO AD_User_Roles(" + m_stdColumns + ",AD_User_ID,AD_Role_ID)"
+ " VALUES (" + m_stdValues + "," + AD_User_ID + "," + AD_Role_ID_U + ")";
no = DB.executeUpdate(sql);
if (no != 1)
Log.error("MSetup.createClient - UserRole ClientUser+User NOT iserted");
// OrgUser - User
sql = "INSERT INTO AD_User_Roles(" + m_stdColumns + ",AD_User_ID,AD_Role_ID)"
+ " VALUES (" + m_stdValues + "," + AD_User_U_ID + "," + AD_Role_ID_U + ")";
no = DB.executeUpdate(sql);
if (no != 1)
Log.error("MSetup.createClient - UserRole OrgUser+Org NOT iserted");
// SuperUser(100) - Admin & User
sql = "INSERT INTO AD_User_Roles(" + m_stdColumns + ",AD_User_ID,AD_Role_ID)"
+ " VALUES (" + m_stdValues + ",100," + AD_Role_ID + ")";
no = DB.executeUpdate(sql);
if (no != 1)
Log.error("MSetup.createClient - UserRole SuperUser+Admin NOT iserted");
sql = "INSERT INTO AD_User_Roles(" + m_stdColumns + ",AD_User_ID,AD_Role_ID)"
+ " VALUES (" + m_stdValues + ",100," + AD_Role_ID_U + ")";
no = DB.executeUpdate(sql);
if (no != 1)
Log.error("MSetup.createClient - UserRole SuperUser+User NOT iserted");
return true;
} // createClient
/*************************************************************************/
/**
* Create Accounting elements.
* - Calendar
* - Account Trees
* - Account Values
* - Accounting Schema
* - Default Accounts
*
* @param newC_Currency_ID currency
* @param curName currency name
* @param hasProduct has product segment
* @param hasBPartner has bp segment
* @param hasProject has project segment
* @param hasMCampaign has campaign segment
* @param hasSRegion has sales region segment
* @param AccountingFile file name of accounting file
* @return true if created
*/
public boolean createAccounting(int newC_Currency_ID, String curName,
boolean hasProduct, boolean hasBPartner, boolean hasProject,
boolean hasMCampaign, boolean hasSRegion,
File AccountingFile)
{
Log.trace(Log.l3_Util, "MSetup.createAccount");
//
C_Currency_ID = newC_Currency_ID;
m_hasProject = hasProject;
m_hasMCampaign = hasMCampaign;
m_hasSRegion = hasSRegion;
// Standard variables
m_info = new StringBuffer();
String name = null;
StringBuffer sqlCmd = null;
int no = 0;
/**
* Create Calendar
*/
C_Calendar_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_Calendar");
name = m_clientName + " " + Msg.translate(m_lang, "C_Calendar_ID");
sqlCmd = new StringBuffer("INSERT INTO C_Calendar(");
sqlCmd.append(m_stdColumns).append(",C_Calendar_ID,Name)").append(" VALUES (");
sqlCmd.append(m_stdValues).append(",").append(C_Calendar_ID).append(",'").append(name).append("')");
no = DB.executeUpdate(sqlCmd.toString());
if (no != 1)
{
String err = "MSetup.createAccounting - Calendar NOT iserted";
Log.error(err);
m_info.append(err);
return false;
}
// Info
m_info.append(Msg.translate(m_lang, "C_Calendar_ID")).append("=").append(name).append("\n");
// Year
int C_Year_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_Year");
sqlCmd = new StringBuffer ("INSERT INTO C_Year ");
sqlCmd.append("(C_Year_ID,").append(m_stdColumns).append(",");
sqlCmd.append("Year,C_Calendar_ID) VALUES (");
sqlCmd.append(C_Year_ID).append(",").append(m_stdValues).append(",");
sqlCmd.append("TO_CHAR(SysDate,'YYYY'),").append(C_Calendar_ID).append(")");
no = DB.executeUpdate(sqlCmd.toString());
if (no != 1)
Log.error("MSetup.createAccounting - Year NOT inserted");
/** @todo Create Periods */
// Create Account Elements
int C_Element_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_Element");
name = m_clientName + " " + Msg.translate(m_lang, "Account_ID");
sqlCmd = new StringBuffer ("INSERT INTO C_ELEMENT(");
sqlCmd.append(m_stdColumns).append(",C_Element_ID,Name,Description,")
.append("VFormat,ElementType,IsBalancing,IsNaturalAccount,AD_Tree_ID)").append(" VALUES (");
sqlCmd.append(m_stdValues).append(",").append(C_Element_ID).append(",'").append(name).append("','").append(name).append("',")
.append("NULL,'A','N','Y',").append(AD_Tree_Account_ID).append(")");
no = DB.executeUpdate(sqlCmd.toString());
if (no != 1)
{
String err = "MSetup.createAccounting - Acct Element NOT iserted";
Log.error(err);
m_info.append(err);
return false;
}
m_info.append(Msg.translate(m_lang, "C_Element_ID")).append("=").append(name).append("\n");
// Create Account Values
m_nap = new NaturalAccountMap();
String errMsg = m_nap.parseFile(AccountingFile);
if (errMsg.length() != 0)
{
Log.error(errMsg);
m_info.append(errMsg);
return false;
}
if (m_nap.createAccounts(AD_Client_ID, AD_Org_ID, C_Element_ID))
m_info.append(Msg.translate(m_lang, "C_ElementValue_ID")).append(" # ").append(m_nap.size()).append("\n");
else
{
String err = "MSetup.createAccounting - Acct Element Values NOT iserted";
Log.error(err);
m_info.append(err);
return false;
}
int C_ElementValue_ID = m_nap.getC_ElementValue_ID("DEFAULT_ACCT");
Log.trace(Log.l4_Data, "C_ElementValue_ID=" + C_ElementValue_ID);
/**
* Create AccountingSchema
*/
C_AcctSchema_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_AcctSchema");
//
String GAAP = "US"; // AD_Reference_ID=123
String CostingMethod = "A"; // AD_Reference_ID=122
name = m_clientName + " " + GAAP + "/" + CostingMethod + "/" + curName;
//
sqlCmd = new StringBuffer ("INSERT INTO C_AcctSchema(");
sqlCmd.append(m_stdColumns).append(",C_AcctSchema_ID,Name,")
.append("GAAP,IsAccrual,CostingMethod,C_Currency_ID,")
.append("AutoPeriodControl,Separator,HasAlias,HasCombination)")
.append(" VALUES (");
sqlCmd.append(m_stdValues).append(",").append(C_AcctSchema_ID).append(",'").append(name).append("',")
.append("'").append(GAAP).append("','Y','").append(CostingMethod).append("',").append(C_Currency_ID).append(",")
.append("'N','-','Y','N')");
no = DB.executeUpdate(sqlCmd.toString());
if (no != 1)
{
String err = "MSetup.createAccounting - AcctSchema NOT iserted";
Log.error(err);
m_info.append(err);
return false;
}
// Info
m_info.append(Msg.translate(m_lang, "C_AcctSchema_ID")).append("=").append(name).append("\n");
/**
* Create AccountingSchema Elements (Structure)
*/
String sql2 = null;
if (Env.isBaseLanguage(m_lang, "AD_Reference")) // Get TreeTypes & Name
sql2 = "SELECT Value, Name FROM AD_Ref_List WHERE AD_Reference_ID=181";
else
sql2 = "SELECT l.Value, t.Name FROM AD_Ref_List l, AD_Ref_List_Trl t "
+ "WHERE l.AD_Reference_ID=181 AND l.AD_Ref_List_ID=t.AD_Ref_List_ID";
//
int Element_OO=0, Element_AC=0, Element_PR=0, Element_BP=0, Element_PJ=0,
Element_MC=0, Element_SR=0;
try
{
Statement stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(sql2);
while (rs.next())
{
String ElementType = rs.getString(1);
name = rs.getString(2);
//
String IsMandatory = null;
String IsBalanced = "N";
int SeqNo = 0;
int C_AcctSchema_Element_ID = 0;
if (ElementType.equals("OO"))
{
C_AcctSchema_Element_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_AcctSchema_Element");
Element_OO = C_AcctSchema_Element_ID;
IsMandatory = "Y";
IsBalanced = "Y";
SeqNo = 10;
}
else if (ElementType.equals("AC"))
{
C_AcctSchema_Element_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_AcctSchema_Element");
Element_AC = C_AcctSchema_Element_ID;
IsMandatory = "Y";
SeqNo = 20;
}
else if (ElementType.equals("PR") && hasProduct)
{
C_AcctSchema_Element_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_AcctSchema_Element");
Element_PR = C_AcctSchema_Element_ID;
IsMandatory = "N";
SeqNo = 30;
}
else if (ElementType.equals("BP") && hasBPartner)
{
C_AcctSchema_Element_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_AcctSchema_Element");
Element_BP = C_AcctSchema_Element_ID;
IsMandatory = "N";
SeqNo = 40;
}
else if (ElementType.equals("PJ") && hasProject)
{
C_AcctSchema_Element_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_AcctSchema_Element");
Element_PJ = C_AcctSchema_Element_ID;
IsMandatory = "N";
SeqNo = 50;
}
else if (ElementType.equals("MC") && hasMCampaign)
{
C_AcctSchema_Element_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_AcctSchema_Element");
Element_MC = C_AcctSchema_Element_ID;
IsMandatory = "N";
SeqNo = 60;
}
else if (ElementType.equals("SR") && hasSRegion)
{
C_AcctSchema_Element_ID = DB.getKeyNextNo(AD_Client_ID, CompiereSys, "C_AcctSchema_Element");
Element_SR = C_AcctSchema_Element_ID;
IsMandatory = "N";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -