KickJava   Java API By Example, From Geeks To Geeks.

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


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.SequenceIdData;
23 import org.openbravo.erpCommon.utility.Utility;
24 import org.openbravo.utils.FormatUtilities;
25 import org.openbravo.base.secureApp.HttpSecureAppServlet;
26 import org.openbravo.base.secureApp.VariablesSecureApp;
27 import org.openbravo.xmlEngine.XmlDocument;
28 import java.io.*;
29 import java.math.*;
30 import javax.servlet.*;
31 import javax.servlet.http.*;
32
33 public class CreateCloseFactAcct 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 strProcessId = vars.getStringParameter("inpProcessId");
46       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
47       String JavaDoc strTab = vars.getStringParameter("inpTabId");
48       String JavaDoc strPediodId = vars.getStringParameter("inpcPeriodId", "");
49       String JavaDoc strKey = vars.getRequiredGlobalVariable("inpcYearId", strWindow + "|C_Year_ID");
50       printPage(response, vars, strKey, strPediodId, strWindow, strTab, strProcessId);
51     } else if (vars.commandIn("SAVE")) {
52       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
53       String JavaDoc strPediodId = vars.getStringParameter("inpcPeriodId", "");
54       String JavaDoc strKey = vars.getRequiredGlobalVariable("inpcYearId", strWindow + "|C_Year_ID");
55       String JavaDoc strTab = vars.getStringParameter("inpTabId");
56       ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab);
57       String JavaDoc strWindowPath="", strTabName="";
58       if (tab!=null && tab.length!=0) {
59         strTabName = FormatUtilities.replace(tab[0].name);
60         strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html";
61       } else strWindowPath = strDefaultServlet;
62       String JavaDoc messageResult = processButton(vars, strKey, strPediodId, strWindow);
63       vars.setSessionValue(strWindow + "|" + strTabName + ".message", messageResult);
64       printPageClosePopUp(response, vars, strWindowPath);
65     } else pageErrorPopUp(response);
66   }
67
68
69   String JavaDoc processButton(VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strPediodId, String JavaDoc windowId) {
70     try {
71       CreateCloseFactAcctData[] asset = CreateCloseFactAcctData.getAmounts(this, strKey, strPediodId, "A");
72       CreateCloseFactAcctData[] liability = CreateCloseFactAcctData.getAmounts(this, strKey, strPediodId, "L");
73       BigDecimal AmtCr, AmtDr;
74       BigDecimal assetAmtDr = new BigDecimal("0");
75       BigDecimal assetAmtCr = new BigDecimal("0");
76       BigDecimal liabilityAmtDr = new BigDecimal("0");
77       BigDecimal liabilityAmtCr = new BigDecimal("0");
78       String JavaDoc strAcctSchema = Utility.getContext(this, vars, "$C_ACCTSCHEMA_ID", windowId);;
79       String JavaDoc Fact_Acct_ID = "";
80       String JavaDoc Fact_Acct_Group_ID = "";
81       String JavaDoc newPeriod = "";
82       if(CreateCloseFactAcctData.getNextPeriod(this, strPediodId, strKey).equals(""))
83         if (CreateCloseFactAcctData.getNextYear(this, strKey).equals(""))return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
84         else if (CreateCloseFactAcctData.getFirstPeriod(this, CreateCloseFactAcctData.getNextYear(this, strKey)).equals(""))
85           return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
86         else newPeriod = CreateCloseFactAcctData.getFirstPeriod(this, CreateCloseFactAcctData.getNextYear(this, strKey));
87       else newPeriod = CreateCloseFactAcctData.getNextPeriod(this, strPediodId, strKey);
88       Fact_Acct_Group_ID = SequenceIdData.getSequence(this, "Fact_Acct_Group", vars.getClient());
89       int i;
90       for (i=0;i<asset.length;i++){
91         assetAmtDr = assetAmtDr.add(new BigDecimal(asset[i].totalamtdr));
92         assetAmtCr = assetAmtCr.add(new BigDecimal(asset[i].totalamtcr));
93         Fact_Acct_ID = SequenceIdData.getSequence(this, "Fact_Acct", vars.getClient());
94         CreateCloseFactAcctData.insert(this, Fact_Acct_ID, vars.getClient(), vars.getOrg(), vars.getUser(), strAcctSchema, asset[i].accountId, CreateCloseFactAcctData.getEndDate(this, strPediodId), strPediodId, CreateCloseFactAcctData.adTableId(this), "A", CreateCloseFactAcctData.cCurrencyId(this, strAcctSchema),asset[i].totalamtdr,asset[i].totalamtcr,asset[i].totalamtdr,asset[i].totalamtcr , Fact_Acct_Group_ID, Integer.toString((i+3)*10), "C");
95       }
96       for (int j=0;j<liability.length;j++){
97         liabilityAmtDr = liabilityAmtDr.add(new BigDecimal(liability[j].totalamtdr));
98         liabilityAmtCr = liabilityAmtCr.add(new BigDecimal(liability[j].totalamtcr));
99         Fact_Acct_ID = SequenceIdData.getSequence(this, "Fact_Acct", vars.getClient());
100         CreateCloseFactAcctData.insert(this, Fact_Acct_ID, vars.getClient(), vars.getOrg(), vars.getUser(), strAcctSchema, liability[j].accountId, CreateCloseFactAcctData.getEndDate(this, strPediodId), strPediodId, CreateCloseFactAcctData.adTableId(this), "A", CreateCloseFactAcctData.cCurrencyId(this, strAcctSchema),liability[j].totalamtdr,liability[j].totalamtcr,liability[j].totalamtdr,liability[j].totalamtcr , Fact_Acct_Group_ID, Integer.toString((i+j+3)*10), "C");
101       }
102       String JavaDoc Fact_Acct_Group_ID2 = SequenceIdData.getSequence(this, "Fact_Acct_Group", vars.getClient());
103       i = 0;
104       for (i=0;i<asset.length;i++){
105         assetAmtDr = assetAmtDr.add(new BigDecimal(asset[i].totalamtdr));
106         assetAmtCr = assetAmtCr.add(new BigDecimal(asset[i].totalamtcr));
107         Fact_Acct_ID = SequenceIdData.getSequence(this, "Fact_Acct", vars.getClient());
108         CreateCloseFactAcctData.insert(this, Fact_Acct_ID, vars.getClient(), vars.getOrg(), vars.getUser(), strAcctSchema, asset[i].accountId, CreateCloseFactAcctData.getStartDate(this, newPeriod), newPeriod, CreateCloseFactAcctData.adTableId(this), "A", CreateCloseFactAcctData.cCurrencyId(this, strAcctSchema),asset[i].totalamtcr,asset[i].totalamtdr,asset[i].totalamtcr,asset[i].totalamtdr , Fact_Acct_Group_ID2, Integer.toString((i+3)*10), "O");
109       }
110       for (int j=0;j<liability.length;j++){
111         liabilityAmtDr = liabilityAmtDr.add(new BigDecimal(liability[j].totalamtdr));
112         liabilityAmtCr = liabilityAmtCr.add(new BigDecimal(liability[j].totalamtcr));
113         Fact_Acct_ID = SequenceIdData.getSequence(this, "Fact_Acct", vars.getClient());
114         CreateCloseFactAcctData.insert(this, Fact_Acct_ID, vars.getClient(), vars.getOrg(), vars.getUser(), strAcctSchema, liability[j].accountId, CreateCloseFactAcctData.getStartDate(this, newPeriod), newPeriod, CreateCloseFactAcctData.adTableId(this), "A", CreateCloseFactAcctData.cCurrencyId(this, strAcctSchema),liability[j].totalamtcr,liability[j].totalamtdr,liability[j].totalamtcr,liability[j].totalamtdr, Fact_Acct_Group_ID2, Integer.toString((i+j+3)*10), "O");
115       }
116       if(CreateCloseFactAcctData.updatePeriods(this, Fact_Acct_Group_ID, strKey, strPediodId)!=0)
117         return Utility.messageBD(this, "ProcessOK", vars.getLanguage());
118       else return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
119     } catch (ServletException e) {
120       log4j.warn(e);
121       return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
122     }
123   }
124
125
126   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strPediodId, String JavaDoc windowId, String JavaDoc strTab, String JavaDoc strProcessId) throws IOException, ServletException {
127       if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Create Close Fact Acct");
128
129       ActionButtonDefaultData[] data = null;
130       String JavaDoc strHelp="", strDescription="";
131       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
132       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
133
134       if (data!=null && data.length!=0) {
135         strDescription = data[0].description;
136         strHelp = data[0].help;
137       }
138       String JavaDoc[] discard = {""};
139       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
140       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/CreateCloseFactAcct", discard).createXmlDocument();
141       xmlDocument.setParameter("key", strKey);
142       xmlDocument.setParameter("window", windowId);
143       xmlDocument.setParameter("tab", strTab);
144       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
145       xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
146       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
147       xmlDocument.setParameter("description", strDescription);
148       xmlDocument.setParameter("help", strHelp);
149
150
151       xmlDocument.setData("reportcPeriodId", "liststructure", CreateCloseFactAcctData.select(this,strKey));
152
153       xmlDocument.setParameter("cPeriodId", strPediodId);
154
155
156       response.setContentType("text/html; charset=UTF-8");
157       PrintWriter out = response.getWriter();
158       out.println(xmlDocument.print());
159       out.close();
160     }
161
162   public String JavaDoc getServletInfo() {
163     return "Servlet Project close fact acct";
164   } // end of getServletInfo() method
165
}
166
167
Popular Tags