1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.kuali.ole.pdp.businessobject;
21
22 import java.sql.Date;
23 import java.sql.Timestamp;
24 import java.text.ParseException;
25 import java.util.ArrayList;
26 import java.util.Calendar;
27 import java.util.LinkedHashMap;
28 import java.util.List;
29
30 import org.apache.commons.lang.StringUtils;
31 import org.kuali.ole.pdp.PdpConstants;
32 import org.kuali.ole.pdp.PdpParameterConstants;
33 import org.kuali.ole.pdp.service.PaymentGroupService;
34 import org.kuali.ole.sys.OLEConstants;
35 import org.kuali.ole.sys.OLEPropertyConstants;
36 import org.kuali.ole.sys.businessobject.TimestampedBusinessObjectBase;
37 import org.kuali.ole.sys.context.SpringContext;
38 import org.kuali.rice.core.api.datetime.DateTimeService;
39 import org.kuali.rice.core.api.util.type.KualiDecimal;
40 import org.kuali.rice.core.api.util.type.KualiInteger;
41 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
42 import org.kuali.rice.krad.util.ObjectUtils;
43
44 public class PaymentDetail extends TimestampedBusinessObjectBase {
45 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PaymentDetail.class);
46 private static KualiDecimal zero = KualiDecimal.ZERO;
47
48 private KualiInteger id;
49 private String invoiceNbr;
50 private Date invoiceDate;
51 private String purchaseOrderNbr;
52 private String custPaymentDocNbr;
53 private String financialSystemOriginCode;
54 private String financialDocumentTypeCode;
55 private String requisitionNbr;
56 private String organizationDocNbr;
57 private String customerInstitutionNumber;
58 private KualiDecimal origInvoiceAmount;
59 private KualiDecimal netPaymentAmount;
60 private KualiDecimal invTotDiscountAmount;
61 private KualiDecimal invTotShipAmount;
62 private KualiDecimal invTotOtherDebitAmount;
63 private KualiDecimal invTotOtherCreditAmount;
64 private Boolean primaryCancelledPayment;
65 private String paymentMethodCode;
66
67 private List<PaymentAccountDetail> accountDetail = new ArrayList<PaymentAccountDetail>();
68 private List<PaymentNoteText> notes = new ArrayList<PaymentNoteText>();
69
70 private KualiInteger paymentGroupId;
71 private PaymentGroup paymentGroup;
72
73 public PaymentDetail() {
74 super();
75 }
76
77 public boolean isDetailAmountProvided() {
78 return (origInvoiceAmount != null) || (invTotDiscountAmount != null) || (invTotShipAmount != null) || (invTotOtherDebitAmount != null) || (invTotOtherCreditAmount != null);
79 }
80
81 public KualiDecimal getCalculatedPaymentAmount() {
82 KualiDecimal orig_invoice_amt = origInvoiceAmount == null ? zero : origInvoiceAmount;
83 KualiDecimal invoice_tot_discount_amt = invTotDiscountAmount == null ? zero : invTotDiscountAmount;
84 KualiDecimal invoice_tot_ship_amt = invTotShipAmount == null ? zero : invTotShipAmount;
85 KualiDecimal invoice_tot_other_debits = invTotOtherDebitAmount == null ? zero : invTotOtherDebitAmount;
86 KualiDecimal invoice_tot_other_credits = invTotOtherCreditAmount == null ? zero : invTotOtherCreditAmount;
87
88 KualiDecimal t = orig_invoice_amt.subtract(invoice_tot_discount_amt);
89 t = t.add(invoice_tot_ship_amt);
90 t = t.add(invoice_tot_other_debits);
91 t = t.subtract(invoice_tot_other_credits);
92
93 return t;
94 }
95
96
97
98
99
100
101
102 public boolean isDisbursementActionAllowed() {
103 if (paymentGroup.getDisbursementDate() == null) {
104 if (PdpConstants.PaymentStatusCodes.EXTRACTED.equals(paymentGroup.getPaymentStatus().getCode())) {
105 return false;
106 }
107 return true;
108 }
109
110 String daysStr = SpringContext.getBean(ParameterService.class).getParameterValueAsString(PaymentDetail.class, PdpParameterConstants.DISBURSEMENT_CANCELLATION_DAYS);
111 int days = Integer.valueOf(daysStr);
112
113 Calendar c = Calendar.getInstance();
114 c.add(Calendar.DATE, (days * -1));
115 c.set(Calendar.HOUR, 12);
116 c.set(Calendar.MINUTE, 0);
117 c.set(Calendar.SECOND, 0);
118 c.set(Calendar.MILLISECOND, 0);
119 c.set(Calendar.AM_PM, Calendar.AM);
120 Timestamp lastDisbursementActionDate = new Timestamp(c.getTimeInMillis());
121
122 Calendar c2 = Calendar.getInstance();
123 c2.setTime(paymentGroup.getDisbursementDate());
124 c2.set(Calendar.HOUR, 11);
125 c2.set(Calendar.MINUTE, 59);
126 c2.set(Calendar.SECOND, 59);
127 c2.set(Calendar.MILLISECOND, 59);
128 c2.set(Calendar.AM_PM, Calendar.PM);
129 Timestamp disbursementDate = new Timestamp(c2.getTimeInMillis());
130
131
132 return ((disbursementDate.compareTo(lastDisbursementActionDate)) >= 0);
133 }
134
135
136
137
138 public KualiDecimal getAccountTotal() {
139 KualiDecimal acctTotal = new KualiDecimal(0.00);
140
141 for (PaymentAccountDetail paymentAccountDetail : accountDetail) {
142 if (paymentAccountDetail.getAccountNetAmount() != null) {
143 acctTotal = acctTotal.add(paymentAccountDetail.getAccountNetAmount());
144 }
145 }
146
147 return acctTotal;
148 }
149
150 public Date getInvoiceDate() {
151 return invoiceDate;
152 }
153
154 public void setInvoiceDate(Date invoiceDate) {
155 this.invoiceDate = invoiceDate;
156 }
157
158
159
160
161
162
163
164 public void setInvoiceDate(String invoiceDate) throws ParseException {
165 this.invoiceDate = SpringContext.getBean(DateTimeService.class).convertToSqlDate(invoiceDate);
166 }
167
168
169
170
171
172
173 public List<PaymentAccountDetail> getAccountDetail() {
174 return accountDetail;
175 }
176
177 public void setAccountDetail(List<PaymentAccountDetail> ad) {
178 accountDetail = ad;
179 }
180
181 public void addAccountDetail(PaymentAccountDetail pad) {
182 pad.setPaymentDetail(this);
183 accountDetail.add(pad);
184 }
185
186 public void deleteAccountDetail(PaymentAccountDetail pad) {
187 accountDetail.remove(pad);
188 }
189
190 public List<PaymentNoteText> getNotes() {
191 return notes;
192 }
193
194 public void setNotes(List<PaymentNoteText> n) {
195 notes = n;
196 }
197
198 public void addNote(PaymentNoteText pnt) {
199 if (!StringUtils.isBlank(pnt.getCustomerNoteText())) {
200 pnt.setPaymentDetail(this);
201 notes.add(pnt);
202 } else {
203 LOG.warn("Did not add note to payment detail build from Document #: "+(!StringUtils.isBlank(custPaymentDocNbr) ? custPaymentDocNbr : "")+" because note was empty");
204 }
205 }
206
207
208
209
210
211
212 public void addPaymentText(String paymentText) {
213 PaymentNoteText paymentNoteText = new PaymentNoteText();
214
215 paymentNoteText.setCustomerNoteText(paymentText);
216 paymentNoteText.setCustomerNoteLineNbr(new KualiInteger(this.notes.size() + 1));
217
218 addNote(paymentNoteText);
219 }
220
221 public void deleteNote(PaymentNoteText pnt) {
222 notes.remove(pnt);
223 }
224
225
226
227
228
229
230 public KualiInteger getId() {
231 return id;
232 }
233
234
235
236
237
238 public String getCustPaymentDocNbr() {
239 return custPaymentDocNbr;
240 }
241
242
243
244
245
246 public String getInvoiceNbr() {
247 return invoiceNbr;
248 }
249
250
251
252
253
254 public KualiDecimal getInvTotDiscountAmount() {
255 return invTotDiscountAmount;
256 }
257
258
259
260
261
262 public KualiDecimal getInvTotOtherCreditAmount() {
263 return invTotOtherCreditAmount;
264 }
265
266
267
268
269
270 public KualiDecimal getInvTotOtherDebitAmount() {
271 return invTotOtherDebitAmount;
272 }
273
274
275
276
277
278 public KualiDecimal getInvTotShipAmount() {
279 return invTotShipAmount;
280 }
281
282
283
284
285
286 public KualiDecimal getNetPaymentAmount() {
287 return netPaymentAmount;
288 }
289
290
291
292
293
294 public String getOrganizationDocNbr() {
295 return organizationDocNbr;
296 }
297
298
299
300
301
302 public KualiDecimal getOrigInvoiceAmount() {
303 return origInvoiceAmount;
304 }
305
306
307
308
309
310 public String getPurchaseOrderNbr() {
311 return purchaseOrderNbr;
312 }
313
314
315
316
317
318 public String getRequisitionNbr() {
319 return requisitionNbr;
320 }
321
322
323
324
325 public PaymentGroup getPaymentGroup() {
326 return paymentGroup;
327 }
328
329
330
331
332 public void setCustPaymentDocNbr(String string) {
333 custPaymentDocNbr = string;
334 }
335
336
337
338
339 public void setId(KualiInteger integer) {
340 id = integer;
341 }
342
343
344
345
346 public void setInvoiceNbr(String string) {
347 invoiceNbr = string;
348 }
349
350
351
352
353 public void setInvTotDiscountAmount(KualiDecimal decimal) {
354 invTotDiscountAmount = decimal;
355 }
356
357 public void setInvTotDiscountAmount(String decimal) {
358 invTotDiscountAmount = new KualiDecimal(decimal);
359 }
360
361
362
363
364 public void setInvTotOtherCreditAmount(KualiDecimal decimal) {
365 invTotOtherCreditAmount = decimal;
366 }
367
368 public void setInvTotOtherCreditAmount(String decimal) {
369 invTotOtherCreditAmount = new KualiDecimal(decimal);
370 }
371
372
373
374
375 public void setInvTotOtherDebitAmount(KualiDecimal decimal) {
376 invTotOtherDebitAmount = decimal;
377 }
378
379 public void setInvTotOtherDebitAmount(String decimal) {
380 invTotOtherDebitAmount = new KualiDecimal(decimal);
381 }
382
383
384
385
386 public void setInvTotShipAmount(KualiDecimal decimal) {
387 invTotShipAmount = decimal;
388 }
389
390 public void setInvTotShipAmount(String decimal) {
391 invTotShipAmount = new KualiDecimal(decimal);
392 }
393
394
395
396
397 public void setNetPaymentAmount(KualiDecimal decimal) {
398 netPaymentAmount = decimal;
399 }
400
401 public void setNetPaymentAmount(String decimal) {
402 netPaymentAmount = new KualiDecimal(decimal);
403 }
404
405
406
407
408 public void setOrganizationDocNbr(String string) {
409 organizationDocNbr = string;
410 }
411
412
413
414
415 public void setOrigInvoiceAmount(KualiDecimal decimal) {
416 origInvoiceAmount = decimal;
417 }
418
419 public void setOrigInvoiceAmount(String decimal) {
420 origInvoiceAmount = new KualiDecimal(decimal);
421 }
422
423
424
425
426 public void setPurchaseOrderNbr(String string) {
427 purchaseOrderNbr = string;
428 }
429
430
431
432
433 public void setRequisitionNbr(String string) {
434 requisitionNbr = string;
435 }
436
437
438
439
440 public String getFinancialDocumentTypeCode() {
441 return financialDocumentTypeCode;
442 }
443
444
445
446
447 public void setFinancialDocumentTypeCode(String financialDocumentTypeCode) {
448 this.financialDocumentTypeCode = financialDocumentTypeCode;
449 }
450
451
452
453
454 public Boolean getPrimaryCancelledPayment() {
455 return primaryCancelledPayment;
456 }
457
458
459
460
461 public void setPrimaryCancelledPayment(Boolean primaryCancelledPayment) {
462 this.primaryCancelledPayment = primaryCancelledPayment;
463 }
464
465
466
467
468 public void setPaymentGroup(PaymentGroup paymentGroup) {
469 this.paymentGroup = paymentGroup;
470 }
471
472
473
474
475
476
477 public KualiInteger getPaymentGroupId() {
478 return paymentGroupId;
479 }
480
481
482
483
484
485
486 public void setPaymentGroupId(KualiInteger paymentGroupId) {
487 this.paymentGroupId = paymentGroupId;
488 }
489
490
491
492
493
494
495 public String getFinancialSystemOriginCode() {
496 return financialSystemOriginCode;
497 }
498
499
500
501
502
503
504 public void setFinancialSystemOriginCode(String financialSystemOriginCode) {
505 this.financialSystemOriginCode = financialSystemOriginCode;
506 }
507
508
509
510
511 public String getCustomerInstitutionNumber() {
512 return customerInstitutionNumber;
513 }
514
515
516
517
518 public void setCustomerInstitutionNumber(String customerInstitutionNumber) {
519 this.customerInstitutionNumber = customerInstitutionNumber;
520 }
521
522
523
524
525
526
527 public String getNotesText() {
528 StringBuffer notes = new StringBuffer();
529 List<PaymentNoteText> notesList = getNotes();
530 for (PaymentNoteText note : notesList) {
531 notes.append(note.getCustomerNoteText());
532 notes.append(OLEConstants.NEWLINE);
533 }
534 return notes.toString();
535 }
536
537
538
539
540
541 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
542 LinkedHashMap m = new LinkedHashMap();
543
544 m.put(OLEPropertyConstants.ID, this.id);
545
546 return m;
547 }
548
549
550
551
552
553
554 public int getNbrOfPaymentsInPaymentGroup() {
555 return paymentGroup.getPaymentDetails().size();
556 }
557
558
559
560
561
562
563 public int getNbrOfPaymentsInDisbursement() {
564
565 int nbrOfPaymentsInDisbursement = 0;
566 if (ObjectUtils.isNotNull((paymentGroup.getDisbursementNbr()))) {
567 List<PaymentGroup> paymentGroupList = SpringContext.getBean(PaymentGroupService.class).getByDisbursementNumber(paymentGroup.getDisbursementNbr().intValue());
568 for (PaymentGroup paymentGroup : paymentGroupList) {
569 nbrOfPaymentsInDisbursement += paymentGroup.getPaymentDetails().size();
570 }
571 }
572 return nbrOfPaymentsInDisbursement;
573 }
574
575 public String getPaymentMethodCode() {
576 return paymentMethodCode;
577 }
578
579 public void setPaymentMethodCode(String paymentMethodCode) {
580 this.paymentMethodCode = paymentMethodCode;
581 }
582 }