KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_forms > InformeInOut


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_forms;
20
21 import org.openbravo.erpCommon.utility.Utility;
22 import org.openbravo.base.secureApp.HttpSecureAppServlet;
23 import org.openbravo.base.secureApp.VariablesSecureApp;
24 import org.openbravo.xmlEngine.XmlDocument;
25 import java.io.*;
26 import javax.servlet.*;
27 import javax.servlet.http.*;
28
29 import org.openbravo.erpCommon.utility.DateTimeData;
30
31
32 public class InformeInOut extends HttpSecureAppServlet {
33   
34
35   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
36     VariablesSecureApp vars = new VariablesSecureApp(request);
37
38     if (!Utility.hasFormAccess(this, vars, "", "org.openbravo.erpCommon.ad_forms.InformeInOut")) {
39       bdError(response, "AccessTableNoView", vars.getLanguage());
40       return;
41     }
42
43     if (vars.commandIn("DEFAULT")) {
44       String JavaDoc strDesde = vars.getStringParameter("inpDesde",DateTimeData.today(this));
45       String JavaDoc strHasta = vars.getStringParameter("inpHasta",DateTimeData.today(this));
46       printPageSelector(response, vars, strDesde, strHasta);
47     } else if (vars.commandIn("FIND")) {
48       String JavaDoc strDesde = vars.getStringParameter("inpDesde");
49       String JavaDoc strHasta = vars.getStringParameter("inpHasta");
50       setHistoryCommand(request, "DEFAULT");
51       String JavaDoc strCategoriaProducto = vars.getStringParameter("inpClaveCategoriaProducto","");
52       printPage(response, vars, strDesde, strHasta, strCategoriaProducto);
53     } else pageError(response);
54   }
55
56   private void printPageSelector(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strDesde, String JavaDoc strHasta) throws IOException, ServletException{
57     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_forms/InformeInOut").createXmlDocument();
58     xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
59     xmlDocument.setParameter("fechaDesde",strDesde);
60     xmlDocument.setParameter("fechaHasta",strHasta);
61     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
62     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
63     xmlDocument.setData("reportCategoriaProducto", "structure1", CategoriaProductoComboData.select(this));
64     response.setContentType("text/html; charset=UTF-8");
65     PrintWriter out = response.getWriter();
66     out.println(xmlDocument.print());
67     out.close();
68   }
69
70   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strDesde, String JavaDoc strHasta, String JavaDoc strCategoriaProducto) throws IOException, ServletException {
71     response.setContentType("application/xls");
72     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_forms/InformeInOut_Excel").createXmlDocument();
73     xmlDocument.setData("structure1", InformeInOutData.select(this, vars.getSqlDateFormat(), strHasta, strDesde, strCategoriaProducto));
74
75
76     response.setContentType("application/xls");
77     PrintWriter out = response.getWriter();
78     out.println(xmlDocument.print());
79     out.close();
80   }
81
82
83   public String JavaDoc getServletInfo() {
84     return "Servlet for the media reports generation";
85   } // end of getServletInfo() method
86
}
87
Popular Tags