KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_callouts > SL_Requisition_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 java.io.*;
26 import javax.servlet.*;
27 import javax.servlet.http.*;
28 import java.math.BigDecimal JavaDoc;
29
30 public class SL_Requisition_Product extends HttpSecureAppServlet {
31   
32
33   public void init (ServletConfig config) {
34     super.init(config);
35     boolHist = false;
36   }
37
38   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
39     VariablesSecureApp vars = new VariablesSecureApp(request);
40     if (vars.commandIn("DEFAULT")) {
41       String JavaDoc strChanged = vars.getStringParameter("inpLastFieldChanged");
42       if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged);
43       String JavaDoc strQty = vars.getStringParameter("inpqty");
44
45       String JavaDoc strMProductID = vars.getStringParameter("inpmProductId");
46       String JavaDoc strWindowId = vars.getStringParameter("inpwindowId");
47       String JavaDoc strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
48       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
49       
50       try {
51         printPage(response, vars, strMProductID, strWindowId, strIsSOTrx, strTabId, strQty, strChanged);
52       } catch (ServletException ex) {
53         pageErrorCallOut(response);
54       }
55     } else pageError(response);
56   }
57
58   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strMProductID, String JavaDoc strWindowId, String JavaDoc strIsSOTrx, String JavaDoc strTabId, String JavaDoc strQty, String JavaDoc strChanged) throws IOException, ServletException {
59     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
60     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
61     
62     String JavaDoc strPriceActual = "";
63     String JavaDoc strPriceList = vars.getStringParameter("inpmProductId_PLIST");
64     String JavaDoc strPriceStd = vars.getStringParameter("inpmProductId_PSTD");
65     String JavaDoc strPriceLimit = vars.getStringParameter("inpmProductId_PLIM");
66
67     if (strMProductID.equals("")) {
68       strPriceList = strPriceLimit = strPriceStd = "";
69     }
70     if (!strChanged.equalsIgnoreCase("inpmProductId")) {
71       strPriceList = vars.getStringParameter("inppricelist");
72       strPriceStd = vars.getStringParameter("inppricestd");
73       strPriceLimit = vars.getStringParameter("inppricelimit");
74     }
75     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
76     
77     //Discount...
78
if (strPriceList.startsWith("\"")) strPriceList = strPriceList.substring(1, strPriceList.length() - 1);
79     if (strPriceStd.startsWith("\"")) strPriceStd = strPriceStd.substring(1, strPriceStd.length() - 1);
80     BigDecimal JavaDoc priceList = (strPriceList.equals("")?new BigDecimal JavaDoc(0.0):new BigDecimal JavaDoc(strPriceList));
81     BigDecimal JavaDoc priceStd = (strPriceStd.equals("")?new BigDecimal JavaDoc(0.0):new BigDecimal JavaDoc(strPriceStd));
82     BigDecimal JavaDoc qty = (strQty.equals("")?new BigDecimal JavaDoc(0.0):new BigDecimal JavaDoc(strQty));
83     BigDecimal JavaDoc lineNet = new BigDecimal JavaDoc(0.0);
84     lineNet = new BigDecimal JavaDoc (priceStd.doubleValue() * qty.doubleValue()).setScale(2, BigDecimal.ROUND_HALF_UP);
85
86     resultado.append("var calloutName='SL_Requisition_Product';\n\n");
87     resultado.append("var respuesta = new Array(");
88     resultado.append("new Array(\"inppricelist\", " + (strPriceList.equals("")?"\"0\"":strPriceList) + "),");
89     resultado.append("new Array(\"inppricelimit\", " + (strPriceLimit.equals("")?"\"0\"":strPriceLimit) + "),");
90     resultado.append("new Array(\"inppricestd\", " + (strPriceStd.equals("")?"\"0\"":strPriceStd) + "),");
91     resultado.append("new Array(\"inplinenetamt\", " + lineNet.toString() + "),");
92     resultado.append("new Array(\"EXECUTE\", \"displayLogic();\"),\n");
93     //To set the cursor focus in the amount field
94
resultado.append("new Array(\"CURSOR_FIELD\", \"inpqty\")\n");
95     resultado.append(");");
96     xmlDocument.setParameter("array", resultado.toString());
97     xmlDocument.setParameter("frameName", "frameAplicacion");
98     response.setContentType("text/html; charset=UTF-8");
99     PrintWriter out = response.getWriter();
100     out.println(xmlDocument.print());
101     out.close();
102   }
103 }
104
Popular Tags