1 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 strcBpartnerId = vars.getGlobalVariable("inpcBpartnerId", "Rpt_Etiquetas|cBpartnerId", ""); 51 String strmProductId = vars.getGlobalVariable("inpmProductId", "Rpt_Etiquetas|mProductId", ""); 52 String strmAttributesetinstanceId = vars.getGlobalVariable("inpmAttributesetinstanceId", "Rpt_Etiquetas|mAttributesetinstanceId", ""); 53 String strqty = vars.getGlobalVariable("inpqty", "Rpt_Etiquetas|qty", ""); 54 printPage(response, vars, strcBpartnerId, strmProductId, strmAttributesetinstanceId, strqty); 55 } else if (vars.commandIn("PRINT_LABEL")) { 56 String strWindow = vars.getGlobalVariable("inpwindowId", "Rpt_Etiquetas|windowID",""); 57 String strBpartner = vars.getRequestGlobalVariable("inpBpartnerId", "Rpt_Etiquetas|cBpartnerId"); 58 String strProduct = vars.getRequestGlobalVariable("inpmProductId", "Rpt_Etiquetas|mProductId"); 59 String strAttribute = vars.getRequestGlobalVariable("inpmAttributesetinstanceId", "Rpt_Etiquetas|mAttributesetinstanceId"); 60 String strPageNumber = vars.getRequestGlobalVariable("inpNumberPages", "Rpt_Etiquetas|qty"); 61 String 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 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 strcBpartnerId, String strmProductId, String strmAttributesetinstanceId, String 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 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 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 compoundLabel(VariablesSecureApp vars, String strBpartner, String strProduct, String strAttribute, String 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 getServletInfo() { 152 return "Servlet Etiquetas. This Servlet was made by Firi"; 153 } } 155 156 | Popular Tags |