KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_forms > InitialClientSetup


1 /*
2  ******************************************************************************
3  * The contents of this file are subject to the Compiere License Version 1.1
4  * ("License"); You may not use this file except in compliance with the License
5  * You may obtain a copy of the License at http://www.compiere.org/license.html
6  * Software distributed under the License is distributed on an "AS IS" basis,
7  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
8  * the specific language governing rights and limitations under the License.
9  * The Original Code is Compiere ERP & CRM Business Solution
10  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
11  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
12  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
13  * Contributor(s): Openbravo SL
14  * Contributions are Copyright (C) 2001-2006 Openbravo S.L.
15  ******************************************************************************
16 */

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 JavaDoc;
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 // imports for transactions
35
import java.sql.*;
36
37 public class InitialClientSetup extends HttpSecureAppServlet {
38   
39   static final String JavaDoc SALTO_LINEA = "<BR>\n";
40   String JavaDoc C_Currency_ID = "";
41   String JavaDoc clientName="";
42   String JavaDoc AD_User_ID="";
43   String JavaDoc AD_User_Name="";
44   String JavaDoc AD_User_U_Name="";
45   String JavaDoc AD_User_U_ID="";
46   String JavaDoc AD_Client_ID="";
47   String JavaDoc AD_Org_ID="";
48   String JavaDoc C_AcctSchema_ID="";
49   String JavaDoc client = "1000000";
50   AcctSchema m_AcctSchema;
51   private String JavaDoc C_Cycle_ID;
52   boolean m_hasProject ;
53   boolean m_hasMCampaign ;
54   boolean m_hasSRegion ;
55   String JavaDoc 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 JavaDoc m_info= new StringBuffer JavaDoc();
58   private final String JavaDoc CompiereSys = "N"; // Should NOT be changed
59

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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc procesarFichero(FieldProvider[] avData, HttpServletRequest request, HttpServletResponse response, VariablesSecureApp vars) throws IOException {
134
135     Connection conn = null;
136
137     String JavaDoc strCliente = new String JavaDoc(vars.getStringParameter("inpCliente").getBytes("ISO-8859-1"),"UTF-8");
138     String JavaDoc strOrganizacion = new String JavaDoc(vars.getStringParameter("inpOrganizacion").getBytes("ISO-8859-1"),"UTF-8");
139     String JavaDoc strClienteUsuario = new String JavaDoc(vars.getStringParameter("inpClienteUsuario").getBytes("ISO-8859-1"),"UTF-8");
140     String JavaDoc strOrganizacionUsuario = new String JavaDoc(vars.getStringParameter("inpOrganizacionUsuario").getBytes("ISO-8859-1"),"UTF-8");
141     String JavaDoc strMoneda = vars.getStringParameter("inpMoneda");
142     String JavaDoc strPais = vars.getStringParameter("inpPais");
143     String JavaDoc strCiudad = new String JavaDoc(vars.getStringParameter("inpCiudad").getBytes("ISO-8859-1"),"UTF-8");
144     String JavaDoc 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 JavaDoc err){
175       log4j.warn(err);
176       try {
177         releaseRollbackConnection(conn);
178       } catch (Exception JavaDoc ignored) {}
179     }
180     return m_info.toString();
181   }
182
183   public boolean isTrue(String JavaDoc s){
184     if (s==null || s.equals("")) return false;
185     else return true;
186   }
187
188
189   public boolean createClient(VariablesSecureApp vars, String JavaDoc m_ClientName, String JavaDoc orgName, String JavaDoc userClient, String JavaDoc 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       // info header
200
m_info.append(SALTO_LINEA);
201       // Standarc columns
202
String JavaDoc name = null;
203       int no = 0;
204
205
206   // * Create Client
207

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 JavaDoc 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       // Info - Client
223
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       // * Create Trees
228
// Get TreeTypes & Name
229
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 JavaDoc ex) {
236         throw new ServletException(ex);
237       }
238
239
240       if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createClient - LIST COUNT: " + data.length);
241
242       // Tree IDs
243

