View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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       * Constructs a OleRequisitionRule.java
61       */
62      public OleValidationRuleBase() {
63          super();
64      }
65  
66      @Override
67      public boolean processCustomAddDiscountRequisitionBusinessRules(Document document, OleRequisitionItem reqItem) {
68          boolean result = true;
69          /*if (reqItem.getItemListPrice() == null) {
70              reqItem.setItemUnitPrice(BigDecimal.ZERO);
71              GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_LIST_PRICE, new String[]{"List Price"});
72              LOG.debug("***Inside DiscountRequisitionBusinessRules ItemListPrice is null***");
73              result = false;
74          } else if ((reqItem.getItemListPrice()).isLessEqual(KualiDecimal.ZERO)) {
75              reqItem.setItemUnitPrice(BigDecimal.ZERO);
76              GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_LIST_PRICE_NON_ZERO, new String[]{"List Price"});
77              LOG.debug("***Inside DiscountRequisitionBusinessRules ItemListPrice is non-zero and positive***");
78              result = false;
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        /* if (purItem.getItemListPrice() == null) {
135             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_LIST_PRICE, new String[]{"List Price"});
136             LOG.debug("***Inside DiscountPurchaseOrderBusinessRules ItemListPrice is null***");
137             result = false;
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         /*if (payItem.getItemListPrice() == null || payItem.getItemListPrice().equals(BigDecimal.ZERO)) {
194             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_LIST_PRICE, new String[]{"List Price"});
195             LOG.debug("***Inside DiscountPaymentRequestBusinessRules ItemListPrice is null***");
196             result = false;
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        /* if (payItem.getExtendedPrice().equals(BigDecimal.ZERO) && payItem.getItemType().isAdditionalChargeIndicator()) {
255             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_LIST_PRICE, new String[]{"List Price"});
256             LOG.debug("***Inside processCustomAddDiscountInvoiceBusinessRules ItemListPrice is null***");
257             result = false;
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            /* if (account != null && account.getSubFundGroupCode().equalsIgnoreCase(subFundGroupParameter)) {
303                 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ACCOUNT_NUMBER, new String[]{"Payment Request"});
304                 result = false;
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             item.setItemForeignListPrice(KualiDecimal.ZERO);
316             LOG.debug("***Inside ForeignCurrencyRequisitionBusinessRules ItemForeignListPrice is null***");
317             result = true;
318         }
319         if (item.getItemForeignDiscount() != null && item.getItemForeignDiscountType() != null) {
320             if (item.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
321                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For requisition---------->");
322                 int inDecimalPoint = String.valueOf(item.getItemForeignDiscount()).indexOf(".");
323                 if (inDecimalPoint != -1) {
324                     if (String.valueOf(item.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
325                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
326                         LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For requisition ---------->");
327                         result = false;
328                     }
329                 } else {
330                     if (String.valueOf(item.getItemForeignDiscount()).length() > 2) {
331                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
332                         LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for  OleRequisitionItem----2------>");
333                         result = false;
334                     }
335                 }
336             } else {
337                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For requisition ---------->");
338                 if (item.getItemForeignListPrice() != null) {
339                     if (item.getItemForeignListPrice().compareTo(item.getItemForeignDiscount()) < 0) {
340                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
341                         LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for  OleRequisitionItem---------->");
342                         result = false;
343                     }
344                 }
345                 if (item.getItemForeignDiscount().bigDecimalValue().scale() > 4) {
346                     GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
347                     LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For requisition ---------->");
348                     result = false;
349                 }
350             }
351         }
352         return result;
353 
354     }
355 
356     @Override
357     public boolean processCustomForeignCurrencyPurchaseOrderBusinessRules(Document document, OlePurchaseOrderItem purItem) {
358         boolean result = true;
359         if (purItem.getItemForeignListPrice() == null) {
360             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
361             LOG.debug("***Inside ForeignCurrencyRequisitionBusinessRules ItemForeignListPrice is null***");
362             result = false;
363         }
364 
365         if (purItem.getItemForeignDiscount() != null && purItem.getItemForeignDiscountType() != null) {
366             if (purItem.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
367                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For requisition---------->");
368                 int inDecimalPoint = String.valueOf(purItem.getItemForeignDiscount()).indexOf(".");
369                 if (inDecimalPoint != -1) {
370                     if (String.valueOf(purItem.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
371                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
372                         LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For requisition ---------->");
373                         result = false;
374                     }
375                 } else {
376                     if (String.valueOf(purItem.getItemForeignDiscount()).length() > 2) {
377                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
378                         LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for  OleRequisitionItem----2------>");
379                         result = false;
380                     }
381                 }
382             } else {
383                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For requisition ---------->");
384                 if (purItem.getItemForeignListPrice() != null) {
385                     if (purItem.getItemForeignListPrice().compareTo(purItem.getItemForeignDiscount()) < 0) {
386                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
387                         LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for  OleRequisitionItem---------->");
388                         result = false;
389                     }
390                 }
391             }
392             if (purItem.getItemForeignDiscount().bigDecimalValue().scale() > 4) {
393                 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
394                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For requisition ---------->");
395                 result = false;
396             }
397         }
398         return result;
399     }
400 
401 
402     @Override
403     public boolean processCustomForeignCurrencyPaymentRequestBusinessRules(Document document, OlePaymentRequestItem payItem) {
404         boolean result = true;
405         if (payItem.getItemForeignListPrice() == null) {
406             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
407             LOG.debug("***Inside ForeignCurrencyPaymentRequestBusinessRules ItemForeignListPrice is null***");
408             result = false;
409         }
410 
411         if (payItem.getItemForeignDiscount() != null && payItem.getItemForeignDiscountType() != null) {
412             if (payItem.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
413                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For PaymentRequest---------->");
414                 int inDecimalPoint = String.valueOf(payItem.getItemForeignDiscount()).indexOf(".");
415                 if (inDecimalPoint != -1) {
416                     if (String.valueOf(payItem.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
417                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
418                         LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For PaymentRequest ---------->");
419                         result = false;
420                     }
421                 } else {
422                     if (String.valueOf(payItem.getItemForeignDiscount()).length() > 2) {
423                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
424                         LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for  OlePaymentRequestItem----2------>");
425                         result = false;
426                     }
427                 }
428             } else {
429                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For PaymentRequest ---------->");
430                 if (payItem.getItemForeignListPrice() != null) {
431                     if (payItem.getItemForeignListPrice().compareTo(payItem.getItemForeignDiscount()) < 0) {
432                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
433                         LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for  OlePaymentRequestItem---------->");
434                         result = false;
435                     }
436                 }
437             }
438             if (payItem.getItemForeignDiscount().bigDecimalValue().scale() > 4) {
439                 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
440                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For PaymentRequest ---------->");
441                 result = false;
442             }
443         }
444         return result;
445     }
446 
447     @Override
448     public boolean processCustomForeignCurrencyInvoiceBusinessRules(Document document, OleInvoiceItem payItem) {
449         boolean result = true;
450         if (payItem.getItemForeignListPrice() == null) {
451             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
452             LOG.debug("***Inside ForeignCurrencyInvoiceBusinessRules ItemForeignListPrice is null***");
453             result = false;
454         }
455 
456         if (payItem.getItemForeignDiscount() != null && payItem.getItemForeignDiscountType() != null) {
457             if (payItem.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
458                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For Invoice---------->");
459                 int inDecimalPoint = String.valueOf(payItem.getItemForeignDiscount()).indexOf(".");
460                 if (inDecimalPoint != -1) {
461                     if (String.valueOf(payItem.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
462                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
463                         LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For Invoice ---------->");
464                         result = false;
465                     }
466                 } else {
467                     if (String.valueOf(payItem.getItemForeignDiscount()).length() > 2) {
468                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
469                         LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for  OleInvoiceItem----2------>");
470                         result = false;
471                     }
472                 }
473             } else {
474                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For Invoice ---------->");
475                 if (payItem.getItemForeignListPrice() != null) {
476                     if (payItem.getItemForeignListPrice().compareTo(payItem.getItemForeignDiscount()) < 0) {
477                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
478                         LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for  OleInvoiceItem---------->");
479                         result = false;
480                     }
481                 }
482             }
483             if (payItem.getItemForeignDiscount().bigDecimalValue().scale() > 4) {
484                 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
485                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For Invoice ---------->");
486                 result = false;
487             }
488         }
489         return result;
490     }
491 
492 
493     /**
494      * @see org.kuali.rice.krad.rules.DocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.rice.krad.document.Document)
495      */
496     @Override
497     protected boolean processCustomSaveDocumentBusinessRules(Document document) {
498         if (document instanceof OleRequisitionDocument) {
499             OleRequisitionDocument oleRequisitionDocument = (OleRequisitionDocument) document;
500             selectVendorDetailsForRequisitionDocument(oleRequisitionDocument);
501             validateItemAccount(oleRequisitionDocument);
502             validateDeliverAddress(oleRequisitionDocument);
503         } else if (document instanceof OlePaymentRequestDocument) {
504             OlePaymentRequestDocument olePaymentRequestDocument = (OlePaymentRequestDocument) document;
505             if (olePaymentRequestDocument.getInvoiceIdentifier() == null) {
506                 selectVendorDetailsForPaymentRequestDocumet(olePaymentRequestDocument);
507             }
508 
509         } else if (document instanceof OleInvoiceDocument) {
510             OleInvoiceDocument oleInvoiceDocument = (OleInvoiceDocument) document;
511             oleInvoiceDocument.setPaymentMethodId(oleInvoiceDocument.getPaymentMethodId());
512             oleInvoiceDocument.setInvoiceCurrencyTypeId(oleInvoiceDocument.getInvoiceCurrencyTypeId());
513         } else if (document instanceof OlePurchaseOrderAmendmentDocument) {
514             OlePurchaseOrderAmendmentDocument olePurchaseOrderAmendmentDocument = (OlePurchaseOrderAmendmentDocument) document;
515             selectVendorDetailsForPurchaseOrderAmendmentDocument(olePurchaseOrderAmendmentDocument);
516         }
517         boolean result = super.processCustomSaveDocumentBusinessRules(document);
518         /*result &= isRequestorPhoneNumberValid(document);*/
519         return result;
520     }
521 
522     public void validateItemAccount(OleRequisitionDocument oleRequisitionDocument){
523         List<OleRequisitionItem> oleRequisitionItemList = oleRequisitionDocument.getItems();
524         for(OleRequisitionItem item : oleRequisitionItemList){
525             if(item.getItemTypeCode().equals("ITEM") && item.getSourceAccountingLines().size() <=0){
526                 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OLEConstants.NO_ACC_LINE);
527             }else{
528                 if(item.getExtendedPrice().isGreaterThan(KualiDecimal.ZERO) && item.getSourceAccountingLines().size()<=0){
529                     GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OLEConstants.NO_ADD_ACC_LINE,item.getItemTypeCode());
530                 }
531             }
532         }
533     }
534 
535     public void validateAdditionalCharges(OleRequisitionDocument oleRequisitionDocument){
536 
537 
538     }
539 
540     public void validateDeliverAddress(OleRequisitionDocument oleRequisitionDocument){
541         boolean receivingAddress = oleRequisitionDocument.getAddressToVendorIndicator();
542         if(receivingAddress){
543             if(oleRequisitionDocument.getReceivingName() == null){
544                 GlobalVariables.getMessageMap().putError(PurapConstants.DELIVERY_TAB_ERRORS, OLEConstants.NO_RECEIVING_ADDR);
545             }
546         }else{
547             if(oleRequisitionDocument.getDeliveryBuildingLine1Address() == null){
548                 GlobalVariables.getMessageMap().putError(PurapConstants.DELIVERY_TAB_ERRORS, OLEConstants.NO_DELIVERY_ADDR);
549             }
550         }
551     }
552 
553     public void selectVendorDetailsForRequisitionDocument(OleRequisitionDocument oleRequisitionDocument) {
554 
555         if(oleRequisitionDocument.getVendorName()== null || oleRequisitionDocument.getVendorName().isEmpty()){
556             GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.NO_VENDOR);
557         }
558         if (oleRequisitionDocument.getVendorAliasName() != null && oleRequisitionDocument.getVendorAliasName().length() > 0) { /* Checks Vendor name is not equal to null  */
559             /* Getting matching vendor for the given vendor alias name */
560             Map vendorAliasMap = new HashMap();
561             vendorAliasMap.put(OLEConstants.VENDOR_ALIAS_NAME, oleRequisitionDocument.getVendorAliasName());
562             org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
563             List<VendorAlias> vendorAliasList = (List<VendorAlias>) getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true);
564             if (vendorAliasList != null && vendorAliasList.size() > 0 && vendorAliasList.get(0) != null) {  /* if there matching vendor found for the given vendor alias name */
565                 if (oleRequisitionDocument.getVendorHeaderGeneratedIdentifier() == null && oleRequisitionDocument.getVendorDetailAssignedIdentifier() == null) {
566                     GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_SELECT);
567                 } else {
568                     String vendorDetailAssignedIdentifier = vendorAliasList.get(0).getVendorDetailAssignedIdentifier().toString();
569                     String VendorHeaderGeneratedIdentifier = vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier().toString();
570                     if (oleRequisitionDocument.getVendorHeaderGeneratedIdentifier().toString().equals(VendorHeaderGeneratedIdentifier) &&
571                             oleRequisitionDocument.getVendorDetailAssignedIdentifier().toString().equals(vendorDetailAssignedIdentifier)) {
572                         LOG.debug("###########vendors are allowed to save###########");
573                     } else {
574                         GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_SAME);
575                     }
576                 }
577             } else {     /* If there is no matching vendor found*/
578                 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_FOUND);
579             }
580         }
581     }
582 
583     public void selectVendorDetailsForPaymentRequestDocumet(OlePaymentRequestDocument olePaymentRequestDocument) {
584         olePaymentRequestDocument.setPaymentMethodId(olePaymentRequestDocument.getPaymentMethod().getPaymentMethodId());
585         if (((olePaymentRequestDocument.getVendorAliasName() != null && olePaymentRequestDocument.getVendorAliasName().length() > 0))) { /* Checks Vendor name is not equal to null  */
586             /* Getting matching vendor for the given vendor alias name */
587             Map vendorAliasMap = new HashMap();
588             vendorAliasMap.put(OLEConstants.VENDOR_ALIAS_NAME, olePaymentRequestDocument.getVendorAliasName());
589             org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
590             List<VendorAlias> vendorAliasList = (List<VendorAlias>) getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true);
591             if (vendorAliasList != null && vendorAliasList.size() > 0 && vendorAliasList.get(0) != null) {  /* if there matching vendor found for the given vendor alias name */
592                 if (olePaymentRequestDocument.getVendorHeaderGeneratedIdentifier() == null && olePaymentRequestDocument.getVendorDetailAssignedIdentifier() == null) {
593                     GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_SELECT);
594                 } else {
595                     String vendorDetailAssignedIdentifier = vendorAliasList.get(0).getVendorDetailAssignedIdentifier().toString();
596                     String VendorHeaderGeneratedIdentifier = vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier().toString();
597                     if (olePaymentRequestDocument.getVendorHeaderGeneratedIdentifier().toString().equals(VendorHeaderGeneratedIdentifier) &&
598                             olePaymentRequestDocument.getVendorDetailAssignedIdentifier().toString().equals(vendorDetailAssignedIdentifier)) {
599                         LOG.debug("###########vendors are allowed to save###########");
600                     } else {
601                         GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_SAME);
602                     }
603                 }
604             } else {     /* If there is no matching vendor found*/
605                 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_FOUND);
606             }
607         }
608     }
609 
610     public void selectVendorDetailsForPurchaseOrderAmendmentDocument(OlePurchaseOrderAmendmentDocument olePurchaseOrderAmendmentDocument) {
611         if (((olePurchaseOrderAmendmentDocument.getVendorAliasName() != null && olePurchaseOrderAmendmentDocument.getVendorAliasName().length() > 0))) { /* Checks Vendor name is not equal to null  */
612             /* Getting matching vendor for the given vendor alias name */
613             Map vendorAliasMap = new HashMap();
614             vendorAliasMap.put(OLEConstants.VENDOR_ALIAS_NAME, olePurchaseOrderAmendmentDocument.getVendorAliasName());
615             org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
616             List<VendorAlias> vendorAliasList = (List<VendorAlias>) getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true);
617             if (vendorAliasList != null && vendorAliasList.size() > 0 && vendorAliasList.get(0) != null) {  /* if there matching vendor found for the given vendor alias name */
618                 if (olePurchaseOrderAmendmentDocument.getVendorHeaderGeneratedIdentifier() == null && olePurchaseOrderAmendmentDocument.getVendorDetailAssignedIdentifier() == null) {
619                     GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_SELECT);
620                 } else {
621                     String vendorDetailAssignedIdentifier = vendorAliasList.get(0).getVendorDetailAssignedIdentifier().toString();
622                     String VendorHeaderGeneratedIdentifier = vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier().toString();
623                     if (olePurchaseOrderAmendmentDocument.getVendorHeaderGeneratedIdentifier().toString().equals(VendorHeaderGeneratedIdentifier) &&
624                             olePurchaseOrderAmendmentDocument.getVendorDetailAssignedIdentifier().toString().equals(vendorDetailAssignedIdentifier)) {
625                         LOG.debug("###########vendors are allowed to save###########");
626                     } else {
627                         GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_SAME);
628                     }
629                 }
630             } else {     /* If there is no matching vendor found*/
631                 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_FOUND);
632             }
633         }
634     }
635 
636     public boolean isRequestorPhoneNumberValid(Document document) {
637         boolean valid = true;
638         MessageMap errorMap = GlobalVariables.getMessageMap();
639         if (document instanceof RequisitionDocument) {
640             RequisitionDocument req = (RequisitionDocument) document;
641             String phNumber = req.getRequestorPersonPhoneNumber();
642             if (StringUtils.isNotEmpty(phNumber) && !SpringContext.getBean(OleForiegnVendorPhoneNumberService.class).isValidForiegnVendorPhoneNumber(phNumber)) {
643                 errorMap.putError(OleSelectConstant.REQUESTOR_PERSON_PHONE_NUMBER, OleSelectConstant.ERROR_REQUESTOR_PHONE_NUMBER);
644                 valid &= false;
645             }
646         } else if (document instanceof PurchaseOrderDocument) {
647             PurchaseOrderDocument req = (PurchaseOrderDocument) document;
648             String phNumber = req.getRequestorPersonPhoneNumber();
649             if (StringUtils.isNotEmpty(phNumber) && !SpringContext.getBean(OleForiegnVendorPhoneNumberService.class).isValidForiegnVendorPhoneNumber(phNumber)) {
650                 errorMap.putError(OleSelectConstant.PURCHASE_ORDER_PERSON_PHONE_NUMBER, OleSelectConstant.ERROR_REQUESTOR_PHONE_NUMBER);
651                 valid &= false;
652             }
653         }
654 
655         return valid;
656     }
657 
658     @Override
659     public boolean processCustomPaymentRequestDescriptionBusinessRules(Document document, OlePaymentRequestItem payItem) {
660         boolean validate = true;
661         if (payItem.getItemDescription() == null || payItem.getItemDescription().isEmpty()) {
662             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, new String[]{"Line Item"});
663             validate = false;
664         }
665         return validate;
666     }
667 
668     @Override
669     public boolean processCustomInvoiceDescriptionBusinessRules(Document document, OleInvoiceItem payItem) {
670         boolean validate = true;
671         if (payItem.getItemDescription() == null || payItem.getItemDescription().isEmpty()) {
672             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, new String[]{"Line Item"});
673             validate = false;
674         }
675         return validate;
676     }
677 
678     @Override
679     public boolean processCustomPurchaseOrderDescriptionBusinessRules(Document document, OlePurchaseOrderItem purItem) {
680         boolean validate = true;
681         if (purItem.getItemDescription() == null || purItem.getItemDescription().isEmpty()) {
682             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, new String[]{"Line Item"});
683             validate = false;
684         }
685         return validate;
686     }
687 
688     @Override
689     public boolean processCustomForeignCurrencyCreditMemoBusinessRules(Document document, OleCreditMemoItem creditMemoItem) {
690         boolean result = true;
691         if (creditMemoItem.getItemForeignListPrice() == null) {
692             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
693             LOG.debug("***Inside ForeignCurrencyCreditMemoBusinessRules ItemForeignListPrice is null***");
694             result = false;
695         }
696 
697         if (creditMemoItem.getItemForeignDiscount() != null && creditMemoItem.getItemForeignDiscountType() != null) {
698             if (creditMemoItem.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
699                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For CreditMemo---------->");
700                 int inDecimalPoint = String.valueOf(creditMemoItem.getItemForeignDiscount()).indexOf(".");
701                 if (inDecimalPoint != -1) {
702                     if (String.valueOf(creditMemoItem.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
703                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
704                         LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT CreditMemo ---------->");
705                         result = false;
706                     }
707                 } else {
708                     if (String.valueOf(creditMemoItem.getItemForeignDiscount()).length() > 2) {
709                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
710                         LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for  OleCreditMemoItem----2------>");
711                         result = false;
712                     }
713                 }
714             } else {
715                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For CreditMemoItem ---------->");
716                 if (creditMemoItem.getItemForeignListPrice() != null) {
717                     if (creditMemoItem.getItemForeignListPrice().compareTo(creditMemoItem.getItemForeignDiscount()) < 0) {
718                         GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
719                         LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for  OleCreditMemoItem---------->");
720                         result = false;
721                     }
722                 }
723             }
724             if (creditMemoItem.getItemForeignDiscount().bigDecimalValue().scale() > 4) {
725                 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT, new String[]{"Discount"});
726                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For CreditMemoItem ---------->");
727                 result = false;
728             }
729         }
730         return result;
731     }
732 
733     @Override
734     public boolean processCustomCreditMemoDescriptionBusinessRules(Document document, OleCreditMemoItem creditMemoItem) {
735         boolean validate = true;
736         if (creditMemoItem.getItemDescription() == null || creditMemoItem.getItemDescription().isEmpty()) {
737             GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, new String[]{"Line Item"});
738             validate = false;
739         }
740         return validate;
741     }
742 
743     @Override
744     public boolean processCustomAddCopiesRequisitionBusinessRules(Document document, OleRequisitionItem reqItem) {
745         boolean isValid = true;
746         if (reqItem.getItemType() != null && reqItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
747             if (reqItem.getItemQuantity() != null && reqItem.getItemNoOfParts() != null && (reqItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
748                     || reqItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1)))) {
749                 if (reqItem.getLinkToOrderOption().equals(OLEConstants.NB_PRINT) || reqItem.getLinkToOrderOption().equals(OLEConstants.EB_PRINT)){
750                     OleCopyHelperService oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
751                     isValid = oleCopyHelperService.checkForTotalCopiesGreaterThanQuantityAtSubmit(reqItem.getCopies(), reqItem.getItemQuantity());
752                     for (OleCopies copies : reqItem.getCopies()) {
753                         List<String> volChar = new ArrayList<>();
754                         String[] volNumbers = copies.getVolumeNumber() != null ? copies.getVolumeNumber().split(",") : new String[0];
755                         for (String volStr : volNumbers) {
756                             volChar.add(volStr);
757                         }
758                         Integer itemCount = volChar.size();
759                         isValid &= oleCopyHelperService.checkCopyEntry(
760                                 copies.getItemCopies(), copies.getLocationCopies(), itemCount, reqItem.getItemQuantity(),
761                                 reqItem.getItemNoOfParts(), reqItem.getCopies(), reqItem.getVolumeNumber(), true);
762                         if (isValid)
763                             reqItem.setItemLocation(OLEConstants.MULTIPLE_ITEM_LOC);
764                     }
765                 }
766                 else if (reqItem.getLinkToOrderOption().equals(OLEConstants.NB_ELECTRONIC) || reqItem.getLinkToOrderOption().equals(OLEConstants.EB_ELECTRONIC)){
767                     GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
768                             OLEConstants.ITEM_COPIESANDPARTS_SHOULDNOT_BE_GREATERTHAN_ONE_EINSTANCE, new String[]{});
769                 }
770             } else {
771                 if (reqItem.getItemLocation() == null || reqItem.getItemLocation().isEmpty()) {
772                     GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
773                             OLEConstants.ITEM_LOCATION_REQUIRED, new String[]{});
774                 }
775             }
776         }
777         return isValid;
778     }
779 
780     public boolean processCustomAddCopiesPurchaseOrderBusinessRules(Document document, OlePurchaseOrderItem purItem) {
781         boolean isValid = true;
782         if (purItem.getItemType() != null && purItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
783             if (purItem.getItemQuantity() != null && purItem.getItemNoOfParts() != null && (purItem.getItemQuantity().isGreaterThan(new KualiDecimal(1))
784                     || purItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1)))) {
785                 if (purItem.getLinkToOrderOption().equals(OLEConstants.NB_PRINT) || purItem.getLinkToOrderOption().equals(OLEConstants.EB_PRINT)){
786                     OleCopyHelperService oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
787                     isValid = oleCopyHelperService.checkForTotalCopiesGreaterThanQuantityAtSubmit(purItem.getCopies(), purItem.getItemQuantity());
788                     for (OleCopies copies : purItem.getCopies()) {
789                         List<String> volChar = new ArrayList<>();
790                         String[] volNumbers = copies.getVolumeNumber() != null ? copies.getVolumeNumber().split(",") : new String[0];
791                         for (String volStr : volNumbers) {
792                             volChar.add(volStr);
793                         }
794                         Integer itemCount = volChar.size();
795                         isValid &= oleCopyHelperService.checkCopyEntry(
796                                 copies.getItemCopies(), copies.getLocationCopies(), itemCount, purItem.getItemQuantity(),
797                                 purItem.getItemNoOfParts(), purItem.getCopies(), purItem.getVolumeNumber(), true);
798                         if (isValid)
799                             purItem.setItemLocation(OLEConstants.MULTIPLE_ITEM_LOC);
800                     }
801                 }
802                 else if (purItem.getLinkToOrderOption().equals(OLEConstants.NB_ELECTRONIC) || purItem.getLinkToOrderOption().equals(OLEConstants.EB_ELECTRONIC)){
803                     GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
804                             OLEConstants.ITEM_COPIESANDPARTS_SHOULDNOT_BE_GREATERTHAN_ONE_EINSTANCE, new String[]{});
805                 }
806             } else {
807                 if (purItem.getItemLocation() == null || purItem.getItemLocation().isEmpty()) {
808                     GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
809                             OLEConstants.ITEM_LOCATION_REQUIRED, new String[]{});
810                 }
811             }
812         }
813         return isValid;
814     }
815 
816     public boolean processInvoiceSubscriptionOverlayBusinessRules(Document document, OleInvoiceItem invoiceItem) {
817         boolean isValid = true;
818         if (invoiceItem.getItemType().isQuantityBasedGeneralLedgerIndicator() && invoiceItem.isSubscriptionOverlap()) {
819             if (invoiceItem.getSubscriptionFromDate() == null) {
820                 isValid &= false;
821                 GlobalVariables.getMessageMap().putErrorForSectionId(OleSelectConstant.INVOICE_ITEM_SECTION_ID,
822                         OleSelectConstant.ERROR_SUBSCIPTION_FROM_DATE_REQUIRED);
823             }
824             if (invoiceItem.getSubscriptionToDate() == null) {
825                 isValid &= false;
826                 GlobalVariables.getMessageMap().putErrorForSectionId(OleSelectConstant.INVOICE_ITEM_SECTION_ID,
827                         OleSelectConstant.ERROR_SUBSCIPTION_TO_DATE_REQUIRED);
828             }
829         }
830         if (invoiceItem.getSubscriptionFromDate() != null && invoiceItem.getSubscriptionToDate() != null &&
831             invoiceItem.getSubscriptionFromDate().compareTo(invoiceItem.getSubscriptionToDate()) > 0)  {
832                 isValid &= false;
833                 GlobalVariables.getMessageMap().putErrorForSectionId(OleSelectConstant.INVOICE_ITEM_SECTION_ID,
834                             OleSelectConstant.ERROR_SUBSCIPTION_FROM_DATE_GREATER_THAN_TO_DATE);
835         }
836         return isValid;
837     }
838 
839     public ParameterService getParameterService() {
840         if (parameterService == null) {
841             parameterService = SpringContext.getBean(ParameterService.class);
842         }
843         return parameterService;
844     }
845 
846     private LookupService getLookupService() {
847         return KRADServiceLocatorWeb.getLookupService();
848     }
849 }