KickJava   Java API By Example, From Geeks To Geeks.

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


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.DateTimeData;
32
33 import net.sf.jasperreports.engine.*;
34 import net.sf.jasperreports.engine.design.JasperDesign;
35 import java.sql.Connection JavaDoc;
36 import net.sf.jasperreports.engine.xml.JRXmlLoader;
37 import net.sf.jasperreports.engine.export.JRHtmlExporter;
38 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
39
40 public class ReportInvoicesJR extends HttpSecureAppServlet {
41
42
43   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
44     VariablesSecureApp vars = new VariablesSecureApp(request);
45
46     /*if (!Utility.hasProcessAccess(this, vars, "", "RV_C_InvoiceLine")) {
47       bdError(response, "AccessTableNoView", vars.getLanguage());
48       return;
49     }*/

50
51     if (vars.commandIn("DEFAULT")) {
52       String JavaDoc strC_BPartner_ID = vars.getGlobalVariable("inpcBPartnerId", "ReportInvoices|C_BPartner_ID", "");
53       String JavaDoc strM_Product_ID = vars.getGlobalVariable("inpmProductId", "ReportInvoices|M_Product_ID", "");
54       String JavaDoc strDateFrom = vars.getGlobalVariable("inpDateInvoiceFrom", "ReportInvoices|DateFrom", "");
55       String JavaDoc strDateTo = vars.getGlobalVariable("inpDateInvoiceTo", "ReportInvoices|DateTo", "");
56       String JavaDoc strDocumentNo = vars.getGlobalVariable("inpInvoicedocumentno", "ReportInvoices|DocumentNo", "");
57       String JavaDoc strOrder = vars.getGlobalVariable("inpOrder", "ReportInvoices|Order", "SalesOrder");
58       String JavaDoc strC_BpGroup_ID = vars.getGlobalVariable("inpcBpGroupId", "ReportInvoices|C_BpGroup_ID", "");
59       String JavaDoc strM_Product_Category_ID = vars.getGlobalVariable("inpmProductCategoryId", "ReportInvoices|M_Product_Category_ID", "");
60       printPageDataSheet(response, vars, strC_BPartner_ID, strM_Product_ID, strDateFrom, strDateTo, strDocumentNo, strOrder, strC_BpGroup_ID, strM_Product_Category_ID);
61     } else if (vars.commandIn("FIND")) {
62       String JavaDoc strC_BPartner_ID = vars.getRequestGlobalVariable("inpcBPartnerId", "ReportInvoices|C_BPartner_ID");
63       String JavaDoc strM_Product_ID = vars.getRequestGlobalVariable("inpmProductId", "ReportInvoices|M_Product_ID");
64       String JavaDoc strDateFrom = vars.getRequestGlobalVariable("inpDateInvoiceFrom", "ReportInvoices|DateFrom");
65       String JavaDoc strDateTo = vars.getRequestGlobalVariable("inpDateInvoiceTo", "ReportInvoices|DateTo");
66       String JavaDoc strDocumentNo = vars.getRequestGlobalVariable("inpInvoicedocumentno", "ReportInvoices|DocumentNo");
67       String JavaDoc strOrder = vars.getGlobalVariable("inpOrder", "ReportInvoices|Order");
68       String JavaDoc strC_BpGroup_ID = vars.getRequestGlobalVariable("inpcBpGroupId", "ReportInvoices|C_BpGroup_ID");
69       String JavaDoc strM_Product_Category_ID = vars.getRequestGlobalVariable("inpmProductCategoryId", "ReportInvoices|M_Product_Category_ID");
70       printPageDataHtml(response, vars, strC_BPartner_ID, strM_Product_ID, strDateFrom, strDateTo, strDocumentNo, strOrder, strC_BpGroup_ID, strM_Product_Category_ID);
71     } else pageError(response);
72   }
73
74   void printPageDataHtml(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strC_BPartner_ID, String JavaDoc strM_Product_ID, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strDocumentNo, String JavaDoc strOrder, String JavaDoc strC_BpGroup_ID, String JavaDoc strM_Product_Category_ID)
75     throws IOException, ServletException {
76     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
77     response.setContentType("text/html; charset=UTF-8");
78     //PrintWriter out = response.getWriter();
79
JasperPrint jasperPrint;
80
81     String JavaDoc strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportInvoicesEditJR.jrxml";
82     String JavaDoc strOutput = "html";
83     if (strOutput.equals("html")) response.setHeader("Content-disposition", "inline; filename=ReportInvoicesEdit.html");
84
85     ReportInvoicesData[] data=null;
86
87     data = ReportInvoicesData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportInvoices"), Utility.getContext(this, vars, "#User_Org", "ReportInvoices"), strC_BpGroup_ID, strM_Product_Category_ID, strC_BPartner_ID, strM_Product_ID, strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocumentNo, (strOrder.equals("PurchaseOrder"))?"":"sales", (strOrder.equals("PurchaseOrder"))?"purchase":"");
88
89     HashMap JavaDoc<String JavaDoc, Object JavaDoc> parameters = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>();
90         parameters.put("REPORT_TITLE", classInfo.name);
91
92         renderJR(vars, response, strReportName, strOutput, parameters, data, null );
93
94     String JavaDoc discard[]={"sectionBPartner"};
95     XmlDocument xmlDocument=null;
96     //ReportInvoicesData[] data=null;
97
/*
98     if (strC_BPartner_ID.equals("") && strM_Product_ID.equals("") && strDateFrom.equals("") && strDateTo.equals("") && strDocumentNo.equals("") && strC_BpGroup_ID.equals("") && strM_Product_Category_ID.equals("")) {
99       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoicesEdit", discard).createXmlDocument();
100       data = ReportInvoicesData.set();
101     } else {
102       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoicesEdit").createXmlDocument();
103       data = ReportInvoicesData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportInvoices"), Utility.getContext(this, vars, "#User_Org", "ReportInvoices"), strC_BpGroup_ID, strM_Product_Category_ID, strC_BPartner_ID, strM_Product_ID, strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocumentNo, (strOrder.equals("PurchaseOrder"))?"":"sales", (strOrder.equals("PurchaseOrder"))?"purchase":"");
104     }
105
106     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
107     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
108   
109
110     xmlDocument.setData("structure1", data);
111     out.println(xmlDocument.print());
112     out.close();*/

113   }
114   
115   void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strC_BPartner_ID, String JavaDoc strM_Product_ID, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strDocumentNo, String JavaDoc strOrder, String JavaDoc strC_BpGroup_ID, String JavaDoc strM_Product_Category_ID)
116     throws IOException, ServletException {
117     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
118     response.setContentType("text/html; charset=UTF-8");
119     PrintWriter out = response.getWriter();
120    
121     XmlDocument xmlDocument=null;
122     xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoicesJR").createXmlDocument();
123     
124     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportInvoicesJR", false, "", "", "",false, "ad_reports", strReplaceWith, false, true);
125     toolbar.prepareSimpleToolBarTemplate();
126     xmlDocument.setParameter("toolbar", toolbar.toString());
127     try {
128       KeyMap key = new KeyMap(this, vars, "ReportInvoicesJR.html");
129       xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
130     } catch (Exception JavaDoc ex) {
131       throw new ServletException(ex);
132     }
133     try {
134       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportInvoicesJR");
135       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
136       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
137       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
138       xmlDocument.setParameter("theme", vars.getTheme());
139       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportInvoicesJR.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
140       xmlDocument.setParameter("navigationBar", nav.toString());
141       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportInvoicesJR.html", strReplaceWith);
142       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
143     } catch (Exception JavaDoc ex) {
144       throw new ServletException(ex);
145     }
146     {
147       OBError myMessage = vars.getMessage("ReportInvoices");
148       vars.removeMessage("ReportInvoices");
149       if (myMessage!=null) {
150         xmlDocument.setParameter("messageType", myMessage.getType());
151         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
152         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
153       }
154     }
155
156
157     xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
158     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
159     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
160     xmlDocument.setParameter("paramBPartnerId", strC_BPartner_ID);
161     xmlDocument.setParameter("paramMProductId", strM_Product_ID);
162     xmlDocument.setParameter("dateFrom", strDateFrom);
163     xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
164     xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
165     xmlDocument.setParameter("dateTo", strDateTo);
166     xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
167     xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
168     xmlDocument.setParameter("paramDocumentNo", strDocumentNo);
169     xmlDocument.setParameter("paramCBpGroupID", strC_BpGroup_ID);
170     xmlDocument.setParameter("paramMProductCategoryID", strM_Product_Category_ID);
171     xmlDocument.setParameter("sales", strOrder);
172     xmlDocument.setParameter("purchase", strOrder);
173     xmlDocument.setParameter("paramBPartnerDescription", ReportInvoicesData.bPartnerDescription(this, strC_BPartner_ID));
174     xmlDocument.setParameter("paramMProductIDDES", ReportInvoicesData.mProductDescription(this, strM_Product_ID));
175
176
177     try {
178       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_BP_Group_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportInvoices"), Utility.getContext(this, vars, "#User_Client", "ReportInvoices"), 0);
179       Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoices", strC_BpGroup_ID);
180       xmlDocument.setData("reportC_Bp_Group","liststructure", comboTableData.select(false));
181       comboTableData = null;
182     } catch (Exception JavaDoc ex) {
183       throw new ServletException(ex);
184     }
185
186
187
188     try {
189       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Product_Category_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportInvoices"), Utility.getContext(this, vars, "#User_Client", "ReportInvoices"), 0);
190       Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoices", strM_Product_Category_ID);
191       xmlDocument.setData("reportM_Product_Category","liststructure", comboTableData.select(false));
192       comboTableData = null;
193     } catch (Exception JavaDoc ex) {
194       throw new ServletException(ex);
195     }
196
197
198     
199     out.println(xmlDocument.print());
200     out.close();
201   }
202   
203  /* void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strC_BPartner_ID, String strM_Product_ID, String strDateFrom, String strDateTo, String strDocumentNo, String strOrder, String strC_BpGroup_ID, String strM_Product_Category_ID)
204     throws IOException, ServletException {
205     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
206     response.setContentType("text/html; charset=UTF-8");
207     PrintWriter out = response.getWriter();
208     String discard[]={"sectionBPartner"};
209     XmlDocument xmlDocument=null;
210     ReportInvoicesData[] data=null;
211     if (strC_BPartner_ID.equals("") && strM_Product_ID.equals("") && strDateFrom.equals("") && strDateTo.equals("") && strDocumentNo.equals("") && strC_BpGroup_ID.equals("") && strM_Product_Category_ID.equals("")) {
212       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoices", discard).createXmlDocument();
213       data = ReportInvoicesData.set();
214     } else {
215       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoices").createXmlDocument();
216       data = ReportInvoicesData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportInvoices"), Utility.getContext(this, vars, "#User_Org", "ReportInvoices"), strC_BpGroup_ID, strM_Product_Category_ID, strC_BPartner_ID, strM_Product_ID, strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocumentNo, (strOrder.equals("PurchaseOrder"))?"":"sales", (strOrder.equals("PurchaseOrder"))?"purchase":"");
217     }
218
219     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportInvoices", false, "", "", "",false, "ad_reports", strReplaceWith, false, true);
220     toolbar.prepareSimpleToolBarTemplate();
221     xmlDocument.setParameter("toolbar", toolbar.toString());
222     try {
223       KeyMap key = new KeyMap(this, vars, "ReportInvoices.html");
224       xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
225     } catch (Exception ex) {
226       throw new ServletException(ex);
227     }
228     try {
229       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportInvoices");
230       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
231       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
232       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
233       xmlDocument.setParameter("theme", vars.getTheme());
234       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportInvoices.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
235       xmlDocument.setParameter("navigationBar", nav.toString());
236       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportInvoices.html", strReplaceWith);
237       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
238     } catch (Exception ex) {
239       throw new ServletException(ex);
240     }
241     {
242       OBError myMessage = vars.getMessage("ReportInvoices");
243       vars.removeMessage("ReportInvoices");
244       if (myMessage!=null) {
245         xmlDocument.setParameter("messageType", myMessage.getType());
246         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
247         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
248       }
249     }
250
251
252     xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
253     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
254     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
255     xmlDocument.setParameter("paramBPartnerId", strC_BPartner_ID);
256     xmlDocument.setParameter("paramMProductId", strM_Product_ID);
257     xmlDocument.setParameter("dateFrom", strDateFrom);
258     xmlDocument.setParameter("dateTo", strDateTo);
259     xmlDocument.setParameter("paramDocumentNo", strDocumentNo);
260     xmlDocument.setParameter("paramCBpGroupID", strC_BpGroup_ID);
261     xmlDocument.setParameter("paramMProductCategoryID", strM_Product_Category_ID);
262     xmlDocument.setParameter("sales", strOrder);
263     xmlDocument.setParameter("purchase", strOrder);
264     xmlDocument.setParameter("paramBPartnerDescription", ReportInvoicesData.bPartnerDescription(this, strC_BPartner_ID));
265     xmlDocument.setParameter("paramMProductIDDES", ReportInvoicesData.mProductDescription(this, strM_Product_ID));
266
267
268     try {
269       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_BP_Group_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportInvoices"), Utility.getContext(this, vars, "#User_Client", "ReportInvoices"), 0);
270       Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoices", strC_BpGroup_ID);
271       xmlDocument.setData("reportC_Bp_Group","liststructure", comboTableData.select(false));
272       comboTableData = null;
273     } catch (Exception ex) {
274       throw new ServletException(ex);
275     }
276
277
278
279     try {
280       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Product_Category_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportInvoices"), Utility.getContext(this, vars, "#User_Client", "ReportInvoices"), 0);
281       Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoices", strM_Product_Category_ID);
282       xmlDocument.setData("reportM_Product_Category","liststructure", comboTableData.select(false));
283       comboTableData = null;
284     } catch (Exception ex) {
285       throw new ServletException(ex);
286     }
287
288
289     xmlDocument.setData("structure1", data);
290     out.println(xmlDocument.print());
291     out.close();
292   }*/

293
294   public String JavaDoc getServletInfo() {
295     return "Servlet ReportInvoices. This Servlet was made by Pablo Sarobe";
296   } // end of getServletInfo() method
297
}
298
299
Popular Tags