KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_callouts > SE_Order_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_Order_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 strOrderType = vars.getStringParameter("inpordertype");
47       String JavaDoc strLocation = vars.getStringParameter("inpcBpartnerId_LOC");
48       String JavaDoc strContact = vars.getStringParameter("inpcBpartnerId_CON");
49       String JavaDoc strWindowId = vars.getStringParameter("inpwindowId");
50       String JavaDoc strProjectId = vars.getStringParameter("inpcProjectId");
51       String JavaDoc strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
52       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
53       
54       try {
55         printPage(response, vars, strBPartner, strOrderType, 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 JavaDoc strBPartner, String JavaDoc strOrderType, String JavaDoc strIsSOTrx, String JavaDoc strWindowId, String JavaDoc strLocation, String JavaDoc strContact, String JavaDoc strProjectId, String JavaDoc 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     String JavaDoc strDeliveryRule, strPaymentrule, strPaymentterm, strMwarehouse, strInvoiceRule, strPriceList, strUserRep;
66     strDeliveryRule = strPaymentrule = strPaymentterm = strMwarehouse = strInvoiceRule = strPriceList = strUserRep = "";
67     SEOrderBPartnerData[] data = SEOrderBPartnerData.select(this, strBPartner);
68     if (data!=null && data.length>0) {
69       strDeliveryRule = data[0].deliveryrule;
70       strUserRep = SEOrderBPartnerData.userIdSalesRep(this, data[0].salesrepId);
71       strPaymentrule = (strIsSOTrx.equals("Y")?data[0].paymentrule: data[0].paymentrulepo);
72       strPaymentterm = (strIsSOTrx.equals("Y")?data[0].cPaymenttermId: data[0].poPaymenttermId);
73       strInvoiceRule = data[0].invoicerule;
74       strPriceList = (strIsSOTrx.equals("Y")?data[0].mPricelistId: data[0].poPricelistId);
75     }
76     strMwarehouse = SEOrderBPartnerData.mWarehouse(this, strBPartner);
77
78     if (strMwarehouse.equals("")) strMwarehouse = vars.getWarehouse();
79
80     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
81     resultado.append("var calloutName='SE_Order_BPartner';\n\n");
82     resultado.append("var respuesta = new Array(");
83     
84     resultado.append("new Array(\"inpmPricelistId\", \"" + (strPriceList.equals("")? Utility.getContext(this, vars, "#M_PriceList_ID", strWindowId): strPriceList) + "\"),");
85     FieldProvider [] tdv = null;
86     try {
87       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);
88       Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
89       tdv = comboTableData.select(false);
90       comboTableData = null;
91     } catch (Exception JavaDoc ex) {
92       throw new ServletException(ex);
93     }
94
95     resultado.append("new Array(\"inpcBpartnerLocationId\", ");
96     if (tdv!=null && tdv.length>0) {
97       resultado.append("new Array(");
98       for (int i=0;i<tdv.length;i++) {
99         resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strLocation)?"true":"false") + "\")");
100         if (i<tdv.length-1) resultado.append(",\n");
101       }
102       resultado.append("\n)");
103     } else resultado.append("null");
104     resultado.append("\n),");
105     FieldProvider [] td = null;
106     try {
107       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Warehouse_ID", "", "", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0);
108       Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
109       td = comboTableData.select(false);
110       comboTableData = null;
111     } catch (Exception JavaDoc ex) {
112       throw new ServletException(ex);
113     }
114
115
116     resultado.append("new Array(\"inpmWarehouseId\", ");
117     if (td!=null && td.length>0) {
118       resultado.append("new Array(");
119       for (int i=0;i<td.length;i++) {
120         resultado.append("new Array(\"" + td[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(td[i].getField("name")) + "\", \"" + (td[i].getField("id").equalsIgnoreCase(strMwarehouse)?"true":"false") + "\")");
121         if (i<td.length-1) resultado.append(",\n");
122       }
123       resultado.append("\n)");
124     } else resultado.append("null");
125     resultado.append("\n),");
126     resultado.append("new Array(\"inpsalesrepId\", ");
127     FieldProvider [] tld = null;
128     try {
129       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "AD_User SalesRep", "", Utility.getContext(this, vars, "#User_Org", "SEOrderBPartner"), Utility.getContext(this, vars, "#User_Client", "SEOrderBPartner"), 0);
130       Utility.fillSQLParameters(this, vars, null, comboTableData, "SEOrderBPartner", "");
131       tld = comboTableData.select(false);
132       comboTableData = null;
133     } catch (Exception JavaDoc ex) {
134       throw new ServletException(ex);
135     }
136
137
138       if (tld!=null && tld.length>0) {
139         resultado.append("new Array(");
140         for (int i=0;i<tld.length;i++) {
141           resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strUserRep)?"true":"false") + "\")");
142           if (i<tld.length-1) resultado.append(",\n");
143         }
144         resultado.append("\n)");
145       } else resultado.append("null");
146       resultado.append("\n),");
147       FieldProvider [] l = null;
148       try {
149         ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "C_Order InvoiceRule", "", Utility.getContext(this, vars, "#User_Org", "SEOrderBPartner"), Utility.getContext(this, vars, "#User_Client", "SEOrderBPartner"), 0);
150         Utility.fillSQLParameters(this, vars, null, comboTableData, "SEOrderBPartner", "");
151         l = comboTableData.select(false);
152         comboTableData = null;
153       } catch (Exception JavaDoc ex) {
154         throw new ServletException(ex);
155       }
156
157
158       resultado.append("new Array(\"inpinvoicerule\", ");
159     if (l!=null && l.length>0) {
160       resultado.append("new Array(");
161       for (int i=0;i<l.length;i++) {
162         resultado.append("new Array(\"" + l[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(l[i].getField("name")) + "\", \"" + (l[i].getField("id").equalsIgnoreCase(strInvoiceRule)?"true":"false") + "\")");
163         if (i<l.length-1) resultado.append(",\n");
164       }
165       resultado.append("\n)");
166     } else resultado.append("null");
167     resultado.append("\n),");
168     resultado.append("new Array(\"inpcProjectId\", \"\"),");
169     resultado.append("new Array(\"inpcProjectId_R\", \"\"),");
170     FieldProvider [] tlv = null;
171     try {
172       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);
173       Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
174       tlv = comboTableData.select(false);
175       comboTableData = null;
176     } catch (Exception JavaDoc ex) {
177       throw new ServletException(ex);
178     }
179
180     resultado.append("new Array(\"inpbilltoId\", ");
181     if (tlv!=null && tlv.length>0) {
182       resultado.append("new Array(");
183       for (int i=0;i<tlv.length;i++) {
184         resultado.append("new Array(\"" + tlv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tlv[i].getField("name")) + "\", \"" + (tlv[i].getField("id").equalsIgnoreCase(strLocation)?"true":"false") + "\")");
185         if (i<tlv.length-1) resultado.append(",\n");
186       }
187       resultado.append("\n)");
188     } else resultado.append("null");
189     resultado.append("\n),");
190     resultado.append("new Array(\"inppaymentrule\", \"" +strPaymentrule + "\"),");
191     resultado.append("new Array(\"inpcPaymenttermId\", \"" + (strPaymentterm.equals("")?SEOrderBPartnerData.selectPaymentTerm(this, Utility.getContext(this, vars, "#User_Client", strWindowId)):strPaymentterm) + "\"),");
192     resultado.append("new Array(\"inpdeliveryrule\", ");
193     try {
194       ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "C_Order DeliveryRule", "", Utility.getContext(this, vars, "#User_Org", "SEOrderBPartner"), Utility.getContext(this, vars, "#User_Client", "SEOrderBPartner"), 0);
195       Utility.fillSQLParameters(this, vars, null, comboTableData, "SEOrderBPartner", "");
196       l = comboTableData.select(false);
197       comboTableData = null;
198     } catch (Exception JavaDoc ex) {
199       throw new ServletException(ex);
200     }
201
202     if (strIsSOTrx.equals("N")) {
203       resultado.append("\"").append((strDeliveryRule.equals("")?((l!=null && l.length>0)?l[0].getField("id"):"null"):strDeliveryRule)).append("\"");
204     } else {
205       if (l!=null && l.length>0) {
206         resultado.append("new Array(");
207         for (int i=0;i<l.length;i++) {
208           resultado.append("new Array(\"" + l[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(l[i].getField("name")) + "\", \"" + (l[i].getField("id").equalsIgnoreCase(strDeliveryRule)?"true":"false") + "\")");
209           if (i<l.length-1) resultado.append(",\n");
210         }
211         resultado.append("\n)");
212       } else resultado.append("null");
213     }
214     resultado.append("\n),");
215     try {
216       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);
217       Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
218       tdv = comboTableData.select(false);
219       comboTableData = null;
220     } catch (Exception JavaDoc ex) {
221       throw new ServletException(ex);
222     }
223
224     resultado.append("new Array(\"inpadUserId\", ");
225     if (tdv!=null && tdv.length>0) {
226       resultado.append("new Array(");
227       for (int i=0;i<tdv.length;i++) {
228         resultado.append("new Array(\"" + tdv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tdv[i].getField("name")) + "\", \"" + (tdv[i].getField("id").equalsIgnoreCase(strContact)?"true":"false") + "\")");
229         if (i<tdv.length-1) resultado.append(",\n");
230       }
231       resultado.append("\n)");
232     } else resultado.append("null");
233     resultado.append("\n)");
234
235     resultado.append(");");
236     xmlDocument.setParameter("array", resultado.toString());
237     xmlDocument.setParameter("frameName", "frameAplicacion");
238     response.setContentType("text/html; charset=UTF-8");
239     PrintWriter out = response.getWriter();
240     out.println(xmlDocument.print());
241     out.close();
242   }
243 }
244
Popular Tags