KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_actionButton > Posted


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.ad_actionButton;
20
21 import org.openbravo.erpCommon.utility.SequenceIdData;
22 import org.openbravo.erpCommon.ad_forms.*;
23 import org.openbravo.erpCommon.reference.*;
24 import org.openbravo.erpCommon.utility.*;
25 import org.openbravo.utils.Replace;
26 import org.openbravo.utils.FormatUtilities;
27 import org.openbravo.base.secureApp.HttpSecureAppServlet;
28 import org.openbravo.base.secureApp.VariablesSecureApp;
29 import org.openbravo.xmlEngine.XmlDocument;
30 import java.io.*;
31 import javax.servlet.*;
32 import javax.servlet.http.*;
33
34 // imports for transactions
35
import java.sql.Connection JavaDoc;
36
37 public class Posted extends HttpSecureAppServlet {
38   
39
40   public void init (ServletConfig config) {
41     super.init(config);
42     boolHist = false;
43   }
44
45   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
46     if (log4j.isDebugEnabled()) log4j.debug("Posted: doPost");
47
48     VariablesSecureApp vars = new VariablesSecureApp(request);
49     
50     if (vars.commandIn("DEFAULT")) {
51       String JavaDoc strKey = vars.getGlobalVariable("inpKey", "Posted|key");
52       String JavaDoc strTableId = vars.getGlobalVariable("inpTableId", "Posted|tableId");
53       String JavaDoc strTabId = vars.getGlobalVariable("inpTabId", "Posted|tabId");
54       String JavaDoc strPosted = vars.getGlobalVariable("inpPosted", "Posted|posted");
55       String JavaDoc strProcessId = vars.getGlobalVariable("inpProcessId", "Posted|processId", "");
56       String JavaDoc strPath = vars.getGlobalVariable("inpPath", "Posted|path", strDireccion + request.getServletPath());
57       String JavaDoc strWindowId = vars.getGlobalVariable("inpWindowId", "Posted|windowId", "");
58       String JavaDoc strTabName = vars.getGlobalVariable("inpTabName", "Posted|tabName", "");
59
60       printPage(response, vars, strKey, strWindowId, strTabId, strProcessId, strTableId, strPath, strTabName, strPosted);
61     } else if (vars.commandIn("SAVE")) {
62       
63       String JavaDoc strKey = vars.getRequiredGlobalVariable("inpKey", "Posted|key");
64       String JavaDoc strTableId = vars.getRequiredGlobalVariable("inpTableId", "Posted|tableId");
65       String JavaDoc strTabId = vars.getRequestGlobalVariable("inpTabId", "Posted|tabId");
66       String JavaDoc strPosted = vars.getRequiredGlobalVariable("inpPosted", "Posted|posted");
67       String JavaDoc strProcessId = vars.getRequestGlobalVariable("inpProcessId", "Posted|processId");
68       String JavaDoc strPath = vars.getRequestGlobalVariable("inpPath", "Posted|path");
69       String JavaDoc strWindowId = vars.getRequestGlobalVariable("inpWindowId", "Posted|windowId");
70       String JavaDoc strTabName = vars.getRequestGlobalVariable("inpTabName", "Posted|tabName");
71       String JavaDoc strEliminar = vars.getStringParameter("inpEliminar", "N");
72       
73
74       if (log4j.isDebugEnabled()) log4j.debug("SAVE, strPosted: " +strPosted+" Elim "+strEliminar);
75
76       ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTabId);
77       String JavaDoc strWindowPath="";
78       if (tab!=null && tab.length!=0) {
79         strTabName = FormatUtilities.replace(tab[0].name);
80         strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html";
81       } else strWindowPath = strDefaultServlet;
82       
83       if (strPosted.equals("N")){
84         OBError messageResult = processButton(vars, strKey, strTableId);
85         if (!messageResult.getType().equals("Success")){
86           vars.setMessage(strTabId, messageResult);
87           printPageClosePopUp(response, vars);
88         } else {
89           PostedData [] data = PostedData.select(this, strKey, strTableId);
90           if (data==null || data.length==0 || data[0].id.equals("")) {
91           // vars.setSessionValue(strWindowId + "|" + strTabName + ".message", messageResult);
92
vars.setMessage(strTabId, messageResult);
93             printPageClosePopUp(response, vars);
94           } else {
95             printPageClosePopUp(response, vars, (strDireccion + "/ad_reports/ReportGeneralLedgerJournal.html?Command=DIRECT&inpTable=" + strTableId + "&inpRecord=" + strKey + "&inpOrg=" + data[0].org));
96           }
97         }
98       } else {
99         if (strEliminar.equals("N")) {
100           PostedData [] data = PostedData.select(this, strKey, strTableId);
101           if (data==null || data.length==0 || data[0].id.equals("")) {
102             //if (log4j.isDebugEnabled()) log4j.debug("***********************" + strWindowId + "|" + strTabName + ".message");
103
//vars.setSessionValue(strWindowId + "|" + strTabName + ".message", Utility.messageBD(this, "NoFactAcct", vars.getLanguage()));
104
vars.setMessage(strTabId, Utility.translateError(this, vars, vars.getLanguage(), "NoFactAcct"));
105             printPageClosePopUp(response, vars);
106           } else {
107             printPageClosePopUp(response, vars, (strDireccion + "/ad_reports/ReportGeneralLedgerJournal.html?Command=DIRECT&inpTable=" + strTableId + "&inpRecord=" + strKey + "&inpOrg=" + data[0].org));
108           }
109         } else {
110           if (log4j.isDebugEnabled()) log4j.debug("SAVE, delete");
111           OBError myMessage = processButtonDelete(vars, strKey, strTableId);
112           vars.setMessage(strTabId, myMessage);
113           printPageClosePopUp(response, vars);
114         }
115       }
116     } else pageErrorPopUp(response);
117   }
118
119
120   OBError processButton(VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strTableId) {
121     if (log4j.isDebugEnabled()) log4j.debug("ProcessButton strKey: "+strKey+"strTableId: "+strTableId );
122     Connection JavaDoc con = null;
123     OBError myMessage = null;
124     try {
125       con = getTransactionConnection();
126       AcctServer acct = AcctServer.get(strTableId, vars.getClient());
127       if (!acct.post(strKey,false, vars,this,con)) {
128           releaseRollbackConnection(con);
129          // return (Utility.messageBD(this, "ProcessRunError", vars.getLanguage()) + "\\n" + acct.getInfo(vars));
130
myMessage = Utility.translateError(this, vars, vars.getLanguage(), "ProcessRunError"+ "\\n" + acct.getInfo(vars));
131       }
132       // Create Automatic Matching
133
//acct.match (vars, this,con);
134
releaseCommitConnection(con);
135     } catch (Exception JavaDoc e) {
136       log4j.error(e);
137       myMessage = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage());
138       try {
139         releaseRollbackConnection(con);
140       } catch (Exception JavaDoc ignored) {}
141    }
142     
143     if (myMessage==null) {
144       myMessage = new OBError();
145       myMessage.setType("Success");
146       myMessage.setTitle("");
147       myMessage.setMessage(Utility.messageBD(this, "Success", vars.getLanguage()));
148     }
149     return myMessage;
150   }
151
152   OBError processButtonDelete(VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strTableId) throws ServletException {
153     OBError myMessage = null;
154     
155     try {
156     
157       String JavaDoc strClient = PostedData.selectClient(this, PostedData.selectTableName(this, strTableId), strKey);
158       String JavaDoc pinstance = SequenceIdData.getSequence(this, "AD_PInstance", vars.getClient());
159       PInstanceProcessData.insertPInstance(this, pinstance, "176", strKey, "N", vars.getUser(), vars.getClient(), vars.getOrg());
160       PInstanceProcessData.insertPInstanceParamNumber(this, pinstance, "10", "AD_Client_ID", strClient, vars.getClient(), vars.getOrg(), vars.getUser());
161       PInstanceProcessData.insertPInstanceParamNumber(this, pinstance, "20", "AD_Table_ID", strTableId, vars.getClient(), vars.getOrg(), vars.getUser());
162       PInstanceProcessData.insertPInstanceParam(this, pinstance, "30", "DeletePosting", "Y", vars.getClient(), vars.getOrg(), vars.getUser());
163       if (log4j.isDebugEnabled()) log4j.debug("delete, pinstance " + pinstance);
164       ActionButtonData.process176(this, pinstance);
165   
166       PInstanceProcessData[] pinstanceData = PInstanceProcessData.select(this, pinstance);
167       myMessage = Utility.getProcessInstanceMessage(this, vars, pinstanceData);
168     } catch (ServletException ex) {
169       myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
170     }
171     if (myMessage==null) {
172       myMessage = new OBError();
173       myMessage.setType("Success");
174       myMessage.setTitle("");
175       myMessage.setMessage(Utility.messageBD(this, "Success", vars.getLanguage()));
176     }
177     return myMessage;
178   }
179
180
181     void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc windowId, String JavaDoc strTab, String JavaDoc strProcessId, String JavaDoc strTableId, String JavaDoc strPath, String JavaDoc strTabName, String JavaDoc strPosted) throws IOException, ServletException {
182       if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Posted");
183
184       ActionButtonDefaultData[] data = null;
185       String JavaDoc strHelp="", strDescription="";
186       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
187       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
188
189       if (data!=null && data.length!=0) {
190         strDescription = data[0].description;
191         strHelp = data[0].help;
192       }
193       String JavaDoc[] discard ={"",""};
194       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
195       if (strPosted.equals("N")) discard[1] = new String JavaDoc("selEliminar");
196       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/Posted", discard).createXmlDocument();
197       xmlDocument.setParameter("key", strKey);
198       xmlDocument.setParameter("window", windowId);
199       xmlDocument.setParameter("tab", strTab);
200       xmlDocument.setParameter("process", strProcessId);
201       xmlDocument.setParameter("table", strTableId);
202       xmlDocument.setParameter("posted", strPosted);
203       xmlDocument.setParameter("path", strPath);
204       xmlDocument.setParameter("tabname", strTabName);
205
206       String JavaDoc message = vars.getSessionValue("Posted|message");
207       if (!message.equals("")) message = "alert('" + message + "');";
208       vars.removeSessionValue("Posted|message");
209       xmlDocument.setParameter("message", message);
210       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
211       xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
212       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
213       xmlDocument.setParameter("description", strDescription);
214       xmlDocument.setParameter("help", strHelp);
215
216       response.setContentType("text/html; charset=UTF-8");
217       PrintWriter out = response.getWriter();
218       out.println(xmlDocument.print());
219       out.close();
220     }
221
222   public String JavaDoc getServletInfo() {
223     return "Servlet Posted";
224   } // end of getServletInfo() method
225
}
226
227
Popular Tags