View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.purap.businessobject;
20  
21  import java.math.BigDecimal;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.kfs.integration.cab.CapitalAssetBuilderAssetTransactionType;
25  import org.kuali.kfs.module.purap.PurapPropertyConstants;
26  import org.kuali.kfs.module.purap.util.PurApItemUtils;
27  import org.kuali.kfs.sys.context.SpringContext;
28  import org.kuali.rice.core.api.util.type.KualiDecimal;
29  import org.kuali.rice.krad.service.KualiModuleService;
30  import org.kuali.rice.krad.util.ObjectUtils;
31  
32  /**
33   * Base class for Accounts Payable Item Business Objects.
34   */
35  public abstract class AccountsPayableItemBase extends PurApItemBase implements AccountsPayableItem {
36      private KualiDecimal extendedPrice;
37      private String capitalAssetTransactionTypeCode;
38      private CapitalAssetBuilderAssetTransactionType capitalAssetTransactionType;
39      
40      /**
41       * Method defaults to {@link #isConsideredEnteredWithZero()}
42       * 
43       * @see org.kuali.module.purap.bo.PurchasingApItem#isConsideredEntered()
44       */
45      public boolean isConsideredEntered() {
46          return isConsideredEnteredWithZero();
47      }
48  
49      public boolean isEligibleDisplay() {
50          return isConsideredEnteredWithZero();
51      }
52  
53      public boolean isConsideredEnteredWithZero() {
54          return isConsideredEntered(true);
55      }
56  
57      public boolean isConsideredEnteredWithoutZero() {
58          return isConsideredEntered(false);
59      }
60  
61      /**
62       * This method is used to determine whether an item has been entered that is we are satisfied there's enough info to continue
63       * processing that particular item. It is currently used by the rules class to determine when it's necessary to run rules on
64       * items (so that lines processors don't touch won't be validated) and to determine when to show items (in combination with the
65       * full entry mode)
66       * 
67       * @param allowsZero if this is true zero will be considered the same as null.
68       * @return true if the item is considered entered false otherwise
69       */
70      private boolean isConsideredEntered(boolean allowsZero) {
71          if (getItemType().isLineItemIndicator()) {
72              if ((getItemType().isQuantityBasedGeneralLedgerIndicator())) {
73                  if ((ObjectUtils.isNull(getItemQuantity())) && (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice().isZero()))) {
74                      return false;
75                  }
76              }
77              else {
78                  if (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice().isZero())) {
79                      return false;
80                  }
81              }
82          }
83          else {
84              if ((ObjectUtils.isNull(getItemUnitPrice()) || (allowsZero && this.getItemUnitPrice().compareTo(new BigDecimal(0)) == 0)) && (StringUtils.isBlank(getItemDescription()))) {
85                  return false;
86              }
87          }
88  
89          return true;
90      }
91  
92      public boolean isNonZeroAmount() {
93          return PurApItemUtils.isNonZeroExtended(this);
94      }
95  
96      /**
97       * Gets the extendedPrice attribute. this override is necessary because extended price needs to be set based on the unit price
98       * for below the line(without this it would always be empty)
99       * 
100      * @return Returns the extendedPrice.
101      */
102     @Override
103     public KualiDecimal getExtendedPrice() {
104         if (ObjectUtils.isNotNull(this.getItemUnitPrice()) && ObjectUtils.isNotNull(this.getItemType()) && this.getItemType().isAmountBasedGeneralLedgerIndicator()) {
105             if (ObjectUtils.isNotNull(this.getItemUnitPrice())) {
106                 extendedPrice = new KualiDecimal(this.getItemUnitPrice().toString());
107             }else{
108                 extendedPrice = null;
109             }
110         }else if (ObjectUtils.isNull(this.getItemUnitPrice()) && ObjectUtils.isNotNull(this.getItemType()) &&
111                   this.getItemType().isAmountBasedGeneralLedgerIndicator() &&
112                   this.getItemType().isAdditionalChargeIndicator()){ // This additional charges check is needed since non qty items also dont have unit price
113             // extendedPrice should be null if the unit price is null
114             extendedPrice = null;
115         }
116         return extendedPrice;
117     }
118     
119     public void setExtendedPrice(KualiDecimal extendedPrice) {
120         this.extendedPrice = extendedPrice;
121     }
122     
123     /**
124      * Override the method in PurApItemBase so that if the item is
125      * not eligible to be displayed in the account summary tab,
126      * which is if the item's extended price is null or zero, 
127      * we'll return null and the item won't be added
128      * to the list of account summary.
129      * 
130      * @see org.kuali.kfs.module.purap.businessobject.PurApItemBase#getSummaryItem()
131      */
132     @Override
133         public PurApSummaryItem getSummaryItem() {
134         if (extendedPrice == null || extendedPrice.isZero()) {
135             return null;
136         }
137         else {
138             return super.getSummaryItem();
139         }
140     }
141 
142 
143     public String getCapitalAssetTransactionTypeCode() {
144         return capitalAssetTransactionTypeCode;
145     }
146 
147     public void setCapitalAssetTransactionTypeCode(String capitalAssetTransactionTypeCode) {
148         this.capitalAssetTransactionTypeCode = capitalAssetTransactionTypeCode;
149     }
150 
151     public CapitalAssetBuilderAssetTransactionType getCapitalAssetTransactionType() {
152         return capitalAssetTransactionType = (CapitalAssetBuilderAssetTransactionType) SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CapitalAssetBuilderAssetTransactionType.class).retrieveExternalizableBusinessObjectIfNecessary(this, capitalAssetTransactionType, PurapPropertyConstants.ITEM_CAPITAL_ASSET_TRANSACTION_TYPE);
153     }
154     
155     public void setItemDescription(String itemDescription) {
156         if((itemDescription != null) && (itemDescription.length() > 100))
157         {
158            super.setItemDescription(itemDescription.substring(0, 100));
159         } else
160         {
161             super.setItemDescription(itemDescription);
162         }
163         
164     }
165 
166 }