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 for(int i = 0;i<assignRow.getTotal().size()-1;i++){ 052 053 BigDecimal value = totals.get(i).add(assignRow.getTotal().get(i), TkConstants.MATH_CONTEXT); 054 totals.set(i, value.setScale(TkConstants.BIG_DECIMAL_SCALE, TkConstants.BIG_DECIMAL_SCALE_ROUNDING)); 055 } 056 assignKeyToAssignmentRowMap.put(assignRow.getAssignmentKey(), assignRow); 057 assignmentsRows.add(assignRow); 058 } 059 060 public void addWeeklyTotal(int index, int weekSize){ 061 062 BigDecimal weeklyTotal = BigDecimal.ZERO; 063 for(int i = index; i >= (index-weekSize) && i >=0;i--){ 064 weeklyTotal = weeklyTotal.add(getTotals().get(i), TkConstants.MATH_CONTEXT); 065 } 066 getTotals().set(index,weeklyTotal); 067 BigDecimal periodTotal = getTotals().get(getTotals().size()-1); 068 periodTotal = periodTotal.add(weeklyTotal, TkConstants.MATH_CONTEXT); 069 getTotals().set(getTotals().size()-1,periodTotal); 070 071 for(AssignmentRow ar : assignmentsRows){ 072 ar.addWeeklyTotal(index, weekSize); 073 } 074 } 075 076 public List<AssignmentRow> getAssignmentsRows() { 077 return assignmentsRows; 078 } 079 public void setAssignmentsRows(List<AssignmentRow> assignmentsRows) { 080 this.assignmentsRows = assignmentsRows; 081 } 082 public List<BigDecimal> getTotals() { 083 return totals; 084 } 085 public void setTotals(List<BigDecimal> totals) { 086 this.totals = totals; 087 } 088 public Map<String, AssignmentRow> getAssignKeyToAssignmentRowMap() { 089 return assignKeyToAssignmentRowMap; 090 } 091 public void setAssignKeyToAssignmentRowMap( 092 Map<String, AssignmentRow> assignKeyToAssignmentRowMap) { 093 this.assignKeyToAssignmentRowMap = assignKeyToAssignmentRowMap; 094 } 095 096 public void addToTotal(int index, BigDecimal hrs){ 097 BigDecimal total = getTotals().get(index); 098 total = total.add(hrs, TkConstants.MATH_CONTEXT); 099 getTotals().set(index, total); 100 } 101 102 public void addToAmount(int index, BigDecimal amount){ 103 BigDecimal amtTotal = getTotals().get(index); 104 amtTotal = amtTotal.add(amount, TkConstants.MATH_CONTEXT); 105 getTotals().set(index, amtTotal); 106 } 107 public EarnGroupSection getEarnGroupSection() { 108 return earnGroupSection; 109 } 110 public void setEarnGroupSection(EarnGroupSection earnGroupSection) { 111 this.earnGroupSection = earnGroupSection; 112 } 113 public Boolean getIsAmountEarnCode() { 114 return isAmountEarnCode; 115 } 116 public void setIsAmountEarnCode(Boolean isAmountEarnCode) { 117 this.isAmountEarnCode = isAmountEarnCode; 118 } 119 120 121 }