1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.List;
22 import java.util.ListIterator;
23
24 import org.kuali.hr.time.util.TkConstants;
25
26 public class AssignmentRow implements Serializable {
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 List<AssignmentColumn> assignmentColumns = new ArrayList<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 List<AssignmentColumn> getAssignmentColumns() {
80 return assignmentColumns;
81 }
82
83 public void setAssignmentColumns(List<AssignmentColumn> assignmentColumns) {
84 this.assignmentColumns = assignmentColumns;
85 }
86
87 public void addAssignmentColumn(AssignmentColumn assignmentColumn) {
88 this.assignmentColumns.add(assignmentColumn);
89 }
90
91 public void addToAmount(int index, BigDecimal amount) {
92 if (amount != null) {
93 if (0 <= index && index < getAssignmentColumns().size()) {
94 AssignmentColumn assignmentColumn = getAssignmentColumns().get(index);
95
96 BigDecimal newAmount = assignmentColumn.getAmount().add(amount, TkConstants.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
107 BigDecimal newTotal = assignmentColumn.getTotal().add(total, TkConstants.MATH_CONTEXT);
108 assignmentColumn.setTotal(newTotal);
109 getEarnCodeSection().addToTotal(index, 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(), TkConstants.MATH_CONTEXT);
121 weeklyTotal = weeklyTotal.add(assignmentColumn.getTotal(), TkConstants.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, TkConstants.MATH_CONTEXT);
135 assignmentColumn.setTotal(periodTotal);
136
137 BigDecimal periodAmount = assignmentColumn.getAmount().add(weeklyAmount, TkConstants.MATH_CONTEXT);
138 assignmentColumn.setAmount(periodAmount);
139
140 assignmentColumn.setWeeklyTotal(true);
141 }
142 }
143
144 }