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.kpme.tklm.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.kpme.core.util.HrConstants;
26  import org.kuali.kpme.tklm.api.time.timesummary.EarnCodeSectionContract;
27  
28  public class EarnCodeSection implements Serializable, EarnCodeSectionContract {
29  
30  	private static final long serialVersionUID = 5595259268960130907L;
31  	private String earnCode;
32  	private String description;
33  	private Map<String, AssignmentRow> assignKeyToAssignmentRowMap = new HashMap<String, AssignmentRow>();
34  	private List<AssignmentRow> assignmentsRows = new ArrayList<AssignmentRow>();
35  	private List<BigDecimal> totals = new ArrayList<BigDecimal>();
36  	private Boolean isAmountEarnCode = Boolean.FALSE;;
37  	
38  	private EarnGroupSection earnGroupSection;
39  	
40  	public String getEarnCode() {
41  		return earnCode;
42  	}
43  	public void setEarnCode(String earnCode) {
44  		this.earnCode = earnCode;
45  	}
46  	public String getDescription() {
47  		return description;
48  	}
49  	public void setDescription(String description) {
50  		this.description = description;
51  	}
52  	
53  	public void addAssignmentRow(AssignmentRow assignRow) {
54  		int i = 0;
55  			for (AssignmentColumn assignmentColumn : assignRow.getAssignmentColumns().values()) {
56  			BigDecimal value = totals.get(i).add(assignmentColumn.getTotal(), HrConstants.MATH_CONTEXT);			
57  			totals.set(i, value.setScale(HrConstants.BIG_DECIMAL_SCALE, HrConstants.BIG_DECIMAL_SCALE_ROUNDING));
58  			i++;
59  		}
60  		assignKeyToAssignmentRowMap.put(assignRow.getAssignmentKey(), assignRow);
61  		assignmentsRows.add(assignRow);
62  	}
63  	
64  	public void addWeeklyTotal(int index, int weekSize){
65  		
66  		BigDecimal weeklyTotal = BigDecimal.ZERO;
67  //		for(int i = index; i >= (index-weekSize) && i >=0;i--){
68  //			weeklyTotal = weeklyTotal.add(getTotals().get(i), HrConstants.MATH_CONTEXT);
69  //		}
70  //		getTotals().set(index,weeklyTotal);
71  //		BigDecimal periodTotal = getTotals().get(getTotals().size()-1);
72  //		periodTotal = periodTotal.add(weeklyTotal, HrConstants.MATH_CONTEXT);
73  //		getTotals().set(getTotals().size()-1,periodTotal);
74  		
75  		for(AssignmentRow ar : assignmentsRows){
76  			ar.addWeeklyTotal(index, weekSize);
77  		}
78  	}
79  	
80  	public List<AssignmentRow> getAssignmentsRows() {
81  		return assignmentsRows;
82  	}
83  	public void setAssignmentsRows(List<AssignmentRow> assignmentsRows) {
84  		this.assignmentsRows = assignmentsRows;
85  	}
86  	public List<BigDecimal> getTotals() {
87  		return totals;
88  	}
89  	public void setTotals(List<BigDecimal> totals) {
90  		this.totals = totals;
91  	}
92  	public Map<String, AssignmentRow> getAssignKeyToAssignmentRowMap() {
93  		return assignKeyToAssignmentRowMap;
94  	}
95  	public void setAssignKeyToAssignmentRowMap(
96  			Map<String, AssignmentRow> assignKeyToAssignmentRowMap) {
97  		this.assignKeyToAssignmentRowMap = assignKeyToAssignmentRowMap;
98  	}
99  	
100 	public void addToTotal(int index, BigDecimal hrs){
101 		BigDecimal total = getTotals().get(index);
102 		total = total.add(hrs, HrConstants.MATH_CONTEXT);
103 		getTotals().set(index, total);
104 	}
105 	
106 	public void addToAmount(int index, BigDecimal amount){
107 		BigDecimal amtTotal = getTotals().get(index);
108 		amtTotal = amtTotal.add(amount, HrConstants.MATH_CONTEXT);
109 		getTotals().set(index, amtTotal);
110 	}
111 	public EarnGroupSection getEarnGroupSection() {
112 		return earnGroupSection;
113 	}
114 	public void setEarnGroupSection(EarnGroupSection earnGroupSection) {
115 		this.earnGroupSection = earnGroupSection;
116 	}
117 	public Boolean getIsAmountEarnCode() {
118 		return isAmountEarnCode;
119 	}
120 	public void setIsAmountEarnCode(Boolean isAmountEarnCode) {
121 		this.isAmountEarnCode = isAmountEarnCode;
122 	}
123 	
124 	
125 }