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.coa.businessobject.Account;
20 import org.kuali.ole.module.purap.PurapConstants;
21 import org.kuali.ole.module.purap.PurapPropertyConstants;
22 import org.kuali.ole.select.OleSelectConstant;
23 import org.kuali.ole.select.businessobject.OleInvoiceItem;
24 import org.kuali.ole.select.businessobject.OleSufficientFundCheck;
25 import org.kuali.ole.select.constants.OleSelectPropertyConstants;
26 import org.kuali.ole.select.document.OleInvoiceDocument;
27 import org.kuali.ole.select.document.service.OleInvoiceFundCheckService;
28 import org.kuali.ole.select.document.service.OleInvoiceService;
29 import org.kuali.ole.sys.OLEConstants;
30 import org.kuali.ole.sys.OLEKeyConstants;
31 import org.kuali.ole.sys.OLEPropertyConstants;
32 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
33 import org.kuali.ole.sys.context.SpringContext;
34 import org.kuali.ole.sys.document.validation.GenericValidation;
35 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
36 import org.kuali.rice.core.api.util.RiceKeyConstants;
37 import org.kuali.rice.core.api.util.type.KualiDecimal;
38 import org.kuali.rice.core.api.util.type.KualiInteger;
39 import org.kuali.rice.krad.service.BusinessObjectService;
40 import org.kuali.rice.krad.service.KRADServiceLocator;
41 import org.kuali.rice.krad.util.GlobalVariables;
42 import org.kuali.rice.krad.util.KRADConstants;
43
44 import java.sql.Timestamp;
45 import java.util.ArrayList;
46 import java.util.HashMap;
47 import java.util.List;
48 import java.util.Map;
49
50 public class OleInvoiceItemValidation extends GenericValidation {
51
52 private BusinessObjectService businessObjectService;
53
54 @Override
55 public boolean validate(AttributedDocumentEvent event) {
56 boolean valid = true;
57 boolean isUnordered = false;
58 boolean orderedWithQty = false;
59 int count = 0;
60 OleInvoiceDocument document = (OleInvoiceDocument) event.getDocument();
61 if ((document.getPaymentMethod() != null) && (document.getPaymentMethod().getPaymentMethodId() != null)) {
62 document.setPaymentMethodId(document.getPaymentMethod().getPaymentMethodId());
63 }
64
65 if(document.getPaymentMethodIdentifier() != null) {
66 String paymentType = SpringContext.getBean(OleInvoiceService.class).getPaymentMethodType(document.getPaymentMethodIdentifier());
67 if (paymentType.equals(OLEConstants.DEPOSIT)) {
68 for (OleInvoiceItem item : (List<OleInvoiceItem>) document.getItems()) {
69 if (item.getItemTypeCode().equals("ITEM")) {
70 if (item.getSourceAccountingLineList().size() <= 0) {
71 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.OFFSET_ACCT_LINE, OLEKeyConstants.ERROR_REQUIRED, PurapConstants.PRQSDocumentsStrings.OFFSET_ACCT_LINE);
72 valid = false;
73 }
74 if (item.getSourceAccountingLineList().size() > 0) {
75 for (SourceAccountingLine accountingLine : item.getSourceAccountingLineList()) {
76 String accNo = accountingLine.getAccountNumber();
77 Integer vendorIdentifier = document.getVendorHeaderGeneratedIdentifier();
78 if ((accNo != null && accNo != "") && (vendorIdentifier != null)) {
79 Map accMap = new HashMap();
80 accMap.put("accountNumber", accNo);
81 accMap.put("subFundGroupCode", "CLRREV");
82 accMap.put("vendorHeaderGeneratedIdentifier", vendorIdentifier);
83 List<Account> account = (List<Account>) KRADServiceLocator.getBusinessObjectService().findMatching(Account.class, accMap);
84 if (account.size() <= 0) {
85 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.OFFSET_ACCT_LINE, OleSelectConstant.ERROR_INVALID_ACC_NO, accNo);
86 valid = false;
87 }
88
89 }
90
91 }
92
93
94 }
95
96 }
97 }
98 }
99 }
100
101 List<OleInvoiceItem> items = document.getItems();
102 for (OleInvoiceItem item : items) {
103 count += 1;
104 if (item.getItemTypeCode().equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) {
105 isUnordered = true;
106 if (StringUtils.equalsIgnoreCase(item.getItemTypeCode(), PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) {
107 if (item.getItemQuantity() == null || item.getItemQuantity().isLessEqual(KualiDecimal.ZERO)) {
108 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_ITEM_QUANTITY_REQUIRED, "Item " + count);
109 valid = false;
110 }
111 }
112 }
113 if (item.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
114 if (StringUtils.equalsIgnoreCase(item.getItemTypeCode(), PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE) || StringUtils.equalsIgnoreCase(item.getItemTypeCode(), PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE)) {
115 if (item.getItemDescription() == null || item.getItemDescription().trim().length() <= 0) {
116 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, "Item " + count);
117 valid = false;
118 }
119 }
120 if (item.getItemQuantity() != null && item.getItemQuantity().isGreaterThan(KualiDecimal.ZERO)) {
121 if (item.getItemNoOfParts() == null || (item.getItemNoOfParts()).isLessEqual(KualiInteger.ZERO)) {
122 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_NO_OF_PARTS_REQUIRED, "Item " + count);
123 valid = false;
124 }
125 }
126 }
127 }
128 if (!isUnordered) {
129 for (OleInvoiceItem item : items) {
130 if (item.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
131 if (item.getItemQuantity() == null || item.getItemQuantity().isLessEqual(KualiDecimal.ZERO)) {
132 orderedWithQty = false;
133 } else {
134 orderedWithQty = true;
135 }
136 }
137 if (orderedWithQty) {
138 break;
139 }
140 }
141 }
142 if (!orderedWithQty) {
143 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_ATLEAST_ONE_ITEM_QTY_REQUIRED);
144 valid = false;
145 }
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250 return valid;
251
252 }
253
254
255 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
256 this.businessObjectService = businessObjectService;
257 }
258
259 public BusinessObjectService getBusinessObjectService() {
260 if (businessObjectService == null) {
261 businessObjectService = SpringContext.getBean(BusinessObjectService.class);
262 }
263 return businessObjectService;
264 }
265
266 }