KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_callouts > SE_Invoice_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_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 JavaDoc strChanged = vars.getStringParameter("inpLastFieldChanged");
44       if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged);
45       String JavaDoc strBPartner = vars.getStringParameter("inpcBpartnerId");
46       String JavaDoc strDocType = vars.getStringParameter("inpcDoctypetargetId");
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, 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 JavaDoc strBPartner, String JavaDoc strDocType, 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     
66     SEOrderBPartnerData[] data = SEOrderBPartnerData.select(this, strBPartner);
67     String JavaDoc strUserRep;
68     String JavaDoc DocBaseType = SEInvoiceBPartnerData.docBaseType(this, strDocType);
69     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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       /*if (data[0].creditavailable.equals("") || Double.valueOf(data[0].creditavailable).doubleValue() < 0) resultado.append("new Array(\"MESSAGE\", \"" + Utility.messageBD(this, "CreditLimitOver", vars.getLanguage()) + data[0].creditavailable + "\"),");*/
169       /*resultado.append("new Array(\"inpporeference\", \"" + data[0].poreference + "\"),");*/
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