KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > info > Account


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

19 package org.openbravo.erpCommon.info;
20
21 import org.openbravo.base.secureApp.*;
22 import org.openbravo.xmlEngine.XmlDocument;
23 import org.openbravo.erpCommon.utility.Utility;
24 import org.openbravo.erpCommon.utility.ComboTableData;
25
26 import java.io.*;
27 import javax.servlet.*;
28 import javax.servlet.http.*;
29 import org.openbravo.utils.Replace;
30
31
32
33 public class Account extends HttpSecureAppServlet {
34
35
36   public void init (ServletConfig config) {
37     super.init(config);
38     boolHist = false;
39   }
40
41   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
42     VariablesSecureApp vars = new VariablesSecureApp(request);
43
44     if (vars.commandIn("DEFAULT")) {
45       String JavaDoc strNameValue = vars.getRequestGlobalVariable("inpNameValue", "Account.combination");
46       String JavaDoc strAcctSchema = vars.getRequestGlobalVariable("inpAcctSchema", "Account.cAcctschemaId");
47       if (strAcctSchema.equals("")) {
48         strAcctSchema = Utility.getContext(this, vars, "$C_AcctSchema_ID", "Account");
49         vars.setSessionValue("Account.cAcctschemaId", strAcctSchema);
50       }
51       vars.removeSessionValue("Account.alias");
52       if (!strNameValue.equals("")) vars.setSessionValue("Account.combination", strNameValue + "%");
53       printPageFS(response, vars);
54     } else if (vars.commandIn("LOAD_FIELD")) {
55       String JavaDoc strClave = vars.getStringParameter("inpClave");
56       printPageFrame1(response, vars, "", "", strClave, false);
57     } else if (vars.commandIn("KEY")) {
58       String JavaDoc strKeyValue = vars.getRequestGlobalVariable("inpNameValue", "Account.alias");
59       String JavaDoc strAcctSchema = vars.getRequestGlobalVariable("inpAcctSchema", "Account.cAcctschemaId");
60       if (strAcctSchema.equals("")) {
61         strAcctSchema = Utility.getContext(this, vars, "$C_AcctSchema_ID", "Account");
62         vars.setSessionValue("Account.cAcctschemaId", strAcctSchema);
63       }
64       vars.removeSessionValue("Account.combination");
65       vars.setSessionValue("Account.alias", strKeyValue + "%");
66       AccountData[] data = AccountData.selectKey(this, strAcctSchema, Utility.getContext(this, vars, "#User_Client", "Account"), Utility.getContext(this, vars, "#User_Org", "Account"), strKeyValue + "%");
67       if (data!=null && data.length==1) {
68         printPageKey(response, vars, data);
69       } else printPageFS(response, vars);
70     } else if (vars.commandIn("FRAME1")) {
71       String JavaDoc strAlias = vars.getGlobalVariable("inpAlias", "Account.alias", "");
72       String JavaDoc strCombination = vars.getGlobalVariable("inpCombination", "Account.combination", "");
73       printPageFrame1(response, vars, strAlias, strCombination, "", true);
74     } else if (vars.commandIn("FRAME2")) {
75       String JavaDoc strAlias = vars.getGlobalVariable("inpAlias", "Account.alias", "");
76       String JavaDoc strCombination = vars.getGlobalVariable("inpCombination", "Account.combination", "");
77       String JavaDoc strOrganization = vars.getStringParameter("inpOrganization");
78       String JavaDoc strAccount = vars.getStringParameter("inpAccount");
79       String JavaDoc strProduct = vars.getStringParameter("inpProduct");
80       String JavaDoc strBPartner = vars.getStringParameter("inpBPartner");
81       String JavaDoc strProject = vars.getStringParameter("inpProject");
82       String JavaDoc strCampaign = vars.getStringParameter("inpCampaign");
83       printPageFrame2(response, vars, strAlias, strCombination, strOrganization, strAccount, strProduct, strBPartner, strProject, strCampaign);
84     } else if (vars.commandIn("FIND")) {
85       String JavaDoc strAlias = vars.getRequestGlobalVariable("inpAlias", "Account.alias");
86       String JavaDoc strCombination = vars.getRequestGlobalVariable("inpCombination", "Account.combination");
87       String JavaDoc strOrganization = vars.getStringParameter("inpOrganization");
88       String JavaDoc strAccount = vars.getStringParameter("inpAccount");
89       String JavaDoc strProduct = vars.getStringParameter("inpProduct");
90       String JavaDoc strBPartner = vars.getStringParameter("inpBPartner");
91       String JavaDoc strProject = vars.getStringParameter("inpProject");
92       String JavaDoc strCampaign = vars.getStringParameter("inpCampaign");
93
94       vars.setSessionValue("Account.initRecordNumber", "0");
95       printPageFrame2(response, vars, strAlias, strCombination, strOrganization, strAccount, strProduct, strBPartner, strProject, strCampaign);
96     } else if (vars.commandIn("FRAME3")) {
97       printPageFrame3(response, vars);
98     } else if (vars.commandIn("SAVE")) {
99       String JavaDoc strAcctSchema = vars.getSessionValue("Account.cAcctschemaId");
100       String JavaDoc strClave = vars.getStringParameter("inpValidCombination");
101       String JavaDoc strAlias = vars.getRequestGlobalVariable("inpAlias", "Account.alias");
102       String JavaDoc strOrganization = vars.getRequiredStringParameter("inpOrganization");
103       String JavaDoc strAccount = vars.getRequiredStringParameter("inpAccount");
104       String JavaDoc strProduct = vars.getStringParameter("inpProduct");
105       String JavaDoc strBPartner = vars.getStringParameter("inpBPartner");
106       String JavaDoc strProject = vars.getStringParameter("inpProject");
107       String JavaDoc strCampaign = vars.getStringParameter("inpCampaign");
108       AccountData data = AccountData.insert(this, vars.getClient(), strOrganization, strAcctSchema, strAccount, strClave, strAlias, vars.getUser(), strProduct, strBPartner, strProject, strCampaign);
109       if (data!=null) strClave = data.cValidcombinationId;
110       vars.removeSessionValue("Account.alias");
111       vars.setSessionValue("Account.combination", AccountData.combination(this, strClave));
112       printPageFS(response, vars);
113     } else if (vars.commandIn("PREVIOUS")) {
114       String JavaDoc strInitRecord = vars.getSessionValue("Account.initRecordNumber");
115       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Account");
116       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
117       if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("Account.initRecordNumber", "0");
118       else {
119         int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
120         initRecord -= intRecordRange;
121         strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
122         vars.setSessionValue("Account.initRecordNumber", strInitRecord);
123       }
124
125       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
126     } else if (vars.commandIn("NEXT")) {
127       String JavaDoc strInitRecord = vars.getSessionValue("Account.initRecordNumber");
128       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Account");
129       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
130       int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
131       if (initRecord==0) initRecord=1;
132       initRecord += intRecordRange;
133       strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
134       vars.setSessionValue("Account.initRecordNumber", strInitRecord);
135
136       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
137     } else pageError(response);
138   }
139
140   void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
141     if (log4j.isDebugEnabled()) log4j.debug("Output: Account seeker Frame Set");
142     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Account_FS").createXmlDocument();
143
144     response.setContentType("text/html; charset=UTF-8");
145     PrintWriter out = response.getWriter();
146     out.println(xmlDocument.print());
147     out.close();
148   }
149
150   void printPageKey(HttpServletResponse response, VariablesSecureApp vars, AccountData[] data) throws IOException, ServletException {
151     if (log4j.isDebugEnabled()) log4j.debug("Output: Account seeker Frame Set");
152     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/SearchUniqueKeyResponse").createXmlDocument();
153
154     xmlDocument.setParameter("script", generateResult(data));
155     response.setContentType("text/html; charset=UTF-8");
156     PrintWriter out = response.getWriter();
157     out.println(xmlDocument.print());
158     out.close();
159   }
160
161   String JavaDoc generateResult(AccountData[] data) throws IOException, ServletException {
162     StringBuffer JavaDoc html = new StringBuffer JavaDoc();
163
164     html.append("\nfunction depurarSelector() {\n");
165     html.append("var clave = \"" + data[0].cValidcombinationId + "\";\n");
166     html.append("var texto = \"" + Replace.replace(data[0].combination, "\"", "\\\"") + "\";\n");
167     html.append("parent.opener.closeSearch(\"SAVE\", clave, texto, null);\n");
168     html.append("}\n");
169     return html.toString();
170   }
171
172   void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strAlias, String JavaDoc strCombination, String JavaDoc strValidCombination, boolean isDefault) throws IOException, ServletException {
173     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of the accounts seeker");
174     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Account_F1").createXmlDocument();
175     AccountData[] data = null;
176     if (isDefault) {
177       if (strAlias.equals("") && strCombination.equals("")) strAlias = "%";
178       data = AccountData.set(strAlias, strCombination);
179     } else {
180       data = AccountData.select(this, "", "", "", "", "", "", "", "", "", strValidCombination, Utility.getContext(this, vars, "#User_Client", "Account"), Utility.getContext(this, vars, "#User_Org", "Account"));
181     }
182     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
183     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
184     xmlDocument.setData("structure1", data);
185     try {
186       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "C_Campaign_ID", "C_Campaign", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0);
187       Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", "");
188       xmlDocument.setData("reportC_Campaign_ID","liststructure", comboTableData.select(false));
189       comboTableData = null;
190     } catch (Exception JavaDoc ex) {
191       throw new ServletException(ex);
192     }
193
194     try {
195       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "C_Project_ID", "C_Project", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0);
196       Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", "");
197       xmlDocument.setData("reportC_Project_ID","liststructure", comboTableData.select(false));
198       comboTableData = null;
199     } catch (Exception JavaDoc ex) {
200       throw new ServletException(ex);
201     }
202
203
204     try {
205       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "AD_Org_ID", "AD_Org (Trx)", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0);
206       Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", "");
207       xmlDocument.setData("reportAD_Org_ID","liststructure", comboTableData.select(false));
208       comboTableData = null;
209     } catch (Exception JavaDoc ex) {
210       throw new ServletException(ex);
211     }
212
213
214     try {
215       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "Account_ID", "C_ElementValue (Accounts)", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0);
216       Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", "");
217       xmlDocument.setData("reportAccount_ID","liststructure", comboTableData.select(false));
218       comboTableData = null;
219     } catch (Exception JavaDoc ex) {
220       throw new ServletException(ex);
221     }
222
223
224     try {
225       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "M_Product_ID", "M_Product (no summary)", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0);
226       Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", "");
227       xmlDocument.setData("reportM_Product_ID","liststructure", comboTableData.select(false));
228       comboTableData = null;
229     } catch (Exception JavaDoc ex) {
230       throw new ServletException(ex);
231     }
232
233
234     try {
235       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "C_BPartner_ID", "C_BPartner", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0);
236       Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", "");
237       xmlDocument.setData("reportC_BPartner_ID","liststructure", comboTableData.select(false));
238       comboTableData = null;
239     } catch (Exception JavaDoc ex) {
240       throw new ServletException(ex);
241     }
242
243     response.setContentType("text/html; charset=UTF-8");
244     PrintWriter out = response.getWriter();
245     out.println(xmlDocument.print());
246     out.close();
247   }
248
249   void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strAlias, String JavaDoc strCombination, String JavaDoc strOrganization, String JavaDoc strAccount, String JavaDoc strProduct, String JavaDoc strBPartner, String JavaDoc strProject, String JavaDoc strCampaign) throws IOException, ServletException {
250     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the accounts seeker");
251     XmlDocument xmlDocument;
252     String JavaDoc strAcctSchema = vars.getSessionValue("Account.cAcctschemaId");
253
254     String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Account");
255     int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange));
256     String JavaDoc strInitRecord = vars.getSessionValue("Account.initRecordNumber");
257     int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
258
259     if (strAlias.equals("") && strCombination.equals("") && strOrganization.equals("") && strAccount.equals("") && strProduct.equals("") && strBPartner.equals("") && strProject.equals("") && strCampaign.equals("")) {
260       String JavaDoc[] discard = {"sectionDetail", "hasPrevious", "hasNext"};
261       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Account_F2", discard).createXmlDocument();
262       xmlDocument.setData("structure1", AccountData.set(strAlias, strCombination));
263     } else {
264       String JavaDoc[] discard = {"withoutPrevious", "withoutNext"};
265       AccountData[] data = AccountData.select(this, strAcctSchema, strAlias, strCombination, strOrganization, strAccount, strProduct, strBPartner, strProject, strCampaign, "", Utility.getContext(this, vars, "#User_Client", "Account"), Utility.getContext(this, vars, "#User_Org", "Account"), initRecordNumber, intRecordRange);
266       if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String JavaDoc("hasPrevious");
267       if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String JavaDoc("hasNext");
268       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Account_F2", discard).createXmlDocument();
269       xmlDocument.setData("structure1", data);
270     }
271
272     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
273     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
274     response.setContentType("text/html; charset=UTF-8");
275     PrintWriter out = response.getWriter();
276     out.println(xmlDocument.print());
277     out.close();
278   }
279
280   void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
281     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the business partners seeker");
282     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Account_F3").createXmlDocument();
283
284     response.setContentType("text/html; charset=UTF-8");
285     PrintWriter out = response.getWriter();
286     out.println(xmlDocument.print());
287     out.close();
288   }
289
290   public String JavaDoc getServletInfo() {
291     return "Servlet that presents que accounts seeker";
292   } // end of getServletInfo() method
293
}
294
Popular Tags