1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.service.impl;
17
18 import java.util.Date;
19 import java.util.Iterator;
20
21 import org.kuali.ole.coa.service.AccountingPeriodService;
22 import org.kuali.ole.gl.businessobject.LedgerEntryForReporting;
23 import org.kuali.ole.gl.businessobject.LedgerEntryHolder;
24 import org.kuali.ole.gl.businessobject.Reversal;
25 import org.kuali.ole.gl.businessobject.Transaction;
26 import org.kuali.ole.gl.dataaccess.ReversalDao;
27 import org.kuali.ole.gl.service.ReversalService;
28 import org.kuali.ole.sys.OLEConstants;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.sys.service.UniversityDateService;
31 import org.kuali.rice.krad.service.BusinessObjectService;
32 import org.springframework.transaction.annotation.Transactional;
33
34
35
36
37
38
39 @Transactional
40 public class ReversalServiceImpl implements ReversalService {
41 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ReversalServiceImpl.class);
42
43 private ReversalDao reversalDao;
44 private AccountingPeriodService accountingPeriodService;
45 private UniversityDateService universityDateService;
46
47
48
49
50
51
52
53 public void delete(Reversal re) {
54 LOG.debug("delete() started");
55
56 reversalDao.delete(re);
57 }
58
59
60
61
62
63
64
65 public Iterator getByDate(Date before) {
66 LOG.debug("getByDate() started");
67
68 return reversalDao.getByDate(before);
69 }
70
71 public Reversal getByTransaction(Transaction t) {
72 LOG.debug("getByTransaction() started");
73
74 return reversalDao.getByTransaction(t);
75 }
76
77
78
79
80
81
82
83 public LedgerEntryHolder getSummaryByDate(Date before) {
84 LOG.debug("getSummaryByDate() started");
85
86 LedgerEntryHolder ledgerEntryHolder = new LedgerEntryHolder();
87
88 Iterator reversalsIterator = reversalDao.getByDate(before);
89 while (reversalsIterator.hasNext()) {
90 Reversal reversal = (Reversal) reversalsIterator.next();
91 LedgerEntryForReporting ledgerEntry = buildLedgerEntryFromReversal(reversal);
92 ledgerEntryHolder.insertLedgerEntry(ledgerEntry, true);
93 }
94 return ledgerEntryHolder;
95 }
96
97
98
99
100
101
102
103
104 protected LedgerEntryForReporting buildLedgerEntryFromReversal(Reversal reversal) {
105 LedgerEntryForReporting entry = new LedgerEntryForReporting(universityDateService.getFiscalYear(reversal.getFinancialDocumentReversalDate()), accountingPeriodService.getByDate(reversal.getFinancialDocumentReversalDate()).getUniversityFiscalPeriodCode(), reversal.getFinancialBalanceTypeCode(), reversal.getFinancialSystemOriginationCode());
106 if (OLEConstants.GL_CREDIT_CODE.equals(reversal.getTransactionDebitCreditCode())) {
107 entry.setCreditAmount(reversal.getTransactionLedgerEntryAmount());
108 entry.setCreditCount(1);
109 }
110 else if (OLEConstants.GL_DEBIT_CODE.equals(reversal.getTransactionDebitCreditCode())) {
111 entry.setDebitAmount(reversal.getTransactionLedgerEntryAmount());
112 entry.setDebitCount(1);
113 }
114 else {
115 entry.setNoDCAmount(reversal.getTransactionLedgerEntryAmount());
116 entry.setNoDCCount(1);
117 }
118 entry.setRecordCount(1);
119 return entry;
120 }
121
122
123
124
125
126
127
128 public void save(Reversal re) {
129 LOG.debug("save() started");
130
131 SpringContext.getBean(BusinessObjectService.class).save(re);
132 }
133
134
135
136
137
138
139
140 public void setReversalDao(ReversalDao reversalDao) {
141 this.reversalDao = reversalDao;
142 }
143
144
145
146
147
148
149
150 public void setAccountingPeriodService(AccountingPeriodService accountingPeriodService) {
151 this.accountingPeriodService = accountingPeriodService;
152 }
153
154
155
156
157
158
159
160 public void setUniversityDateService(UniversityDateService universityDateService) {
161 this.universityDateService = universityDateService;
162 }
163 }