1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.businessobject;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.commons.lang.builder.EqualsBuilder;
20 import org.kuali.ole.sys.OLEPropertyConstants;
21 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
22 import org.kuali.rice.core.api.util.type.KualiDecimal;
23 import org.kuali.rice.krad.util.ObjectUtils;
24
25 import java.math.BigDecimal;
26 import java.util.LinkedHashMap;
27 import java.util.Map;
28
29
30
31
32 public abstract class PurApAccountingLineBase extends SourceAccountingLine implements PurApAccountingLine, Comparable {
33 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurApAccountingLineBase.class);
34 protected Integer accountIdentifier;
35 private Integer itemIdentifier;
36 private BigDecimal accountLinePercent;
37 private String postingPeriodCode;
38 private KualiDecimal alternateAmountForGLEntryCreation;
39 public Integer purApSequenceNumber;
40
41 private PurApItem purapItem;
42
43
44
45
46
47
48 public PurApAccountingLineBase() {
49 super();
50 this.setSequenceNumber(0);
51 setAmount(null);
52 }
53
54 @Override
55 public Integer getAccountIdentifier() {
56 return accountIdentifier;
57 }
58
59 @Override
60 public void setAccountIdentifier(Integer requisitionAccountIdentifier) {
61 this.accountIdentifier = requisitionAccountIdentifier;
62 }
63
64 @Override
65 public Integer getItemIdentifier() {
66 return itemIdentifier;
67 }
68
69 @Override
70 public void setItemIdentifier(Integer requisitionItemIdentifier) {
71 this.itemIdentifier = requisitionItemIdentifier;
72 }
73
74 @Override
75 public BigDecimal getAccountLinePercent() {
76 if (accountLinePercent != null) {
77 accountLinePercent = accountLinePercent.setScale(2, BigDecimal.ROUND_HALF_UP);
78 return accountLinePercent;
79 } else {
80 return new BigDecimal(100).setScale(2, BigDecimal.ROUND_HALF_UP);
81 }
82 }
83
84 @Override
85 public void setAccountLinePercent(BigDecimal accountLinePercent) {
86 this.accountLinePercent = accountLinePercent;
87 }
88
89
90
91
92 @Override
93 public boolean isEmpty() {
94 return !(StringUtils.isNotEmpty(getAccountNumber()) || StringUtils.isNotEmpty(getChartOfAccountsCode()) || StringUtils.isNotEmpty(getFinancialObjectCode()) || StringUtils.isNotEmpty(getFinancialSubObjectCode()) || StringUtils.isNotEmpty(getOrganizationReferenceId()) || StringUtils.isNotEmpty(getProjectCode()) || StringUtils.isNotEmpty(getSubAccountNumber()) || ObjectUtils.isNotNull(getAccountLinePercent()));
95 }
96
97
98
99
100 @Override
101 public PurApAccountingLine createBlankAmountsCopy() {
102 PurApAccountingLine newAccount = (PurApAccountingLine) ObjectUtils.deepCopy(this);
103 newAccount.setAccountLinePercent(BigDecimal.ZERO);
104 newAccount.setAmount(KualiDecimal.ZERO);
105 newAccount.setSequenceNumber(0);
106
107
108
109 return newAccount;
110 }
111
112
113
114
115 @Override
116 public boolean accountStringsAreEqual(SourceAccountingLine accountingLine) {
117 if (accountingLine == null) {
118 return false;
119 }
120 return new EqualsBuilder().append(getChartOfAccountsCode(), accountingLine.getChartOfAccountsCode()).append(getAccountNumber(), accountingLine.getAccountNumber()).append(getSubAccountNumber(), accountingLine.getSubAccountNumber()).append(getFinancialObjectCode(), accountingLine.getFinancialObjectCode()).append(getFinancialSubObjectCode(), accountingLine.getFinancialSubObjectCode()).append(getProjectCode(), accountingLine.getProjectCode()).append(getOrganizationReferenceId(), accountingLine.getOrganizationReferenceId())
121 .isEquals();
122 }
123
124 @Override
125 public boolean accountStringsAreEqual(PurApAccountingLine accountingLine) {
126 return accountStringsAreEqual((SourceAccountingLine) accountingLine);
127
128 }
129
130
131
132
133 @Override
134 public SourceAccountingLine generateSourceAccountingLine() {
135
136 SourceAccountingLine sourceLine = new SourceAccountingLine();
137 sourceLine.setChartOfAccountsCode(getChartOfAccountsCode());
138 sourceLine.setAccountNumber(getAccountNumber());
139 sourceLine.setSubAccountNumber(getSubAccountNumber());
140 sourceLine.setFinancialObjectCode(getFinancialObjectCode());
141 sourceLine.setFinancialSubObjectCode(getFinancialSubObjectCode());
142 sourceLine.setProjectCode(getProjectCode());
143 sourceLine.setOrganizationReferenceId(getOrganizationReferenceId());
144 sourceLine.setAmount(getAmount());
145 sourceLine.setSequenceNumber(getSequenceNumber());
146 return sourceLine;
147 }
148
149
150
151
152
153 @Override
154 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
155 LinkedHashMap m = new LinkedHashMap();
156
157 m.put("chart", getChartOfAccountsCode());
158 m.put("account", getAccountNumber());
159 m.put("objectCode", getFinancialObjectCode());
160 m.put("subAccount", getSubAccountNumber());
161 m.put("subObjectCode", getFinancialSubObjectCode());
162 m.put("projectCode", getProjectCode());
163 m.put("orgRefId", getOrganizationReferenceId());
164
165 return m;
166 }
167
168 @Override
169 public int compareTo(Object arg0) {
170 if (arg0 instanceof PurApAccountingLine) {
171 PurApAccountingLine account = (PurApAccountingLine) arg0;
172 return this.getString().compareTo(account.getString());
173 }
174 return -1;
175 }
176
177 @Override
178 public String getString() {
179 return getChartOfAccountsCode() + "~" + getAccountNumber() + "~" + getSubAccountNumber() + "~" + getFinancialObjectCode() + "~" + getFinancialSubObjectCode() + "~" + getProjectCode() + "~" + getOrganizationReferenceId();
180 }
181
182 @Override
183 public KualiDecimal getAlternateAmountForGLEntryCreation() {
184 return alternateAmountForGLEntryCreation;
185 }
186
187 @Override
188 public void setAlternateAmountForGLEntryCreation(KualiDecimal alternateAmount) {
189 this.alternateAmountForGLEntryCreation = alternateAmount;
190 }
191
192
193
194
195 @Override
196 public Integer getSequenceNumber() {
197 return this.getAccountIdentifier();
198 }
199
200 protected void copyFrom(PurApAccountingLine other) {
201
202 super.copyFrom(other);
203
204 setAccountLinePercent(other.getAccountLinePercent());
205 setAmount(other.getAmount());
206 setAlternateAmountForGLEntryCreation(other.getAlternateAmountForGLEntryCreation());
207
208 }
209
210 @Override
211 public void refreshNonUpdateableReferences() {
212
213 PurApItem item = null;
214 PurApItem tempItem = getPurapItem();
215 if (tempItem != null &&
216 tempItem.getItemIdentifier() != null) {
217 item = tempItem;
218 }
219 super.refreshNonUpdateableReferences();
220 if (ObjectUtils.isNotNull(item)) {
221 this.setPurapItem(item);
222 }
223 }
224
225 @Override
226 public <T extends PurApItem> T getPurapItem() {
227 return (T) purapItem;
228 }
229
230
231
232
233
234
235
236 @Deprecated
237 @Override
238 public void setPurapItem(PurApItem item) {
239 purapItem = item;
240 }
241
242 @Override
243 public String getPostingPeriodCode() {
244 return postingPeriodCode;
245 }
246
247 @Override
248 public void setPostingPeriodCode(String postingPeriodCode) {
249 this.postingPeriodCode = postingPeriodCode;
250 }
251
252
253
254
255
256
257 @Override
258 public Map getValuesMap() {
259 Map valuesMap = super.getValuesMap();
260
261 valuesMap.remove(OLEPropertyConstants.DOCUMENT_NUMBER);
262 return valuesMap;
263 }
264
265
266
267
268
269
270
271 @Override
272 public Integer getPurApSequenceNumber() {
273 return super.getSequenceNumber();
274 }
275 }