001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.timesummary;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.json.simple.JSONValue;
020 import org.kuali.hr.lm.leaveSummary.LeaveSummaryRow;
021
022 import java.io.Serializable;
023 import java.math.BigDecimal;
024 import java.util.*;
025
026 public class TimeSummary implements Serializable {
027 private List<String> summaryHeader = new ArrayList<String>();
028 private List<EarnGroupSection> sections = new ArrayList<EarnGroupSection>();
029 private List<LeaveSummaryRow> maxedLeaveRows = new ArrayList<LeaveSummaryRow>();
030 private List<BigDecimal> workedHours = new ArrayList<BigDecimal>();
031
032 public List<String> getSummaryHeader() {
033 return summaryHeader;
034 }
035 public void setSummaryHeader(List<String> summaryHeader) {
036 this.summaryHeader = summaryHeader;
037 }
038 public List<EarnGroupSection> getSections() {
039 return sections;
040 }
041 public void setSections(List<EarnGroupSection> sections) {
042 this.sections = sections;
043 }
044 public List<BigDecimal> getWorkedHours() {
045 return workedHours;
046 }
047 public void setWorkedHours(List<BigDecimal> workedHours) {
048 this.workedHours = workedHours;
049 }
050
051 public String toJsonString() {
052 List<Map<String, Object>> earnGroupSections = new ArrayList<Map<String, Object>>();
053
054 //Lets add a fake EarnGroupSection for worked hours!!!
055 Map<String, Object> workedHours = new HashMap<String, Object>();
056 workedHours.put("totals", getWorkedHours());
057 workedHours.put("earnGroup", "Worked Hours");
058 workedHours.put("earnCodeSections", new HashMap<String, Object>());
059
060 //Map<String, Object> workedHoursECS = new HashMap<String, Object>();
061 //workedHoursECS.put("earnCode", "");
062 ///workedHoursECS.put("desc", "Worked Hours");
063 //workedHoursECS.put("totals", getWorkedHours());
064 //workedHoursECS.put("isAmountEarnCode", earnCodeSection.getIsAmountEarnCode());
065
066 for (EarnGroupSection earnGroupSection : this.sections) {
067 List<Map<String, Object>> earnCodeSections = new ArrayList<Map<String, Object>>();
068 Map<String, Object> egs = new TreeMap<String, Object>();
069 egs.put("earnGroup", earnGroupSection.getEarnGroup());
070 egs.put("totals", earnGroupSection.getTotals());
071
072 for (EarnCodeSection earnCodeSection : earnGroupSection.getEarnCodeSections()) {
073 Map<String, Object> ecs = new TreeMap<String, Object>();
074
075 ecs.put("earnCode", earnCodeSection.getEarnCode());
076 ecs.put("desc", earnCodeSection.getDescription());
077 ecs.put("totals", earnCodeSection.getTotals());
078 ecs.put("isAmountEarnCode", earnCodeSection.getIsAmountEarnCode());
079
080 List<Map<String, Object>> assignmentRows = new ArrayList<Map<String, Object>>();
081 for (AssignmentRow assignmentRow : earnCodeSection.getAssignmentsRows()) {
082 Map<String, Object> ar = new TreeMap<String, Object>();
083
084 ar.put("descr", assignmentRow.getDescr());
085 ar.put("assignmentKey", assignmentRow.getAssignmentKey());
086 ar.put("cssClass", assignmentRow.getCssClass());
087 ar.put("earnCode", earnCodeSection.getEarnCode());
088 ecs.put("earnGroup", earnGroupSection.getEarnGroup());
089 ecs.put("totals", earnGroupSection.getTotals());
090
091 List<Map<String, Object>> assignmentColumns = new ArrayList<Map<String, Object>>();
092 for (AssignmentColumn assignmentColumn : assignmentRow.getAssignmentColumns()) {
093 Map<String, Object> ac = new TreeMap<String, Object>();
094
095 ac.put("cssClass", assignmentColumn.getCssClass());
096 ac.put("amount", assignmentColumn.getAmount());
097 ac.put("total", assignmentColumn.getTotal());
098 ac.put("isWeeklyTotal", assignmentColumn.isWeeklyTotal());
099
100 assignmentColumns.add(ac);
101 }
102 ar.put("assignmentColumns", assignmentColumns);
103
104 assignmentRows.add(ar);
105 }
106 ecs.put("assignmentRows", assignmentRows);
107
108 earnCodeSections.add(ecs);
109 }
110 egs.put("earnCodeSections", earnCodeSections);
111 earnGroupSections.add(egs);
112 }
113 earnGroupSections.add(workedHours);
114
115 return JSONValue.toJSONString(earnGroupSections);
116 }
117 public List<LeaveSummaryRow> getMaxedLeaveRows() {
118 return maxedLeaveRows;
119 }
120 public void setMaxedLeaveRows(List<LeaveSummaryRow> maxedLeaveRows) {
121 this.maxedLeaveRows = maxedLeaveRows;
122 }
123
124 }