KickJava   Java API By Example, From Geeks To Geeks.

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


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
30 import org.openbravo.utils.CommPortsOpen;
31
32 public class Rpt_Etiquetas extends HttpSecureAppServlet {
33
34
35   public void init (ServletConfig config) {
36     super.init(config);
37     boolHist = false;
38   }
39
40   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
41     VariablesSecureApp vars = new VariablesSecureApp(request);
42
43     if (!Utility.hasProcessAccess(this, vars, "", "RptM_ProductionLine")) {
44       bdError(response, "AccessTableNoView", vars.getLanguage());
45       return;
46     }
47
48     if (vars.commandIn("DEFAULT")) {
49       vars.getGlobalVariable("inpwindowId", "Rpt_Etiquetas|windowID","");
50       String JavaDoc strcBpartnerId = vars.getGlobalVariable("inpcBpartnerId", "Rpt_Etiquetas|cBpartnerId", "");
51       String JavaDoc strmProductId = vars.getGlobalVariable("inpmProductId", "Rpt_Etiquetas|mProductId", "");
52       String JavaDoc strmAttributesetinstanceId = vars.getGlobalVariable("inpmAttributesetinstanceId", "Rpt_Etiquetas|mAttributesetinstanceId", "");
53       String JavaDoc strqty = vars.getGlobalVariable("inpqty", "Rpt_Etiquetas|qty", "");
54       printPage(response, vars, strcBpartnerId, strmProductId, strmAttributesetinstanceId, strqty);
55     } else if (vars.commandIn("PRINT_LABEL")) {
56       String JavaDoc strWindow = vars.getGlobalVariable("inpwindowId", "Rpt_Etiquetas|windowID","");
57       String JavaDoc strBpartner = vars.getRequestGlobalVariable("inpBpartnerId", "Rpt_Etiquetas|cBpartnerId");
58       String JavaDoc strProduct = vars.getRequestGlobalVariable("inpmProductId", "Rpt_Etiquetas|mProductId");
59       String JavaDoc strAttribute = vars.getRequestGlobalVariable("inpmAttributesetinstanceId", "Rpt_Etiquetas|mAttributesetinstanceId");
60       String JavaDoc strPageNumber = vars.getRequestGlobalVariable("inpNumberPages", "Rpt_Etiquetas|qty");
61       String JavaDoc label = compoundLabel(vars, strBpartner, strProduct, strAttribute, strPageNumber);
62       try {
63         CommPortsOpen comm = new CommPortsOpen();
64         comm.transmit(label);
65         comm.close();
66         if (strWindow.equals("")) bdError(response, "ProcessOK", vars.getLanguage());
67         else printPageClosePopUpWindow(response, vars);
68       } catch(Exception JavaDoc e) {
69         log4j.error(e);
70         advise(response, "Error", e.toString());
71       }
72     } else pageError(response);
73   }
74
75   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strcBpartnerId, String JavaDoc strmProductId, String JavaDoc strmAttributesetinstanceId, String JavaDoc strqty) 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     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/Rpt_Etiquetas_Config").createXmlDocument();
80
81     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
82     xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
83     xmlDocument.setParameter("product", strmProductId);
84     xmlDocument.setParameter("productName", RptEtiquetasData.selectProduct(this, strmProductId));
85     xmlDocument.setParameter("bpartner", strcBpartnerId);
86     xmlDocument.setParameter("bpartnerName", RptEtiquetasData.selectBPartner(this, strcBpartnerId));
87     xmlDocument.setParameter("attribute", strmAttributesetinstanceId);
88     xmlDocument.setParameter("attributeName", RptEtiquetasData.selectAttribute(this, strmAttributesetinstanceId));
89     xmlDocument.setParameter("numberPages", strqty);
90
91     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "RptEtiquetas", false, "", "", "",false, "ad_reports", strReplaceWith, false, true);
92     toolbar.prepareSimpleToolBarTemplate();
93     xmlDocument.setParameter("toolbar", toolbar.toString());
94     try {
95       KeyMap key = new KeyMap(this, vars, "Rpt_Etiquetas_Config.html");
96       xmlDocument.setParameter("keyMap", key.getReportKeyMaps());
97     } catch (Exception JavaDoc ex) {
98       throw new ServletException(ex);
99     }
100     try {
101       WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.Rpt_Etiquetas");
102       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
103       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
104       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
105       xmlDocument.setParameter("theme", vars.getTheme());
106       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "Rpt_Etiquetas_Config.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
107       xmlDocument.setParameter("navigationBar", nav.toString());
108       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "Rpt_Etiquetas_Config.html", strReplaceWith);
109       xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
110     } catch (Exception JavaDoc ex) {
111       throw new ServletException(ex);
112     }
113     {
114       OBError myMessage = vars.getMessage("Rpt_Etiquetas");
115       vars.removeMessage("Rpt_Etiquetas");
116       if (myMessage!=null) {
117         xmlDocument.setParameter("messageType", myMessage.getType());
118         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
119         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
120       }
121     }
122
123     out.println(xmlDocument.print());
124     out.close();
125   }
126
127   String JavaDoc compoundLabel(VariablesSecureApp vars, String JavaDoc strBpartner, String JavaDoc strProduct, String JavaDoc strAttribute, String JavaDoc strPageNumber) throws IOException,ServletException {
128     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
129
130     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/Rpt_Etiquetas").createXmlDocument();
131     RptEtiquetasData[] data = RptEtiquetasData.select(this, strProduct, strBpartner);
132
133     xmlDocument.setParameter("bPartnerName", RptEtiquetasData.selectBPartner(this, strBpartner));
134     if (data!=null && data.length>0) {
135       xmlDocument.setParameter("productName", data[0].name);
136       xmlDocument.setParameter("productDescription", data[0].description);
137       xmlDocument.setParameter("productEAN", data[0].upc);
138     }
139     RptEtiquetasData[] data2 = RptEtiquetasData.selectAttributeComplete(this, strAttribute);
140     if (data2!=null && data2.length>0) {
141       xmlDocument.setParameter("productAttribute", data2[0].lot);
142       xmlDocument.setParameter("productAttributeCad", data2[0].guaranteedate);
143     }
144
145     xmlDocument.setParameter("numberPages", strPageNumber);
146
147     return(xmlDocument.print());
148   }
149
150
151   public String JavaDoc getServletInfo() {
152     return "Servlet Etiquetas. This Servlet was made by Firi";
153   } // end of the getServletInfo() method
154
}
155
156
Popular Tags