1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.pdp.service.impl;
17
18 import java.sql.Timestamp;
19 import java.text.MessageFormat;
20 import java.text.ParseException;
21 import java.util.ArrayList;
22 import java.util.Calendar;
23 import java.util.List;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.kuali.ole.coa.businessobject.Account;
27 import org.kuali.ole.coa.businessobject.ObjectCode;
28 import org.kuali.ole.coa.businessobject.ProjectCode;
29 import org.kuali.ole.coa.businessobject.SubAccount;
30 import org.kuali.ole.coa.businessobject.SubObjectCode;
31 import org.kuali.ole.coa.service.AccountService;
32 import org.kuali.ole.coa.service.ObjectCodeService;
33 import org.kuali.ole.coa.service.SubAccountService;
34 import org.kuali.ole.coa.service.SubObjectCodeService;
35 import org.kuali.ole.pdp.PdpConstants;
36 import org.kuali.ole.pdp.PdpKeyConstants;
37 import org.kuali.ole.pdp.PdpParameterConstants;
38 import org.kuali.ole.pdp.PdpPropertyConstants;
39 import org.kuali.ole.pdp.businessobject.AccountingChangeCode;
40 import org.kuali.ole.pdp.businessobject.CustomerProfile;
41 import org.kuali.ole.pdp.businessobject.PayeeType;
42 import org.kuali.ole.pdp.businessobject.PaymentAccountDetail;
43 import org.kuali.ole.pdp.businessobject.PaymentAccountHistory;
44 import org.kuali.ole.pdp.businessobject.PaymentDetail;
45 import org.kuali.ole.pdp.businessobject.PaymentFileLoad;
46 import org.kuali.ole.pdp.businessobject.PaymentGroup;
47 import org.kuali.ole.pdp.businessobject.PaymentStatus;
48 import org.kuali.ole.pdp.dataaccess.PaymentFileLoadDao;
49 import org.kuali.ole.pdp.service.CustomerProfileService;
50 import org.kuali.ole.pdp.service.PaymentFileValidationService;
51 import org.kuali.ole.sys.OLEConstants;
52 import org.kuali.ole.sys.businessobject.Bank;
53 import org.kuali.ole.sys.businessobject.OriginationCode;
54 import org.kuali.ole.sys.service.BankService;
55 import org.kuali.ole.sys.service.OriginationCodeService;
56 import org.kuali.ole.sys.service.impl.OleParameterConstants;
57 import org.kuali.rice.core.api.config.property.ConfigurationService;
58 import org.kuali.rice.core.api.datetime.DateTimeService;
59 import org.kuali.rice.core.api.util.type.KualiDecimal;
60 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
61 import org.kuali.rice.kew.api.doctype.DocumentTypeService;
62 import org.kuali.rice.krad.bo.KualiCodeBase;
63 import org.kuali.rice.krad.service.BusinessObjectService;
64 import org.kuali.rice.krad.util.MessageMap;
65 import org.springframework.transaction.annotation.Transactional;
66
67
68
69
70 @Transactional
71 public class PaymentFileValidationServiceImpl implements PaymentFileValidationService {
72 protected CustomerProfileService customerProfileService;
73 protected PaymentFileLoadDao paymentFileLoadDao;
74 protected ParameterService parameterService;
75 protected ConfigurationService kualiConfigurationService;
76 protected DateTimeService dateTimeService;
77 protected AccountService accountService;
78 protected SubAccountService subAccountService;
79 protected ObjectCodeService objectCodeService;
80 protected SubObjectCodeService subObjectCodeService;
81 protected BankService bankService;
82 protected OriginationCodeService originationCodeService;
83 protected DocumentTypeService documentTypeService;
84 protected BusinessObjectService businessObjectService;
85
86
87
88
89
90 @Override
91 public void doHardEdits(PaymentFileLoad paymentFile, MessageMap errorMap) {
92 processHeaderValidation(paymentFile, errorMap);
93
94 if (errorMap.hasNoErrors()) {
95 processGroupValidation(paymentFile, errorMap);
96 }
97
98 if (errorMap.hasNoErrors()) {
99 processTrailerValidation(paymentFile, errorMap);
100 }
101 }
102
103
104
105
106
107
108
109 protected void processHeaderValidation(PaymentFileLoad paymentFile, MessageMap errorMap) {
110 CustomerProfile customer = customerProfileService.get(paymentFile.getChart(), paymentFile.getUnit(), paymentFile.getSubUnit());
111 if (customer == null) {
112 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_CUSTOMER, paymentFile.getChart(), paymentFile.getUnit(), paymentFile.getSubUnit());
113 }
114 else {
115 if (!customer.isActive()) {
116 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INACTIVE_CUSTOMER, paymentFile.getChart(), paymentFile.getUnit(), paymentFile.getSubUnit());
117 }
118 else {
119 paymentFile.setCustomer(customer);
120 }
121 }
122 }
123
124
125
126
127
128
129
130
131 protected void processTrailerValidation(PaymentFileLoad paymentFile, MessageMap errorMap) {
132
133 if (paymentFile.getActualPaymentCount() != paymentFile.getPaymentCount()) {
134 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_PAYMENT_COUNT_MISMATCH, Integer.toString(paymentFile.getPaymentCount()), Integer.toString(paymentFile.getActualPaymentCount()));
135 }
136
137
138 if (paymentFile.getCalculatedPaymentTotalAmount().compareTo(paymentFile.getPaymentTotalAmount()) != 0) {
139 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_PAYMENT_TOTAL_MISMATCH, paymentFile.getPaymentTotalAmount().toString(), paymentFile.getCalculatedPaymentTotalAmount().toString());
140 }
141
142
143 Timestamp now = new Timestamp(paymentFile.getCreationDate().getTime());
144
145 if (paymentFileLoadDao.isDuplicateBatch(paymentFile.getCustomer(), paymentFile.getPaymentCount(), paymentFile.getPaymentTotalAmount().bigDecimalValue(), now)) {
146 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_DUPLICATE_BATCH);
147 }
148 }
149
150
151
152
153
154
155
156
157 protected void processGroupValidation(PaymentFileLoad paymentFile, MessageMap errorMap) {
158 int groupCount = 0;
159 for (PaymentGroup paymentGroup : paymentFile.getPaymentGroups()) {
160 groupCount++;
161
162 int noteLineCount = 0;
163 int detailCount = 0;
164
165
166 if (paymentFile.getCustomer().getPayeeIdRequired() && StringUtils.isBlank(paymentGroup.getPayeeId())) {
167 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_PAYEE_ID_REQUIRED, Integer.toString(groupCount));
168 }
169
170 if (paymentFile.getCustomer().getOwnershipCodeRequired() && StringUtils.isBlank(paymentGroup.getPayeeOwnerCd())) {
171 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_PAYEE_OWNER_CODE, Integer.toString(groupCount));
172 }
173
174
175 if (StringUtils.isNotBlank(paymentGroup.getPayeeIdTypeCd())) {
176 PayeeType payeeType = businessObjectService.findBySinglePrimaryKey(PayeeType.class, paymentGroup.getPayeeIdTypeCd());
177 if (payeeType == null) {
178 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_PAYEE_ID_TYPE, Integer.toString(groupCount), paymentGroup.getPayeeIdTypeCd());
179 }
180 }
181
182
183 String bankCode = paymentGroup.getBankCode();
184 if (StringUtils.isNotBlank(bankCode)) {
185 Bank bank = bankService.getByPrimaryId(bankCode);
186 if (bank == null) {
187 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_BANK_CODE, Integer.toString(groupCount), bankCode);
188 }
189 else if (!bank.isActive()) {
190 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INACTIVE_BANK_CODE, Integer.toString(groupCount), bankCode);
191 }
192 }
193
194 KualiDecimal groupTotal = KualiDecimal.ZERO;
195 for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
196 detailCount++;
197
198 noteLineCount++;
199 noteLineCount = noteLineCount + paymentDetail.getNotes().size();
200
201 if ((paymentDetail.getNetPaymentAmount() == null) && (!paymentDetail.isDetailAmountProvided())) {
202 paymentDetail.setNetPaymentAmount(paymentDetail.getAccountTotal());
203 }
204 else if ((paymentDetail.getNetPaymentAmount() == null) && (paymentDetail.isDetailAmountProvided())) {
205 paymentDetail.setNetPaymentAmount(paymentDetail.getCalculatedPaymentAmount());
206 }
207
208
209 if (paymentDetail.getAccountTotal().compareTo(paymentDetail.getNetPaymentAmount()) != 0) {
210 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_DETAIL_TOTAL_MISMATCH, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getAccountTotal().toString(), paymentDetail.getNetPaymentAmount().toString());
211 }
212
213
214 if (StringUtils.isNotBlank(paymentDetail.getFinancialSystemOriginCode())) {
215 OriginationCode originationCode = originationCodeService.getByPrimaryKey(paymentDetail.getFinancialSystemOriginCode());
216 if (originationCode == null) {
217 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_ORIGIN_CODE, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getFinancialSystemOriginCode());
218 }
219 }
220
221
222 if (StringUtils.isNotBlank(paymentDetail.getFinancialDocumentTypeCode())) {
223 if ( !documentTypeService.isActiveByName(paymentDetail.getFinancialDocumentTypeCode()) ) {
224 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_DOC_TYPE, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getFinancialDocumentTypeCode());
225 }
226 }
227
228 groupTotal = groupTotal.add(paymentDetail.getNetPaymentAmount());
229 }
230
231
232 if (groupTotal.doubleValue() < 0) {
233 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_NEGATIVE_GROUP_TOTAL, Integer.toString(groupCount));
234 }
235
236
237 if (noteLineCount > getMaxNoteLines()) {
238 errorMap.putError(OLEConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_MAX_NOTE_LINES, Integer.toString(groupCount), Integer.toString(noteLineCount), Integer.toString(getMaxNoteLines()));
239 }
240 }
241 }
242
243
244
245
246 @Override
247 public List<String> doSoftEdits(PaymentFileLoad paymentFile) {
248 List<String> warnings = new ArrayList<String>();
249
250 CustomerProfile customer = customerProfileService.get(paymentFile.getChart(), paymentFile.getUnit(), paymentFile.getSubUnit());
251
252
253 if (paymentFile.getPaymentTotalAmount().compareTo(customer.getFileThresholdAmount()) > 0) {
254 addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_FILE_THRESHOLD, paymentFile.getPaymentTotalAmount().toString(), customer.getFileThresholdAmount().toString());
255 paymentFile.setFileThreshold(true);
256 }
257
258 processGroupSoftEdits(paymentFile, customer, warnings);
259
260 return warnings;
261 }
262
263
264
265
266
267
268
269
270 public void processGroupSoftEdits(PaymentFileLoad paymentFile, CustomerProfile customer, List<String> warnings) {
271 PaymentStatus openStatus = businessObjectService.findBySinglePrimaryKey(PaymentStatus.class, PdpConstants.PaymentStatusCodes.OPEN);
272
273 for (PaymentGroup paymentGroup : paymentFile.getPaymentGroups()) {
274 paymentGroup.setBatchId(paymentFile.getBatchId());
275 paymentGroup.setPaymentStatusCode(openStatus.getCode());
276 paymentGroup.setPaymentStatus(openStatus);
277 paymentGroup.setPayeeName(paymentGroup.getPayeeName().toUpperCase());
278
279
280 defaultGroupIndicators(paymentGroup);
281
282
283 checkForTaxEmailRequired(paymentFile, paymentGroup, customer);
284
285
286 for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
287 paymentDetail.setPaymentGroupId(paymentGroup.getId());
288
289 processDetailSoftEdits(paymentFile, customer, paymentDetail, warnings);
290 }
291
292 }
293 }
294
295
296
297
298
299
300
301
302
303 protected void processDetailSoftEdits(PaymentFileLoad paymentFile, CustomerProfile customer, PaymentDetail paymentDetail, List<String> warnings) {
304 updateDetailAmounts(paymentDetail);
305
306
307 KualiDecimal testAmount = paymentDetail.getNetPaymentAmount();
308 if (testAmount.compareTo(customer.getPaymentThresholdAmount()) > 0) {
309 addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_DETAIL_THRESHOLD, testAmount.toString(), customer.getPaymentThresholdAmount().toString());
310 paymentFile.setDetailThreshold(true);
311 paymentFile.getThresholdPaymentDetails().add(paymentDetail);
312 }
313
314
315 if (paymentDetail.getInvoiceDate() == null) {
316 paymentDetail.setInvoiceDate(dateTimeService.getCurrentSqlDate());
317 }
318
319 if (paymentDetail.getPrimaryCancelledPayment() == null) {
320 paymentDetail.setPrimaryCancelledPayment(Boolean.FALSE);
321 }
322
323
324 for (PaymentAccountDetail paymentAccountDetail : paymentDetail.getAccountDetail()) {
325 paymentAccountDetail.setPaymentDetailId(paymentDetail.getId());
326
327 processAccountSoftEdits(paymentFile, customer, paymentAccountDetail, warnings);
328 }
329 }
330
331
332
333
334
335
336
337
338
339 protected void processAccountSoftEdits(PaymentFileLoad paymentFile, CustomerProfile customer, PaymentAccountDetail paymentAccountDetail, List<String> warnings) {
340 List<PaymentAccountHistory> changeRecords = paymentAccountDetail.getAccountHistory();
341
342
343 paymentAccountDetail.setFinChartCode(paymentAccountDetail.getFinChartCode().toUpperCase());
344
345
346 if (customer.getAccountingEditRequired()) {
347
348 Account account = accountService.getByPrimaryId(paymentAccountDetail.getFinChartCode(), paymentAccountDetail.getAccountNbr());
349 if (account == null) {
350 addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_INVALID_ACCOUNT, paymentAccountDetail.getFinChartCode(), paymentAccountDetail.getAccountNbr());
351
352 KualiCodeBase objChangeCd = businessObjectService.findBySinglePrimaryKey(AccountingChangeCode.class, PdpConstants.AccountChangeCodes.INVALID_ACCOUNT);
353 replaceAccountingString(objChangeCd, changeRecords, customer, paymentAccountDetail);
354 }
355 else {
356
357 if (StringUtils.isNotBlank(paymentAccountDetail.getSubAccountNbr())) {
358 SubAccount subAccount = subAccountService.getByPrimaryId(paymentAccountDetail.getFinChartCode(), paymentAccountDetail.getAccountNbr(), paymentAccountDetail.getSubAccountNbr());
359 if (subAccount == null) {
360 addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_INVALID_SUB_ACCOUNT, paymentAccountDetail.getFinChartCode(), paymentAccountDetail.getAccountNbr(), paymentAccountDetail.getSubAccountNbr());
361
362 KualiCodeBase objChangeCd = businessObjectService.findBySinglePrimaryKey(AccountingChangeCode.class, PdpConstants.AccountChangeCodes.INVALID_SUB_ACCOUNT);
363 changeRecords.add(newAccountHistory(PdpPropertyConstants.SUB_ACCOUNT_DB_COLUMN_NAME, OLEConstants.getDashSubAccountNumber(), paymentAccountDetail.getSubAccountNbr(), objChangeCd));
364
365 paymentAccountDetail.setSubAccountNbr(OLEConstants.getDashSubAccountNumber());
366 }
367 }
368
369
370 ObjectCode objectCode = objectCodeService.getByPrimaryIdForCurrentYear(paymentAccountDetail.getFinChartCode(), paymentAccountDetail.getFinObjectCode());
371 if (objectCode == null) {
372 addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_INVALID_OBJECT, paymentAccountDetail.getFinChartCode(), paymentAccountDetail.getFinObjectCode());
373
374 KualiCodeBase objChangeCd = businessObjectService.findBySinglePrimaryKey(AccountingChangeCode.class, PdpConstants.AccountChangeCodes.INVALID_OBJECT);
375 replaceAccountingString(objChangeCd, changeRecords, customer, paymentAccountDetail);
376 }
377
378
379 else if (StringUtils.isNotBlank(paymentAccountDetail.getFinSubObjectCode())) {
380 SubObjectCode subObjectCode = subObjectCodeService.getByPrimaryIdForCurrentYear(paymentAccountDetail.getFinChartCode(), paymentAccountDetail.getAccountNbr(), paymentAccountDetail.getFinObjectCode(), paymentAccountDetail.getFinSubObjectCode());
381 if (subObjectCode == null) {
382 addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_INVALID_SUB_OBJECT, paymentAccountDetail.getFinChartCode(), paymentAccountDetail.getAccountNbr(), paymentAccountDetail.getFinObjectCode(), paymentAccountDetail.getFinSubObjectCode());
383
384 KualiCodeBase objChangeCd = businessObjectService.findBySinglePrimaryKey(AccountingChangeCode.class, PdpConstants.AccountChangeCodes.INVALID_SUB_OBJECT);
385 changeRecords.add(newAccountHistory(PdpPropertyConstants.SUB_OBJECT_DB_COLUMN_NAME, OLEConstants.getDashFinancialSubObjectCode(), paymentAccountDetail.getFinSubObjectCode(), objChangeCd));
386
387 paymentAccountDetail.setFinSubObjectCode(OLEConstants.getDashFinancialSubObjectCode());
388 }
389 }
390 }
391
392
393 if (StringUtils.isNotBlank(paymentAccountDetail.getProjectCode())) {
394 ProjectCode projectCode = businessObjectService.findBySinglePrimaryKey(ProjectCode.class, paymentAccountDetail.getProjectCode());
395 if (projectCode == null) {
396 addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_INVALID_PROJECT, paymentAccountDetail.getProjectCode());
397
398 KualiCodeBase objChangeCd = businessObjectService.findBySinglePrimaryKey(AccountingChangeCode.class, PdpConstants.AccountChangeCodes.INVALID_PROJECT);
399 changeRecords.add(newAccountHistory(PdpPropertyConstants.PROJECT_DB_COLUMN_NAME, OLEConstants.getDashProjectCode(), paymentAccountDetail.getProjectCode(), objChangeCd));
400 paymentAccountDetail.setProjectCode(OLEConstants.getDashProjectCode());
401 }
402 }
403 }
404
405
406 if (StringUtils.isBlank(paymentAccountDetail.getFinSubObjectCode())) {
407 paymentAccountDetail.setFinSubObjectCode(OLEConstants.getDashFinancialSubObjectCode());
408 }
409
410 if (StringUtils.isBlank(paymentAccountDetail.getSubAccountNbr())) {
411 paymentAccountDetail.setSubAccountNbr(OLEConstants.getDashSubAccountNumber());
412 }
413
414 if (StringUtils.isBlank(paymentAccountDetail.getProjectCode())) {
415 paymentAccountDetail.setProjectCode(OLEConstants.getDashProjectCode());
416 }
417
418 }
419
420
421
422
423
424
425
426
427
428 protected void replaceAccountingString(KualiCodeBase objChangeCd, List<PaymentAccountHistory> changeRecords, CustomerProfile customer, PaymentAccountDetail paymentAccountDetail) {
429 changeRecords.add(newAccountHistory(PdpPropertyConstants.CHART_DB_COLUMN_NAME, customer.getDefaultChartCode(), paymentAccountDetail.getFinChartCode(), objChangeCd));
430 changeRecords.add(newAccountHistory(PdpPropertyConstants.ACCOUNT_DB_COLUMN_NAME, customer.getDefaultAccountNumber(), paymentAccountDetail.getAccountNbr(), objChangeCd));
431 changeRecords.add(newAccountHistory(PdpPropertyConstants.SUB_ACCOUNT_DB_COLUMN_NAME, customer.getDefaultSubAccountNumber(), paymentAccountDetail.getSubAccountNbr(), objChangeCd));
432 changeRecords.add(newAccountHistory(PdpPropertyConstants.OBJECT_DB_COLUMN_NAME, customer.getDefaultObjectCode(), paymentAccountDetail.getFinObjectCode(), objChangeCd));
433 changeRecords.add(newAccountHistory(PdpPropertyConstants.SUB_OBJECT_DB_COLUMN_NAME, customer.getDefaultSubObjectCode(), paymentAccountDetail.getFinSubObjectCode(), objChangeCd));
434
435 paymentAccountDetail.setFinChartCode(customer.getDefaultChartCode());
436 paymentAccountDetail.setAccountNbr(customer.getDefaultAccountNumber());
437 if (StringUtils.isNotBlank(customer.getDefaultSubAccountNumber())) {
438 paymentAccountDetail.setSubAccountNbr(customer.getDefaultSubAccountNumber());
439 }
440 else {
441 paymentAccountDetail.setSubAccountNbr(OLEConstants.getDashSubAccountNumber());
442 }
443 paymentAccountDetail.setFinObjectCode(customer.getDefaultObjectCode());
444 if (StringUtils.isNotBlank(customer.getDefaultSubAccountNumber())) {
445 paymentAccountDetail.setFinSubObjectCode(customer.getDefaultSubObjectCode());
446 }
447 else {
448 paymentAccountDetail.setFinSubObjectCode(OLEConstants.getDashFinancialSubObjectCode());
449 }
450 }
451
452
453
454
455
456
457
458
459
460
461 protected PaymentAccountHistory newAccountHistory(String attName, String newValue, String oldValue, KualiCodeBase changeCode) {
462 PaymentAccountHistory paymentAccountHistory = new PaymentAccountHistory();
463
464 paymentAccountHistory.setAcctAttributeName(attName);
465 paymentAccountHistory.setAcctAttributeNewValue(newValue);
466 paymentAccountHistory.setAcctAttributeOrigValue(oldValue);
467 paymentAccountHistory.setAcctChangeDate(dateTimeService.getCurrentTimestamp());
468 paymentAccountHistory.setAccountingChange((AccountingChangeCode) changeCode);
469
470 return paymentAccountHistory;
471 }
472
473
474
475
476
477
478 protected void updateDetailAmounts(PaymentDetail paymentDetail) {
479 KualiDecimal zero = KualiDecimal.ZERO;
480
481 if (paymentDetail.getInvTotDiscountAmount() == null) {
482 paymentDetail.setInvTotDiscountAmount(zero);
483 }
484
485 if (paymentDetail.getInvTotShipAmount() == null) {
486 paymentDetail.setInvTotShipAmount(zero);
487 }
488
489 if (paymentDetail.getInvTotOtherDebitAmount() == null) {
490 paymentDetail.setInvTotOtherDebitAmount(zero);
491 }
492
493 if (paymentDetail.getInvTotOtherCreditAmount() == null) {
494 paymentDetail.setInvTotOtherCreditAmount(zero);
495 }
496
497
498 if (paymentDetail.getNetPaymentAmount() == null) {
499 paymentDetail.setNetPaymentAmount(paymentDetail.getAccountTotal());
500 }
501
502 if (paymentDetail.getOrigInvoiceAmount() == null) {
503 KualiDecimal amt = paymentDetail.getNetPaymentAmount();
504 amt = amt.add(paymentDetail.getInvTotDiscountAmount());
505 amt = amt.subtract(paymentDetail.getInvTotShipAmount());
506 amt = amt.subtract(paymentDetail.getInvTotOtherDebitAmount());
507 amt = amt.add(paymentDetail.getInvTotOtherCreditAmount());
508 paymentDetail.setOrigInvoiceAmount(amt);
509 }
510 }
511
512
513
514
515
516
517 protected void defaultGroupIndicators(PaymentGroup paymentGroup) {
518
519
520
521
522
523 if (paymentGroup.getCampusAddress() == null) {
524 paymentGroup.setCampusAddress(Boolean.FALSE);
525 }
526
527 if (paymentGroup.getPymtAttachment() == null) {
528 paymentGroup.setPymtAttachment(Boolean.FALSE);
529 }
530
531 if (paymentGroup.getPymtSpecialHandling() == null) {
532 paymentGroup.setPymtSpecialHandling(Boolean.FALSE);
533 }
534
535 if (paymentGroup.getProcessImmediate() == null) {
536 paymentGroup.setProcessImmediate(Boolean.FALSE);
537 }
538
539 if (paymentGroup.getEmployeeIndicator() == null) {
540 paymentGroup.setEmployeeIndicator(Boolean.FALSE);
541 }
542
543 if (paymentGroup.getNraPayment() == null) {
544 paymentGroup.setNraPayment(Boolean.FALSE);
545 }
546
547 if (paymentGroup.getTaxablePayment() == null) {
548 paymentGroup.setTaxablePayment(Boolean.FALSE);
549 }
550 }
551
552
553
554
555
556
557
558
559 protected void checkForTaxEmailRequired(PaymentFileLoad paymentFile, PaymentGroup paymentGroup, CustomerProfile customer) {
560 PaymentStatus heldForNRAEmployee = businessObjectService.findBySinglePrimaryKey(PaymentStatus.class, PdpConstants.PaymentStatusCodes.HELD_TAX_NRA_EMPL_CD);
561 PaymentStatus heldForEmployee = businessObjectService.findBySinglePrimaryKey(PaymentStatus.class, PdpConstants.PaymentStatusCodes.HELD_TAX_EMPLOYEE_CD);
562 PaymentStatus heldForNRA = businessObjectService.findBySinglePrimaryKey(PaymentStatus.class, PdpConstants.PaymentStatusCodes.HELD_TAX_NRA_CD);
563
564 if (customer.getNraReview() && customer.getEmployeeCheck() && paymentGroup.getEmployeeIndicator().booleanValue() && paymentGroup.getNraPayment().booleanValue()) {
565 paymentGroup.setPaymentStatus(heldForNRAEmployee);
566 paymentFile.setTaxEmailRequired(true);
567 }
568
569 else if (customer.getEmployeeCheck() && paymentGroup.getEmployeeIndicator().booleanValue()) {
570 paymentGroup.setPaymentStatus(heldForEmployee);
571 paymentFile.setTaxEmailRequired(true);
572 }
573
574 else if (customer.getNraReview() && paymentGroup.getNraPayment().booleanValue()) {
575 paymentGroup.setPaymentStatus(heldForNRA);
576 paymentFile.setTaxEmailRequired(true);
577 }
578 }
579
580
581
582
583
584
585
586 protected void checkGroupPaymentDate(PaymentGroup paymentGroup, List<String> warnings) {
587 Timestamp now = dateTimeService.getCurrentTimestamp();
588
589 Calendar nowPlus30 = Calendar.getInstance();
590 nowPlus30.setTime(now);
591 nowPlus30.add(Calendar.DATE, 30);
592
593 Calendar nowMinus30 = Calendar.getInstance();
594 nowMinus30.setTime(now);
595 nowMinus30.add(Calendar.DATE, -30);
596
597 if (paymentGroup.getPaymentDate() != null) {
598 Calendar payDate = Calendar.getInstance();
599 payDate.setTime(paymentGroup.getPaymentDate());
600
601 if (payDate.before(nowMinus30)) {
602 addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_PAYDATE_OVER_30_DAYS_PAST, dateTimeService.toDateString(paymentGroup.getPaymentDate()));
603 }
604
605 if (payDate.after(nowPlus30)) {
606 addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_PAYDATE_OVER_30_DAYS_OUT, dateTimeService.toDateString(paymentGroup.getPaymentDate()));
607 }
608 }
609 else {
610 try {
611 paymentGroup.setPaymentDate(dateTimeService.convertToSqlDate(now));
612 }
613 catch (ParseException e) {
614 throw new RuntimeException("Unable to parse current timestamp into sql date " + e.getMessage());
615 }
616 }
617 }
618
619
620
621
622 protected int getMaxNoteLines() {
623 String maxLines = parameterService.getParameterValueAsString(OleParameterConstants.PRE_DISBURSEMENT_ALL.class, PdpParameterConstants.MAX_NOTE_LINES);
624 if (StringUtils.isBlank(maxLines)) {
625 throw new RuntimeException("System parameter for max note lines is blank");
626 }
627
628 return Integer.parseInt(maxLines);
629 }
630
631
632
633
634
635
636
637
638 protected void addWarningMessage(List<String> warnings, String messageKey, String... arguments) {
639 String message = kualiConfigurationService.getPropertyValueAsString(messageKey);
640 warnings.add(MessageFormat.format(message, (Object[]) arguments));
641 }
642
643
644
645
646
647
648 public void setCustomerProfileService(CustomerProfileService customerProfileService) {
649 this.customerProfileService = customerProfileService;
650 }
651
652
653
654
655
656
657 public void setPaymentFileLoadDao(PaymentFileLoadDao paymentFileLoadDao) {
658 this.paymentFileLoadDao = paymentFileLoadDao;
659 }
660
661
662
663
664
665
666 public void setParameterService(ParameterService parameterService) {
667 this.parameterService = parameterService;
668 }
669
670
671
672
673
674
675 public void setDateTimeService(DateTimeService dateTimeService) {
676 this.dateTimeService = dateTimeService;
677 }
678
679
680
681
682
683
684 public void setAccountService(AccountService accountService) {
685 this.accountService = accountService;
686 }
687
688
689
690
691
692
693 public void setSubAccountService(SubAccountService subAccountService) {
694 this.subAccountService = subAccountService;
695 }
696
697
698
699
700
701
702 public void setObjectCodeService(ObjectCodeService objectCodeService) {
703 this.objectCodeService = objectCodeService;
704 }
705
706
707
708
709
710
711 public void setSubObjectCodeService(SubObjectCodeService subObjectCodeService) {
712 this.subObjectCodeService = subObjectCodeService;
713 }
714
715
716
717
718
719
720 public void setConfigurationService(ConfigurationService kualiConfigurationService) {
721 this.kualiConfigurationService = kualiConfigurationService;
722 }
723
724
725
726
727
728
729 public void setBankService(BankService bankService) {
730 this.bankService = bankService;
731 }
732
733
734
735
736
737
738 public void setOriginationCodeService(OriginationCodeService originationCodeService) {
739 this.originationCodeService = originationCodeService;
740 }
741
742
743
744
745
746
747 protected BusinessObjectService getBusinessObjectService() {
748 return businessObjectService;
749 }
750
751
752
753
754
755
756 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
757 this.businessObjectService = businessObjectService;
758 }
759
760 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
761 this.documentTypeService = documentTypeService;
762 }
763
764 }