244
245       try {
246         int i =0;
247         while (i<data.length) {
248           String JavaDoc value = data[i].getField("id");
249           String JavaDoc 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            // Not added to clientinfo
271
}else if (!value.equals("MM")){ // No Menu
272
AD_Tree_ID = SequenceIdData.getSequence(this, "AD_Tree", client);
273           }
274           //
275
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       // Get Primary Tree
290
String JavaDoc AD_Tree_Menu_ID = "10"; // hardcoded
291
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 JavaDoc 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 // * Create Org
305

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 JavaDoc m_orgName = name;
311       if (InitialClientSetupData.insertOrg(conn ,this, AD_Client_ID, AD_Org_ID, name) != 1) {
312         String JavaDoc 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       // Info
319
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 // * Create Roles
326
// * - Admin
327
// * - User
328

329     
330       name = clientName + " Admin";
331       String JavaDoc 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 JavaDoc 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       // OrgAccess x,0
341
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       // OrgAccess x,y
345
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       // Info - Admin Role
349
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       //
353
name = clientName + " User";
354       String JavaDoc 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 JavaDoc 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       // OrgAccess x,y
364
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       // Info - Client Role
368
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 // * Create Users
375
// * - Client
376
// * - Org
377

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 JavaDoc 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       // Info
393
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 JavaDoc 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       // Info
412
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 // * Create User-Role
419

420       // ClientUser - Admin & User
421
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       // OrgUser - User
426
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       // SuperUser(100) - Admin & User
429
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 JavaDoc e) {
435       m_info.append(e).append(SALTO_LINEA);
436       try {
437         releaseRollbackConnection(conn);
438       } catch (Exception JavaDoc ignored) {}
439       try {
440         conn = this.getTransactionConnection();
441       } catch (Exception JavaDoc 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 JavaDoc AD_Client_ID, String JavaDoc AD_Org_ID, String JavaDoc 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 JavaDoc IsDocControlled = data[i].accountDocument.equals("Yes") ? "Y" : "N";
456       String JavaDoc C_ElementValue_ID = data[i].cElementValueId;
457       String JavaDoc IsSummary =data[i].accountSummary.equals("Yes") ? "Y" : "N";
458       String JavaDoc accountType="";
459       String JavaDoc accountSign="";
460       if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - save - AccountType debug");
461       if (!data[i].accountType.equals("")){
462         String JavaDoc 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 JavaDoc 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   }// save
501

502   public AccountingValueData[] parseData (FieldProvider[] data) throws ServletException {
503     AccountingValueData[] result = null;
504     Vector JavaDoc<Object JavaDoc> vec = new Vector JavaDoc<Object JavaDoc>();
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   }// parseData
533

534   public String JavaDoc getC_ElementValue_ID (AccountingValueData[] data, String JavaDoc 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   } // getC_ElementValue_ID
539

540   public boolean createAccounting(VariablesSecureApp vars, String JavaDoc newC_Currency_ID, String JavaDoc curName,boolean hasProduct, boolean hasBPartner, boolean hasProject,
541     boolean hasMCampaign, boolean hasSRegion,FieldProvider[] avData) throws ServletException{
542     //
543
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 JavaDoc name = null;
550     String JavaDoc C_Calendar_ID = null;
551     String JavaDoc C_Year_ID = null;
552     String JavaDoc C_Element_ID = null;
553     String JavaDoc C_ElementValue_ID = null;
554     String JavaDoc GAAP = null;
555     String JavaDoc CostingMethod = null;
556     AccountingValueData[] data = null;
557     try {
558       conn = this.getTransactionConnection();
559
560       // Standard variables
561
m_info.append(SALTO_LINEA);
562   
563   
564   // * Create Calendar
565

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 JavaDoc 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       // Info
577
m_info.append(Utility.messageBD(this, "C_Calendar_ID", vars.getLanguage())).append("=").append(name).append(SALTO_LINEA);
578   
579       // Year
580
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       // @todo Create Periods
584
if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - YEAR INSERTED");
585       releaseCommitConnection(conn);
586       conn = this.getTransactionConnection();
587
588       // Create Account Elements
589
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 JavaDoc 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       // Create Account Values
603
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 JavaDoc 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   // * Create AccountingSchema
616
C_ElementValue_ID = getC_ElementValue_ID(data, "DEFAULT_ACCT");
617       C_AcctSchema_ID = SequenceIdData.getSequence(this, "C_AcctSchema", client);
618       //
619
GAAP = "US"; // AD_Reference_ID=123
620
CostingMethod = "A"; // AD_Reference_ID=122
621
name = clientName + " " + GAAP + "/" + CostingMethod + "/" + curName;
622       //
623
if (InitialClientSetupData.insertAcctSchema(conn ,this, AD_Client_ID, C_AcctSchema_ID,name, GAAP, CostingMethod, C_Currency_ID) != 1){
624         String JavaDoc 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       // Info
632
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 JavaDoc ex3) {
638       throw new ServletException("@CODE=@" + ex3.getMessage());
639     }
640
641
642 // * Create AccountingSchema Elements (Structure)
643

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 JavaDoc ex) {
651       throw new ServletException(ex);
652     }
653
654
655     String JavaDoc 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 JavaDoc ElementType = data1[i].getField("id");
660         name = data1[i].getField("name");
661         //
662
String JavaDoc IsMandatory = "";
663         String JavaDoc IsBalanced = "N";
664         String JavaDoc SeqNo = "";
665         String JavaDoc 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         // Not OT, LF, LT, U1, U2, AY
705
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           // Default value for mandatory elements: OO and AC
712
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 JavaDoc e1) {
723      log4j.warn("InitialClientSetup - createAccounting - Elements", e1);
724      try {
725        releaseRollbackConnection(conn);
726      } catch (Exception JavaDoc 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       // Create AcctSchema
733
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 JavaDoc err = "InitialClientSetup - createAccounting - GL Accounts NOT inserted";
742           log4j.warn(err);
743           m_info.append(err);
744           return false;
745       }
746
747       String JavaDoc 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 JavaDoc 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 JavaDoc ex) {
777       try {
778         releaseRollbackConnection(conn);
779       } catch (Exception JavaDoc ignored) {}
780       throw new ServletException("@CODE=@" + ex.getMessage());
781     }
782
783     // GL Categories
784
String JavaDoc GL_Standard = createGLCategory(vars,"Standard", "M", true);
785     String JavaDoc GL_None = createGLCategory(vars,"None", "D", false);
786     String JavaDoc GL_GL = createGLCategory(vars,"Manual", "M", false);
787     String JavaDoc GL_ARI = createGLCategory(vars,"AR Invoice", "D", false);
788     String JavaDoc GL_ARR = createGLCategory(vars,"AR Receipt", "D", false);
789     String JavaDoc GL_MM = createGLCategory(vars,"Material Management", "D", false);
790     String JavaDoc GL_API = createGLCategory(vars,"AP Invoice", "D", false);
791     String JavaDoc GL_APP = createGLCategory(vars,"AP Payment", "D", false);
792     String JavaDoc GL_STT = createGLCategory(vars,"Settlement", "D", false);
793     String JavaDoc GL_CMB = createGLCategory(vars,"Bank Statement", "D", false);
794     String JavaDoc GL_CMC = createGLCategory(vars,"Cash", "D", false);
795     String JavaDoc GL_MMI = createGLCategory(vars,"Inventory", "D", false);
796     String JavaDoc GL_MMM = createGLCategory(vars,"Movement", "D", false);
797     String JavaDoc GL_MMP = createGLCategory(vars,"Production", "D", false);
798     String JavaDoc GL_MXI = createGLCategory(vars,"MatchInv", "D", false);
799     String JavaDoc GL_MXP = createGLCategory(vars,"MatchPO", "D", false);
800     if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createAccounting - GL CATEGORIES CREATED");
801
802     // Base DocumentTypes
803
createDocType(vars,"GL Journal", "Journal", "GLJ", "", "0", "0", "1000", GL_GL, "224");
804     String JavaDoc DT_I = createDocType(vars,"AR Invoice", "Invoice", "ARI", "", "0", "0", "100000", GL_ARI, "318");
805     String JavaDoc 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 JavaDoc DT_S = createDocType(vars,"MM Shipment", "Delivery Note", "MMS", "", "0", "0", "500000", GL_MM, "319");
809     String JavaDoc 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     // Order Entry
831
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"); // RE
837
String JavaDoc DT_WO = createDocType(vars,"Warehouse Order", "Order Confirmation", "SOO", "WP", DT_S, DT_I, "70000", GL_None, "259"); // LS
838
String JavaDoc DT = createDocType(vars,"POS Order", "Order Confirmation", "SOO", "WR", DT_SI, DT_II, "80000", GL_None, "259"); // Bar
839
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       // Update ClientInfo
845
if (InitialClientSetupData.updateClientInfo(conn ,this,C_AcctSchema_ID, C_Calendar_ID, AD_Client_ID) != 1){
846         String JavaDoc 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       //
855
releaseCommitConnection(conn);
856     } catch (SQLException ex2) {
857       try {
858         releaseRollbackConnection(conn);
859       } catch (Exception JavaDoc ignored) {}
860       throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage());
861     } catch (Exception JavaDoc ex3) {
862       try {
863         releaseRollbackConnection(conn);
864       } catch (Exception JavaDoc ignored) {}
865       throw new ServletException("@CODE=@" + ex3.getMessage());
866     }
867     return true;
868   } // createAccounting
869

870   private String JavaDoc createGLCategory (VariablesSecureApp vars, String JavaDoc Name, String JavaDoc CategoryType, boolean isDefault)throws ServletException{
871     Connection conn = null;
872     String JavaDoc GL_Category_ID = "";
873     try {
874       conn = this.getTransactionConnection();
875       GL_Category_ID = SequenceIdData.getSequence(this, "GL_Category", client);
876       String JavaDoc 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       //
880
releaseCommitConnection(conn);
881     } catch (NoConnectionAvailableException ex) {
882       throw new ServletException("@CODE=NoConnectionAvailable");
883     } catch (SQLException ex2) {
884       try {
885         releaseRollbackConnection(conn);
886       } catch (Exception JavaDoc ignored) {}
887       throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage());
888     } catch (Exception JavaDoc ex3) {
889       try {
890         releaseRollbackConnection(conn);
891       } catch (Exception JavaDoc ignored) {}
892       throw new ServletException("@CODE=@" + ex3.getMessage());
893     }
894     return GL_Category_ID;
895   }
896
897   private void createPreference (VariablesSecureApp vars, String JavaDoc Attribute, String JavaDoc Value, String JavaDoc AD_Window_ID)throws ServletException{
898     Connection conn = null;
899     try {
900       conn = this.getTransactionConnection();
901       String JavaDoc 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 JavaDoc ignored) {}
911       throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage());
912     } catch (Exception JavaDoc ex3) {
913       try {
914         releaseRollbackConnection(conn);
915       } catch (Exception JavaDoc ignored) {}
916       throw new ServletException("@CODE=@" + ex3.getMessage());
917     }
918   } // createPreference
919

