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  
17  package org.kuali.ole.gl.businessobject;
18  
19  import java.sql.Date;
20  import java.text.NumberFormat;
21  import java.text.ParseException;
22  import java.text.SimpleDateFormat;
23  import java.util.LinkedHashMap;
24  
25  import org.kuali.ole.coa.businessobject.Account;
26  import org.kuali.ole.coa.businessobject.Chart;
27  import org.kuali.ole.coa.businessobject.ObjectCode;
28  import org.kuali.ole.gl.GeneralLedgerConstants;
29  import org.kuali.ole.sys.OLEPropertyConstants;
30  import org.kuali.rice.core.api.util.type.KualiDecimal;
31  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
32  
33  /**
34   * This class represents sufficient fund balances
35   */
36  public class SufficientFundBalances extends PersistableBusinessObjectBase {
37  
38      private Integer universityFiscalYear;
39      private String chartOfAccountsCode;
40      private String accountNumber;
41      private String financialObjectCode;
42      private String accountSufficientFundsCode;
43      private KualiDecimal currentBudgetBalanceAmount;
44      private KualiDecimal accountActualExpenditureAmt;
45      private KualiDecimal accountEncumbranceAmount;
46      private Date transactionDateTimeStamp;
47      private ObjectCode objectCode;
48      private Chart chart;
49      private Account account;
50  
51      public static final String BLANKS = "                 ";
52      public static final String DATE_FORMAT_STRING = "yyyy-MM-dd";
53  
54      /**
55       * Default constructor.
56       */
57      public SufficientFundBalances() {
58  
59      }
60  
61      /**
62       * Constructs a SufficientFundBalances.java.
63       * @param line
64       */
65      public SufficientFundBalances(String line) {
66          setFromTextFile(line);
67      }
68  
69      /**
70       * This method sets this object's attributes from the passed in line
71       * 
72       * @param line with sufficient fund balance related attributes
73       */
74      public void setFromTextFile(String line) {
75  
76          // Just in case
77          line = line + "                   ";
78  
79          if (!GeneralLedgerConstants.getSpaceUniversityFiscalYear().equals(line.substring(0, 4))) {
80              setUniversityFiscalYear(new Integer(line.substring(0, 4)));
81          }
82          else {
83              setUniversityFiscalYear(null);
84          }
85          setChartOfAccountsCode(line.substring(4, 6).trim());
86          setAccountNumber(line.substring(6, 13).trim());
87          setFinancialObjectCode(line.substring(13, 17).trim());
88          setAccountSufficientFundsCode(line.substring(17, 24).trim());
89          setCurrentBudgetBalanceAmount(new KualiDecimal(line.substring(24, 41).trim()));
90          setAccountActualExpenditureAmt(new KualiDecimal(line.substring(41, 58).trim()));
91          setAccountEncumbranceAmount(new KualiDecimal(line.substring(58, 75).trim()));
92          setTransactionDateTimeStamp(parseDate(line.substring(75, 85), true));
93      }
94  
95      /**
96       * This method returns a string representing this sufficient fund balance object and its attributes
97       * 
98       * @return String representing this sufficient fund balance object and its attributes
99       */
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 }