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