1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
56
57 public SufficientFundBalances() {
58
59 }
60
61
62
63
64
65 public SufficientFundBalances(String line) {
66 setFromTextFile(line);
67 }
68
69
70
71
72
73
74 public void setFromTextFile(String line) {
75
76
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
97
98
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
149
150
151
152
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
170
171
172
173
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
195
196
197
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
211
212
213
214 public Integer getUniversityFiscalYear() {
215 return universityFiscalYear;
216 }
217
218
219
220
221
222
223 public void setUniversityFiscalYear(Integer universityFiscalYear) {
224 this.universityFiscalYear = universityFiscalYear;
225 }
226
227
228
229
230
231
232
233 public String getChartOfAccountsCode() {
234 return chartOfAccountsCode;
235 }
236
237
238
239
240
241
242 public void setChartOfAccountsCode(String chartOfAccountsCode) {
243 this.chartOfAccountsCode = chartOfAccountsCode;
244 }
245
246
247
248
249
250
251
252 public String getAccountNumber() {
253 return accountNumber;
254 }
255
256
257
258
259
260
261 public void setAccountNumber(String accountNumber) {
262 this.accountNumber = accountNumber;
263 }
264
265
266
267
268
269
270
271 public String getFinancialObjectCode() {
272 return financialObjectCode;
273 }
274
275
276
277
278
279
280 public void setFinancialObjectCode(String financialObjectCode) {
281 this.financialObjectCode = financialObjectCode;
282 }
283
284
285
286
287
288
289
290 public String getAccountSufficientFundsCode() {
291 return accountSufficientFundsCode;
292 }
293
294
295
296
297
298
299 public void setAccountSufficientFundsCode(String accountSufficientFundsCode) {
300 this.accountSufficientFundsCode = accountSufficientFundsCode;
301 }
302
303
304
305
306
307
308
309 public KualiDecimal getCurrentBudgetBalanceAmount() {
310 return currentBudgetBalanceAmount;
311 }
312
313
314
315
316
317
318 public void setCurrentBudgetBalanceAmount(KualiDecimal currentBudgetBalanceAmount) {
319 this.currentBudgetBalanceAmount = currentBudgetBalanceAmount;
320 }
321
322
323
324
325
326
327
328 public KualiDecimal getAccountActualExpenditureAmt() {
329 return accountActualExpenditureAmt;
330 }
331
332
333
334
335
336
337 public void setAccountActualExpenditureAmt(KualiDecimal accountActualExpenditureAmt) {
338 this.accountActualExpenditureAmt = accountActualExpenditureAmt;
339 }
340
341
342
343
344
345
346
347 public KualiDecimal getAccountEncumbranceAmount() {
348 return accountEncumbranceAmount;
349 }
350
351
352
353
354
355
356 public void setAccountEncumbranceAmount(KualiDecimal accountEncumbranceAmount) {
357 this.accountEncumbranceAmount = accountEncumbranceAmount;
358 }
359
360
361
362
363
364
365
366 public Date getTransactionDateTimeStamp() {
367 return transactionDateTimeStamp;
368 }
369
370
371
372
373
374
375 public void setTransactionDateTimeStamp(Date transactionDateTimeStamp) {
376 this.transactionDateTimeStamp = transactionDateTimeStamp;
377 }
378
379
380
381
382
383
384
385 public ObjectCode getObjectCode() {
386 return objectCode;
387 }
388
389
390
391
392
393
394
395 public void setObjectCode(ObjectCode objectCode) {
396 this.objectCode = objectCode;
397 }
398
399
400
401
402
403
404 public Chart getChart() {
405 return chart;
406 }
407
408
409
410
411
412
413
414 public void setChart(Chart chart) {
415 this.chart = chart;
416 }
417
418
419
420
421
422
423 public Account getAccount() {
424 return account;
425 }
426
427
428
429
430
431
432
433 public void setAccount(Account account) {
434 this.account = account;
435 }
436
437
438
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 }