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
017 package org.kuali.kfs.module.ld.businessobject;
018
019 import java.sql.Timestamp;
020 import java.util.ArrayList;
021 import java.util.LinkedHashMap;
022 import java.util.List;
023
024 import org.apache.commons.lang.StringUtils;
025 import org.kuali.kfs.coa.businessobject.Chart;
026 import org.kuali.kfs.coa.businessobject.ObjectType;
027 import org.kuali.kfs.gl.businessobject.Balance;
028 import org.kuali.kfs.integration.ld.LaborLedgerBalance;
029 import org.kuali.kfs.integration.ld.LaborLedgerObject;
030 import org.kuali.kfs.sys.KFSConstants;
031 import org.kuali.kfs.sys.KFSPropertyConstants;
032 import org.kuali.kfs.sys.context.SpringContext;
033 import org.kuali.rice.kim.bo.Person;
034 import org.kuali.rice.kim.service.PersonService;
035 import org.kuali.rice.kns.util.KualiDecimal;
036
037 /**
038 * Labor business object for LedgerBalance.
039 */
040 public class LedgerBalance extends Balance implements LaborLedgerBalance{
041 private String financialObjectCode;
042 private String financialSubObjectCode;
043 private String financialBalanceTypeCode;
044 private String financialObjectTypeCode;
045 private String positionNumber;
046 private String emplid;
047 private KualiDecimal financialBeginningBalanceLineAmount;
048 private Timestamp transactionDateTimeStamp;
049 private String financialObjectFringeOrSalaryCode;
050 private Chart chartOfAccounts;
051 private ObjectType financialObjectType;
052 private Person ledgerPerson;
053 private LaborObject laborObject;
054
055 /**
056 * Default constructor.
057 */
058 public LedgerBalance() {
059 super();
060 this.setAccountLineAnnualBalanceAmount(KualiDecimal.ZERO);
061 this.setFinancialBeginningBalanceLineAmount(KualiDecimal.ZERO);
062 super.setBeginningBalanceLineAmount(KualiDecimal.ZERO);
063 this.setContractsGrantsBeginningBalanceAmount(KualiDecimal.ZERO);
064 }
065
066 /**
067 * Constructs a LedgerBalance.java.
068 *
069 * @param transaction
070 */
071 public LedgerBalance(LaborTransaction transaction) {
072 this();
073 this.setChartOfAccountsCode(transaction.getChartOfAccountsCode());
074 this.setAccountNumber(transaction.getAccountNumber());
075 this.setFinancialBalanceTypeCode(transaction.getFinancialBalanceTypeCode());
076 this.setEmplid(transaction.getEmplid());
077 this.setFinancialObjectCode(transaction.getFinancialObjectCode());
078 this.setFinancialObjectTypeCode(transaction.getFinancialObjectTypeCode());
079 this.setFinancialSubObjectCode(transaction.getFinancialSubObjectCode());
080 this.setPositionNumber(transaction.getPositionNumber());
081 this.setUniversityFiscalYear(transaction.getUniversityFiscalYear());
082 this.setSubAccountNumber(transaction.getSubAccountNumber());
083 }
084
085 /**
086 * Constructs a LedgerBalance.java.
087 *
088 * @param transaction
089 */
090 public LedgerBalance(LaborBalanceHistory ledgerBalanceHistory) {
091 this();
092 this.setChartOfAccountsCode(ledgerBalanceHistory.getChartOfAccountsCode());
093 this.setAccountNumber(ledgerBalanceHistory.getAccountNumber());
094 this.setFinancialBalanceTypeCode(ledgerBalanceHistory.getFinancialBalanceTypeCode());
095 this.setEmplid(ledgerBalanceHistory.getEmplid());
096 this.setFinancialObjectCode(ledgerBalanceHistory.getFinancialObjectCode());
097 this.setFinancialObjectTypeCode(ledgerBalanceHistory.getFinancialObjectTypeCode());
098 this.setFinancialSubObjectCode(ledgerBalanceHistory.getFinancialSubObjectCode());
099 this.setPositionNumber(ledgerBalanceHistory.getPositionNumber());
100 this.setUniversityFiscalYear(ledgerBalanceHistory.getUniversityFiscalYear());
101 this.setSubAccountNumber(ledgerBalanceHistory.getSubAccountNumber());
102 }
103
104 /**
105 * Gets the emplid
106 *
107 * @return Returns the emplid.
108 */
109 public String getEmplid() {
110 return emplid;
111 }
112
113 /**
114 * Sets the emplid
115 *
116 * @param emplid The emplid to set.
117 */
118 public void setEmplid(String emplid) {
119 this.emplid = emplid;
120 }
121
122 /**
123 * Gets the financialBalanceTypeCode
124 *
125 * @return Returns the financialBalanceTypeCode.
126 */
127 public String getFinancialBalanceTypeCode() {
128 return financialBalanceTypeCode;
129 }
130
131 /**
132 * Sets the financialBalanceTypeCode
133 *
134 * @param financialBalanceTypeCode The financialBalanceTypeCode to set.
135 */
136 public void setFinancialBalanceTypeCode(String financialBalanceTypeCode) {
137 this.financialBalanceTypeCode = financialBalanceTypeCode;
138 }
139
140 /**
141 * Gets the financialBeginningBalanceLineAmount
142 *
143 * @return Returns the financialBeginningBalanceLineAmount.
144 */
145 public KualiDecimal getFinancialBeginningBalanceLineAmount() {
146 return financialBeginningBalanceLineAmount;
147 }
148
149 /**
150 * Sets the financialBeginningBalanceLineAmount
151 *
152 * @param financialBeginningBalanceLineAmount The financialBeginningBalanceLineAmount to set.
153 */
154 public void setFinancialBeginningBalanceLineAmount(KualiDecimal financialBeginningBalanceLineAmount) {
155 this.financialBeginningBalanceLineAmount = financialBeginningBalanceLineAmount;
156 super.setBeginningBalanceLineAmount(financialBeginningBalanceLineAmount);
157
158 }
159
160 /**
161 * Gets the financialObjectCode
162 *
163 * @return Returns the financialObjectCode.
164 */
165 public String getFinancialObjectCode() {
166 return financialObjectCode;
167 }
168
169 /**
170 * Sets the financialObjectCode
171 *
172 * @param financialObjectCode The financialObjectCode to set.
173 */
174 public void setFinancialObjectCode(String financialObjectCode) {
175 this.financialObjectCode = financialObjectCode;
176 }
177
178 /**
179 * Gets the financialObjectTypeCode
180 *
181 * @return Returns the financialObjectTypeCode.
182 */
183 public String getFinancialObjectTypeCode() {
184 return financialObjectTypeCode;
185 }
186
187 /**
188 * Sets the financialObjectTypeCode
189 *
190 * @param financialObjectTypeCode The financialObjectTypeCode to set.
191 */
192 public void setFinancialObjectTypeCode(String financialObjectTypeCode) {
193 this.financialObjectTypeCode = financialObjectTypeCode;
194 }
195
196 /**
197 * Gets the financialSubObjectCode
198 *
199 * @return Returns the financialSubObjectCode.
200 */
201 public String getFinancialSubObjectCode() {
202 return financialSubObjectCode;
203 }
204
205 /**
206 * Sets the financialSubObjectCode
207 *
208 * @param financialSubObjectCode The financialSubObjectCode to set.
209 */
210 public void setFinancialSubObjectCode(String financialSubObjectCode) {
211 this.financialSubObjectCode = financialSubObjectCode;
212 }
213
214 /**
215 * Gets the positionNumber
216 *
217 * @return Returns the positionNumber.
218 */
219 public String getPositionNumber() {
220 return positionNumber;
221 }
222
223 /**
224 * Sets the positionNumber
225 *
226 * @param positionNumber The positionNumber to set.
227 */
228 public void setPositionNumber(String positionNumber) {
229 this.positionNumber = positionNumber;
230 }
231
232 /**
233 * Gets the transactionDateTimeStamp
234 *
235 * @return Returns the transactionDateTimeStamp.
236 */
237 public Timestamp getTransactionDateTimeStamp() {
238 return transactionDateTimeStamp;
239 }
240
241 /**
242 * Sets the transactionDateTimeStamp
243 *
244 * @param transactionDateTimeStamp The transactionDateTimeStamp to set.
245 */
246 public void setTransactionDateTimeStamp(Timestamp transactionDateTimeStamp) {
247 this.transactionDateTimeStamp = transactionDateTimeStamp;
248 }
249
250 /**
251 * Gets the getFinancialBalanceTypeCode
252 *
253 * @return getFinancialBalanceTypeCode
254 * @see org.kuali.kfs.gl.businessobject.Balance#getBalanceTypeCode()
255 */
256 @Override
257 public String getBalanceTypeCode() {
258 return this.getFinancialBalanceTypeCode();
259 }
260
261 /**
262 * Sets the setFinancialBalanceTypeCode
263 *
264 * @param balanceTypeCode
265 * @see org.kuali.kfs.gl.businessobject.Balance#setBalanceTypeCode(java.lang.String)
266 */
267 @Override
268 public void setBalanceTypeCode(String balanceTypeCode) {
269 this.setFinancialBalanceTypeCode(balanceTypeCode);
270 }
271
272 /**
273 * Gets the getChartOfAccounts
274 *
275 * @return getChartOfAccounts
276 * @see org.kuali.kfs.gl.businessobject.Balance#getChart()
277 */
278 @Override
279 public Chart getChart() {
280 return this.getChartOfAccounts();
281 }
282
283 /**
284 * Sets the setChartOfAccounts
285 *
286 * @param chart
287 * @see org.kuali.kfs.gl.businessobject.Balance#setChart(org.kuali.kfs.coa.businessobject.Chart)
288 */
289 @Override
290 public void setChart(Chart chart) {
291 this.setChartOfAccounts(chart);
292 }
293
294 /**
295 * Gets the chartOfAccounts
296 *
297 * @return Returns the chartOfAccounts.
298 */
299 public Chart getChartOfAccounts() {
300 return chartOfAccounts;
301 }
302
303 /**
304 * Sets the chartOfAccounts
305 *
306 * @param chartOfAccounts The chartOfAccounts to set.
307 */
308 public void setChartOfAccounts(Chart chartOfAccounts) {
309 this.chartOfAccounts = chartOfAccounts;
310 }
311
312 /**
313 * Gets the financialObjectType
314 *
315 * @return Returns the financialObjectType.
316 */
317 public ObjectType getFinancialObjectType() {
318 return financialObjectType;
319 }
320
321 /**
322 * Sets the financialObjectType
323 *
324 * @param financialObjectType The financialObjectType to set.
325 */
326 public void setFinancialObjectType(ObjectType financialObjectType) {
327 this.financialObjectType = financialObjectType;
328 }
329
330 /**
331 * Adds amounts in a period.
332 *
333 * @param period, amount
334 * @see org.kuali.kfs.gl.businessobject.Balance#addAmount(java.lang.String, org.kuali.rice.kns.util.KualiDecimal)
335 */
336 @Override
337 public void addAmount(String period, KualiDecimal amount) {
338 if (KFSConstants.PERIOD_CODE_ANNUAL_BALANCE.equals(period)) {
339 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
340 }
341 else if (KFSConstants.PERIOD_CODE_BEGINNING_BALANCE.equals(period)) {
342 this.setFinancialBeginningBalanceLineAmount(this.getFinancialBeginningBalanceLineAmount().add(amount));
343 super.getBeginningBalanceLineAmount().add(amount);
344 }
345 else if (KFSConstants.PERIOD_CODE_CG_BEGINNING_BALANCE.equals(period)) {
346 this.setContractsGrantsBeginningBalanceAmount(this.getContractsGrantsBeginningBalanceAmount().add(amount));
347 }
348 else if (KFSConstants.MONTH1.equals(period)) {
349 setMonth1Amount(getMonth1Amount().add(amount));
350 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
351 }
352 else if (KFSConstants.MONTH2.equals(period)) {
353 setMonth2Amount(getMonth2Amount().add(amount));
354 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
355 }
356 else if (KFSConstants.MONTH3.equals(period)) {
357 setMonth3Amount(getMonth3Amount().add(amount));
358 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
359 }
360 else if (KFSConstants.MONTH4.equals(period)) {
361 setMonth4Amount(getMonth4Amount().add(amount));
362 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
363 }
364 else if (KFSConstants.MONTH5.equals(period)) {
365 setMonth5Amount(getMonth5Amount().add(amount));
366 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
367 }
368 else if (KFSConstants.MONTH6.equals(period)) {
369 setMonth6Amount(getMonth6Amount().add(amount));
370 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
371 }
372 else if (KFSConstants.MONTH7.equals(period)) {
373 setMonth7Amount(getMonth7Amount().add(amount));
374 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
375 }
376 else if (KFSConstants.MONTH8.equals(period)) {
377 setMonth8Amount(getMonth8Amount().add(amount));
378 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
379 }
380 else if (KFSConstants.MONTH9.equals(period)) {
381 setMonth9Amount(getMonth9Amount().add(amount));
382 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
383 }
384 else if (KFSConstants.MONTH10.equals(period)) {
385 setMonth10Amount(getMonth10Amount().add(amount));
386 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
387 }
388 else if (KFSConstants.MONTH11.equals(period)) {
389 setMonth11Amount(getMonth11Amount().add(amount));
390 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
391 }
392 else if (KFSConstants.MONTH12.equals(period)) {
393 setMonth12Amount(getMonth12Amount().add(amount));
394 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
395 }
396 else if (KFSConstants.MONTH13.equals(period)) {
397 setMonth13Amount(getMonth13Amount().add(amount));
398 this.setAccountLineAnnualBalanceAmount(this.getAccountLineAnnualBalanceAmount().add(amount));
399 }
400 }
401
402 /**
403 * get the amount in the given period.
404 *
405 * @param periodCode the given period code
406 */
407 public KualiDecimal getAmountByPeriod(String periodCode) {
408 if (KFSConstants.PERIOD_CODE_ANNUAL_BALANCE.equals(periodCode)) {
409 return this.getAccountLineAnnualBalanceAmount();
410 }
411 else if (KFSConstants.PERIOD_CODE_BEGINNING_BALANCE.equals(periodCode)) {
412 return this.getFinancialBeginningBalanceLineAmount();
413 }
414 else if (KFSConstants.PERIOD_CODE_CG_BEGINNING_BALANCE.equals(periodCode)) {
415 return this.getContractsGrantsBeginningBalanceAmount();
416 }
417 else if (KFSConstants.MONTH1.equals(periodCode)) {
418 return this.getMonth1Amount();
419 }
420 else if (KFSConstants.MONTH2.equals(periodCode)) {
421 return this.getMonth2Amount();
422 }
423 else if (KFSConstants.MONTH3.equals(periodCode)) {
424 return this.getMonth3Amount();
425 }
426 else if (KFSConstants.MONTH4.equals(periodCode)) {
427 return this.getMonth4Amount();
428 }
429 else if (KFSConstants.MONTH5.equals(periodCode)) {
430 return this.getMonth5Amount();
431 }
432 else if (KFSConstants.MONTH6.equals(periodCode)) {
433 return this.getMonth6Amount();
434 }
435 else if (KFSConstants.MONTH7.equals(periodCode)) {
436 return this.getMonth7Amount();
437 }
438 else if (KFSConstants.MONTH8.equals(periodCode)) {
439 return this.getMonth8Amount();
440 }
441 else if (KFSConstants.MONTH9.equals(periodCode)) {
442 return this.getMonth9Amount();
443 }
444 else if (KFSConstants.MONTH10.equals(periodCode)) {
445 return this.getMonth10Amount();
446 }
447 else if (KFSConstants.MONTH11.equals(periodCode)) {
448 return this.getMonth11Amount();
449 }
450 else if (KFSConstants.MONTH12.equals(periodCode)) {
451 return this.getMonth12Amount();
452 }
453 else if (KFSConstants.MONTH13.equals(periodCode)) {
454 return this.getMonth13Amount();
455 }
456 else {
457 throw new IllegalArgumentException("Unsupport Period Code: " + periodCode);
458 }
459 }
460
461 /**
462 * @see org.kuali.module.effort.bo.LaborLedgerEntry#getLaborLedgerObject()
463 */
464 public LaborLedgerObject getLaborLedgerObject() {
465 return this.laborObject;
466 }
467
468 /**
469 * @see org.kuali.module.effort.bo.LaborLedgerEntry#setLaborLedgerObject(org.kuali.kfs.bo.LaborLedgerObject)
470 */
471 @Deprecated
472 public void setLaborLedgerObject(LaborLedgerObject laborLedgerObject) {
473 this.laborObject = (LaborObject) laborLedgerObject;
474 }
475
476 /**
477 * Gets the laborObject attribute.
478 *
479 * @return Returns the laborObject.
480 */
481 public LaborObject getLaborObject() {
482 return laborObject;
483 }
484
485 /**
486 * Sets the laborObject attribute value.
487 *
488 * @param laborObject The laborObject to set.
489 */
490 @Deprecated
491 public void setLaborObject(LaborObject laborObject) {
492 this.laborObject = laborObject;
493 }
494
495 /**
496 * Gets the Person
497 *
498 * @return Returns the Person
499 */
500 public Person getLedgerPerson() {
501 if(ledgerPerson == null || !StringUtils.equals(ledgerPerson.getEmployeeId(), emplid)) {
502 ledgerPerson = SpringContext.getBean(PersonService.class).getPersonByEmployeeId(emplid);
503 }
504
505 return ledgerPerson;
506 }
507
508 /**
509 * Sets the ledgerPerson
510 *
511 * @param ledgerPerson The ledgerPerson to set.
512 */
513 public void setLedgerPerson(Person ledgerPerson) {
514 this.ledgerPerson = ledgerPerson;
515 }
516
517 /**
518 * construct the primary key list of the business object
519 *
520 * @return the primary key list of the business object
521 */
522 public static List<String> getPrimaryKeyList() {
523 List<String> primaryKeyList = new ArrayList<String>();
524 primaryKeyList.add(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
525 primaryKeyList.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
526 primaryKeyList.add(KFSPropertyConstants.ACCOUNT_NUMBER);
527 primaryKeyList.add(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
528 primaryKeyList.add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
529 primaryKeyList.add(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
530 primaryKeyList.add(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE);
531 primaryKeyList.add(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE);
532 primaryKeyList.add(KFSPropertyConstants.POSITION_NUMBER);
533 primaryKeyList.add(KFSPropertyConstants.EMPLID);
534
535 return primaryKeyList;
536 }
537
538 /**
539 * @see org.kuali.kfs.gl.businessobject.Balance#toStringMapper()
540 */
541 @Override
542 protected LinkedHashMap toStringMapper() {
543 LinkedHashMap map = new LinkedHashMap();
544 map.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, getUniversityFiscalYear());
545 map.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, getChartOfAccountsCode());
546 map.put(KFSPropertyConstants.ACCOUNT_NUMBER, getAccountNumber());
547 map.put(KFSPropertyConstants.SUB_ACCOUNT_NUMBER, getSubAccountNumber());
548 map.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, getFinancialObjectCode());
549 map.put(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE, getFinancialSubObjectCode());
550 map.put(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE, getFinancialBalanceTypeCode());
551 map.put(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE, getFinancialObjectTypeCode());
552 map.put(KFSPropertyConstants.POSITION_NUMBER, this.getPositionNumber());
553 map.put(KFSPropertyConstants.EMPLID, this.getEmplid());
554 return map;
555 }
556 }
557