KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Cash Journal Line
24  *
25  * @author Jorg Janke
26  * @version $Id: DocLine_Cash.java,v 1.6 2003/04/30 06:26:09 jjanke Exp $
27  */

28 public class DocLine_Cash extends DocLine
29 {
30     /**
31      * Cosntructor
32      * @param DocumentType document type
33      * @param TrxHeader_ID trx header
34      * @param TrxLine_ID trx line
35      */

36     public DocLine_Cash (String JavaDoc DocumentType, int TrxHeader_ID, int TrxLine_ID)
37     {
38         super (DocumentType, TrxHeader_ID, TrxLine_ID);
39     } // DocLine_Cash
40

41     /** Cash Type */
42     private String JavaDoc m_CashType = "";
43
44     // AD_Reference_ID=217
45
public static final String JavaDoc CASHTYPE_CHARGE = "C";
46     public static final String JavaDoc CASHTYPE_DIFFERENCE = "D";
47     public static final String JavaDoc CASHTYPE_EXPENSE = "E";
48     public static final String JavaDoc CASHTYPE_INVOICE = "I";
49     public static final String JavaDoc CASHTYPE_RECEIPT = "R";
50     public static final String JavaDoc CASHTYPE_TRANSFER = "T";
51
52     // References
53
private int m_C_BankAccount_ID = 0;
54     private int m_C_Invoice_ID = 0;
55     private int m_C_BPartner_ID = 0;
56     //
57
private int m_C_Currency_ID = -1;
58     private int m_AD_Org_ID = -1;
59
60     // Amounts
61
private BigDecimal m_Amount = Env.ZERO;
62     private BigDecimal m_DiscountAmt = Env.ZERO;
63     private BigDecimal m_WriteOffAmt = Env.ZERO;
64
65     /**
66      * Set Cash Type
67      * @param CashType see CASHTYPE_*
68      */

69     public void setCashType(String JavaDoc CashType)
70     {
71         if (CashType != null)
72             m_CashType = CashType;
73     } // setCashType
74

75     /**
76      * Get Cash Type
77      * @return cash type
78      */

79     public String JavaDoc getCashType()
80     {
81         return m_CashType;
82     } // getCashType
83

84     /**
85      * Set References
86      * @param C_BankAccount_ID bank account
87      * @param C_Invoice_ID invoice
88      */

89     public void setReference (int C_BankAccount_ID, int C_Invoice_ID)
90     {
91         m_C_BankAccount_ID = C_BankAccount_ID;
92         m_C_Invoice_ID = C_Invoice_ID;
93         setReferenceInfo();
94     } // setReference
95

96     /**
97      * Get Bank Account
98      * @return Bank Account
99      */

100     public int getC_BankAccount_ID()
101     {
102         return m_C_BankAccount_ID;
103     } // getC_BankAccount_ID
104

105     /**
106      * Get Invoice
107      * @return C_Invoice_ID
108      */

109     public int getC_Invoice_ID()
110     {
111         return m_C_Invoice_ID;
112     } // getC_Invoice_ID
113

114     /**
115      * Set Amounts
116      * @param Amount payment amount
117      * @param DiscountAmt discount
118      * @param WriteOffAmt wrire-off
119      */

120     public void setAmount(BigDecimal Amount, BigDecimal DiscountAmt, BigDecimal WriteOffAmt)
121     {
122         if (Amount != null)
123             m_Amount = Amount;
124         if (DiscountAmt != null)
125             m_DiscountAmt = DiscountAmt;
126         if (WriteOffAmt != null)
127             m_WriteOffAmt = WriteOffAmt;
128         //
129
setAmount(Amount);
130     } // setAmount
131

132     /**
133      * Get Amount
134      * @return Payment Amount
135      */

136     public BigDecimal getAmount()
137     {
138         return m_Amount;
139     }
140     /**
141      * Get Discount
142      * @return Discount Amount
143      */

144     public BigDecimal getDiscountAmt()
145     {
146         return m_DiscountAmt;
147     }
148     /**
149      * Get WriteOff
150      * @return Write-Off Amount
151      */

152     public BigDecimal getWriteOffAmt()
153     {
154         return m_WriteOffAmt;
155     }
156
157     /**
158      * Get Currency of invoice or bank
159      * @return C_Currency_ID
160      */

161     public int getC_Currency_ID()
162     {
163         if (m_C_BankAccount_ID == 0 && m_C_Invoice_ID == 0)
164             return super.getC_Currency_ID();
165
166         if (m_C_Currency_ID == -1)
167             setReferenceInfo();
168         return m_C_Currency_ID;
169     } // getC_Currency_ID
170

171     /**
172      * Get Organization of invoice or bank
173      * @return AD_Org_ID
174      */

175     public int getAD_Org_ID()
176     {
177         if (m_C_BankAccount_ID == 0 && m_C_Invoice_ID == 0)
178             return super.getAD_Org_ID();
179
180         if (m_AD_Org_ID == -1)
181             setReferenceInfo();
182         return m_AD_Org_ID;
183     } // getAD_Org_ID
184

185     /**
186      * Get BPartner of Invoice
187      * @return C_BPartner_ID
188      */

189     public int getC_BPartner_ID()
190     {
191         if (m_C_Invoice_ID == 0)
192             return super.getC_BPartner_ID();
193
194         if (m_C_BPartner_ID == -1)
195             setReferenceInfo();
196         return m_C_BPartner_ID;
197     } // getC_BPartner_ID
198

199     /**
200      * Get Reference Info
201      * - Organization
202      * - Currency
203      * - BPartner
204      */

205     private void setReferenceInfo()
206     {
207         m_C_Currency_ID = 0;
208         m_AD_Org_ID = 0;
209         m_C_BPartner_ID = 0;
210
211         String JavaDoc sql = null;
212         int parameter = 0;
213         // Bank Account Info
214
if (m_C_BankAccount_ID != 0)
215         {
216             sql = "SELECT AD_Org_ID, C_Currency_ID, 0 FROM C_BankAccount WHERE C_BankAccount_ID=?";
217             parameter = m_C_BankAccount_ID;
218         }
219         else if (m_C_Invoice_ID != 0)
220         {
221             sql = "SELECT AD_Org_ID, C_Currency_ID, C_BPartner_ID FROM C_Invoice WHERE C_Invoice_ID=?";
222             parameter = m_C_Invoice_ID;
223         }
224         else
225             return;
226
227         try
228         {
229             PreparedStatement pstmt = DB.prepareStatement(sql);
230             pstmt.setInt(1, parameter);
231             ResultSet rs = pstmt.executeQuery();
232             if (rs.next())
233             {
234                 m_AD_Org_ID = rs.getInt(1);
235                 m_C_Currency_ID = rs.getInt(2);
236                 m_C_BPartner_ID = rs.getInt(3);
237             }
238             rs.close();
239             pstmt.close();
240         }
241         catch (SQLException e)
242         {
243             log.error("setReferenceInfo", e);
244         }
245     } // setReferenceInfo
246

247 } // DocLine_Cash
248
Popular Tags