KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_callouts > SL_Order_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 import java.math.BigDecimal JavaDoc;
31
32 import org.openbravo.erpCommon.businessUtility.Tax;
33 import org.openbravo.erpCommon.businessUtility.PAttributeSet;
34 import org.openbravo.erpCommon.businessUtility.PAttributeSetData;
35
36 public class SL_Order_Product extends HttpSecureAppServlet {
37   
38
39   public void init (ServletConfig config) {
40     super.init(config);
41     boolHist = false;
42   }
43
44   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
45     VariablesSecureApp vars = new VariablesSecureApp(request);
46     if (vars.commandIn("DEFAULT")) {
47       String JavaDoc strChanged = vars.getStringParameter("inpLastFieldChanged");
48       if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged);
49       String JavaDoc strUOM = vars.getStringParameter("inpmProductId_UOM");
50       String JavaDoc strPriceList = vars.getStringParameter("inpmProductId_PLIST");
51       String JavaDoc strPriceStd = vars.getStringParameter("inpmProductId_PSTD");
52       String JavaDoc strPriceLimit = vars.getStringParameter("inpmProductId_PLIM");
53       String JavaDoc strCurrency = vars.getStringParameter("inpmProductId_CURR");
54       String JavaDoc strQty = vars.getStringParameter("inpqtyordered");
55
56       String JavaDoc strCBpartnerID = vars.getStringParameter("inpcBpartnerId");
57       String JavaDoc strMProductID = vars.getStringParameter("inpmProductId");
58       String JavaDoc strCBPartnerLocationID = vars.getStringParameter("inpcBpartnerLocationId");
59       String JavaDoc strDateOrdered = vars.getStringParameter("inpdateordered");
60       String JavaDoc strADOrgID = vars.getStringParameter("inpadOrgId");
61       String JavaDoc strMWarehouseID = vars.getStringParameter("inpmWarehouseId");
62       String JavaDoc strCOrderId = vars.getStringParameter("inpcOrderId");
63       String JavaDoc strWindowId = vars.getStringParameter("inpwindowId");
64       String JavaDoc strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
65       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
66       
67       try {
68         printPage(response, vars, strUOM, strPriceList, strPriceStd, strPriceLimit, strCurrency, strMProductID, strCBPartnerLocationID, strDateOrdered, strADOrgID, strMWarehouseID, strCOrderId, strWindowId, strIsSOTrx, strCBpartnerID, strTabId, strQty);
69       } catch (ServletException ex) {
70         pageErrorCallOut(response);
71       }
72     } else pageError(response);
73   }
74
75   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 strCBPartnerLocationID, String JavaDoc strDateOrdered, String JavaDoc strADOrgID, String JavaDoc strMWarehouseID, String JavaDoc strCOrderId, String JavaDoc strWindowId, String JavaDoc strIsSOTrx, String JavaDoc strCBpartnerID, String JavaDoc strTabId, String JavaDoc strQty) throws IOException, ServletException {
76     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
77     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
78     
79     String JavaDoc strLastPriceSO = "";
80     String JavaDoc strPriceActual = "";
81
82     if (!strMProductID.equals("")) {
83       strLastPriceSO = SLOrderProductData.lastPriceSo(this, strCBpartnerID, strMProductID);
84       SLOrderProductData[] dataOrder = SLOrderProductData.select(this, strCOrderId);
85       
86       if (log4j.isDebugEnabled()) log4j.debug("get Offers date: "+dataOrder[0].dateordered+" partner:" +dataOrder[0].cBpartnerId+" prod:"+ strMProductID +" std:"+strPriceStd.replace("\"", ""));
87       strPriceActual = SLOrderProductData.getOffersPrice(this, dataOrder[0].dateordered, dataOrder[0].cBpartnerId, strMProductID, (strPriceStd.equals("undefined")?"0":strPriceStd.replace("\"", "")), strQty, dataOrder[0].mPricelistId, dataOrder[0].id);
88       if (log4j.isDebugEnabled()) log4j.debug("get Offers price:"+strPriceActual);
89
90       dataOrder = null;
91     } else {
92       strUOM = strPriceList = strPriceLimit = strPriceStd = "";
93     }
94     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
95     
96     if (strPriceActual.equals("")) strPriceActual = strPriceStd;
97
98     //Discount...
99
if (strPriceList.startsWith("\"")) strPriceList = strPriceList.substring(1, strPriceList.length() - 1);
100     if (strPriceStd.startsWith("\"")) strPriceStd = strPriceStd.substring(1, strPriceStd.length() - 1);
101     BigDecimal JavaDoc priceList = (strPriceList.equals("")?new BigDecimal JavaDoc(0.0):new BigDecimal JavaDoc(strPriceList));
102     BigDecimal JavaDoc priceStd = (strPriceStd.equals("")?new BigDecimal JavaDoc(0.0):new BigDecimal JavaDoc(strPriceStd));
103     BigDecimal JavaDoc discount = new BigDecimal JavaDoc(0.0);
104     if (priceList.doubleValue() != discount.doubleValue()) {
105       discount = new BigDecimal JavaDoc ((priceList.doubleValue()-priceStd.doubleValue()) / priceList.doubleValue() * 100.0).setScale(2, BigDecimal.ROUND_HALF_UP);
106     }
107
108     resultado.append("var calloutName='SL_Order_Product';\n\n");
109     resultado.append("var respuesta = new Array(");
110     resultado.append("new Array(\"inpcUomId\", " + (strUOM.equals("")?"\"\"":strUOM) + "),");
111     resultado.append("new Array(\"inppricelist\", " + (strPriceList.equals("")?"\"0\"":strPriceList) + "),");
112     resultado.append("new Array(\"inppricelimit\", " + (strPriceLimit.equals("")?"\"0\"":strPriceLimit) + "),");
113     resultado.append("new Array(\"inppricestd\", " + (strPriceStd.equals("")?"\"0\"":strPriceStd) + "),");
114     resultado.append("new Array(\"inppriceactual\", " + (strPriceActual.equals("")?"\"0\"":strPriceActual) + "),");
115     resultado.append("new Array(\"inplastpriceso\", \"" + strLastPriceSO + "\"),");
116     resultado.append("new Array(\"inpcCurrencyId\", " + (strCurrency.equals("")?"\"\"":strCurrency) + "),");
117     resultado.append("new Array(\"inpdiscount\", \"" + discount.toString() + "\"),");
118     if (!strMProductID.equals("")) {
119       PAttributeSetData[] dataPAttr = PAttributeSetData.selectProductAttr(this, strMProductID);
120       if (dataPAttr != null && dataPAttr.length>0) {
121         PAttributeSetData[] data2 = PAttributeSetData.select(this, dataPAttr[0].mAttributesetId);
122         if (PAttributeSet.isInstanceAttributeSet(data2)) {
123           resultado.append("new Array(\"inpmAttributesetinstanceId\", \"\"),");
124           resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"\"),");
125         } else {
126           resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + dataPAttr[0].mAttributesetinstanceId + "\"),");
127           resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"" + FormatUtilities.replaceJS(dataPAttr[0].description) + "\"),");
128         }
129       }
130     }
131     String JavaDoc strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strMProductID);
132     resultado.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + "),\n");
133
134     SLOrderTaxData [] data = SLOrderTaxData.select(this, strCOrderId);
135
136     String JavaDoc strCTaxID = Tax.get(this, strMProductID, data[0].dateordered, strADOrgID, strMWarehouseID, (data[0].billtoId.equals("")?strCBPartnerLocationID:data[0].billtoId), strCBPartnerLocationID, data[0].cProjectId, strIsSOTrx.equals("Y"));
137
138     resultado.append("new Array(\"inpcTaxId\", \"" + (strCTaxID.equals("")?"0":strCTaxID) + "\"),\n");
139     resultado.append("new Array(\"inpmProductUomId\", ");
140 // if (strUOM.startsWith("\"")) strUOM=strUOM.substring(1,strUOM.length()-1);
141
// String strmProductUOMId = SLOrderProductData.strMProductUOMID(this,strMProductID,strUOM);
142
if (vars.getLanguage().equals("en_US")) {
143     FieldProvider [] tld = null;
144     try {
145         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);
146         Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", "");
147         tld = comboTableData.select(false);
148         comboTableData = null;
149     } catch (Exception JavaDoc ex) {
150         throw new ServletException(ex);
151     }
152
153       if (tld!=null && tld.length>0) {
154         resultado.append("new Array(");
155         for (int i=0;i<tld.length;i++) {
156           resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (i==0?"true":"false") + "\")");
157           if (i<tld.length-1) resultado.append(",\n");
158         }
159         resultado.append("\n)");
160       } else resultado.append("null");
161       resultado.append("\n),");
162     } else {
163     FieldProvider [] tld = null;
164     try {
165         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);
166         Utility.fillSQLParameters(this, vars, null, comboTableData, "SLOrderProduct", "");
167         tld = comboTableData.select(false);
168         comboTableData = null;
169     } catch (Exception JavaDoc ex) {
170         throw new ServletException(ex);
171     }
172
173       if (tld!=null && tld.length>0) {
174         resultado.append("new Array(");
175         for (int i=0;i<tld.length;i++) {
176           resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (i==0?"true":"false") + "\")");
177           if (i<tld.length-1) resultado.append(",\n");
178         }
179         resultado.append("\n)");
180       } else resultado.append("null");
181       resultado.append("\n),");
182     }
183     resultado.append("new Array(\"EXECUTE\", \"displayLogic();\"),\n");
184     //Para posicionar el cursor en el campo de cantidad
185
resultado.append("new Array(\"CURSOR_FIELD\", \"inpqtyordered\")\n");
186     if (!strHasSecondaryUOM.equals("0")) resultado.append(", new Array(\"CURSOR_FIELD\", \"inpquantityorder\")\n");
187
188     resultado.append(");");
189     xmlDocument.setParameter("array", resultado.toString());
190     xmlDocument.setParameter("frameName", "frameAplicacion");
191     response.setContentType("text/html; charset=UTF-8");
192     PrintWriter out = response.getWriter();
193     out.println(xmlDocument.print());
194     out.close();
195   }
196 }
197
Popular Tags