KickJava   Java API By Example, From Geeks To Geeks.

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


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.Tree;
23 import org.openbravo.erpCommon.businessUtility.TreeData;
24 import org.openbravo.erpCommon.businessUtility.WindowTabs;
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.util.HashMap JavaDoc;
30 import java.util.Date JavaDoc;
31 import java.text.*;
32 import javax.servlet.*;
33 import javax.servlet.http.*;
34
35 import org.openbravo.utils.Replace;
36 import org.openbravo.erpCommon.ad_combos.OrganizationComboData;
37
38 import org.openbravo.erpCommon.utility.DateTimeData;
39
40 import net.sf.jasperreports.engine.*;
41 import net.sf.jasperreports.engine.design.JasperDesign;
42 import java.sql.Connection JavaDoc;
43 import net.sf.jasperreports.engine.xml.JRXmlLoader;
44 import net.sf.jasperreports.engine.export.JRHtmlExporter;
45 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
46
47 public class ReportProductionJR extends HttpSecureAppServlet {
48
49
50   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
51     VariablesSecureApp vars = new VariablesSecureApp(request);
52
53     if (!Utility.hasProcessAccess(this, vars, "", "RV_ReportProductionJR")) {
54       bdError(response, "AccessTableNoView", vars.getLanguage());
55       return;
56     }
57
58     if (vars.commandIn("DEFAULT")) {
59       String JavaDoc strDateFrom = vars.getGlobalVariable("inpDateFrom", "ReportProduction|DateFrom", "");
60       String JavaDoc strDateTo = vars.getGlobalVariable("inpDateTo", "ReportProduction|DateTo", "");
61       String JavaDoc strRawMaterial = vars.getGlobalVariable("inpRawMaterial", "ReportProduction|RawMaterial", "");
62       printPageDataSheet(response, vars, strDateFrom, strDateTo, strRawMaterial);
63     } else if (vars.commandIn("FIND")) {
64       String JavaDoc strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportProduction|DateFrom");
65       String JavaDoc strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportProduction|DateTo");
66       String JavaDoc strRawMaterial = vars.getRequestGlobalVariable("inpRawMaterial", "ReportProduction|RawMaterial");
67       printPagePDF(response, vars, strDateFrom, strDateTo, strRawMaterial);
68     } else pageError(response);
69   }
70
71   void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strRawMaterial)
72     throws IOException, ServletException {
73     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
74     response.setContentType("text/html; charset=UTF-8");
75     PrintWriter out = response.getWriter();
76     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportProductionJR").createXmlDocument();
77
78
79     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportProduction", false, "", "", "",false, "ad_reports", strReplaceWith, false, true);
80     toolbar.prepareSimpleToolBarTemplate();
81     xmlDocument.setParameter("toolbar", toolbar.toString());
82
83     try {
84       KeyMap key = new KeyMap(this, vars, "ReportProduction.html");
85       xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
86     } catch (Exception JavaDoc ex) {
87       throw new ServletException(ex);
88     }
89     try {
90       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportProductionJR");
91       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
92       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
93       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
94       xmlDocument.setParameter("theme", vars.getTheme());
95       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportProductionJR.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
96       xmlDocument.setParameter("navigationBar", nav.toString());
97       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportProductionJR.html", strReplaceWith);
98       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
99     } catch (Exception JavaDoc ex) {
100       throw new ServletException(ex);
101     }
102     {
103       OBError myMessage = vars.getMessage("ReportProductionJR");
104       vars.removeMessage("ReportProductionJR");
105       if (myMessage!=null) {
106         xmlDocument.setParameter("messageType", myMessage.getType());
107         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
108         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
109       }
110     }
111
112     xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
113     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
114     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
115     xmlDocument.setParameter("dateFrom", strDateFrom);
116     xmlDocument.setParameter("dateTo", strDateTo);
117     xmlDocument.setParameter("rawMaterial", strRawMaterial);
118     xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
119     xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
120     xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
121     xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
122     out.println(xmlDocument.print());
123     out.close();
124   }
125
126   void printPagePDF(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strRawMaterial)
127     throws IOException, ServletException {
128     
129     if (log4j.isDebugEnabled()) log4j.debug("Output: Jasper Report : Production Report");
130     
131     JasperPrint jasperPrint;
132     
133     String JavaDoc strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/productionReport.jrxml";
134     response.setHeader("Content-disposition", "inline; filename=ProductionReportJR.pdf");
135
136     String JavaDoc strTitle = "Production Report";
137     String JavaDoc strSubTitle = (!strDateFrom.equals("")?"From "+strDateFrom:"") + (!strDateTo.equals("")?" to "+strDateTo:"");
138     
139
140     if (!strRawMaterial.equals("Y")) strRawMaterial = "N";
141
142     ReportProductionData[] data = ReportProductionData.select(this, strRawMaterial, Utility.getContext(this, vars, "#User_Client", "ReportProduction"), Utility.getContext(this, vars, "#User_Org", "ReportProduction"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"));
143     
144     if (data == null || data.length == 0) {
145       data = ReportProductionData.set();
146     }
147    
148     
149     HashMap JavaDoc<String JavaDoc, Object JavaDoc> parameters = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>();
150     
151     if (log4j.isDebugEnabled()) log4j.debug("inpDateFrom:"+vars.getRequestGlobalVariable("inpDateFrom", "ReportProduction|DateFrom"));
152     if (log4j.isDebugEnabled()) log4j.debug("inpDateTo:"+vars.getRequestGlobalVariable("inpDateTo", "ReportProduction|DateFrom"));
153     
154     parameters.put("REPORT_TITLE", strTitle);
155     parameters.put("REPORT_SUBTITLE", strSubTitle);
156     
157     try{
158       parameters.put("DATE_FROM", new SimpleDateFormat("dd-MM-yyyy").parse(vars.getRequestGlobalVariable("inpDateFrom", "ReportProduction|DateFrom")));
159       parameters.put("DATE_TO", new SimpleDateFormat("dd-MM-yyyy").parse(vars.getRequestGlobalVariable("inpDateTo", "ReportProduction|DateTo")));
160     } catch (Exception JavaDoc ex) {
161       throw new ServletException(ex);
162     }
163     
164     if (log4j.isDebugEnabled()) log4j.debug("parameters: " + parameters.toString());
165     if (log4j.isDebugEnabled()) log4j.debug("data: " + data);
166     
167     renderJR(vars, response, strReportName, "pdf", parameters, data, null );
168
169   }
170
171   public String JavaDoc getServletInfo() {
172     return "Servlet ReportProduction. This Servlet was made by Jon Alegria";
173   } // end of getServletInfo() method
174
}
175
176
Popular Tags