use of org.compiere.model.MCountry 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@";
}
use of org.compiere.model.MCountry in project adempiere by adempiere.
the class VLocationDialog method action_OK.
/**
* OK - check for changes (save them) & Exit
*/
private boolean action_OK() {
m_location.setAddress1(fAddress1.getText());
m_location.setAddress2(fAddress2.getText());
m_location.setAddress3(fAddress3.getText());
m_location.setAddress4(fAddress4.getText());
m_location.setCity(fCity.getText());
m_location.setC_City_ID(fCityAutoCompleter.getC_City_ID());
m_location.setPostal(fPostal.getText());
m_location.setPostal_Add(fPostalAdd.getText());
// Country/Region
MCountry c = (MCountry) fCountry.getSelectedItem();
m_location.setCountry(c);
if (m_location.getCountry().isHasRegion()) {
MRegion r = (MRegion) fRegion.getSelectedItem();
m_location.setRegion(r);
} else
m_location.setC_Region_ID(0);
// Save changes
if (m_location.save()) {
return true;
} else {
return false;
}
}
use of org.compiere.model.MCountry in project adempiere by adempiere.
the class VLocationDialog method initLocation.
// jbInit
/**
* Dynamic Init & fill fields - Called when Country changes!
*/
private void initLocation() {
MCountry country = m_location.getCountry();
log.fine(country.getName() + ", Region=" + country.isHasRegion() + " " + country.getCaptureSequence() + ", C_Location_ID=" + m_location.getC_Location_ID());
// new Country
if (country.getC_Country_ID() != s_oldCountry_ID) {
fRegion.removeAllItems();
if (country.isHasRegion()) {
for (MRegion region : MRegion.getRegions(Env.getCtx(), country.getC_Country_ID())) {
fRegion.addItem(region);
}
if (m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName) != null && m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName).trim().length() > 0)
lRegion.setText(m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName));
else
lRegion.setText(Msg.getMsg(Env.getCtx(), "Region"));
}
s_oldCountry_ID = m_location.getC_Country_ID();
}
if (m_location.getC_Region_ID() > 0 && m_location.getC_Region().getC_Country_ID() == country.getC_Country_ID()) {
fRegion.setSelectedItem(m_location.getC_Region());
} else {
fRegion.setSelectedItem(null);
m_location.setC_Region_ID(0);
}
if (country.isHasRegion() && m_location.getC_Region_ID() > 0) {
Env.setContext(Env.getCtx(), m_WindowNo, Env.TAB_INFO, "C_Region_ID", String.valueOf(m_location.getC_Region_ID()));
} else {
Env.setContext(Env.getCtx(), m_WindowNo, Env.TAB_INFO, "C_Region_ID", "0");
}
Env.setContext(Env.getCtx(), m_WindowNo, Env.TAB_INFO, "C_Country_ID", String.valueOf(country.get_ID()));
fCityAutoCompleter.fillList();
gbc.anchor = GridBagConstraints.NORTHWEST;
// line
gbc.gridy = 0;
gbc.gridx = 0;
gbc.gridwidth = 1;
gbc.insets = fieldInsets;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 0;
gbc.weighty = 0;
mainPanel.removeAll();
// top gap
mainPanel.add(Box.createVerticalStrut(5), gbc);
int line = 1;
// sequence of City Postal Region - @P@ @C@ - @C@, @R@ @P@
String ds = country.getCaptureSequence();
if (ds == null || ds.length() == 0) {
log.log(Level.SEVERE, "CaptureSequence empty - " + country);
// @C@, @P@
ds = "";
}
isCityMandatory = false;
isRegionMandatory = false;
isAddress1Mandatory = false;
isAddress2Mandatory = false;
isAddress3Mandatory = false;
isAddress4Mandatory = false;
isPostalMandatory = false;
isPostalAddMandatory = false;
StringTokenizer st = new StringTokenizer(ds, "@", false);
while (st.hasMoreTokens()) {
String s = st.nextToken();
if (s.startsWith("CO")) {
// Country Last
addLine(line++, lCountry, fCountry);
// disable online if this country doesn't have post code lookup
if (m_location.getCountry().isPostcodeLookup()) {
addLine(line++, lOnline, fOnline);
}
} else if (s.startsWith("A1")) {
addLine(line++, lAddress1, fAddress1);
isAddress1Mandatory = s.endsWith("!");
} else if (s.startsWith("A2")) {
addLine(line++, lAddress2, fAddress2);
isAddress2Mandatory = s.endsWith("!");
} else if (s.startsWith("A3")) {
addLine(line++, lAddress3, fAddress3);
isAddress3Mandatory = s.endsWith("!");
} else if (s.startsWith("A4")) {
addLine(line++, lAddress4, fAddress4);
isAddress4Mandatory = s.endsWith("!");
} else if (s.startsWith("C")) {
addLine(line++, lCity, fCity);
isCityMandatory = s.endsWith("!");
} else if (s.startsWith("P")) {
addLine(line++, lPostal, fPostal);
isPostalMandatory = s.endsWith("!");
} else if (s.startsWith("A")) {
addLine(line++, lPostalAdd, fPostalAdd);
isPostalAddMandatory = s.endsWith("!");
} else if (s.startsWith("R") && m_location.getCountry().isHasRegion()) {
addLine(line++, lRegion, fRegion);
isRegionMandatory = s.endsWith("!");
}
}
// Fill it
if (m_location.getC_Location_ID() != 0) {
fAddress1.setText(m_location.getAddress1());
fAddress2.setText(m_location.getAddress2());
fAddress3.setText(m_location.getAddress3());
fAddress4.setText(m_location.getAddress4());
fCity.setText(m_location.getCity());
fPostal.setText(m_location.getPostal());
fPostalAdd.setText(m_location.getPostal_Add());
if (m_location.getCountry().isHasRegion()) {
if (m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName) != null && m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName).trim().length() > 0)
lRegion.setText(m_location.getCountry().get_Translation(MCountry.COLUMNNAME_RegionName));
else
lRegion.setText(Msg.getMsg(Env.getCtx(), "Region"));
fRegion.setSelectedItem(m_location.getRegion());
}
if (!fCountry.getSelectedItem().equals(country))
fCountry.setSelectedItem(country);
}
// Update UI
pack();
}
use of org.compiere.model.MCountry in project adempiere by adempiere.
the class ADServiceImpl method getCountry.
private LookupValues getCountry(MLocation location) {
MCountry[] countries = MCountry.getCountries(location.getCtx());
int comp = location.getC_Country_ID();
if (comp == 0)
comp = Env.getContextAsInt(m_cs.getM_ctx(), "C_Country_ID");
LookupValues lvs = LookupValues.Factory.newInstance();
for (int i = 0; i < countries.length; i++) {
LookupValue lv = lvs.addNewLv();
lv.setKey(String.valueOf(countries[i].getC_Country_ID()));
lv.setVal(countries[i].getName());
}
return lvs;
}
use of org.compiere.model.MCountry in project adempiere by adempiere.
the class LocationServlet method doPost.
// doGet
/**
* Process the HTTP Post request.
*
* @param request request
* @param response response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.info("From " + request.getRemoteHost() + " - " + request.getRemoteAddr());
HttpSession session = request.getSession(true);
Properties ctx = JSPEnv.getCtx(request);
MLocation loc = new MLocation(ctx, 0, null);
response.setHeader("Cache-Control", "no-cache");
response.setContentType("text/xml; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
String cmd = request.getParameter("cmd");
cmd = Util.maskHTML(cmd, true);
if (cmd == null) {
out.println("<error>Unknown Request: NULL</error>");
} else {
String selected = request.getParameter("selected");
int selectedID = 0;
try {
selectedID = Integer.parseInt(selected);
} catch (Exception e) {
selectedID = 0;
}
if (// should probably put these in enum
cmd.equalsIgnoreCase("countries")) {
out.println("<countries>");
MCountry[] countries = MCountry.getCountries(loc.getCtx());
for (MCountry country : countries) {
int id = country.getC_Country_ID();
out.print("<country id='" + id + "'");
if (id == selectedID)
out.print(" selected='true'");
out.println(">" + country.getName() + "</country>");
}
out.println("</countries>");
} else if (cmd.equalsIgnoreCase("regions")) {
String country = Util.maskHTML(request.getParameter("country"), true);
try {
int countryId = Integer.parseInt(country);
out.println("<regions country='" + countryId + "'>");
MRegion[] regions = MRegion.getRegions(loc.getCtx(), countryId);
if ((regions.length > 0) && (selectedID == 0))
selectedID = regions[0].getC_Region_ID();
for (MRegion region : regions) {
int id = region.getC_Region_ID();
out.print("<region id='" + id + "'");
if (id == selectedID)
out.print(" selected='true'");
out.println(">" + region.getName() + "</region>");
}
out.println("</regions>");
} catch (Exception e) {
out.println("<error>Unknown Country: " + country + "</error>");
}
} else {
out.println("<error>Unknown Request: " + cmd + "</error>");
}
}
out.flush();
out.close();
}
Aggregations