1 19 package org.openbravo.erpCommon.ad_callouts; 20 21 import org.openbravo.base.secureApp.HttpSecureAppServlet; 22 import org.openbravo.base.secureApp.VariablesSecureApp; 23 import org.openbravo.xmlEngine.XmlDocument; 24 import org.openbravo.utils.FormatUtilities; 25 import org.openbravo.erpCommon.utility.*; 26 import org.openbravo.data.FieldProvider; 27 import java.io.*; 28 import javax.servlet.*; 29 import javax.servlet.http.*; 30 31 public class SL_GlobalUse_Product extends HttpSecureAppServlet { 32 33 34 public void init (ServletConfig config) { 35 super.init(config); 36 boolHist = false; 37 } 38 39 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 40 VariablesSecureApp vars = new VariablesSecureApp(request); 41 if (vars.commandIn("DEFAULT")) { 42 String strChanged = vars.getStringParameter("inpLastFieldChanged"); 43 if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged); 44 String strTabId = vars.getStringParameter("inpTabId"); 45 46 String strMProductID = vars.getStringParameter("inpmProductId"); 47 String strPAttr = vars.getStringParameter("inpmProductId_ATR"); 48 49 try { 50 printPage(response, vars, strTabId, strMProductID, strPAttr); 51 } catch (ServletException ex) { 52 pageErrorCallOut(response); 53 } 54 } else pageError(response); 55 } 56 57 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strTabId, String strMProductID, String strPAttr) throws IOException, ServletException { 58 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 59 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 60 61 String strProductUom = SLWRPhaseProductProductData.selectProductUom(this, strMProductID); 62 StringBuffer resultado = new StringBuffer (); 63 resultado.append("var calloutName='SL_GlobalUse_Product';\n\n"); 64 resultado.append("var respuesta = new Array("); 65 resultado.append("new Array(\"inpcUomId\", \"" + FormatUtilities.replaceJS((strProductUom.equals("")?"\"\"":strProductUom)) + "\"),\n"); 66 String strHasSecondaryUOM = SLGlobalUseProductData.hasSecondaryUOM(this, strMProductID); 67 resultado.append("new Array(\"inphasseconduom\", \"" + strHasSecondaryUOM + "\"),\n"); 68 if (strPAttr.startsWith("\"")) strPAttr=strPAttr.substring(1,strPAttr.length()-1); 69 resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + strPAttr + "\"),\n"); 70 resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"" + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, strPAttr)) + "\"),\n"); 71 72 74 resultado.append("new Array(\"inpmProductUomId\", "); 75 String strmProductUOMId = SLGlobalUseProductData.strMProductUOMID(this,strMProductID,strProductUom); 76 if (vars.getLanguage().equals("en_US")) { 77 FieldProvider [] tld = null; 78 try { 79 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLOrderProduct"), Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0); 80 Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", ""); 81 tld = comboTableData.select(false); 82 comboTableData = null; 83 } catch (Exception ex) { 84 throw new ServletException(ex); 85 } 86 87 if (tld!=null && tld.length>0) { 88 resultado.append("new Array("); 89 for (int i=0;i<tld.length;i++) { 90 resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strmProductUOMId)?"true":"false") + "\")"); 91 if (i<tld.length-1) resultado.append(",\n"); 92 } 93 resultado.append("\n)"); 94 } else resultado.append("null"); 95 resultado.append("\n),"); 96 } else { 97 FieldProvider [] tld = null; 98 try { 99 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLOrderProduct"), Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0); 100 Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", ""); 101 tld = comboTableData.select(false); 102 comboTableData = null; 103 } catch (Exception ex) { 104 throw new ServletException(ex); 105 } 106 107 if (tld!=null && tld.length>0) { 108 resultado.append("new Array("); 109 for (int i=0;i<tld.length;i++) { 110 resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strmProductUOMId)?"true":"false") + "\")"); 111 if (i<tld.length-1) resultado.append(",\n"); 112 } 113 resultado.append("\n)"); 114 } else resultado.append("null"); 115 resultado.append("\n),"); 116 } 117 resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n"); 118 resultado.append(");\n"); 122 123 xmlDocument.setParameter("array", resultado.toString()); 124 xmlDocument.setParameter("frameName", "frameAplicacion"); 125 response.setContentType("text/html; charset=UTF-8"); 126 PrintWriter out = response.getWriter(); 127 out.println(xmlDocument.print()); 128 out.close(); 129 } 130 } 131 | Popular Tags |