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
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.ole.coa.businessobject.Account;
21 import org.kuali.ole.module.purap.PurapConstants;
22 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
23 import org.kuali.ole.module.purap.document.RequisitionDocument;
24 import org.kuali.ole.select.OleSelectConstant;
25 import org.kuali.ole.select.businessobject.*;
26 import org.kuali.ole.select.constants.OleSelectPropertyConstants;
27 import org.kuali.ole.select.document.OleInvoiceDocument;
28 import org.kuali.ole.select.document.OlePaymentRequestDocument;
29 import org.kuali.ole.select.document.OlePurchaseOrderAmendmentDocument;
30 import org.kuali.ole.select.document.OleRequisitionDocument;
31 import org.kuali.ole.select.document.service.OleCopyHelperService;
32 import org.kuali.ole.select.document.service.OleDocstoreHelperService;
33 import org.kuali.ole.select.service.OleForiegnVendorPhoneNumberService;
34 import org.kuali.ole.sys.OLEConstants;
35 import org.kuali.ole.sys.context.SpringContext;
36 import org.kuali.ole.sys.document.validation.impl.AccountingRuleEngineRuleBase;
37 import org.kuali.ole.vnd.businessobject.VendorAlias;
38 import org.kuali.rice.core.api.util.type.KualiDecimal;
39 import org.kuali.rice.core.api.util.type.KualiInteger;
40 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
41 import org.kuali.rice.krad.document.Document;
42 import org.kuali.rice.krad.service.BusinessObjectService;
43 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
44 import org.kuali.rice.krad.service.LookupService;
45 import org.kuali.rice.krad.util.GlobalVariables;
46 import org.kuali.rice.krad.util.MessageMap;
47
48 import java.math.BigDecimal;
49 import java.util.ArrayList;
50 import java.util.HashMap;
51 import java.util.List;
52 import java.util.Map;
53
54 public class OleValidationRuleBase extends AccountingRuleEngineRuleBase implements OleValidationRule {
55 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleValidationRuleBase.class);
56
57 protected static ParameterService parameterService;
58
59
60
61
62 public OleValidationRuleBase() {
63 super();
64 }
65
66 @Override
67 public boolean processCustomAddDiscountRequisitionBusinessRules(Document document, OleRequisitionItem reqItem) {
68 boolean result = true;
69
70
71
72
73
74
75
76
77
78
79
80 if (reqItem.getItemDiscount() != null && reqItem.getItemDiscountType() != null) {
81 if (reqItem.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
82 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules '%' for OleRequisitionItem---------->");
83 int inDecimalPoint = String.valueOf(reqItem.getItemDiscount()).indexOf(".");
84 if (inDecimalPoint != -1) {
85 if (String.valueOf(reqItem.getItemDiscount()).substring(0, inDecimalPoint).length() > 2) {
86 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
87 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OleRequisitionItem ---------->");
88 result = false;
89 }
90 } else {
91
92 if (String.valueOf(reqItem.getItemDiscount()).length() > 2) {
93 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
94 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OleRequisitionItem----2------>");
95 result = false;
96 }
97 }
98 } else {
99 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules '#' for OleRequisitionItem---------->");
100 if (reqItem.getItemListPrice() != null) {
101 if (reqItem.getItemListPrice().compareTo(reqItem.getItemDiscount()) < 0) {
102 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
103 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for OleRequisitionItem---------->");
104 result = false;
105 }
106 }
107 }
108 if (reqItem.getItemDiscount().bigDecimalValue().scale() > 4) {
109 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
110 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DECIMAL_LIMIT for OleRequisitionItem ---------->");
111 result = false;
112 }
113 }
114 if (reqItem.getSourceAccountingLines().size() > 0) {
115 String accountNumber = reqItem.getSourceAccountingLine(0).getAccountNumber();
116 String chartOfAccountsCode = reqItem.getSourceAccountingLine(0).getChartOfAccountsCode();
117 Map<String, String> criteria = new HashMap<String, String>();
118 criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
119 criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
120 Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class, criteria);
121 String subFundGroupParameter = getParameterService().getParameterValueAsString(Account.class,
122 OleSelectConstant.SUB_FUND_GRP_CD);
123 if (account != null && account.getSubFundGroupCode().equalsIgnoreCase(subFundGroupParameter)) {
124 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ACCOUNT_NUMBER, new String[]{"Requisition"});
125 result = false;
126 }
127 }
128 return result;
129 }
130
131 @Override
132 public boolean processCustomAddDiscountPurchaseOrderBusinessRules(Document document, OlePurchaseOrderItem purItem) {
133 boolean result = true;
134
135
136
137
138
139 if (purItem.getItemDiscount() != null && purItem.getItemDiscountType() != null) {
140 if (purItem.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
141 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules '%' for OleRequisitionItem---------->");
142 int inDecimalPoint = String.valueOf(purItem.getItemDiscount()).indexOf(".");
143 if (inDecimalPoint != -1) {
144 if (String.valueOf(purItem.getItemDiscount()).substring(0, inDecimalPoint).length() > 2) {
145 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
146 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OleRequisitionItem ---------->");
147 result = false;
148 }
149 } else {
150
151 if (String.valueOf(purItem.getItemDiscount()).length() > 2) {
152 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
153 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OleRequisitionItem----2------>");
154 result = false;
155 }
156 }
157 } else {
158
159 if (purItem.getItemListPrice() != null) {
160 if (purItem.getItemListPrice().compareTo(purItem.getItemDiscount()) < 0) {
161 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
162 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for OleRequisitionItem---------->");
163 result = false;
164 }
165 }
166 }
167 if (purItem.getItemDiscount().bigDecimalValue().scale() > 4) {
168 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
169 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DECIMAL_LIMIT for OleRequisitionItem ---------->");
170 result = false;
171 }
172 }
173 if (purItem.getSourceAccountingLines().size() > 0) {
174 String accountNumber = purItem.getSourceAccountingLine(0).getAccountNumber();
175 String chartOfAccountsCode = purItem.getSourceAccountingLine(0).getChartOfAccountsCode();
176 Map<String, String> criteria = new HashMap<String, String>();
177 criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
178 criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
179 Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class, criteria);
180 String subFundGroupParameter = getParameterService().getParameterValueAsString(Account.class,
181 OleSelectConstant.SUB_FUND_GRP_CD);
182 if (account != null && account.getSubFundGroupCode().equalsIgnoreCase(subFundGroupParameter)) {
183 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ACCOUNT_NUMBER, new String[]{"Purchase Order"});
184 result = false;
185 }
186 }
187 return result;
188 }
189
190 @Override
191 public boolean processCustomAddDiscountPaymentRequestBusinessRules(Document document, OlePaymentRequestItem payItem) {
192 boolean result = true;
193
194
195
196
197
198
199 if (payItem.getItemDiscount() != null && payItem.getItemDiscountType() != null) {
200 if (payItem.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
201 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules '%' for OlePaymentRequestItem---------->");
202 int inDecimalPoint = String.valueOf(payItem.getItemDiscount()).indexOf(".");
203 if (inDecimalPoint != -1) {
204 if (String.valueOf(payItem.getItemDiscount()).substring(0, inDecimalPoint).length() > 2) {
205 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
206 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OlePaymentRequestItem ---------->");
207 result = false;
208 } else if (payItem.getItemDiscount().bigDecimalValue().scale() > 4) {
209 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
210 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DECIMAL_LIMIT for OlePaymentRequestItem ---------->");
211 result = false;
212 }
213 } else {
214 if (String.valueOf(payItem.getItemDiscount()).length() > 2) {
215 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
216 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OlePaymentRequestItem----2------>");
217 result = false;
218 }
219
220 }
221 } else {
222 if (payItem.getItemListPrice().compareTo(payItem.getItemDiscount()) < 0) {
223 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
224 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for OlePaymentRequestItem---------->");
225 result = false;
226 }
227 }
228 }
229 if (payItem.getSourceAccountingLines().size() > 0) {
230 String accountNumber = payItem.getSourceAccountingLine(0).getAccountNumber();
231 String chartOfAccountsCode = payItem.getSourceAccountingLine(0).getChartOfAccountsCode();
232 Map<String, String> criteria = new HashMap<String, String>();
233 criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
234 criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
235 Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class, criteria);
236 String subFundGroupParameter = getParameterService().getParameterValueAsString(Account.class,
237 OleSelectConstant.SUB_FUND_GRP_CD);
238 if (account != null && account.getSubFundGroupCode().equalsIgnoreCase(subFundGroupParameter)) {
239 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ACCOUNT_NUMBER, new String[]{"Payment Request"});
240 result = false;
241 }
242 }
243 return result;
244 }
245
246 @Override
247 public boolean processCustomAddDiscountInvoiceBusinessRules(Document document, OleInvoiceItem payItem) {
248 boolean result = true;
249 if (payItem.getItemListPrice() == null ) {
250 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_LIST_PRICE, new String[]{"List Price"});
251 LOG.debug("***Inside processCustomAddDiscountInvoiceBusinessRules ItemListPrice is null***");
252 result = false;
253 }
254
255
256
257
258
259
260 if (payItem.getItemDiscount() != null && payItem.getItemDiscountType() != null) {
261 if (payItem.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
262 LOG.debug("<------------------Inside processCustomAddDiscountInvoiceBusinessRules '%' for OleInvoiceItem---------->");
263 int inDecimalPoint = String.valueOf(payItem.getItemDiscount()).indexOf(".");
264 if (inDecimalPoint != -1) {
265 if (String.valueOf(payItem.getItemDiscount()).substring(0, inDecimalPoint).length() > 2) {
266 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
267 LOG.debug("<------------------Inside processCustomAddDiscountInvoiceBusinessRules PERCENTAGE_MAX_LIMIT for OleInvoiceItem ---------->");
268 result = false;
269 } else if (payItem.getItemDiscount().bigDecimalValue().scale() > 4) {
270 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
271 LOG.debug("<------------------Inside processCustomAddDiscountInvoiceBusinessRules MAX_DECIMAL_LIMIT for OleInvoiceItem ---------->");
272 result = false;
273 }
274 } else {
275 if (String.valueOf(payItem.getItemDiscount()).length() > 2) {
276 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
277 LOG.debug("<------------------Inside processCustomAddDiscountInvoiceBusinessRules PERCENTAGE_MAX_LIMIT for OleInvoiceItem----2------>");
278 result = false;
279 }
280
281 }
282 } else {
283 if (payItem.getItemListPrice().compareTo(payItem.getItemDiscount()) < 0) {
284 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
285 LOG.debug("<------------------Inside processCustomAddDiscountInvoiceBusinessRules MAX_DISCOUNT_LIMIT for OleInvoiceItem---------->");
286 result = false;
287 }
288 }
289 }
290 if (payItem.getSourceAccountingLines().size() > 0) {
291 String accountNumber = payItem.getSourceAccountingLine(0).getAccountNumber();
292 String chartOfAccountsCode = payItem.getSourceAccountingLine(0).getChartOfAccountsCode();
293 Map<String, String> criteria = new HashMap<String, String>();
294 criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
295 criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
296 Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class, criteria);
297 String subFundGroupParameter = getParameterService().getParameterValueAsString(Account.class,
298 OleSelectConstant.SUB_FUND_GRP_CD);
299 if (LOG.isDebugEnabled()){
300 LOG.debug("subFundGroupParameter value in processCustomAddDiscountInvoiceBusinessRules >>>>>>>" + subFundGroupParameter);
301 }
302
303
304
305
306 }
307 return result;
308 }
309
310 @Override
311 public boolean processCustomForeignCurrencyRequisitionBusinessRules(Document document, OleRequisitionItem item) {
312 boolean result = true;
313 if (item.getItemForeignListPrice() == null) {
314 item.setItemUnitPrice(BigDecimal.ZERO);
315 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
316 LOG.debug("***Inside ForeignCurrencyRequisitionBusinessRules ItemForeignListPrice is null***");
317 result = false;
318 } else if ((item.getItemForeignListPrice()).isLessEqual(KualiDecimal.ZERO)) {
319 item.setItemUnitPrice(BigDecimal.ZERO);
320 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_LIST_PRICE_NON_ZERO, new String[]{"Foreign List Price"});
321 LOG.debug("***Inside DiscountPaymentRequestBusinessRules ItemListPrice is non-zero and positive***");
322 result = false;
323 }
324 if (item.getItemForeignDiscount() != null && item.getItemForeignDiscountType() != null) {
325 if (item.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
326 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For requisition---------->");
327 int inDecimalPoint = String.valueOf(item.getItemForeignDiscount()).indexOf(".");
328 if (inDecimalPoint != -1) {
329 if (String.valueOf(item.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
330 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
331 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For requisition ---------->");
332 result = false;
333 }
334 } else {
335 if (String.valueOf(item.getItemForeignDiscount()).length() > 2) {
336 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
337 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OleRequisitionItem----2------>");
338 result = false;
339 }
340 }
341 } else {
342 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For requisition ---------->");
343 if (item.getItemForeignListPrice() != null) {
344 if (item.getItemForeignListPrice().compareTo(item.getItemForeignDiscount()) < 0) {
345 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
346 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for OleRequisitionItem---------->");
347 result = false;
348 }
349 }
350 if (item.getItemForeignDiscount().bigDecimalValue().scale() > 4) {
351 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
352 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For requisition ---------->");
353 result = false;
354 }
355 }
356 }
357 return result;
358
359 }
360
361 @Override
362 public boolean processCustomForeignCurrencyPurchaseOrderBusinessRules(Document document, OlePurchaseOrderItem purItem) {
363 boolean result = true;
364 if (purItem.getItemForeignListPrice() == null) {
365 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
366 LOG.debug("***Inside ForeignCurrencyRequisitionBusinessRules ItemForeignListPrice is null***");
367 result = false;
368 }
369
370 if (purItem.getItemForeignDiscount() != null && purItem.getItemForeignDiscountType() != null) {
371 if (purItem.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
372 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For requisition---------->");
373 int inDecimalPoint = String.valueOf(purItem.getItemForeignDiscount()).indexOf(".");
374 if (inDecimalPoint != -1) {
375 if (String.valueOf(purItem.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
376 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
377 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For requisition ---------->");
378 result = false;
379 }
380 } else {
381 if (String.valueOf(purItem.getItemForeignDiscount()).length() > 2) {
382 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
383 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OleRequisitionItem----2------>");
384 result = false;
385 }
386 }
387 } else {
388 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For requisition ---------->");
389 if (purItem.getItemForeignListPrice() != null) {
390 if (purItem.getItemForeignListPrice().compareTo(purItem.getItemForeignDiscount()) < 0) {
391 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
392 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for OleRequisitionItem---------->");
393 result = false;
394 }
395 }
396 }
397 if (purItem.getItemForeignDiscount().bigDecimalValue().scale() > 4) {
398 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
399 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For requisition ---------->");
400 result = false;
401 }
402 }
403 return result;
404 }
405
406
407 @Override
408 public boolean processCustomForeignCurrencyPaymentRequestBusinessRules(Document document, OlePaymentRequestItem payItem) {
409 boolean result = true;
410 if (payItem.getItemForeignListPrice() == null) {
411 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
412 LOG.debug("***Inside ForeignCurrencyPaymentRequestBusinessRules ItemForeignListPrice is null***");
413 result = false;
414 }
415
416 if (payItem.getItemForeignDiscount() != null && payItem.getItemForeignDiscountType() != null) {
417 if (payItem.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
418 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For PaymentRequest---------->");
419 int inDecimalPoint = String.valueOf(payItem.getItemForeignDiscount()).indexOf(".");
420 if (inDecimalPoint != -1) {
421 if (String.valueOf(payItem.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
422 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
423 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For PaymentRequest ---------->");
424 result = false;
425 }
426 } else {
427 if (String.valueOf(payItem.getItemForeignDiscount()).length() > 2) {
428 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
429 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OlePaymentRequestItem----2------>");
430 result = false;
431 }
432 }
433 } else {
434 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For PaymentRequest ---------->");
435 if (payItem.getItemForeignListPrice() != null) {
436 if (payItem.getItemForeignListPrice().compareTo(payItem.getItemForeignDiscount()) < 0) {
437 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
438 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for OlePaymentRequestItem---------->");
439 result = false;
440 }
441 }
442 }
443 if (payItem.getItemForeignDiscount().bigDecimalValue().scale() > 4) {
444 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
445 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For PaymentRequest ---------->");
446 result = false;
447 }
448 }
449 return result;
450 }
451
452 @Override
453 public boolean processCustomForeignCurrencyInvoiceBusinessRules(Document document, OleInvoiceItem payItem) {
454 boolean result = true;
455 if (payItem.getItemForeignListPrice() == null) {
456 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
457 LOG.debug("***Inside ForeignCurrencyInvoiceBusinessRules ItemForeignListPrice is null***");
458 result = false;
459 }
460
461 if (payItem.getItemForeignDiscount() != null && payItem.getItemForeignDiscountType() != null) {
462 if (payItem.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
463 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For Invoice---------->");
464 int inDecimalPoint = String.valueOf(payItem.getItemForeignDiscount()).indexOf(".");
465 if (inDecimalPoint != -1) {
466 if (String.valueOf(payItem.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
467 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
468 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For Invoice ---------->");
469 result = false;
470 }
471 } else {
472 if (String.valueOf(payItem.getItemForeignDiscount()).length() > 2) {
473 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
474 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OleInvoiceItem----2------>");
475 result = false;
476 }
477 }
478 } else {
479 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For Invoice ---------->");
480 if (payItem.getItemForeignListPrice() != null) {
481 if (payItem.getItemForeignListPrice().compareTo(payItem.getItemForeignDiscount()) < 0) {
482 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
483 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for OleInvoiceItem---------->");
484 result = false;
485 }
486 }
487 }
488 if (payItem.getItemForeignDiscount().bigDecimalValue().scale() > 4) {
489 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
490 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For Invoice ---------->");
491 result = false;
492 }
493 }
494 return result;
495 }
496
497
498
499
500
501 @Override
502 protected boolean processCustomSaveDocumentBusinessRules(Document document) {
503 if (document instanceof OleRequisitionDocument) {
504 OleRequisitionDocument oleRequisitionDocument = (OleRequisitionDocument) document;
505 selectVendorDetailsForRequisitionDocument(oleRequisitionDocument);
506 validateItemAccount(oleRequisitionDocument);
507 validateDeliverAddress(oleRequisitionDocument);
508 } else if (document instanceof OlePaymentRequestDocument) {
509 OlePaymentRequestDocument olePaymentRequestDocument = (OlePaymentRequestDocument) document;
510 if (olePaymentRequestDocument.getInvoiceIdentifier() == null) {
511 selectVendorDetailsForPaymentRequestDocumet(olePaymentRequestDocument);
512 }
513
514 } else if (document instanceof OleInvoiceDocument) {
515 OleInvoiceDocument oleInvoiceDocument = (OleInvoiceDocument) document;
516 oleInvoiceDocument.setPaymentMethodId(oleInvoiceDocument.getPaymentMethodId());
517 oleInvoiceDocument.setInvoiceCurrencyTypeId(oleInvoiceDocument.getInvoiceCurrencyTypeId());
518 } else if (document instanceof OlePurchaseOrderAmendmentDocument) {
519 OlePurchaseOrderAmendmentDocument olePurchaseOrderAmendmentDocument = (OlePurchaseOrderAmendmentDocument) document;
520 selectVendorDetailsForPurchaseOrderAmendmentDocument(olePurchaseOrderAmendmentDocument);
521 }
522 boolean result = super.processCustomSaveDocumentBusinessRules(document);
523
524 return result;
525 }
526
527 public void validateItemAccount(OleRequisitionDocument oleRequisitionDocument){
528 List<OleRequisitionItem> oleRequisitionItemList = oleRequisitionDocument.getItems();
529 for(OleRequisitionItem item : oleRequisitionItemList){
530 if(item.getItemTypeCode().equals("ITEM") && item.getSourceAccountingLines().size() <=0){
531 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OLEConstants.NO_ACC_LINE);
532 }else{
533 if(item.getExtendedPrice().isGreaterThan(KualiDecimal.ZERO) && item.getSourceAccountingLines().size()<=0){
534 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OLEConstants.NO_ADD_ACC_LINE,item.getItemTypeCode());
535 }
536 }
537 }
538 }
539
540 public void validateAdditionalCharges(OleRequisitionDocument oleRequisitionDocument){
541
542
543 }
544
545 public void validateDeliverAddress(OleRequisitionDocument oleRequisitionDocument){
546 boolean receivingAddress = oleRequisitionDocument.getAddressToVendorIndicator();
547 if(receivingAddress){
548 if(oleRequisitionDocument.getReceivingName() == null){
549 GlobalVariables.getMessageMap().putError(PurapConstants.DELIVERY_TAB_ERRORS, OLEConstants.NO_RECEIVING_ADDR);
550 }
551 }else{
552 if(oleRequisitionDocument.getDeliveryBuildingLine1Address() == null){
553 GlobalVariables.getMessageMap().putError(PurapConstants.DELIVERY_TAB_ERRORS, OLEConstants.NO_DELIVERY_ADDR);
554 }
555 }
556 }
557
558 public void selectVendorDetailsForRequisitionDocument(OleRequisitionDocument oleRequisitionDocument) {
559
560 if(oleRequisitionDocument.getVendorName()== null || oleRequisitionDocument.getVendorName().isEmpty()){
561 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.NO_VENDOR);
562 }
563 if (oleRequisitionDocument.getVendorAliasName() != null && oleRequisitionDocument.getVendorAliasName().length() > 0) {
564
565 Map vendorAliasMap = new HashMap();
566 vendorAliasMap.put(OLEConstants.VENDOR_ALIAS_NAME, oleRequisitionDocument.getVendorAliasName());
567 org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
568 List<VendorAlias> vendorAliasList = (List<VendorAlias>) getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true);
569 if (vendorAliasList != null && vendorAliasList.size() > 0 && vendorAliasList.get(0) != null) {
570 if (oleRequisitionDocument.getVendorHeaderGeneratedIdentifier() == null && oleRequisitionDocument.getVendorDetailAssignedIdentifier() == null) {
571 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_SELECT);
572 } else {
573 String vendorDetailAssignedIdentifier = vendorAliasList.get(0).getVendorDetailAssignedIdentifier().toString();
574 String VendorHeaderGeneratedIdentifier = vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier().toString();
575 if (oleRequisitionDocument.getVendorHeaderGeneratedIdentifier().toString().equals(VendorHeaderGeneratedIdentifier) &&
576 oleRequisitionDocument.getVendorDetailAssignedIdentifier().toString().equals(vendorDetailAssignedIdentifier)) {
577 LOG.debug("###########vendors are allowed to save###########");
578 } else {
579 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_SAME);
580 }
581 }
582 } else {
583 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_FOUND);
584 }
585 }
586 }
587
588 public void selectVendorDetailsForPaymentRequestDocumet(OlePaymentRequestDocument olePaymentRequestDocument) {
589 olePaymentRequestDocument.setPaymentMethodId(olePaymentRequestDocument.getPaymentMethod().getPaymentMethodId());
590 if (((olePaymentRequestDocument.getVendorAliasName() != null && olePaymentRequestDocument.getVendorAliasName().length() > 0))) {
591
592 Map vendorAliasMap = new HashMap();
593 vendorAliasMap.put(OLEConstants.VENDOR_ALIAS_NAME, olePaymentRequestDocument.getVendorAliasName());
594 org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
595 List<VendorAlias> vendorAliasList = (List<VendorAlias>) getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true);
596 if (vendorAliasList != null && vendorAliasList.size() > 0 && vendorAliasList.get(0) != null) {
597 if (olePaymentRequestDocument.getVendorHeaderGeneratedIdentifier() == null && olePaymentRequestDocument.getVendorDetailAssignedIdentifier() == null) {
598 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_SELECT);
599 } else {
600 String vendorDetailAssignedIdentifier = vendorAliasList.get(0).getVendorDetailAssignedIdentifier().toString();
601 String VendorHeaderGeneratedIdentifier = vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier().toString();
602 if (olePaymentRequestDocument.getVendorHeaderGeneratedIdentifier().toString().equals(VendorHeaderGeneratedIdentifier) &&
603 olePaymentRequestDocument.getVendorDetailAssignedIdentifier().toString().equals(vendorDetailAssignedIdentifier)) {
604 LOG.debug("###########vendors are allowed to save###########");
605 } else {
606 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_SAME);
607 }
608 }
609 } else {
610 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_FOUND);
611 }
612 }
613 }
614
615 public void selectVendorDetailsForPurchaseOrderAmendmentDocument(OlePurchaseOrderAmendmentDocument olePurchaseOrderAmendmentDocument) {
616 if (((olePurchaseOrderAmendmentDocument.getVendorAliasName() != null && olePurchaseOrderAmendmentDocument.getVendorAliasName().length() > 0))) {
617
618 Map vendorAliasMap = new HashMap();
619 vendorAliasMap.put(OLEConstants.VENDOR_ALIAS_NAME, olePurchaseOrderAmendmentDocument.getVendorAliasName());
620 org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
621 List<VendorAlias> vendorAliasList = (List<VendorAlias>) getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true);
622 if (vendorAliasList != null && vendorAliasList.size() > 0 && vendorAliasList.get(0) != null) {
623 if (olePurchaseOrderAmendmentDocument.getVendorHeaderGeneratedIdentifier() == null && olePurchaseOrderAmendmentDocument.getVendorDetailAssignedIdentifier() == null) {
624 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_SELECT);
625 } else {
626 String vendorDetailAssignedIdentifier = vendorAliasList.get(0).getVendorDetailAssignedIdentifier().toString();
627 String VendorHeaderGeneratedIdentifier = vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier().toString();
628 if (olePurchaseOrderAmendmentDocument.getVendorHeaderGeneratedIdentifier().toString().equals(VendorHeaderGeneratedIdentifier) &&
629 olePurchaseOrderAmendmentDocument.getVendorDetailAssignedIdentifier().toString().equals(vendorDetailAssignedIdentifier)) {
630 LOG.debug("###########vendors are allowed to save###########");
631 } else {
632 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_SAME);
633 }
634 }
635 } else {
636 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_FOUND);
637 }
638 }
639 }
640
641 public boolean isRequestorPhoneNumberValid(Document document) {
642 boolean valid = true;
643 MessageMap errorMap = GlobalVariables.getMessageMap();
644 if (document instanceof RequisitionDocument) {
645 RequisitionDocument req = (RequisitionDocument) document;
646 String phNumber = req.getRequestorPersonPhoneNumber();
647 if (StringUtils.isNotEmpty(phNumber) && !SpringContext.getBean(OleForiegnVendorPhoneNumberService.class).isValidForiegnVendorPhoneNumber(phNumber)) {
648 errorMap.putError(OleSelectConstant.REQUESTOR_PERSON_PHONE_NUMBER, OleSelectConstant.ERROR_REQUESTOR_PHONE_NUMBER);
649 valid &= false;
650 }
651 } else if (document instanceof PurchaseOrderDocument) {
652 PurchaseOrderDocument req = (PurchaseOrderDocument) document;
653 String phNumber = req.getRequestorPersonPhoneNumber();
654 if (StringUtils.isNotEmpty(phNumber) && !SpringContext.getBean(OleForiegnVendorPhoneNumberService.class).isValidForiegnVendorPhoneNumber(phNumber)) {
655 errorMap.putError(OleSelectConstant.PURCHASE_ORDER_PERSON_PHONE_NUMBER, OleSelectConstant.ERROR_REQUESTOR_PHONE_NUMBER);
656 valid &= false;
657 }
658 }
659
660 return valid;
661 }
662
663 @Override
664 public boolean processCustomPaymentRequestDescriptionBusinessRules(Document document, OlePaymentRequestItem payItem) {
665 boolean validate = true;
666 if (payItem.getItemDescription() == null || payItem.getItemDescription().isEmpty()) {
667 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, new String[]{"Line Item"});
668 validate = false;
669 }
670 return validate;
671 }
672
673 @Override
674 public boolean processCustomInvoiceDescriptionBusinessRules(Document document, OleInvoiceItem payItem) {
675 boolean validate = true;
676 if (payItem.getItemDescription() == null || payItem.getItemDescription().isEmpty()) {
677 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, new String[]{"Line Item"});
678 validate = false;
679 }
680 return validate;
681 }
682
683 @Override
684 public boolean processCustomPurchaseOrderDescriptionBusinessRules(Document document, OlePurchaseOrderItem purItem) {
685 boolean validate = true;
686 if (purItem.getItemDescription() == null || purItem.getItemDescription().isEmpty()) {
687 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, new String[]{"Line Item"});
688 validate = false;
689 }
690 return validate;
691 }
692
693 @Override
694 public boolean processCustomForeignCurrencyCreditMemoBusinessRules(Document document, OleCreditMemoItem creditMemoItem) {
695 boolean result = true;
696 if (creditMemoItem.getItemForeignListPrice() == null) {
697 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
698 LOG.debug("***Inside ForeignCurrencyCreditMemoBusinessRules ItemForeignListPrice is null***");
699 result = false;
700 }
701
702 if (creditMemoItem.getItemForeignDiscount() != null && creditMemoItem.getItemForeignDiscountType() != null) {
703 if (creditMemoItem.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
704 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For CreditMemo---------->");
705 int inDecimalPoint = String.valueOf(creditMemoItem.getItemForeignDiscount()).indexOf(".");
706 if (inDecimalPoint != -1) {
707 if (String.valueOf(creditMemoItem.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
708 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
709 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT CreditMemo ---------->");
710 result = false;
711 }
712 } else {
713 if (String.valueOf(creditMemoItem.getItemForeignDiscount()).length() > 2) {
714 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
715 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for OleCreditMemoItem----2------>");
716 result = false;
717 }
718 }
719 } else {
720 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For CreditMemoItem ---------->");
721 if (creditMemoItem.getItemForeignListPrice() != null) {
722 if (creditMemoItem.getItemForeignListPrice().compareTo(creditMemoItem.getItemForeignDiscount()) < 0) {
723 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
724 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for OleCreditMemoItem---------->");
725 result = false;
726 }
727 }
728 }
729 if (creditMemoItem.getItemForeignDiscount().bigDecimalValue().scale() > 4) {
730 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
731 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For CreditMemoItem ---------->");
732 result = false;
733 }
734 }
735 return result;
736 }
737
738 @Override
739 public boolean processCustomCreditMemoDescriptionBusinessRules(Document document, OleCreditMemoItem creditMemoItem) {
740 boolean validate = true;
741 if (creditMemoItem.getItemDescription() == null || creditMemoItem.getItemDescription().isEmpty()) {
742 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, new String[]{"Line Item"});
743 validate = false;
744 }
745 return validate;
746 }
747
748 @Override
749 public boolean processCustomAddCopiesRequisitionBusinessRules(Document document, OleRequisitionItem reqItem) {
750 boolean isValid = true;
751 if (reqItem.getItemType() != null && reqItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
752 if (reqItem.getItemQuantity() != null && reqItem.getItemNoOfParts() != null && (reqItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
753 || reqItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1)))) {
754 if (reqItem.getLinkToOrderOption().equals(OLEConstants.NB_PRINT) || reqItem.getLinkToOrderOption().equals(OLEConstants.EB_PRINT)){
755 OleCopyHelperService oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
756 isValid = oleCopyHelperService.checkForTotalCopiesGreaterThanQuantityAtSubmit(reqItem.getCopies(), reqItem.getItemQuantity());
757 for (OleCopies copies : reqItem.getCopies()) {
758 List<String> volChar = new ArrayList<>();
759 String[] volNumbers = copies.getVolumeNumber() != null ? copies.getVolumeNumber().split(",") : new String[0];
760 for (String volStr : volNumbers) {
761 volChar.add(volStr);
762 }
763 Integer itemCount = volChar.size();
764 isValid &= oleCopyHelperService.checkCopyEntry(
765 copies.getItemCopies(), copies.getLocationCopies(), itemCount, reqItem.getItemQuantity(),
766 reqItem.getItemNoOfParts(), reqItem.getCopies(), reqItem.getVolumeNumber(), true);
767 if (isValid)
768 reqItem.setItemLocation(OLEConstants.MULTIPLE_ITEM_LOC);
769 }
770 }
771 else if (reqItem.getLinkToOrderOption().equals(OLEConstants.NB_ELECTRONIC) || reqItem.getLinkToOrderOption().equals(OLEConstants.EB_ELECTRONIC)){
772 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
773 OLEConstants.ITEM_COPIESANDPARTS_SHOULDNOT_BE_GREATERTHAN_ONE_EINSTANCE, new String[]{});
774 }
775 } else {
776 if (reqItem.getItemLocation() == null || reqItem.getItemLocation().isEmpty()) {
777 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
778 OLEConstants.ITEM_LOCATION_REQUIRED, new String[]{});
779 }
780 }
781 }
782 return isValid;
783 }
784
785 public boolean processCustomAddCopiesPurchaseOrderBusinessRules(Document document, OlePurchaseOrderItem purItem) {
786 boolean isValid = true;
787 if (purItem.getItemType() != null && purItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
788 if (purItem.getItemQuantity() != null && purItem.getItemNoOfParts() != null && (purItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
789 || purItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1)))) {
790 if (purItem.getLinkToOrderOption().equals(OLEConstants.NB_PRINT) || purItem.getLinkToOrderOption().equals(OLEConstants.EB_PRINT)){
791 OleCopyHelperService oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
792 isValid = oleCopyHelperService.checkForTotalCopiesGreaterThanQuantityAtSubmit(purItem.getCopies(), purItem.getItemQuantity());
793 for (OleCopies copies : purItem.getCopies()) {
794 List<String> volChar = new ArrayList<>();
795 String[] volNumbers = copies.getVolumeNumber() != null ? copies.getVolumeNumber().split(",") : new String[0];
796 for (String volStr : volNumbers) {
797 volChar.add(volStr);
798 }
799 Integer itemCount = volChar.size();
800 isValid &= oleCopyHelperService.checkCopyEntry(
801 copies.getItemCopies(), copies.getLocationCopies(), itemCount, purItem.getItemQuantity(),
802 purItem.getItemNoOfParts(), purItem.getCopies(), purItem.getVolumeNumber(), true);
803 if (isValid)
804 purItem.setItemLocation(OLEConstants.MULTIPLE_ITEM_LOC);
805 }
806 }
807 else if (purItem.getLinkToOrderOption().equals(OLEConstants.NB_ELECTRONIC) || purItem.getLinkToOrderOption().equals(OLEConstants.EB_ELECTRONIC)){
808 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
809 OLEConstants.ITEM_COPIESANDPARTS_SHOULDNOT_BE_GREATERTHAN_ONE_EINSTANCE, new String[]{});
810 }
811 } else {
812 if (purItem.getItemLocation() == null || purItem.getItemLocation().isEmpty()) {
813 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
814 OLEConstants.ITEM_LOCATION_REQUIRED, new String[]{});
815 }
816 }
817 }
818 return isValid;
819 }
820
821 public boolean processInvoiceSubscriptionOverlayBusinessRules(Document document, OleInvoiceItem invoiceItem) {
822 boolean isValid = true;
823 if (invoiceItem.getItemType().isQuantityBasedGeneralLedgerIndicator() && invoiceItem.isSubscriptionOverlap()) {
824 if (invoiceItem.getSubscriptionFromDate() == null) {
825 isValid &= false;
826 GlobalVariables.getMessageMap().putErrorForSectionId(OleSelectConstant.INVOICE_ITEM_SECTION_ID,
827 OleSelectConstant.ERROR_SUBSCIPTION_FROM_DATE_REQUIRED);
828 }
829 if (invoiceItem.getSubscriptionToDate() == null) {
830 isValid &= false;
831 GlobalVariables.getMessageMap().putErrorForSectionId(OleSelectConstant.INVOICE_ITEM_SECTION_ID,
832 OleSelectConstant.ERROR_SUBSCIPTION_TO_DATE_REQUIRED);
833 }
834 }
835 if (invoiceItem.getSubscriptionFromDate() != null && invoiceItem.getSubscriptionToDate() != null &&
836 invoiceItem.getSubscriptionFromDate().compareTo(invoiceItem.getSubscriptionToDate()) > 0) {
837 isValid &= false;
838 GlobalVariables.getMessageMap().putErrorForSectionId(OleSelectConstant.INVOICE_ITEM_SECTION_ID,
839 OleSelectConstant.ERROR_SUBSCIPTION_FROM_DATE_GREATER_THAN_TO_DATE);
840 }
841 return isValid;
842 }
843
844 public ParameterService getParameterService() {
845 if (parameterService == null) {
846 parameterService = SpringContext.getBean(ParameterService.class);
847 }
848 return parameterService;
849 }
850
851 private LookupService getLookupService() {
852 return KRADServiceLocatorWeb.getLookupService();
853 }
854 }