920   private String JavaDoc createDocType (VariablesSecureApp vars, String JavaDoc Name, String JavaDoc PrintName,String JavaDoc DocBaseType, String JavaDoc DocSubTypeSO,
921     String JavaDoc C_DocTypeShipment_ID, String JavaDoc C_DocTypeInvoice_ID,String JavaDoc StartNo, String JavaDoc GL_Category_ID, String JavaDoc strTableId)throws ServletException{
922     Connection conn = null;
923     String JavaDoc C_DocType_ID = "";
924     try {
925       conn = this.getTransactionConnection();
926       StringBuffer JavaDoc sqlCmd = null;
927       // Get Sequence
928
String JavaDoc AD_Sequence_ID = "";
929       if (!StartNo.equals("0")){// manual sequenec, if startNo == 0
930
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       // Get Document Type
937
C_DocType_ID = SequenceIdData.getSequence(this, "C_DocType", client);
938       String JavaDoc IsDocNoControlled = "";
939       String JavaDoc IsSOTrx = "";
940       if (AD_Sequence_ID.equals(""))
941         IsDocNoControlled = "N";
942       else
943         IsDocNoControlled = "Y";
944       String JavaDoc 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       //
959
releaseCommitConnection(conn);
960     } catch (NoConnectionAvailableException ex) {
961       throw new ServletException("@CODE=NoConnectionAvailable");
962     } catch (SQLException ex2) {
963       try {
964         releaseRollbackConnection(conn);
965       } catch (Exception JavaDoc ignored) {}
966       throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage());
967     } catch (Exception JavaDoc ex3) {
968       try {
969         releaseRollbackConnection(conn);
970       } catch (Exception JavaDoc ignored) {}
971       throw new ServletException("@CODE=@" + ex3.getMessage());
972     }
973     return C_DocType_ID;
974   } // createDocType
975

