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.json.simple.JSONValue;
019
020 import java.math.BigDecimal;
021 import java.util.ArrayList;
022 import java.util.HashMap;
023 import java.util.List;
024 import java.util.Map;
025
026 public class TimeSummary {
027 private List<String> summaryHeader = new ArrayList<String>();
028 private List<EarnGroupSection> sections = new ArrayList<EarnGroupSection>();
029
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
053 List<Map<String, Object>> earnCodeSections = new ArrayList<Map<String, Object>>();
054
055 for (EarnGroupSection earnGroupSection : this.sections) {
056 for (EarnCodeSection earnCodeSection : earnGroupSection.getEarnCodeSections()) {
057 Map<String, Object> ecs = new HashMap<String, Object>();
058
059
060 ecs.put("earnCode", earnCodeSection.getEarnCode());
061 ecs.put("desc", earnCodeSection.getDescription());
062 ecs.put("totals", earnCodeSection.getTotals());
063 ecs.put("isAmountEarnCode", earnCodeSection.getIsAmountEarnCode());
064
065 List<Map<String, Object>> assignmentRows = new ArrayList<Map<String, Object>>();
066 for (AssignmentRow assignmentRow : earnCodeSection.getAssignmentsRows()) {
067
068 Map<String, Object> ar = new HashMap<String, Object>();
069
070 ar.put("assignmentKey", assignmentRow.getAssignmentKey());
071 ar.put("descr", assignmentRow.getDescr());
072 ar.put("cssClass", assignmentRow.getCssClass());
073 ar.put("amount", assignmentRow.getAmount());
074 ar.put("total", assignmentRow.getTotal());
075 ar.put("amount", assignmentRow.getAmount());
076
077 assignmentRows.add(ar);
078 }
079
080 ecs.put("assignmentRows", assignmentRows);
081 ecs.put("earnGroup", earnGroupSection.getEarnGroup());
082 ecs.put("totals", earnGroupSection.getTotals());
083
084 earnCodeSections.add(ecs);
085 }
086
087 }
088
089 return JSONValue.toJSONString(earnCodeSections);
090 }
091
092 }