Search in sources :

Example 1 with MSetup

use of org.compiere.model.MSetup in project adempiere by adempiere.

the class VSetup method run.

//	createSetup
/**
	 * 	Create Setup Batch Part.
	 * 	if done - disposes window
	 */
public void run() {
    MSetup ms = new MSetup(Env.getCtx(), m_WindowNo);
    m_frame.setBusyTimer(45);
    //  Step 1
    boolean ok = ms.createClient(fClientName.getText(), fOrgValue.getText(), fOrgName.getText(), fUserClient.getText(), fUserOrg.getText(), null, null, null, null, null, null, null, 0);
    String info = ms.getInfo();
    if (ok) {
        //  Generate Accounting
        KeyNamePair currency = (KeyNamePair) fCurrency.getSelectedItem();
        if (!ms.createAccounting(currency, fProduct.isSelected(), fBPartner.isSelected(), fProject.isSelected(), fMCampaign.isSelected(), fSRegion.isSelected(), null, 0, m_file)) {
            ADialog.error(m_WindowNo, this, "AccountSetupError");
            dispose();
        } else {
            //  Generate Entities
            KeyNamePair p = (KeyNamePair) fCountry.getSelectedItem();
            int C_Country_ID = p.getKey();
            p = (KeyNamePair) fRegion.getSelectedItem();
            int C_Region_ID = p.getKey();
            ms.createEntities(C_Country_ID, fCity.getText(), C_Region_ID, currency.getKey(), null, null);
            info += ms.getInfo();
            //	Create Print Documents
            PrintUtil.setupPrintForm(ms.getAD_Client_ID());
        }
    }
    ADialog.info(m_WindowNo, this, "VSetup", info);
    dispose();
}
Also used : MSetup(org.compiere.model.MSetup) KeyNamePair(org.compiere.util.KeyNamePair)

Example 2 with MSetup

use of org.compiere.model.MSetup 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@";
}
Also used : MCountry(org.compiere.model.MCountry) Query(org.compiere.model.Query) MCity(org.compiere.model.MCity) MCurrency(org.compiere.model.MCurrency) MLanguage(org.compiere.model.MLanguage) AdempiereException(org.adempiere.exceptions.AdempiereException) AdempiereException(org.adempiere.exceptions.AdempiereException) MSetup(org.compiere.model.MSetup) KeyNamePair(org.compiere.util.KeyNamePair) File(java.io.File)

Aggregations

MSetup (org.compiere.model.MSetup)2 KeyNamePair (org.compiere.util.KeyNamePair)2 File (java.io.File)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 MCity (org.compiere.model.MCity)1 MCountry (org.compiere.model.MCountry)1 MCurrency (org.compiere.model.MCurrency)1 MLanguage (org.compiere.model.MLanguage)1 Query (org.compiere.model.Query)1