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  import java.sql.Timestamp;
20  import java.util.ArrayList;
21  import java.util.Collection;
22  
23  import org.kuali.ole.gl.GeneralLedgerConstants;
24  import org.kuali.ole.gl.batch.PosterEntriesStep;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.rice.core.api.util.type.KualiDecimal;
28  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
29  import org.kuali.rice.krad.util.ObjectUtils;
30  
31  /**
32   * Encumbrance BO for Balancing process. I.e. a shadow representation.
33  */
34  public class EncumbranceHistory extends Encumbrance {
35  
36      public EncumbranceHistory() {
37          super();
38          this.setAccountLineEncumbranceAmount(KualiDecimal.ZERO);
39          this.setAccountLineEncumbranceClosedAmount(KualiDecimal.ZERO);
40      }
41  
42      /**
43       * Constructs a BalanceHistory.java.
44       * 
45       * @param transaction
46       */
47      public EncumbranceHistory(OriginEntryInformation originEntry) {
48          this();
49          this.setUniversityFiscalYear(originEntry.getUniversityFiscalYear());
50          this.setChartOfAccountsCode(originEntry.getChartOfAccountsCode());
51          this.setAccountNumber(originEntry.getAccountNumber());
52          this.setSubAccountNumber(originEntry.getSubAccountNumber());
53          this.setObjectCode(originEntry.getFinancialObjectCode());
54          this.setSubObjectCode(originEntry.getFinancialSubObjectCode());
55          this.setBalanceTypeCode(originEntry.getFinancialBalanceTypeCode());
56          this.setDocumentTypeCode(originEntry.getFinancialDocumentTypeCode());
57          this.setOriginCode(originEntry.getFinancialSystemOriginationCode());
58          this.setDocumentNumber(originEntry.getDocumentNumber());
59      }
60      
61      /**
62       * Updates amount if the object already existed
63       * @param originEntry representing the update details
64       */
65      public void addAmount(OriginEntryInformation originEntry) {
66          //KFSMI-1571 - check parameter encumbranceOpenAmountOeverridingDocTypes
67          ParameterService parameterService = SpringContext.getBean(ParameterService.class);
68          Collection<String> encumbranceOpenAmountOeverridingDocTypes = new ArrayList<String>( parameterService.getParameterValuesAsString(PosterEntriesStep.class, GeneralLedgerConstants.PosterService.ENCUMBRANCE_OPEN_AMOUNT_OVERRIDING_DOCUMENT_TYPES) );
69          
70          if (OLEConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(originEntry.getTransactionEncumbranceUpdateCode()) 
71                  && !encumbranceOpenAmountOeverridingDocTypes.contains( originEntry.getFinancialDocumentTypeCode())) {
72              // If using referring doc number, add or subtract transaction amount from
73              // encumbrance closed amount
74              if (OLEConstants.GL_DEBIT_CODE.equals(originEntry.getTransactionDebitCreditCode())) {
75                  this.setAccountLineEncumbranceClosedAmount(this.getAccountLineEncumbranceClosedAmount().subtract(originEntry.getTransactionLedgerEntryAmount()));
76              }
77              else {
78                  this.setAccountLineEncumbranceClosedAmount(this.getAccountLineEncumbranceClosedAmount().add(originEntry.getTransactionLedgerEntryAmount()));
79              }
80          }
81          else {
82              // If not using referring doc number, add or subtract transaction amount from
83              // encumbrance amount
84              if (OLEConstants.GL_DEBIT_CODE.equals(originEntry.getTransactionDebitCreditCode()) || OLEConstants.GL_BUDGET_CODE.equals(originEntry.getTransactionDebitCreditCode())) {
85                  this.setAccountLineEncumbranceAmount(this.getAccountLineEncumbranceAmount().add(originEntry.getTransactionLedgerEntryAmount()));
86              }
87              else {
88                  this.setAccountLineEncumbranceAmount(this.getAccountLineEncumbranceAmount().subtract(originEntry.getTransactionLedgerEntryAmount()));
89              }
90          }
91      }
92      
93      /**
94       * Compare amounts
95       * @param accountBalance
96       */
97      public boolean compareAmounts(Encumbrance encumbrance) {
98          if (ObjectUtils.isNotNull(encumbrance)
99                  && encumbrance.getAccountLineEncumbranceAmount().equals(this.getAccountLineEncumbranceAmount())
100                 && encumbrance.getAccountLineEncumbranceClosedAmount().equals(this.getAccountLineEncumbranceClosedAmount())) {
101             return true;
102         }
103         
104         return false;
105     }
106     
107     /**
108      * History does not track this field.
109      * @see org.kuali.ole.gl.businessobject.Balance#getTimestamp()
110      */
111     @Override
112     public String getAccountLineEncumbrancePurgeCode() {
113         throw new UnsupportedOperationException();
114     }
115 
116     /**
117      * History does not track this field.
118      * @see org.kuali.ole.gl.businessobject.Balance#getTimestamp()
119      */
120     @Override
121     public void setAccountLineEncumbrancePurgeCode(String accountLineEncumbrancePurgeCode) {
122         throw new UnsupportedOperationException();
123     }
124 
125     /**
126      * History does not track this field.
127      * @see org.kuali.ole.gl.businessobject.Balance#getTimestamp()
128      */
129     @Override
130     public Timestamp getTimestamp() {
131         throw new UnsupportedOperationException();
132     }
133 
134     /**
135      * History does not track this field.
136      * @see org.kuali.ole.gl.businessobject.Balance#getTimestamp()
137      */
138     @Override
139     public void setTimestamp(Timestamp timestamp) {
140         throw new UnsupportedOperationException();
141     }
142 
143     /**
144      * History does not track this field.
145      * @see org.kuali.ole.gl.businessobject.Balance#getTimestamp()
146      */
147     @Override
148     public Date getTransactionEncumbranceDate() {
149         throw new UnsupportedOperationException();
150     }
151 
152     /**
153      * History does not track this field.
154      * @see org.kuali.ole.gl.businessobject.Balance#getTimestamp()
155      */
156     @Override
157     public void setTransactionEncumbranceDate(Date transactionEncumbranceDate) {
158         throw new UnsupportedOperationException();
159     }
160 
161     /**
162      * History does not track this field.
163      * @see org.kuali.ole.gl.businessobject.Balance#getTimestamp()
164      */
165     @Override
166     public String getTransactionEncumbranceDescription() {
167         throw new UnsupportedOperationException();
168     }
169 
170     /**
171      * History does not track this field.
172      * @see org.kuali.ole.gl.businessobject.Balance#getTimestamp()
173      */
174     @Override
175     public void setTransactionEncumbranceDescription(String transactionEncumbranceDescription) {
176         throw new UnsupportedOperationException();
177     }
178 }