KickJava   Java API By Example, From Geeks To Geeks.

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


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.Utility;
25 import java.io.*;
26 import java.math.BigDecimal JavaDoc;
27 import javax.servlet.*;
28 import javax.servlet.http.*;
29
30 import org.openbravo.erpCommon.utility.DateTimeData;
31
32 public class SL_JournalLineAmt extends HttpSecureAppServlet {
33   
34   static final BigDecimal JavaDoc ZERO = new BigDecimal JavaDoc(0.0);
35
36   public void init (ServletConfig config) {
37     super.init(config);
38     boolHist = false;
39   }
40
41   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
42     VariablesSecureApp vars = new VariablesSecureApp(request);
43     if (vars.commandIn("DEFAULT")) {
44       String JavaDoc strChanged = vars.getStringParameter("inpLastFieldChanged");
45       String JavaDoc strWindowId = vars.getStringParameter("inpWindowId");
46       if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged);
47       String JavaDoc strGLJournal= vars.getRequiredStringParameter("inpglJournalId");
48       String JavaDoc strCurrencyRate= vars.getStringParameter("inpcurrencyrate", "1");
49       String JavaDoc strCurrency = vars.getStringParameter("inpcCurrencyId");
50       String JavaDoc strDateAcct = vars.getStringParameter("inpdateacct", DateTimeData.today(this));
51       String JavaDoc strCurrencyRateType = vars.getStringParameter("inpcurrencyratetype", "S");
52       String JavaDoc strAmtSourceDr = vars.getStringParameter("inpamtsourcedr", "0");
53       String JavaDoc strAmtSourceCr = vars.getStringParameter("inpamtsourcecr", "0");
54       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
55       
56       try {
57         printPage(response, vars, strGLJournal, strCurrencyRate, strCurrency, strDateAcct, strCurrencyRateType, strWindowId, strAmtSourceDr, strAmtSourceCr, strTabId);
58       } catch (ServletException ex) {
59         pageErrorCallOut(response);
60       }
61     } else pageError(response);
62   }
63
64   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strGLJournal, String JavaDoc strCurrencyRate, String JavaDoc strCurrency, String JavaDoc strDateAcct, String JavaDoc strCurrencyRateType, String JavaDoc strWindowId, String JavaDoc strAmtSourceDr, String JavaDoc strAmtSourceCr, String JavaDoc strTabId) throws IOException, ServletException {
65     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
66     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
67     String JavaDoc strAcctSchema = Utility.getContext(this, vars, "$C_ACCTSCHEMA_ID", strWindowId);
68     SLJournalLineAmtData[] data = SLJournalLineAmtData.select(this, strAcctSchema);
69     String JavaDoc strPrecision = "2", strTargetCurrencyId="";
70     if (data!=null && data.length>0) {
71       strPrecision = data[0].stdprecision.equals("")?"2":data[0].stdprecision;
72       strTargetCurrencyId = data[0].cCurrencyId.equals("")?"0":data[0].cCurrencyId;
73     }
74     String JavaDoc CurrencyRate = SLJournalLineAmtData.currencyRate(this, strCurrency, strTargetCurrencyId, strDateAcct, strCurrencyRateType, vars.getClient(), vars.getOrg());
75     if (CurrencyRate.equals("")) CurrencyRate = SLJournalLineAmtData.currencyRate2(this, strGLJournal, strCurrency, strCurrencyRateType);
76     int StdPrecision = Integer.valueOf(strPrecision).intValue();
77
78     BigDecimal JavaDoc AmtSourceDr = new BigDecimal JavaDoc(strAmtSourceDr);
79     BigDecimal JavaDoc AmtSourceCr = new BigDecimal JavaDoc(strAmtSourceCr);
80     BigDecimal JavaDoc CurrencyRateValue = new BigDecimal JavaDoc(strCurrencyRate);
81     CurrencyRateValue = CurrencyRateValue.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
82     BigDecimal JavaDoc AmtAcctDr, AmtAcctCr;
83
84     AmtAcctDr = (strAmtSourceDr.equals("")?ZERO:AmtSourceDr.multiply(new BigDecimal JavaDoc(CurrencyRate))).setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
85     AmtAcctCr = (strAmtSourceCr.equals("")?ZERO:AmtSourceCr.multiply(new BigDecimal JavaDoc(CurrencyRate))).setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
86
87     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
88     resultado.append("var calloutName='SL_JournalLineAmt';\n\n");
89     resultado.append("var respuesta = new Array(");
90     resultado.append("new Array(\"inpamtacctdr\", \"" + AmtAcctDr.toString() + "\"),");
91     resultado.append("new Array(\"inpamtacctcr\", \"" + AmtAcctCr.toString() + "\"),");
92     resultado.append("new Array(\"inpcurrencyrate\", \"" + CurrencyRateValue.toString() + "\"),");
93     resultado.append("new Array(\"inpcurrencyratetype\", \"" + strCurrencyRateType + "\")");
94
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