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  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.module.purap.PurapConstants;
20  import org.kuali.ole.module.purap.PurapConstants.ItemFields;
21  import org.kuali.ole.module.purap.PurapKeyConstants;
22  import org.kuali.ole.module.purap.businessobject.PaymentRequestItem;
23  import org.kuali.ole.module.purap.document.validation.impl.PaymentRequestProcessItemValidation;
24  import org.kuali.rice.krad.util.GlobalVariables;
25  import org.kuali.rice.krad.util.ObjectUtils;
26  
27  public class OlePaymentRequestProcessItemValidation extends PaymentRequestProcessItemValidation {
28  
29      /**
30       * Validates above the line items.
31       *
32       * @param item             - payment request item
33       * @param identifierString - identifier string used to mark in an error map
34       * @return
35       */
36      @Override
37      protected boolean validateAboveTheLineItems(PaymentRequestItem item, String identifierString, boolean isReceivingDocumentRequiredIndicator) {
38          boolean valid = true;
39          // Currently Quantity is allowed to be NULL on screen;
40          // must be either a positive number or NULL for DB
41          if (ObjectUtils.isNotNull(item.getItemQuantity())) {
42              if (item.getItemQuantity().isNegative()) {
43                  // if quantity is negative give an error
44                  valid = false;
45                  GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_AMOUNT_BELOW_ZERO, ItemFields.INVOICE_QUANTITY, identifierString);
46              }
47              if (!isReceivingDocumentRequiredIndicator) {
48                  if (!StringUtils.equalsIgnoreCase(item.getItemTypeCode(), PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) {
49                      if (item.getPoOutstandingQuantity().isLessThan(item.getItemQuantity())) {
50                          valid = false;
51                          GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_QUANTITY_TOO_MANY, ItemFields.INVOICE_QUANTITY, identifierString, ItemFields.OPEN_QUANTITY);
52                      }
53                  }
54              }
55  
56          }
57          if (ObjectUtils.isNotNull(item.getExtendedPrice()) && item.getExtendedPrice().isPositive() && ObjectUtils.isNotNull(item.getPoOutstandingQuantity()) && item.getPoOutstandingQuantity().isPositive()) {
58  
59              // here we must require the user to enter some value for quantity if they want a credit amount associated
60              if (ObjectUtils.isNull(item.getItemQuantity()) || item.getItemQuantity().isZero()) {
61                  // here we have a user not entering a quantity with an extended amount but the PO has a quantity...require user to
62                  // enter a quantity
63                  valid = false;
64                  GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_QUANTITY_REQUIRED, ItemFields.INVOICE_QUANTITY, identifierString, ItemFields.OPEN_QUANTITY);
65              }
66          }
67  
68          // check that non-quantity based items are not trying to pay on a zero encumbrance amount (check only prior to ap approval)
69          if ((ObjectUtils.isNull(item.getPaymentRequest().getPurapDocumentIdentifier())) || (PurapConstants.PaymentRequestStatuses.APPDOC_IN_PROCESS.equals(item.getPaymentRequest().getApplicationDocumentStatus()))) {
70              if ((item.getItemType().isAmountBasedGeneralLedgerIndicator()) && ((item.getExtendedPrice() != null) && item.getExtendedPrice().isNonZero())) {
71                  if (item.getPoOutstandingAmount() == null || item.getPoOutstandingAmount().isZero()) {
72                      valid = false;
73                      GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_AMOUNT_ALREADY_PAID, identifierString);
74                  }
75              }
76          }
77         /* if(StringUtils.equalsIgnoreCase(item.getItemTypeCode(),PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)){
78              if(item.getItemQuantity()==null || item.getItemQuantity().isLessEqual(KualiDecimal.ZERO)){
79                  valid=false;
80                  GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,OleSelectConstant.ERROR_ITEM_QUANTITY_REQUIRED , identifierString);
81              }
82          }
83          if(StringUtils.equalsIgnoreCase(item.getItemTypeCode(),PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE) || StringUtils.equalsIgnoreCase(item.getItemTypeCode(),PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE) ){
84              if (item.getItemDescription() == null || item.getItemDescription().trim().length() <= 0) {
85                  GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, identifierString);
86                  valid= false;
87              }
88          }
89          OlePaymentRequestItem oleItem = (OlePaymentRequestItem) item;       
90          if(oleItem.getItemQuantity()!=null && oleItem.getItemQuantity().isGreaterThan(KualiDecimal.ZERO)){   
91              if(oleItem.getItemNoOfParts()==null ||new KualiDecimal(oleItem.getItemNoOfParts()).isLessEqual(KualiDecimal.ZERO)){
92                  GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_NO_OF_PARTS_REQUIRED, identifierString);
93                  valid=false;
94              }
95          }*/
96          return valid;
97      }
98  
99  
100 }