001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.util;
017:
018: import java.io.Serializable;
019:
020: import org.kuali.core.util.KualiDecimal;
021: import org.kuali.kfs.KFSConstants;
022: import org.kuali.kfs.bo.AccountingLine;
023: import org.kuali.kfs.bo.Options;
024: import org.kuali.module.chart.bo.Account;
025: import org.kuali.module.chart.bo.ObjectCode;
026: import org.kuali.module.chart.bo.ObjectType;
027: import org.kuali.module.chart.bo.codes.BalanceTyp;
028: import org.kuali.module.gl.bo.Transaction;
029:
030: /**
031: * Represents a sufficient fund item which is used to show if a document has sufficient funds
032: */
033: public class SufficientFundsItem implements Serializable, Comparable {
034: private Options year;
035: private Account account;
036: private ObjectCode financialObject;
037: private ObjectType financialObjectType;
038: private String sufficientFundsObjectCode;
039: private KualiDecimal amount;
040: private String documentTypeCode;
041: private BalanceTyp balanceTyp;
042:
043: public BalanceTyp getBalanceTyp() {
044: return balanceTyp;
045: }
046:
047: public void setBalanceTyp(BalanceTyp balanceTyp) {
048: this .balanceTyp = balanceTyp;
049: }
050:
051: public SufficientFundsItem() {
052: amount = KualiDecimal.ZERO;
053: }
054:
055: /**
056: * Constructs a SufficientFundsItem.java.
057: * @param universityFiscalYear
058: * @param tran
059: * @param sufficientFundsObjectCode
060: */
061: public SufficientFundsItem(Options universityFiscalYear,
062: Transaction tran, String sufficientFundsObjectCode) {
063:
064: amount = KualiDecimal.ZERO;
065: year = universityFiscalYear;
066: account = tran.getAccount();
067: financialObject = tran.getFinancialObject();
068: financialObjectType = tran.getObjectType();
069: this .sufficientFundsObjectCode = sufficientFundsObjectCode;
070: this .balanceTyp = tran.getBalanceType();
071:
072: add(tran);
073: }
074:
075: /**
076: * Constructs a SufficientFundsItem.java.
077: * @param universityFiscalYear
078: * @param accountLine
079: * @param sufficientFundsObjectCode
080: */
081: public SufficientFundsItem(Options universityFiscalYear,
082: AccountingLine accountLine, String sufficientFundsObjectCode) {
083:
084: amount = KualiDecimal.ZERO;
085: year = universityFiscalYear;
086: account = accountLine.getAccount();
087: financialObject = accountLine.getObjectCode();
088: financialObjectType = accountLine.getObjectType();
089: this .sufficientFundsObjectCode = sufficientFundsObjectCode;
090: this .balanceTyp = accountLine.getBalanceTyp();
091:
092: add(accountLine);
093: }
094:
095: /**
096: * Adds an accounting line's amount to this sufficient funds item
097: * @param a accounting line
098: */
099: public void add(AccountingLine a) {
100: if (a.getObjectType().getFinObjectTypeDebitcreditCd().equals(
101: a.getDebitCreditCode())
102: || KFSConstants.EMPTY_STRING.equals(a
103: .getDebitCreditCode())) {
104: amount = amount.add(a.getAmount());
105: } else {
106: amount = amount.subtract(a.getAmount());
107: }
108: }
109:
110: /**
111: * Adds a transactions amount to this sufficient funds item
112: * @param t transactions
113: */
114: public void add(Transaction t) {
115: if (t.getObjectType().getFinObjectTypeDebitcreditCd().equals(
116: t.getTransactionDebitCreditCode())
117: || KFSConstants.EMPTY_STRING.equals(t
118: .getTransactionDebitCreditCode())) {
119: amount = amount.add(t.getTransactionLedgerEntryAmount());
120: } else {
121: amount = amount.subtract(t
122: .getTransactionLedgerEntryAmount());
123: }
124: }
125:
126: /**
127: * Compare to other sufficient funds item based on key
128: *
129: * @see java.lang.Comparable#compareTo(java.lang.Object)
130: */
131: public int compareTo(Object arg0) {
132: SufficientFundsItem item = (SufficientFundsItem) arg0;
133: return getKey().compareTo(item.getKey());
134: }
135:
136: /**
137: * Returns string to uniquely represent this sufficient funds item
138: *
139: * @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
140: */
141: public String getKey() {
142: return year.getUniversityFiscalYear()
143: + account.getChartOfAccountsCode()
144: + account.getAccountNumber()
145: + financialObjectType.getCode()
146: + sufficientFundsObjectCode + balanceTyp.getCode();
147: }
148:
149: public String getDocumentTypeCode() {
150: return documentTypeCode;
151: }
152:
153: public void setDocumentTypeCode(String documentTypeCode) {
154: this .documentTypeCode = documentTypeCode;
155: }
156:
157: public String getAccountSufficientFundsCode() {
158: return account.getAccountSufficientFundsCode();
159: }
160:
161: public ObjectType getFinancialObjectType() {
162: return financialObjectType;
163: }
164:
165: public void setFinancialObjectType(ObjectType financialObjectType) {
166: this .financialObjectType = financialObjectType;
167: }
168:
169: @Override
170: public String toString() {
171: return year.getUniversityFiscalYear() + "-"
172: + account.getChartOfAccountsCode() + "-"
173: + account.getAccountNumber() + "-"
174: + financialObject.getFinancialObjectCode() + "-"
175: + account.getAccountSufficientFundsCode() + "-"
176: + sufficientFundsObjectCode + "-" + amount.toString();
177: }
178:
179: public Account getAccount() {
180: return account;
181: }
182:
183: public void setAccount(Account account) {
184: this .account = account;
185: }
186:
187: public KualiDecimal getAmount() {
188: return amount;
189: }
190:
191: public void setAmount(KualiDecimal amount) {
192: this .amount = amount;
193: }
194:
195: public ObjectCode getFinancialObject() {
196: return financialObject;
197: }
198:
199: public void setFinancialObject(ObjectCode financialObject) {
200: this .financialObject = financialObject;
201: }
202:
203: public String getSufficientFundsObjectCode() {
204: return sufficientFundsObjectCode;
205: }
206:
207: public void setSufficientFundsObjectCode(
208: String sufficientFundsObjectCode) {
209: this .sufficientFundsObjectCode = sufficientFundsObjectCode;
210: }
211:
212: public Options getYear() {
213: return year;
214: }
215:
216: public void setYear(Options year) {
217: this.year = year;
218: }
219:
220: }
|