KickJava   Java API By Example, From Geeks To Geeks.

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


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.erpCommon.utility.*;
25 import org.openbravo.data.FieldProvider;
26 import org.openbravo.utils.FormatUtilities;
27 import java.io.*;
28 import javax.servlet.*;
29 import javax.servlet.http.*;
30
31 import org.openbravo.erpCommon.businessUtility.Tax;
32 import org.openbravo.erpCommon.businessUtility.PAttributeSet;
33 import org.openbravo.erpCommon.businessUtility.PAttributeSetData;
34
35 public class SL_Invoice_Product extends HttpSecureAppServlet {
36   
37
38   public void init (ServletConfig config) {
39     super.init(config);
40     boolHist = false;
41   }
42
43   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
44     VariablesSecureApp vars = new VariablesSecureApp(request);
45     if (vars.commandIn("DEFAULT")) {
46       String JavaDoc strChanged = vars.getStringParameter("inpLastFieldChanged");
47       if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged);
48       String JavaDoc strUOM = vars.getStringParameter("inpmProductId_UOM");
49       String JavaDoc strPriceList = vars.getStringParameter("inpmProductId_PLIST");
50       String JavaDoc strPriceStd = vars.getStringParameter("inpmProductId_PSTD");
51       String JavaDoc strPriceLimit = vars.getStringParameter("inpmProductId_PLIM");
52       String JavaDoc strCurrency = vars.getStringParameter("inpmProductId_CURR");
53       String JavaDoc strQty = vars.getStringParameter("inpqtyinvoiced");
54
55       String JavaDoc strMProductID = vars.getStringParameter("inpmProductId");
56       String JavaDoc strADOrgID = vars.getStringParameter("inpadOrgId");
57       String JavaDoc strCInvoiceID = vars.getStringParameter("inpcInvoiceId");
58       String JavaDoc strWindowId = vars.getStringParameter("inpwindowId");
59       String JavaDoc strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
60       String JavaDoc strWharehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", strWindowId);
61       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
62       
63       try {
64         printPage(response, vars, strUOM, strPriceList, strPriceStd, strPriceLimit, strCurrency, strMProductID, strADOrgID, strCInvoiceID, strIsSOTrx, strWharehouse, strTabId, strQty);
65       } catch (ServletException ex) {
66         pageErrorCallOut(response);
67       }
68     } else pageError(response);
69   }
70
71   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strUOM, String JavaDoc strPriceList, String JavaDoc strPriceStd, String JavaDoc strPriceLimit, String JavaDoc strCurrency, String JavaDoc strMProductID, String JavaDoc strADOrgID, String JavaDoc strCInvoiceID, String JavaDoc strIsSOTrx, String JavaDoc strWharehouse, String JavaDoc strTabId, String JavaDoc strQty) throws IOException, ServletException {
72     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
73     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
74
75    
76     String JavaDoc strPriceActual="";
77     if (!strMProductID.equals("")) {
78       SLOrderProductData[] dataInvoice = SLOrderProductData.selectInvoice(this, strCInvoiceID);
79       
80       if (log4j.isDebugEnabled()) log4j.debug("get Offers date: "+dataInvoice[0].dateinvoiced+" partner:" +dataInvoice[0].cBpartnerId+" prod:"+ strMProductID +" std:"+strPriceStd.replace("\"", ""));
81       strPriceActual = SLOrderProductData.getOffersPriceInvoice(this, dataInvoice[0].dateinvoiced, dataInvoice[0].cBpartnerId, strMProductID, strPriceStd.replace("\"", ""), strQty, dataInvoice[0].mPricelistId, dataInvoice[0].id);
82       if (log4j.isDebugEnabled()) log4j.debug("get Offers price:"+strPriceActual);
83
84       dataInvoice=null;
85     }
86     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
87
88     if (strPriceActual.equals("")) strPriceActual = strPriceStd;
89     
90     resultado.append("var calloutName='SL_Invoice_Product';\n\n");
91     resultado.append("var respuesta = new Array(");
92     resultado.append("new Array(\"inpcUomId\", " + (strUOM.equals("")?"\"\"":strUOM) + "),");
93     resultado.append("new Array(\"inppricelist\", " + (strPriceList.equals("")?"\"\"":strPriceList) + "),");
94     resultado.append("new Array(\"inppricelimit\", " + (strPriceLimit.equals("")?"\"\"":strPriceLimit) + "),");
95     resultado.append("new Array(\"inppricestd\", " + (strPriceStd.equals("")?"\"\"":strPriceStd) + "),");
96     resultado.append("new Array(\"inppriceactual\", " + (strPriceActual.equals("")?"\"\"":strPriceActual) + "),");
97     PAttributeSetData[] dataPAttr = PAttributeSetData.selectProductAttr(this, strMProductID);
98     if (dataPAttr!=null && dataPAttr.length>0){
99       PAttributeSetData[] data2 = PAttributeSetData.select(this, dataPAttr[0].mAttributesetId);
100       if (PAttributeSet.isInstanceAttributeSet(data2)) {
101         resultado.append("new Array(\"inpmAttributesetinstanceId\", \"\"),");
102         resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"\"),");
103       } else {
104         resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + dataPAttr[0].mAttributesetinstanceId + "\"),");
105         resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"" + FormatUtilities.replaceJS(dataPAttr[0].description) + "\"),");
106       }
107     }
108     String JavaDoc strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strMProductID);
109     resultado.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + "),\n");
110     resultado.append("new Array(\"inpcCurrencyId\", " + (strCurrency.equals("")?"\"\"":strCurrency) + ")");
111
112     SLInvoiceTaxData [] data = SLInvoiceTaxData.select(this, strCInvoiceID);
113     if (data!=null && data.length>0) {
114       String JavaDoc strCTaxID = Tax.get(this, strMProductID, data[0].dateinvoiced, strADOrgID, strWharehouse, data[0].cBpartnerLocationId, data[0].cBpartnerLocationId, data[0].cProjectId, strIsSOTrx.equals("Y"));
115       
116       resultado.append(", new Array(\"inpcTaxId\", \"" + strCTaxID + "\")");
117     }
118
119     resultado.append(", new Array(\"inpmProductUomId\", ");
120     //if (strUOM.startsWith("\"")) strUOM=strUOM.substring(1,strUOM.length()-1);
121
//String strmProductUOMId = SLOrderProductData.strMProductUOMID(this,strMProductID,strUOM);
122

123     FieldProvider [] tld = null;
124     try {
125       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLOrderProduct"), Utility.getContext(this, vars, "#User_Client", "SLOrderProduct"), 0);
126       Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", "");
127       tld = comboTableData.select(false);
128       comboTableData = null;
129     } catch (Exception JavaDoc ex) {
130       throw new ServletException(ex);
131     }
132
133     if (tld!=null && tld.length>0) {
134       resultado.append("new Array(");
135       for (int i=0;i<tld.length;i++) {
136         resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (i==0?"true":"false") + "\")");
137         if (i<tld.length-1) resultado.append(",\n");
138       }
139       resultado.append("\n)");
140     } else resultado.append("null");
141     resultado.append("\n),");
142     resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
143
144
145     resultado.append(");");
146     xmlDocument.setParameter("array", resultado.toString());
147     xmlDocument.setParameter("frameName", "frameAplicacion");
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