View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.time.timesummary;
17  
18  import java.math.BigDecimal;
19  import java.util.ArrayList;
20  import java.util.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.kuali.hr.time.util.TkConstants;
25  
26  public class EarnGroupSection {
27  	private String earnGroup;
28  	private Map<String, EarnCodeSection> earnCodeToEarnCodeSectionMap = new HashMap<String, EarnCodeSection>();
29  	private List<EarnCodeSection> earnCodeSections = new ArrayList<EarnCodeSection>();
30  	private List<BigDecimal> totals = new ArrayList<BigDecimal>();
31  	public String getEarnGroup() {
32  		return earnGroup;
33  	}
34  	public void setEarnGroup(String earnGroup) {
35  		this.earnGroup = earnGroup;
36  	}
37  
38  	public List<BigDecimal> getTotals() {
39  		return totals;
40  	}
41  	
42  	public void addEarnCodeSection(EarnCodeSection earnCodeSection, List<Boolean> dayArrangements){
43  		for(AssignmentRow assignRow : earnCodeSection.getAssignmentsRows()){
44  			for(int i = 0;i<(assignRow.getTotal().size()-1);i++){
45  				BigDecimal value = totals.get(i).add(assignRow.getTotal().get(i), TkConstants.MATH_CONTEXT);
46  				totals.set(i, value.setScale(TkConstants.BIG_DECIMAL_SCALE, TkConstants.BIG_DECIMAL_SCALE_ROUNDING));
47  			}
48  		}
49  		earnCodeToEarnCodeSectionMap.put(earnCodeSection.getEarnCode(), earnCodeSection);
50  		earnCodeSections.add(earnCodeSection);
51  		
52  		BigDecimal periodTotal = BigDecimal.ZERO;
53  		for(int i =0;i<totals.size()-2;i++){
54  			if(dayArrangements.get(i)){
55  				periodTotal = periodTotal.add(totals.get(i), TkConstants.MATH_CONTEXT);
56  			}
57  		}
58  		totals.set(totals.size()-1, periodTotal);
59  	}
60  	public Map<String, EarnCodeSection> getEarnCodeToEarnCodeSectionMap() {
61  		return earnCodeToEarnCodeSectionMap;
62  	}
63  	public void setEarnCodeToEarnCodeSectionMap(
64  			Map<String, EarnCodeSection> earnCodeToEarnCodeSectionMap) {
65  		this.earnCodeToEarnCodeSectionMap = earnCodeToEarnCodeSectionMap;
66  	}
67  	
68  	
69  	public void addToTotal(int index, BigDecimal hrs){
70  		BigDecimal total = getTotals().get(index);
71  		total = total.add(hrs, TkConstants.MATH_CONTEXT);
72  		getTotals().set(index, total);
73  	}
74  	public List<EarnCodeSection> getEarnCodeSections() {
75  		return earnCodeSections;
76  	}
77  	public void setEarnCodeSections(List<EarnCodeSection> earnCodeSections) {
78  		this.earnCodeSections = earnCodeSections;
79  	}
80  }