View Javadoc
1   /*
2    * Copyright 2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.businessobject;
17  
18  import java.io.Serializable;
19  
20  import org.kuali.ole.coa.businessobject.Account;
21  import org.kuali.ole.coa.businessobject.BalanceType;
22  import org.kuali.ole.coa.businessobject.ObjectCode;
23  import org.kuali.ole.coa.businessobject.ObjectType;
24  import org.kuali.ole.gl.businessobject.Transaction;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.rice.core.api.util.type.KualiDecimal;
27  
28  /**
29   * Represents a sufficient fund item which is used to show if a document has sufficient funds
30   */
31  public class SufficientFundsItem implements Serializable, Comparable {
32      private SystemOptions year;
33      private Account account;
34      private ObjectCode financialObject;
35      private ObjectType financialObjectType;
36      private String sufficientFundsObjectCode;
37      private KualiDecimal amount;
38      private String documentTypeCode;
39      private BalanceType balanceTyp;
40  
41      public BalanceType getBalanceTyp() {
42          return balanceTyp;
43      }
44  
45      public void setBalanceTyp(BalanceType balanceTyp) {
46          this.balanceTyp = balanceTyp;
47      }
48  
49      public SufficientFundsItem() {
50          amount = KualiDecimal.ZERO;
51      }
52  
53      /**
54       * Constructs a SufficientFundsItem.java.
55       * @param universityFiscalYear
56       * @param tran
57       * @param sufficientFundsObjectCode
58       */
59      public SufficientFundsItem(SystemOptions universityFiscalYear, Transaction tran, String sufficientFundsObjectCode) {
60  
61          amount = KualiDecimal.ZERO;
62          year = universityFiscalYear;
63          account = tran.getAccount();
64          financialObject = tran.getFinancialObject();
65          financialObjectType = tran.getObjectType();
66          this.sufficientFundsObjectCode = sufficientFundsObjectCode;
67          this.balanceTyp = tran.getBalanceType();
68  
69          add(tran);
70      }
71  
72      /**
73       * Constructs a SufficientFundsItem.java.
74       * @param universityFiscalYear
75       * @param accountLine
76       * @param sufficientFundsObjectCode
77       */
78      public SufficientFundsItem(SystemOptions universityFiscalYear, AccountingLine accountLine, String sufficientFundsObjectCode) {
79  
80          amount = KualiDecimal.ZERO;
81          year = universityFiscalYear;
82          account = accountLine.getAccount();
83          financialObject = accountLine.getObjectCode();
84          financialObjectType = accountLine.getObjectType();
85          this.sufficientFundsObjectCode = sufficientFundsObjectCode;
86          this.balanceTyp = accountLine.getBalanceTyp();
87  
88          add(accountLine);
89      }
90  
91      /**
92       * Adds an accounting line's amount to this sufficient funds item
93       * @param a accounting line
94       */
95      public void add(AccountingLine a) {
96          if (a.getObjectType().getFinObjectTypeDebitcreditCd().equals(a.getDebitCreditCode()) || OLEConstants.EMPTY_STRING.equals(a.getDebitCreditCode())) {
97              amount = amount.add(a.getAmount());
98          }
99          else {
100             amount = amount.subtract(a.getAmount());
101         }
102     }
103 
104     /**
105      * Adds a transactions amount to this sufficient funds item
106      * @param t transactions
107      */
108     public void add(Transaction t) {
109         if (t.getObjectType().getFinObjectTypeDebitcreditCd().equals(t.getTransactionDebitCreditCode()) || OLEConstants.EMPTY_STRING.equals(t.getTransactionDebitCreditCode())) {
110             amount = amount.add(t.getTransactionLedgerEntryAmount());
111         }
112         else {
113             amount = amount.subtract(t.getTransactionLedgerEntryAmount());
114         }
115     }
116 
117     /**
118      * Compare to other sufficient funds item based on key
119      * 
120      * @see java.lang.Comparable#compareTo(java.lang.Object)
121      */
122     public int compareTo(Object arg0) {
123         SufficientFundsItem item = (SufficientFundsItem) arg0;
124         return getKey().compareTo(item.getKey());
125     }
126 
127     /**
128      * Returns string to uniquely represent this sufficient funds item
129      * 
130      * @return string with the following concatenated: fiscal year, chart of accounts code, account number, financial object type code, sufficient funds object code and balance type code
131      */
132     public String getKey() {
133         return year.getUniversityFiscalYear() + account.getChartOfAccountsCode() + account.getAccountNumber() + financialObjectType.getCode() + sufficientFundsObjectCode + balanceTyp.getCode();
134     }
135 
136     public String getDocumentTypeCode() {
137         return documentTypeCode;
138     }
139 
140     public void setDocumentTypeCode(String documentTypeCode) {
141         this.documentTypeCode = documentTypeCode;
142     }
143 
144     public String getAccountSufficientFundsCode() {
145         return account.getAccountSufficientFundsCode();
146     }
147 
148     public ObjectType getFinancialObjectType() {
149         return financialObjectType;
150     }
151 
152     public void setFinancialObjectType(ObjectType financialObjectType) {
153         this.financialObjectType = financialObjectType;
154     }
155 
156     @Override
157     public String toString() {
158         return year.getUniversityFiscalYear() + "-" + account.getChartOfAccountsCode() + "-" + account.getAccountNumber() + "-" + financialObject.getFinancialObjectCode() + "-" + account.getAccountSufficientFundsCode() + "-" + sufficientFundsObjectCode + "-" + amount.toString();
159     }
160 
161     public Account getAccount() {
162         return account;
163     }
164 
165     public void setAccount(Account account) {
166         this.account = account;
167     }
168 
169     public KualiDecimal getAmount() {
170         return amount;
171     }
172 
173     public void setAmount(KualiDecimal amount) {
174         this.amount = amount;
175     }
176 
177     public ObjectCode getFinancialObject() {
178         return financialObject;
179     }
180 
181     public void setFinancialObject(ObjectCode financialObject) {
182         this.financialObject = financialObject;
183     }
184 
185     public String getSufficientFundsObjectCode() {
186         return sufficientFundsObjectCode;
187     }
188 
189     public void setSufficientFundsObjectCode(String sufficientFundsObjectCode) {
190         this.sufficientFundsObjectCode = sufficientFundsObjectCode;
191     }
192 
193     public SystemOptions getYear() {
194         return year;
195     }
196 
197     public void setYear(SystemOptions year) {
198         this.year = year;
199     }
200 
201 
202 }