001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.gl.businessobject;
017
018 import java.sql.Date;
019 import java.sql.Timestamp;
020
021 import org.apache.commons.lang.ArrayUtils;
022 import org.kuali.kfs.gl.GeneralLedgerConstants;
023 import org.kuali.kfs.gl.batch.PosterEntriesStep;
024 import org.kuali.kfs.sys.KFSConstants;
025 import org.kuali.kfs.sys.context.SpringContext;
026 import org.kuali.rice.kns.service.ParameterService;
027 import org.kuali.rice.kns.util.KualiDecimal;
028 import org.kuali.rice.kns.util.ObjectUtils;
029
030 /**
031 * Encumbrance BO for Balancing process. I.e. a shadow representation.
032 */
033 public class EncumbranceHistory extends Encumbrance {
034
035 public EncumbranceHistory() {
036 super();
037 this.setAccountLineEncumbranceAmount(KualiDecimal.ZERO);
038 this.setAccountLineEncumbranceClosedAmount(KualiDecimal.ZERO);
039 }
040
041 /**
042 * Constructs a BalanceHistory.java.
043 *
044 * @param transaction
045 */
046 public EncumbranceHistory(OriginEntryInformation originEntry) {
047 this();
048 this.setUniversityFiscalYear(originEntry.getUniversityFiscalYear());
049 this.setChartOfAccountsCode(originEntry.getChartOfAccountsCode());
050 this.setAccountNumber(originEntry.getAccountNumber());
051 this.setSubAccountNumber(originEntry.getSubAccountNumber());
052 this.setObjectCode(originEntry.getFinancialObjectCode());
053 this.setSubObjectCode(originEntry.getFinancialSubObjectCode());
054 this.setBalanceTypeCode(originEntry.getFinancialBalanceTypeCode());
055 this.setDocumentTypeCode(originEntry.getFinancialDocumentTypeCode());
056 this.setOriginCode(originEntry.getFinancialSystemOriginationCode());
057 this.setDocumentNumber(originEntry.getDocumentNumber());
058 }
059
060 /**
061 * Updates amount if the object already existed
062 * @param originEntry representing the update details
063 */
064 public void addAmount(OriginEntryInformation originEntry) {
065 //KFSMI-1571 - check parameter encumbranceOpenAmountOeverridingDocTypes
066 ParameterService parameterService = SpringContext.getBean(ParameterService.class);
067 String[] encumbranceOpenAmountOeverridingDocTypes = parameterService.getParameterValues(PosterEntriesStep.class, GeneralLedgerConstants.PosterService.ENCUMBRANCE_OPEN_AMOUNT_OVERRIDING_DOCUMENT_TYPES).toArray(new String[] {});
068
069 if (KFSConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(originEntry.getTransactionEncumbranceUpdateCode()) && !ArrayUtils.contains(encumbranceOpenAmountOeverridingDocTypes, originEntry.getFinancialDocumentTypeCode())) {
070 // If using referring doc number, add or subtract transaction amount from
071 // encumbrance closed amount
072 if (KFSConstants.GL_DEBIT_CODE.equals(originEntry.getTransactionDebitCreditCode())) {
073 this.setAccountLineEncumbranceClosedAmount(this.getAccountLineEncumbranceClosedAmount().subtract(originEntry.getTransactionLedgerEntryAmount()));
074 }
075 else {
076 this.setAccountLineEncumbranceClosedAmount(this.getAccountLineEncumbranceClosedAmount().add(originEntry.getTransactionLedgerEntryAmount()));
077 }
078 }
079 else {
080 // If not using referring doc number, add or subtract transaction amount from
081 // encumbrance amount
082 if (KFSConstants.GL_DEBIT_CODE.equals(originEntry.getTransactionDebitCreditCode()) || KFSConstants.GL_BUDGET_CODE.equals(originEntry.getTransactionDebitCreditCode())) {
083 this.setAccountLineEncumbranceAmount(this.getAccountLineEncumbranceAmount().add(originEntry.getTransactionLedgerEntryAmount()));
084 }
085 else {
086 this.setAccountLineEncumbranceAmount(this.getAccountLineEncumbranceAmount().subtract(originEntry.getTransactionLedgerEntryAmount()));
087 }
088 }
089 }
090
091 /**
092 * Compare amounts
093 * @param accountBalance
094 */
095 public boolean compareAmounts(Encumbrance encumbrance) {
096 if (ObjectUtils.isNotNull(encumbrance)
097 && encumbrance.getAccountLineEncumbranceAmount().equals(this.getAccountLineEncumbranceAmount())
098 && encumbrance.getAccountLineEncumbranceClosedAmount().equals(this.getAccountLineEncumbranceClosedAmount())) {
099 return true;
100 }
101
102 return false;
103 }
104
105 /**
106 * History does not track this field.
107 * @see org.kuali.kfs.gl.businessobject.Balance#getTimestamp()
108 */
109 @Override
110 public String getAccountLineEncumbrancePurgeCode() {
111 throw new UnsupportedOperationException();
112 }
113
114 /**
115 * History does not track this field.
116 * @see org.kuali.kfs.gl.businessobject.Balance#getTimestamp()
117 */
118 @Override
119 public void setAccountLineEncumbrancePurgeCode(String accountLineEncumbrancePurgeCode) {
120 throw new UnsupportedOperationException();
121 }
122
123 /**
124 * History does not track this field.
125 * @see org.kuali.kfs.gl.businessobject.Balance#getTimestamp()
126 */
127 @Override
128 public Timestamp getTimestamp() {
129 throw new UnsupportedOperationException();
130 }
131
132 /**
133 * History does not track this field.
134 * @see org.kuali.kfs.gl.businessobject.Balance#getTimestamp()
135 */
136 @Override
137 public void setTimestamp(Timestamp timestamp) {
138 throw new UnsupportedOperationException();
139 }
140
141 /**
142 * History does not track this field.
143 * @see org.kuali.kfs.gl.businessobject.Balance#getTimestamp()
144 */
145 @Override
146 public Date getTransactionEncumbranceDate() {
147 throw new UnsupportedOperationException();
148 }
149
150 /**
151 * History does not track this field.
152 * @see org.kuali.kfs.gl.businessobject.Balance#getTimestamp()
153 */
154 @Override
155 public void setTransactionEncumbranceDate(Date transactionEncumbranceDate) {
156 throw new UnsupportedOperationException();
157 }
158
159 /**
160 * History does not track this field.
161 * @see org.kuali.kfs.gl.businessobject.Balance#getTimestamp()
162 */
163 @Override
164 public String getTransactionEncumbranceDescription() {
165 throw new UnsupportedOperationException();
166 }
167
168 /**
169 * History does not track this field.
170 * @see org.kuali.kfs.gl.businessobject.Balance#getTimestamp()
171 */
172 @Override
173 public void setTransactionEncumbranceDescription(String transactionEncumbranceDescription) {
174 throw new UnsupportedOperationException();
175 }
176 }