1 17 package org.openbravo.erpCommon.ad_forms; 18 19 import org.openbravo.utils.FormatUtilities; 20 import org.openbravo.erpCommon.utility.*; 21 import org.openbravo.erpCommon.businessUtility.WindowTabs; 22 import org.openbravo.base.secureApp.*; 23 import org.openbravo.xmlEngine.XmlDocument; 24 import java.io.*; 25 import javax.servlet.*; 26 import java.util.Vector ; 27 import javax.servlet.http.*; 28 29 import org.openbravo.erpCommon.ad_combos.*; 30 import org.openbravo.exception.*; 31 32 import org.openbravo.data.*; 33 34 import java.sql.*; 36 37 public class InitialClientSetup extends HttpSecureAppServlet { 38 39 static final String SALTO_LINEA = "<BR>\n"; 40 String C_Currency_ID = ""; 41 String clientName=""; 42 String AD_User_ID=""; 43 String AD_User_Name=""; 44 String AD_User_U_Name=""; 45 String AD_User_U_ID=""; 46 String AD_Client_ID=""; 47 String AD_Org_ID=""; 48 String C_AcctSchema_ID=""; 49 String client = "1000000"; 50 AcctSchema m_AcctSchema; 51 private String C_Cycle_ID; 52 boolean m_hasProject ; 53 boolean m_hasMCampaign ; 54 boolean m_hasSRegion ; 55 String AD_Tree_Org_ID="", AD_Tree_BPartner_ID="", AD_Tree_Project_ID="", 56 AD_Tree_SalesRegion_ID="", AD_Tree_Product_ID="", AD_Tree_Account_ID=""; 57 static StringBuffer m_info= new StringBuffer (); 58 private final String CompiereSys = "N"; 60 61 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 62 VariablesSecureApp vars = new VariablesSecureApp(request); 63 if (vars.commandIn("DEFAULT")) { 64 printPage(response, vars); 65 } else if (vars.commandIn("ACEPTAR")) { 66 AccountingValueData av = new AccountingValueData(vars, "inpArchivo", true, "C"); 67 String strResultado = procesarFichero(av.getFieldProvider(), request, response, vars); 68 printPageResultado(response, vars, strResultado); 69 } else if (vars.commandIn("CANCELAR")) { 70 } else pageError(response); 71 } 72 73 private void printPage(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException{ 74 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_forms/InitialClientSetup").createXmlDocument(); 75 PaisComboData [] data = PaisComboData.select(this); 76 77 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 78 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 79 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "InitialClientSetup", false, "", "", "",false, "ad_forms", strReplaceWith, false, true); 80 toolbar.prepareSimpleToolBarTemplate(); 81 xmlDocument.setParameter("toolbar", toolbar.toString()); 82 try { 83 KeyMap key = new KeyMap(this, vars, "InitialClientSetup.html"); 84 xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps()); 85 } catch (Exception ex) { 86 throw new ServletException(ex); 87 } 88 try { 89 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_forms.InitialClientSetup"); 90 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 91 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 92 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 93 xmlDocument.setParameter("theme", vars.getTheme()); 94 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "InitialClientSetup.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 95 xmlDocument.setParameter("navigationBar", nav.toString()); 96 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "InitialClientSetup.html", strReplaceWith); 97 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 98 } catch (Exception ex) { 99 throw new ServletException(ex); 100 } 101 { 102 OBError myMessage = vars.getMessage("InitialClientSetup"); 103 vars.removeMessage("InitialClientSetup"); 104 if (myMessage!=null) { 105 xmlDocument.setParameter("messageType", myMessage.getType()); 106 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 107 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 108 } 109 110 xmlDocument.setParameter("region", arrayDobleEntrada("arrRegion", RegionComboData.selectTotal(this))); 111 xmlDocument.setData("reportMoneda","liststructure", MonedaComboData.select(this)); 112 xmlDocument.setData("reportPais","liststructure", data); 113 xmlDocument.setData("reportRegion","liststructure", RegionComboData.select(this, data[0].id)); 114 115 response.setContentType("text/html; charset=UTF-8"); 116 PrintWriter out = response.getWriter(); 117 out.println(xmlDocument.print()); 118 out.close(); 119 } 120 } 121 122 private void printPageResultado(HttpServletResponse response, VariablesSecureApp vars, String strResultado) throws IOException, ServletException{ 123 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_forms/Resultado").createXmlDocument(); 124 125 xmlDocument.setParameter("resultado",strResultado); 126 127 response.setContentType("text/html; charset=UTF-8"); 128 PrintWriter out = response.getWriter(); 129 out.println(xmlDocument.print()); 130 out.close(); 131 } 132 133 public String procesarFichero(FieldProvider[] avData, HttpServletRequest request, HttpServletResponse response, VariablesSecureApp vars) throws IOException { 134 135 Connection conn = null; 136 137 String strCliente = new String (vars.getStringParameter("inpCliente").getBytes("ISO-8859-1"),"UTF-8"); 138 String strOrganizacion = new String (vars.getStringParameter("inpOrganizacion").getBytes("ISO-8859-1"),"UTF-8"); 139 String strClienteUsuario = new String (vars.getStringParameter("inpClienteUsuario").getBytes("ISO-8859-1"),"UTF-8"); 140 String strOrganizacionUsuario = new String (vars.getStringParameter("inpOrganizacionUsuario").getBytes("ISO-8859-1"),"UTF-8"); 141 String strMoneda = vars.getStringParameter("inpMoneda"); 142 String strPais = vars.getStringParameter("inpPais"); 143 String strCiudad = new String (vars.getStringParameter("inpCiudad").getBytes("ISO-8859-1"),"UTF-8"); 144 String strRegion = vars.getStringParameter("inpRegion"); 145 boolean bProducto = isTrue(vars.getStringParameter("inpProducto")); 146 boolean bTercero = isTrue(vars.getStringParameter("inpTercero")); 147 boolean bProyecto = isTrue(vars.getStringParameter("inpProyecto")); 148 boolean bCampana = isTrue(vars.getStringParameter("inpCampana")); 149 boolean bZonaVentas = isTrue(vars.getStringParameter("inpZonaVentas")); 150 boolean bIsSystemInstalation = isTrue(vars.getStringParameter("inpSystem")); 151 if (bIsSystemInstalation) client = vars.getClient(); 152 try { 153 conn = this.getTransactionConnection(); 154 if (InitialClientSetupData.updateUser2(conn, this,strClienteUsuario)!=0){ 155 m_info.append("Duplicate UserClient").append(SALTO_LINEA); 156 releaseRollbackConnection(conn); 157 return m_info.toString(); 158 } else if (InitialClientSetupData.updateUser2(conn, this,strOrganizacionUsuario)!=0){ 159 m_info.append("Duplicate UserOrg").append(SALTO_LINEA); 160 releaseRollbackConnection(conn); 161 return m_info.toString(); 162 } 163 releaseCommitConnection(conn); 164 if (!createClient(vars, strCliente, strOrganizacion, strClienteUsuario, strOrganizacionUsuario)){ 165 releaseRollbackConnection(conn); 166 return m_info.toString(); 167 } else if (!createAccounting(vars, strMoneda, InitialClientSetupData.moneda(this, strMoneda), bProducto, bTercero, bProyecto, bCampana, bZonaVentas, avData)){ 168 releaseRollbackConnection(conn); 169 return m_info.toString(); 170 } else if (!createEntities(vars, strPais, strCiudad, strRegion)){ 171 releaseRollbackConnection(conn); 172 return m_info.toString(); 173 } 174 } catch (Exception err){ 175 log4j.warn(err); 176 try { 177 releaseRollbackConnection(conn); 178 } catch (Exception ignored) {} 179 } 180 return m_info.toString(); 181 } 182 183 public boolean isTrue(String s){ 184 if (s==null || s.equals("")) return false; 185 else return true; 186 } 187 188 189 public boolean createClient(VariablesSecureApp vars, String m_ClientName, String orgName, String userClient, String userOrg) throws ServletException{ 190 191 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient"); 192 clientName = m_ClientName; 193 if (clientName.equals("")) 194 clientName = "newClient"; 195 196 Connection conn = null; 197 try { 198 conn = this.getTransactionConnection(); 199 m_info.append(SALTO_LINEA); 201 String name = null; 203 int no = 0; 204 205 206 208 vars.setSessionValue("#CompiereSys", CompiereSys); 209 AD_Client_ID = SequenceIdData.getSequence(this, "AD_Client", client); 210 vars.setSessionValue("AD_Client_ID", AD_Client_ID); 211 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - CLIENT_ID: " + AD_Client_ID); 212 213 if (InitialClientSetupData.insertCliente(conn ,this, AD_Client_ID, clientName) != 1) { 214 String err = "InitialClientSetup - createClient - Client NOT inserted"; 215 log4j.warn(err); 216 m_info.append(err).append(SALTO_LINEA); 217 releaseRollbackConnection(conn); 218 return false; 219 } 220 releaseCommitConnection(conn); 221 conn = this.getTransactionConnection(); 222 m_info.append(Utility.messageBD(this, "AD_Client_ID", vars.getLanguage())).append("=").append(clientName).append(SALTO_LINEA); 224 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - M_INFO: " + m_info.toString()); 225 226 227 FieldProvider [] data = null; 230 try { 231 ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "AD_TreeType Type", "", Utility.getContext(this, vars, "#User_Org", "InitialClientSetup"), Utility.getContext(this, vars, "#User_Client", "InitialClientSetup"), 0); 232 Utility.fillSQLParameters(this, vars, null, comboTableData, "InitialClientSetup", ""); 233 data = comboTableData.select(false); 234 comboTableData = null; 235 } catch (Exception ex) { 236 throw new ServletException(ex); 237 } 238 239 240 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - LIST COUNT: " + data.length); 241 242 244 245 try { 246 int i =0; 247 while (i<data.length) { 248 String value = data[i].getField("id"); 249 String AD_Tree_ID = "0"; 250 if (value.equals("OO")) { 251 AD_Tree_ID = SequenceIdData.getSequence(this, "AD_Tree", client); 252 AD_Tree_Org_ID = AD_Tree_ID; 253 }else if (value.equals("BP")) { 254 AD_Tree_ID = SequenceIdData.getSequence(this, "AD_Tree", client); 255 AD_Tree_BPartner_ID = AD_Tree_ID; 256 }else if (value.equals("PJ")) { 257 AD_Tree_ID = SequenceIdData.getSequence(this, "AD_Tree", client); 258 AD_Tree_Project_ID = AD_Tree_ID; 259 }else if (value.equals("SR")) { 260 AD_Tree_ID = SequenceIdData.getSequence(this, "AD_Tree", client); 261 AD_Tree_SalesRegion_ID = AD_Tree_ID; 262 }else if (value.equals("PR")) { 263 AD_Tree_ID = SequenceIdData.getSequence(this, "AD_Tree", client); 264 AD_Tree_Product_ID = AD_Tree_ID; 265 }else if (value.endsWith("EV")) { 266 AD_Tree_ID = SequenceIdData.getSequence(this, "AD_Tree", client); 267 AD_Tree_Account_ID = AD_Tree_ID; 268 }else if (value.endsWith("AR")) { 269 AD_Tree_ID = SequenceIdData.getSequence(this, "AD_Tree", client); 270 }else if (!value.equals("MM")){ AD_Tree_ID = SequenceIdData.getSequence(this, "AD_Tree", client); 273 } 274 if (!AD_Tree_ID.equals("0")){ 276 name = clientName + " " + data[i].getField("name"); 277 if (InitialClientSetupData.insertTree(conn, this,AD_Client_ID, AD_Tree_ID, name, value) == 1) { 278 m_info.append(Utility.messageBD(this, "AD_Client_ID", vars.getLanguage())).append("=").append(name).append(SALTO_LINEA); 279 } else log4j.warn("InitialClientSetup - createClient - Tree NOT created: " + name); 280 } 281 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - VALUE " + i + ": "+ value + " ,AD_Tree_ID: " + AD_Tree_ID); 282 i++; 283 } 284 } catch (ServletException e1) { 285 log4j.warn("InitialClientSetup - createClient - Trees"); 286 } 287 releaseCommitConnection(conn); 288 conn = this.getTransactionConnection(); 289 String AD_Tree_Menu_ID = "10"; if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - AD_Client_ID: " + AD_Client_ID + ", AD_Tree_Menu_ID: " + AD_Tree_Menu_ID + ", AD_Tree_Org_ID: " + AD_Tree_Org_ID + ", AD_Tree_BPartner_ID: " + AD_Tree_BPartner_ID + ", AD_Tree_Project_ID: " + AD_Tree_Project_ID + ", AD_Tree_SalesRegion_ID: " + AD_Tree_SalesRegion_ID + ", AD_Tree_Product_ID: " + AD_Tree_Product_ID); 292 if (InitialClientSetupData.insertClientInfo(conn ,this, AD_Client_ID, AD_Tree_Menu_ID, AD_Tree_Org_ID, AD_Tree_BPartner_ID, AD_Tree_Project_ID, AD_Tree_SalesRegion_ID, AD_Tree_Product_ID) != 1) { 293 String err = "InitialClientSetup - createClient - ClientInfo NOT inserted"; 294 log4j.warn(err); 295 m_info.append(err).append(SALTO_LINEA); 296 releaseRollbackConnection(conn); 297 return false; 298 } 299 releaseCommitConnection(conn); 300 conn = this.getTransactionConnection(); 301 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - CLIENT INFO CREATED"); 302 303 304 306 AD_Org_ID = SequenceIdData.getSequence(this, "AD_Org", client); 307 name = orgName; 308 if (name == null || name.length() == 0) 309 name = "newOrg"; 310 String m_orgName = name; 311 if (InitialClientSetupData.insertOrg(conn ,this, AD_Client_ID, AD_Org_ID, name) != 1) { 312 String err = "InitialClientSetup - createClient - Org NOT inserted"; 313 log4j.warn(err); 314 m_info.append(err).append(SALTO_LINEA); 315 releaseRollbackConnection(conn); 316 return false; 317 } 318 releaseCommitConnection(conn); 320 conn = this.getTransactionConnection(); 321 m_info.append(Utility.messageBD(this, "AD_Org_ID", vars.getLanguage())).append("=").append(name).append(SALTO_LINEA); 322 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - m_info: " + m_info.toString()); 323 324 325 329 330 name = clientName + " Admin"; 331 String AD_Role_ID = SequenceIdData.getSequence(this, "AD_Role", client); 332 if (InitialClientSetupData.insertRole(conn ,this, AD_Client_ID, AD_Role_ID, name, "0,"+AD_Org_ID) != 1) { 333 String err = "InitialClientSetup - createClient - Admin Role A NOT inserted"; 334 log4j.warn(err); 335 m_info.append(err).append(SALTO_LINEA); 336 releaseRollbackConnection(conn); 337 return false; 338 } 339 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - ROLE CREATED"); 340 if (InitialClientSetupData.insertRoleOrgAccess(conn ,this, AD_Client_ID,"0" , AD_Role_ID) != 1) 342 log4j.warn("InitialClientSetup - createClient - Admin Role_OrgAccess 0 NOT created"); 343 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - ROLE ORG ACCESS CREATED"); 344 if (InitialClientSetupData.insertRoleOrgAccess(conn ,this, AD_Client_ID,AD_Org_ID, AD_Role_ID) != 1) 346 log4j.warn("InitialClientSetup - createClient - Admin Role_OrgAccess NOT created"); 347 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - SECOND ROLE ORG ACCESS CREATED"); 348 m_info.append(Utility.messageBD(this, "AD_Role_ID", vars.getLanguage())).append("=").append(name).append(SALTO_LINEA); 350 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - m_info: " + m_info.toString()); 351 352 name = clientName + " User"; 354 String AD_Role_ID_U = SequenceIdData.getSequence(this, "AD_Role", client); 355 if (InitialClientSetupData.insertRole2(conn ,this, AD_Client_ID, AD_Role_ID_U, name,AD_Org_ID) != 1){ 356 String err = "InitialClientSetup - createClient - User Role A NOT inserted"; 357 log4j.warn(err); 358 m_info.append(err).append(SALTO_LINEA); 359 releaseRollbackConnection(conn); 360 return false; 361 } 362 else if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - ROLE2 CREATED"); 363 if (InitialClientSetupData.insertRoleOrgAccess(conn, this, AD_Client_ID,AD_Org_ID , AD_Role_ID_U) != 1) 365 log4j.warn("InitialClientSetup - createClient - User Role_OrgAccess NOT created"); 366 else if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - ROLE2 ORG ACCESS CREATED"); 367 m_info.append(Utility.messageBD(this, "AD_Role_ID", vars.getLanguage())).append("=").append(name).append(SALTO_LINEA); 369 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - m_info: " + m_info.toString()); 370 371 releaseCommitConnection(conn); 372 conn = this.getTransactionConnection(); 373 374 378 name = userClient; 379 if (name == null || name.length() == 0) 380 name = clientName + "Client"; 381 AD_User_ID = SequenceIdData.getSequence(this, "AD_User", client); 382 AD_User_Name = name; 383 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - AD_User_Name : " + AD_User_Name); 384 if (InitialClientSetupData.insertUser(conn ,this, AD_Client_ID,AD_User_ID , name, FormatUtilities.sha1Base64(name)) != 1) { 385 String err = "InitialClientSetup - createClient - Admin User A NOT inserted"; 386 log4j.warn(err); 387 m_info.append(err).append(SALTO_LINEA); 388 releaseRollbackConnection(conn); 389 return false; 390 } 391 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - USER INSERTED " + name); 392 m_info.append(Utility.messageBD(this, "AD_User_ID", vars.getLanguage())).append("=").append(name).append("/").append(name).append(SALTO_LINEA); 394 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - m_info: " + m_info.toString()); 395 396 397 name = userOrg; 398 if (name == null || name.length() == 0 || userClient == userOrg) 399 name = clientName + "Org"; 400 AD_User_U_ID = SequenceIdData.getSequence(this, "AD_User", client); 401 AD_User_U_Name = name; 402 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - AD_User_U_Name : " + AD_User_U_Name); 403 if (InitialClientSetupData.insertUser(conn ,this, AD_Client_ID,AD_User_U_ID , name, FormatUtilities.sha1Base64(name)) != 1) { 404 String err = "InitialClientSetup - createClient - Org User A NOT inserted"; 405 log4j.warn(err); 406 m_info.append(err).append(SALTO_LINEA); 407 releaseRollbackConnection(conn); 408 return false; 409 } 410 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - USER INSERTED " + name); 411 m_info.append(Utility.messageBD(this, "AD_User_ID", vars.getLanguage())).append("=").append(name).append("/").append(name).append(SALTO_LINEA); 413 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - m_info: " + m_info.toString()); 414 releaseCommitConnection(conn); 415 conn = this.getTransactionConnection(); 416 417 418 420 if (InitialClientSetupData.insertUserRoles(conn ,this, AD_Client_ID,AD_User_ID , AD_Role_ID) != 1) 422 log4j.warn("InitialClientSetup - createClient - UserRole ClientUser+Admin NOT inserted"); 423 if (InitialClientSetupData.insertUserRoles(conn ,this, AD_Client_ID,AD_User_ID , AD_Role_ID_U) != 1) 424 log4j.warn("InitialClientSetup - createClient - UserRole ClientUser+User NOT inserted"); 425 if (InitialClientSetupData.insertUserRoles(conn ,this, AD_Client_ID,AD_User_U_ID , AD_Role_ID_U) != 1) 427 log4j.warn("InitialClientSetup - createClient - UserRole OrgUser+Org NOT inserted"); 428 if (InitialClientSetupData.insertUserRoles(conn ,this, AD_Client_ID,"100" , AD_Role_ID) != 1) 430 log4j.warn("InitialClientSetup - createClient - UserRole SuperUser+Admin NOT inserted"); 431 if (InitialClientSetupData.insertUserRoles(conn ,this, AD_Client_ID,"100" , AD_Role_ID_U) != 1) 432 log4j.warn("InitialClientSetup - createClient - UserRole SuperUser+User NOT inserted"); 433 releaseCommitConnection(conn); 434 } catch (Exception e) { 435 m_info.append(e).append(SALTO_LINEA); 436 try { 437 releaseRollbackConnection(conn); 438 } catch (Exception ignored) {} 439 try { 440 conn = this.getTransactionConnection(); 441 } catch (Exception ignored) {} 442 return false; 443 } 444 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - m_info last: " + m_info.toString()); 445 return true; 446 } 447 448 449 450 public boolean save (Connection conn, VariablesSecureApp vars, String AD_Client_ID, String AD_Org_ID, String C_Element_ID, AccountingValueData[] data) throws ServletException { 451 boolean OK=true; 452 for (int i=0;i<data.length;i++) { 453 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - DATA LENGTH : " + data.length + ", POSICION : " + i + ", DEFAULT_ACCT: " + data[i].defaultAccount); 454 data[i].cElementValueId = SequenceIdData.getSequence(this, "C_ElementValue", client); 455 String IsDocControlled = data[i].accountDocument.equals("Yes") ? "Y" : "N"; 456 String C_ElementValue_ID = data[i].cElementValueId; 457 String IsSummary =data[i].accountSummary.equals("Yes") ? "Y" : "N"; 458 String accountType=""; 459 String accountSign=""; 460 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - AccountType debug"); 461 if (!data[i].accountType.equals("")){ 462 String s = data[i].accountType.toUpperCase().substring(0, 1); 463 if(s.equals("A") || s.equals("L") || s.equals("O") || s.equals("E") || s.equals("R") || s.equals("M")) accountType = s; 464 else accountType = "E"; 465 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - Not is account type"); 466 } else { 467 accountType = "E"; 468 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - Is account type"); 469 } 470 if (!data[i].accountSign.equals("")){ 471 String s = data[i].accountSign.toUpperCase().substring(0, 1); 472 if(s.equals("D") || s.equals("C")) accountSign = s; 473 else accountSign = "N"; 474 } else accountSign = "N"; 475 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - ACCOUNT VALUE : " + data[i].accountValue + " ACCOUNT NAME : " + data[i].accountName + " DEFAULT_ACCOUNT: " + data[i].defaultAccount); 476 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - C_ElementValue_ID: " + C_ElementValue_ID ); 477 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - C_Element_ID: " + C_Element_ID); 478 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - data[i].accountValue: " + data[i].accountValue); 479 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - data[i].accountName: " + data[i].accountName); 480 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - data[i].accountDescription: " + data[i].accountDescription); 481 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - accountType: " + accountType); 482 483 if (!data[i].accountValue.equals("")) { 484 try { 485 if (InitialClientSetupData.insertElementValue(conn ,this, C_ElementValue_ID, C_Element_ID, AD_Client_ID, AD_Org_ID, data[i].accountValue, data[i].accountName, data[i].accountDescription, accountType, accountSign, IsDocControlled, IsSummary) != 1) { 486 log4j.warn("InitialClientSetup - save - Natural Account not added"); 487 data[i].cElementValueId = ""; 488 return false; 489 } 490 } catch (ServletException e) { 491 log4j.warn("InitialClientSetup - save - Natural Account not added"); 492 data[i].cElementValueId = ""; 493 return false; 494 } 495 } 496 } 497 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - NATURAL ACCOUNT ADDED"); 498 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - m_info last: " + m_info.toString()); 499 return OK; 500 } 502 public AccountingValueData[] parseData (FieldProvider[] data) throws ServletException { 503 AccountingValueData[] result = null; 504 Vector <Object > vec = new Vector <Object >(); 505 for (int i=0;i<data.length;i++) { 506 AccountingValueData dataAux = new AccountingValueData(); 507 dataAux.accountValue = data[i].getField("accountValue"); 508 dataAux.accountName = data[i].getField("accountName"); 509 dataAux.accountDescription = data[i].getField("accountDescription"); 510 dataAux.accountType = data[i].getField("accountType"); 511 dataAux.accountSign = data[i].getField("accountSign"); 512 dataAux.accountDocument = data[i].getField("accountDocument"); 513 dataAux.accountSummary = data[i].getField("accountSummary"); 514 dataAux.defaultAccount = data[i].getField("defaultAccount"); 515 dataAux.accountParent = data[i].getField("accountParent"); 516 dataAux.balanceSheet = data[i].getField("balanceSheet"); 517 dataAux.balanceSheetName = data[i].getField("balanceSheetName"); 518 dataAux.uS1120BalanceSheet = data[i].getField("uS1120BalanceSheet"); 519 dataAux.uS1120BalanceSheetName = data[i].getField("uS1120BalanceSheetName"); 520 dataAux.profitAndLoss = data[i].getField("profitAndLoss"); 521 dataAux.profitAndLossName = data[i].getField("profitAndLossName"); 522 dataAux.uS1120IncomeStatement = data[i].getField("uS1120IncomeStatement"); 523 dataAux.uS1120IncomeStatementName = data[i].getField("uS1120IncomeStatementName"); 524 dataAux.cashFlow = data[i].getField("cashFlow"); 525 dataAux.cashFlowName = data[i].getField("cashFlowName"); 526 dataAux.cElementValueId = data[i].getField("cElementValueId"); 527 vec.addElement(dataAux); 528 } 529 result = new AccountingValueData[vec.size()]; 530 vec.copyInto(result); 531 return result; 532 } 534 public String getC_ElementValue_ID (AccountingValueData[] data, String key) { 535 if (data==null || data.length==0) return ""; 536 for (int i=0;i<data.length;i++) if (data[i].defaultAccount.equalsIgnoreCase(key) && !data[i].defaultAccount.equals("")) return data[i].cElementValueId; 537 return ""; 538 } 540 public boolean createAccounting(VariablesSecureApp vars, String newC_Currency_ID, String curName,boolean hasProduct, boolean hasBPartner, boolean hasProject, 541 boolean hasMCampaign, boolean hasSRegion,FieldProvider[] avData) throws ServletException{ 542 C_Currency_ID = newC_Currency_ID; 544 m_hasProject = hasProject; 545 m_hasMCampaign = hasMCampaign; 546 m_hasSRegion = hasSRegion; 547 548 Connection conn = null; 549 String name = null; 550 String C_Calendar_ID = null; 551 String C_Year_ID = null; 552 String C_Element_ID = null; 553 String C_ElementValue_ID = null; 554 String GAAP = null; 555 String CostingMethod = null; 556 AccountingValueData[] data = null; 557 try { 558 conn = this.getTransactionConnection(); 559 560 m_info.append(SALTO_LINEA); 562 563 564 566 C_Calendar_ID = SequenceIdData.getSequence(this, "C_Calendar", client); 567 name = clientName + " " + Utility.messageBD(this, "C_Calendar_ID", vars.getLanguage()); 568 if (InitialClientSetupData.insertCalendar(conn ,this, AD_Client_ID,C_Calendar_ID , name) != 1) { 569 String err = "InitialClientSetup - createAccounting - Calendar NOT inserted"; 570 log4j.warn(err); 571 m_info.append(err).append(SALTO_LINEA); 572 releaseRollbackConnection(conn); 573 return false; 574 } 575 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - CALENDAR INSERTED"); 576 m_info.append(Utility.messageBD(this, "C_Calendar_ID", vars.getLanguage())).append("=").append(name).append(SALTO_LINEA); 578 579 C_Year_ID = SequenceIdData.getSequence(this, "C_Year", client); 581 if (InitialClientSetupData.insertYear(conn ,this, C_Year_ID, AD_Client_ID,C_Calendar_ID) != 1) 582 log4j.warn("InitialClientSetup - createAccounting - Year NOT inserted"); 583 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - YEAR INSERTED"); 585 releaseCommitConnection(conn); 586 conn = this.getTransactionConnection(); 587 588 C_Element_ID = SequenceIdData.getSequence(this, "C_Element", client); 590 name = clientName + " " + Utility.messageBD(this, "Account_ID", vars.getLanguage()); 591 if (InitialClientSetupData.insertElement(conn ,this, AD_Client_ID, C_Element_ID,name, AD_Tree_Account_ID) != 1) { 592 String err = "InitialClientSetup - createAccounting - Acct Element NOT inserted"; 593 log4j.warn(err); 594 m_info.append(err).append(SALTO_LINEA); 595 releaseRollbackConnection(conn); 596 return false; 597 } 598 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - ELEMENT INSERTED :" + C_Element_ID); 599 m_info.append(Utility.messageBD(this, "C_Element_ID", vars.getLanguage())).append("=").append(name).append(SALTO_LINEA); 600 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - m_info last: " + m_info.toString()); 601 602 data = parseData(avData); 604 boolean errMsg = save(conn, vars, AD_Client_ID, AD_Org_ID, C_Element_ID, data); 605 if (!errMsg) { 606 releaseRollbackConnection(conn); 607 String err = "InitialClientSetup - createAccounting - Acct Element Values NOT inserted"; 608 log4j.warn(err); 609 m_info.append(err).append(SALTO_LINEA); 610 return false; 611 } 612 else m_info.append(Utility.messageBD(this, "C_ElementValue_ID", vars.getLanguage())).append(" # ").append(SALTO_LINEA); 613 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - m_info last: " + m_info.toString()); 614 615 C_ElementValue_ID = getC_ElementValue_ID(data, "DEFAULT_ACCT"); 617 C_AcctSchema_ID = SequenceIdData.getSequence(this, "C_AcctSchema", client); 618 GAAP = "US"; CostingMethod = "A"; name = clientName + " " + GAAP + "/" + CostingMethod + "/" + curName; 622 if (InitialClientSetupData.insertAcctSchema(conn ,this, AD_Client_ID, C_AcctSchema_ID,name, GAAP, CostingMethod, C_Currency_ID) != 1){ 624 String err = "InitialClientSetup - createAccounting - AcctSchema NOT inserted"; 625 log4j.warn(err); 626 m_info.append(err).append(SALTO_LINEA); 627 releaseRollbackConnection(conn); 628 return false; 629 } 630 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - ACCT SCHEMA INSERTED"); 631 m_info.append(Utility.messageBD(this, "C_AcctSchema_ID", vars.getLanguage())).append("=").append(name).append(SALTO_LINEA); 633 } catch (NoConnectionAvailableException ex) { 634 throw new ServletException("@CODE=NoConnectionAvailable"); 635 } catch (SQLException ex2) { 636 throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage()); 637 } catch (Exception ex3) { 638 throw new ServletException("@CODE=@" + ex3.getMessage()); 639 } 640 641 642 644 FieldProvider [] data1 = null; 645 try { 646 ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "C_AcctSchema ElementType", "", Utility.getContext(this, vars, "#User_Org", "InitialClientSetup"), Utility.getContext(this, vars, "#User_Client", "InitialClientSetup"), 0); 647 Utility.fillSQLParameters(this, vars, null, comboTableData, "InitialClientSetup", ""); 648 data1 = comboTableData.select(false); 649 comboTableData = null; 650 } catch (Exception ex) { 651 throw new ServletException(ex); 652 } 653 654 655 String Element_OO="", Element_AC="", Element_PR="", Element_BP="", Element_PJ="", 656 Element_MC="", Element_SR=""; 657 try { 658 for (int i=0; i< data1.length;i++) { 659 String ElementType = data1[i].getField("id"); 660 name = data1[i].getField("name"); 661 String IsMandatory = ""; 663 String IsBalanced = "N"; 664 String SeqNo = ""; 665 String C_AcctSchema_Element_ID = ""; 666 667 if (ElementType.equals("OO")){ 668 C_AcctSchema_Element_ID = SequenceIdData.getSequence(this, "C_AcctSchema_Element", client); 669 Element_OO = C_AcctSchema_Element_ID; 670 IsMandatory = "Y"; 671 IsBalanced = "Y"; 672 SeqNo = "10"; 673 } else if (ElementType.equals("AC")){ 674 C_AcctSchema_Element_ID = SequenceIdData.getSequence(this, "C_AcctSchema_Element", client); 675 Element_AC = C_AcctSchema_Element_ID; 676 IsMandatory = "Y"; 677 SeqNo = "20"; 678 } else if (ElementType.equals("PR") && hasProduct){ 679 C_AcctSchema_Element_ID = SequenceIdData.getSequence(this, "C_AcctSchema_Element", client); 680 Element_PR = C_AcctSchema_Element_ID; 681 IsMandatory = "N"; 682 SeqNo = "30"; 683 } else if (ElementType.equals("BP") && hasBPartner){ 684 C_AcctSchema_Element_ID = SequenceIdData.getSequence(this, "C_AcctSchema_Element", client); 685 Element_BP = C_AcctSchema_Element_ID; 686 IsMandatory = "N"; 687 SeqNo = "40"; 688 } else if (ElementType.equals("PJ") && hasProject){ 689 C_AcctSchema_Element_ID = SequenceIdData.getSequence(this, "C_AcctSchema_Element", client); 690 Element_PJ = C_AcctSchema_Element_ID; 691 IsMandatory = "N"; 692 SeqNo = "50"; 693 } else if (ElementType.equals("MC") && hasMCampaign){ 694 C_AcctSchema_Element_ID = SequenceIdData.getSequence(this, "C_AcctSchema_Element", client); 695 Element_MC = C_AcctSchema_Element_ID; 696 IsMandatory = "N"; 697 SeqNo = "60"; 698 } else if (ElementType.equals("SR") && hasSRegion){ 699 C_AcctSchema_Element_ID = SequenceIdData.getSequence(this, "C_AcctSchema_Element", client); 700 Element_SR = C_AcctSchema_Element_ID; 701 IsMandatory = "N"; 702 SeqNo = "70"; 703 } 704 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - C_ElementValue_ID: " + C_ElementValue_ID); 706 707 if (!IsMandatory.equals("")){ 708 if (InitialClientSetupData.insertAcctSchemaElement(conn, this, AD_Client_ID, C_AcctSchema_Element_ID,C_AcctSchema_ID, ElementType, name, SeqNo, IsMandatory, IsBalanced) == 1) 709 m_info.append(Utility.messageBD(this, "C_AcctSchema_Element_ID", vars.getLanguage())).append("=").append(name).append(SALTO_LINEA); 710 711 if (ElementType.equals("OO")){ 713 if (InitialClientSetupData.updateAcctSchemaElement(conn, this, AD_Org_ID, C_AcctSchema_Element_ID) != 1) 714 log4j.warn("InitialClientSetup - createAccounting - Default Org in AcctSchamaElement NOT updated"); 715 } 716 if (ElementType.equals("AC")){ 717 if (InitialClientSetupData.updateAcctSchemaElement2(conn, this, C_ElementValue_ID, C_Element_ID, C_AcctSchema_Element_ID) != 1) 718 log4j.warn("InitialClientSetup - createAccounting - Default Account in AcctSchamaElement NOT updated"); 719 } 720 } 721 } 722 } catch (Exception e1) { 723 log4j.warn("InitialClientSetup - createAccounting - Elements", e1); 724 try { 725 releaseRollbackConnection(conn); 726 } catch (Exception ignored) {} 727 throw new ServletException(e1); 728 } 729 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - ACCT SCHEMA ELEMENTS INSERTED"); 730 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - m_info last: " + m_info.toString()); 731 try { 732 releaseCommitConnection(conn); 734 conn = this.getTransactionConnection(); 735 736 m_AcctSchema = new AcctSchema(this, C_AcctSchema_ID); 737 if(InitialClientSetupData.insertAcctSchemaGL(conn, this, AD_Client_ID, C_AcctSchema_ID, getAcct(conn, data, 738 "SUSPENSEBALANCING_ACCT"), getAcct(conn, data, "SUSPENSEERROR_ACCT"), getAcct(conn, data, "CURRENCYBALANCING_ACCT"), getAcct(conn, data, 739 "RETAINEDEARNING_ACCT"), getAcct(conn, data, "INCOMESUMMARY_ACCT"), getAcct(conn, data, "INTERCOMPANYDUETO_ACCT"), getAcct(conn, data, 740 "INTERCOMPANYDUEFROM_ACCT"), getAcct(conn, data, "PPVOFFSET_ACCT")) != 1) { 741 String err = "InitialClientSetup - createAccounting - GL Accounts NOT inserted"; 742 log4j.warn(err); 743 m_info.append(err); 744 return false; 745 } 746 747 String C_AcctSchema_Default_ID = SequenceIdData.getSequence(this, "C_AcctSchema_Default", AD_Client_ID); 748 if(InitialClientSetupData.insertAcctSchemaDEFAULT(conn, this, AD_Client_ID, C_AcctSchema_ID, getAcct(conn, data, 749 "W_INVENTORY_ACCT"), getAcct(conn, data, "W_DIFFERENCES_ACCT"), getAcct(conn, data, "W_REVALUATION_ACCT"), getAcct(conn, data, 750 "W_INVACTUALADJUST_ACCT"), getAcct(conn, data, "P_REVENUE_ACCT"), getAcct(conn, data, "P_EXPENSE_ACCT"), getAcct(conn, data, 751 "P_ASSET_ACCT"), getAcct(conn, data, "P_COGS_ACCT"), getAcct(conn, data, "P_PURCHASEPRICEVARIANCE_ACCT"), getAcct(conn, data, 752 "P_INVOICEPRICEVARIANCE_ACCT"), getAcct(conn, data, "P_TRADEDISCOUNTREC_ACCT"), getAcct(conn, data, "P_TRADEDISCOUNTGRANT_ACCT"), 753 getAcct(conn, data, "C_RECEIVABLE_ACCT"), getAcct(conn, data, "C_PREPAYMENT_ACCT"), getAcct(conn, data, "V_LIABILITY_ACCT"), 754 getAcct(conn, data, "V_LIABILITY_SERVICES_ACCT"), getAcct(conn, data, "V_PREPAYMENT_ACCT"), getAcct(conn, data, "PAYDISCOUNT_EXP_ACCT"), 755 getAcct(conn, data, "PAYDISCOUNT_REV_ACCT"), getAcct(conn, data, "WRITEOFF_ACCT"), getAcct(conn, data, "UNREALIZEDGAIN_ACCT"), 756 getAcct(conn, data, "UNREALIZEDLOSS_ACCT"), getAcct(conn, data, "REALIZEDGAIN_ACCT"), getAcct(conn, data, "REALIZEDLOSS_ACCT"), 757 getAcct(conn, data, "WITHHOLDING_ACCT"), getAcct(conn, data, "E_PREPAYMENT_ACCT"), getAcct(conn, data, "E_EXPENSE_ACCT"), getAcct(conn, 758 data, "PJ_ASSET_ACCT"), getAcct(conn, data, "PJ_WIP_ACCT"), getAcct(conn, data, "T_EXPENSE_ACCT"), getAcct(conn, data, 759 "T_LIABILITY_ACCT"), getAcct(conn, data, "T_RECEIVABLES_ACCT"), getAcct(conn, data, "T_DUE_ACCT"), getAcct(conn, data, "T_CREDIT_ACCT"), 760 getAcct(conn, data, "B_INTRANSIT_ACCT"), getAcct(conn, data, "B_ASSET_ACCT"), getAcct(conn, data, "B_EXPENSE_ACCT"), getAcct(conn, data, 761 "B_INTERESTREV_ACCT"), getAcct(conn, data, "B_INTERESTEXP_ACCT"), getAcct(conn, data, "B_UNIDENTIFIED_ACCT"), getAcct(conn, data, 762 "B_SETTLEMENTGAIN_ACCT"), getAcct(conn, data, "B_SETTLEMENTLOSS_ACCT"), getAcct(conn, data, "B_REVALUATIONGAIN_ACCT"), getAcct(conn, 763 data, "B_REVALUATIONLOSS_ACCT"), getAcct(conn, data, "B_PAYMENTSELECT_ACCT"), getAcct(conn, data, "B_UNALLOCATEDCASH_ACCT"), 764 getAcct(conn, data, "CH_EXPENSE_ACCT"), getAcct(conn, data, "CH_REVENUE_ACCT"), getAcct(conn, data, "UNEARNEDREVENUE_ACCT"), 765 getAcct(conn, data, "NOTINVOICEDRECEIVABLES_ACCT"), getAcct(conn, data, "NOTINVOICEDREVENUE_ACCT"), getAcct(conn, data, 766 "NOTINVOICEDRECEIPTS_ACCT"), getAcct(conn, data, "CB_ASSET_ACCT"), getAcct(conn, data, "CB_CASHTRANSFER_ACCT"), getAcct(conn, data, 767 "CB_DIFFERENCES_ACCT"), getAcct(conn, data, "CB_EXPENSE_ACCT"), getAcct(conn, data, "CB_RECEIPT_ACCT"),C_AcctSchema_Default_ID, 768 getAcct(conn, data, "A_DEPRECIATION_ACCT"),getAcct(conn, data, "A_ACCUMDEPRECIATION_ACCT"),getAcct(conn, data, "A_DISPOSAL_LOSS"),getAcct(conn, data, "A_DISPOSAL_GAIN")) != 1) { 769 String err = "InitialClientSetup - createAccounting - Default Accounts NOT inserted"; 770 log4j.warn(err); 771 m_info.append(err); 772 return false; 773 } 774 releaseCommitConnection(conn); 775 conn = this.getTransactionConnection(); 776 } catch (Exception ex) { 777 try { 778 releaseRollbackConnection(conn); 779 } catch (Exception ignored) {} 780 throw new ServletException("@CODE=@" + ex.getMessage()); 781 } 782 783 String GL_Standard = createGLCategory(vars,"Standard", "M", true); 785 String GL_None = createGLCategory(vars,"None", "D", false); 786 String GL_GL = createGLCategory(vars,"Manual", "M", false); 787 String GL_ARI = createGLCategory(vars,"AR Invoice", "D", false); 788 String GL_ARR = createGLCategory(vars,"AR Receipt", "D", false); 789 String GL_MM = createGLCategory(vars,"Material Management", "D", false); 790 String GL_API = createGLCategory(vars,"AP Invoice", "D", false); 791 String GL_APP = createGLCategory(vars,"AP Payment", "D", false); 792 String GL_STT = createGLCategory(vars,"Settlement", "D", false); 793 String GL_CMB = createGLCategory(vars,"Bank Statement", "D", false); 794 String GL_CMC = createGLCategory(vars,"Cash", "D", false); 795 String GL_MMI = createGLCategory(vars,"Inventory", "D", false); 796 String GL_MMM = createGLCategory(vars,"Movement", "D", false); 797 String GL_MMP = createGLCategory(vars,"Production", "D", false); 798 String GL_MXI = createGLCategory(vars,"MatchInv", "D", false); 799 String GL_MXP = createGLCategory(vars,"MatchPO", "D", false); 800 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - GL CATEGORIES CREATED"); 801 802 createDocType(vars,"GL Journal", "Journal", "GLJ", "", "0", "0", "1000", GL_GL, "224"); 804 String DT_I = createDocType(vars,"AR Invoice", "Invoice", "ARI", "", "0", "0", "100000", GL_ARI, "318"); 805 String DT_II = createDocType(vars,"AR Invoice Indirect", "Invoice Indirect.", "ARI", "", "0", "0", "200000", GL_ARI, "318"); 806 createDocType(vars,"AR Credit Memo", "Credit Memo", "ARC", "", "0", "0", "300000", GL_ARI, "318"); 807 createDocType(vars,"AR Receipt", "Receipt", "ARR", "", "0", "0", "400000", GL_ARR, ""); 808 String DT_S = createDocType(vars,"MM Shipment", "Delivery Note", "MMS", "", "0", "0", "500000", GL_MM, "319"); 809 String DT_SI = createDocType(vars,"MM Shipment Indirect", "Delivery Note", "MMS", "", "0", "0", "600000", GL_MM, "319"); 810 createDocType(vars,"MM Receipt", "Vendor Delivery", "MMR", "", "0", "0", "0", GL_MM, "319"); 811 createDocType(vars,"AP Invoice", "Vendor Invoice", "API", "", "0", "0", "0", GL_API, "318"); 812 createDocType(vars,"AP CreditMemo", "Vendor Credit Memo", "APC", "", "0", "0", "0", GL_API, "318"); 813 createDocType(vars,"AP Payment", "Vendor Payment", "APP", "", "0", "0", "700000", GL_APP, ""); 814 createDocType(vars,"Purchase Order", "Purchase Order", "POO", "", "0", "0", "800000", GL_None, "259"); 815 createDocType(vars,"Purchase Requisition", "Purchase Requisition", "POR", "", "0", "0", "900000", GL_None, "259"); 816 817 818 createDocType(vars,"Settlement", "Settlement", "STT", "", "0", "0", "10000", GL_STT, "800019"); 819 createDocType(vars,"Manual Settlement", "Manual Settlement", "STM", "", "0", "0", "10000", GL_STT, "800019"); 820 createDocType(vars,"Bank Statement", "Bank Statement", "CMB", "", "0", "0", "1000000", GL_CMB, "392"); 821 createDocType(vars,"Cash Journal", "Cash Journal", "CMC", "", "0", "0", "1000000", GL_CMC, "407"); 822 createDocType(vars,"Physical Inventory", "Physical Inventory", "MMI", "", "0", "0", "1000000", GL_MMI, "321"); 823 createDocType(vars,"Inventory Move", "Inventory Move", "MMM", "", "0", "0", "1000000", GL_MMM, "323"); 824 createDocType(vars,"Production", "Production", "MMP", "", "0", "0", "1000000", GL_MMP, "325"); 825 createDocType(vars,"Matched Invoices", "Matched Invoices", "MXI", "", "0", "0", "1000000", GL_MXI, "472"); 826 createDocType(vars,"Matched Purchase Orders", "Matched Purchase Orders", "MXP", "", "0", "0", "1000000", GL_MXP, "473"); 827 createDocType(vars,"Debt Payement Management", "Debt Payement Management", "DPM", "", "0", "0", "10000", GL_Standard, "800176"); 828 createDocType(vars,"Depreciation", "Depreciation", "AMZ", "", "0", "0", "10000", GL_Standard, "800060"); 829 830 createDocType(vars,"Quotation", "Binding offer", "SOO", "OB", "0", "0", "10000", GL_None, "259"); 832 createDocType(vars,"Proposal", "Non binding offer", "SOO", "ON", "0", "0", "20000", GL_None, "259"); 833 createDocType(vars,"Prepay Order", "Prepay Order", "SOO", "PR", DT_S, DT_I, "30000", GL_None, "259"); 834 createDocType(vars,"Return Material", "Return Material Authorization", "SOO", "RM", DT_S, DT_I, "40000", GL_None, "259"); 835 createDocType(vars,"Standard Order", "Order Confirmation", "SOO", "SO", DT_S, DT_I, "50000", GL_None, "259"); 836 createDocType(vars,"Credit Order", "Order Confirmation", "SOO", "WI", DT_SI, DT_I, "60000", GL_None, "259"); String DT_WO = createDocType(vars,"Warehouse Order", "Order Confirmation", "SOO", "WP", DT_S, DT_I, "70000", GL_None, "259"); String DT = createDocType(vars,"POS Order", "Order Confirmation", "SOO", "WR", DT_SI, DT_II, "80000", GL_None, "259"); createPreference(vars,"C_DocTypeTarget_ID", DT, "143"); 840 createPreference(vars,"C_DocTypeTarget_ID", DT_WO, "800004"); 841 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - DOCTYPES & PREFERENCE CREATED"); 842 843 try { 844 if (InitialClientSetupData.updateClientInfo(conn ,this,C_AcctSchema_ID, C_Calendar_ID, AD_Client_ID) != 1){ 846 String err = "InitialClientSetup - createAccounting - ClientInfo not updated"; 847 log4j.warn(err); 848 m_info.append(err).append(SALTO_LINEA); 849 releaseRollbackConnection(conn); 850 return false; 851 } 852 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - CLIENT INFO UPDATED"); 853 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - m_info last: " + m_info.toString()); 854 releaseCommitConnection(conn); 856 } catch (SQLException ex2) { 857 try { 858 releaseRollbackConnection(conn); 859 } catch (Exception ignored) {} 860 throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage()); 861 } catch (Exception ex3) { 862 try { 863 releaseRollbackConnection(conn); 864 } catch (Exception ignored) {} 865 throw new ServletException("@CODE=@" + ex3.getMessage()); 866 } 867 return true; 868 } 870 private String createGLCategory (VariablesSecureApp vars, String Name, String CategoryType, boolean isDefault)throws ServletException{ 871 Connection conn = null; 872 String GL_Category_ID = ""; 873 try { 874 conn = this.getTransactionConnection(); 875 GL_Category_ID = SequenceIdData.getSequence(this, "GL_Category", client); 876 String strisDefault = (isDefault ? "Y" : "N"); 877 if (InitialClientSetupData.insertCategory(conn ,this,GL_Category_ID, AD_Client_ID, Name, CategoryType, strisDefault) != 1) 878 log4j.warn("InitialClientSetup - createGLCategory - GL Logger NOT created - " + Name); 879 releaseCommitConnection(conn); 881 } catch (NoConnectionAvailableException ex) { 882 throw new ServletException("@CODE=NoConnectionAvailable"); 883 } catch (SQLException ex2) { 884 try { 885 releaseRollbackConnection(conn); 886 } catch (Exception ignored) {} 887 throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage()); 888 } catch (Exception ex3) { 889 try { 890 releaseRollbackConnection(conn); 891 } catch (Exception ignored) {} 892 throw new ServletException("@CODE=@" + ex3.getMessage()); 893 } 894 return GL_Category_ID; 895 } 896 897 private void createPreference (VariablesSecureApp vars, String Attribute, String Value, String AD_Window_ID)throws ServletException{ 898 Connection conn = null; 899 try { 900 conn = this.getTransactionConnection(); 901 String AD_Preference_ID = SequenceIdData.getSequence(this, "AD_Preference", client); 902 if (InitialClientSetupData.insertPreference(conn ,this,AD_Preference_ID, AD_Client_ID, Attribute, Value, AD_Window_ID) != 1) 903 log4j.warn("InitialClientSetup - createPreference - Preference NOT inserted - " + Attribute); 904 releaseCommitConnection(conn); 905 } catch (NoConnectionAvailableException ex) { 906 throw new ServletException("@CODE=NoConnectionAvailable"); 907 } catch (SQLException ex2) { 908 try { 909 releaseRollbackConnection(conn); 910 } catch (Exception ignored) {} 911 throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage()); 912 } catch (Exception ex3) { 913 try { 914 releaseRollbackConnection(conn); 915 } catch (Exception ignored) {} 916 throw new ServletException("@CODE=@" + ex3.getMessage()); 917 } 918 } 920 private String createDocType (VariablesSecureApp vars, String Name, String PrintName,String DocBaseType, String DocSubTypeSO, 921 String C_DocTypeShipment_ID, String C_DocTypeInvoice_ID,String StartNo, String GL_Category_ID, String strTableId)throws ServletException{ 922 Connection conn = null; 923 String C_DocType_ID = ""; 924 try { 925 conn = this.getTransactionConnection(); 926 StringBuffer sqlCmd = null; 927 String AD_Sequence_ID = ""; 929 if (!StartNo.equals("0")){ AD_Sequence_ID = SequenceIdData.getSequence(this, "AD_Sequence", client); 931 log4j.debug("inserting sequence ID:"+AD_Sequence_ID+" name: "+Name); 932 if (InitialClientSetupData.insertSequence(conn ,this,AD_Sequence_ID, AD_Client_ID, Name, StartNo) != 1) 933 log4j.warn("InitialClientSetup - createDocType - Sequence NOT created - " + Name); 934 } 935 936 C_DocType_ID = SequenceIdData.getSequence(this, "C_DocType", client); 938 String IsDocNoControlled = ""; 939 String IsSOTrx = ""; 940 if (AD_Sequence_ID.equals("")) 941 IsDocNoControlled = "N"; 942 else 943 IsDocNoControlled = "Y"; 944 String IsTransferred = ""; 945 if (DocBaseType.equals("SOO")) 946 IsTransferred = "N"; 947 else 948 IsTransferred = "Y"; 949 if (DocBaseType.startsWith("AR") || DocBaseType.equals("MMS") || DocBaseType.equals("SOO")) 950 IsSOTrx = "Y"; 951 else 952 IsSOTrx = "N"; 953 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createDocType - C_DocType_ID: " + C_DocType_ID + ", AD_Client_ID: " + AD_Client_ID + ", Name: " + Name + ", PrintName: " + PrintName + "DocBaseType: " + DocBaseType + ", DocSubTypeSO: " + DocSubTypeSO + ", C_DocTypeShipment_ID: " + C_DocTypeShipment_ID + ", C_DocTypeInvoice_ID: " + C_DocTypeInvoice_ID + ", IsDocNoControlled: " + IsDocNoControlled + ", AD_Sequence_ID: " + AD_Sequence_ID + ", GL_Category_ID: " + GL_Category_ID + ", IsTransferred: " + IsTransferred + ", IsSOTrx: " + IsSOTrx); 954 if (InitialClientSetupData.insertDocType(conn ,this,C_DocType_ID, AD_Client_ID, Name, PrintName,DocBaseType, 955 DocSubTypeSO, C_DocTypeShipment_ID, C_DocTypeInvoice_ID, IsDocNoControlled, AD_Sequence_ID, GL_Category_ID, 956 IsTransferred, IsSOTrx, strTableId) != 1) 957 log4j.warn("InitialClientSetup - createDocType - DocType NOT created - " + Name); 958 releaseCommitConnection(conn); 960 } catch (NoConnectionAvailableException ex) { 961 throw new ServletException("@CODE=NoConnectionAvailable"); 962 } catch (SQLException ex2) { 963 try { 964 releaseRollbackConnection(conn); 965 } catch (Exception ignored) {} 966 throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage()); 967 } catch (Exception ex3) { 968 try { 969 releaseRollbackConnection(conn); 970 } catch (Exception ignored) {} 971 throw new ServletException("@CODE=@" + ex3.getMessage()); 972 } 973 return C_DocType_ID; 974 } 976 977 978 public boolean createEntities (VariablesSecureApp vars,String C_Country_ID, String City, String C_Region_ID) throws ServletException{ 979 m_info.append(SALTO_LINEA).append("----").append(SALTO_LINEA); 980 Connection conn = null; 981 try { 982 conn = this.getTransactionConnection(); 983 String defaultName = Utility.messageBD(this, "Standard", vars.getLanguage()); 985 986 String C_Channel_ID = SequenceIdData.getSequence(this, "C_Channel", client); 988 if (InitialClientSetupData.insertChannel(conn ,this,C_Channel_ID, defaultName, AD_Client_ID) != 1) 989 log4j.warn("InitialClientSetup - createEntities - Channel NOT inserted"); 990 String C_Campaign_ID = SequenceIdData.getSequence(this, "C_Campaign", client); 991 if (InitialClientSetupData.insertCampaign(conn ,this,C_Campaign_ID,C_Channel_ID, AD_Client_ID, defaultName) == 1) 992 m_info.append(Utility.messageBD(this, "C_Campaign_ID", vars.getLanguage())).append("=").append(defaultName).append(SALTO_LINEA); 993 else 994 log4j.warn("InitialClientSetup - createEntities - Campaign NOT inserted"); 995 if (m_hasMCampaign) { 996 if (InitialClientSetupData.updateAcctSchemaElementMC(conn ,this,C_Campaign_ID,C_AcctSchema_ID) != 1) 998 log4j.warn("InitialClientSetup - createEntities - AcctSchema ELement Campaign NOT updated"); 999 } 1000 releaseCommitConnection(conn); 1001 conn = this.getTransactionConnection(); 1002 1003 String C_SalesRegion_ID = SequenceIdData.getSequence(this, "C_SalesRegion", client); 1005 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - C_SalesRegion_ID: " + C_SalesRegion_ID + ", AD_Client_ID: " + AD_Client_ID + ", defaultName: " + defaultName); 1006 if (InitialClientSetupData.insertSalesRegion(conn ,this,C_SalesRegion_ID,AD_Client_ID,defaultName) == 1) 1007 m_info.append(Utility.messageBD(this, "C_SalesRegion_ID", vars.getLanguage())).append("=").append(defaultName).append(SALTO_LINEA); 1008 else 1009 log4j.warn("InitialClientSetup - createEntities - SalesRegion NOT inserted"); 1010 if (m_hasSRegion) { 1011 if (InitialClientSetupData.updateAcctSchemaElementSR(conn ,this,C_SalesRegion_ID,C_AcctSchema_ID) != 1) 1013 log4j.warn("InitialClientSetup - createEntities - AcctSchema ELement SalesRegion NOT updated"); 1014 } 1015 releaseCommitConnection(conn); 1016 conn = this.getTransactionConnection(); 1017 1018 1021 String C_BP_Group_ID = SequenceIdData.getSequence(this, "C_BP_Group", client); 1023 if (InitialClientSetupData.insertBPGroup(conn ,this,C_BP_Group_ID,AD_Client_ID,defaultName) == 1) 1024 m_info.append(Utility.messageBD(this, "C_BP_Group_ID", vars.getLanguage())).append("=").append(defaultName).append(SALTO_LINEA); 1025 else 1026 log4j.warn("InitialClientSetup - createEntities - BP Group NOT inserted"); 1027 1028 String C_BPartner_ID = SequenceIdData.getSequence(this, "C_BPartner", client); 1030 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - C_BPartner_ID: " + C_BPartner_ID + ", AD_Client_ID: " + AD_Client_ID + ", defaultName: " + defaultName + ", C_BP_Group_ID: " + C_BP_Group_ID); 1031 if (InitialClientSetupData.insertBPartner(conn ,this,C_BPartner_ID,AD_Client_ID,defaultName, C_BP_Group_ID) == 1) 1032 m_info.append(Utility.messageBD(this, "C_BPartner_ID", vars.getLanguage())).append("=").append(defaultName).append(SALTO_LINEA); 1033 else 1034 log4j.warn("InitialClientSetup - createEntities - BPartner NOT inserted"); 1035 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - C_BPartner_ID: " + C_BPartner_ID + ", C_AcctSchema_ID: " + C_AcctSchema_ID); 1037 if (InitialClientSetupData.updateAcctSchemaElementBP(conn ,this,C_BPartner_ID,C_AcctSchema_ID) != 1) 1038 log4j.warn("InitialClientSetup - createEntities - AcctSchema Element BPartner NOT updated"); 1039 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - C_BPartner_ID: " + C_BPartner_ID + ", C_AcctSchema_ID: " + C_AcctSchema_ID); 1040 1041 releaseCommitConnection(conn); 1045 conn = this.getTransactionConnection(); 1046 1047 1050 String A_Asset_Group_ID = SequenceIdData.getSequence(this, "A_Asset_Group", client); 1052 if (InitialClientSetupData.insertAssetGroup(conn ,this,C_BP_Group_ID,AD_Client_ID,defaultName) == 1) 1053 m_info.append(Utility.messageBD(this, "A_Asset_Group", vars.getLanguage())).append("=").append(defaultName).append(SALTO_LINEA); 1054 else 1055 log4j.warn("InitialClientSetup - createEntities - Asset Group NOT inserted"); 1056 1057 1058 1061 String M_Product_Category_ID = SequenceIdData.getSequence(this, "M_Product_Category", client); 1063 if (InitialClientSetupData.insertProductCategory(conn ,this,M_Product_Category_ID,AD_Client_ID, defaultName) == 1) 1064 m_info.append(Utility.messageBD(this, "M_Product_Category_ID", vars.getLanguage())).append("=").append(defaultName).append(SALTO_LINEA); 1065 else 1066 log4j.warn("InitialClientSetup - createEntities - Product Logger NOT inserted"); 1067 1068 String C_UOM_ID = "100"; 1070 1071 String append=""; 1073 String C_TaxCategory_ID = SequenceIdData.getSequence(this, "C_TaxCategory", client); 1074 if (C_Country_ID.equals("100")) append="Sales Tax"; 1076 else 1077 append=defaultName; 1078 if (InitialClientSetupData.insertTaxCategory(conn ,this,C_TaxCategory_ID,AD_Client_ID, append) != 1) 1079 log4j.warn("InitialClientSetup - createEntities - TaxCategory NOT inserted"); 1080 1081 String C_Tax_ID = SequenceIdData.getSequence(this, "C_Tax", client); 1083 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - C_Tax_ID: " + C_Tax_ID + ", AD_Client_ID: " + AD_Client_ID + ", defaultName: " + defaultName + ", C_TaxCategory_ID: " + C_TaxCategory_ID + ", C_Country_ID: " + C_Country_ID); 1084 if (InitialClientSetupData.insertTax(conn ,this,C_Tax_ID,AD_Client_ID,defaultName,C_TaxCategory_ID, C_Country_ID) != 1) 1085 log4j.warn("InitialClientSetup - createEntities - Tax NOT inserted"); 1086 1087 String M_Product_ID = SequenceIdData.getSequence(this, "M_Product", client); 1089 if (InitialClientSetupData.insertProduct(conn ,this,M_Product_ID,AD_Client_ID,defaultName,C_UOM_ID,M_Product_Category_ID,C_TaxCategory_ID) == 1) 1090 m_info.append(Utility.messageBD(this, "M_Product_ID", vars.getLanguage())).append("=").append(defaultName).append(SALTO_LINEA); 1091 else 1092 log4j.warn("InitialClientSetup - createEntities - Product NOT inserted"); 1093 if (InitialClientSetupData.updateAcctSchemaElementPR(conn ,this,M_Product_ID,C_AcctSchema_ID) != 1) 1095 log4j.warn("InitialClientSetup - createEntities - AcctSchema Element Product NOT updated"); 1096 releaseCommitConnection(conn); 1097 conn = this.getTransactionConnection(); 1098 1099 1102 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_Location: "); 1104 String C_Location_ID = SequenceIdData.getSequence(this, "C_Location", client); 1105 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -C_Location_ID: " + C_Location_ID); 1106 InitialClientSetupData.insertLocation(conn ,this,C_Location_ID,AD_Client_ID,City ,C_Country_ID, C_Region_ID); 1107 if (InitialClientSetupData.updateOrgInfo(conn ,this,C_Location_ID,AD_Org_ID) != 1) 1108 log4j.warn("InitialClientSetup - createEntities - Location NOT inserted"); 1109 1110 createPreference(vars,"C_Country_ID", C_Country_ID, ""); 1113 1114 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -M_Warehouse: "); 1116 String M_Warehouse_ID = SequenceIdData.getSequence(this, "M_Warehouse", client); 1117 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -M_Warehouse_ID: " + M_Warehouse_ID); 1118 if (InitialClientSetupData.insertWarehouse(conn ,this,M_Warehouse_ID,AD_Client_ID,AD_Org_ID, defaultName, C_Location_ID) != 1) 1119 log4j.warn("InitialClientSetup - createEntities - Warehouse NOT inserted"); 1120 1121 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -M_Locator: "); 1123 String M_Locator_ID = SequenceIdData.getSequence(this, "M_Locator", client); 1124 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -M_Locator_ID: " + M_Locator_ID); 1125 if (InitialClientSetupData.insertLocator(conn ,this,M_Locator_ID,AD_Client_ID, defaultName, M_Warehouse_ID) != 1) 1126 log4j.warn("InitialClientSetup - createEntities - Locator NOT inserted"); 1127 1128 if (InitialClientSetupData.updateClientInfo2(conn ,this,C_BPartner_ID,M_Product_ID, AD_Client_ID) != 1) 1130 { 1131 String err = "InitialClientSetup - createEntities - ClientInfo not updated"; 1132 log4j.warn(err); 1133 m_info.append(err).append(SALTO_LINEA); 1134 return false; 1135 } 1136 releaseCommitConnection(conn); 1137 conn = this.getTransactionConnection(); 1138 1139 1142 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -M_PriceList: "); 1144 String M_PriceList_ID = SequenceIdData.getSequence(this, "M_PriceList", client); 1145 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -M_PriceList_ID: " + M_PriceList_ID); 1146 if (InitialClientSetupData.insertPriceList(conn ,this,M_PriceList_ID, AD_Client_ID,defaultName, C_Currency_ID) != 1) 1147 log4j.warn("InitialClientSetup - createEntities - PriceList NOT inserted"); 1148 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -M_DiscountSchema: "); 1150 String M_DiscountSchema_ID = SequenceIdData.getSequence(this, "M_DiscountSchema", client); 1151 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -M_DiscountSchema_ID: " + M_DiscountSchema_ID); 1152 if (InitialClientSetupData.insertDiscountSchema(conn ,this,M_DiscountSchema_ID, AD_Client_ID,defaultName) != 1) 1153 log4j.warn("InitialClientSetup - createEntities - DiscountSchema NOT inserted"); 1154 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -M_PriceList_Version: "); 1156 String M_PriceList_Version_ID = SequenceIdData.getSequence(this, "M_PriceList_Version", client); 1157 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -M_PriceList_Version_ID: " + M_PriceList_Version_ID); 1158 if (InitialClientSetupData.insertPriceListVersion(conn ,this,M_PriceList_Version_ID, AD_Client_ID,M_PriceList_ID, M_DiscountSchema_ID) != 1) 1159 log4j.warn("InitialClientSetup - createEntities - PriceList_Version NOT inserted"); 1160 if (InitialClientSetupData.insertProductPrice(conn ,this,M_PriceList_Version_ID, AD_Client_ID,M_Product_ID) != 1) 1162 log4j.warn("InitialClientSetup - createEntities - ProductPrice NOT inserted"); 1163 1164 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_Location: "); 1166 C_Location_ID = SequenceIdData.getSequence(this, "C_Location", client); 1167 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -C_Location_ID: " + C_Location_ID); 1168 InitialClientSetupData.insertLocation(conn ,this,C_Location_ID, AD_Client_ID,City, C_Country_ID, C_Region_ID); 1169 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -C_Location_ID: " + C_Location_ID); 1170 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_BPartner_Location: "); 1171 String C_BPartner_Location_ID = SequenceIdData.getSequence(this, "C_BPartner_Location", client); 1172 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -C_BPartner_Location_ID: " + C_BPartner_Location_ID); 1173 if (InitialClientSetupData.insertBPartnerLocation(conn ,this,C_BPartner_Location_ID, AD_Client_ID,City, C_BPartner_ID, C_Location_ID) != 1) 1174 log4j.warn("InitialClientSetup - createEntities - BP_Location NOT inserted"); 1175 1176 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_BPartner: "); 1178 C_BPartner_ID = SequenceIdData.getSequence(this, "C_BPartner", client); 1179 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -C_BPartner_ID: " + C_BPartner_ID); 1180 if (InitialClientSetupData.insertBPartner2(conn ,this,C_BPartner_ID, AD_Client_ID,AD_User_U_Name, C_BP_Group_ID) == 1) 1181 m_info.append(Utility.messageBD(this, "IsSalesRep", vars.getLanguage())).append("=").append(AD_User_U_Name).append(SALTO_LINEA); 1182 else 1183 log4j.warn("InitialClientSetup - createEntities - SalesRep (User) NOT inserted"); 1184 if (InitialClientSetupData.updateUser(conn ,this, C_BPartner_ID,AD_User_U_ID) != 1) 1186 log4j.warn("InitialClientSetup - createEntities - User of SalesRep (User) NOT updated"); 1187 1188 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_BPartner: "); 1190 C_BPartner_ID = SequenceIdData.getSequence(this, "C_BPartner", client); 1191 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -C_BPartner_ID: " + C_BPartner_ID); 1192 if (InitialClientSetupData.insertBPartner2(conn ,this,C_BPartner_ID, AD_Client_ID,AD_User_Name, C_BP_Group_ID) == 1) 1193 m_info.append(Utility.messageBD(this, "IsSalesRep", vars.getLanguage())).append("=").append(AD_User_Name).append(SALTO_LINEA); 1194 else 1195 log4j.warn("InitialClientSetup - createEntities - SalesRep (Admin) NOT inserted"); 1196 if (InitialClientSetupData.updateUser(conn ,this, C_BPartner_ID,AD_User_ID) != 1) 1198 log4j.warn("InitialClientSetup - createEntities - User of SalesRep (Admin) NOT updated"); 1199 1200 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_PaymentTerm: "); 1202 String C_PaymentTerm_ID = SequenceIdData.getSequence(this, "C_PaymentTerm", client); 1203 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -C_PaymentTerm_ID: " + C_PaymentTerm_ID); 1204 if (InitialClientSetupData.insertPaymentTerm(conn ,this, C_PaymentTerm_ID,AD_Client_ID) != 1) 1205 log4j.warn("InitialClientSetup - createEntities - PaymentTerm NOT inserted"); 1206 1207 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_Cycle: "); 1209 C_Cycle_ID = SequenceIdData.getSequence(this, "C_Cycle", client); 1210 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -C_Cycle_ID: " + C_Cycle_ID); 1211 if (InitialClientSetupData.insertCycle(conn ,this, C_Cycle_ID,AD_Client_ID, defaultName, C_Currency_ID) != 1) 1212 log4j.warn("InitialClientSetup - createEntities - Cycle NOT inserted"); 1213 1214 releaseCommitConnection(conn); 1215 conn = this.getTransactionConnection(); 1216 1217 1220 1221 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_Project: "); 1223 String C_Project_ID = SequenceIdData.getSequence(this, "C_Project", client); 1224 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -C_Project_ID: " + C_Project_ID + ", AD_Client_ID: " + AD_Client_ID + ", AD_Org_ID: " + AD_Org_ID + ", defaultName: " + defaultName + ", C_Currency_ID: " + C_Currency_ID); 1225 if (InitialClientSetupData.insertProject(conn ,this, C_Project_ID,AD_Client_ID,AD_Org_ID, defaultName, C_Currency_ID) == 1) 1226 m_info.append(Utility.messageBD(this, "C_Project_ID", vars.getLanguage())).append("=").append(defaultName).append(SALTO_LINEA); 1227 else 1228 log4j.warn("InitialClientSetup - createEntities - Project NOT inserted"); 1229 if (m_hasProject) { 1231 if (InitialClientSetupData.updateAcctSchemaElement3(conn ,this, C_Project_ID,C_AcctSchema_ID) != 1) 1232 log4j.warn("InitialClientSetup - createEntities - AcctSchema ELement Project NOT updated"); 1233 } 1234 1235 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_CashBook: "); 1237 String C_CashBook_ID = SequenceIdData.getSequence(this, "C_CashBook", client); 1238 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - THE SEQUENCE -C_CashBook_ID: " + C_CashBook_ID); 1239 if (InitialClientSetupData.insertCashBook(conn ,this, C_CashBook_ID,AD_Client_ID,AD_Org_ID,defaultName,C_Currency_ID) == 1) 1240 m_info.append(Utility.messageBD(this, "C_CashBook_ID", vars.getLanguage())).append("=").append(defaultName).append(SALTO_LINEA); 1241 else 1242 log4j.warn("InitialClientSetup - createEntities - CashBook NOT inserted"); 1243 1244 1245 1252 releaseCommitConnection(conn); 1253 } catch (NoConnectionAvailableException ex) { 1254 throw new ServletException("@CODE=NoConnectionAvailable"); 1255 } catch (SQLException ex2) { 1256 try { 1257 releaseRollbackConnection(conn); 1258 } catch (Exception ignored) {} 1259 throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage()); 1260 } catch (Exception ex3) { 1261 try { 1262 releaseRollbackConnection(conn); 1263 } catch (Exception ignored) {} 1264 throw new ServletException("@CODE=@" + ex3.getMessage()); 1265 } 1266 return true; 1267} 1268 1269 private String getAcct(Connection conn, AccountingValueData [] data, String key) throws ServletException { 1270 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - getAcct - " + key); 1271 String C_ElementValue_ID = getC_ElementValue_ID(data, key); 1272 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - getAcct - C_ElementValue_ID: " + C_ElementValue_ID); 1273 Account vc = Account.getDefault(m_AcctSchema, true); 1274 vc.Account_ID=C_ElementValue_ID; 1275 vc.save(conn, this, AD_Client_ID, ""); String C_ValidCombination_ID = vc.C_ValidCombination_ID; 1277 if(C_ValidCombination_ID.equals("")) { 1278 log4j.warn("InitialClientSetup - getAcct - C_ElementValue_ID: " + C_ElementValue_ID); 1279 log4j.warn("InitialClientSetup - getAcct - no account for " + key); 1280 C_ValidCombination_ID = ""; } 1282 if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - getAcct - "+ key + "-- valid combination:" + C_ValidCombination_ID); 1283 return C_ValidCombination_ID; 1284 } 1285 1286 } 1287 | Popular Tags |