001 /** 002 * Copyright 2004-2012 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.hr.time.timesummary; 017 018 import java.math.BigDecimal; 019 import java.util.ArrayList; 020 import java.util.HashMap; 021 import java.util.List; 022 import java.util.Map; 023 024 import org.kuali.hr.time.util.TkConstants; 025 026 public class EarnGroupSection { 027 private String earnGroup; 028 private Map<String, EarnCodeSection> earnCodeToEarnCodeSectionMap = new HashMap<String, EarnCodeSection>(); 029 private List<EarnCodeSection> earnCodeSections = new ArrayList<EarnCodeSection>(); 030 private List<BigDecimal> totals = new ArrayList<BigDecimal>(); 031 public String getEarnGroup() { 032 return earnGroup; 033 } 034 public void setEarnGroup(String earnGroup) { 035 this.earnGroup = earnGroup; 036 } 037 038 public List<BigDecimal> getTotals() { 039 return totals; 040 } 041 042 public void addEarnCodeSection(EarnCodeSection earnCodeSection, List<Boolean> dayArrangements){ 043 for(AssignmentRow assignRow : earnCodeSection.getAssignmentsRows()){ 044 for(int i = 0;i<(assignRow.getTotal().size()-1);i++){ 045 BigDecimal value = totals.get(i).add(assignRow.getTotal().get(i), TkConstants.MATH_CONTEXT); 046 totals.set(i, value.setScale(TkConstants.BIG_DECIMAL_SCALE, TkConstants.BIG_DECIMAL_SCALE_ROUNDING)); 047 } 048 } 049 earnCodeToEarnCodeSectionMap.put(earnCodeSection.getEarnCode(), earnCodeSection); 050 earnCodeSections.add(earnCodeSection); 051 052 BigDecimal periodTotal = BigDecimal.ZERO; 053 for(int i =0;i<totals.size()-2;i++){ 054 if(dayArrangements.get(i)){ 055 periodTotal = periodTotal.add(totals.get(i), TkConstants.MATH_CONTEXT); 056 } 057 } 058 totals.set(totals.size()-1, periodTotal); 059 } 060 public Map<String, EarnCodeSection> getEarnCodeToEarnCodeSectionMap() { 061 return earnCodeToEarnCodeSectionMap; 062 } 063 public void setEarnCodeToEarnCodeSectionMap( 064 Map<String, EarnCodeSection> earnCodeToEarnCodeSectionMap) { 065 this.earnCodeToEarnCodeSectionMap = earnCodeToEarnCodeSectionMap; 066 } 067 068 069 public void addToTotal(int index, BigDecimal hrs){ 070 BigDecimal total = getTotals().get(index); 071 total = total.add(hrs, TkConstants.MATH_CONTEXT); 072 getTotals().set(index, total); 073 } 074 public List<EarnCodeSection> getEarnCodeSections() { 075 return earnCodeSections; 076 } 077 public void setEarnCodeSections(List<EarnCodeSection> earnCodeSections) { 078 this.earnCodeSections = earnCodeSections; 079 } 080 }