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.businessobject;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.integration.cab.CapitalAssetBuilderAssetTransactionType;
20  import org.kuali.ole.module.purap.PurapPropertyConstants;
21  import org.kuali.ole.module.purap.util.PurApItemUtils;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.core.api.util.type.KualiDecimal;
24  import org.kuali.rice.krad.service.KualiModuleService;
25  import org.kuali.rice.krad.util.ObjectUtils;
26  
27  import java.math.BigDecimal;
28  
29  /**
30   * Base class for Accounts Payable Item Business Objects.
31   */
32  public abstract class AccountsPayableItemBase extends PurApItemBase implements AccountsPayableItem {
33      private KualiDecimal extendedPrice;
34      private String capitalAssetTransactionTypeCode;
35      private CapitalAssetBuilderAssetTransactionType capitalAssetTransactionType;
36  
37      /**
38       * Method defaults to {@link #isConsideredEnteredWithZero()}
39       *
40       * @see org.kuali.module.purap.bo.PurchasingApItem#isConsideredEntered()
41       */
42      public boolean isConsideredEntered() {
43          return isConsideredEnteredWithZero();
44      }
45  
46      public boolean isEligibleDisplay() {
47          return isConsideredEnteredWithZero();
48      }
49  
50      public boolean isConsideredEnteredWithZero() {
51          return isConsideredEntered(true);
52      }
53  
54      public boolean isConsideredEnteredWithoutZero() {
55          return isConsideredEntered(false);
56      }
57  
58      /**
59       * This method is used to determine whether an item has been entered that is we are satisfied there's enough info to continue
60       * processing that particular item. It is currently used by the rules class to determine when it's necessary to run rules on
61       * items (so that lines processors don't touch won't be validated) and to determine when to show items (in combination with the
62       * full entry mode)
63       *
64       * @param allowsZero if this is true zero will be considered the same as null.
65       * @return true if the item is considered entered false otherwise
66       */
67      private boolean isConsideredEntered(boolean allowsZero) {
68          if (getItemType().isLineItemIndicator()) {
69              if ((getItemType().isQuantityBasedGeneralLedgerIndicator())) {
70                  if ((ObjectUtils.isNull(getItemQuantity())) && (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice().isZero()))) {
71                      return false;
72                  }
73              } else {
74                  if (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice().isZero())) {
75                      return false;
76                  }
77              }
78          } else {
79              if ((ObjectUtils.isNull(getItemUnitPrice()) || (allowsZero && this.getItemUnitPrice().compareTo(new BigDecimal(0)) == 0)) && (StringUtils.isBlank(getItemDescription()))) {
80                  return false;
81              }
82          }
83  
84          return true;
85      }
86  
87      public boolean isNonZeroAmount() {
88          return PurApItemUtils.isNonZeroExtended(this);
89      }
90  
91      /**
92       * Gets the extendedPrice attribute. this override is necessary because extended price needs to be set based on the unit price
93       * for below the line(without this it would always be empty)
94       *
95       * @return Returns the extendedPrice.
96       */
97      @Override
98      public KualiDecimal getExtendedPrice() {
99          if (ObjectUtils.isNotNull(this.getItemUnitPrice()) && this.getItemType().isAmountBasedGeneralLedgerIndicator()) {
100             if (ObjectUtils.isNotNull(this.getItemUnitPrice())) {
101                 extendedPrice = new KualiDecimal(this.getItemUnitPrice().toString());
102             } else {
103                 extendedPrice = null;
104             }
105         } else if (ObjectUtils.isNull(this.getItemUnitPrice()) &&
106                 this.getItemType().isAmountBasedGeneralLedgerIndicator() &&
107                 this.getItemType().isAdditionalChargeIndicator()) { // This additional charges check is needed since non qty items also dont have unit price
108             // extendedPrice should be null if the unit price is null
109             extendedPrice = null;
110         }
111         return extendedPrice;
112     }
113 
114     public void setExtendedPrice(KualiDecimal extendedPrice) {
115         this.extendedPrice = extendedPrice;
116     }
117 
118     /**
119      * Override the method in PurApItemBase so that if the item is
120      * not eligible to be displayed in the account summary tab,
121      * which is if the item's extended price is null or zero,
122      * we'll return null and the item won't be added
123      * to the list of account summary.
124      *
125      * @see org.kuali.ole.module.purap.businessobject.PurApItemBase#getSummaryItem()
126      */
127     @Override
128     public PurApSummaryItem getSummaryItem() {
129         if (extendedPrice == null || extendedPrice.compareTo(KualiDecimal.ZERO)==0) {
130             return null;
131         } else {
132             return super.getSummaryItem();
133         }
134     }
135 
136     public String getCapitalAssetTransactionTypeCode() {
137         return capitalAssetTransactionTypeCode;
138     }
139 
140     public void setCapitalAssetTransactionTypeCode(String capitalAssetTransactionTypeCode) {
141         this.capitalAssetTransactionTypeCode = capitalAssetTransactionTypeCode;
142     }
143 
144     public CapitalAssetBuilderAssetTransactionType getCapitalAssetTransactionType() {
145         return capitalAssetTransactionType = (CapitalAssetBuilderAssetTransactionType) SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CapitalAssetBuilderAssetTransactionType.class).retrieveExternalizableBusinessObjectIfNecessary(this, capitalAssetTransactionType, PurapPropertyConstants.ITEM_CAPITAL_ASSET_TRANSACTION_TYPE);
146     }
147 
148     public void setItemDescription(String itemDescription) {
149         if ((itemDescription != null) && (itemDescription.length() > 100)) {
150             super.setItemDescription(itemDescription.substring(0, 100));
151         } else {
152             super.setItemDescription(itemDescription);
153         }
154 
155     }
156 
157 }