1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.batch.service.impl;
17
18 import java.util.Collection;
19 import java.util.Date;
20 import java.util.Iterator;
21
22 import org.apache.commons.lang.ArrayUtils;
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.ole.gl.GeneralLedgerConstants;
25 import org.kuali.ole.gl.batch.PosterEntriesStep;
26 import org.kuali.ole.gl.batch.service.AccountingCycleCachingService;
27 import org.kuali.ole.gl.batch.service.EncumbranceCalculator;
28 import org.kuali.ole.gl.batch.service.PostTransaction;
29 import org.kuali.ole.gl.businessobject.Encumbrance;
30 import org.kuali.ole.gl.businessobject.Entry;
31 import org.kuali.ole.gl.businessobject.Transaction;
32 import org.kuali.ole.sys.OLEConstants;
33 import org.kuali.ole.sys.service.ReportWriterService;
34 import org.kuali.rice.core.api.datetime.DateTimeService;
35 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
36 import org.kuali.rice.krad.service.PersistenceStructureService;
37 import org.springframework.transaction.annotation.Transactional;
38
39
40
41
42 @Transactional
43 public class PostEncumbrance implements PostTransaction, EncumbranceCalculator {
44 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PostEncumbrance.class);
45
46 private AccountingCycleCachingService accountingCycleCachingService;
47 private DateTimeService dateTimeService;
48 private PersistenceStructureService persistenceStructureService;
49 private ParameterService parameterService;
50
51
52
53
54 public PostEncumbrance() {
55 super();
56 }
57
58
59
60
61
62
63
64
65
66
67 public String post(Transaction t, int mode, Date postDate, ReportWriterService posterReportWriterService) {
68 LOG.debug("post() started");
69
70 String returnCode = GeneralLedgerConstants.UPDATE_CODE;
71
72
73
74 if ((StringUtils.isBlank(t.getTransactionEncumbranceUpdateCode())) || " ".equals(t.getTransactionEncumbranceUpdateCode()) || OLEConstants.ENCUMB_UPDT_NO_ENCUMBRANCE_CD.equals(t.getTransactionEncumbranceUpdateCode()) || t.getOption().getFinObjectTypeFundBalanceCd().equals(t.getFinancialObjectTypeCode())) {
75 LOG.debug("post() not posting non-encumbrance transaction");
76 return "";
77 }
78
79
80 Entry e = new Entry(t, null);
81 if (OLEConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(t.getTransactionEncumbranceUpdateCode())) {
82 e.setDocumentNumber(t.getReferenceFinancialDocumentNumber());
83 e.setFinancialSystemOriginationCode(t.getReferenceFinancialSystemOriginationCode());
84 e.setFinancialDocumentTypeCode(t.getReferenceFinancialDocumentTypeCode());
85 }
86
87 Encumbrance enc = accountingCycleCachingService.getEncumbrance(e);
88 if (enc == null) {
89
90 enc = new Encumbrance(e);
91
92 returnCode = GeneralLedgerConstants.INSERT_CODE;
93 }
94 else {
95
96 if (enc.getTransactionEncumbranceDate() == null) {
97 enc.setTransactionEncumbranceDate(t.getTransactionDate());
98 }
99
100 returnCode = GeneralLedgerConstants.UPDATE_CODE;
101 }
102
103 updateEncumbrance(t, enc);
104
105 if (returnCode.equals(GeneralLedgerConstants.INSERT_CODE)) {
106 accountingCycleCachingService.insertEncumbrance(enc);
107 } else {
108 accountingCycleCachingService.updateEncumbrance(enc);
109 }
110
111 return returnCode;
112 }
113
114
115
116
117
118
119
120
121
122 public Encumbrance findEncumbrance(Collection encumbranceList, Transaction t) {
123
124
125 if ((!OLEConstants.ENCUMB_UPDT_DOCUMENT_CD.equals(t.getTransactionEncumbranceUpdateCode())) && (!OLEConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(t.getTransactionEncumbranceUpdateCode()))) {
126 return null;
127 }
128
129
130 for (Iterator iter = encumbranceList.iterator(); iter.hasNext();) {
131 Encumbrance e = (Encumbrance) iter.next();
132
133 if (OLEConstants.ENCUMB_UPDT_DOCUMENT_CD.equals(t.getTransactionEncumbranceUpdateCode()) && e.getUniversityFiscalYear().equals(t.getUniversityFiscalYear()) && e.getChartOfAccountsCode().equals(t.getChartOfAccountsCode()) && e.getAccountNumber().equals(t.getAccountNumber()) && e.getSubAccountNumber().equals(t.getSubAccountNumber()) && e.getObjectCode().equals(t.getFinancialObjectCode()) && e.getSubObjectCode().equals(t.getFinancialSubObjectCode()) && e.getBalanceTypeCode().equals(t.getFinancialBalanceTypeCode()) && e.getDocumentTypeCode().equals(t.getFinancialDocumentTypeCode()) && e.getOriginCode().equals(t.getFinancialSystemOriginationCode()) && e.getDocumentNumber().equals(t.getDocumentNumber())) {
134 return e;
135 }
136
137 if (OLEConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(t.getTransactionEncumbranceUpdateCode()) && e.getUniversityFiscalYear().equals(t.getUniversityFiscalYear()) && e.getChartOfAccountsCode().equals(t.getChartOfAccountsCode()) && e.getAccountNumber().equals(t.getAccountNumber()) && e.getSubAccountNumber().equals(t.getSubAccountNumber()) && e.getObjectCode().equals(t.getFinancialObjectCode()) && e.getSubObjectCode().equals(t.getFinancialSubObjectCode()) && e.getBalanceTypeCode().equals(t.getFinancialBalanceTypeCode()) && e.getDocumentTypeCode().equals(t.getReferenceFinancialDocumentTypeCode()) && e.getOriginCode().equals(t.getReferenceFinancialSystemOriginationCode()) && e.getDocumentNumber().equals(t.getReferenceFinancialDocumentNumber())) {
138 return e;
139 }
140 }
141
142
143
144
145
146 Entry e = new Entry(t, dateTimeService.getCurrentDate());
147 if (OLEConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(t.getTransactionEncumbranceUpdateCode())) {
148 e.setDocumentNumber(t.getReferenceFinancialDocumentNumber());
149 e.setFinancialSystemOriginationCode(t.getReferenceFinancialSystemOriginationCode());
150 e.setFinancialDocumentTypeCode(t.getReferenceFinancialDocumentTypeCode());
151 }
152
153 Encumbrance enc = new Encumbrance(e);
154 encumbranceList.add(enc);
155 return enc;
156 }
157
158
159
160
161
162 public void updateEncumbrance(Transaction t, Encumbrance enc) {
163
164 String[] encumbranceOpenAmountOeverridingDocTypes = parameterService.getParameterValuesAsString(PosterEntriesStep.class, GeneralLedgerConstants.PosterService.ENCUMBRANCE_OPEN_AMOUNT_OVERRIDING_DOCUMENT_TYPES).toArray(new String[] {});
165
166 if (OLEConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(t.getTransactionEncumbranceUpdateCode()) && !ArrayUtils.contains(encumbranceOpenAmountOeverridingDocTypes, t.getFinancialDocumentTypeCode())) {
167
168
169 if (OLEConstants.GL_DEBIT_CODE.equals(t.getTransactionDebitCreditCode())) {
170 enc.setAccountLineEncumbranceClosedAmount(enc.getAccountLineEncumbranceClosedAmount().subtract(t.getTransactionLedgerEntryAmount()));
171 }
172 else {
173 enc.setAccountLineEncumbranceClosedAmount(enc.getAccountLineEncumbranceClosedAmount().add(t.getTransactionLedgerEntryAmount()));
174 }
175 }
176 else {
177
178
179 if (OLEConstants.GL_DEBIT_CODE.equals(t.getTransactionDebitCreditCode()) || OLEConstants.GL_BUDGET_CODE.equals(t.getTransactionDebitCreditCode())) {
180 enc.setAccountLineEncumbranceAmount(enc.getAccountLineEncumbranceAmount().add(t.getTransactionLedgerEntryAmount()));
181 }
182 else {
183 enc.setAccountLineEncumbranceAmount(enc.getAccountLineEncumbranceAmount().subtract(t.getTransactionLedgerEntryAmount()));
184 }
185 }
186 }
187
188
189
190
191 public String getDestinationName() {
192 return persistenceStructureService.getTableName(Encumbrance.class);
193 }
194
195
196 public void setDateTimeService(DateTimeService dateTimeService) {
197 this.dateTimeService = dateTimeService;
198 }
199
200 public void setAccountingCycleCachingService(AccountingCycleCachingService accountingCycleCachingService) {
201 this.accountingCycleCachingService = accountingCycleCachingService;
202 }
203
204 public void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) {
205 this.persistenceStructureService = persistenceStructureService;
206 }
207
208 public void setParameterService(ParameterService parameterService) {
209 this.parameterService = parameterService;
210 }
211 }