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.module.endow.report.util; 017 018 import java.math.BigDecimal; 019 import java.util.Collection; 020 import java.util.Iterator; 021 import java.util.TreeMap; 022 023 import org.kuali.kfs.module.endow.EndowConstants.IncomePrincipalIndicator; 024 import org.kuali.kfs.module.endow.businessobject.Security; 025 import org.kuali.kfs.module.endow.businessobject.SecurityReportingGroup; 026 027 028 public class AssetStatementReportDataHolder { 029 030 // header 031 private String institution; 032 private String monthEndDate; 033 private String endingDate; 034 private String kemid; 035 private String kemidLongTitle; 036 037 // body 038 private BigDecimal historyIncomeCash; // 1i 039 private BigDecimal historyPrincipalCash; // 1p 040 041 // Map<report group order, Map<securityId, ReportGroupData>> 042 private TreeMap<Integer, TreeMap<String, ReportGroupData>> reportGroupsForIncome; // 2,3,4,5,6,7 for income 043 private TreeMap<Integer, TreeMap<String, ReportGroupData>> reportGroupsForPrincipal; // 2,3,4,5,6,7 for principal 044 045 // footer 046 private EndowmentReportFooterDataHolder footer; 047 048 public AssetStatementReportDataHolder() { 049 reportGroupsForIncome = new TreeMap<Integer, TreeMap<String, ReportGroupData>>(); 050 reportGroupsForPrincipal = new TreeMap<Integer, TreeMap<String, ReportGroupData>>(); 051 historyIncomeCash = BigDecimal.ZERO; 052 historyPrincipalCash = BigDecimal.ZERO; 053 footer = null; 054 } 055 056 /** 057 * Creates a report group data and registers it 058 * 059 * @param reportingGroup 060 * @param security 061 * @param ipInd 062 * @return 063 */ 064 public ReportGroupData createReportGroupData(SecurityReportingGroup reportingGroup, Security security, String ipInd) { 065 066 Integer reportGroupOrder = reportingGroup.getSecurityReportingGrpOrder(); 067 String securityId = security.getId(); 068 069 // create a new report group data 070 ReportGroupData rgd = new ReportGroupData(); 071 rgd.setSecurityId(securityId); 072 rgd.setSecurityDesc(security.getDescription()); 073 rgd.setReportGroupOrder(reportGroupOrder); 074 rgd.setReportGroupDesc(reportingGroup.getName()); 075 076 if (ipInd.equalsIgnoreCase(IncomePrincipalIndicator.INCOME)) { 077 if (reportGroupsForIncome.containsKey(reportGroupOrder)) { 078 TreeMap<String, ReportGroupData> dataBySecurityId = reportGroupsForIncome.get(reportGroupOrder); 079 // assume that the same securityId does not exist 080 dataBySecurityId.put(securityId, rgd); 081 } else { 082 TreeMap<String, ReportGroupData> dataBySecurityId = new TreeMap<String, ReportGroupData>(); 083 dataBySecurityId.put(securityId, rgd); 084 reportGroupsForIncome.put(reportGroupOrder, dataBySecurityId); 085 } 086 } else { 087 if (reportGroupsForPrincipal.containsKey(reportGroupOrder)) { 088 TreeMap<String, ReportGroupData> dataBySecurityId = reportGroupsForPrincipal.get(reportGroupOrder); 089 dataBySecurityId.put(securityId, rgd); 090 } else { 091 TreeMap<String, ReportGroupData> dataBySecurityId = new TreeMap<String, ReportGroupData>(); 092 dataBySecurityId.put(securityId, rgd); 093 reportGroupsForPrincipal.put(reportGroupOrder, dataBySecurityId); 094 } 095 } 096 097 return rgd; 098 } 099 100 /** 101 * Calculates the sum of units 102 * 103 * @param ipInd 104 * @return 105 */ 106 public BigDecimal getTotalSumOfUnits(String ipInd) { 107 108 BigDecimal total = BigDecimal.ZERO; 109 Collection<TreeMap<String, ReportGroupData>> reportGroupMap; 110 if (IncomePrincipalIndicator.INCOME.equalsIgnoreCase(ipInd) && reportGroupsForIncome != null) { 111 reportGroupMap = reportGroupsForIncome.values(); 112 } else { 113 reportGroupMap = reportGroupsForPrincipal.values(); 114 } 115 for (TreeMap<String, ReportGroupData> reportGroup : reportGroupMap) { 116 Iterator<ReportGroupData> iter = reportGroup.values().iterator(); 117 while (iter.hasNext()) { 118 total = total.add(iter.next().getSumOfUnits()); 119 } 120 } 121 122 return total; 123 } 124 125 /** 126 * Calculates the sum of market values for cash and equivalents 127 * 128 * @param ipInd 129 * @return 130 */ 131 public BigDecimal getTotalMarketValueForCashEquivalents(String ipInd) { 132 return getTotalSumOfMarketValue(ipInd, new Integer(1)); 133 } 134 135 /** 136 * Calculates the sum of market values 137 * 138 * @param ipInd 139 * @param reportGroupOrder 140 * @return 141 */ 142 public BigDecimal getTotalSumOfMarketValue(String ipInd, Integer reportGroupOrder) { 143 144 BigDecimal total = BigDecimal.ZERO; 145 TreeMap<String, ReportGroupData> reportGroupMap; 146 if (IncomePrincipalIndicator.INCOME.equalsIgnoreCase(ipInd) && reportGroupsForIncome != null) { 147 reportGroupMap = reportGroupsForIncome.get(reportGroupOrder); 148 } else { 149 reportGroupMap = reportGroupsForPrincipal.get(reportGroupOrder); 150 } 151 if (reportGroupMap != null && !reportGroupMap.isEmpty()) { 152 Iterator<ReportGroupData> iter = reportGroupMap.values().iterator(); 153 while (iter.hasNext()) { 154 total = total.add(iter.next().getSumOfMarketValue()); 155 } 156 } 157 158 return total; 159 } 160 161 /** 162 * Calculates the sum of market values 163 * 164 * @param ipInd 165 * @return 166 */ 167 public BigDecimal getTotalSumOfMarketValue(String ipInd) { 168 169 BigDecimal total = BigDecimal.ZERO; 170 Collection<TreeMap<String, ReportGroupData>> reportGroupMap; 171 if (IncomePrincipalIndicator.INCOME.equalsIgnoreCase(ipInd) && reportGroupsForIncome != null) { 172 reportGroupMap = reportGroupsForIncome.values(); 173 } else { 174 reportGroupMap = reportGroupsForPrincipal.values(); 175 } 176 for (TreeMap<String, ReportGroupData> reportGroup : reportGroupMap) { 177 Iterator<ReportGroupData> iter = reportGroup.values().iterator(); 178 while (iter.hasNext()) { 179 total = total.add(iter.next().getSumOfMarketValue()); 180 } 181 } 182 183 return total; 184 } 185 186 /** 187 * Calculates the sum of estimated income 188 * 189 * @param ipInd 190 * @return 191 */ 192 public BigDecimal getTotalSumOfEstimatedIncome(String ipInd) { 193 194 BigDecimal total = BigDecimal.ZERO; 195 Collection<TreeMap<String, ReportGroupData>> reportGroupMap; 196 if (IncomePrincipalIndicator.INCOME.equalsIgnoreCase(ipInd) && reportGroupsForIncome != null) { 197 reportGroupMap = reportGroupsForIncome.values(); 198 } else { 199 reportGroupMap = reportGroupsForPrincipal.values(); 200 } 201 for (TreeMap<String, ReportGroupData> reportGroup : reportGroupMap) { 202 Iterator<ReportGroupData> iter = reportGroup.values().iterator(); 203 while (iter.hasNext()) { 204 total = total.add(iter.next().getSumOfEstimatedIncome()); 205 } 206 } 207 208 return total; 209 } 210 211 /** 212 * Calculates the sum of remainder of FY estimated income 213 * 214 * @param ipInd 215 * @return 216 */ 217 public BigDecimal getTotalSumOfRemainderOfFYEstimated(String ipInd) { 218 219 BigDecimal total = BigDecimal.ZERO; 220 Collection<TreeMap<String, ReportGroupData>> reportGroupMap; 221 if (IncomePrincipalIndicator.INCOME.equalsIgnoreCase(ipInd) && reportGroupsForIncome != null) { 222 reportGroupMap = reportGroupsForIncome.values(); 223 } else { 224 reportGroupMap = reportGroupsForPrincipal.values(); 225 } 226 for (TreeMap<String, ReportGroupData> reportGroup : reportGroupMap) { 227 Iterator<ReportGroupData> iter = reportGroup.values().iterator(); 228 while (iter.hasNext()) { 229 total = total.add(iter.next().getSumOfRemainderOfFYEstimated()); 230 } 231 } 232 233 return total; 234 } 235 236 /** 237 * Calculates the sum of next FY estimated income 238 * 239 * @param ipInd 240 * @return 241 */ 242 public BigDecimal getTotalSumOfNextFYEstimatedIncome(String ipInd) { 243 244 BigDecimal total = BigDecimal.ZERO; 245 Collection<TreeMap<String, ReportGroupData>> reportGroupMap; 246 if (IncomePrincipalIndicator.INCOME.equalsIgnoreCase(ipInd) && reportGroupsForIncome != null) { 247 reportGroupMap = reportGroupsForIncome.values(); 248 } else { 249 reportGroupMap = reportGroupsForPrincipal.values(); 250 } 251 for (TreeMap<String, ReportGroupData> reportGroup : reportGroupMap) { 252 Iterator<ReportGroupData> iter = reportGroup.values().iterator(); 253 while (iter.hasNext()) { 254 total = total.add(iter.next().getSumOfNextFYEstimatedIncome()); 255 } 256 } 257 258 return total; 259 } 260 261 /** 262 * Report group data holder 263 */ 264 public class ReportGroupData { 265 private Integer reportGroupOrder; 266 private String reportGroupDesc; 267 private String securityId; 268 private String securityDesc; 269 private BigDecimal sumOfUnits; 270 private BigDecimal sumOfMarketValue; 271 private BigDecimal sumOfEstimatedIncome; 272 private BigDecimal sumOfRemainderOfFYEstimated; 273 private BigDecimal sumOfNextFYEstimatedIncome; 274 275 public ReportGroupData() { 276 sumOfUnits = BigDecimal.ZERO; 277 sumOfMarketValue = BigDecimal.ZERO; 278 sumOfEstimatedIncome = BigDecimal.ZERO; 279 sumOfRemainderOfFYEstimated = BigDecimal.ZERO; 280 sumOfNextFYEstimatedIncome = BigDecimal.ZERO; 281 } 282 283 public Integer getReportGroupOrder() { 284 return reportGroupOrder; 285 } 286 287 public void setReportGroupOrder(Integer reportGroupOrder) { 288 this.reportGroupOrder = reportGroupOrder; 289 } 290 291 public String getReportGroupDesc() { 292 return reportGroupDesc; 293 } 294 295 public void setReportGroupDesc(String reportGroupDesc) { 296 this.reportGroupDesc = reportGroupDesc; 297 } 298 299 public String getSecurityId() { 300 return securityId; 301 } 302 303 public void setSecurityId(String securityId) { 304 this.securityId = securityId; 305 } 306 307 public String getSecurityDesc() { 308 return securityDesc; 309 } 310 311 public void setSecurityDesc(String securityDesc) { 312 this.securityDesc = securityDesc; 313 } 314 315 public BigDecimal getSumOfUnits() { 316 return sumOfUnits; 317 } 318 319 public void addSumOfUnits(BigDecimal sumOfUnits) { 320 this.sumOfUnits = this.sumOfUnits.add(sumOfUnits); 321 } 322 323 public BigDecimal getSumOfMarketValue() { 324 return sumOfMarketValue; 325 } 326 327 public void addSumOfMarketValue(BigDecimal sumOfMarketValue) { 328 this.sumOfMarketValue = this.sumOfMarketValue.add(sumOfMarketValue); 329 } 330 331 public BigDecimal getSumOfEstimatedIncome() { 332 return sumOfEstimatedIncome; 333 } 334 335 public void addSumOfEstimatedIncome(BigDecimal sumOfEstimatedIncome) { 336 this.sumOfEstimatedIncome = this.sumOfEstimatedIncome.add(sumOfEstimatedIncome); 337 } 338 339 public BigDecimal getSumOfRemainderOfFYEstimated() { 340 return sumOfRemainderOfFYEstimated; 341 } 342 343 public void addSumOfRemainderOfFYEstimated(BigDecimal sumOfRemainderOfFYEstimated) { 344 this.sumOfRemainderOfFYEstimated = this.sumOfRemainderOfFYEstimated.add(sumOfRemainderOfFYEstimated); 345 } 346 347 public BigDecimal getSumOfNextFYEstimatedIncome() { 348 return sumOfNextFYEstimatedIncome; 349 } 350 351 public void addSumOfNextFYEstimatedIncome(BigDecimal sumOfNextFYEstimatedIncome) { 352 this.sumOfNextFYEstimatedIncome = this.sumOfNextFYEstimatedIncome.add(sumOfNextFYEstimatedIncome); 353 } 354 } 355 356 public String getInstitution() { 357 return institution; 358 } 359 360 public void setInstitution(String institution) { 361 this.institution = institution; 362 } 363 364 public String getMonthEndDate() { 365 return monthEndDate; 366 } 367 368 public void setMonthEndDate(String monthEndDate) { 369 this.monthEndDate = monthEndDate; 370 } 371 372 public String getEndingDate() { 373 return endingDate; 374 } 375 376 public void setEndingDate(String endingDate) { 377 this.endingDate = endingDate; 378 } 379 380 public String getKemid() { 381 return kemid; 382 } 383 384 public void setKemid(String kemid) { 385 this.kemid = kemid; 386 } 387 388 public String getKemidLongTitle() { 389 return kemidLongTitle; 390 } 391 392 public void setKemidLongTitle(String kemidLongTitle) { 393 this.kemidLongTitle = kemidLongTitle; 394 } 395 396 public BigDecimal getHistoryIncomeCash() { 397 return historyIncomeCash; 398 } 399 400 public void setHistoryIncomeCash(BigDecimal historyIncomeCash) { 401 this.historyIncomeCash = historyIncomeCash; 402 } 403 404 public BigDecimal getHistoryPrincipalCash() { 405 return historyPrincipalCash; 406 } 407 408 public void setHistoryPrincipalCash(BigDecimal historyPrincipalCash) { 409 this.historyPrincipalCash = historyPrincipalCash; 410 } 411 412 public TreeMap<Integer, TreeMap<String, ReportGroupData>> getReportGroupsForIncome() { 413 return reportGroupsForIncome; 414 } 415 416 public void setReportGroupsForIncome(TreeMap<Integer, TreeMap<String, ReportGroupData>> reportGroupsForIncome) { 417 this.reportGroupsForIncome = reportGroupsForIncome; 418 } 419 420 public TreeMap<Integer, TreeMap<String, ReportGroupData>> getReportGroupsForPrincipal() { 421 return reportGroupsForPrincipal; 422 } 423 424 public void setReportGroupsForPrincipal(TreeMap<Integer, TreeMap<String, ReportGroupData>> reportGroupsForPrincipal) { 425 this.reportGroupsForPrincipal = reportGroupsForPrincipal; 426 } 427 428 public EndowmentReportFooterDataHolder getFooter() { 429 return footer; 430 } 431 432 public void setFooter(EndowmentReportFooterDataHolder footer) { 433 this.footer = footer; 434 } 435 436 }