KickJava   Java API By Example, From Geeks To Geeks.

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


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 ReportInvoiceDiscountJR 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_ReportInvoiceCustomer")) {
47       bdError(response, "AccessTableNoView", vars.getLanguage());
48       return;
49     }
50
51     if (vars.commandIn("DEFAULT")){
52       String JavaDoc strDateFrom = vars.getGlobalVariable("inpDateFrom", "ReportInvoiceDiscountJR|dateFrom", "");
53       String JavaDoc strDateTo = vars.getGlobalVariable("inpDateTo", "ReportInvoiceDiscountJR|dateTo", "");
54       String JavaDoc strcBpartnerId = vars.getInGlobalVariable("inpcBPartnerId_IN", "ReportInvoiceDiscountJR|partner", "");
55       String JavaDoc strDiscount = vars.getGlobalVariable("inpDiscount", "ReportInvoiceDiscountJR|discount", "N");
56       printPageDataSheet(response, vars, strDateFrom, strDateTo, strcBpartnerId, strDiscount);
57     } else if (vars.commandIn("FIND")) {
58       String JavaDoc strDateFrom = vars.getGlobalVariable("inpDateFrom", "ReportInvoiceDiscountJR|dateFrom", "");
59       String JavaDoc strDateTo = vars.getGlobalVariable("inpDateTo", "ReportInvoiceDiscountJR|dateTo", "");
60       String JavaDoc strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportInvoiceDiscountJR|partner");
61       String JavaDoc strDiscount = vars.getRequestGlobalVariable("inpDiscount", "ReportInvoiceDiscountJR|discount");
62       printPageDataHtml(response, vars, strDateFrom, strDateTo, strcBpartnerId, strDiscount);
63     } else pageError(response);
64   }
65
66   void printPageDataHtml(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strcBpartnerId, String JavaDoc strDiscount) throws IOException, ServletException {
67     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
68  
69     
70     XmlDocument xmlDocument=null;
71     if (strDiscount.equals("")) strDiscount = "N";
72
73
74           JasperPrint jasperPrint;
75
76      String JavaDoc strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscountJR.jrxml";
77      String JavaDoc strOutput = "html";
78       if (strOutput.equals("pdf")) response.setHeader("Content-disposition", "inline; filename=ReportInvoiceDiscountEdit.pdf");
79       ReportInvoiceDiscountData[] data = ReportInvoiceDiscountData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportInvoiceDiscountJR"), Utility.getContext(this, vars, "#User_Org", "ReportInvoiceDiscountJR"), strDateFrom,DateTimeData.nDaysAfter(this, strDateTo,"1"), strcBpartnerId, (strDiscount.equals("N"))?"":"discount");
80         HashMap JavaDoc<String JavaDoc, Object JavaDoc> parameters = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>();
81         parameters.put("REPORT_TITLE", "");
82     
83       renderJR(vars, response, strReportName, strOutput, parameters, data, null );
84
85   /* xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscountEdit").createXmlDocument();
86
87     
88     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
89     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
90
91     xmlDocument.setData("structure1", ReportInvoiceDiscountData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportInvoiceDiscount"), Utility.getContext(this, vars, "#User_Org", "ReportInvoiceDiscount"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strcBpartnerId, (strDiscount.equals("N"))?"":"discount"));
92     response.setContentType("text/html; charset=UTF-8");
93     PrintWriter out = response.getWriter();
94     out.println(xmlDocument.print());
95     out.close();*/

96   }
97   
98   void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strcBpartnerId, String JavaDoc strDiscount) throws IOException, ServletException {
99     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
100     
101     XmlDocument xmlDocument=null;
102     if (strDiscount.equals("")) strDiscount = "N";
103     xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscountJR").createXmlDocument();
104
105     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportInvoiceDiscountReportInvoiceDiscountJR", false, "", "", "",false, "ad_reports", strReplaceWith, false, true);
106     toolbar.prepareSimpleToolBarTemplate();
107     xmlDocument.setParameter("toolbar", toolbar.toString());
108     try {
109       KeyMap key = new KeyMap(this, vars, "ReportInvoiceDiscountJR.html");
110       xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
111     } catch (Exception JavaDoc ex) {
112       throw new ServletException(ex);
113     }
114     try {
115       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportInvoiceDiscountJR");
116       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
117       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
118       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
119       xmlDocument.setParameter("theme", vars.getTheme());
120       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportInvoiceDiscountJR.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
121       xmlDocument.setParameter("navigationBar", nav.toString());
122       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportInvoiceDiscountJR.html", strReplaceWith);
123       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
124     } catch (Exception JavaDoc ex) {
125       throw new ServletException(ex);
126     }
127     {
128       OBError myMessage = vars.getMessage("ReportInvoiceDiscountJR");
129       vars.removeMessage("ReportInvoiceDiscountJR");
130       if (myMessage!=null) {
131         xmlDocument.setParameter("messageType", myMessage.getType());
132         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
133         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
134       }
135     }
136
137     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
138     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
139     xmlDocument.setParameter("dateFrom", strDateFrom);
140     xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
141     xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
142     xmlDocument.setParameter("dateTo", strDateTo);
143     xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
144     xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
145     xmlDocument.setParameter("discount", strDiscount);
146     xmlDocument.setData("reportCBPartnerId_IN", "liststructure", ReportInvoiceDiscountData.selectBpartner(this, Utility.getContext(this, vars, "#User_Org", "ReportInvoiceDiscountJR"), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceDiscountJR"), strcBpartnerId));
147     
148     response.setContentType("text/html; charset=UTF-8");
149     PrintWriter out = response.getWriter();
150     out.println(xmlDocument.print());
151     out.close();
152   }
153
154   
155   /*void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strcBpartnerId, String strDiscount) throws IOException, ServletException {
156     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
157     String discard[]={"discard"};
158     XmlDocument xmlDocument=null;
159     if (strDiscount.equals("")) strDiscount = "N";
160     xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscount").createXmlDocument();
161
162     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportInvoiceDiscountReportInvoiceDiscount", false, "", "", "",false, "ad_reports", strReplaceWith, false, true);
163     toolbar.prepareSimpleToolBarTemplate();
164     xmlDocument.setParameter("toolbar", toolbar.toString());
165     try {
166       KeyMap key = new KeyMap(this, vars, "ReportInvoiceDiscount.html");
167       xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
168     } catch (Exception ex) {
169       throw new ServletException(ex);
170     }
171     try {
172       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportInvoiceDiscount");
173       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
174       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
175       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
176       xmlDocument.setParameter("theme", vars.getTheme());
177       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportInvoiceDiscount.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
178       xmlDocument.setParameter("navigationBar", nav.toString());
179       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportInvoiceDiscount.html", strReplaceWith);
180       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
181     } catch (Exception ex) {
182       throw new ServletException(ex);
183     }
184     {
185       OBError myMessage = vars.getMessage("ReportInvoiceDiscount");
186       vars.removeMessage("ReportInvoiceDiscount");
187       if (myMessage!=null) {
188         xmlDocument.setParameter("messageType", myMessage.getType());
189         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
190         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
191       }
192     }
193
194     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
195     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
196     xmlDocument.setParameter("dateFrom", strDateFrom);
197     xmlDocument.setParameter("dateTo", strDateTo);
198     xmlDocument.setParameter("discount", strDiscount);
199     xmlDocument.setData("reportCBPartnerId_IN", "liststructure", ReportInvoiceDiscountData.selectBpartner(this, Utility.getContext(this, vars, "#User_Org", "ReportInvoiceDiscount"), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceDiscount"), strcBpartnerId));
200     xmlDocument.setData("structure1", ReportInvoiceDiscountData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportInvoiceDiscount"), Utility.getContext(this, vars, "#User_Org", "ReportInvoiceDiscount"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strcBpartnerId, (strDiscount.equals("N"))?"":"discount"));
201     response.setContentType("text/html; charset=UTF-8");
202     PrintWriter out = response.getWriter();
203     out.println(xmlDocument.print());
204     out.close();
205   }*/

206
207
208   public String JavaDoc getServletInfo() {
209     return "Servlet ReportInvoiceDiscount. This Servlet was made by Pablo Sarobe";
210   } // end of getServletInfo() method
211
}
212
213
Popular Tags