KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_process > CreateAccountingReport


1 /*
2  ******************************************************************************
3  * The contents of this file are subject to the Compiere License Version 1.1
4  * ("License"); You may not use this file except in compliance with the License
5  * You may obtain a copy of the License at http://www.compiere.org/license.html
6  * Software distributed under the License is distributed on an "AS IS" basis,
7  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
8  * the specific language governing rights and limitations under the License.
9  * The Original Code is Compiere ERP & CRM Business Solution
10  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
11  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
12  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
13  * Contributor(s): Openbravo SL
14  * Contributions are Copyright (C) 2001-2007 Openbravo S.L.
15  ******************************************************************************
16 */

17
18 package org.openbravo.erpCommon.ad_process;
19
20
21 import org.openbravo.erpCommon.businessUtility.WindowTabs;
22 import org.openbravo.erpCommon.utility.*;
23
24 import org.openbravo.erpCommon.ad_actionButton.*;
25
26 import org.openbravo.base.secureApp.HttpSecureAppServlet;
27 import org.openbravo.base.secureApp.VariablesSecureApp;
28 import org.openbravo.xmlEngine.XmlDocument;
29 import java.io.*;
30 import java.util.*;
31 import javax.servlet.*;
32 import javax.servlet.http.*;
33
34 import org.openbravo.erpCommon.utility.DateTimeData;
35
36
37 public class CreateAccountingReport extends HttpSecureAppServlet {
38
39   public static String JavaDoc strTreeOrg = "";
40
41   public void init (ServletConfig config) {
42     super.init(config);
43     boolHist = false;
44   }
45
46   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
47     VariablesSecureApp vars = new VariablesSecureApp(request);
48
49     if (!Utility.hasProcessAccess(this, vars, "", "CreateAccountingReport")) {
50       bdError(response, "AccessTableNoView", vars.getLanguage());
51       return;
52     }
53     String JavaDoc process = CreateAccountingReportData.processId(this, "CreateAccountingReport");
54     /*String strTabId = vars.getGlobalVariable("inpTabId", "CreateAccountingReport|tabId");
55     String strWindowId = vars.getGlobalVariable("inpwindowId", "CreateAccountingReport|windowId");*/

56     //String strDeleteOld = vars.getStringParameter("inpDeleteOld", "Y");
57
//String strCElementId = vars.getStringParameter("inpElementId", "");
58
//String strUpdateDefault = vars.getStringParameter("inpUpdateDefault", "Y");
59
//String strCreateNewCombination = vars.getStringParameter("inpCreateNewCombination", "Y");
60
if (vars.commandIn("DEFAULT")) {
61       //printPage(response, vars, process, strWindowId, strTabId, strDeleteOld, strCElementId, strUpdateDefault, strCreateNewCombination);
62
String JavaDoc strAccountingReportId = vars.getGlobalVariable("inpAccountingReportId", "CreateAccountingReport|accountingReport", "");
63       String JavaDoc strOrg = vars.getGlobalVariable("inpadOrgId", "CreateAccountingReport|orgId", "0");
64       String JavaDoc strPeriod = vars.getGlobalVariable("inpPeriodId", "CreateAccountingReport|period", "");
65       printPage(response, vars, strAccountingReportId, strOrg, strPeriod, process);
66     } else if (vars.commandIn("FIND")){
67       String JavaDoc strAccountingReportId = vars.getRequestGlobalVariable("inpAccountingReportId", "CreateAccountingReport|accountingReport");
68       String JavaDoc strOrg = vars.getGlobalVariable("inpadOrgId", "CreateAccountingReport|orgId", "0");
69       String JavaDoc strPeriod = vars.getRequestGlobalVariable("inpPeriodId", "CreateAccountingReport|period");
70       printPagePopUp(response, vars, strAccountingReportId, strOrg, strPeriod);
71       //printPageClosePopUp(response, vars, strWindowPath);
72
} else pageErrorPopUp(response);
73   }
74
75
76 void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strAccountingReportId, String JavaDoc strOrg, String JavaDoc strPeriod, String JavaDoc strProcessId) throws IOException, ServletException {
77       if (log4j.isDebugEnabled()) log4j.debug("Output: process CreateAccountingReport");
78       
79       ActionButtonDefaultData[] data = null;
80       String JavaDoc strHelp="", strDescription="";
81       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
82       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
83       if (data!=null && data.length!=0) {
84         strDescription = data[0].description;
85         strHelp = data[0].help;
86       }
87
88       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CreateAccountingReport").createXmlDocument();
89
90       String JavaDoc strArray = arrayEntry(vars);
91
92       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
93       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
94       xmlDocument.setParameter("description", strDescription);
95       xmlDocument.setParameter("help", strHelp);
96       xmlDocument.setParameter("accounting", strAccountingReportId);
97       xmlDocument.setParameter("org", strOrg);
98       xmlDocument.setParameter("period", strPeriod);
99       xmlDocument.setParameter("array", strArray);
100
101       try {
102         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_Org_ID", "", "", Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), 0);
103         Utility.fillSQLParameters(this, vars, null, comboTableData, "CreateAccountingReport", "");
104         xmlDocument.setData("reportAD_ORG", "liststructure", comboTableData.select(false));
105         comboTableData = null;
106       } catch (Exception JavaDoc ex) {
107         throw new ServletException(ex);
108       }
109
110       xmlDocument.setData("reportAD_ACCOUNTINGRPT_ELEMENT", "liststructure", CreateAccountingReportData.selectAD_Accountingrpt_Element_ID(this, Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), ""));
111
112       //xmlDocument.setData("reportPeriod", "liststructure", CreateAccountingReportData.selectPeriod(this, vars.getLanguage(), Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), "800074"));
113
xmlDocument.setData("reportPeriod", "liststructure", CreateAccountingReportData.selectCombo(this, Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), vars.getLanguage()));
114
115       ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "CreateAccountingReport", false, "", "", "",false, "ad_process", strReplaceWith, false, true);
116       toolbar.prepareSimpleToolBarTemplate();
117       xmlDocument.setParameter("toolbar", toolbar.toString());
118
119       
120       // New interface paramenters
121
try {
122         KeyMap key = new KeyMap(this, vars, "CreateAccountingReport.html");
123         xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps());
124       } catch (Exception JavaDoc ex) {
125         throw new ServletException(ex);
126       }
127       try {
128         WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_process.CreateAccountingReport");
129         xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
130         xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
131         xmlDocument.setParameter("childTabContainer", tabs.childTabs());
132         xmlDocument.setParameter("theme", vars.getTheme());
133         NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "CreateAccountingReport.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
134         xmlDocument.setParameter("navigationBar", nav.toString());
135         LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "CreateAccountingReport.html", strReplaceWith);
136         xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
137       } catch (Exception JavaDoc ex) {
138         throw new ServletException(ex);
139       }
140       {
141         OBError myMessage = vars.getMessage("CreateAccountingReport");
142         vars.removeMessage("CreateAccountingReport");
143         if (myMessage!=null) {
144           xmlDocument.setParameter("messageType", myMessage.getType());
145           xmlDocument.setParameter("messageTitle", myMessage.getTitle());
146           xmlDocument.setParameter("messageMessage", myMessage.getMessage());
147         }
148       }
149       
150      ////----
151

