1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.kuali.ole.module.purap.PurapConstants;
19 import org.kuali.ole.module.purap.PurapKeyConstants;
20 import org.kuali.ole.module.purap.PurapPropertyConstants;
21 import org.kuali.ole.module.purap.document.PurchasingDocument;
22 import org.kuali.ole.sys.document.validation.GenericValidation;
23 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24 import org.kuali.ole.sys.service.UniversityDateService;
25 import org.kuali.rice.core.api.datetime.DateTimeService;
26 import org.kuali.rice.krad.util.GlobalVariables;
27 import org.kuali.rice.krad.util.ObjectUtils;
28
29 import java.util.Date;
30
31 public class PurchasingPaymentInfoValidation extends GenericValidation {
32
33 DateTimeService dateTimeService;
34 UniversityDateService universityDateService;
35
36 public boolean validate(AttributedDocumentEvent event) {
37 boolean valid = true;
38 PurchasingDocument purDocument = (PurchasingDocument) event.getDocument();
39
40 GlobalVariables.getMessageMap().addToErrorPath(PurapConstants.PAYMENT_INFO_ERRORS);
41 valid &= checkBeginDateBeforeEndDate(purDocument);
42 if (valid && (ObjectUtils.isNotNull(purDocument.getPurchaseOrderBeginDate()) || ObjectUtils.isNotNull(purDocument.getPurchaseOrderEndDate()))) {
43 if (ObjectUtils.isNotNull(purDocument.getPurchaseOrderBeginDate()) && ObjectUtils.isNull(purDocument.getPurchaseOrderEndDate())) {
44 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_END_DATE, PurapKeyConstants.ERROR_PURCHASE_ORDER_BEGIN_DATE_NO_END_DATE);
45 valid &= false;
46 } else {
47 if (ObjectUtils.isNull(purDocument.getPurchaseOrderBeginDate()) && ObjectUtils.isNotNull(purDocument.getPurchaseOrderEndDate())) {
48 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_BEGIN_DATE, PurapKeyConstants.ERROR_PURCHASE_ORDER_END_DATE_NO_BEGIN_DATE);
49 valid &= false;
50 }
51 }
52 }
53 if (valid && ObjectUtils.isNotNull(purDocument.getPurchaseOrderBeginDate()) && ObjectUtils.isNotNull(purDocument.getPurchaseOrderEndDate())) {
54 if (ObjectUtils.isNull(purDocument.getRecurringPaymentTypeCode())) {
55 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.RECURRING_PAYMENT_TYPE_CODE, PurapKeyConstants.ERROR_RECURRING_DATE_NO_TYPE);
56
57 valid &= false;
58 }
59 } else if (valid && ObjectUtils.isNotNull(purDocument.getRecurringPaymentTypeCode())) {
60 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_BEGIN_DATE, PurapKeyConstants.ERROR_RECURRING_TYPE_NO_DATE);
61 valid &= false;
62 }
63
64
65 if (purDocument.isPostingYearNext()) {
66 Integer currentFY = universityDateService.getCurrentFiscalYear();
67 Date closingDate = universityDateService.getLastDateOfFiscalYear(currentFY);
68
69
70 if (ObjectUtils.isNotNull(purDocument.getPurchaseOrderBeginDate()) &&
71 (purDocument.getPurchaseOrderBeginDate().before(closingDate) ||
72 purDocument.getPurchaseOrderBeginDate().equals(closingDate))) {
73 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_BEGIN_DATE, PurapKeyConstants.ERROR_NEXT_FY_BEGIN_DATE_INVALID);
74 valid &= false;
75 }
76 }
77
78 GlobalVariables.getMessageMap().removeFromErrorPath(PurapConstants.PAYMENT_INFO_ERRORS);
79 return valid;
80 }
81
82
83
84
85
86
87
88
89
90 protected boolean checkBeginDateBeforeEndDate(PurchasingDocument purDocument) {
91 boolean valid = true;
92
93 Date beginDate = purDocument.getPurchaseOrderBeginDate();
94 Date endDate = purDocument.getPurchaseOrderEndDate();
95 if (ObjectUtils.isNotNull(beginDate) && ObjectUtils.isNotNull(endDate)) {
96 if (dateTimeService.dateDiff(beginDate, endDate, false) <= 0) {
97 valid &= false;
98 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_END_DATE, PurapKeyConstants.ERROR_PURCHASE_ORDER_BEGIN_DATE_AFTER_END);
99 }
100 }
101
102 return valid;
103 }
104
105 public DateTimeService getDateTimeService() {
106 return dateTimeService;
107 }
108
109 public void setDateTimeService(DateTimeService dateTimeService) {
110 this.dateTimeService = dateTimeService;
111 }
112
113 public UniversityDateService getUniversityDateService() {
114 return universityDateService;
115 }
116
117 public void setUniversityDateService(UniversityDateService universityDateService) {
118 this.universityDateService = universityDateService;
119 }
120
121 }