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.PurapConstants.PREQDocumentsStrings;
21 import org.kuali.ole.module.purap.PurapKeyConstants;
22 import org.kuali.ole.module.purap.PurapParameterConstants;
23 import org.kuali.ole.module.purap.document.AccountsPayableDocument;
24 import org.kuali.ole.module.purap.document.PaymentRequestDocument;
25 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
26 import org.kuali.ole.module.purap.document.service.PaymentRequestService;
27 import org.kuali.ole.module.purap.document.service.PurapService;
28 import org.kuali.ole.module.purap.document.validation.event.AttributedExpiredAccountWarningEvent;
29 import org.kuali.ole.module.purap.document.validation.event.AttributedTradeInWarningEvent;
30 import org.kuali.ole.sys.OLEConstants;
31 import org.kuali.ole.sys.OLEKeyConstants;
32 import org.kuali.ole.sys.context.SpringContext;
33 import org.kuali.ole.sys.service.UniversityDateService;
34 import org.kuali.ole.sys.service.impl.OleParameterConstants;
35 import org.kuali.rice.core.api.config.property.ConfigurationService;
36 import org.kuali.rice.core.web.format.CurrencyFormatter;
37 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
38 import org.kuali.rice.krad.document.Document;
39 import org.kuali.rice.krad.service.KualiRuleService;
40
41
42
43
44 public class PaymentRequestDocumentPreRules extends AccountsPayableDocumentPreRulesBase {
45
46
47
48
49 public PaymentRequestDocumentPreRules() {
50 super();
51 }
52
53
54
55
56
57
58 @Override
59 public boolean doPrompts(Document document) {
60 boolean preRulesOK = true;
61
62 PaymentRequestDocument preq = (PaymentRequestDocument) document;
63 if ((!SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(preq)) || (StringUtils.equals(preq.getApplicationDocumentStatus(), PurapConstants.PaymentRequestStatuses.APPDOC_AWAITING_ACCOUNTS_PAYABLE_REVIEW))) {
64 if (!confirmPayDayNotOverThresholdDaysAway(preq)) {
65 return false;
66 }
67 if (!confirmUnusedTradeIn(preq)) {
68 return false;
69 }
70 if (!confirmEncumberNextFiscalYear(preq)) {
71 return false;
72 }
73
74 if (!confirmEncumberPriorFiscalYear(preq)) {
75 return false;
76 }
77 }
78 if (SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(preq)) {
79 if (!confirmExpiredAccount(preq)) {
80 return false;
81 }
82 }
83
84
85 preRulesOK &= super.doPrompts(document);
86 return preRulesOK;
87 }
88
89
90
91
92
93
94
95
96 protected boolean askForConfirmation(String questionType, String messageConstant) {
97
98 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(messageConstant);
99 if (questionText.contains("{")) {
100 questionText = prepareQuestionText(questionType, questionText);
101 } else if (StringUtils.equals(messageConstant, OLEKeyConstants.ERROR_ACCOUNT_EXPIRED) || StringUtils.equals(messageConstant, PurapKeyConstants.WARNING_ITEM_TRADE_IN_AMOUNT_UNUSED)) {
102 questionText = questionType;
103 }
104
105
106 boolean confirmOverride = super.askOrAnalyzeYesNoQuestion(questionType, questionText);
107
108 if (!confirmOverride) {
109 event.setActionForwardName(OLEConstants.MAPPING_BASIC);
110 return false;
111 }
112 return true;
113 }
114
115
116
117
118
119
120
121
122 protected String prepareQuestionText(String questionType, String questionText) {
123 if (StringUtils.equals(questionType, PREQDocumentsStrings.THRESHOLD_DAYS_OVERRIDE_QUESTION)) {
124 questionText = StringUtils.replace(questionText, "{0}", new Integer(PurapConstants.PREQ_PAY_DATE_DAYS_BEFORE_WARNING).toString());
125 }
126 return questionText;
127 }
128
129
130
131
132
133
134
135
136 public boolean confirmPayDayNotOverThresholdDaysAway(PaymentRequestDocument preq) {
137
138
139
140
141
142
143 int thresholdDays = PurapConstants.PREQ_PAY_DATE_DAYS_BEFORE_WARNING;
144 if ((preq.getPaymentRequestPayDate() != null) && SpringContext.getBean(PurapService.class).isDateMoreThanANumberOfDaysAway(preq.getPaymentRequestPayDate(), thresholdDays)) {
145 return askForConfirmation(PREQDocumentsStrings.THRESHOLD_DAYS_OVERRIDE_QUESTION, PurapKeyConstants.MESSAGE_PAYMENT_REQUEST_PAYDATE_OVER_THRESHOLD_DAYS);
146 }
147 return true;
148 }
149
150 public boolean confirmUnusedTradeIn(PaymentRequestDocument preq) {
151 boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedTradeInWarningEvent("", preq));
152
153 if (!rulePassed) {
154 return askForConfirmation(PREQDocumentsStrings.UNUSED_TRADE_IN_QUESTION, PurapKeyConstants.WARNING_ITEM_TRADE_IN_AMOUNT_UNUSED);
155 }
156 return true;
157 }
158
159 public boolean confirmExpiredAccount(PaymentRequestDocument preq) {
160 boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedExpiredAccountWarningEvent("", preq));
161
162 if (!rulePassed) {
163 return askForConfirmation(PREQDocumentsStrings.EXPIRED_ACCOUNT_QUESTION, OLEKeyConstants.ERROR_ACCOUNT_EXPIRED);
164 }
165 return true;
166 }
167
168 public boolean confirmEncumberNextFiscalYear(PaymentRequestDocument preq) {
169 Integer fiscalYear = SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear();
170 if (preq.getPurchaseOrderDocument().getPostingYear().intValue() > fiscalYear) {
171 return askForConfirmation(PREQDocumentsStrings.ENCUMBER_NEXT_FISCAL_YEAR_QUESTION, PurapKeyConstants.WARNING_ENCUMBER_NEXT_FY);
172 }
173
174 return true;
175 }
176
177 public boolean confirmEncumberPriorFiscalYear(PaymentRequestDocument preq) {
178
179 Integer fiscalYear = SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear();
180 if (preq.getPurchaseOrderDocument().getPostingYear().intValue() == fiscalYear && SpringContext.getBean(PaymentRequestService.class).allowBackpost(preq)) {
181 return askForConfirmation(PREQDocumentsStrings.ENCUMBER_PRIOR_FISCAL_YEAR_QUESTION, PurapKeyConstants.WARNING_ENCUMBER_PRIOR_FY);
182 }
183 return true;
184 }
185
186
187
188
189 @Override
190 public String getDocumentName() {
191 return "Payment Request";
192 }
193
194
195
196
197 @Override
198 public String createInvoiceNoMatchQuestionText(AccountsPayableDocument accountsPayableDocument) {
199
200 String questionText = super.createInvoiceNoMatchQuestionText(accountsPayableDocument);
201
202 CurrencyFormatter cf = new CurrencyFormatter();
203 PaymentRequestDocument preq = (PaymentRequestDocument) accountsPayableDocument;
204
205 StringBuffer questionTextBuffer = new StringBuffer("");
206 questionTextBuffer.append(questionText);
207
208 questionTextBuffer.append("[br][br][b]Summary Detail Below:[b][br][br][table questionTable]");
209 questionTextBuffer.append("[tr][td leftTd]Vendor Invoice Amount entered on start screen:[/td][td rightTd]" + (String) cf.format(preq.getInitialAmount()) + "[/td][/tr]");
210 questionTextBuffer.append("[tr][td leftTd]Invoice Total Prior to Additional Charges:[/td][td rightTd]" + (String) cf.format(preq.getTotalPreTaxDollarAmountAboveLineItems()) + "[/td][/tr]");
211
212
213
214 if (preq.isDiscount()) {
215 questionTextBuffer.append("[tr][td leftTd]Total Before Discount:[/td][td rightTd]" + (String) cf.format(preq.getGrandPreTaxTotalExcludingDiscount()) + "[/td][/tr]");
216 }
217
218
219 boolean salesTaxInd = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.ENABLE_SALES_TAX_IND);
220 if (salesTaxInd) {
221 questionTextBuffer.append("[tr][td leftTd]Grand Total Prior to Tax:[/td][td rightTd]" + (String) cf.format(preq.getGrandPreTaxTotal()) + "[/td][/tr]");
222 questionTextBuffer.append("[tr][td leftTd]Grand Total Tax:[/td][td rightTd]" + (String) cf.format(preq.getGrandTaxAmount()) + "[/td][/tr]");
223 }
224
225 questionTextBuffer.append("[tr][td leftTd]Grand Total:[/td][td rightTd]" + (String) cf.format(preq.getGrandTotal()) + "[/td][/tr][/table]");
226
227 return questionTextBuffer.toString();
228
229 }
230
231 @Override
232 protected boolean checkCAMSWarningStatus(PurchasingAccountsPayableDocument purapDocument) {
233 return PurapConstants.CAMSWarningStatuses.PAYMENT_REQUEST_STATUS_WARNING_NO_CAMS_DATA.contains(purapDocument.getApplicationDocumentStatus());
234 }
235
236
237
238
239
240
241
242 @Override
243 protected boolean validateInvoiceTotalsAreMismatched(AccountsPayableDocument accountsPayableDocument) {
244 boolean mismatched = false;
245 PaymentRequestDocument payReqDoc = (PaymentRequestDocument) accountsPayableDocument;
246 String[] excludeArray = {PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE};
247
248
249
250 if (payReqDoc.isUseTaxIndicator()) {
251 if (payReqDoc.getTotalPreTaxDollarAmountAllItems(excludeArray).compareTo(accountsPayableDocument.getInitialAmount()) != 0 && !accountsPayableDocument.isUnmatchedOverride()) {
252 mismatched = true;
253 }
254 }
255
256
257
258 else {
259 if (accountsPayableDocument.getTotalDollarAmountAllItems(excludeArray).compareTo(accountsPayableDocument.getInitialAmount()) != 0 && !accountsPayableDocument.isUnmatchedOverride()) {
260 mismatched = true;
261 }
262 }
263
264 return mismatched;
265 }
266
267 }