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.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.module.purap.PurapKeyConstants;
21 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
22 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
23 import org.kuali.ole.module.purap.document.PurchasingDocument;
24 import org.kuali.ole.module.purap.document.service.PurapService;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.ole.sys.document.AmountTotaling;
28 import org.kuali.rice.core.api.config.property.ConfigurationService;
29 import org.kuali.rice.core.api.util.type.KualiDecimal;
30 import org.kuali.rice.kns.util.KNSGlobalVariables;
31 import org.kuali.rice.krad.document.Document;
32 import org.kuali.rice.krad.util.ObjectUtils;
33
34
35
36
37 public class PurchaseOrderDocumentPreRules extends PurchasingDocumentPreRulesBase {
38
39
40
41
42
43
44
45
46
47 @Override
48 public boolean doPrompts(Document document) {
49
50 boolean preRulesOK = true;
51
52 PurchaseOrderDocument purchaseOrderDocument = (PurchaseOrderDocument) document;
53
54 if (StringUtils.isBlank(event.getQuestionContext()) || StringUtils.equals(question, PurapConstants.PO_OVERRIDE_NOT_TO_EXCEED_QUESTION)) {
55 preRulesOK &= confirmNotToExceedOverride(purchaseOrderDocument);
56 }
57
58 if (isDocumentInStateToReceiveNextFyWarning(purchaseOrderDocument) &&
59 (StringUtils.isBlank(event.getQuestionContext()) || StringUtils.equals(question, PurapConstants.PO_NEXT_FY_WARNING))) {
60 preRulesOK &= confirmNextFYPriorToApoAllowedDate(purchaseOrderDocument);
61 }
62
63 if (!purchaseOrderDocument.isUseTaxIndicator()) {
64 preRulesOK &= checkForTaxRecalculation(purchaseOrderDocument);
65 }
66
67 return preRulesOK;
68 }
69
70
71
72
73
74
75
76 protected boolean isDocumentInStateToReceiveNextFyWarning(PurchaseOrderDocument poDocument) {
77 return (PurapConstants.PurchaseOrderStatuses.APPDOC_IN_PROCESS.equals(poDocument.getApplicationDocumentStatus()) ||
78 PurapConstants.PurchaseOrderStatuses.APPDOC_AWAIT_PURCHASING_REVIEW.equals(poDocument.getApplicationDocumentStatus()));
79 }
80
81
82
83
84
85
86
87
88
89 protected boolean confirmNotToExceedOverride(PurchaseOrderDocument purchaseOrderDocument) {
90
91
92 if (!validateTotalDollarAmountIsLessThanPurchaseOrderTotalLimit(purchaseOrderDocument)) {
93 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.PURCHASE_ORDER_QUESTION_OVERRIDE_NOT_TO_EXCEED);
94
95 boolean confirmOverride = super.askOrAnalyzeYesNoQuestion(PurapConstants.PO_OVERRIDE_NOT_TO_EXCEED_QUESTION, questionText);
96
97
98 if (confirmOverride && StringUtils.isBlank(event.getQuestionContext())) {
99 event.setQuestionContext(PurapConstants.PO_OVERRIDE_NOT_TO_EXCEED_QUESTION);
100 }
101
102 if (!confirmOverride) {
103 event.setActionForwardName(OLEConstants.MAPPING_BASIC);
104
105 return false;
106 }
107 }
108
109 return true;
110 }
111
112
113
114
115
116
117
118
119 public boolean validateTotalDollarAmountIsLessThanPurchaseOrderTotalLimit(PurchasingDocument purDocument) {
120 boolean valid = true;
121 if (ObjectUtils.isNotNull(purDocument.getPurchaseOrderTotalLimit()) && ObjectUtils.isNotNull(((AmountTotaling) purDocument).getTotalDollarAmount())) {
122 KualiDecimal totalAmount = ((AmountTotaling) purDocument).getTotalDollarAmount();
123 if (((AmountTotaling) purDocument).getTotalDollarAmount().isGreaterThan(purDocument.getPurchaseOrderTotalLimit())) {
124 valid &= false;
125 KNSGlobalVariables.getMessageList().add(PurapKeyConstants.PO_TOTAL_GREATER_THAN_PO_TOTAL_LIMIT);
126 }
127 }
128
129 return valid;
130 }
131
132
133
134
135
136
137
138
139
140 protected boolean confirmNextFYPriorToApoAllowedDate(PurchaseOrderDocument poDocument) {
141
142
143 if (poDocument.isPostingYearNext() && !SpringContext.getBean(PurapService.class).isTodayWithinApoAllowedRange()) {
144 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.WARNING_PURCHASE_ORDER_ENCUMBER_NEXT_FY);
145 boolean confirmOverride = super.askOrAnalyzeYesNoQuestion(PurapConstants.PO_NEXT_FY_WARNING, questionText);
146
147
148 if (confirmOverride && StringUtils.isBlank(event.getQuestionContext())) {
149 event.setQuestionContext(PurapConstants.PO_NEXT_FY_WARNING);
150 }
151 if (!confirmOverride) {
152 event.setActionForwardName(OLEConstants.MAPPING_BASIC);
153 return false;
154 }
155 }
156
157 return true;
158 }
159
160 @Override
161 protected boolean checkCAMSWarningStatus(PurchasingAccountsPayableDocument purapDocument) {
162 return PurapConstants.CAMSWarningStatuses.PURCHASEORDER_STATUS_WARNING_NO_CAMS_DATA.contains(purapDocument.getApplicationDocumentStatus());
163 }
164
165 }