KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_reports > ReportCashJR


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_reports;
20
21 import org.openbravo.erpCommon.utility.*;
22 import org.openbravo.erpCommon.businessUtility.WindowTabs;
23 import org.openbravo.base.secureApp.HttpSecureAppServlet;
24 import org.openbravo.base.secureApp.VariablesSecureApp;
25 import org.openbravo.xmlEngine.XmlDocument;
26 import java.io.*;
27 import javax.servlet.*;
28 import javax.servlet.http.*;
29 import org.openbravo.utils.Replace;
30 import java.util.*;
31
32 import org.openbravo.erpCommon.utility.DateTimeData;
33
34 import net.sf.jasperreports.engine.export.JRHtmlExporter;
35 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
36 import net.sf.jasperreports.engine.export.JExcelApiExporter;
37 import net.sf.jasperreports.engine.*;
38 import net.sf.jasperreports.engine.design.JasperDesign;
39 import net.sf.jasperreports.engine.xml.JRXmlLoader;
40 import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
41
42 public class ReportCashJR extends HttpSecureAppServlet {
43
44
45   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
46     VariablesSecureApp vars = new VariablesSecureApp(request);
47
48     if (!Utility.hasProcessAccess(this, vars, "", "ReportCashJR")) {
49       bdError(response, "AccessTableNoView", vars.getLanguage());
50       return;
51     }
52
53     if (vars.commandIn("DEFAULT")) {
54       String JavaDoc strDateFrom = vars.getGlobalVariable("inpDateFrom", "ReportCashJR|DateFrom", "");
55       String JavaDoc strDateTo = vars.getGlobalVariable("inpDateTo", "ReportCashJR|DateTo", "");
56       String JavaDoc strCashbook = vars.getGlobalVariable("inpcCashbookId", "ReportCashJR|Cashbook", "");
57       printPageDataSheet(response, vars, strDateFrom, strDateTo, strCashbook);
58     } else if (vars.commandIn("FIND")) {
59       String JavaDoc strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportCashJR|DateFrom");
60       String JavaDoc strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportCashJR|DateTo");
61       String JavaDoc strCashbook = vars.getRequestGlobalVariable("inpcCashbookId", "ReportCashJR|Cashbook");
62       printPageHtml(response, vars, strDateFrom, strDateTo, strCashbook);
63     } else pageError(response);
64   }
65
66   void printPageHtml(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strCashbook)
67     throws IOException, ServletException {
68     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
69     response.setContentType("text/html; charset=UTF-8");
70     String JavaDoc strOutput = "html";
71     ReportCashJRData[] data=null;
72     if (strDateFrom.equals("") && strDateTo.equals("")) {
73       printPageDataSheet(response, vars, strDateFrom, strDateTo, strCashbook);
74     } else {
75       data = ReportCashJRData.select(this, vars.getLanguage(), Utility.getContext(this, vars, "#User_Client", "ReportCashJR"), Utility.getContext(this, vars, "#User_Org", "ReportCashJR"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strCashbook);
76       
77       String JavaDoc strReportName = PrintJRData.getReportName(this, classInfo.id);
78       String JavaDoc strReportPath = "@basedesign@" + "/org/openbravo/erpCommon/ad_reports/ReportCashJR.jrxml";
79       HashMap<String JavaDoc, Object JavaDoc> parameters = new HashMap<String JavaDoc, Object JavaDoc>();
80       parameters.put("REPORT_TITLE", "Cash Report");
81       renderJR(vars, response, strReportPath, "html", parameters, data, null);
82     }
83       
84       
85       
86       
87       
88       
89       /*xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportCashJREdit").createXmlDocument();
90       data = ReportCashJRData.select(this, vars.getLanguage(), Utility.getContext(this, vars, "#User_Client", "ReportCashJR"), Utility.getContext(this, vars, "#User_Org", "ReportCashJR"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strCashbook);
91       xmlDocument.setParameter("sumAmount", ReportCashJRData.BeginningBalance(this, Utility.getContext(this, vars, "#User_Client", "ReportCashJR"), Utility.getContext(this, vars, "#User_Org", "ReportCashJR"), strDateFrom, strCashbook));
92       xmlDocument.setData("structure1", data);
93       out.println(xmlDocument.print());
94       out.close();*/

95     
96   }
97
98   void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strCashbook)
99     throws IOException, ServletException {
100     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
101     response.setContentType("text/html; charset=UTF-8");
102     PrintWriter out = response.getWriter();
103     
104     XmlDocument xmlDocument=null;
105
106     xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportCashJR").createXmlDocument();
107
108     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportCashJR", false, "", "", "",false, "ad_reports", strReplaceWith, false, true);
109     toolbar.prepareSimpleToolBarTemplate();
110     xmlDocument.setParameter("toolbar", toolbar.toString());
111     try {
112       KeyMap key = new KeyMap(this, vars, "ReportCashJR.html");
113       xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
114     } catch (Exception JavaDoc ex) {
115       throw new ServletException(ex);
116     }
117     try {
118       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportCashJR");
119       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
120       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
121       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
122       xmlDocument.setParameter("theme", vars.getTheme());
123       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportCashJR.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
124       xmlDocument.setParameter("navigationBar", nav.toString());
125       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportCashJR.html", strReplaceWith);
126       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
127     } catch (Exception JavaDoc ex) {
128       throw new ServletException(ex);
129     }
130     {
131       OBError myMessage = vars.getMessage("ReportCashJR");
132       vars.removeMessage("ReportCashJR");
133       if (myMessage!=null) {
134         xmlDocument.setParameter("messageType", myMessage.getType());
135         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
136         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
137       }
138     }
139
140
141     xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
142     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
143     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
144     xmlDocument.setParameter("cCashbook", strCashbook);
145     xmlDocument.setParameter("dateFrom", strDateFrom);
146     xmlDocument.setParameter("dateFromsaveFormat", strDateFrom);
147     xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
148     xmlDocument.setParameter("dateTo", strDateTo);
149     xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
150     xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
151     try {
152       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_CashBook_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportCashJR"), Utility.getContext(this, vars, "#User_Client", "ReportCashJR"), 0);
153       Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportCashJR", strCashbook);
154       xmlDocument.setData("reportC_CASHBOOK","liststructure", comboTableData.select(false));
155       comboTableData = null;
156     } catch (Exception JavaDoc ex) {
157       throw new ServletException(ex);
158     }
159
160     out.println(xmlDocument.print());
161     out.close();
162   }
163
164   public String JavaDoc getServletInfo() {
165     return "Servlet ReportCashJR.";
166   } // end of getServletInfo() method
167
}
168
169
Popular Tags