View Javadoc
1   /*
2    * Copyright 2007 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.module.purap.util;
17  
18  import org.kuali.ole.module.purap.businessobject.PurApItem;
19  import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
20  import org.kuali.rice.krad.util.ObjectUtils;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  /**
26   * Purchasing Accounts Payable Item Utilities.
27   * This class contains item utilities.
28   */
29  public class PurApItemUtils {
30  
31      /**
32       * Checks if an item is active. It is used mainly when were dealing with generic items (which may be po) And need to
33       * make sure the active rules are applied if it is a poitem
34       *
35       * @param item the purap item passed in
36       * @return true if item is active
37       */
38      public static boolean checkItemActive(PurApItem item) {
39          boolean active = true;
40          if (item instanceof PurchaseOrderItem) {
41              PurchaseOrderItem poi = (PurchaseOrderItem) item;
42              active = poi.isItemActiveIndicator();
43          }
44          return active;
45      }
46  
47      public static boolean isNonZeroExtended(PurApItem item) {
48          return (ObjectUtils.isNotNull(item) && ObjectUtils.isNotNull(item.getExtendedPrice()) && !item.getExtendedPrice().isZero());
49      }
50  
51      /**
52       * Helper to get aboveTheLineItems only from an item list
53       *
54       * @param items a list of items including above and below the line
55       * @return below the line items only
56       */
57      public static List<PurApItem> getAboveTheLineOnly(List<PurApItem> items) {
58          List<PurApItem> returnItems = new ArrayList<PurApItem>();
59          for (PurApItem item : items) {
60              if (item.getItemType().isLineItemIndicator()) {
61                  returnItems.add((PurApItem) ObjectUtils.deepCopy(item));
62              }
63          }
64          return returnItems;
65      }
66  
67      /**
68       * Counts the below the line, currently it relies on below the line being at the bottom
69       *
70       * @return a count of below the line items
71       */
72      public static int countBelowTheLineItems(List<PurApItem> items) {
73          int count = 0;
74          for (int i = items.size() - 1; i > 0; i--) {
75              PurApItem item = items.get(i);
76              // will have to change if we stop putting below the line at bottom
77              if (item.getItemType().isLineItemIndicator()) {
78                  break;
79              } else {
80                  count++;
81              }
82          }
83          return count;
84      }
85  
86  }