001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.purap.bo;
017:
018: import java.math.BigDecimal;
019:
020: import org.apache.commons.lang.StringUtils;
021: import org.kuali.core.util.KualiDecimal;
022: import org.kuali.core.util.ObjectUtils;
023: import org.kuali.module.purap.util.PurApItemUtils;
024:
025: /**
026: * Base class for Accounts Payable Item Business Objects.
027: */
028: public abstract class AccountsPayableItemBase extends PurApItemBase
029: implements AccountsPayableItem {
030: private KualiDecimal extendedPrice;
031:
032: /**
033: * Method defaults to {@link #isConsideredEnteredWithZero()}
034: *
035: * @see org.kuali.module.purap.bo.PurchasingApItem#isConsideredEntered()
036: */
037: public boolean isConsideredEntered() {
038: return isConsideredEnteredWithZero();
039: }
040:
041: public boolean isEligibleDisplay() {
042: return isConsideredEnteredWithZero();
043: }
044:
045: public boolean isConsideredEnteredWithZero() {
046: return isConsideredEntered(true);
047: }
048:
049: public boolean isConsideredEnteredWithoutZero() {
050: return isConsideredEntered(false);
051: }
052:
053: /**
054: * This method is used to determine whether an item has been entered that is we are satisfied there's enough info to continue
055: * processing that particular item. It is currently used by the rules class to determine when it's necessary to run rules on
056: * items (so that lines processors don't touch won't be validated) and to determine when to show items (in combination with the
057: * full entry mode)
058: *
059: * @param allowsZero if this is true zero will be considered the same as null.
060: * @return true if the item is considered entered false otherwise
061: */
062: private boolean isConsideredEntered(boolean allowsZero) {
063: if (getItemType().isItemTypeAboveTheLineIndicator()) {
064: if ((getItemType().isQuantityBasedGeneralLedgerIndicator())) {
065: if ((ObjectUtils.isNull(getItemQuantity()))
066: && (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice()
067: .isZero()))) {
068: return false;
069: }
070: } else {
071: if (ObjectUtils.isNull(getExtendedPrice())
072: || (allowsZero && getExtendedPrice().isZero())) {
073: return false;
074: }
075: }
076: } else {
077: if ((ObjectUtils.isNull(getItemUnitPrice()) || (allowsZero && this
078: .getItemUnitPrice().compareTo(new BigDecimal(0)) == 0))
079: && (StringUtils.isBlank(getItemDescription()))) {
080: return false;
081: }
082: }
083:
084: return true;
085: }
086:
087: public boolean isNonZeroAmount() {
088: return PurApItemUtils.isNonZeroExtended(this );
089: }
090:
091: /**
092: * Gets the extendedPrice attribute. this override is necessary because extended price needs to be set based on the unit price
093: * for below the line(without this it would always be empty) NOTE: this should always return zero instead of null.
094: *
095: * @return Returns the extendedPrice.
096: */
097: public KualiDecimal getExtendedPrice() {
098: if (ObjectUtils.isNotNull(this .getItemUnitPrice())
099: && !this .getItemType()
100: .isQuantityBasedGeneralLedgerIndicator()) {
101: extendedPrice = new KualiDecimal(this .getItemUnitPrice()
102: .toString());
103: }
104: if (ObjectUtils.isNull(extendedPrice)) {
105: extendedPrice = KualiDecimal.ZERO;
106: }
107: return extendedPrice;
108: }
109:
110: public void setExtendedPrice(KualiDecimal extendedPrice) {
111: this.extendedPrice = extendedPrice;
112: }
113: }
|