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