KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.mail.smtp.SMTPMessage;
22
import org.openbravo.erpCommon.utility.Utility;
23 import org.openbravo.utils.FormatUtilities;
24 import org.openbravo.base.secureApp.HttpSecureAppServlet;
25 import org.openbravo.base.secureApp.VariablesSecureApp;
26 import org.openbravo.xmlEngine.XmlDocument;
27 import java.io.*;
28 import javax.servlet.*;
29 import javax.servlet.http.*;
30
31
32 // imports for transactions
33
import java.sql.Connection JavaDoc;
34
35 public class DropRegFactAcct extends HttpSecureAppServlet {
36   
37
38   public void init (ServletConfig config) {
39     super.init(config);
40     boolHist = false;
41   }
42
43   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
44     VariablesSecureApp vars = new VariablesSecureApp(request);
45
46     if (vars.commandIn("DEFAULT")) {
47       String JavaDoc strProcessId = vars.getStringParameter("inpProcessId");
48       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
49       String JavaDoc strTab = vars.getStringParameter("inpTabId");
50       String JavaDoc strRegFactAcctGroupId = vars.getStringParameter("inpRegFactAcctGroupId", "");
51       String JavaDoc strKey = vars.getRequiredGlobalVariable("inpcYearId", strWindow + "|C_Year_ID");
52       printPage(response, vars, strKey, strRegFactAcctGroupId, strWindow, strTab, strProcessId);
53     } else if (vars.commandIn("SAVE")) {
54       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
55       String JavaDoc strRegFactAcctGroupId = vars.getStringParameter("inpRegFactAcctGroupId", "");
56       String JavaDoc strKey = vars.getRequiredGlobalVariable("inpcYearId", strWindow + "|C_Year_ID");
57       String JavaDoc strTab = vars.getStringParameter("inpTabId");
58       ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab);
59       String JavaDoc strWindowPath="", strTabName="";
60       if (tab!=null && tab.length!=0) {
61         strTabName = FormatUtilities.replace(tab[0].name);
62         strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html";
63       } else strWindowPath = strDefaultServlet;
64       String JavaDoc messageResult = processButton(vars, strRegFactAcctGroupId);
65       vars.setSessionValue(strWindow + "|" + strTabName + ".message", messageResult);
66       printPageClosePopUp(response, vars, strWindowPath);
67     } else pageErrorPopUp(response);
68   }
69
70   String JavaDoc processButton(VariablesSecureApp vars, String JavaDoc strRegFactAcctGroupId) {
71       Connection JavaDoc conn = null;
72     try {
73       conn = this.getTransactionConnection();
74       String JavaDoc strCloseFactAcctGroupId = DropRegFactAcctData.selectClose(this, strRegFactAcctGroupId);
75       processButtonReg(conn, vars, strRegFactAcctGroupId);
76       if (!strCloseFactAcctGroupId.equals(""))processButtonClose(conn, vars, strCloseFactAcctGroupId);
77       releaseCommitConnection(conn);
78       return Utility.messageBD(this, "ProcessOK", vars.getLanguage());
79     } catch (Exception JavaDoc e) {
80       log4j.warn(e);
81       try {
82         releaseRollbackConnection(conn);
83       } catch (Exception JavaDoc ignored) {}
84       return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
85     }
86   }
87
88   String JavaDoc processButtonReg(Connection JavaDoc conn, VariablesSecureApp vars, String JavaDoc strRegFactAcctGroupId) throws ServletException{
89       DropRegFactAcctData.updatePeriods(conn, this, vars.getUser(), strRegFactAcctGroupId);
90       DropRegFactAcctData.deleteFactAcct(conn, this, strRegFactAcctGroupId);
91       return "ProcessOK";
92   }
93
94   String JavaDoc processButtonClose(Connection JavaDoc conn, VariablesSecureApp vars, String JavaDoc strCloseFactAcctGroupId) throws ServletException{
95     DropRegFactAcctData.updatePeriodsOpen(conn, this, vars.getUser(), strCloseFactAcctGroupId);
96     DropRegFactAcctData.updatePeriodsClose(conn, this, vars.getUser(), strCloseFactAcctGroupId);
97     DropRegFactAcctData.deleteFactAcctClose(conn, this, strCloseFactAcctGroupId);
98     return "ProcessOK";
99   }
100
101
102   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strRegFactAcctGroupId, String JavaDoc windowId, String JavaDoc strTab, String JavaDoc strProcessId) throws IOException, ServletException {
103       if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Create Close Fact Acct");
104
105       ActionButtonDefaultData[] data = null;
106       String JavaDoc strHelp="", strDescription="";
107       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
108       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
109
110       if (data!=null && data.length!=0) {
111         strDescription = data[0].description;
112         strHelp = data[0].help;
113       }
114       String JavaDoc[] discard = {""};
115       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
116       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/DropRegFactAcct", discard).createXmlDocument();
117       xmlDocument.setParameter("key", strKey);
118       xmlDocument.setParameter("window", windowId);
119       xmlDocument.setParameter("tab", strTab);
120       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
121       xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
122       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
123       xmlDocument.setParameter("description", strDescription);
124       xmlDocument.setParameter("help", strHelp);
125
126       xmlDocument.setData("reportRegFactAcctGroupId", "liststructure", DropRegFactAcctData.select(this,strKey));
127
128       xmlDocument.setParameter("RegFactAcctGroupId", strRegFactAcctGroupId);
129
130
131       response.setContentType("text/html; charset=UTF-8");
132       PrintWriter out = response.getWriter();
133       out.println(xmlDocument.print());
134       out.close();
135     }
136
137   public String JavaDoc getServletInfo() {
138     return "Servlet Drop reg fact acct";
139   } // end of getServletInfo() method
140
}
141
142
Popular Tags