1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.businessobject;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.LinkedHashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.rice.core.api.datetime.DateTimeService;
28 import org.kuali.rice.core.api.util.type.KualiDecimal;
29 import org.kuali.rice.krad.bo.TransientBusinessObjectBase;
30
31
32
33
34 public class CashieringTransaction extends TransientBusinessObjectBase {
35 public static final String DETAIL_DOCUMENT_TYPE = "OLE_CMD";
36
37 private String campusCode;
38 private String referenceFinancialDocumentNumber;
39
40
41 private List<Check> moneyInChecks;
42 private CoinDetail moneyInCoin;
43 private CurrencyDetail moneyInCurrency;
44 private CashieringItemInProcess newItemInProcess;
45 private List<Check> baselineChecks;
46 private Check newCheck;
47 private KualiDecimal checkTotal;
48
49
50 private CoinDetail moneyOutCoin;
51 private CurrencyDetail moneyOutCurrency;
52 private List<CashieringItemInProcess> openItemsInProcess;
53
54 private java.util.Date transactionStarted;
55 private java.util.Date transactionEnded;
56
57
58 private Integer nextCheckSequenceId;
59
60
61
62
63
64 public CashieringTransaction(String campusCode, String referenceFinancialDocumentNumber) {
65 super();
66 this.campusCode = campusCode;
67 this.referenceFinancialDocumentNumber = referenceFinancialDocumentNumber;
68 this.transactionStarted = SpringContext.getBean(DateTimeService.class).getCurrentDate();
69
70 moneyInCoin = new CoinDetail();
71 moneyInCurrency = new CurrencyDetail();
72
73 moneyOutCoin = new CoinDetail();
74 moneyOutCurrency = new CurrencyDetail();
75
76 newItemInProcess = new CashieringItemInProcess();
77 moneyInChecks = new ArrayList<Check>();
78 newCheck = new CheckBase();
79 baselineChecks = new ArrayList<Check>();
80 openItemsInProcess = new ArrayList<CashieringItemInProcess>();
81 nextCheckSequenceId = new Integer(1);
82 }
83
84
85
86
87
88
89 public List<Check> getMoneyInChecks() {
90 return moneyInChecks;
91 }
92
93
94
95
96
97
98 public void setMoneyInChecks(List<Check> moneyInChecks) {
99 this.moneyInChecks = moneyInChecks;
100 }
101
102
103
104
105
106
107
108 public Check getMoneyInCheck(int index) {
109 if (index >= moneyInChecks.size()) {
110 for (int i = moneyInChecks.size(); i <= index; i++) {
111 moneyInChecks.add(createNewCheck());
112 }
113 }
114 return moneyInChecks.get(index);
115 }
116
117
118
119
120
121
122 public CoinDetail getMoneyInCoin() {
123 return moneyInCoin;
124 }
125
126
127
128
129
130
131 public void setMoneyInCoin(CoinDetail moneyInCoin) {
132 this.moneyInCoin = moneyInCoin;
133 }
134
135
136
137
138
139
140 public CurrencyDetail getMoneyInCurrency() {
141 return moneyInCurrency;
142 }
143
144
145
146
147
148
149 public void setMoneyInCurrency(CurrencyDetail moneyInCurrency) {
150 this.moneyInCurrency = moneyInCurrency;
151 }
152
153
154
155
156
157
158 public CoinDetail getMoneyOutCoin() {
159 return moneyOutCoin;
160 }
161
162
163
164
165
166
167 public void setMoneyOutCoin(CoinDetail moneyOutCoin) {
168 this.moneyOutCoin = moneyOutCoin;
169 }
170
171
172
173
174
175
176 public java.util.Date getTransactionEnded() {
177 return transactionEnded;
178 }
179
180
181
182
183
184
185 public void setTransactionEnded(java.util.Date transactionEnded) {
186 this.transactionEnded = transactionEnded;
187 }
188
189
190
191
192
193
194 public java.util.Date getTransactionStarted() {
195 return transactionStarted;
196 }
197
198
199
200
201
202
203 public void setTransactionStarted(java.util.Date transactionStarted) {
204 this.transactionStarted = transactionStarted;
205 }
206
207
208
209
210
211
212 public String getCampusCode() {
213 return campusCode;
214 }
215
216
217
218
219
220
221 public void setCampusCode(String campusCode) {
222 this.campusCode = campusCode;
223 }
224
225
226
227
228
229
230 public void setMoneyOutCurrency(CurrencyDetail moneyOutCurrency) {
231 this.moneyOutCurrency = moneyOutCurrency;
232 }
233
234
235
236
237
238
239 public String getReferenceFinancialDocumentNumber() {
240 return referenceFinancialDocumentNumber;
241 }
242
243
244
245
246
247
248 public void setReferenceFinancialDocumentNumber(String referenceFinancialDocumentNumber) {
249 this.referenceFinancialDocumentNumber = referenceFinancialDocumentNumber;
250 }
251
252
253
254
255
256
257 public CurrencyDetail getMoneyOutCurrency() {
258 return moneyOutCurrency;
259 }
260
261
262
263
264
265
266 public CashieringItemInProcess getNewItemInProcess() {
267 return newItemInProcess;
268 }
269
270
271
272
273
274
275 public void setNewItemInProcess(CashieringItemInProcess newItemInProcess) {
276 this.newItemInProcess = newItemInProcess;
277 }
278
279
280
281
282
283
284 public List<CashieringItemInProcess> getOpenItemsInProcess() {
285 return openItemsInProcess;
286 }
287
288
289
290
291
292
293 public void setOpenItemsInProcess(List<CashieringItemInProcess> openItemsInProcess) {
294 this.openItemsInProcess = openItemsInProcess;
295 }
296
297
298
299
300
301
302 public CashieringItemInProcess getOpenItemInProcess(int index) {
303 extendOpenItemsList(index);
304 return this.openItemsInProcess.get(index);
305 }
306
307
308
309
310
311
312 private void extendOpenItemsList(int minSize) {
313 while (this.openItemsInProcess.size() <= minSize) {
314 this.openItemsInProcess.add(new CashieringItemInProcess());
315 }
316 }
317
318
319
320
321
322
323 public Check getNewCheck() {
324 return newCheck;
325 }
326
327
328
329
330
331
332 public void setNewCheck(Check newCheck) {
333 this.newCheck = newCheck;
334 }
335
336
337
338
339
340 public void prepareForSave() {
341 moneyInCoin.setDocumentNumber(this.referenceFinancialDocumentNumber);
342 moneyInCoin.setFinancialDocumentTypeCode(DETAIL_DOCUMENT_TYPE);
343 moneyInCoin.setCashieringStatus(OLEConstants.CurrencyCoinSources.CASH_MANAGEMENT_IN);
344
345 moneyInCurrency.setDocumentNumber(this.referenceFinancialDocumentNumber);
346 moneyInCurrency.setFinancialDocumentTypeCode(DETAIL_DOCUMENT_TYPE);
347 moneyInCurrency.setCashieringStatus(OLEConstants.CurrencyCoinSources.CASH_MANAGEMENT_IN);
348
349 moneyOutCoin.setDocumentNumber(this.referenceFinancialDocumentNumber);
350 moneyOutCoin.setFinancialDocumentTypeCode(DETAIL_DOCUMENT_TYPE);
351 moneyOutCoin.setCashieringStatus(OLEConstants.CurrencyCoinSources.DEPOSITS);
352
353 moneyOutCurrency.setDocumentNumber(this.referenceFinancialDocumentNumber);
354 moneyOutCurrency.setFinancialDocumentTypeCode(DETAIL_DOCUMENT_TYPE);
355 moneyOutCurrency.setCashieringStatus(OLEConstants.CurrencyCoinSources.DEPOSITS);
356
357 newItemInProcess.setCampusCode(this.campusCode);
358 }
359
360
361
362
363
364 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
365 LinkedHashMap pkMap = new LinkedHashMap();
366 pkMap.put("campusCode", this.campusCode);
367 pkMap.put("referenceFinancialDocumentNumber", this.referenceFinancialDocumentNumber);
368 pkMap.put("transactionStarted", this.transactionStarted);
369 return pkMap;
370 }
371
372
373
374
375
376
377 public List getChecks() {
378 return getMoneyInChecks();
379 }
380
381
382
383
384
385
386 public void setChecks(List checks) {
387 moneyInChecks = new ArrayList<Check>();
388 for (Object o : checks) {
389 moneyInChecks.add((Check) o);
390 }
391 }
392
393
394
395
396
397
398 public int getCheckCount() {
399 int count = 0;
400 if (moneyInChecks != null) {
401 count = moneyInChecks.size();
402 }
403 return count;
404 }
405
406
407
408
409
410
411
412 public void addCheck(Check check) {
413 check.setSequenceId(this.nextCheckSequenceId);
414
415 this.moneyInChecks.add(check);
416
417 this.nextCheckSequenceId = new Integer(this.nextCheckSequenceId.intValue() + 1);
418 }
419
420
421
422
423
424
425
426 public Check getCheck(int index) {
427 while (this.moneyInChecks.size() <= index) {
428 moneyInChecks.add(createNewCheck());
429 }
430 return (Check) moneyInChecks.get(index);
431 }
432
433
434
435
436
437 private Map buildCheckMap(List checks) {
438 Map checkMap = new HashMap();
439
440 for (Iterator i = checks.iterator(); i.hasNext();) {
441 Check check = (Check) i.next();
442 Integer sequenceId = check.getSequenceId();
443
444 Object oldCheck = checkMap.put(sequenceId, check);
445
446
447 if (oldCheck != null) {
448 throw new IllegalStateException("sequence id collision detected for sequence id " + sequenceId);
449 }
450 }
451
452 return checkMap;
453 }
454
455
456
457
458
459
460 public void removeCheck(int index) {
461 Check check = (Check) moneyInChecks.remove(index);
462 KualiDecimal newTotalCheckAmount = getTotalCheckAmount().subtract(check.getAmount());
463
464 if (newTotalCheckAmount.isNegative()) {
465 newTotalCheckAmount = KualiDecimal.ZERO;
466 }
467 }
468
469 public KualiDecimal getTotalCheckAmount() {
470 KualiDecimal result = KualiDecimal.ZERO;
471 for (Check c : moneyInChecks) {
472 if (c != null && c.getAmount() != null) {
473 result = result.add(c.getAmount());
474 }
475 }
476 return result;
477 }
478
479
480
481
482
483
484 public Integer getNextCheckSequenceId() {
485 return nextCheckSequenceId;
486 }
487
488
489
490
491
492
493 public void setNextCheckSequenceId(Integer nextCheckSequenceId) {
494 this.nextCheckSequenceId = nextCheckSequenceId;
495 }
496
497 public Check createNewCheck() {
498 Check newCheck = new CheckBase();
499 newCheck.setFinancialDocumentTypeCode(DETAIL_DOCUMENT_TYPE);
500 newCheck.setCashieringStatus(OLEConstants.CheckSources.CASH_MANAGEMENT);
501 return newCheck;
502 }
503
504
505
506
507
508
509 public KualiDecimal getPaidBackItemsInProcessAmount() {
510 KualiDecimal amount = KualiDecimal.ZERO;
511 if (this.openItemsInProcess != null) {
512 for (CashieringItemInProcess itemInProcess : this.openItemsInProcess) {
513 if (itemInProcess.getCurrentPayment() != null && itemInProcess.getCurrentPayment().isGreaterThan(KualiDecimal.ZERO)) {
514 amount = amount.add(itemInProcess.getCurrentPayment());
515 }
516 }
517 }
518 return amount;
519 }
520
521
522
523
524 public List getBaselineChecks() {
525 return baselineChecks;
526 }
527
528
529
530
531
532
533 public void setBaselineChecks(List baselineChecks) {
534 this.baselineChecks = baselineChecks;
535 }
536
537
538
539
540
541 public boolean hasBaselineCheck(int index) {
542 boolean has = false;
543
544 if ((index >= 0) && (index <= baselineChecks.size())) {
545 has = true;
546 }
547
548 return has;
549 }
550
551
552
553
554
555
556
557
558 public Check getBaselineCheck(int index) {
559 while (baselineChecks.size() <= index) {
560 baselineChecks.add(this.createNewCheck());
561 }
562 return (Check) baselineChecks.get(index);
563 }
564
565
566
567
568
569
570 public KualiDecimal getMoneyInTotal() {
571 KualiDecimal result = KualiDecimal.ZERO;
572 result = result.add(this.moneyInCurrency.getTotalAmount());
573 result = result.add(this.moneyInCoin.getTotalAmount());
574 result = result.add(this.getTotalCheckAmount());
575 if (this.newItemInProcess.isPopulated()) {
576 result = result.add(this.newItemInProcess.getItemAmount());
577 }
578 return result;
579 }
580
581
582
583
584
585
586 public KualiDecimal getMoneyOutTotal() {
587 KualiDecimal result = KualiDecimal.ZERO;
588 result = result.add(this.moneyOutCurrency.getTotalAmount());
589 result = result.add(this.moneyOutCoin.getTotalAmount());
590 result = result.add(this.getPaidBackItemsInProcessAmount());
591 return result;
592 }
593
594
595
596
597
598 public void setCheckTotal(KualiDecimal checkTotal) {
599 this.checkTotal = checkTotal;
600 }
601
602 }