KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.math.BigDecimal JavaDoc;
26 import javax.servlet.*;
27 import javax.servlet.http.*;
28
29
30 public class SL_BankStmt_Amount extends HttpSecureAppServlet {
31   
32   static final BigDecimal JavaDoc ZERO = new BigDecimal JavaDoc(0.0);
33
34   public void init (ServletConfig config) {
35     super.init(config);
36     boolHist = false;
37   }
38
39   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
40     VariablesSecureApp vars = new VariablesSecureApp(request);
41     if (vars.commandIn("DEFAULT")) {
42       String JavaDoc strChanged = vars.getStringParameter("inpLastFieldChanged");
43       if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged);
44       String JavaDoc strStmAmount = vars.getStringParameter("inpstmtamt");
45       String JavaDoc strChgAmount = vars.getStringParameter("inpchargeamt");
46       String JavaDoc strTrxAmount = vars.getStringParameter("inptrxamt");
47       String JavaDoc strConvChgAmount = vars.getStringParameter("inpconvertchargeamt");
48       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
49       String JavaDoc strBankStmtLine = vars.getStringParameter("inpcBankstatementlineId");
50       String JavaDoc strCurrencyId = vars.getStringParameter("inpcCurrencyId");
51       String JavaDoc strDP = vars.getStringParameter("inpcDebtPaymentId");
52       
53       try {
54         printPage(response, vars, strChanged, strStmAmount, strTrxAmount, strChgAmount, strTabId, strConvChgAmount, strBankStmtLine, strCurrencyId, strDP);
55       } catch (ServletException ex) {
56         pageErrorCallOut(response);
57       }
58     } else pageError(response);
59   }
60
61   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strChanged, String JavaDoc strStmAmount, String JavaDoc strTrxAmount, String JavaDoc strChgAmount, String JavaDoc strTabId, String JavaDoc strConChgAmount, String JavaDoc strBankStmtLine, String JavaDoc strCurrencyId, String JavaDoc strDP) throws IOException, ServletException {
62     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
63     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
64
65     BigDecimal JavaDoc StmAmount = new BigDecimal JavaDoc(strStmAmount.equals("")?"0":strStmAmount);
66     BigDecimal JavaDoc TrxAmount = new BigDecimal JavaDoc(strTrxAmount.equals("")?"0":strTrxAmount);
67     BigDecimal JavaDoc ChgAmount = new BigDecimal JavaDoc(strChgAmount.equals("")?"0":strChgAmount);
68     BigDecimal JavaDoc ConvChgAmount = new BigDecimal JavaDoc(strConChgAmount.equals("")?"0":strConChgAmount);
69     BigDecimal JavaDoc Aux = ZERO;
70
71     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
72     resultado.append("var calloutName='SL_BankStmt_Amount';\n\n");
73     resultado.append("var respuesta = new Array(");
74     boolean isConversion = false;
75
76     if (!strDP.equals(""))
77       isConversion = SLBankStmtAmountData.isConversion(this,strCurrencyId, strDP).equals("Y");
78
79
80     if (strChanged.equals("inpstmtamt")) {
81       if (isConversion) {
82          if (log4j.isDebugEnabled()) log4j.debug("trx: " + TrxAmount.toString()+"chg"+ChgAmount.toString());
83         //ConvChgAmount = StmAmount.subtract(TrxAmount).subtract(ChgAmount);
84
ConvChgAmount = TrxAmount.subtract(ChgAmount).subtract(StmAmount);
85         resultado.append("new Array(\"inpconvertchargeamt\", \"" + ConvChgAmount.toString() + "\")");
86         resultado.append(");");
87       } else {
88         ChgAmount = StmAmount.subtract(TrxAmount);
89         resultado.append("new Array(\"inpchargeamt\", \"" + ChgAmount.toString() + "\")");
90         resultado.append(");");
91       }
92     }
93     if (strChanged.equals("inpchargeamt")||(strChanged.equals("inpconvertchargeamt"))) {
94       //StmAmount = TrxAmount.add(ChgAmount).add(ConvChgAmount);
95
StmAmount = TrxAmount.subtract(ChgAmount).subtract(ConvChgAmount);
96       resultado.append("new Array(\"inpstmtamt\", \"" + StmAmount.toString() + "\")");
97       resultado.append(");");
98     }
99
100     xmlDocument.setParameter("array", resultado.toString());
101     xmlDocument.setParameter("frameName", "frameAplicacion");
102     response.setContentType("text/html; charset=UTF-8");
103     PrintWriter out = response.getWriter();
104     out.println(xmlDocument.print());
105     out.close();
106   }
107 }
108
Popular Tags