KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > acct > DocTax


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.acct;
15
16 import java.math.*;
17 import java.sql.*;
18
19 import org.compiere.util.*;
20 import org.compiere.model.*;
21
22 /**
23  * Document Tax Line
24  *
25  * @author Jorg Janke
26  * @version $Id: DocTax.java,v 1.5 2002/09/03 05:15:59 jjanke Exp $
27  */

28 public final class DocTax
29 {
30     /**
31      * Create Tax
32      * @param C_Tax_ID tax
33      * @param name name
34      * @param rate rate
35      * @param taxBaseAmt tax base amount
36      * @param amount amount
37      */

38     public DocTax (int C_Tax_ID, String JavaDoc name, BigDecimal rate, BigDecimal taxBaseAmt, BigDecimal amount)
39     {
40         m_C_Tax_ID = C_Tax_ID;
41         m_name = name;
42         m_rate = rate;
43         m_amount = amount;
44     } // DocTax
45

46     /** Tax ID */
47     private int m_C_Tax_ID = 0;
48     /** Amount */
49     private BigDecimal m_amount = null;
50     /** Tax Rate */
51     private BigDecimal m_rate = null;
52     /** Name */
53     private String JavaDoc m_name = null;
54     /** Base Tax Amt */
55     private BigDecimal m_taxBaseAmt = null;
56
57
58     /** Tax Due Acct */
59     public static final int ACCTTYPE_TaxDue = 0;
60     /** Tax Liability */
61     public static final int ACCTTYPE_TaxLiability = 1;
62     /** Tax Credit */
63     public static final int ACCTTYPE_TaxCredit = 2;
64     /** Tax Receivables */
65     public static final int ACCTTYPE_TaxReceivables = 3;
66     /** Tax Expense */
67     public static final int ACCTTYPE_TaxExpense = 4;
68
69     /**
70      * Get Account
71      * @param AcctType see ACCTTYPE_*
72      * @param as account schema
73      * @return Account
74      */

75     public Account getAccount (int AcctType, AcctSchema as)
76     {
77         if (AcctType < 0 || AcctType > 4)
78             return null;
79         //
80
String JavaDoc sql = "SELECT T_Due_Acct, T_Liability_Acct, T_Credit_Acct, T_Receivables_Acct, T_Expense_Acct "
81             + "FROM C_Tax_Acct WHERE C_Tax_ID=? AND C_AcctSchema_ID=?";
82         int validCombination_ID = 0;
83         try
84         {
85             PreparedStatement pstmt = DB.prepareStatement(sql);
86             pstmt.setInt(1, m_C_Tax_ID);
87             pstmt.setInt(2, as.getC_AcctSchema_ID());
88             ResultSet rs = pstmt.executeQuery();
89             if (rs.next())
90                 validCombination_ID = rs.getInt(AcctType+1); // 1..5
91
rs.close();
92             pstmt.close();
93         }
94         catch (SQLException e)
95         {
96             Log.error ("Tax.getAccount", e);
97         }
98         if (validCombination_ID == 0)
99             return null;
100         return Account.getAccount(validCombination_ID);
101     } // getAccount
102

103     /**
104      * Get Amount
105      * @return gross amount
106      */

107     public BigDecimal getAmount()
108     {
109         return m_amount;
110     }
111
112     /**
113      * Get Base Amount
114      * @return net amount
115      */

116     public BigDecimal getTaxBaseAmt()
117     {
118         return m_taxBaseAmt;
119     }
120
121     /**
122      * Get Rate
123      * @return tax rate in percent
124      */

125     public BigDecimal getRate()
126     {
127         return m_rate;
128     }
129
130     /**
131      * Get Name of Tax
132      * @return name
133      */

134     public String JavaDoc getName()
135     {
136         return m_name;
137     }
138
139     /**
140      * Get Description (Tax Name and Base Amount)
141      * @return tax anme and base amount
142      */

143     public String JavaDoc getDescription()
144     {
145         return m_name + " " + m_taxBaseAmt.toString();
146     } // getDescription
147

148     /**
149      * Return String representation
150      * @return tax anme and base amount
151      */

152     public String JavaDoc toString()
153     {
154         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Tax=(");
155         sb.append(m_name);
156         sb.append(" Amt=").append(m_amount);
157         sb.append(")");
158         return sb.toString();
159     } // toString
160

161 } // DocTax
162
Popular Tags