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 java.io.Serializable; 019 import java.math.BigDecimal; 020 import java.util.ArrayList; 021 import java.util.HashMap; 022 import java.util.List; 023 import java.util.Map; 024 025 import org.kuali.hr.time.util.TkConstants; 026 027 public class EarnCodeSection implements Serializable { 028 private String earnCode; 029 private String description; 030 private Map<String, AssignmentRow> assignKeyToAssignmentRowMap = new HashMap<String, AssignmentRow>(); 031 private List<AssignmentRow> assignmentsRows = new ArrayList<AssignmentRow>(); 032 private List<BigDecimal> totals = new ArrayList<BigDecimal>(); 033 private Boolean isAmountEarnCode = Boolean.FALSE;; 034 035 private EarnGroupSection earnGroupSection; 036 037 public String getEarnCode() { 038 return earnCode; 039 } 040 public void setEarnCode(String earnCode) { 041 this.earnCode = earnCode; 042 } 043 public String getDescription() { 044 return description; 045 } 046 public void setDescription(String description) { 047 this.description = description; 048 } 049 050 public void addAssignmentRow(AssignmentRow assignRow) { 051 int i = 0; 052 for (AssignmentColumn assignmentColumn : assignRow.getAssignmentColumns()) { 053 BigDecimal value = totals.get(i).add(assignmentColumn.getTotal(), TkConstants.MATH_CONTEXT); 054 totals.set(i, value.setScale(TkConstants.BIG_DECIMAL_SCALE, TkConstants.BIG_DECIMAL_SCALE_ROUNDING)); 055 i++; 056 } 057 assignKeyToAssignmentRowMap.put(assignRow.getAssignmentKey(), assignRow); 058 assignmentsRows.add(assignRow); 059 } 060 061 public void addWeeklyTotal(int index, int weekSize){ 062 063 BigDecimal weeklyTotal = BigDecimal.ZERO; 064 for(int i = index; i >= (index-weekSize) && i >=0;i--){ 065 weeklyTotal = weeklyTotal.add(getTotals().get(i), TkConstants.MATH_CONTEXT); 066 } 067 getTotals().set(index,weeklyTotal); 068 BigDecimal periodTotal = getTotals().get(getTotals().size()-1); 069 periodTotal = periodTotal.add(weeklyTotal, TkConstants.MATH_CONTEXT); 070 getTotals().set(getTotals().size()-1,periodTotal); 071 072 for(AssignmentRow ar : assignmentsRows){ 073 ar.addWeeklyTotal(index, weekSize); 074 } 075 } 076 077 public List<AssignmentRow> getAssignmentsRows() { 078 return assignmentsRows; 079 } 080 public void setAssignmentsRows(List<AssignmentRow> assignmentsRows) { 081 this.assignmentsRows = assignmentsRows; 082 } 083 public List<BigDecimal> getTotals() { 084 return totals; 085 } 086 public void setTotals(List<BigDecimal> totals) { 087 this.totals = totals; 088 } 089 public Map<String, AssignmentRow> getAssignKeyToAssignmentRowMap() { 090 return assignKeyToAssignmentRowMap; 091 } 092 public void setAssignKeyToAssignmentRowMap( 093 Map<String, AssignmentRow> assignKeyToAssignmentRowMap) { 094 this.assignKeyToAssignmentRowMap = assignKeyToAssignmentRowMap; 095 } 096 097 public void addToTotal(int index, BigDecimal hrs){ 098 BigDecimal total = getTotals().get(index); 099 total = total.add(hrs, TkConstants.MATH_CONTEXT); 100 getTotals().set(index, total); 101 } 102 103 public void addToAmount(int index, BigDecimal amount){ 104 BigDecimal amtTotal = getTotals().get(index); 105 amtTotal = amtTotal.add(amount, TkConstants.MATH_CONTEXT); 106 getTotals().set(index, amtTotal); 107 } 108 public EarnGroupSection getEarnGroupSection() { 109 return earnGroupSection; 110 } 111 public void setEarnGroupSection(EarnGroupSection earnGroupSection) { 112 this.earnGroupSection = earnGroupSection; 113 } 114 public Boolean getIsAmountEarnCode() { 115 return isAmountEarnCode; 116 } 117 public void setIsAmountEarnCode(Boolean isAmountEarnCode) { 118 this.isAmountEarnCode = isAmountEarnCode; 119 } 120 121 122 }