1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.LinkedHashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.TreeMap;
26
27 import org.json.simple.JSONValue;
28 import org.kuali.kpme.tklm.api.time.timesummary.TimeSummaryContract;
29 import org.kuali.kpme.tklm.leave.summary.LeaveSummaryRow;
30
31 public class TimeSummary implements Serializable, TimeSummaryContract {
32
33 private static final long serialVersionUID = -1292273625423289154L;
34 private Map<Integer,String> timeSummaryHeader;
35 private BigDecimal grandTotal= BigDecimal.ZERO;
36 private List<String> summaryHeader = new ArrayList<String>();
37 private List<EarnGroupSection> sections = new ArrayList<EarnGroupSection>();
38 private Map<String, List<EarnGroupSection>> weeklySections = new LinkedHashMap<String, List<EarnGroupSection>>();
39 private List<LeaveSummaryRow> maxedLeaveRows = new ArrayList<LeaveSummaryRow>();
40 private List<BigDecimal> workedHours = new ArrayList<BigDecimal>();
41 private Map<String, BigDecimal> weekTotalMap = new LinkedHashMap<String, BigDecimal>();
42 private Map<String, BigDecimal> flsaWeekTotalMap = new LinkedHashMap<String, BigDecimal>();
43 private Map<String, Map<Integer, BigDecimal>> weeklyWorkedHours = new LinkedHashMap<String, Map<Integer, BigDecimal>>();
44 private Map<String, String> weekDates = new LinkedHashMap<String, String>();
45
46 public BigDecimal getGrandTotal() {
47 return grandTotal;
48 }
49 public void setGrandTotal(BigDecimal grandTotal) {
50 this.grandTotal = grandTotal;
51 }
52 public List<String> getSummaryHeader() {
53 return summaryHeader;
54 }
55 public void setSummaryHeader(List<String> summaryHeader) {
56 this.summaryHeader = summaryHeader;
57 }
58 public List<EarnGroupSection> getSections() {
59 return sections;
60 }
61 public void setSections(List<EarnGroupSection> sections) {
62 this.sections = sections;
63 }
64 public List<BigDecimal> getWorkedHours() {
65 return workedHours;
66 }
67 public void setWorkedHours(List<BigDecimal> workedHours) {
68 this.workedHours = workedHours;
69 }
70
71 public String toJsonString() {
72 List<Map<String, Object>> earnGroupSections = new ArrayList<Map<String, Object>>();
73
74
75 Map<String, Object> wkHours = new HashMap<String, Object>();
76 wkHours.put("totals", getWorkedHours());
77 wkHours.put("earnGroup", "Worked Hours");
78 wkHours.put("earnCodeSections", new HashMap<String, Object>());
79
80 for (EarnGroupSection earnGroupSection : this.sections) {
81 List<Map<String, Object>> earnCodeSections = new ArrayList<Map<String, Object>>();
82 Map<String, Object> egs = new TreeMap<String, Object>();
83 egs.put("earnGroup", earnGroupSection.getEarnGroup());
84 egs.put("totals", earnGroupSection.getTotals());
85 for (EarnCodeSection earnCodeSection : earnGroupSection.getEarnCodeSections()) {
86 Map<String, Object> ecs = new TreeMap<String, Object>();
87
88 ecs.put("earnCode", earnCodeSection.getEarnCode());
89 ecs.put("desc", earnCodeSection.getDescription());
90 ecs.put("totals", earnCodeSection.getTotals());
91 ecs.put("isAmountEarnCode", earnCodeSection.getIsAmountEarnCode());
92 ecs.put("assignmentSize", earnCodeSection.getAssignmentsRows().size() + 1);
93 ecs.put("earnGroup", earnGroupSection.getEarnGroup());
94 ecs.put("totals", earnGroupSection.getTotals());
95
96 List<Map<String, Object>> assignmentRows = new ArrayList<Map<String, Object>>();
97 for (AssignmentRow assignmentRow : earnCodeSection.getAssignmentsRows()) {
98 Map<String, Object> ar = new TreeMap<String, Object>();
99
100 ar.put("descr", assignmentRow.getDescr());
101 ar.put("assignmentKey", assignmentRow.getAssignmentKey());
102 ar.put("cssClass", assignmentRow.getCssClass());
103 ar.put("earnCode", earnCodeSection.getEarnCode());
104
105 List<Map<String, Object>> assignmentColumns = new ArrayList<Map<String, Object>>();
106 for (AssignmentColumn assignmentColumn : assignmentRow.getAssignmentColumns().values()) {
107 Map<String, Object> ac = new TreeMap<String, Object>();
108
109 ac.put("cssClass", assignmentColumn.getCssClass());
110 ac.put("amount", assignmentColumn.getAmount());
111 ac.put("total", assignmentColumn.getTotal());
112 ac.put("isWeeklyTotal", assignmentColumn.isWeeklyTotal());
113
114 assignmentColumns.add(ac);
115 }
116 ar.put("assignmentColumns", assignmentColumns);
117
118 assignmentRows.add(ar);
119 }
120
121 ecs.put("assignmentRows", assignmentRows);
122
123 List<Map<String, Object>> weekTotalRows = new java.util.LinkedList<Map<String, Object>>();
124 for(String key : this.weekTotalMap.keySet()) {
125 Map<String, Object> wt = new HashMap<String, Object>();
126 wt.put("weekName", key);
127 wt.put("weekTotal", weekTotalMap.get(key));
128 weekTotalRows.add(wt);
129 }
130
131 ecs.put("weekTotals", weekTotalRows);
132
133 List<Map<String, Object>> flsaWeekTotalRows = new java.util.LinkedList<Map<String, Object>>();
134 for(String key : this.flsaWeekTotalMap.keySet()) {
135 Map<String, Object> wt = new HashMap<String, Object>();
136 wt.put("weekName", key);
137 wt.put("weekTotal", flsaWeekTotalMap.get(key));
138 flsaWeekTotalRows.add(wt);
139 }
140
141 ecs.put("flsaWeekTotals", flsaWeekTotalRows);
142
143 earnCodeSections.add(ecs);
144 }
145 egs.put("earnCodeSections", earnCodeSections);
146 earnGroupSections.add(egs);
147 }
148 earnGroupSections.add(wkHours);
149 return JSONValue.toJSONString(earnGroupSections);
150 }
151
152 public List<LeaveSummaryRow> getMaxedLeaveRows() {
153 return maxedLeaveRows;
154 }
155
156 public void setMaxedLeaveRows(List<LeaveSummaryRow> maxedLeaveRows) {
157 this.maxedLeaveRows = maxedLeaveRows;
158 }
159
160
161
162 public Map<String, BigDecimal> getWeekTotalMap() {
163 return weekTotalMap;
164 }
165
166
167
168 public void setWeekTotalMap(Map<String, BigDecimal> weekTotalMap) {
169 this.weekTotalMap = weekTotalMap;
170 }
171
172 public Map<String, BigDecimal> getFlsaWeekTotalMap() {
173 return flsaWeekTotalMap;
174 }
175
176 public void setFlsaWeekTotalMap(Map<String, BigDecimal> flsaWeekTotalMap) {
177 this.flsaWeekTotalMap = flsaWeekTotalMap;
178 }
179
180 public Map<String, String> getWeekDates() {
181 return weekDates;
182 }
183 public void setWeekDates(Map<String, String> weekDates) {
184 this.weekDates = weekDates;
185 }
186 public Map<String, List<EarnGroupSection>> getWeeklySections() {
187 return weeklySections;
188 }
189
190 public void setWeeklySections(Map<String, List<EarnGroupSection>> weeklySections) {
191 this.weeklySections = weeklySections;
192 }
193
194 public Map<String, Map<Integer, BigDecimal>> getWeeklyWorkedHours() {
195 return weeklyWorkedHours;
196 }
197
198 public void setWeeklyWorkedHours(
199 Map<String, Map<Integer, BigDecimal>> weeklyWorkedHours) {
200 this.weeklyWorkedHours = weeklyWorkedHours;
201 }
202
203 public Map<Integer, String> getTimeSummaryHeader() {
204 return timeSummaryHeader;
205 }
206
207 public void setTimeSummaryHeader(Map<Integer, String> timeSummaryHeader) {
208 this.timeSummaryHeader = timeSummaryHeader;
209 }
210
211
212
213 }