View Javadoc
1   /*
2    * Copyright 2006 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.businessobject;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.module.purap.PurapPropertyConstants;
20  import org.kuali.ole.module.purap.document.PurchasingDocument;
21  import org.kuali.ole.sys.businessobject.UnitOfMeasure;
22  import org.kuali.ole.vnd.businessobject.CommodityCode;
23  import org.kuali.rice.krad.util.ObjectUtils;
24  
25  import java.math.BigDecimal;
26  
27  /**
28   * Purchasing Item Base Business Object.
29   */
30  public abstract class PurchasingItemBase extends PurApItemBase implements PurchasingItem {
31  
32      private String purchasingCommodityCode;
33  
34      private CommodityCode commodityCode;
35  
36      private UnitOfMeasure itemUnitOfMeasure;
37  
38      /**
39       * @see org.kuali.ole.module.purap.businessobject.PurApItem#isConsideredEntered()
40       */
41      public boolean isConsideredEntered() {
42          if (this instanceof PurchaseOrderItem) {
43              // if item is PO item... only validate active items
44              PurchaseOrderItem poi = (PurchaseOrderItem) this;
45              if (!poi.isItemActiveIndicator()) {
46                  return false;
47              }
48          }
49          if (getItemType().isAdditionalChargeIndicator()) {
50              if ((ObjectUtils.isNull(getItemUnitPrice())) && (StringUtils.isBlank(getItemDescription())) && (getSourceAccountingLines().isEmpty())) {
51                  return false;
52              }
53          }
54          return true;
55      }
56  
57      /**
58       * Determines if the Purchasing Item is empty.
59       *
60       * @return boolean - true if item is empty, false if conditions show its not empty.
61       */
62      public boolean isEmpty() {
63          return !(StringUtils.isNotEmpty(getItemUnitOfMeasureCode()) || StringUtils.isNotEmpty(getItemCatalogNumber()) || StringUtils.isNotEmpty(getItemDescription()) || StringUtils.isNotEmpty(getItemAuxiliaryPartIdentifier()) || ObjectUtils.isNotNull(getItemQuantity()) || (ObjectUtils.isNotNull(getItemUnitPrice()) && (getItemUnitPrice().compareTo(BigDecimal.ZERO) != 0)) || (!this.isAccountListEmpty()));
64      }
65  
66      /**
67       * Determines if the Purchasing Item Detail is empty.
68       *
69       * @return boolean - true if item is empty, false if conditions show its not empty.
70       */
71      public boolean isItemDetailEmpty() {
72          boolean empty = true;
73          empty &= ObjectUtils.isNull(getItemQuantity()) || StringUtils.isEmpty(getItemQuantity().toString());
74          empty &= StringUtils.isEmpty(getItemUnitOfMeasureCode());
75          empty &= StringUtils.isEmpty(getItemCatalogNumber());
76          empty &= StringUtils.isEmpty(getItemDescription());
77          empty &= ObjectUtils.isNull(getItemUnitPrice()) || (getItemUnitPrice().compareTo(BigDecimal.ZERO) == 0);
78          return empty;
79      }
80  
81      public CommodityCode getCommodityCode() {
82          if (ObjectUtils.isNull(commodityCode) || !StringUtils.equalsIgnoreCase(commodityCode.getPurchasingCommodityCode(), getPurchasingCommodityCode())) {
83              refreshReferenceObject(PurapPropertyConstants.COMMODITY_CODE);
84          }
85          return commodityCode;
86      }
87  
88      public void setCommodityCode(CommodityCode commodityCode) {
89          this.commodityCode = commodityCode;
90      }
91  
92      public String getPurchasingCommodityCode() {
93          return purchasingCommodityCode;
94      }
95  
96      public void setPurchasingCommodityCode(String purchasingCommodityCode) {
97          this.purchasingCommodityCode = (StringUtils.isNotBlank(purchasingCommodityCode) ? purchasingCommodityCode.toUpperCase() : purchasingCommodityCode);
98      }
99  
100     public PurchasingCapitalAssetItem getPurchasingCapitalAssetItem() {
101         PurchasingDocument pd = (PurchasingDocument) this.getPurapDocument();
102         if (this.getItemIdentifier() != null) {
103             return pd.getPurchasingCapitalAssetItem(this.getItemIdentifier());
104         } else {
105             return null;
106         }
107     }
108 
109     public UnitOfMeasure getItemUnitOfMeasure() {
110         if (ObjectUtils.isNull(itemUnitOfMeasure) || !StringUtils.equalsIgnoreCase(itemUnitOfMeasure.getItemUnitOfMeasureCode(), getItemUnitOfMeasureCode())) {
111             refreshReferenceObject(PurapPropertyConstants.ITEM_UNIT_OF_MEASURE);
112         }
113         return itemUnitOfMeasure;
114     }
115 
116     public void setItemUnitOfMeasure(UnitOfMeasure itemUnitOfMeasure) {
117         this.itemUnitOfMeasure = itemUnitOfMeasure;
118     }
119 
120     public boolean isNewItemForAmendment() {
121         return false;
122     }
123 }