KickJava   Java API By Example, From Geeks To Geeks.

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


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) 2007 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
30 import java.util.*;
31 import net.sf.jasperreports.engine.*;
32 import net.sf.jasperreports.engine.design.JasperDesign;
33 import java.sql.Connection JavaDoc;
34 import net.sf.jasperreports.engine.xml.JRXmlLoader;
35 import net.sf.jasperreports.engine.export.JRHtmlExporter;
36 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
37
38 import org.openbravo.erpCommon.utility.ComboTableData;
39
40 import org.openbravo.erpCommon.utility.ToolBar;
41
42 public class ReportSalesOrderJR 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, "", "ReportSalesOrderJR")) {
49       bdError(response, "AccessTableNoView", vars.getLanguage());
50       return;
51     }
52
53     if (vars.commandIn("DEFAULT")){
54       String JavaDoc strdateFrom = vars.getGlobalVariable("inpDateFrom", "ReportSalesOrderJR|dateFrom", "");
55       String JavaDoc strdateTo = vars.getGlobalVariable("inpDateTo", "ReportSalesOrderJR|dateTo", "");
56       String JavaDoc strcProjectId = vars.getGlobalVariable("inpcProjectId", "ReportSalesOrderJR|projectId", "");
57       String JavaDoc strmWarehouseId = vars.getGlobalVariable("inpmWarehouseId", "ReportSalesOrderJR|warehouseId", "");
58       String JavaDoc strProjectpublic = vars.getGlobalVariable("inpProjectpublic", "ReportSalesOrderJR|projectpublic", "");
59       printPageDataSheet(response, vars, strdateFrom, strdateTo, strmWarehouseId, strcProjectId, strProjectpublic);
60     }else if (vars.commandIn("EDIT_HTML","EDIT_PDF")) {
61       String JavaDoc strdateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportSalesOrderJR|dateFrom");
62       String JavaDoc strdateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportSalesOrderJR|dateTo");
63       String JavaDoc strmWarehouseId = vars.getRequestGlobalVariable("inpmWarehouseId", "ReportSalesOrderJR|warehouseId");
64       String JavaDoc strcProjectId = vars.getRequestGlobalVariable("inpcProjectId", "ReportSalesOrderJR|projectId");
65       String JavaDoc strProjectpublic = vars.getRequestGlobalVariable("inpProjectpublic", "ReportSalesOrderJR|projectpublic");
66       String JavaDoc strcRegionId = vars.getRequestInGlobalVariable("inpcRegionId", "ReportSalesOrderJR|regionId");
67       String JavaDoc strmProductCategoryId = vars.getRequestInGlobalVariable("inpmProductCategoryId", "ReportSalesOrderJR|productCategoryId");
68       String JavaDoc strProjectkind = vars.getRequestInGlobalVariable("inpProjectkind", "ReportSalesOrderJR|projectKind");
69       String JavaDoc strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportSalesOrderJR|bpartnerId");
70       String JavaDoc strmProductId = vars.getRequestInGlobalVariable("inpmProductId_IN", "ReportSalesOrderJR|productId");
71       printPageHtml(response, vars, strdateFrom, strdateTo, strmWarehouseId, strcProjectId, strProjectpublic, strcRegionId, strmProductCategoryId, strProjectkind, strcBpartnerId, strmProductId);
72     } else pageErrorPopUp(response);
73   }
74
75   void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strdateFrom, String JavaDoc strdateTo, String JavaDoc strmWarehouseId, String JavaDoc strcProjectId, String JavaDoc strProjectpublic) throws IOException, ServletException {
76     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
77     String JavaDoc discard[]={"discard"};
78     XmlDocument xmlDocument=null;
79     xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportSalesOrderFilterJR").createXmlDocument();
80
81     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportSalesOrderJR", false, "", "", "openServletNewWindow('EDIT_PDF', true, 'ReportSalesOrderJR.pdf', 'ReportSalesOrderFilterJR', null, false, '700', '1000', true);return false;",false, "ad_reports", strReplaceWith, false, true);
82     toolbar.prepareSimpleToolBarTemplate();
83     xmlDocument.setParameter("toolbar", toolbar.toString());
84
85     try {
86       KeyMap key = new KeyMap(this, vars, "ReportSalesOrderFilterJR.html");
87       xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
88     } catch (Exception JavaDoc ex) {
89       throw new ServletException(ex);
90     }
91     try {
92       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportSalesOrderJR");
93       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
94       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
95       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
96       xmlDocument.setParameter("theme", vars.getTheme());
97       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportSalesOrderFilterJR.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
98       xmlDocument.setParameter("navigationBar", nav.toString());
99       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportSalesOrderFilterJR.html", strReplaceWith);
100       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
101     } catch (Exception JavaDoc ex) {
102       throw new ServletException(ex);
103     }
104     {
105       OBError myMessage = vars.getMessage("ReportSalesOrderJR");
106       vars.removeMessage("ReportSalesOrderJR");
107       if (myMessage!=null) {
108         xmlDocument.setParameter("messageType", myMessage.getType());
109         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
110         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
111       }
112     }
113
114
115     xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
116     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
117     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
118     xmlDocument.setParameter("dateFrom", strdateFrom);
119     xmlDocument.setParameter("dateTo", strdateTo);
120     xmlDocument.setParameter("paramBPartnerId", "");
121     xmlDocument.setParameter("mWarehouseId", strmWarehouseId);
122     xmlDocument.setParameter("cProjectId", strcProjectId);
123     xmlDocument.setParameter("projectName", OrderEditionData.selectProject(this, strcProjectId));
124     xmlDocument.setParameter("cProjectKind", "");
125     xmlDocument.setParameter("cRegionId", "");
126     xmlDocument.setParameter("cProjectPublic", strProjectpublic);
127     xmlDocument.setParameter("mProductCatId", "");
128     try {
129       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Warehouse_ID", "", "", Utility.getContext(this, vars, "#User_Org", "SalesOrderFilterJR"), Utility.getContext(this, vars, "#User_Client", "SalesOrderFilter"), 0);
130       Utility.fillSQLParameters(this, vars, null, comboTableData, "SalesOrderFilterJR", "");
131       xmlDocument.setData("reportM_WAREHOUSEID","liststructure", comboTableData.select(false));
132       comboTableData = null;
133     } catch (Exception JavaDoc ex) {
134       throw new ServletException(ex);
135     }
136
137     try {
138       ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "C_Projectkind_ID", "Projectkind", "", Utility.getContext(this, vars, "#User_Org", "SalesOrderFilterJR"), Utility.getContext(this, vars, "#User_Client", "SalesOrderFilterJR"), 0);
139       Utility.fillSQLParameters(this, vars, null, comboTableData, "SalesOrderFilterJR", "");
140       xmlDocument.setData("reportC_PROJECTKIND","liststructure", comboTableData.select(false));
141       comboTableData = null;
142     } catch (Exception JavaDoc ex) {
143       throw new ServletException(ex);
144     }
145
146     try {
147       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Region_ID", "", "C_Region of Country", Utility.getContext(this, vars, "#User_Org", "SalesOrderFilterJR"), Utility.getContext(this, vars, "#User_Client", "SalesOrderFilterJR"), 0);
148       Utility.fillSQLParameters(this, vars, null, comboTableData, "SalesOrderFilterJR", "");
149       xmlDocument.setData("reportC_REGIONID","liststructure", comboTableData.select(false));
150       comboTableData = null;
151     } catch (Exception JavaDoc ex) {
152       throw new ServletException(ex);
153     }
154
155     try {
156       ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "C_Projectkind_ID", "PublicPrivate", "", Utility.getContext(this, vars, "#User_Org", "SalesOrderFilterJR"), Utility.getContext(this, vars, "#User_Client", "SalesOrderFilterJR"), 0);
157       Utility.fillSQLParameters(this, vars, null, comboTableData, "SalesOrderFilter", "");
158       xmlDocument.setData("reportC_PROJECTKIND","liststructure", comboTableData.select(false));
159       comboTableData = null;
160     } catch (Exception JavaDoc ex) {
161       throw new ServletException(ex);
162     }
163
164     xmlDocument.setData("reportCBPartnerId_IN", "liststructure", ReportProjectBuildingSiteData.selectBpartner(this, Utility.getContext(this, vars, "#User_Org", ""), Utility.getContext(this, vars, "#User_Client", ""), ""));
165     xmlDocument.setData("reportMProductId_IN", "liststructure", ReportProjectBuildingSiteData.selectMproduct(this, Utility.getContext(this, vars, "#User_Org", ""), Utility.getContext(this, vars, "#User_Client", ""), ""));
166     xmlDocument.setData("reportC_PRODUCTCATREGORY","liststructure",SubCategoryProductData.select(this));
167     response.setContentType("text/html; charset=UTF-8");
168     
169     xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
170     xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
171     xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
172     xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
173     
174     
175     PrintWriter out = response.getWriter();
176     out.println(xmlDocument.print());
177     out.close();
178   }
179
180   void printPageHtml(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strdateFrom, String JavaDoc strdateTo, String JavaDoc strmWarehouseId, String JavaDoc strcProjectId, String JavaDoc strProjectpublic, String JavaDoc strcRegionId, String JavaDoc strmProductCategoryId, String JavaDoc strProjectkind, String JavaDoc strcBpartnerId, String JavaDoc strmProductId) throws IOException, ServletException{
181     if (log4j.isDebugEnabled()) log4j.debug("Output: print html");
182     OrderEditionData[] data = null;
183     data = OrderEditionData.select(this, Utility.getContext(this, vars, "#User_Org", "SalesOrderFilterJR"), Utility.getContext(this, vars, "#User_Client", "SalesOrderFilterJR"), strdateFrom, strdateTo, strmWarehouseId, strcProjectId, strProjectpublic, strcRegionId, strmProductCategoryId, strProjectkind, strcBpartnerId, strmProductId);
184     if (data == null || data.length == 0) data = OrderEditionData.set();
185   
186     JasperPrint jasperPrint;
187     String JavaDoc strOutput = vars.commandIn("EDIT_HTML")?"html":"pdf";
188     String JavaDoc strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportSalesOrderJR.jrxml";
189     
190     HashMap<String JavaDoc, Object JavaDoc> parameters = new HashMap<String JavaDoc, Object JavaDoc>();
191     parameters.put("Title", classInfo.name);
192     //parameters.put("Subtitle",strSubtitle);
193
renderJR(vars, response, strReportName, strOutput, parameters, data, null );
194   }
195    
196
197
198
199   public String JavaDoc getServletInfo() {
200     return "Servlet PurchaseOrderFilter. This Servlet was made by Jon Alegría";
201   } // end of getServletInfo() method
202
}
203
204
Popular Tags