KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashMap JavaDoc;
30
31 import org.openbravo.erpCommon.utility.ComboTableData;
32
33 import org.openbravo.erpCommon.utility.DateTimeData;
34
35 import net.sf.jasperreports.engine.*;
36 import net.sf.jasperreports.engine.design.JasperDesign;
37 import java.sql.Connection JavaDoc;
38 import net.sf.jasperreports.engine.xml.JRXmlLoader;
39 import net.sf.jasperreports.engine.export.JRHtmlExporter;
40 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
41
42 public class ReportSalesOrderInvoicedJasper 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, "", "RV_ReportSalesOrderInvoicedJR")) {
49       bdError(response, "AccessTableNoView", vars.getLanguage());
50       return;
51     }
52
53     if (vars.commandIn("DEFAULT")){
54       String JavaDoc strdateFrom = vars.getStringParameter("inpDateFrom", "");
55       String JavaDoc strdateTo = vars.getStringParameter("inpDateTo", "");
56       String JavaDoc strcBpartnerId = vars.getStringParameter("inpcBPartnerId", "");
57       String JavaDoc strmWarehouseId = vars.getStringParameter("inpmWarehouseId", "");
58       String JavaDoc strcProjectId = vars.getStringParameter("inpcProjectId", "");
59       String JavaDoc strmCategoryId = vars.getStringParameter("inpProductCategory", "");
60       String JavaDoc strProjectkind = vars.getStringParameter("inpProjectkind", "");
61       String JavaDoc strcRegionId = vars.getStringParameter("inpcRegionId", "");
62       String JavaDoc strProjectpublic = vars.getStringParameter("inpProjectpublic", "");
63       String JavaDoc strProduct = vars.getStringParameter("inpProductId", "");
64       printPageDataSheet(response, vars, strdateFrom, strdateTo, strcBpartnerId, strmWarehouseId, strcProjectId, strmCategoryId, strProjectkind, strcRegionId, strProjectpublic, strProduct);
65     }else if(vars.commandIn("FIND")){
66       String JavaDoc strdateFrom = vars.getStringParameter("inpDateFrom");
67       String JavaDoc strdateTo = vars.getStringParameter("inpDateTo");
68       String JavaDoc strcBpartnerId = vars.getStringParameter("inpcBPartnerId");
69       String JavaDoc strmWarehouseId = vars.getStringParameter("inpmWarehouseId");
70       String JavaDoc strcProjectId = vars.getStringParameter("inpcProjectId");
71       String JavaDoc strmCategoryId = vars.getStringParameter("inpProductCategory");
72       String JavaDoc strProjectkind = vars.getStringParameter("inpProjectkind");
73       String JavaDoc strcRegionId = vars.getStringParameter("inpcRegionId");
74       String JavaDoc strProjectpublic = vars.getStringParameter("inpProjectpublic");
75       String JavaDoc strProduct = vars.getStringParameter("inpmProductId");
76       printPageDataSheetJasper(response, vars, strdateFrom, strdateTo, strcBpartnerId, strmWarehouseId, strcProjectId, strmCategoryId, strProjectkind, strcRegionId, strProjectpublic, strProduct);
77     } else pageErrorPopUp(response);
78   }
79
80   void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strdateFrom, String JavaDoc strdateTo, String JavaDoc strcBpartnerId, String JavaDoc strmWarehouseId, String JavaDoc strcProjectId, String JavaDoc strmCategoryId, String JavaDoc strProjectkind, String JavaDoc strcRegionId, String JavaDoc strProjectpublic, String JavaDoc strProduct) throws IOException, ServletException {
81     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
82     String JavaDoc discard[]={"sectionPartner"};
83     String JavaDoc strTitle = "";
84     XmlDocument xmlDocument=null;
85     if (vars.commandIn("DEFAULT")){
86       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportSalesOrderInvoicedJasper").createXmlDocument();
87
88       ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportSalesOrderInvoicedJasper", false, "", "", "",false, "ad_reports", strReplaceWith, false, true);
89       toolbar.prepareSimpleToolBarTemplate();
90       xmlDocument.setParameter("toolbar", toolbar.toString());
91
92       try {
93         KeyMap key = new KeyMap(this, vars, "ReportSalesOrderInvoicedJasper.html");
94         xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
95       } catch (Exception JavaDoc ex) {
96         throw new ServletException(ex);
97       }
98       try {
99         WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportSalesOrderInvoicedJasper");
100         xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
101         xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
102         xmlDocument.setParameter("childTabContainer", tabs.childTabs());
103         xmlDocument.setParameter("theme", vars.getTheme());
104         NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportSalesOrderInvoicedJasper.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
105         xmlDocument.setParameter("navigationBar", nav.toString());
106         LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportSalesOrderInvoicedJasper.html", strReplaceWith);
107         xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
108       } catch (Exception JavaDoc ex) {
109         throw new ServletException(ex);
110       }
111       {
112         OBError myMessage = vars.getMessage("ReportSalesOrderInvoicedJasper");
113         vars.removeMessage("ReportSalesOrderInvoicedJasper");
114         if (myMessage!=null) {
115           xmlDocument.setParameter("messageType", myMessage.getType());
116           xmlDocument.setParameter("messageTitle", myMessage.getTitle());
117           xmlDocument.setParameter("messageMessage", myMessage.getMessage());
118         }
119       }
120
121       xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
122       xmlDocument.setParameter("dateFrom", strdateFrom);
123     xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
124     xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
125       xmlDocument.setParameter("dateTo", strdateTo);
126     xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
127     xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
128       xmlDocument.setParameter("paramBPartnerId", strcBpartnerId);
129       xmlDocument.setParameter("mWarehouseId", strmWarehouseId);
130       xmlDocument.setParameter("cProjectId", strcProjectId);
131       xmlDocument.setParameter("mProductCategoryId", strmCategoryId);
132       xmlDocument.setParameter("cProjectKind", strProjectkind);
133       xmlDocument.setParameter("cRegionId", strcRegionId);
134       xmlDocument.setParameter("cProjectPublic", strProjectpublic);
135       xmlDocument.setParameter("projectName", ReportProjectBuildingSiteData.selectProject(this, strcProjectId));
136       xmlDocument.setParameter("paramBPartnerDescription", ReportSalesOrderInvoicedData.bPartnerDescription(this, strcBpartnerId));
137       try {
138         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Warehouse_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoicedJasper"), Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoicedJasper"), 0);
139         Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportSalesOrderInvoicedJasper", strmWarehouseId);
140         xmlDocument.setData("reportM_WAREHOUSEID","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", "M_Product_Category_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoicedJasper"), Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoicedJasper"), 0);
148         Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportSalesOrderInvoicedJasper", strmCategoryId);
149         xmlDocument.setData("reportM_PRODUCT_CATEGORYID","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", "Projectkind", "", Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoicedJasper"), Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoicedJasper"), 0);
157         Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportSalesOrderInvoicedJasper", strProjectkind);
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       try {
165         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Region_ID", "", "C_Region of Country", Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoicedJasper"), Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoicedJasper"), 0);
166         Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportSalesOrderInvoicedJasper", strcRegionId);
167         xmlDocument.setData("reportC_REGIONID","liststructure", comboTableData.select(false));
168         comboTableData = null;
169       } catch (Exception JavaDoc ex) {
170         throw new ServletException(ex);
171       }
172
173       try {
174         ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "C_Project_Public_ID", "PublicPrivate", "", Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoicedJasper"), Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoicedJasper"), 0);
175         Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportSalesOrderInvoicedJasper", strProjectpublic);
176         xmlDocument.setData("reportC_PROJECTPUBLIC","liststructure", comboTableData.select(false));
177         comboTableData = null;
178       } catch (Exception JavaDoc ex) {
179         throw new ServletException(ex);
180       }
181
182       SubCategoryProductData[] dataSub = SubCategoryProductData.select(this);
183       xmlDocument.setParameter("product", arrayDobleEntrada("array", SubCategoryProductData.selectProduct(this)));
184       xmlDocument.setData("structureCategory", dataSub);
185       xmlDocument.setData("structureProduct", SubCategoryProductData.selectCategoryProduct(this, dataSub[0].id));
186     }
187     else {
188       ReportSalesOrderInvoicedData[] data = ReportSalesOrderInvoicedData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoiced"), Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoiced"), strdateFrom, DateTimeData.nDaysAfter(this, strdateTo,"1"), strcBpartnerId, strmWarehouseId, strcProjectId, strmCategoryId, strProjectkind, strcRegionId, strProjectpublic, strProduct);
189       if (data == null || data.length == 0){
190         xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportSalesOrderInvoicedPop", discard).createXmlDocument();
191         xmlDocument.setData("structure1", ReportSalesOrderInvoicedData.set());
192       }
193       else {
194         xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportSalesOrderInvoicedPop").createXmlDocument();
195         xmlDocument.setData("structure1", data);
196       }
197       if (!strmWarehouseId.equals("")) strTitle += " " + Utility.messageBD(this, "ForWarehouse", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectWarehouse(this, strmWarehouseId);
198       if (!strcRegionId.equals("")) strTitle += ", " + Utility.messageBD(this, "InRegion", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectRegionId(this, strcRegionId);
199       if (!strmCategoryId.equals("")) strTitle += ", " + Utility.messageBD(this, "ForProductCategory", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectCategoryId(this, strmCategoryId);
200       if (!strProjectkind.equals("")) strTitle += ", " + Utility.messageBD(this, "ProjectType", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectProjectkind(this, vars.getLanguage(), strProjectkind);
201       if (!strProjectpublic.equals("")) strTitle += ", " + Utility.messageBD(this, "WithInitiativeType", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectProjectpublic(this, vars.getLanguage(), strProjectpublic);
202       if (!strdateFrom.equals("")) strTitle += ", " + Utility.messageBD(this, "From", vars.getLanguage()) + " " + strdateFrom;
203       if (!strdateTo.equals("")) strTitle += " " + Utility.messageBD(this, "To", vars.getLanguage()) + " " + strdateTo;
204       if (!strProduct.equals("")) strTitle += ", " + Utility.messageBD(this, "ForProduct", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectProduct(this, strProduct);
205       xmlDocument.setParameter("title", strTitle);
206     }
207     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
208     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
209
210     response.setContentType("text/html; charset=UTF-8");
211     PrintWriter out = response.getWriter();
212     out.println(xmlDocument.print());
213     out.close();
214   }
215
216
217 //Aquí empieza el que llama al Jasper
218

219
220
221
222   void printPageDataSheetJasper(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strdateFrom, String JavaDoc strdateTo, String JavaDoc strcBpartnerId, String JavaDoc strmWarehouseId, String JavaDoc strcProjectId, String JavaDoc strmCategoryId, String JavaDoc strProjectkind, String JavaDoc strcRegionId, String JavaDoc strProjectpublic, String JavaDoc strProduct) throws IOException, ServletException {
223
224    JasperPrint jasperPrint;
225
226
227     ReportSalesOrderInvoicedData[] data = ReportSalesOrderInvoicedData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoiced"), Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoiced"), strdateFrom, DateTimeData.nDaysAfter(this, strdateTo,"1"), strcBpartnerId, strmWarehouseId, strcProjectId, strmCategoryId, strProjectkind, strcRegionId, strProjectpublic, strProduct);
228
229    String JavaDoc strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportSalesOrderInvoicedJasper.jrxml";
230    String JavaDoc strOutput = "html";
231     if (strOutput.equals("pdf")) response.setHeader("Content-disposition", "inline; filename=ReportSalesOrderInvoiced.pdf");
232
233    HashMap JavaDoc<String JavaDoc, Object JavaDoc> parameters = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>();
234         parameters.put("REPORT_TITLE", "Invoiced sale orders report");
235         parameters.put("REPORT_SUBTITLE", "From "+strdateFrom +" to "+strdateTo);
236     renderJR(vars, response, strReportName, strOutput, parameters, data, null );
237
238   }
239
240   public String JavaDoc getServletInfo() {
241     return "Servlet ReportSalesOrderInvoicedJasper. This Servlet was made by Jon Alegría";
242   } // end of getServletInfo() method
243
}
244
245
Popular Tags