1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.document.validation.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.document.validation.impl.PurchaseOrderDocumentPreRules;
20 import org.kuali.ole.select.businessobject.OleCopy;
21 import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
22 import org.kuali.ole.select.businessobject.OleSufficientFundCheck;
23 import org.kuali.ole.select.document.OlePurchaseOrderAmendmentDocument;
24 import org.kuali.ole.select.document.service.OleRequisitionDocumentService;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.OLEPropertyConstants;
27 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
28 import org.kuali.ole.sys.context.SpringContext;
29 import org.kuali.rice.core.api.config.property.ConfigurationService;
30 import org.kuali.rice.krad.document.Document;
31 import org.kuali.rice.krad.service.BusinessObjectService;
32 import org.kuali.rice.krad.service.KRADServiceLocator;
33
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37
38 public class OlePurchaseOrderDocumentPreRules extends PurchaseOrderDocumentPreRules {
39
40
41
42 public OlePurchaseOrderDocumentPreRules() {
43 super();
44 }
45
46
47
48
49
50
51 @Override
52 public boolean doPrompts(Document document) {
53 boolean preRulesOK = true;
54 OlePurchaseOrderAmendmentDocument purDoc = null;
55 if (document instanceof OlePurchaseOrderAmendmentDocument) {
56 purDoc = (OlePurchaseOrderAmendmentDocument) document;
57 }
58 OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
59 .getBean("oleRequisitionDocumentService");
60 StringBuilder accountNumbers = new StringBuilder();
61 if (oleRequisitionDocumentService != null && purDoc != null) {
62 List<SourceAccountingLine> sourceAccountingLineList = purDoc.getSourceAccountingLines();
63 for (SourceAccountingLine accLine : sourceAccountingLineList) {
64 String notificationOption = null;
65 boolean sufficientFundCheck;
66 Map<String, Object> key = new HashMap<String, Object>();
67 String chartCode = accLine.getChartOfAccountsCode();
68 String accNo = accLine.getAccountNumber();
69 String objectCd = accLine.getFinancialObjectCode();
70 key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
71 key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
72 OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
73 OleSufficientFundCheck.class, key);
74 if (account != null) {
75 notificationOption = account.getNotificationOption();
76 }
77 if (notificationOption != null && notificationOption.equals(OLEPropertyConstants.WARNING_MSG)
78 && oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine)) {
79 accountNumbers.append(accLine.getAccountNumber());
80 }
81 }
82 }
83 if (accountNumbers.length() > 0) {
84 preRulesOK = askForConfirmation(OLEConstants.SufficientFundCheck.REQUISITION_SFC_CHECKING_STRING,
85 OLEConstants.SufficientFundCheck.REQUISITION_SFC_CHECKING, accountNumbers);
86 }
87 if (purDoc != null && preRulesOK) {
88 List<OlePurchaseOrderItem> purItem = purDoc.getItems();
89 boolean confirmOverride = false;
90 for (int i = 0; purItem.size() > i; i++) {
91 OlePurchaseOrderItem item = (OlePurchaseOrderItem) purDoc.getItem(i);
92 if (item.getCopyList().size() == 1 && item.getItemQuantity().intValue() == 1) {
93 OleCopy oleCopy = item.getCopyList().get(0);
94 if (oleCopy != null && oleCopy.getLocation() != null && item.getItemLocation() != null) {
95 if (!oleCopy.getLocation().equalsIgnoreCase(item.getItemLocation())) {
96
97
98
99
100
101
102
103
104 preRulesOK = true;
105 }
106 }
107 }
108 }
109 }
110 preRulesOK &= super.doPrompts(document);
111 return preRulesOK;
112 }
113
114
115
116
117
118
119
120
121 protected boolean askForConfirmation(String questionType, String messageConstant, StringBuilder accountNumbers) {
122
123 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(
124 messageConstant);
125 if (questionText.contains("{")) {
126 questionText = prepareQuestionText(questionType, questionText, accountNumbers);
127 }
128
129 boolean confirmOverride = super.askOrAnalyzeYesNoQuestion(questionType, questionText);
130
131 if (!confirmOverride) {
132 event.setActionForwardName(OLEConstants.MAPPING_BASIC);
133 return false;
134 }
135 return true;
136 }
137
138
139
140
141
142
143
144
145 protected String prepareQuestionText(String questionType, String questionText, StringBuilder accountNumbers) {
146 if (StringUtils.equals(questionType, OLEConstants.SufficientFundCheck.REQUISITION_SFC_CHECKING_STRING)) {
147 questionText = StringUtils.replace(questionText, "{0}", accountNumbers.toString());
148 }
149 return questionText;
150 }
151
152 }