KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_callouts > SE_Expense_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 java.io.*;
25 import javax.servlet.*;
26 import javax.servlet.http.*;
27
28 import org.openbravo.erpCommon.utility.DateTimeData;
29 import java.math.BigDecimal JavaDoc;
30
31
32 public class SE_Expense_Product 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 strDateexpense = vars.getStringParameter("inpdateexpense", DateTimeData.today(this));
44       String JavaDoc strmProductId = vars.getStringParameter("inpmProductId");
45       //String strUOM = vars.getStringParameter("inpmProductId_UOM");
46
String JavaDoc strsTimeexpenseId = vars.getStringParameter("inpsTimeexpenseId");
47       String JavaDoc strqty = vars.getStringParameter("inpqty");
48       String JavaDoc strChanged = vars.getStringParameter("inpLastFieldChanged");
49       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
50       
51       try {
52         printPage(response, vars, strDateexpense, strmProductId, strsTimeexpenseId, strqty, strChanged, strTabId);
53       } catch (ServletException ex) {
54         pageErrorCallOut(response);
55       }
56     } else pageError(response);
57   }
58
59   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strDateexpense, String JavaDoc strmProductId, String JavaDoc strsTimeexpenseId, String JavaDoc strqty, String JavaDoc strChanged, String JavaDoc strTabId) throws IOException, ServletException {
60     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
61     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
62     String JavaDoc strmPricelistId = SEExpenseProductData.priceList(this, strsTimeexpenseId);
63     SEExpenseProductData[] data = SEExpenseProductData.select(this, strmProductId, strmPricelistId);
64     String JavaDoc strUOM = SEExpenseProductData.selectUOM(this, strmProductId);
65     boolean noPrice = true;
66     String JavaDoc priceActual = "";
67     String JavaDoc CCurrencyID = "";
68     BigDecimal JavaDoc Qty = new BigDecimal JavaDoc(strqty);
69     BigDecimal JavaDoc Amount = null;
70     for (int i=0;data!=null && i<data.length && noPrice;i++){
71       if (data[i].validfrom == null || data[i].validfrom.equals("") || !DateTimeData.compare(this, strDateexpense, data[i].validfrom).equals("-1")){
72         noPrice = false;
73         // Price
74
priceActual = data[i].pricestd;
75         if (priceActual.equals(""))
76         priceActual = data[i].pricelist;
77         if (priceActual.equals(""))
78         priceActual = data[i].pricelimit;
79         // Currency
80
CCurrencyID = data[i].cCurrencyId;
81       }
82     }
83     if (noPrice){
84       data = SEExpenseProductData.selectBasePriceList(this, strmProductId, strmPricelistId);
85       for (int i=0;data!=null && i<data.length && noPrice;i++){
86         if (data[i].validfrom == null || data[i].validfrom.equals("") || !DateTimeData.compare(this, strDateexpense, data[i].validfrom).equals("-1")){
87           noPrice = false;
88           // Price
89
priceActual = data[i].pricestd;
90           if (priceActual.equals(""))
91           priceActual = data[i].pricelist;
92           if (priceActual.equals(""))
93           priceActual = data[i].pricelimit;
94           // Currency
95
CCurrencyID = data[i].cCurrencyId;
96         }
97       }
98     }
99     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
100     resultado.append("var calloutName='SE_Expense_Product';\n\n");
101     resultado.append("var respuesta = new Array(");
102     resultado.append("new Array(\"inpcUomId\", " + (strUOM.equals("")?"\"\"":strUOM) + ")\n");
103     if (!priceActual.equals("") && !CCurrencyID.equals("")) {
104       if (!priceActual.equals("")) Amount = new BigDecimal JavaDoc(priceActual);
105       else Amount = new BigDecimal JavaDoc("0.0");
106       priceActual = Amount.multiply(Qty).toString();
107       resultado.append(", new Array(\"inpexpenseamt\", \"" + priceActual + "\")");
108       if (strChanged.equals("inpmProductId"))resultado.append(",new Array(\"inpcCurrencyId\", \"" + CCurrencyID + "\")");
109     }
110     
111     resultado.append(");");
112     xmlDocument.setParameter("array", resultado.toString());
113     xmlDocument.setParameter("frameName", "frameAplicacion");
114     response.setContentType("text/html; charset=UTF-8");
115     PrintWriter out = response.getWriter();
116     out.println(xmlDocument.print());
117     out.close();
118   }
119 }
120
Popular Tags