001 /* 002 * Copyright 2011 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 */ 016 package org.kuali.kfs.gl.businessobject; 017 018 import org.kuali.kfs.sys.KFSConstants; 019 import org.kuali.rice.kns.util.KualiDecimal; 020 021 /** 022 * A representation of LedgerEntries, which are summaries that show up on Ledger Reports created by the scrubber and poster. 023 */ 024 public class LedgerEntry { 025 026 private String balanceType; 027 private String originCode; 028 private Integer fiscalYear; 029 private String period; 030 private int recordCount; 031 private KualiDecimal debitAmount; 032 private int debitCount; 033 private KualiDecimal creditAmount; 034 private int creditCount; 035 private KualiDecimal noDCAmount; 036 private int noDCCount; 037 038 /** 039 * Constructs a LedgerEntry.java. 040 */ 041 public LedgerEntry() { 042 this(null, null, null, null); 043 } 044 045 /** 046 * Constructs a LedgerEntry.java. 047 * 048 * @param fiscalYear 049 * @param period 050 * @param balanceType 051 * @param originCode 052 */ 053 public LedgerEntry(Integer fiscalYear, String period, String balanceType, String originCode) { 054 this.fiscalYear = fiscalYear; 055 this.period = period; 056 this.balanceType = balanceType; 057 this.originCode = originCode; 058 059 this.creditAmount = KualiDecimal.ZERO; 060 this.debitAmount = KualiDecimal.ZERO; 061 this.noDCAmount = KualiDecimal.ZERO; 062 } 063 064 /** 065 * Constructs a LedgerEntry.java. 066 * 067 * @param fiscalYear 068 * @param period 069 * @param balanceType 070 * @param originCode 071 * @param debitCreditCode 072 * @param amount 073 * @param count 074 */ 075 public LedgerEntry(Integer fiscalYear, String period, String balanceType, String originCode, String debitCreditCode, KualiDecimal amount, int count) { 076 this.fiscalYear = fiscalYear; 077 this.period = period; 078 this.balanceType = balanceType; 079 this.originCode = originCode; 080 081 if (KFSConstants.GL_CREDIT_CODE.equals(debitCreditCode)) { 082 this.creditAmount = amount; 083 this.creditCount = count; 084 } 085 else if (KFSConstants.GL_DEBIT_CODE.equals(debitCreditCode)) { 086 this.debitAmount = amount; 087 this.debitCount = count; 088 } 089 else { 090 this.noDCAmount = amount; 091 this.noDCCount = count; 092 } 093 094 this.recordCount = count; 095 } 096 097 /** 098 * Add the amounts of the given ledger entry into those of current ledger entry, and update the counts of corresponding fields 099 * 100 * @param addend the given ledger entry to be added into current one 101 */ 102 public void add(LedgerEntry addend) { 103 this.creditAmount = this.creditAmount.add(addend.getCreditAmount()); 104 this.creditCount += addend.getCreditCount(); 105 106 this.debitAmount = this.debitAmount.add(addend.getDebitAmount()); 107 this.debitCount += addend.getDebitCount(); 108 109 this.noDCAmount = this.noDCAmount.add(addend.getNoDCAmount()); 110 this.noDCCount += addend.getNoDCCount(); 111 112 this.recordCount = this.creditCount + this.debitCount + this.noDCCount; 113 } 114 115 /** 116 * create or update a ledger entry with the array of information from the given entry summary object 117 * 118 * @param entrySummary an entry summary to turn into a ledger entry 119 * @return a LedgerEntry created from the entrySummary array 120 */ 121 public static LedgerEntry buildLedgerEntry(Object[] entrySummary) { 122 // extract the data from an array and use them to populate a ledger entry 123 Object oFiscalYear = entrySummary[0]; 124 Object oPeriodCode = entrySummary[1]; 125 Object oBalanceType = entrySummary[2]; 126 Object oOriginCode = entrySummary[3]; 127 Object oDebitCreditCode = entrySummary[4]; 128 Object oAmount = entrySummary[5]; 129 Object oCount = entrySummary[6]; 130 131 Integer fiscalYear = oFiscalYear != null ? new Integer(oFiscalYear.toString()) : null; 132 String periodCode = oPeriodCode != null ? oPeriodCode.toString() : " "; 133 String balanceType = oBalanceType != null ? oBalanceType.toString() : " "; 134 String originCode = oOriginCode != null ? oOriginCode.toString() : " "; 135 String debitCreditCode = oDebitCreditCode != null ? oDebitCreditCode.toString() : " "; 136 KualiDecimal amount = oAmount != null ? new KualiDecimal(oAmount.toString()) : KualiDecimal.ZERO; 137 int count = oCount != null ? Integer.parseInt(oCount.toString()) : 0; 138 139 // construct a ledger entry with the information fetched from the given array 140 LedgerEntry ledgerEntry = new LedgerEntry(fiscalYear, periodCode, balanceType, originCode); 141 if (KFSConstants.GL_CREDIT_CODE.equals(debitCreditCode)) { 142 ledgerEntry.setCreditAmount(amount); 143 ledgerEntry.setCreditCount(count); 144 } 145 else if (KFSConstants.GL_DEBIT_CODE.equals(debitCreditCode)) { 146 ledgerEntry.setDebitAmount(amount); 147 ledgerEntry.setDebitCount(count); 148 } 149 else { 150 ledgerEntry.setNoDCAmount(amount); 151 ledgerEntry.setNoDCCount(count); 152 } 153 ledgerEntry.setRecordCount(count); 154 155 return ledgerEntry; 156 } 157 158 /** 159 * Gets the balanceType attribute. 160 * 161 * @return Returns the balanceType. 162 */ 163 public String getBalanceType() { 164 return balanceType; 165 } 166 167 /** 168 * Sets the balanceType attribute value. 169 * 170 * @param balanceType The balanceType to set. 171 */ 172 public void setBalanceType(String balanceType) { 173 this.balanceType = balanceType; 174 } 175 176 /** 177 * Gets the creditAmount attribute. 178 * 179 * @return Returns the creditAmount. 180 */ 181 public KualiDecimal getCreditAmount() { 182 return creditAmount; 183 } 184 185 /** 186 * Sets the creditAmount attribute value. 187 * 188 * @param creditAmount The creditAmount to set. 189 */ 190 public void setCreditAmount(KualiDecimal creditAmount) { 191 this.creditAmount = creditAmount; 192 } 193 194 /** 195 * Gets the creditCount attribute. 196 * 197 * @return Returns the creditCount. 198 */ 199 public int getCreditCount() { 200 return creditCount; 201 } 202 203 /** 204 * Sets the creditCount attribute value. 205 * 206 * @param creditCount The creditCount to set. 207 */ 208 public void setCreditCount(int creditCount) { 209 this.creditCount = creditCount; 210 } 211 212 /** 213 * Gets the debitAmount attribute. 214 * 215 * @return Returns the debitAmount. 216 */ 217 public KualiDecimal getDebitAmount() { 218 return debitAmount; 219 } 220 221 /** 222 * Sets the debitAmount attribute value. 223 * 224 * @param debitAmount The debitAmount to set. 225 */ 226 public void setDebitAmount(KualiDecimal debitAmount) { 227 this.debitAmount = debitAmount; 228 } 229 230 /** 231 * Gets the debitCount attribute. 232 * 233 * @return Returns the debitCount. 234 */ 235 public int getDebitCount() { 236 return debitCount; 237 } 238 239 /** 240 * Sets the debitCount attribute value. 241 * 242 * @param debitCount The debitCount to set. 243 */ 244 public void setDebitCount(int debitCount) { 245 this.debitCount = debitCount; 246 } 247 248 /** 249 * Gets the fiscalYear attribute. 250 * 251 * @return Returns the fiscalYear. 252 */ 253 public Integer getFiscalYear() { 254 return fiscalYear; 255 } 256 257 /** 258 * Sets the fiscalYear attribute value. 259 * 260 * @param fiscalYear The fiscalYear to set. 261 */ 262 public void setFiscalYear(Integer fiscalYear) { 263 this.fiscalYear = fiscalYear; 264 } 265 266 /** 267 * Gets the noDCAmount attribute. 268 * 269 * @return Returns the noDCAmount. 270 */ 271 public KualiDecimal getNoDCAmount() { 272 return noDCAmount; 273 } 274 275 /** 276 * Sets the noDCAmount attribute value. 277 * 278 * @param noDCAmount The noDCAmount to set. 279 */ 280 public void setNoDCAmount(KualiDecimal noDCAmount) { 281 this.noDCAmount = noDCAmount; 282 } 283 284 /** 285 * Gets the noDCCount attribute. 286 * 287 * @return Returns the noDCCount. 288 */ 289 public int getNoDCCount() { 290 return noDCCount; 291 } 292 293 /** 294 * Sets the noDCCount attribute value. 295 * 296 * @param noDCCount The noDCCount to set. 297 */ 298 public void setNoDCCount(int noDCCount) { 299 this.noDCCount = noDCCount; 300 } 301 302 /** 303 * Gets the originCode attribute. 304 * 305 * @return Returns the originCode. 306 */ 307 public String getOriginCode() { 308 return originCode; 309 } 310 311 /** 312 * Sets the originCode attribute value. 313 * 314 * @param originCode The originCode to set. 315 */ 316 public void setOriginCode(String originCode) { 317 this.originCode = originCode; 318 } 319 320 /** 321 * Gets the period attribute. 322 * 323 * @return Returns the period. 324 */ 325 public String getPeriod() { 326 return period; 327 } 328 329 /** 330 * Sets the period attribute value. 331 * 332 * @param period The period to set. 333 */ 334 public void setPeriod(String period) { 335 this.period = period; 336 } 337 338 /** 339 * Gets the recordCount attribute. 340 * 341 * @return Returns the recordCount. 342 */ 343 public int getRecordCount() { 344 return recordCount; 345 } 346 347 /** 348 * Sets the recordCount attribute value. 349 * 350 * @param recordCount The recordCount to set. 351 */ 352 public void setRecordCount(int recordCount) { 353 this.recordCount = recordCount; 354 } 355 356 /** 357 * @see java.lang.Object#toString() 358 */ 359 public String toString() { 360 StringBuffer ledgerEntryDescription = new StringBuffer(); 361 362 ledgerEntryDescription.append(fiscalYear + "\t"); 363 ledgerEntryDescription.append(period + "\t"); 364 ledgerEntryDescription.append(balanceType + "\t"); 365 ledgerEntryDescription.append(originCode + "\t"); 366 ledgerEntryDescription.append(recordCount + "\t"); 367 368 ledgerEntryDescription.append(debitAmount + "\t\t"); 369 ledgerEntryDescription.append(debitCount + "\t"); 370 371 ledgerEntryDescription.append(creditAmount + "\t\t"); 372 ledgerEntryDescription.append(creditCount + "\t"); 373 374 ledgerEntryDescription.append(noDCAmount + "\t\t"); 375 ledgerEntryDescription.append(noDCCount + "\t"); 376 377 return ledgerEntryDescription.toString(); 378 } 379 }