1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document;
17
18 import static org.kuali.ole.sys.OLEConstants.EMPTY_STRING;
19 import static org.kuali.ole.sys.OLEConstants.GL_CREDIT_CODE;
20 import static org.kuali.ole.sys.OLEConstants.GL_DEBIT_CODE;
21 import static org.kuali.ole.sys.OLEPropertyConstants.BALANCE_TYPE;
22
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.kuali.ole.coa.businessobject.BalanceType;
29 import org.kuali.ole.fp.businessobject.JournalVoucherAccountingLineParser;
30 import org.kuali.ole.fp.businessobject.VoucherSourceAccountingLine;
31 import org.kuali.ole.sys.OLEConstants;
32 import org.kuali.ole.sys.businessobject.AccountingLine;
33 import org.kuali.ole.sys.businessobject.AccountingLineBase;
34 import org.kuali.ole.sys.businessobject.AccountingLineParser;
35 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
36 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper;
37 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
38 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
39 import org.kuali.ole.sys.businessobject.SufficientFundsItem;
40 import org.kuali.ole.sys.context.SpringContext;
41 import org.kuali.ole.sys.document.AccountingDocumentBase;
42 import org.kuali.ole.sys.document.AmountTotaling;
43 import org.kuali.ole.sys.document.Correctable;
44 import org.kuali.ole.sys.document.service.DebitDeterminerService;
45 import org.kuali.ole.sys.service.OptionsService;
46 import org.kuali.rice.core.api.util.type.KualiDecimal;
47 import org.kuali.rice.kew.api.exception.WorkflowException;
48 import org.kuali.rice.krad.document.Copyable;
49
50
51
52
53
54
55
56 public class JournalVoucherDocument extends AccountingDocumentBase implements VoucherDocument, Copyable, Correctable, AmountTotaling {
57 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(JournalVoucherDocument.class);
58
59
60 protected String balanceTypeCode;
61 protected BalanceType balanceType;
62 protected java.sql.Date reversalDate;
63
64
65
66
67 public JournalVoucherDocument() {
68 super();
69 this.balanceType = new BalanceType();
70 }
71
72
73
74
75 @Override
76 public List<SufficientFundsItem> checkSufficientFunds() {
77 LOG.debug("checkSufficientFunds() started");
78
79
80 return new ArrayList<SufficientFundsItem>();
81 }
82
83
84
85
86 @Override
87 public Class getSourceAccountingLineClass() {
88 return VoucherSourceAccountingLine.class;
89 }
90
91
92
93
94
95
96 public BalanceType getBalanceType() {
97 return balanceType;
98 }
99
100
101
102
103
104
105
106 @Deprecated
107 public void setBalanceType(BalanceType balanceType) {
108 this.balanceType = balanceType;
109 }
110
111
112
113
114
115
116 public String getBalanceTypeCode() {
117 return balanceTypeCode;
118 }
119
120
121
122
123
124
125 public void setBalanceTypeCode(String balanceTypeCode) {
126 this.balanceTypeCode = balanceTypeCode;
127 }
128
129
130
131
132
133
134 public java.sql.Date getReversalDate() {
135 return reversalDate;
136 }
137
138
139
140
141
142
143 public void setReversalDate(java.sql.Date reversalDate) {
144 this.reversalDate = reversalDate;
145 }
146
147
148
149
150
151
152 @Override
153 public String getSourceAccountingLinesSectionTitle() {
154 return EMPTY_STRING;
155 }
156
157
158
159
160
161
162 @Override
163 public String getTargetAccountingLinesSectionTitle() {
164 return EMPTY_STRING;
165 }
166
167
168
169
170
171
172
173 public KualiDecimal getDebitTotal() {
174 KualiDecimal debitTotal = KualiDecimal.ZERO;
175 AccountingLineBase al = null;
176 Iterator iter = sourceAccountingLines.iterator();
177 while (iter.hasNext()) {
178 al = (AccountingLineBase) iter.next();
179 if (StringUtils.isNotBlank(al.getDebitCreditCode()) && al.getDebitCreditCode().equals(GL_DEBIT_CODE)) {
180 debitTotal = debitTotal.add(al.getAmount());
181 }
182 }
183
184 return debitTotal;
185 }
186
187
188
189
190
191
192
193 public KualiDecimal getCreditTotal() {
194 KualiDecimal creditTotal = KualiDecimal.ZERO;
195 AccountingLineBase al = null;
196 Iterator iter = sourceAccountingLines.iterator();
197 while (iter.hasNext()) {
198 al = (AccountingLineBase) iter.next();
199 if (StringUtils.isNotBlank(al.getDebitCreditCode()) && al.getDebitCreditCode().equals(GL_CREDIT_CODE)) {
200 creditTotal = creditTotal.add(al.getAmount());
201 }
202 }
203 return creditTotal;
204 }
205
206
207
208
209
210
211
212
213 public KualiDecimal getTotalDollarAmount() {
214
215 KualiDecimal total = KualiDecimal.ZERO;
216
217 this.refreshReferenceObject("balanceType");
218
219 if (this.balanceType.isFinancialOffsetGenerationIndicator()) {
220 if (getCreditTotal().isGreaterThan(getDebitTotal())) {
221 total = getCreditTotal();
222 }
223 else {
224 total = getDebitTotal();
225 }
226 }
227 else {
228 total = getDebitTotal();
229 }
230 return total;
231 }
232
233
234
235
236
237
238 @Override
239 public AccountingLineParser getAccountingLineParser() {
240 return new JournalVoucherAccountingLineParser(getBalanceTypeCode());
241 }
242
243
244
245
246 @Override
247 public void toErrorCorrection() throws WorkflowException {
248 super.toErrorCorrection();
249 processJournalVoucherErrorCorrections();
250 }
251
252
253
254
255
256
257 protected void processJournalVoucherErrorCorrections() {
258 Iterator i = getSourceAccountingLines().iterator();
259
260 this.refreshReferenceObject(BALANCE_TYPE);
261
262 if (this.getBalanceType().isFinancialOffsetGenerationIndicator()) {
263 int index = 0;
264 while (i.hasNext()) {
265 SourceAccountingLine sLine = (SourceAccountingLine) i.next();
266
267 String debitCreditCode = sLine.getDebitCreditCode();
268
269 if (StringUtils.isNotBlank(debitCreditCode)) {
270
271 sLine.setAmount(sLine.getAmount().negated());
272
273
274 if (GL_DEBIT_CODE.equals(debitCreditCode)) {
275 sLine.setDebitCreditCode(GL_CREDIT_CODE);
276 }
277 else if (GL_CREDIT_CODE.equals(debitCreditCode)) {
278 sLine.setDebitCreditCode(GL_DEBIT_CODE);
279 }
280 else {
281 throw new IllegalStateException("SourceAccountingLine at index " + index + " does not have a debit/credit " + "code associated with it. This should never have occured. Please contact your system administrator.");
282
283 }
284 index++;
285 }
286 }
287 }
288 }
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311 public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) throws IllegalStateException {
312 AccountingLine accountingLine = (AccountingLine)postable;
313 String debitCreditCode = accountingLine.getDebitCreditCode();
314
315 DebitDeterminerService isDebitUtils = SpringContext.getBean(DebitDeterminerService.class);
316 boolean isDebit = StringUtils.isBlank(debitCreditCode) || isDebitUtils.isDebitCode(debitCreditCode);
317
318 return isDebit;
319 }
320
321
322
323
324
325
326
327
328
329
330
331
332
333 @Override
334 public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) {
335 AccountingLine accountingLine = (AccountingLine)postable;
336
337
338 explicitEntry.setUniversityFiscalPeriodCode(getPostingPeriodCode());
339 explicitEntry.setUniversityFiscalYear(getPostingYear());
340
341
342 explicitEntry.setFinancialObjectTypeCode(accountingLine.getObjectTypeCode());
343
344
345 explicitEntry.setFinancialBalanceTypeCode(accountingLine.getBalanceTypeCode());
346
347
348 refreshReferenceObject(BALANCE_TYPE);
349 if (getBalanceType().isFinancialOffsetGenerationIndicator()) {
350 explicitEntry.setTransactionDebitCreditCode(StringUtils.isNotBlank(accountingLine.getDebitCreditCode()) ? accountingLine.getDebitCreditCode() : OLEConstants.BLANK_SPACE);
351 }
352 else {
353 explicitEntry.setTransactionDebitCreditCode(OLEConstants.BLANK_SPACE);
354 }
355
356
357 explicitEntry.setTransactionEncumbranceUpdateCode(StringUtils.isNotBlank(accountingLine.getEncumbranceUpdateCode()) ? accountingLine.getEncumbranceUpdateCode() : OLEConstants.BLANK_SPACE);
358
359
360 if (getReversalDate() != null) {
361 explicitEntry.setFinancialDocumentReversalDate(getReversalDate());
362 }
363 }
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380 @Override
381 public boolean processOffsetGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySequenceHelper sequenceHelper, GeneralLedgerPendingEntrySourceDetail glpeSourceDetail, GeneralLedgerPendingEntry explicitEntry, GeneralLedgerPendingEntry offsetEntry) {
382 sequenceHelper.decrement();
383 return true;
384 }
385
386
387
388
389
390 @Override
391 public KualiDecimal getGeneralLedgerPendingEntryAmountForDetail(GeneralLedgerPendingEntrySourceDetail accountingLine) {
392 LOG.debug("getGeneralLedgerPendingEntryAmountForAccountingLine(AccountingLine) - start");
393 KualiDecimal returnKualiDecimal;
394
395 String budgetCodes = SpringContext.getBean(OptionsService.class).getOptions(accountingLine.getPostingYear()).getBudgetCheckingBalanceTypeCd();
396 if (!this.balanceType.isFinancialOffsetGenerationIndicator()) {
397 returnKualiDecimal = accountingLine.getAmount();
398 }
399 else {
400 returnKualiDecimal = accountingLine.getAmount().abs();
401 }
402 LOG.debug("getGeneralLedgerPendingEntryAmountForAccountingLine(AccountingLine) - end");
403 return returnKualiDecimal;
404 }
405 }