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.InvoiceItem;
23  import org.kuali.ole.module.purap.document.validation.impl.InvoiceProcessItemValidation;
24  import org.kuali.rice.krad.util.GlobalVariables;
25  import org.kuali.rice.krad.util.ObjectUtils;
26  
27  public class OleInvoiceProcessItemValidation extends InvoiceProcessItemValidation {
28  
29      /**
30       * Validates above the line items.
31       *
32       * @param item             - invoice item
33       * @param identifierString - identifier string used to mark in an error map
34       * @return
35       */
36      @Override
37      protected boolean validateAboveTheLineItems(InvoiceItem 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          if (ObjectUtils.isNotNull(item.getExtendedPrice())) {
60  
61              // here we must require the user to enter some value for quantity if they want a credit amount associated
62              if (ObjectUtils.isNull(item.getItemQuantity()) || item.getItemQuantity().isZero()) {
63                  // here we have a user not entering a quantity with an extended amount but the PO has a quantity...require user to
64                  // enter a quantity
65                  valid = false;
66                  GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_QUANTITY_REQUIRED, ItemFields.INVOICE_QUANTITY, identifierString, ItemFields.OPEN_QUANTITY);
67              }
68          }
69  
70          // check that non-quantity based items are not trying to pay on a zero encumbrance amount (check only prior to ap approval)
71          if ((ObjectUtils.isNull(item.getInvoice().getPurapDocumentIdentifier())) || (PurapConstants.InvoiceStatuses.APPDOC_IN_PROCESS.equals(item.getInvoice().getApplicationDocumentStatus()))) {
72              if ((item.getItemType().isAmountBasedGeneralLedgerIndicator()) && ((item.getExtendedPrice() != null) && item.getExtendedPrice().isNonZero())) {
73                  if (item.getPoOutstandingAmount() == null || item.getPoOutstandingAmount().isZero()) {
74                      valid = false;
75                      GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_AMOUNT_ALREADY_PAID, identifierString);
76                  }
77              }
78          }
79         /* if(StringUtils.equalsIgnoreCase(item.getItemTypeCode(),PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)){
80              if(item.getItemQuantity()==null || item.getItemQuantity().isLessEqual(KualiDecimal.ZERO)){
81                  valid=false;
82                  GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,OleSelectConstant.ERROR_ITEM_QUANTITY_REQUIRED , identifierString);
83              }
84          }
85          if(StringUtils.equalsIgnoreCase(item.getItemTypeCode(),PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE) || StringUtils.equalsIgnoreCase(item.getItemTypeCode(),PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE) ){
86              if (item.getItemDescription() == null || item.getItemDescription().trim().length() <= 0) {
87                  GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, identifierString);
88                  valid= false;
89              }
90          }
91          OleInvoiceItem oleItem = (OleInvoiceItem) item;
92          if(oleItem.getItemQuantity()!=null && oleItem.getItemQuantity().isGreaterThan(KualiDecimal.ZERO)){   
93              if(oleItem.getItemNoOfParts()==null ||new KualiDecimal(oleItem.getItemNoOfParts()).isLessEqual(KualiDecimal.ZERO)){
94                  GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_NO_OF_PARTS_REQUIRED, identifierString);
95                  valid=false;
96              }
97          }*/
98          return valid;
99      }
100 
101 
102 }