View Javadoc
1   /*
2    * Copyright 2005-2009 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.gl.businessobject;
17  
18  import java.sql.Date;
19  
20  import org.kuali.ole.sys.OLEConstants;
21  import org.kuali.rice.core.api.util.type.KualiDecimal;
22  import org.kuali.rice.krad.util.ObjectUtils;
23  
24  /**
25   * AccountBalance BO for Balancing process. I.e. a shadow representation.
26   */
27  public class AccountBalanceHistory extends AccountBalance {
28      
29      /**
30       * Constructs a AccountBalanceHistory.java.
31       */
32      public AccountBalanceHistory() {
33          super();
34          this.setCurrentBudgetLineBalanceAmount(KualiDecimal.ZERO);
35          this.setAccountLineActualsBalanceAmount(KualiDecimal.ZERO);
36          this.setAccountLineEncumbranceBalanceAmount(KualiDecimal.ZERO);
37      }
38  
39      /**
40       * Constructs a BalanceHistory.java.
41       * 
42       * @param transaction
43       */
44      public AccountBalanceHistory(OriginEntryInformation originEntry) {
45          this();
46          this.setChartOfAccountsCode(originEntry.getChartOfAccountsCode());
47          this.setAccountNumber(originEntry.getAccountNumber());
48          this.setObjectCode(originEntry.getFinancialObjectCode());
49          this.setSubObjectCode(originEntry.getFinancialSubObjectCode());
50          this.setUniversityFiscalYear(originEntry.getUniversityFiscalYear());
51          this.setSubAccountNumber(originEntry.getSubAccountNumber());
52      }
53      
54      /**
55       * Updates amount if the object already existed
56       * @param originEntry representing the update details
57       */
58      public boolean addAmount(OriginEntryFull originEntryFull) {
59          if (originEntryFull.getFinancialBalanceTypeCode().equals(originEntryFull.getOption().getBudgetCheckingBalanceTypeCd())) {
60              this.setCurrentBudgetLineBalanceAmount(this.getCurrentBudgetLineBalanceAmount().add(originEntryFull.getTransactionLedgerEntryAmount()));
61          }
62          else if (originEntryFull.getFinancialBalanceTypeCode().equals(originEntryFull.getOption().getActualFinancialBalanceTypeCd())) {
63              if (originEntryFull.getObjectType().getFinObjectTypeDebitcreditCd().equals(originEntryFull.getTransactionDebitCreditCode()) || ((!originEntryFull.getBalanceType().isFinancialOffsetGenerationIndicator()) && OLEConstants.GL_BUDGET_CODE.equals(originEntryFull.getTransactionDebitCreditCode()))) {
64                  this.setAccountLineActualsBalanceAmount(this.getAccountLineActualsBalanceAmount().add(originEntryFull.getTransactionLedgerEntryAmount()));
65              }
66              else {
67                  this.setAccountLineActualsBalanceAmount(this.getAccountLineActualsBalanceAmount().subtract(originEntryFull.getTransactionLedgerEntryAmount()));
68              }
69          }
70          else if (originEntryFull.getFinancialBalanceTypeCode().equals(originEntryFull.getOption().getExtrnlEncumFinBalanceTypCd()) || originEntryFull.getFinancialBalanceTypeCode().equals(originEntryFull.getOption().getIntrnlEncumFinBalanceTypCd()) || originEntryFull.getFinancialBalanceTypeCode().equals(originEntryFull.getOption().getPreencumbranceFinBalTypeCd()) || originEntryFull.getFinancialBalanceTypeCode().equals(originEntryFull.getOption().getCostShareEncumbranceBalanceTypeCd())) {
71              if (originEntryFull.getObjectType().getFinObjectTypeDebitcreditCd().equals(originEntryFull.getTransactionDebitCreditCode()) || ((!originEntryFull.getBalanceType().isFinancialOffsetGenerationIndicator()) && OLEConstants.GL_BUDGET_CODE.equals(originEntryFull.getTransactionDebitCreditCode()))) {
72                  this.setAccountLineEncumbranceBalanceAmount(this.getAccountLineEncumbranceBalanceAmount().add(originEntryFull.getTransactionLedgerEntryAmount()));
73              }
74              else {
75                  this.setAccountLineEncumbranceBalanceAmount(this.getAccountLineEncumbranceBalanceAmount().subtract(originEntryFull.getTransactionLedgerEntryAmount()));
76              }
77          }
78          else {
79              return false;
80          }
81          return true;
82      }
83      
84      /**
85       * Compare amounts
86       * @param accountBalance
87       */
88      public boolean compareAmounts(AccountBalance accountBalance) {
89          if (ObjectUtils.isNotNull(accountBalance)
90                  && accountBalance.getCurrentBudgetLineBalanceAmount().equals(this.getCurrentBudgetLineBalanceAmount())
91                  && accountBalance.getAccountLineActualsBalanceAmount().equals(this.getAccountLineActualsBalanceAmount())
92                  && accountBalance.getAccountLineEncumbranceBalanceAmount().equals(this.getAccountLineEncumbranceBalanceAmount())) {
93              return true;
94          }
95          
96          return false;
97      }
98      
99      /**
100      * History does not track this field.
101      * @see org.kuali.ole.gl.businessobject.Balance#getTimestamp()
102      */
103     @Override
104     public Date getTimestamp() {
105         throw new UnsupportedOperationException();
106     }
107 
108     /**
109      * History does not track this field.
110      * @see org.kuali.ole.gl.businessobject.Balance#getTimestamp()
111      */
112     @Override
113     public void setTimestamp(Date timestamp) {
114         throw new UnsupportedOperationException();
115     }
116 }