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