KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_callouts > SE_Project_BPartner


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_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_Project_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 JavaDoc strChanged = vars.getStringParameter("inpLastFieldChanged");
44       if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged);
45       String JavaDoc strBPartner = vars.getStringParameter("inpcBpartnerId");
46       String JavaDoc strLocation = vars.getStringParameter("inpcBpartnerId_LOC");
47       String JavaDoc strContact = vars.getStringParameter("inpcBpartnerId_CON");
48       String JavaDoc strWindowId = vars.getStringParameter("inpwindowId");
49       String JavaDoc strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
50       
51       try {
52         printPage(response, vars, strBPartner, strIsSOTrx, strWindowId, strLocation, strContact);
53       } catch (ServletException ex) {
54         pageErrorCallOut(response);
55       }
56     } else pageError(response);
57   }
58
59   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strBPartner, String JavaDoc strIsSOTrx, String JavaDoc strWindowId, String JavaDoc strLocation, String JavaDoc strContact) throws IOException, ServletException {
60     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
61     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
62     String JavaDoc strPaymentrule, strPaymentterm, strPricelist;
63     strPaymentrule = strPaymentterm = strPricelist = "";
64     SEOrderBPartnerData[] data = SEOrderBPartnerData.select(this, strBPartner);
65     if (data!=null && data.length>0) {
66       strPaymentrule = (strIsSOTrx.equals("Y")?data[0].paymentrule: data[0].paymentrulepo);
67       strPaymentterm = (strIsSOTrx.equals("Y")?data[0].cPaymenttermId: data[0].poPaymenttermId);
68       strPricelist = (strIsSOTrx.equals("Y")?data[0].mPricelistId: data[0].poPricelistId);
69     }
70     
71     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
72     resultado.append("var calloutName='SE_Project_BPartner';\n\n");
73     resultado.append("var respuesta = new Array(");
74       FieldProvider [] tdv = null;
75       try {
76         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_PriceList_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0);
77         Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
78         tdv = comboTableData.select(false);
79         comboTableData = null;
80       } catch (Exception JavaDoc ex) {
81         throw new ServletException(ex);
82       }
83       
84
85       try {
86         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);
87         Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
88         tdv = comboTableData.select(false);
89         comboTableData = null;
90       } catch (Exception JavaDoc ex) {
91         throw new ServletException(ex);
92       }
93
94     resultado.append("new Array(\"inpcBpartnerLocationId\", ");
95     if (tdv!=null && tdv.length>0) {
96       resultado.append("new Array(");
97       for (int i=0;i<tdv.length;i++) {
98         resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strLocation)?"true":"false") + "\")");
99         if (i<tdv.length-1) resultado.append(",\n");
100       }
101       resultado.append("\n)");
102     } else resultado.append("null");
103     resultado.append("\n),");
104       try {
105         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);
106         Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
107         tdv = comboTableData.select(false);
108         comboTableData = null;
109       } catch (Exception JavaDoc ex) {
110         throw new ServletException(ex);
111       }
112
113     resultado.append("new Array(\"inpadUserId\", ");
114     if (tdv!=null && tdv.length>0) {
115       resultado.append("new Array(");
116       for (int i=0;i<tdv.length;i++) {
117         resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strContact)?"true":"false") + "\")");
118         if (i<tdv.length-1) resultado.append(",\n");
119       }
120       resultado.append("\n)");
121     } else resultado.append("null");
122     resultado.append("\n),");
123     FieldProvider [] tlv = null;
124       try {
125         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "C_BPartner Location", "C_BPartner Location - Bill To", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0);
126         Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
127         tlv = comboTableData.select(false);
128         comboTableData = null;
129       } catch (Exception JavaDoc ex) {
130         throw new ServletException(ex);
131       }
132
133     resultado.append("new Array(\"inpbilltoId\", ");
134     if (tlv!=null && tlv.length>0) {
135       resultado.append("new Array(");
136       for (int i=0;i<tlv.length;i++) {
137         resultado.append("new Array(\"" + tlv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tlv[i].getField("name")) + "\", \"" + (tlv[i].getField("id").equalsIgnoreCase(strLocation)?"true":"false") + "\")");
138         if (i<tlv.length-1) resultado.append(",\n");
139       }
140       resultado.append("\n)");
141     } else resultado.append("null");
142     resultado.append("\n),");
143     resultado.append("new Array(\"inppaymentrule\", \"" +strPaymentrule + "\"),");
144     resultado.append("new Array(\"inpcPaymenttermId\", \"" +strPaymentterm + "\"),");
145     resultado.append("new Array(\"inpmPricelistId\", \"" + strPricelist + "\")");
146     resultado.append(");");
147     xmlDocument.setParameter("array", resultado.toString());
148     response.setContentType("text/html; charset=UTF-8");
149     PrintWriter out = response.getWriter();
150     out.println(xmlDocument.print());
151     out.close();
152   }
153 }
154
Popular Tags