001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.module.purap.businessobject;
017
018 import java.math.BigDecimal;
019
020 import org.apache.commons.lang.StringUtils;
021 import org.kuali.kfs.module.purap.PurapPropertyConstants;
022 import org.kuali.kfs.module.purap.document.PurchasingDocument;
023 import org.kuali.kfs.sys.businessobject.UnitOfMeasure;
024 import org.kuali.kfs.vnd.businessobject.CommodityCode;
025 import org.kuali.rice.kns.util.ObjectUtils;
026
027 /**
028 * Purchasing Item Base Business Object.
029 */
030 public abstract class PurchasingItemBase extends PurApItemBase implements PurchasingItem {
031
032 private String purchasingCommodityCode;
033
034 private CommodityCode commodityCode;
035
036 private UnitOfMeasure itemUnitOfMeasure;
037
038 /**
039 * @see org.kuali.kfs.module.purap.businessobject.PurApItem#isConsideredEntered()
040 */
041 public boolean isConsideredEntered() {
042 if (this instanceof PurchaseOrderItem) {
043 // if item is PO item... only validate active items
044 PurchaseOrderItem poi = (PurchaseOrderItem) this;
045 if (!poi.isItemActiveIndicator()) {
046 return false;
047 }
048 }
049 if (getItemType().isAdditionalChargeIndicator()) {
050 if ((ObjectUtils.isNull(getItemUnitPrice())) && (StringUtils.isBlank(getItemDescription())) && (getSourceAccountingLines().isEmpty())) {
051 return false;
052 }
053 }
054 return true;
055 }
056
057 /**
058 * Determines if the Purchasing Item is empty.
059 *
060 * @return boolean - true if item is empty, false if conditions show its not empty.
061 */
062 public boolean isEmpty() {
063 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()));
064 }
065
066 /**
067 * Determines if the Purchasing Item Detail is empty.
068 *
069 * @return boolean - true if item is empty, false if conditions show its not empty.
070 */
071 public boolean isItemDetailEmpty() {
072 boolean empty = true;
073 empty &= ObjectUtils.isNull(getItemQuantity()) || StringUtils.isEmpty(getItemQuantity().toString());
074 empty &= StringUtils.isEmpty(getItemUnitOfMeasureCode());
075 empty &= StringUtils.isEmpty(getItemCatalogNumber());
076 empty &= StringUtils.isEmpty(getItemDescription());
077 empty &= ObjectUtils.isNull(getItemUnitPrice()) || (getItemUnitPrice().compareTo(BigDecimal.ZERO) == 0);
078 return empty;
079 }
080
081 public CommodityCode getCommodityCode() {
082 if (ObjectUtils.isNull(commodityCode) || !StringUtils.equalsIgnoreCase( commodityCode.getPurchasingCommodityCode(), getPurchasingCommodityCode()) ) {
083 refreshReferenceObject(PurapPropertyConstants.COMMODITY_CODE);
084 }
085 return commodityCode;
086 }
087
088 public void setCommodityCode(CommodityCode commodityCode) {
089 this.commodityCode = commodityCode;
090 }
091
092 public String getPurchasingCommodityCode() {
093 return purchasingCommodityCode;
094 }
095
096 public void setPurchasingCommodityCode(String purchasingCommodityCode) {
097 this.purchasingCommodityCode = (StringUtils.isNotBlank(purchasingCommodityCode) ? purchasingCommodityCode.toUpperCase() : purchasingCommodityCode);
098 }
099
100 public PurchasingCapitalAssetItem getPurchasingCapitalAssetItem(){
101 PurchasingDocument pd = (PurchasingDocument)this.getPurapDocument();
102 if (this.getItemIdentifier() != null) {
103 return pd.getPurchasingCapitalAssetItem(this.getItemIdentifier());
104 }
105 else {
106 return null;
107 }
108 }
109
110 public UnitOfMeasure getItemUnitOfMeasure() {
111 if (ObjectUtils.isNull(itemUnitOfMeasure) || !StringUtils.equalsIgnoreCase( itemUnitOfMeasure.getItemUnitOfMeasureCode(), getItemUnitOfMeasureCode()) ) {
112 refreshReferenceObject(PurapPropertyConstants.ITEM_UNIT_OF_MEASURE);
113 }
114 return itemUnitOfMeasure;
115 }
116
117 public void setItemUnitOfMeasure(UnitOfMeasure itemUnitOfMeasure) {
118 this.itemUnitOfMeasure = itemUnitOfMeasure;
119 }
120
121 public boolean isNewItemForAmendment() {
122 return false;
123 }
124 }