View Javadoc

1   /**
2    * Copyright 2004-2014 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.HashMap;
21  import java.util.Map;
22  
23  import org.kuali.kpme.core.util.HrConstants;
24  import org.kuali.kpme.tklm.api.time.timesummary.AssignmentRowContract;
25  
26  public class AssignmentRow implements Serializable, AssignmentRowContract {
27  	
28  	private static final long serialVersionUID = 5550424832906084957L;
29  	
30  	private String descr;
31  	private String assignmentKey;
32  	private String cssClass;
33  
34  	private EarnCodeSection earnCodeSection;
35  	private BigDecimal periodTotal = BigDecimal.ZERO;
36  	
37  	private Map<Integer,AssignmentColumn> assignmentColumns = new HashMap<Integer, AssignmentColumn>();
38  	
39  	public String getDescr() {
40  		return descr;
41  	}
42  	
43  	public void setDescr(String descr) {
44  		this.descr = descr;
45  	}
46  
47  	public String getAssignmentKey() {
48  		return assignmentKey;
49  	}
50  	
51  	public void setAssignmentKey(String assignmentKey) {
52  		this.assignmentKey = assignmentKey;
53  	}
54  	
55  	public String getCssClass() {
56  		return cssClass;
57  	}
58  	
59  	public void setCssClass(String cssClass) {
60  		this.cssClass = cssClass;
61  	}
62  
63  	public EarnCodeSection getEarnCodeSection() {
64  		return earnCodeSection;
65  	}
66  	
67  	public void setEarnCodeSection(EarnCodeSection earnCodeSection) {
68  		this.earnCodeSection = earnCodeSection;
69  	}
70  	
71  	public BigDecimal getPeriodTotal() {
72  		return periodTotal;
73  	}
74  	
75  	public void setPeriodTotal(BigDecimal periodTotal) {
76  		this.periodTotal = periodTotal;
77  	}
78  
79  	public Map<Integer, AssignmentColumn> getAssignmentColumns() {
80  		return assignmentColumns;
81  	}
82  
83  	public void setAssignmentColumns(
84  			Map<Integer, AssignmentColumn> assignmentColumns) {
85  		this.assignmentColumns = assignmentColumns;
86  	}
87  
88  	public void addAssignmentColumn(Integer index, AssignmentColumn assignmentColumn) {
89  		this.assignmentColumns.put(index,assignmentColumn);
90  	}
91  
92  	public void addToAmount(int index, BigDecimal amount) {
93  		if (amount != null) {
94  			if (0 <= index && index <= getAssignmentColumns().size()) {
95  				AssignmentColumn assignmentColumn = getAssignmentColumns().get(index);
96  				BigDecimal newAmount = assignmentColumn.getAmount().add(amount, HrConstants.MATH_CONTEXT);
97  				assignmentColumn.setAmount(newAmount);
98  			}
99  		}
100 	}
101 	
102 	public void addToTotal(int index, BigDecimal total) {
103 		if (total != null) {
104 			if (0 <= index && index <= getAssignmentColumns().size()) {
105 				AssignmentColumn assignmentColumn = getAssignmentColumns().get(index);
106 				BigDecimal newTotal = assignmentColumn.getTotal().add(total, HrConstants.MATH_CONTEXT);
107 				assignmentColumn.setTotal(newTotal);
108 				getEarnCodeSection().addToTotal(index-1, total);
109 				periodTotal = periodTotal.add(total);
110 			}
111 		}
112 	}
113 
114 	public void addWeeklyTotal(int index, int weekSize) {
115 //		BigDecimal weeklyAmount = BigDecimal.ZERO;
116 //		BigDecimal weeklyTotal = BigDecimal.ZERO;
117 //
118 //		for (ListIterator<AssignmentColumn> iterator = getAssignmentColumns().listIterator(index); iterator.hasPrevious() && iterator.previousIndex() >= (index - weekSize); ) {
119 //			AssignmentColumn assignmentColumn = iterator.previous();
120 //			weeklyAmount = weeklyAmount.add(assignmentColumn.getAmount(), HrConstants.MATH_CONTEXT);
121 //			weeklyTotal = weeklyTotal.add(assignmentColumn.getTotal(), HrConstants.MATH_CONTEXT);
122 //		}
123 //
124 //		if (0 <= index && index < getAssignmentColumns().size()) {
125 //			AssignmentColumn assignmentColumn = getAssignmentColumns().get(index);
126 //			assignmentColumn.setAmount(weeklyAmount);
127 //			assignmentColumn.setTotal(weeklyTotal);
128 //			assignmentColumn.setWeeklyTotal(true);
129 //		}
130 //
131 //		if (!getAssignmentColumns().isEmpty()) {
132 //			AssignmentColumn assignmentColumn = getAssignmentColumns().get(getAssignmentColumns().size() - 1);
133 //
134 //			BigDecimal periodTotal = assignmentColumn.getTotal().add(weeklyTotal, HrConstants.MATH_CONTEXT);
135 //			assignmentColumn.setTotal(periodTotal);
136 //
137 //			BigDecimal periodAmount = assignmentColumn.getAmount().add(weeklyAmount, HrConstants.MATH_CONTEXT);
138 //			assignmentColumn.setAmount(periodAmount);
139 //
140 //			assignmentColumn.setWeeklyTotal(true);
141 //		}
142 	}
143 	
144 }