KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.openbravo.erpCommon.ad_reports;
21
22 import org.openbravo.erpCommon.utility.*;
23 import org.openbravo.erpCommon.businessUtility.WindowTabs;
24 import org.openbravo.base.secureApp.HttpSecureAppServlet;
25 import org.openbravo.base.secureApp.VariablesSecureApp;
26 import org.openbravo.xmlEngine.XmlDocument;
27 import java.io.*;
28 import javax.servlet.*;
29 import javax.servlet.http.*;
30
31 //import org.openbravo.erpCommon.ad_combos.WarehouseComboData;
32

33 public class ReportInventory extends HttpSecureAppServlet {
34
35
36   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
37     VariablesSecureApp vars = new VariablesSecureApp(request);
38
39     if (!Utility.hasProcessAccess(this, vars, "", "ReportInventory")) {
40       bdError(response, "AccessTableNoView", vars.getLanguage());
41       return;
42     }
43
44     if (vars.commandIn("DEFAULT")) {
45       String JavaDoc strmWarehouseId = vars.getStringParameter("inpmWarehouseId", vars.getWarehouse());
46       String JavaDoc strDetalle = vars.getStringParameter("inpDetalle", "");
47       printPageDataSheet(response, vars, strmWarehouseId, strDetalle);
48     } else if (vars.commandIn("FIND")) {
49       String JavaDoc strDetalle = vars.getStringParameter("inpDetalle");
50       String JavaDoc strmWarehouseId = vars.getStringParameter("inpmWarehouseId");
51       printPageDataHtml(response, vars, strmWarehouseId, strDetalle);
52     } else pageError(response);
53   }
54
55   void printPageDataHtml(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strmWarehouseId, String JavaDoc strDetalle)
56     throws IOException, ServletException {
57     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
58     response.setContentType("text/html; charset=UTF-8");
59     PrintWriter out = response.getWriter();
60     XmlDocument xmlDocument=null;
61     ReportInventoryData [] data = ReportInventoryData.selectSinDetalle(this, strmWarehouseId, Utility.getContext(this, vars, "#User_Client", "ReportInventory"), Utility.getContext(this, vars, "#User_Org", "ReportInventory"));
62
63
64     if (data.length == 0) {
65       String JavaDoc[] discard = {"sectionLocator"};
66       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInventoryEdit", discard).createXmlDocument();
67       xmlDocument.setData("structure1", ReportInventoryData.set());
68     } else if(!strDetalle.equals("-1")){
69       String JavaDoc[] discard = {"reportDetalle"};
70       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInventoryEdit", discard).createXmlDocument();
71       xmlDocument.setData("structure1", data);
72     } else{
73       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInventoryEdit").createXmlDocument();
74
75
76       ReportInventoryData [] [] subreport = new ReportInventoryData [data.length] [];
77
78       String JavaDoc strWarehouse = "";
79       String JavaDoc strProduct = "";
80       String JavaDoc strUom = "";
81       int j = 0;
82       boolean existsAtt = false;
83       for (int i=0;i<data.length ;i++){
84         existsAtt = false;
85         if (!(strWarehouse.equals(data[i].mLocatorId))||!(strProduct.equals(data[i].mProductId))||!(strUom.equals(data[i].productUom))) {
86           strWarehouse = data[i].mLocatorId;
87           strProduct = data[i].mProductId;
88           strUom = data[i].productUom;
89           ReportInventoryData [] data2 = ReportInventoryData.select(this, data[i].mProductId, data[i].cUomId, data[i].mLocatorId, Utility.getContext(this, vars, "#User_Client", "ReportInventory"), Utility.getContext(this, vars, "#User_Org", "ReportInventory"));
90           for (int k=0;k<data2.length ;k++ ){
91             if (!data2[k].lot.equals("")){
92               subreport[j] = data2;
93               existsAtt = true;
94               break;
95             }
96           }
97           if (!existsAtt) {
98             subreport[j] = new ReportInventoryData [0];
99           }
100           j++;
101         }
102       }
103
104       xmlDocument.setDataArray("reportDetalle","structure4",subreport);
105       xmlDocument.setData("structure1", data);
106     }
107     
108     
109     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
110     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
111     
112     out.println(xmlDocument.print());
113     out.close();
114   }
115   
116   void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strmWarehouseId, String JavaDoc strDetalle)
117     throws IOException, ServletException {
118     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
119     response.setContentType("text/html; charset=UTF-8");
120     PrintWriter out = response.getWriter();
121     XmlDocument xmlDocument=null;
122    
123
124       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInventory").createXmlDocument();
125
126
127       
128
129       String JavaDoc strWarehouse = "";
130       String JavaDoc strProduct = "";
131       String JavaDoc strUom = "";
132       int j = 0;
133       boolean existsAtt = false;
134       
135     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportInventory", false, "", "", "",false, "ad_reports", strReplaceWith, false, true);
136     toolbar.prepareSimpleToolBarTemplate();
137     xmlDocument.setParameter("toolbar", toolbar.toString());
138     try {
139       KeyMap key = new KeyMap(this, vars, "ReportInventory.html");
140       xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
141     } catch (Exception JavaDoc ex) {
142       throw new ServletException(ex);
143     }
144     try {
145       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportInventory");
146       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
147       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
148       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
149       xmlDocument.setParameter("theme", vars.getTheme());
150       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportInventory.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
151       xmlDocument.setParameter("navigationBar", nav.toString());
152       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportInventory.html", strReplaceWith);
153       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
154     } catch (Exception JavaDoc ex) {
155       throw new ServletException(ex);
156     }
157     {
158       OBError myMessage = vars.getMessage("ReportInventory");
159       vars.removeMessage("ReportInventory");
160       if (myMessage!=null) {
161         xmlDocument.setParameter("messageType", myMessage.getType());
162         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
163         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
164       }
165     }
166
167
168
169   // xmlDocument.setData("structure", WarehouseComboData.selectFilter(this, Utility.getContext(this, vars, "#User_Client", "ReportInventory")));
170

171     xmlDocument.setParameter("mWarehouseId", strmWarehouseId);
172     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
173     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
174     xmlDocument.setParameter("Detalle", strDetalle);
175    try {
176       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Warehouse_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportInventory"), Utility.getContext(this, vars, "#User_Client", "ReportInventory"), 0);
177       Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInventory", strmWarehouseId);
178       xmlDocument.setData("reportM_WAREHOUSEID","liststructure", comboTableData.select(false));
179       comboTableData = null;
180     } catch (Exception JavaDoc ex) {
181       throw new ServletException(ex);
182     }
183     out.println(xmlDocument.print());
184     out.close();
185   }
186   
187   /*void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strmWarehouseId, String strDetalle)
188     throws IOException, ServletException {
189     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
190     response.setContentType("text/html; charset=UTF-8");
191     PrintWriter out = response.getWriter();
192     XmlDocument xmlDocument=null;
193     ReportInventoryData [] data = ReportInventoryData.selectSinDetalle(this, strmWarehouseId, Utility.getContext(this, vars, "#User_Client", "ReportInventory"), Utility.getContext(this, vars, "#User_Org", "ReportInventory"));
194
195
196     if (data.length == 0) {
197       String[] discard = {"sectionLocator"};
198       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInventory", discard).createXmlDocument();
199       xmlDocument.setData("structure1", ReportInventoryData.set());
200     } else if(!strDetalle.equals("-1")){
201       String[] discard = {"reportDetalle"};
202       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInventory", discard).createXmlDocument();
203       xmlDocument.setData("structure1", data);
204     } else{
205       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInventory").createXmlDocument();
206
207
208       ReportInventoryData [] [] subreport = new ReportInventoryData [data.length] [];
209
210       String strWarehouse = "";
211       String strProduct = "";
212       String strUom = "";
213       int j = 0;
214       boolean existsAtt = false;
215       for (int i=0;i<data.length ;i++){
216         existsAtt = false;
217         if (!(strWarehouse.equals(data[i].mLocatorId))||!(strProduct.equals(data[i].mProductId))||!(strUom.equals(data[i].productUom))) {
218           strWarehouse = data[i].mLocatorId;
219           strProduct = data[i].mProductId;
220           strUom = data[i].productUom;
221           ReportInventoryData [] data2 = ReportInventoryData.select(this, data[i].mProductId, data[i].cUomId, data[i].mLocatorId, Utility.getContext(this, vars, "#User_Client", "ReportInventory"), Utility.getContext(this, vars, "#User_Org", "ReportInventory"));
222           for (int k=0;k<data2.length ;k++ ){
223             if (!data2[k].lot.equals("")){
224               subreport[j] = data2;
225               existsAtt = true;
226               break;
227             }
228           }
229           if (!existsAtt) {
230             subreport[j] = new ReportInventoryData [0];
231           }
232           j++;
233         }
234       }
235
236       xmlDocument.setDataArray("reportDetalle","structure4",subreport);
237       xmlDocument.setData("structure1", data);
238     }
239     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportInventory", false, "", "", "",false, "ad_reports", strReplaceWith, false, true);
240     toolbar.prepareSimpleToolBarTemplate();
241     xmlDocument.setParameter("toolbar", toolbar.toString());
242     try {
243       KeyMap key = new KeyMap(this, vars, "ReportInventory.html");
244       xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
245     } catch (Exception ex) {
246       throw new ServletException(ex);
247     }
248     try {
249       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportInventory");
250       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
251       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
252       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
253       xmlDocument.setParameter("theme", vars.getTheme());
254       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportInventory.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
255       xmlDocument.setParameter("navigationBar", nav.toString());
256       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportInventory.html", strReplaceWith);
257       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
258     } catch (Exception ex) {
259       throw new ServletException(ex);
260     }
261     {
262       OBError myMessage = vars.getMessage("ReportInventory");
263       vars.removeMessage("ReportInventory");
264       if (myMessage!=null) {
265         xmlDocument.setParameter("messageType", myMessage.getType());
266         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
267         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
268       }
269     }
270
271
272
273     xmlDocument.setData("structure", WarehouseComboData.selectFilter(this, Utility.getContext(this, vars, "#User_Client", "ReportInventory")));
274
275     xmlDocument.setParameter("warehouse", strmWarehouseId);
276     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
277     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
278     xmlDocument.setParameter("Detalle", strDetalle);
279     out.println(xmlDocument.print());
280     out.close();
281   }*/

282
283   public String JavaDoc getServletInfo() {
284     return "Servlet ReportInventory. This Servlet was made by Eduardo Argal";
285   } // end of getServletInfo() method
286
}
287
288
Popular Tags