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 */ 016 017package org.kuali.ole.gl.businessobject; 018 019import java.sql.Date; 020import java.text.NumberFormat; 021import java.text.ParseException; 022import java.text.SimpleDateFormat; 023import java.util.LinkedHashMap; 024 025import org.kuali.ole.coa.businessobject.Account; 026import org.kuali.ole.coa.businessobject.Chart; 027import org.kuali.ole.coa.businessobject.ObjectCode; 028import org.kuali.ole.gl.GeneralLedgerConstants; 029import org.kuali.ole.sys.OLEPropertyConstants; 030import org.kuali.rice.core.api.util.type.KualiDecimal; 031import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 032 033/** 034 * This class represents sufficient fund balances 035 */ 036public class SufficientFundBalances extends PersistableBusinessObjectBase { 037 038 private Integer universityFiscalYear; 039 private String chartOfAccountsCode; 040 private String accountNumber; 041 private String financialObjectCode; 042 private String accountSufficientFundsCode; 043 private KualiDecimal currentBudgetBalanceAmount; 044 private KualiDecimal accountActualExpenditureAmt; 045 private KualiDecimal accountEncumbranceAmount; 046 private Date transactionDateTimeStamp; 047 private ObjectCode objectCode; 048 private Chart chart; 049 private Account account; 050 051 public static final String BLANKS = " "; 052 public static final String DATE_FORMAT_STRING = "yyyy-MM-dd"; 053 054 /** 055 * Default constructor. 056 */ 057 public SufficientFundBalances() { 058 059 } 060 061 /** 062 * Constructs a SufficientFundBalances.java. 063 * @param line 064 */ 065 public SufficientFundBalances(String line) { 066 setFromTextFile(line); 067 } 068 069 /** 070 * This method sets this object's attributes from the passed in line 071 * 072 * @param line with sufficient fund balance related attributes 073 */ 074 public void setFromTextFile(String line) { 075 076 // Just in case 077 line = line + " "; 078 079 if (!GeneralLedgerConstants.getSpaceUniversityFiscalYear().equals(line.substring(0, 4))) { 080 setUniversityFiscalYear(new Integer(line.substring(0, 4))); 081 } 082 else { 083 setUniversityFiscalYear(null); 084 } 085 setChartOfAccountsCode(line.substring(4, 6).trim()); 086 setAccountNumber(line.substring(6, 13).trim()); 087 setFinancialObjectCode(line.substring(13, 17).trim()); 088 setAccountSufficientFundsCode(line.substring(17, 24).trim()); 089 setCurrentBudgetBalanceAmount(new KualiDecimal(line.substring(24, 41).trim())); 090 setAccountActualExpenditureAmt(new KualiDecimal(line.substring(41, 58).trim())); 091 setAccountEncumbranceAmount(new KualiDecimal(line.substring(58, 75).trim())); 092 setTransactionDateTimeStamp(parseDate(line.substring(75, 85), true)); 093 } 094 095 /** 096 * This method returns a string representing this sufficient fund balance object and its attributes 097 * 098 * @return String representing this sufficient fund balance object and its attributes 099 */ 100 public String getLine() { 101 NumberFormat nf = NumberFormat.getInstance(); 102 nf.setMaximumFractionDigits(2); 103 nf.setMinimumFractionDigits(0); 104 nf.setMinimumIntegerDigits(1); 105 nf.setGroupingUsed(false); 106 107 StringBuffer sb = new StringBuffer(); 108 if (universityFiscalYear == null) { 109 sb.append(GeneralLedgerConstants.getSpaceUniversityFiscalYear()); 110 } 111 else { 112 sb.append(universityFiscalYear); 113 } 114 sb.append(getField(2, chartOfAccountsCode)); 115 sb.append(getField(7, accountNumber)); 116 sb.append(getField(4, financialObjectCode)); 117 sb.append(getField(1, accountSufficientFundsCode)); 118 if (currentBudgetBalanceAmount == null) { 119 sb.append(BLANKS); 120 } 121 else { 122 String a = nf.format(currentBudgetBalanceAmount.doubleValue()); 123 sb.append(BLANKS.substring(0, 17 - a.length())); 124 sb.append(a); 125 } 126 if (accountActualExpenditureAmt == null) { 127 sb.append(BLANKS); 128 } 129 else { 130 String a = nf.format(accountActualExpenditureAmt.doubleValue()); 131 sb.append(BLANKS.substring(0, 17 - a.length())); 132 sb.append(a); 133 } 134 if (accountEncumbranceAmount == null) { 135 sb.append(BLANKS); 136 } 137 else { 138 String a = nf.format(accountEncumbranceAmount.doubleValue()); 139 sb.append(BLANKS.substring(0, 17 - a.length())); 140 sb.append(a); 141 } 142 return sb.toString(); 143 } 144 145 private static String SPACES = " "; 146 147 /** 148 * Returns value passed in with additional spaces if need be 149 * 150 * @param size 151 * @param value 152 * @return 153 */ 154 private String getField(int size, String value) { 155 if (value == null) { 156 return SPACES.substring(0, size); 157 } 158 else { 159 if (value.length() < size) { 160 return value + SPACES.substring(0, size - value.length()); 161 } 162 else { 163 return value; 164 } 165 } 166 } 167 168 /** 169 * This method parses a date as yyyy-MM-dd 170 * 171 * @param sdate 172 * @param beLenientWithDates 173 * @return 174 */ 175 private java.sql.Date parseDate(String sdate, boolean beLenientWithDates) { 176 if ((sdate == null) || (sdate.trim().length() == 0)) { 177 return null; 178 } 179 else { 180 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_STRING); 181 sdf.setLenient(beLenientWithDates); 182 183 try { 184 java.util.Date d = sdf.parse(sdate); 185 return new Date(d.getTime()); 186 } 187 catch (ParseException e) { 188 return null; 189 } 190 } 191 } 192 193 /** 194 * This method returns a string representation of date as yyyy-MM-dd 195 * 196 * @param date 197 * @return 198 */ 199 private String formatDate(Date date) { 200 if (date == null) { 201 return " "; 202 } 203 else { 204 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_STRING); 205 return sdf.format(date); 206 } 207 } 208 209 /** 210 * Gets the universityFiscalYear attribute. 211 * 212 * @return Returns the universityFiscalYear 213 */ 214 public Integer getUniversityFiscalYear() { 215 return universityFiscalYear; 216 } 217 218 /** 219 * Sets the universityFiscalYear attribute. 220 * 221 * @param universityFiscalYear The universityFiscalYear to set. 222 */ 223 public void setUniversityFiscalYear(Integer universityFiscalYear) { 224 this.universityFiscalYear = universityFiscalYear; 225 } 226 227 228 /** 229 * Gets the chartOfAccountsCode attribute. 230 * 231 * @return Returns the chartOfAccountsCode 232 */ 233 public String getChartOfAccountsCode() { 234 return chartOfAccountsCode; 235 } 236 237 /** 238 * Sets the chartOfAccountsCode attribute. 239 * 240 * @param chartOfAccountsCode The chartOfAccountsCode to set. 241 */ 242 public void setChartOfAccountsCode(String chartOfAccountsCode) { 243 this.chartOfAccountsCode = chartOfAccountsCode; 244 } 245 246 247 /** 248 * Gets the accountNumber attribute. 249 * 250 * @return Returns the accountNumber 251 */ 252 public String getAccountNumber() { 253 return accountNumber; 254 } 255 256 /** 257 * Sets the accountNumber attribute. 258 * 259 * @param accountNumber The accountNumber to set. 260 */ 261 public void setAccountNumber(String accountNumber) { 262 this.accountNumber = accountNumber; 263 } 264 265 266 /** 267 * Gets the financialObjectCode attribute. 268 * 269 * @return Returns the financialObjectCode 270 */ 271 public String getFinancialObjectCode() { 272 return financialObjectCode; 273 } 274 275 /** 276 * Sets the financialObjectCode attribute. 277 * 278 * @param financialObjectCode The financialObjectCode to set. 279 */ 280 public void setFinancialObjectCode(String financialObjectCode) { 281 this.financialObjectCode = financialObjectCode; 282 } 283 284 285 /** 286 * Gets the accountSufficientFundsCode attribute. 287 * 288 * @return Returns the accountSufficientFundsCode 289 */ 290 public String getAccountSufficientFundsCode() { 291 return accountSufficientFundsCode; 292 } 293 294 /** 295 * Sets the accountSufficientFundsCode attribute. 296 * 297 * @param accountSufficientFundsCode The accountSufficientFundsCode to set. 298 */ 299 public void setAccountSufficientFundsCode(String accountSufficientFundsCode) { 300 this.accountSufficientFundsCode = accountSufficientFundsCode; 301 } 302 303 304 /** 305 * Gets the currentBudgetBalanceAmount attribute. 306 * 307 * @return Returns the currentBudgetBalanceAmount 308 */ 309 public KualiDecimal getCurrentBudgetBalanceAmount() { 310 return currentBudgetBalanceAmount; 311 } 312 313 /** 314 * Sets the currentBudgetBalanceAmount attribute. 315 * 316 * @param currentBudgetBalanceAmount The currentBudgetBalanceAmount to set. 317 */ 318 public void setCurrentBudgetBalanceAmount(KualiDecimal currentBudgetBalanceAmount) { 319 this.currentBudgetBalanceAmount = currentBudgetBalanceAmount; 320 } 321 322 323 /** 324 * Gets the accountActualExpenditureAmt attribute. 325 * 326 * @return Returns the accountActualExpenditureAmt 327 */ 328 public KualiDecimal getAccountActualExpenditureAmt() { 329 return accountActualExpenditureAmt; 330 } 331 332 /** 333 * Sets the accountActualExpenditureAmt attribute. 334 * 335 * @param accountActualExpenditureAmt The accountActualExpenditureAmt to set. 336 */ 337 public void setAccountActualExpenditureAmt(KualiDecimal accountActualExpenditureAmt) { 338 this.accountActualExpenditureAmt = accountActualExpenditureAmt; 339 } 340 341 342 /** 343 * Gets the accountEncumbranceAmount attribute. 344 * 345 * @return Returns the accountEncumbranceAmount 346 */ 347 public KualiDecimal getAccountEncumbranceAmount() { 348 return accountEncumbranceAmount; 349 } 350 351 /** 352 * Sets the accountEncumbranceAmount attribute. 353 * 354 * @param accountEncumbranceAmount The accountEncumbranceAmount to set. 355 */ 356 public void setAccountEncumbranceAmount(KualiDecimal accountEncumbranceAmount) { 357 this.accountEncumbranceAmount = accountEncumbranceAmount; 358 } 359 360 361 /** 362 * Gets the transactionDateTimeStamp attribute. 363 * 364 * @return Returns the transactionDateTimeStamp 365 */ 366 public Date getTransactionDateTimeStamp() { 367 return transactionDateTimeStamp; 368 } 369 370 /** 371 * Sets the transactionDateTimeStamp attribute. 372 * 373 * @param transactionDateTimeStamp The transactionDateTimeStamp to set. 374 */ 375 public void setTransactionDateTimeStamp(Date transactionDateTimeStamp) { 376 this.transactionDateTimeStamp = transactionDateTimeStamp; 377 } 378 379 380 /** 381 * Gets the objectCode attribute. 382 * 383 * @return Returns the objectCode 384 */ 385 public ObjectCode getObjectCode() { 386 return objectCode; 387 } 388 389 /** 390 * Sets the objectCode attribute. 391 * 392 * @param objectCode The objectCode to set. 393 * @deprecated 394 */ 395 public void setObjectCode(ObjectCode objectCode) { 396 this.objectCode = objectCode; 397 } 398 399 /** 400 * Gets the chart attribute. 401 * 402 * @return Returns the chart 403 */ 404 public Chart getChart() { 405 return chart; 406 } 407 408 /** 409 * Sets the chart attribute. 410 * 411 * @param chart The chart to set. 412 * @deprecated 413 */ 414 public void setChart(Chart chart) { 415 this.chart = chart; 416 } 417 418 /** 419 * Gets the account attribute. 420 * 421 * @return Returns the account 422 */ 423 public Account getAccount() { 424 return account; 425 } 426 427 /** 428 * Sets the account attribute. 429 * 430 * @param account The account to set. 431 * @deprecated 432 */ 433 public void setAccount(Account account) { 434 this.account = account; 435 } 436 437 /** 438 * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper() 439 */ 440 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() { 441 LinkedHashMap m = new LinkedHashMap(); 442 m.put(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, this.universityFiscalYear.toString()); 443 m.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, this.chartOfAccountsCode); 444 m.put(OLEPropertyConstants.ACCOUNT_NUMBER, this.accountNumber); 445 m.put(OLEPropertyConstants.FINANCIAL_OBJECT_CODE, this.financialObjectCode); 446 return m; 447 } 448}