001/* 002 * Copyright 2006 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */ 016package org.kuali.ole.sys.businessobject; 017 018import java.io.Serializable; 019 020import org.kuali.ole.coa.businessobject.Account; 021import org.kuali.ole.coa.businessobject.BalanceType; 022import org.kuali.ole.coa.businessobject.ObjectCode; 023import org.kuali.ole.coa.businessobject.ObjectType; 024import org.kuali.ole.gl.businessobject.Transaction; 025import org.kuali.ole.sys.OLEConstants; 026import org.kuali.rice.core.api.util.type.KualiDecimal; 027 028/** 029 * Represents a sufficient fund item which is used to show if a document has sufficient funds 030 */ 031public class SufficientFundsItem implements Serializable, Comparable { 032 private SystemOptions year; 033 private Account account; 034 private ObjectCode financialObject; 035 private ObjectType financialObjectType; 036 private String sufficientFundsObjectCode; 037 private KualiDecimal amount; 038 private String documentTypeCode; 039 private BalanceType balanceTyp; 040 041 public BalanceType getBalanceTyp() { 042 return balanceTyp; 043 } 044 045 public void setBalanceTyp(BalanceType balanceTyp) { 046 this.balanceTyp = balanceTyp; 047 } 048 049 public SufficientFundsItem() { 050 amount = KualiDecimal.ZERO; 051 } 052 053 /** 054 * Constructs a SufficientFundsItem.java. 055 * @param universityFiscalYear 056 * @param tran 057 * @param sufficientFundsObjectCode 058 */ 059 public SufficientFundsItem(SystemOptions universityFiscalYear, Transaction tran, String sufficientFundsObjectCode) { 060 061 amount = KualiDecimal.ZERO; 062 year = universityFiscalYear; 063 account = tran.getAccount(); 064 financialObject = tran.getFinancialObject(); 065 financialObjectType = tran.getObjectType(); 066 this.sufficientFundsObjectCode = sufficientFundsObjectCode; 067 this.balanceTyp = tran.getBalanceType(); 068 069 add(tran); 070 } 071 072 /** 073 * Constructs a SufficientFundsItem.java. 074 * @param universityFiscalYear 075 * @param accountLine 076 * @param sufficientFundsObjectCode 077 */ 078 public SufficientFundsItem(SystemOptions universityFiscalYear, AccountingLine accountLine, String sufficientFundsObjectCode) { 079 080 amount = KualiDecimal.ZERO; 081 year = universityFiscalYear; 082 account = accountLine.getAccount(); 083 financialObject = accountLine.getObjectCode(); 084 financialObjectType = accountLine.getObjectType(); 085 this.sufficientFundsObjectCode = sufficientFundsObjectCode; 086 this.balanceTyp = accountLine.getBalanceTyp(); 087 088 add(accountLine); 089 } 090 091 /** 092 * Adds an accounting line's amount to this sufficient funds item 093 * @param a accounting line 094 */ 095 public void add(AccountingLine a) { 096 if (a.getObjectType().getFinObjectTypeDebitcreditCd().equals(a.getDebitCreditCode()) || OLEConstants.EMPTY_STRING.equals(a.getDebitCreditCode())) { 097 amount = amount.add(a.getAmount()); 098 } 099 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}