View Javadoc
1   /*
2    * Copyright 2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.gl.businessobject;
17  
18  import java.util.LinkedHashMap;
19  import java.util.List;
20  
21  import org.apache.commons.lang.ArrayUtils;
22  import org.kuali.ole.coa.service.ObjectTypeService;
23  import org.kuali.ole.sys.OLEConstants;
24  import org.kuali.ole.sys.OLEKeyConstants;
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.rice.core.api.config.property.ConfigurationService;
27  import org.kuali.rice.core.api.util.type.KualiDecimal;
28  import org.kuali.rice.krad.bo.TransientBusinessObjectBase;
29  
30  public class PosterOutputSummaryTotal extends TransientBusinessObjectBase implements PosterOutputSummaryAmountHolder {
31      private KualiDecimal creditAmount;
32      private KualiDecimal debitAmount;
33      private KualiDecimal budgetAmount;
34      private KualiDecimal netAmount;
35      
36      private String objectTypeCode;
37      
38      private final String[] assetExpenseObjectTypeCodes;
39      
40      public PosterOutputSummaryTotal() {
41          creditAmount = KualiDecimal.ZERO;
42          debitAmount = KualiDecimal.ZERO;
43          budgetAmount = KualiDecimal.ZERO;
44          netAmount = KualiDecimal.ZERO;
45          
46          ObjectTypeService objectTypeService = (ObjectTypeService) SpringContext.getBean(ObjectTypeService.class);
47          List<String> objectTypes = objectTypeService.getCurrentYearExpenseObjectTypes();
48          objectTypes.add(objectTypeService.getCurrentYearAssetObjectType());
49  
50          assetExpenseObjectTypeCodes = objectTypes.toArray(new String[0]);
51      }
52      
53      /**
54       * This method sets the amounts for this poster output summary entry.
55       * 
56       * @param debitCreditCode credit code used to determine whether amounts is debit or credit
57       * @param objectTypeCode object type code associated with amount
58       * @param amount amount to add
59       */
60      public void addAmount(String debitCreditCode, String objectTypeCode, KualiDecimal amount) {
61  
62          if (OLEConstants.GL_CREDIT_CODE.equals(debitCreditCode)) {
63              creditAmount = creditAmount.add(amount);
64              if (ArrayUtils.contains(assetExpenseObjectTypeCodes, objectTypeCode)) {
65                  netAmount = netAmount.subtract(amount);
66              }
67              else {
68                  netAmount = netAmount.add(amount);
69              }
70          }
71          else if (OLEConstants.GL_DEBIT_CODE.equals(debitCreditCode)) {
72              debitAmount = debitAmount.add(amount);
73              if (ArrayUtils.contains(assetExpenseObjectTypeCodes, objectTypeCode)) {
74                  netAmount = netAmount.add(amount);
75              }
76              else {
77                  netAmount = netAmount.subtract(amount);
78              }
79          }
80          else {
81              netAmount = netAmount.add(amount);
82              budgetAmount = budgetAmount.add(amount);
83          }
84      }
85      
86      /**
87       * Adds the totals from the entry to the totals this total line carries
88       * @param entry the entry to add totals from
89       */
90      public void addAmount(PosterOutputSummaryEntry entry) {
91          debitAmount = debitAmount.add(entry.getDebitAmount());
92          creditAmount = creditAmount.add(entry.getCreditAmount());
93          budgetAmount = budgetAmount.add(entry.getBudgetAmount());
94          netAmount = netAmount.add(entry.getNetAmount());
95      }
96      
97      public KualiDecimal getBudgetAmount() {
98          return budgetAmount;
99      }
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(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.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.krad.bo.BusinessObjectBase#toStringMapper()
131      */
132     
133     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
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 }