152       response.setContentType("text/html; charset=UTF-8");
153       PrintWriter out = response.getWriter();
154       out.println(xmlDocument.print());
155       out.close();
156     }
157
158 void printPagePopUp (HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strAccountingReportId, String JavaDoc strOrg, String JavaDoc strPeriod) throws IOException, ServletException {
159       if (log4j.isDebugEnabled()) log4j.debug("Output: pop up CreateAccountingReport");
160       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CreateAccountingReportPopUp").createXmlDocument();
161       String JavaDoc strPeriodFrom = "";
162       int level = 0;
163       String JavaDoc strPeriodTo = "";
164       String JavaDoc strYear = DateTimeData.sysdateYear(this);
165       //log4j.debug("****************************strAccountingReportId: "+strAccountingReportId);
166
String JavaDoc strAccountingType = CreateAccountingReportData.selectType(this, strAccountingReportId);
167       //log4j.debug("****************************strAccountingType: "+strAccountingType);
168
if (strAccountingType.equals("Q")) {
169         String JavaDoc strAux = CreateAccountingReportData.selectMax(this, strPeriod);
170         //log4j.debug("*************************strAux: "+strAux);
171
strPeriodFrom = "01/" + CreateAccountingReportData.selectMin(this, strPeriod) + "/" + strYear;
172         //log4j.debug("*************************strPeriodFrom: "+strPeriodFrom);
173
strPeriodTo = CreateAccountingReportData.lastDay(this, "01/"+ strAux + "/" + strYear, vars.getSqlDateFormat());
174         strPeriodTo = DateTimeData.nDaysAfter(this, strPeriodTo, "1");
175         //log4j.debug("*************************strPeriodTo: "+strPeriodTo);
176
}else if (strAccountingType.equals("M")) {
177         strPeriodFrom = "01/" + strPeriod + "/" + strYear;
178         //log4j.debug("*************************strPeriodFrom1: "+strPeriodFrom);
179
strPeriodTo = CreateAccountingReportData.lastDay(this, strPeriodFrom, vars.getSqlDateFormat());
180         strPeriodTo = DateTimeData.nDaysAfter(this, strPeriodTo, "1");
181         //log4j.debug("*************************strPeriodTo1: "+strPeriodTo);
182
}else {
183         strPeriodFrom = "01/01/" + strPeriod;
184         //log4j.debug("*************************strPeriodFrom2: "+strPeriodFrom);
185
strPeriodTo = DateTimeData.nDaysAfter(this, "31/12/" + strPeriod, "1");
186       }
187       strPeriodFrom = CreateAccountingReportData.selectFormat(this, strPeriodFrom, vars.getSqlDateFormat());
188       strPeriodTo = CreateAccountingReportData.selectFormat(this, strPeriodTo, vars.getSqlDateFormat());
189       strTreeOrg = strOrg;
190       treeOrg(vars, strOrg);
191
192       Vector<Object JavaDoc> vectorArray = new Vector<Object JavaDoc>();
193
194       childData(vars, vectorArray, strAccountingReportId, strPeriodFrom, strPeriodTo, strTreeOrg, level);
195
196       CreateAccountingReportData[] dataTree = convertVector(vectorArray);
197       strTreeOrg = "";
198
199       xmlDocument.setParameter("title", dataTree[0].name);
200       xmlDocument.setData("structure", dataTree);
201       response.setContentType("text/html; charset=UTF-8");
202       PrintWriter out = response.getWriter();
203       out.println(xmlDocument.print());
204       out.close();
205 }
206
207 String JavaDoc arrayEntry(VariablesSecureApp vars) throws ServletException{
208       String JavaDoc result = "";
209       CreateAccountingReportData[] data = CreateAccountingReportData.selectAD_Accountingrpt_Element_ID(this, Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), "");
210       if (data == null || data.length == 0) {
211         result = "var array = null;";
212       } else {
213         result = "var array = new Array(\n";
214         for (int i = 0;i<data.length;i++) {
215           result += "new Array(\"" + data[i].id + "\",\"" + data[i].filteredbyorganization + "\",\"" + data[i].temporaryfiltertype + "\")";
216           if (i<data.length-1) result += ",\n";
217         }
218         result += ");";
219         CreateAccountingReportData[] dataPeriod = CreateAccountingReportData.selectCombo(this, Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), vars.getLanguage());
220         if (dataPeriod == null || dataPeriod.length == 0){
221           result += "\nvar combo = null;";
222         } else {
223           result += "\nvar combo = new Array(\n";
224             for (int j = 0; j<dataPeriod.length; j++){
225               result += "new Array(\"" + dataPeriod[j].value + "\", \"" + dataPeriod[j].id +"\", \"" + dataPeriod[j].name + "\")";
226               if (j<dataPeriod.length-1) result += ",\n";
227             }
228           result += ");";
229         }
230         
231       }
232       return result;
233 }
234
235
236 void treeOrg(VariablesSecureApp vars, String JavaDoc strOrg) throws ServletException{
237       CreateAccountingReportData[] dataOrg = CreateAccountingReportData.selectOrg(this, strOrg, vars.getClient());
238       for (int i = 0; i<dataOrg.length; i++) {
239         strTreeOrg += "," + dataOrg[i].id;
240         if (dataOrg[i].issummary.equals("Y")) treeOrg(vars, dataOrg[i].id);
241       }
242       return;
243 }
244
245 void childData(VariablesSecureApp vars, Vector<Object JavaDoc> vectorArray, String JavaDoc strAccountingReportId, String JavaDoc strPeriodFrom, String JavaDoc strPeriodTo, String JavaDoc strOrg, int level) throws IOException, ServletException{
246       /*if (log4j.isDebugEnabled()) log4j.debug("**********************strAccountingReportId: "+strAccountingReportId);
247       if (log4j.isDebugEnabled()) log4j.debug("**********************strPeriodFrom: "+strPeriodFrom);
248       if (log4j.isDebugEnabled()) log4j.debug("**********************strPeriodTo: "+strPeriodTo);
249       if (log4j.isDebugEnabled()) log4j.debug("**********************strOrg: "+strOrg);
250       if (log4j.isDebugEnabled()) log4j.debug("**********************level: "+String.valueOf(level));
251       if (log4j.isDebugEnabled()) log4j.debug("**********************User_Client: "+Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"));
252       if (log4j.isDebugEnabled()) log4j.debug("**********************#User_Org: "+Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"));*/

253       if (log4j.isDebugEnabled()) log4j.debug("Ouput: child tree data");
254       //CreateAccountingReportData[] dataTree = new CreateAccountingReportData[data.length];
255
String JavaDoc strAccountId = CreateAccountingReportData.selectAccounting(this, strAccountingReportId);
256       //if (log4j.isDebugEnabled()) log4j.debug("**********************strAccountId: "+strAccountId);
257
CreateAccountingReportData[] data = CreateAccountingReportData.select(this, String.valueOf(level), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), strOrg, strPeriodFrom, strPeriodTo, strAccountId, strAccountingReportId);
258       if (data == null || data.length == 0) data = CreateAccountingReportData.set();
259       vectorArray.addElement(data[0]);
260       //if (log4j.isDebugEnabled()) log4j.debug("**********************data[0]*********************: "+data[0].name+" "+data[0].total);
261
CreateAccountingReportData[] dataAux = CreateAccountingReportData.selectChild(this, Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), data[0].id);
262       for (int i = 0; i<dataAux.length; i++){
263           //if (dataAux[i].issummary.equals("Y")){
264
childData(vars, vectorArray, dataAux[i].id, strPeriodFrom, strPeriodTo, strOrg, level+1);
265           //}
266
}
267 }
268
269 CreateAccountingReportData[] convertVector(Vector<Object JavaDoc> vectorArray) throws ServletException {
270     CreateAccountingReportData[] data = new CreateAccountingReportData[vectorArray.size()];
271     double count = 0;
272     for (int i = 0; i<vectorArray.size(); i++){
273       data[i] = (CreateAccountingReportData)vectorArray.elementAt(i);
274     }
275       //if (log4j.isDebugEnabled()) log4j.debug("***************************data.length: "+data.length);
276
for (int i = 0; i<data.length; i++){
277         //if (log4j.isDebugEnabled()) log4j.debug("*******************dataissummary: "+data[i].name+" "+data[i].issummary+" "+data[i].levelAccount);
278
if (data[i].issummary.equals("Y")){
279             String JavaDoc strLevel = data[i].levelAccount;
280             for (int j=i+1; j<data.length; j++){
281                 //if (log4j.isDebugEnabled()) log4j.debug("******************************data[j].name: "+data[j].name+" "+data[j].levelAccount+" "+data[i].levelAccount);
282
if (Integer.valueOf(data[j].levelAccount).intValue() > Integer.valueOf(data[i].levelAccount).intValue()){
283                     //if (log4j.isDebugEnabled()) log4j.debug("******************************issummary[j]: "+data[j].issummary);
284
if (!data[j].issummary.equals("Y")){
285                         String JavaDoc total = data[j].total;
286                         count += Double.valueOf(total).doubleValue();
287                     }
288                 }
289                 /*String strLevelSecundary = data[j].levelAccount;
290                 if (!strLevelSecundary.equals("")){
291                     if (Integer.valueOf(strLevelSecundary).intValue() == Integer.valueOf(strLevel).intValue()+1) {
292                         String total = data[j].total;
293                         count += Double.valueOf(total).doubleValue();
294                     }
295                 }*/

296             }
297             data[i].total = String.valueOf(count);
298             count = 0;
299         }
300     }
301     return data;
302 }
303
304   public String JavaDoc getServletInfo() {
305     return "Servlet CreateAccountingReport";
306   } // end of getServletInfo() method
307
}
308
309
Popular Tags