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.AccountsPayableDocument;
22 import org.kuali.ole.module.purap.document.service.PurapService;
23 import org.kuali.ole.sys.OLEConstants;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.rice.core.api.config.property.ConfigurationService;
26 import org.kuali.rice.krad.document.Document;
27
28
29
30
31 public abstract class AccountsPayableDocumentPreRulesBase extends PurapDocumentPreRulesBase {
32 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountsPayableDocumentPreRulesBase.class);
33
34 public AccountsPayableDocumentPreRulesBase() {
35 super();
36 }
37
38
39
40
41
42
43
44 @Override
45 public boolean doPrompts(Document document) {
46
47 boolean preRulesOK = true;
48
49 AccountsPayableDocument accountsPayableDocument = (AccountsPayableDocument) document;
50
51
52 if (SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(accountsPayableDocument) == false) {
53 preRulesOK = confirmInvoiceNoMatchOverride(accountsPayableDocument);
54 } else if (SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(accountsPayableDocument)) {
55
56 accountsPayableDocument.setUnmatchedOverride(true);
57 }
58
59 return preRulesOK;
60 }
61
62
63
64
65
66
67
68
69 protected boolean confirmInvoiceNoMatchOverride(AccountsPayableDocument accountsPayableDocument) {
70
71
72 if (validateInvoiceTotalsAreMismatched(accountsPayableDocument)) {
73
74 String questionText = createInvoiceNoMatchQuestionText(accountsPayableDocument);
75
76 boolean confirmOverride = super.askOrAnalyzeYesNoQuestion(PurapConstants.AP_OVERRIDE_INVOICE_NOMATCH_QUESTION, questionText);
77
78
79 if (confirmOverride && StringUtils.isBlank(event.getQuestionContext())) {
80 event.setQuestionContext(PurapConstants.AP_OVERRIDE_INVOICE_NOMATCH_QUESTION);
81 accountsPayableDocument.setUnmatchedOverride(true);
82 }
83
84 if (!confirmOverride) {
85 event.setActionForwardName(OLEConstants.MAPPING_BASIC);
86 return false;
87 }
88 }
89
90 return true;
91 }
92
93
94
95
96
97
98
99 public String createInvoiceNoMatchQuestionText(AccountsPayableDocument accountsPayableDocument) {
100
101 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.AP_QUESTION_CONFIRM_INVOICE_MISMATCH);
102 questionText = StringUtils.replace(questionText, "{0}", getDocumentName());
103
104 return questionText;
105 }
106
107
108
109
110
111
112
113 protected boolean validateInvoiceTotalsAreMismatched(AccountsPayableDocument accountsPayableDocument) {
114 boolean mismatched = false;
115 String[] excludeArray = {PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE};
116 if (accountsPayableDocument.getTotalDollarAmountAllItems(excludeArray).compareTo(accountsPayableDocument.getInitialAmount()) != 0 && !accountsPayableDocument.isUnmatchedOverride()) {
117 mismatched = true;
118 }
119
120 return mismatched;
121 }
122
123
124
125
126
127
128 public String getDocumentName() {
129 return "";
130 }
131
132 }