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.util.LinkedHashMap;
019 import java.util.List;
020
021 import org.apache.commons.lang.ArrayUtils;
022 import org.kuali.kfs.coa.service.ObjectTypeService;
023 import org.kuali.kfs.sys.KFSConstants;
024 import org.kuali.kfs.sys.KFSKeyConstants;
025 import org.kuali.kfs.sys.context.SpringContext;
026 import org.kuali.rice.kns.bo.TransientBusinessObjectBase;
027 import org.kuali.rice.kns.service.KualiConfigurationService;
028 import org.kuali.rice.kns.util.KualiDecimal;
029
030 public class PosterOutputSummaryTotal extends TransientBusinessObjectBase implements PosterOutputSummaryAmountHolder {
031 private KualiDecimal creditAmount;
032 private KualiDecimal debitAmount;
033 private KualiDecimal budgetAmount;
034 private KualiDecimal netAmount;
035
036 private String objectTypeCode;
037
038 private final String[] assetExpenseObjectTypeCodes;
039
040 public PosterOutputSummaryTotal() {
041 creditAmount = KualiDecimal.ZERO;
042 debitAmount = KualiDecimal.ZERO;
043 budgetAmount = KualiDecimal.ZERO;
044 netAmount = KualiDecimal.ZERO;
045
046 ObjectTypeService objectTypeService = (ObjectTypeService) SpringContext.getBean(ObjectTypeService.class);
047 List<String> objectTypes = objectTypeService.getCurrentYearExpenseObjectTypes();
048 objectTypes.add(objectTypeService.getCurrentYearAssetObjectType());
049
050 assetExpenseObjectTypeCodes = objectTypes.toArray(new String[0]);
051 }
052
053 /**
054 * This method sets the amounts for this poster output summary entry.
055 *
056 * @param debitCreditCode credit code used to determine whether amounts is debit or credit
057 * @param objectTypeCode object type code associated with amount
058 * @param amount amount to add
059 */
060 public void addAmount(String debitCreditCode, String objectTypeCode, KualiDecimal amount) {
061
062 if (KFSConstants.GL_CREDIT_CODE.equals(debitCreditCode)) {
063 creditAmount = creditAmount.add(amount);
064 if (ArrayUtils.contains(assetExpenseObjectTypeCodes, objectTypeCode)) {
065 netAmount = netAmount.subtract(amount);
066 }
067 else {
068 netAmount = netAmount.add(amount);
069 }
070 }
071 else if (KFSConstants.GL_DEBIT_CODE.equals(debitCreditCode)) {
072 debitAmount = debitAmount.add(amount);
073 if (ArrayUtils.contains(assetExpenseObjectTypeCodes, objectTypeCode)) {
074 netAmount = netAmount.add(amount);
075 }
076 else {
077 netAmount = netAmount.subtract(amount);
078 }
079 }
080 else {
081 netAmount = netAmount.add(amount);
082 budgetAmount = budgetAmount.add(amount);
083 }
084 }
085
086 /**
087 * Adds the totals from the entry to the totals this total line carries
088 * @param entry the entry to add totals from
089 */
090 public void addAmount(PosterOutputSummaryEntry entry) {
091 debitAmount = debitAmount.add(entry.getDebitAmount());
092 creditAmount = creditAmount.add(entry.getCreditAmount());
093 budgetAmount = budgetAmount.add(entry.getBudgetAmount());
094 netAmount = netAmount.add(entry.getNetAmount());
095 }
096
097 public KualiDecimal getBudgetAmount() {
098 return budgetAmount;
099 }
100
101 public KualiDecimal getCreditAmount() {
102 return creditAmount;
103 }
104
105 public KualiDecimal getDebitAmount() {
106 return debitAmount;
107 }
108
109 public KualiDecimal getNetAmount() {
110 return netAmount;
111 }
112
113 public String getObjectTypeCode() {
114 return objectTypeCode;
115 }
116
117 public void setObjectTypeCode(String objectTypeCode) {
118 this.objectTypeCode = objectTypeCode;
119 }
120
121 /**
122 * @return a summary of this total line
123 */
124 public String getSummary() {
125 return SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.MESSAGE_REPORT_POSTER_OUTPUT_SUMMARY_TOTAL);
126 }
127
128 /**
129 * A map of the "keys" of this transient business object
130 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
131 */
132 @Override
133 protected LinkedHashMap toStringMapper() {
134 LinkedHashMap pks = new LinkedHashMap<String, Object>();
135 pks.put("objectTypeCode",this.getObjectTypeCode());
136 pks.put("creditAmount",this.getCreditAmount());
137 pks.put("debitAmount",this.getDebitAmount());
138 pks.put("budgetAmount",this.getBudgetAmount());
139 pks.put("netAmount",this.getNetAmount());
140 return pks;
141 }
142
143 }