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 int i = 0; 046 for (AssignmentColumn assignmentColumn : assignRow.getAssignmentColumns()) { 047 BigDecimal value = totals.get(i).add(assignmentColumn.getTotal(), TkConstants.MATH_CONTEXT); 048 totals.set(i, value.setScale(TkConstants.BIG_DECIMAL_SCALE, TkConstants.BIG_DECIMAL_SCALE_ROUNDING)); 049 i++; 050 } 051 } 052 earnCodeToEarnCodeSectionMap.put(earnCodeSection.getEarnCode(), earnCodeSection); 053 earnCodeSections.add(earnCodeSection); 054 055 BigDecimal periodTotal = BigDecimal.ZERO; 056 for(int i =0;i<totals.size()-2;i++){ 057 if(dayArrangements.get(i)){ 058 periodTotal = periodTotal.add(totals.get(i), TkConstants.MATH_CONTEXT); 059 } 060 } 061 totals.set(totals.size()-1, periodTotal); 062 } 063 public Map<String, EarnCodeSection> getEarnCodeToEarnCodeSectionMap() { 064 return earnCodeToEarnCodeSectionMap; 065 } 066 public void setEarnCodeToEarnCodeSectionMap( 067 Map<String, EarnCodeSection> earnCodeToEarnCodeSectionMap) { 068 this.earnCodeToEarnCodeSectionMap = earnCodeToEarnCodeSectionMap; 069 } 070 071 072 public void addToTotal(int index, BigDecimal hrs){ 073 BigDecimal total = getTotals().get(index); 074 total = total.add(hrs, TkConstants.MATH_CONTEXT); 075 getTotals().set(index, total); 076 } 077 public List<EarnCodeSection> getEarnCodeSections() { 078 return earnCodeSections; 079 } 080 public void setEarnCodeSections(List<EarnCodeSection> earnCodeSections) { 081 this.earnCodeSections = earnCodeSections; 082 } 083 }