1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.batch;
17
18 import java.sql.Date;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.log4j.Logger;
23 import org.kuali.ole.coa.service.ObjectTypeService;
24 import org.kuali.ole.gl.GeneralLedgerConstants;
25 import org.kuali.ole.gl.ObjectHelper;
26 import org.kuali.ole.gl.batch.service.impl.exception.FatalErrorException;
27 import org.kuali.ole.gl.businessobject.Balance;
28 import org.kuali.ole.gl.businessobject.OriginEntryFull;
29 import org.kuali.ole.sys.OLEConstants;
30 import org.kuali.ole.sys.OLEKeyConstants;
31 import org.kuali.ole.sys.context.SpringContext;
32 import org.kuali.ole.sys.service.FlexibleOffsetAccountService;
33 import org.kuali.ole.sys.service.impl.OleParameterConstants;
34 import org.kuali.rice.core.api.config.property.ConfigurationService;
35 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
36
37
38
39
40 public class NominalActivityClosingHelper {
41 private Integer fiscalYear;
42 private Date transactionDate;
43 private String varNetExpenseObjectCode;
44 private String varNetRevenueObjectCode;
45 private String varFundBalanceObjectCode;
46 private String varFundBalanceObjectTypeCode;
47 private String[] expenseObjectCodeTypes;
48 private ParameterService parameterService;
49 private ConfigurationService configurationService;
50 private FlexibleOffsetAccountService flexibleOffsetService;
51 private Logger LOG = Logger.getLogger(NominalActivityClosingHelper.class);
52 private int nonFatalErrorCount;
53
54
55
56
57
58
59
60
61 public NominalActivityClosingHelper(Integer fiscalYear, Date transactionDate, ParameterService parameterService, ConfigurationService configurationService) {
62 this.fiscalYear = fiscalYear;
63 this.transactionDate = transactionDate;
64 this.parameterService = parameterService;
65 this.configurationService = configurationService;
66 this.flexibleOffsetService = SpringContext.getBean(FlexibleOffsetAccountService.class);
67 this.nonFatalErrorCount = 0;
68
69 ObjectTypeService objectTypeService = (ObjectTypeService) SpringContext.getBean(ObjectTypeService.class);
70 List<String> objectTypes = objectTypeService.getExpenseObjectTypes(fiscalYear);
71 expenseObjectCodeTypes = objectTypes.toArray(new String[0]);
72
73
74
75
76 varNetExpenseObjectCode = parameterService.getParameterValueAsString(NominalActivityClosingStep.class, "NET_EXPENSE_OBJECT_CODE");
77 varNetRevenueObjectCode = parameterService.getParameterValueAsString(NominalActivityClosingStep.class, "NET_REVENUE_OBJECT_CODE");
78 varFundBalanceObjectCode = parameterService.getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_FUND_BALANCE_OBJECT_CODE_PARM);
79 varFundBalanceObjectTypeCode = parameterService.getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_FUND_BALANCE_OBJECT_TYPE_PARM);
80
81 }
82
83
84
85
86
87
88
89
90 public OriginEntryFull generateActivityEntry(Balance balance, Integer sequenceNumber) throws FatalErrorException {
91
92
93 OriginEntryFull activityEntry = new OriginEntryFull();
94
95
96
97
98
99 activityEntry.setUniversityFiscalYear(fiscalYear);
100
101
102
103
104 activityEntry.setChartOfAccountsCode(balance.getChartOfAccountsCode());
105
106
107
108
109 activityEntry.setAccountNumber(balance.getAccountNumber());
110
111
112
113
114 activityEntry.setSubAccountNumber(balance.getSubAccountNumber());
115
116
117
118
119
120
121
122
123 if (ObjectHelper.isOneOf(balance.getObjectTypeCode(), expenseObjectCodeTypes)) {
124
125
126
127
128 activityEntry.setFinancialObjectCode(varNetExpenseObjectCode);
129
130
131
132 }
133 else {
134
135
136
137
138 activityEntry.setFinancialObjectCode(varNetRevenueObjectCode);
139
140 }
141
142 activityEntry.setFinancialSubObjectCode(OLEConstants.getDashFinancialSubObjectCode());
143 activityEntry.setFinancialBalanceTypeCode(balance.getOption().getNominalFinancialBalanceTypeCd());
144
145 if (null == balance.getObjectTypeCode()) {
146 throw new FatalErrorException(" BALANCE SELECTED FOR PROCESSING IS MISSING ITS OBJECT TYPE CODE ");
147
148 }
149
150 activityEntry.setFinancialObjectTypeCode(balance.getObjectTypeCode());
151
152
153
154
155 activityEntry.setUniversityFiscalPeriodCode(OLEConstants.MONTH13);
156
157
158
159
160 activityEntry.setFinancialDocumentTypeCode(parameterService.getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, OLEConstants.SystemGroupParameterNames.GL_ANNUAL_CLOSING_DOC_TYPE));
161
162
163
164
165 activityEntry.setFinancialSystemOriginationCode(parameterService.getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, OLEConstants.SystemGroupParameterNames.GL_ORIGINATION_CODE));
166
167
168
169
170
171
172 activityEntry.setDocumentNumber(new StringBuffer(balance.getOption().getActualFinancialBalanceTypeCd()).append(balance.getAccountNumber()).toString());
173
174
175
176
177 activityEntry.setTransactionLedgerEntrySequenceNumber(sequenceNumber);
178
179
180
181
182 if (ObjectHelper.isOneOf(balance.getObjectTypeCode(), expenseObjectCodeTypes)) {
183
184
185
186
187
188
189
190
191
192
193
194
195
196 activityEntry.setTransactionLedgerEntryDescription(this.createTransactionLedgerEntryDescription(configurationService.getPropertyValueAsString(OLEKeyConstants.MSG_CLOSE_ENTRY_TO_NOMINAL_EXPENSE), balance));
197
198
199
200 }
201 else {
202
203
204
205
206
207
208
209
210
211
212
213
214
215 activityEntry.setTransactionLedgerEntryDescription(this.createTransactionLedgerEntryDescription(configurationService.getPropertyValueAsString(OLEKeyConstants.MSG_CLOSE_ENTRY_TO_NOMINAL_REVENUE), balance));
216
217 }
218
219
220
221
222 activityEntry.setTransactionLedgerEntryAmount(balance.getAccountLineAnnualBalanceAmount());
223
224
225
226
227 activityEntry.setFinancialObjectTypeCode(balance.getObjectTypeCode());
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244 String debitCreditCode = null;
245
246 if (null != balance.getObjectType()) {
247
248
249
250 if (ObjectHelper.isOneOf(balance.getObjectType().getFinObjectTypeDebitcreditCd(), new String[] { OLEConstants.GL_CREDIT_CODE, OLEConstants.GL_DEBIT_CODE })) {
251
252
253
254
255 debitCreditCode = balance.getObjectType().getFinObjectTypeDebitcreditCd();
256
257
258
259 }
260 else {
261
262
263
264 debitCreditCode = OLEConstants.GL_CREDIT_CODE;
265
266
267
268 }
269
270
271
272
273
274
275 if (balance.getAccountLineAnnualBalanceAmount().isNegative()) {
276
277
278
279 if (ObjectHelper.isOneOf(balance.getObjectType().getFinObjectTypeDebitcreditCd(), new String[] { OLEConstants.GL_CREDIT_CODE, OLEConstants.GL_DEBIT_CODE })) {
280
281
282
283
284 activityEntry.setTransactionDebitCreditCode(balance.getObjectType().getFinObjectTypeDebitcreditCd());
285
286
287
288 }
289 else {
290
291
292
293 activityEntry.setTransactionDebitCreditCode(OLEConstants.GL_CREDIT_CODE);
294
295
296
297
298
299
300
301
302
303
304
305
306 }
307
308
309
310
311
312
313 }
314 else {
315
316
317
318 if (OLEConstants.GL_CREDIT_CODE.equals(balance.getObjectType().getFinObjectTypeDebitcreditCd())) {
319
320
321
322 activityEntry.setTransactionDebitCreditCode(OLEConstants.GL_DEBIT_CODE);
323
324
325
326 }
327 else {
328
329
330
331 if (OLEConstants.GL_DEBIT_CODE.equals(balance.getObjectType().getFinObjectTypeDebitcreditCd())) {
332
333
334
335 activityEntry.setTransactionDebitCreditCode(OLEConstants.GL_CREDIT_CODE);
336
337
338
339 }
340 else {
341
342
343
344 activityEntry.setTransactionDebitCreditCode(OLEConstants.GL_DEBIT_CODE);
345
346
347
348
349
350
351
352
353
354
355
356
357 }
358
359
360
361
362
363
364
365
366
367 }
368
369
370
371 }
372
373
374
375
376
377
378 }
379 else {
380
381
382
383
384
385 if (balance.getAccountLineAnnualBalanceAmount().isNegative()) {
386
387
388
389 activityEntry.setTransactionDebitCreditCode(OLEConstants.GL_CREDIT_CODE);
390
391
392
393 }
394 else {
395
396
397
398 activityEntry.setTransactionDebitCreditCode(OLEConstants.GL_DEBIT_CODE);
399
400
401
402 }
403
404 nonFatalErrorCount += 1;
405
406
407
408
409
410
411 LOG.info(new StringBuffer("FIN OBJ TYP CODE ").append(balance.getObjectTypeCode()).append(" NOT IN TABLE").toString());
412
413
414
415
416
417
418
419
420
421
422
423
424 }
425
426
427
428
429 activityEntry.setTransactionDate(transactionDate);
430
431
432
433
434 activityEntry.setOrganizationDocumentNumber(null);
435
436
437
438
439 activityEntry.setProjectCode(OLEConstants.getDashProjectCode());
440
441
442
443
444 activityEntry.setOrganizationReferenceId(null);
445
446
447
448
449 activityEntry.setReferenceFinancialDocumentTypeCode(null);
450
451
452
453
454 activityEntry.setReferenceFinancialSystemOriginationCode(null);
455
456
457
458
459 activityEntry.setReferenceFinancialDocumentNumber(null);
460
461
462
463
464 activityEntry.setReversalDate(null);
465
466
467
468
469 activityEntry.setTransactionEncumbranceUpdateCode(null);
470
471
472
473 if (balance.getAccountLineAnnualBalanceAmount().isNegative()) {
474
475
476
477
478
479 activityEntry.setTransactionLedgerEntryAmount(balance.getAccountLineAnnualBalanceAmount().negated());
480
481 }
482
483 return activityEntry;
484
485 }
486
487
488
489
490
491
492
493
494 public OriginEntryFull generateOffset(Balance balance, Integer sequenceNumber) throws FatalErrorException {
495 String debitCreditCode = null;
496
497
498
499 if (null == balance.getObjectTypeCode()) {
500 throw new FatalErrorException(" BALANCE SELECTED FOR PROCESSING IS MISSING ITS OBJECT TYPE CODE ");
501
502 }
503
504 if (ObjectHelper.isOneOf(balance.getObjectType().getFinObjectTypeDebitcreditCd(), new String[] { OLEConstants.GL_CREDIT_CODE, OLEConstants.GL_DEBIT_CODE })) {
505
506
507
508
509 debitCreditCode = balance.getObjectType().getFinObjectTypeDebitcreditCd();
510
511
512
513 }
514 else {
515
516
517
518 debitCreditCode = OLEConstants.GL_CREDIT_CODE;
519
520
521
522 }
523
524
525
526
527 OriginEntryFull offsetEntry = new OriginEntryFull();
528
529
530
531
532 offsetEntry.setUniversityFiscalYear(fiscalYear);
533
534
535
536
537 offsetEntry.setChartOfAccountsCode(balance.getChartOfAccountsCode());
538
539
540
541
542 offsetEntry.setAccountNumber(balance.getAccountNumber());
543
544
545
546
547 offsetEntry.setSubAccountNumber(balance.getSubAccountNumber());
548
549
550
551
552 offsetEntry.setFinancialObjectCode(varFundBalanceObjectCode);
553
554
555
556
557 offsetEntry.setFinancialSubObjectCode(OLEConstants.getDashFinancialSubObjectCode());
558
559
560
561
562 offsetEntry.setFinancialBalanceTypeCode(balance.getOption().getNominalFinancialBalanceTypeCd());
563
564
565
566
567 offsetEntry.setFinancialObjectTypeCode(varFundBalanceObjectTypeCode);
568
569
570
571
572 offsetEntry.setUniversityFiscalPeriodCode(OLEConstants.MONTH13);
573
574
575
576
577 offsetEntry.setFinancialDocumentTypeCode(parameterService.getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, OLEConstants.SystemGroupParameterNames.GL_ANNUAL_CLOSING_DOC_TYPE));
578
579
580
581
582 offsetEntry.setFinancialSystemOriginationCode(parameterService.getParameterValueAsString(OleParameterConstants.GENERAL_LEDGER_BATCH.class, OLEConstants.SystemGroupParameterNames.GL_ORIGINATION_CODE));
583
584
585
586
587
588
589
590 offsetEntry.setDocumentNumber(new StringBuffer(balance.getOption().getActualFinancialBalanceTypeCd()).append(balance.getAccountNumber()).toString());
591
592
593
594
595 offsetEntry.setTransactionLedgerEntrySequenceNumber(new Integer(sequenceNumber.intValue()));
596
597
598
599
600
601
602
603
604
605
606
607
608
609 offsetEntry.setTransactionLedgerEntryDescription(this.createTransactionLedgerEntryDescription(configurationService.getPropertyValueAsString(OLEKeyConstants.MSG_CLOSE_ENTRY_TO_FUND_BALANCE), balance));
610
611
612
613
614 offsetEntry.setTransactionLedgerEntryAmount(balance.getAccountLineAnnualBalanceAmount());
615
616
617
618
619 offsetEntry.setTransactionDebitCreditCode(debitCreditCode);
620
621
622
623
624 offsetEntry.setTransactionDate(transactionDate);
625
626
627
628
629 offsetEntry.setOrganizationDocumentNumber(null);
630
631
632
633
634 offsetEntry.setProjectCode(OLEConstants.getDashProjectCode());
635
636
637
638
639 offsetEntry.setOrganizationReferenceId(null);
640
641
642
643
644 offsetEntry.setReferenceFinancialDocumentTypeCode(null);
645
646
647
648
649 offsetEntry.setReferenceFinancialSystemOriginationCode(null);
650
651
652
653
654 offsetEntry.setReferenceFinancialDocumentNumber(null);
655
656
657
658
659 offsetEntry.setFinancialDocumentReversalDate(null);
660
661
662
663
664 offsetEntry.setTransactionEncumbranceUpdateCode(null);
665
666
667
668 if (balance.getAccountLineAnnualBalanceAmount().isNegative()) {
669
670
671
672 if (OLEConstants.GL_CREDIT_CODE.equals(debitCreditCode)) {
673
674
675
676 offsetEntry.setTransactionDebitCreditCode(OLEConstants.GL_DEBIT_CODE);
677
678
679
680 }
681 else {
682
683
684
685 offsetEntry.setTransactionDebitCreditCode(OLEConstants.GL_CREDIT_CODE);
686
687 }
688
689 }
690
691
692
693 if (balance.getAccountLineAnnualBalanceAmount().isNegative()) {
694
695
696
697
698
699 offsetEntry.setTransactionLedgerEntryAmount(balance.getAccountLineAnnualBalanceAmount().negated());
700
701 }
702
703 flexibleOffsetService.updateOffset(offsetEntry);
704
705 return offsetEntry;
706 }
707
708
709
710
711
712 public void addNominalClosingJobParameters(Map nominalClosingJobParameters) {
713 nominalClosingJobParameters.put(GeneralLedgerConstants.ColumnNames.UNIVERSITY_FISCAL_YEAR, fiscalYear);
714 nominalClosingJobParameters.put(GeneralLedgerConstants.ColumnNames.NET_EXP_OBJECT_CD, varNetExpenseObjectCode);
715 nominalClosingJobParameters.put(GeneralLedgerConstants.ColumnNames.NET_REV_OBJECT_CD, varNetRevenueObjectCode);
716 nominalClosingJobParameters.put(GeneralLedgerConstants.ColumnNames.FUND_BAL_OBJECT_CD, varFundBalanceObjectCode);
717 nominalClosingJobParameters.put(GeneralLedgerConstants.ColumnNames.FUND_BAL_OBJ_TYP_CD, varFundBalanceObjectTypeCode);
718 }
719
720
721
722
723
724
725
726
727 private String createTransactionLedgerEntryDescription(String descriptorIntro, Balance balance) {
728 StringBuilder description = new StringBuilder();
729 description.append(descriptorIntro.trim()).append(' ');
730 return description.append(getSizedField(5, balance.getSubAccountNumber())).append("-").append(getSizedField(4, balance.getObjectCode())).append("-").append(getSizedField(3, balance.getSubObjectCode())).append("-").append(getSizedField(2, balance.getObjectTypeCode())).toString();
731 }
732
733
734
735
736
737
738
739
740 private StringBuilder getSizedField(int size, String value) {
741 StringBuilder fieldString = new StringBuilder();
742 if (value != null) {
743 fieldString.append(value);
744 while (fieldString.length() < size) {
745 fieldString.append(' ');
746 }
747 }
748 else {
749 while (fieldString.length() < size) {
750 fieldString.append('-');
751 }
752 }
753 return fieldString;
754 }
755
756
757
758
759
760 public Integer getNonFatalErrorCount() {
761 return new Integer(this.nonFatalErrorCount);
762 }
763 }