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 32 public class SE_Invoice_BPartner 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 if (vars.commandIn("DEFAULT")) { 43 String strChanged = vars.getStringParameter("inpLastFieldChanged"); 44 if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged); 45 String strBPartner = vars.getStringParameter("inpcBpartnerId"); 46 String strDocType = vars.getStringParameter("inpcDoctypetargetId"); 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, strDocType, strIsSOTrx, strWindowId, strLocation, strContact, strProjectId, 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 strDocType, String strIsSOTrx, String strWindowId, String strLocation, String strContact, String strProjectId, 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 String strUserRep; 68 String DocBaseType = SEInvoiceBPartnerData.docBaseType(this, strDocType); 69 StringBuffer resultado = new StringBuffer (); 70 resultado.append("var calloutName='SE_Invoice_BPartner';\n\n"); 71 if (data==null || data.length==0) resultado.append("var respuesta = null;"); 72 else { 73 resultado.append("var respuesta = new Array("); 74 strUserRep = SEOrderBPartnerData.userIdSalesRep(this, data[0].salesrepId); 75 String strPriceList = (strIsSOTrx.equals("Y")?data[0].mPricelistId: data[0].poPricelistId); 76 resultado.append("new Array(\"inpmPricelistId\", \"" + (strPriceList.equals("")? Utility.getContext(this, vars, "#M_PriceList_ID", strWindowId): strPriceList) + "\"),"); 77 String strPaymentRule = (strIsSOTrx.equals("Y")?data[0].paymentrule:data[0].paymentrulepo); 78 if (strPaymentRule.equals("") && DocBaseType.endsWith("C")) strPaymentRule="P"; 79 else if (strPaymentRule.equals("S") || strPaymentRule.equals("U") && strIsSOTrx.equals("Y")) strPaymentRule = "P"; 80 resultado.append("new Array(\"inppaymentrule\", \"" + strPaymentRule + "\"),"); 81 String PaymentTerm = (strIsSOTrx.equals("Y")?data[0].cPaymenttermId:data[0].poPaymenttermId); 82 resultado.append("new Array(\"inpcPaymenttermId\", \"" + PaymentTerm + "\"),"); 83 FieldProvider [] tdv = null; 84 try { 85 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_BPartner_Location_ID", "", "C_BPartner Location - Bill To", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0); 86 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, ""); 87 tdv = comboTableData.select(false); 88 comboTableData = null; 89 } catch (Exception ex) { 90 throw new ServletException(ex); 91 } 92 93 resultado.append("new Array(\"inpcBpartnerLocationId\", "); 94 if (tdv!=null && tdv.length>0) { 95 resultado.append("new Array("); 96 for (int i=0;i<tdv.length;i++) { 97 resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strLocation)?"true":"false") + "\")"); 98 if (i<tdv.length-1) resultado.append(",\n"); 99 } 100 resultado.append("\n)"); 101 } else resultado.append("null"); 102 resultado.append("\n),"); 103 resultado.append("new Array(\"inpsalesrepId\", "); 104 FieldProvider [] tld = null; 105 try { 106 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "AD_User SalesRep", "", Utility.getContext(this, vars, "#User_Org", "SEInvoiceBPartner"), Utility.getContext(this, vars, "#User_Client", "SEInvoiceBPartner"), 0); 107 Utility.fillSQLParameters(this, vars, null, comboTableData, "SEInvoiceBPartner", ""); 108 tld = comboTableData.select(false); 109 comboTableData = null; 110 } catch (Exception ex) { 111 throw new ServletException(ex); 112 } 113 114 if (tld!=null && tld.length>0) { 115 resultado.append("new Array("); 116 for (int i=0;i<tld.length;i++) { 117 resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strUserRep)?"true":"false") + "\")"); 118 if (i<tld.length-1) resultado.append(",\n"); 119 } 120 resultado.append("\n)"); 121 } else resultado.append("null"); 122 resultado.append("\n),"); 123 resultado.append("new Array(\"inpcProjectId\", \"\"),"); 124 resultado.append("new Array(\"inpcProjectId_R\", \"\"),"); 125 try { 126 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); 127 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, ""); 128 tdv = comboTableData.select(false); 129 comboTableData = null; 130 } catch (Exception ex) { 131 throw new ServletException(ex); 132 } 133 134 resultado.append("new Array(\"inpcBpartnerContactId\", "); 135 if (tdv!=null && tdv.length>0) { 136 resultado.append("new Array("); 137 for (int i=0;i<tdv.length;i++) { 138 resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strContact)?"true":"false") + "\")"); 139 if (i<tdv.length-1) resultado.append(",\n"); 140 } 141 resultado.append("\n)"); 142 } else resultado.append("null"); 143 resultado.append("\n),"); 144 145 146 147 try { 148 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); 149 Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, ""); 150 tdv = comboTableData.select(false); 151 comboTableData = null; 152 } catch (Exception ex) { 153 throw new ServletException(ex); 154 } 155 156 resultado.append("new Array(\"inpadUserId\", "); 157 if (tdv!=null && tdv.length>0) { 158 resultado.append("new Array("); 159 for (int i=0;i<tdv.length;i++) { 160 resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strContact)?"true":"false") + "\")"); 161 if (i<tdv.length-1) resultado.append(",\n"); 162 } 163 resultado.append("\n)"); 164 } else resultado.append("null"); 165 resultado.append("\n),"); 166 167 168 169 170 resultado.append("new Array(\"inpdescription\", \"" + FormatUtilities.replaceJS(data[0].soDescription) + "\"),"); 171 resultado.append("new Array(\"inpisdiscountprinted\", \"" + data[0].isdiscountprinted + "\")"); 172 173 resultado.append(");"); 174 } 175 xmlDocument.setParameter("array", resultado.toString()); 176 xmlDocument.setParameter("frameName", "frameAplicacion"); 177 response.setContentType("text/html; charset=UTF-8"); 178 PrintWriter out = response.getWriter(); 179 out.println(xmlDocument.print()); 180 out.close(); 181 } 182 } 183 | Popular Tags |