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