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 org.openbravo.utils.Replace; 28 import java.io.*; 29 import javax.servlet.*; 30 import javax.servlet.http.*; 31 32 33 public class SL_InOut_BPartner extends HttpSecureAppServlet { 34 35 36 public void init (ServletConfig config) { 37 super.init(config); 38 boolHist = false; 39 } 40 41 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 42 VariablesSecureApp vars = new VariablesSecureApp(request); 43 if (vars.commandIn("DEFAULT")) { 44 String strChanged = vars.getStringParameter("inpLastFieldChanged"); 45 if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged); 46 String strBPartner = vars.getStringParameter("inpcBpartnerId"); 47 String strLocation = vars.getStringParameter("inpcBpartnerId_LOC"); 48 String strContact = vars.getStringParameter("inpcBpartnerId_CON"); 49 String strWindowId = vars.getStringParameter("inpwindowId"); 50 String strProjectId = vars.getStringParameter("inpcProjectId"); 51 String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId); 52 String strTabId = vars.getStringParameter("inpTabId"); 53 54 try { 55 printPage(response, vars, strBPartner, strLocation, strContact, strWindowId, strProjectId, strIsSOTrx, strTabId); 56 } catch (ServletException ex) { 57 pageErrorCallOut(response); 58 } 59 } else pageError(response); 60 } 61 62 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strBPartner, String strLocation, String strContact, String strWindowId, String strProjectId, String strIsSOTrx, String strTabId) throws IOException, ServletException { 63 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 64 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); 65 66 SEOrderBPartnerData[] data = SEOrderBPartnerData.select(this, strBPartner); 67 68 String strUserRep=""; 69 if (data!=null && data.length>0) strUserRep = SEOrderBPartnerData.userIdSalesRep(this, data[0].salesrepId); 70 71 StringBuffer resultado = new StringBuffer (); 72 resultado.append("var calloutName='SL_InOut_BPartner';\n\n"); 73 resultado.append("var respuesta = new Array("); 74 75 FieldProvider [] tdv = null; 76 try { 77 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_BPartner_Location_ID", "", "C_BPartner Location - Ship To", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0); 78 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, ""); 79 tdv = comboTableData.select(false); 80 comboTableData = null; 81 } catch (Exception ex) { 82 throw new ServletException(ex); 83 } 84 85 resultado.append("new Array(\"inpcBpartnerLocationId\", "); 86 if (tdv!=null && tdv.length>0) { 87 resultado.append("new Array("); 88 for (int i=0;i<tdv.length;i++) { 89 resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", "\\\"")) + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strLocation)?"true":"false") + "\")"); 90 if (i<tdv.length-1) resultado.append(",\n"); 91 } 92 resultado.append("\n)"); 93 } else resultado.append("null"); 94 resultado.append("\n),"); 95 resultado.append("new Array(\"inpsalesrepId\", "); 96 FieldProvider [] tld = null; 97 try { 98 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "SalesRep_ID", "AD_User SalesRep", "", Utility.getContext(this, vars, "#User_Org", "SEOrderBPartner"), Utility.getContext(this, vars, "#User_Client", "SEOrderBPartner"), 0); 99 Utility.fillSQLParameters(this, vars, null, comboTableData, "SEOrderBPartner", ""); 100 tld = comboTableData.select(false); 101 comboTableData = null; 102 } catch (Exception ex) { 103 throw new ServletException(ex); 104 } 105 106 if (tld!=null && tld.length>0) { 107 resultado.append("new Array("); 108 for (int i=0;i<tld.length;i++) { 109 resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strUserRep)?"true":"false") + "\")"); 110 if (i<tld.length-1) resultado.append(",\n"); 111 } 112 resultado.append("\n)"); 113 } else resultado.append("null"); 114 resultado.append("\n),"); 115 resultado.append("new Array(\"inpcProjectId\", \"\"),"); 116 resultado.append("new Array(\"inpcProjectId_R\", \"\"),"); 117 try { 118 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_User_ID", "", "AD_User C_BPartner User/Contacts", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0); 119 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, ""); 120 tdv = comboTableData.select(false); 121 comboTableData = null; 122 } catch (Exception ex) { 123 throw new ServletException(ex); 124 } 125 126 127 resultado.append("new Array(\"inpadUserId\", "); 128 if (tdv!=null && tdv.length>0) { 129 resultado.append("new Array("); 130 for (int i=0;i<tdv.length;i++) { 131 resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(Replace.replace(tdv[i].getField("name"), "\"", "\\\"")) + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strContact)?"true":"false") + "\")"); 132 if (i<tdv.length-1) resultado.append(",\n"); 133 } 134 resultado.append("\n)"); 135 } else resultado.append("null"); 136 resultado.append("\n)"); 137 if (data!=null && data.length >0 && Double.valueOf(data[0].creditavailable).doubleValue() < 0.0) 138 resultado.append(", new Array('MESSAGE', \"" + Utility.messageBD(this, "CreditLimitOver", vars.getLanguage()) + data[0].creditavailable + "\")"); 139 resultado.append(");"); 140 xmlDocument.setParameter("array", resultado.toString()); 141 xmlDocument.setParameter("frameName", "frameAplicacion"); 142 response.setContentType("text/html; charset=UTF-8"); 143 PrintWriter out = response.getWriter(); 144 out.println(xmlDocument.print()); 145 out.close(); 146 } 147 } 148 | Popular Tags |