001/*
002 * Copyright 2005-2009 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 */
016package org.kuali.ole.gl.businessobject;
017
018import java.sql.Date;
019
020import org.kuali.ole.sys.OLEConstants;
021import org.kuali.rice.core.api.util.type.KualiDecimal;
022import org.kuali.rice.krad.util.ObjectUtils;
023
024/**
025 * AccountBalance BO for Balancing process. I.e. a shadow representation.
026 */
027public class AccountBalanceHistory extends AccountBalance {
028    
029    /**
030     * Constructs a AccountBalanceHistory.java.
031     */
032    public AccountBalanceHistory() {
033        super();
034        this.setCurrentBudgetLineBalanceAmount(KualiDecimal.ZERO);
035        this.setAccountLineActualsBalanceAmount(KualiDecimal.ZERO);
036        this.setAccountLineEncumbranceBalanceAmount(KualiDecimal.ZERO);
037    }
038
039    /**
040     * Constructs a BalanceHistory.java.
041     * 
042     * @param transaction
043     */
044    public AccountBalanceHistory(OriginEntryInformation originEntry) {
045        this();
046        this.setChartOfAccountsCode(originEntry.getChartOfAccountsCode());
047        this.setAccountNumber(originEntry.getAccountNumber());
048        this.setObjectCode(originEntry.getFinancialObjectCode());
049        this.setSubObjectCode(originEntry.getFinancialSubObjectCode());
050        this.setUniversityFiscalYear(originEntry.getUniversityFiscalYear());
051        this.setSubAccountNumber(originEntry.getSubAccountNumber());
052    }
053    
054    /**
055     * Updates amount if the object already existed
056     * @param originEntry representing the update details
057     */
058    public boolean addAmount(OriginEntryFull originEntryFull) {
059        if (originEntryFull.getFinancialBalanceTypeCode().equals(originEntryFull.getOption().getBudgetCheckingBalanceTypeCd())) {
060            this.setCurrentBudgetLineBalanceAmount(this.getCurrentBudgetLineBalanceAmount().add(originEntryFull.getTransactionLedgerEntryAmount()));
061        }
062        else if (originEntryFull.getFinancialBalanceTypeCode().equals(originEntryFull.getOption().getActualFinancialBalanceTypeCd())) {
063            if (originEntryFull.getObjectType().getFinObjectTypeDebitcreditCd().equals(originEntryFull.getTransactionDebitCreditCode()) || ((!originEntryFull.getBalanceType().isFinancialOffsetGenerationIndicator()) && OLEConstants.GL_BUDGET_CODE.equals(originEntryFull.getTransactionDebitCreditCode()))) {
064                this.setAccountLineActualsBalanceAmount(this.getAccountLineActualsBalanceAmount().add(originEntryFull.getTransactionLedgerEntryAmount()));
065            }
066            else {
067                this.setAccountLineActualsBalanceAmount(this.getAccountLineActualsBalanceAmount().subtract(originEntryFull.getTransactionLedgerEntryAmount()));
068            }
069        }
070        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())) {
071            if (originEntryFull.getObjectType().getFinObjectTypeDebitcreditCd().equals(originEntryFull.getTransactionDebitCreditCode()) || ((!originEntryFull.getBalanceType().isFinancialOffsetGenerationIndicator()) && OLEConstants.GL_BUDGET_CODE.equals(originEntryFull.getTransactionDebitCreditCode()))) {
072                this.setAccountLineEncumbranceBalanceAmount(this.getAccountLineEncumbranceBalanceAmount().add(originEntryFull.getTransactionLedgerEntryAmount()));
073            }
074            else {
075                this.setAccountLineEncumbranceBalanceAmount(this.getAccountLineEncumbranceBalanceAmount().subtract(originEntryFull.getTransactionLedgerEntryAmount()));
076            }
077        }
078        else {
079            return false;
080        }
081        return true;
082    }
083    
084    /**
085     * Compare amounts
086     * @param accountBalance
087     */
088    public boolean compareAmounts(AccountBalance accountBalance) {
089        if (ObjectUtils.isNotNull(accountBalance)
090                && accountBalance.getCurrentBudgetLineBalanceAmount().equals(this.getCurrentBudgetLineBalanceAmount())
091                && accountBalance.getAccountLineActualsBalanceAmount().equals(this.getAccountLineActualsBalanceAmount())
092                && accountBalance.getAccountLineEncumbranceBalanceAmount().equals(this.getAccountLineEncumbranceBalanceAmount())) {
093            return true;
094        }
095        
096        return false;
097    }
098    
099    /**
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}