976
977
978 public boolean createEntities (VariablesSecureApp vars,String JavaDoc C_Country_ID, String JavaDoc City, String JavaDoc 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     //
984
String JavaDoc defaultName = Utility.messageBD(this, "Standard", vars.getLanguage());
985   
986     // Create Marketing Channel/Campaign
987
String JavaDoc 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 JavaDoc 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       // Default
997
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    // Create Sales Region
1004
String JavaDoc 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      // Default
1012
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    /**
1019     * Business Partner
1020     */

1021    // Create BP Group
1022
String JavaDoc 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    // Create BPartner
1029
String JavaDoc 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    // Default
1036
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    //**************************************************************************************************************
1042
//**************************************************************************************************************
1043
//createPreference(vars,"C_BPartner_ID", C_BPartner_ID, "143");
1044
releaseCommitConnection(conn);
1045    conn = this.getTransactionConnection();
1046  
1047    /**
1048     * Asset
1049     */

1050    // Create Asset Group
1051
String JavaDoc 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    /**
1059     * Product
1060     */

1061    // Create Product Category
1062
String JavaDoc 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    // UOM (EA)
1069
String JavaDoc C_UOM_ID = "100";
1070  
1071    // TaxCategory
1072
String JavaDoc append="";
1073    String JavaDoc C_TaxCategory_ID = SequenceIdData.getSequence(this, "C_TaxCategory", client);
1074    if (C_Country_ID.equals("100")) // US
1075
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    // Tax - Zero Rate
1082
String JavaDoc 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    // Create Product
1088
String JavaDoc 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    // Default
1094
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    /**
1100     * Warehouse
1101     */

1102    // Location (Company)
1103
if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_Location: ");
1104    String JavaDoc 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    //*******************************************************************************************
1111
//*******************************************************************************************
1112
createPreference(vars,"C_Country_ID", C_Country_ID, "");
1113  
1114    // Default Warehouse
1115
if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -M_Warehouse: ");
1116    String JavaDoc 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    // Locator
1122
if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -M_Locator: ");
1123    String JavaDoc 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    // Update ClientInfo
1129
if (InitialClientSetupData.updateClientInfo2(conn ,this,C_BPartner_ID,M_Product_ID, AD_Client_ID) != 1)
1130    {
1131      String JavaDoc 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    /**
1140     * Other
1141     */

1142    // PriceList
1143
if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -M_PriceList: ");
1144    String JavaDoc 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    // DiscountSchema
1149
if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -M_DiscountSchema: ");
1150    String JavaDoc 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    // PriceList Version
1155
if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -M_PriceList_Version: ");
1156    String JavaDoc 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    // ProductPrice
1161
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    // Location for Standard BP
1165
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 JavaDoc 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    // Create Sales Rep for User
1177
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    // Update User
1185
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    // Create Sales Rep for Admin
1189
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    // Update User
1197
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    // Payment Term
1201
if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_PaymentTerm: ");
1202    String JavaDoc 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    // Project Cycle
1208
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    /**
1218     * Organization level data ===========================================
1219     */

1220  
1221    // Create Default Project
1222
if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_Project: ");
1223    String JavaDoc 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    // Default Project
1230
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    // CashBook
1236
if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - createEntities - SEQUENCE GENERATION -C_CashBook: ");
1237    String JavaDoc 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    // Create Other Defaults
1246
/* try {
1247      InitialClientSetupData.setup(this, AD_Client_ID,AD_Org_ID);
1248    }
1249    catch (Exception e) {
1250      log4j.warn("InitialClientSetup.CreateEntities - Call AD_Setup", e);
1251    }*/

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 JavaDoc ignored) {}
1259    throw new ServletException("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage());
1260  } catch (Exception JavaDoc ex3) {
1261    try {
1262      releaseRollbackConnection(conn);
1263    } catch (Exception JavaDoc ignored) {}
1264    throw new ServletException("@CODE=@" + ex3.getMessage());
1265  }
1266  return true;
1267}
1268
1269    private String JavaDoc getAcct(Connection conn, AccountingValueData [] data, String JavaDoc key) throws ServletException {
1270        if (log4j.isDebugEnabled()) log4j.debug("InitialClientSetup - getAcct - " + key);
1271        String JavaDoc 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, "");// BEFORE, HERE IT WAS 0
1276
String JavaDoc 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 = "";// HERE IT WAS 0
1281
}
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