use of org.compiere.model.MCity in project adempiere by adempiere.
the class InitialClientSetup method doIt.
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("InitialClientSetup" + ": ClientName=" + getClientName() + ", OrgValue=" + getOrgKey() + ", OrgName=" + getOrganizationName() + ", AdminUserName=" + getAdministrativeUserName() + ", NormalUserName=" + getNormalUserName() + ", C_Currency_ID=" + getCurrencyId() + ", C_Country_ID=" + getCountryId() + ", C_Region_ID=" + getRegionId() + ", CityName=" + getCityName() + ", C_City_ID=" + getCityId() + ", IsUseBPDimension=" + isBPAccounting() + ", IsUseProductDimension=" + isProductAccounting() + ", IsUseProjectDimension=" + isProjectAccounting() + ", IsUseCampaignDimension=" + isCampaignAccounting() + ", IsUseSalesRegionDimension=" + isSalesRegionAccounting() + ", ChartofAccountsFile=" + getChartofAccountsFile());
// Validate Mandatory parameters
if (getClientName() == null || getClientName().length() == 0 || getOrganizationName() == null || getOrganizationName().length() == 0 || getCurrencyId() <= 0 || getCountryId() <= 0 || getChartofAccountsFile() == null || getChartofAccountsFile().length() == 0)
throw new IllegalArgumentException("Missing required parameters");
// Unique Client Name
if (DB.executeUpdate("UPDATE AD_Client SET CreatedBy=0 WHERE Name=?", new Object[] { getClientName() }, false, null) != 0)
throw new AdempiereException("@NotUnique@ " + getClientName());
// Unique User Names
if (DB.executeUpdate("UPDATE AD_User SET CreatedBy=0 WHERE Name=?", new Object[] { getAdministrativeUserName() }, false, null) != 0)
throw new AdempiereException("@NotUnique@ " + getAdministrativeUserName());
if (DB.executeUpdate("UPDATE AD_User SET CreatedBy=0 WHERE Name=?", new Object[] { getNormalUserName() }, false, null) != 0)
throw new AdempiereException("@NotUnique@ " + getNormalUserName());
// City_ID overrides CityName if both used
if (getCityId() > 0) {
MCity city = MCity.get(getCtx(), getCityId());
if (!city.getName().equals(getCityName())) {
log.info("City name changed from " + getCityName() + " to " + city.getName());
setCityName(city.getName());
}
}
// Validate existence and read permissions on CoA file
File chartofAccountsFile = new File(getChartofAccountsFile());
if (!chartofAccountsFile.exists())
throw new AdempiereException("CoaFile " + getChartofAccountsFile() + " does not exist");
if (!chartofAccountsFile.canRead())
throw new AdempiereException("Cannot read CoaFile " + getChartofAccountsFile());
if (!chartofAccountsFile.isFile())
throw new AdempiereException("CoaFile " + getChartofAccountsFile() + " is not a file");
if (chartofAccountsFile.length() <= 0L)
throw new AdempiereException("CoaFile " + getChartofAccountsFile() + " is empty");
// Process
MSetup setup = null;
MCountry country = MCountry.get(getCtx(), getCountryId());
try {
Class<?> ppClass = Class.forName("org.compiere.model.MSetup_" + country.getCountryCode());
if (ppClass != null)
setup = (MSetup) ppClass.newInstance();
} catch (// NoClassDefFound
Exception e) {
// ignore as country specific setup class may not exist
}
if (setup == null)
setup = new MSetup();
setup.initialize(Env.getCtx(), WINDOW_THIS_PROCESS);
if (!setup.createClient(getClientName(), getOrgKey(), getOrganizationName(), getAdministrativeUserName(), getNormalUserName(), getPhone(), getPhone2(), getFax(), getEMailAddress(), getTaxID(), getDUNS(), getLogo(), getCountryId())) {
setup.rollback();
throw new AdempiereException("Create client failed");
}
addLog(setup.getInfo());
// Generate Accounting
MCurrency currency = MCurrency.get(getCtx(), getCurrencyId());
KeyNamePair currencyKeyNamePair = new KeyNamePair(getCurrencyId(), currency.getDescription());
if (!setup.createAccounting(currencyKeyNamePair, isProductAccounting(), isBPAccounting(), isProjectAccounting(), isCampaignAccounting(), isSalesRegionAccounting(), getStartDate(), getHistoryYears(), chartofAccountsFile)) {
setup.rollback();
throw new AdempiereException("@AccountSetupError@");
}
// Generate Entities
if (!setup.createEntities(getCountryId(), getCityName(), getRegionId(), getCurrencyId(), getZIP(), getAddress1())) {
setup.rollback();
throw new AdempiereException("@AccountSetupError@");
}
// Create Bank
if (!Util.isEmpty(getBankName()) && !Util.isEmpty(getRoutingNo()) && !Util.isEmpty(getAccountNo())) {
setup.createBank(getBankName(), getRoutingNo(), getAccountNo(), getCurrencyId());
}
// load chart of accounts
if (!setup.importChart(chartofAccountsFile)) {
setup.rollback();
throw new AdempiereException("@AccountSetupError@");
}
addLog(setup.getInfo());
// Create Print Documents
PrintUtil.setupPrintForm(setup.getAD_Client_ID());
// Update translation after create a new tenant
//Adempiere-53 Changes
String whereClause = MLanguage.COLUMNNAME_IsSystemLanguage + "='Y' AND " + MLanguage.COLUMNNAME_IsActive + "='Y'";
List<MLanguage> list = new Query(Env.getCtx(), MLanguage.Table_Name, whereClause, get_TrxName()).list();
for (MLanguage lang : list) {
log.fine("Updating Translation - " + lang);
lang.maintain(true);
}
return "@OK@";
}
Aggregations