001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.purap.bo;
017:
018: import java.math.BigDecimal;
019: import java.util.LinkedHashMap;
020:
021: import org.apache.commons.lang.StringUtils;
022: import org.apache.commons.lang.builder.EqualsBuilder;
023: import org.kuali.core.util.KualiDecimal;
024: import org.kuali.core.util.ObjectUtils;
025: import org.kuali.kfs.bo.SourceAccountingLine;
026:
027: /**
028: * Purap Accounting Line Base Business Object.
029: */
030: public abstract class PurApAccountingLineBase extends
031: SourceAccountingLine implements PurApAccountingLine, Comparable {
032:
033: protected Integer accountIdentifier;
034: private Integer itemIdentifier;
035: private BigDecimal accountLinePercent;
036: private KualiDecimal alternateAmountForGLEntryCreation; // not stored in DB; needed for disencumbrances and such
037:
038: public Integer getAccountIdentifier() {
039: return accountIdentifier;
040: }
041:
042: public void setAccountIdentifier(
043: Integer requisitionAccountIdentifier) {
044: this .accountIdentifier = requisitionAccountIdentifier;
045: }
046:
047: public Integer getItemIdentifier() {
048: return itemIdentifier;
049: }
050:
051: public void setItemIdentifier(Integer requisitionItemIdentifier) {
052: this .itemIdentifier = requisitionItemIdentifier;
053: }
054:
055: public BigDecimal getAccountLinePercent() {
056: return accountLinePercent;
057: }
058:
059: public void setAccountLinePercent(BigDecimal accountLinePercent) {
060: this .accountLinePercent = accountLinePercent;
061: }
062:
063: /**
064: * @see org.kuali.module.purap.bo.PurApAccountingLine#isEmpty()
065: */
066: public boolean isEmpty() {
067: return !(StringUtils.isNotEmpty(getAccountNumber())
068: || StringUtils.isNotEmpty(getChartOfAccountsCode())
069: || StringUtils.isNotEmpty(getFinancialObjectCode())
070: || StringUtils.isNotEmpty(getFinancialSubObjectCode())
071: || StringUtils.isNotEmpty(getOrganizationReferenceId())
072: || StringUtils.isNotEmpty(getProjectCode())
073: || StringUtils.isNotEmpty(getSubAccountNumber()) || ObjectUtils
074: .isNotNull(getAccountLinePercent()));
075: }
076:
077: /**
078: * @see org.kuali.module.purap.bo.PurApAccountingLine#createBlankAmountsCopy()
079: */
080: public PurApAccountingLine createBlankAmountsCopy() {
081: PurApAccountingLine newAccount = (PurApAccountingLine) ObjectUtils
082: .deepCopy(this );
083: newAccount.setAccountLinePercent(BigDecimal.ZERO);
084: newAccount.setAmount(KualiDecimal.ZERO);
085: return newAccount;
086: }
087:
088: /**
089: * @see org.kuali.module.purap.bo.PurApAccountingLine#accountStringsAreEqual(org.kuali.kfs.bo.SourceAccountingLine)
090: */
091: public boolean accountStringsAreEqual(
092: SourceAccountingLine accountingLine) {
093: if (accountingLine == null) {
094: return false;
095: }
096: return new EqualsBuilder().append(getChartOfAccountsCode(),
097: accountingLine.getChartOfAccountsCode()).append(
098: getAccountNumber(), accountingLine.getAccountNumber())
099: .append(getSubAccountNumber(),
100: accountingLine.getSubAccountNumber()).append(
101: getFinancialObjectCode(),
102: accountingLine.getFinancialObjectCode())
103: .append(getFinancialSubObjectCode(),
104: accountingLine.getFinancialSubObjectCode())
105: .append(getProjectCode(),
106: accountingLine.getProjectCode()).append(
107: getOrganizationReferenceId(),
108: accountingLine.getOrganizationReferenceId())
109: .isEquals();
110: }
111:
112: public boolean accountStringsAreEqual(
113: PurApAccountingLine accountingLine) {
114: return accountStringsAreEqual((SourceAccountingLine) accountingLine);
115:
116: }
117:
118: /**
119: * @see org.kuali.module.purap.bo.PurApAccountingLine#generateSourceAccountingLine()
120: */
121: public SourceAccountingLine generateSourceAccountingLine() {
122: // the fields here should probably match method 'accountStringsAreEqual' above
123: SourceAccountingLine sourceLine = new SourceAccountingLine();
124: sourceLine.setChartOfAccountsCode(getChartOfAccountsCode());
125: sourceLine.setAccountNumber(getAccountNumber());
126: sourceLine.setSubAccountNumber(getSubAccountNumber());
127: sourceLine.setFinancialObjectCode(getFinancialObjectCode());
128: sourceLine
129: .setFinancialSubObjectCode(getFinancialSubObjectCode());
130: sourceLine.setProjectCode(getProjectCode());
131: sourceLine
132: .setOrganizationReferenceId(getOrganizationReferenceId());
133: sourceLine.setAmount(getAmount());
134: return sourceLine;
135: }
136:
137: /**
138: * @see org.kuali.kfs.bo.AccountingLineBase#toStringMapper()
139: */
140: @Override
141: protected LinkedHashMap toStringMapper() {
142: LinkedHashMap m = new LinkedHashMap();
143:
144: m.put("chart", getChartOfAccountsCode());
145: m.put("account", getAccountNumber());
146: m.put("objectCode", getFinancialObjectCode());
147: m.put("subAccount", getSubAccountNumber());
148: m.put("subObjectCode", getFinancialSubObjectCode());
149: m.put("projectCode", getProjectCode());
150: m.put("orgRefId", getOrganizationReferenceId());
151:
152: return m;
153: }
154:
155: public int compareTo(Object arg0) {
156: if (arg0 instanceof PurApAccountingLine) {
157: PurApAccountingLine account = (PurApAccountingLine) arg0;
158: return this .getString().compareTo(account.getString());
159: }
160: return -1;
161: }
162:
163: public String getString() {
164: return getChartOfAccountsCode() + "~" + getAccountNumber()
165: + "~" + getSubAccountNumber() + "~"
166: + getFinancialObjectCode() + "~"
167: + getFinancialSubObjectCode() + "~" + getProjectCode()
168: + "~" + getOrganizationReferenceId();
169: }
170:
171: public KualiDecimal getAlternateAmountForGLEntryCreation() {
172: return alternateAmountForGLEntryCreation;
173: }
174:
175: public void setAlternateAmountForGLEntryCreation(
176: KualiDecimal alternateAmount) {
177: this .alternateAmountForGLEntryCreation = alternateAmount;
178: }
179:
180: /**
181: * @see org.kuali.kfs.bo.AccountingLineBase#getSequenceNumber()
182: */
183: @Override
184: public Integer getSequenceNumber() {
185: return this.getAccountIdentifier();
186: }
187:
188: }
|