KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class DropCloseFactAcct extends HttpSecureAppServlet {
32   
33
34   public void init (ServletConfig config) {
35     super.init(config);
36     boolHist = false;
37   }
38
39   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
40     VariablesSecureApp vars = new VariablesSecureApp(request);
41
42     if (vars.commandIn("DEFAULT")) {
43       String JavaDoc strProcessId = vars.getStringParameter("inpProcessId");
44       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
45       String JavaDoc strTab = vars.getStringParameter("inpTabId");
46       String JavaDoc strCloseFactAcctGroupId = vars.getStringParameter("inpCloseFactAcctGroupId", "");
47       String JavaDoc strKey = vars.getRequiredGlobalVariable("inpcYearId", strWindow + "|C_Year_ID");
48       printPage(response, vars, strKey, strCloseFactAcctGroupId, strWindow, strTab, strProcessId);
49     } else if (vars.commandIn("SAVE")) {
50       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
51       String JavaDoc strCloseFactAcctGroupId = vars.getStringParameter("inpCloseFactAcctGroupId", "");
52       String JavaDoc strKey = vars.getRequiredGlobalVariable("inpcYearId", strWindow + "|C_Year_ID");
53       String JavaDoc strTab = vars.getStringParameter("inpTabId");
54       ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab);
55       String JavaDoc strWindowPath="", strTabName="";
56       if (tab!=null && tab.length!=0) {
57         strTabName = FormatUtilities.replace(tab[0].name);
58         strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html";
59       } else strWindowPath = strDefaultServlet;
60       String JavaDoc messageResult = processButton(vars, strCloseFactAcctGroupId, strWindow);
61       vars.setSessionValue(strWindow + "|" + strTabName + ".message", messageResult);
62       printPageClosePopUp(response, vars, strWindowPath);
63     } else pageErrorPopUp(response);
64   }
65
66
67   String JavaDoc processButton(VariablesSecureApp vars, String JavaDoc strCloseFactAcctGroupId, String JavaDoc windowId) {
68     try {
69       DropCloseFactAcctData.updatePeriods(this, strCloseFactAcctGroupId);
70       DropCloseFactAcctData.deleteFactAcct(this, strCloseFactAcctGroupId);
71       return Utility.messageBD(this, "ProcessOK", vars.getLanguage());
72     } catch (ServletException e) {
73       log4j.warn(e);
74       return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
75     }
76   }
77
78
79   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strCloseFactAcctGroupId, String JavaDoc windowId, String JavaDoc strTab, String JavaDoc strProcessId) throws IOException, ServletException {
80       if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Create Close Fact Acct");
81
82       ActionButtonDefaultData[] data = null;
83       String JavaDoc strHelp="", strDescription="";
84       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
85       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
86
87       if (data!=null && data.length!=0) {
88         strDescription = data[0].description;
89         strHelp = data[0].help;
90       }
91       String JavaDoc[] discard = {""};
92       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
93       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/DropCloseFactAcct", discard).createXmlDocument();
94       xmlDocument.setParameter("key", strKey);
95       xmlDocument.setParameter("window", windowId);
96       xmlDocument.setParameter("tab", strTab);
97       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
98       xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
99       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
100       xmlDocument.setParameter("description", strDescription);
101       xmlDocument.setParameter("help", strHelp);
102
103
104       xmlDocument.setData("reportCloseFactAcctGroupId", "liststructure", DropCloseFactAcctData.select(this,strKey));
105
106       xmlDocument.setParameter("CloseFactAcctGroupId", strCloseFactAcctGroupId);
107
108
109       response.setContentType("text/html; charset=UTF-8");
110       PrintWriter out = response.getWriter();
111       out.println(xmlDocument.print());
112       out.close();
113     }
114
115   public String JavaDoc getServletInfo() {
116     return "Servlet Drop reg fact acct";
117   } // end of getServletInfo() method
118
}
119
120
Popular Tags