001 /** 002 * Copyright 2004-2012 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.List; 021 022 import org.kuali.hr.time.util.TkConstants; 023 024 public class AssignmentRow { 025 private String descr; 026 private List<BigDecimal> total = new ArrayList<BigDecimal>(); 027 private String cssClass; 028 private String assignmentKey; 029 030 private List<BigDecimal> amount = new ArrayList<BigDecimal>(); 031 032 private BigDecimal periodTotal = BigDecimal.ZERO; 033 034 private EarnCodeSection earnCodeSection; 035 036 public String getDescr() { 037 return descr; 038 } 039 public void setDescr(String descr) { 040 this.descr = descr; 041 } 042 public List<BigDecimal> getTotal() { 043 return total; 044 } 045 public void setTotal(List<BigDecimal> total) { 046 this.total = total; 047 } 048 public String getCssClass() { 049 return cssClass; 050 } 051 public void setCssClass(String cssClass) { 052 this.cssClass = cssClass; 053 } 054 public String getAssignmentKey() { 055 return assignmentKey; 056 } 057 public void setAssignmentKey(String assignmentKey) { 058 this.assignmentKey = assignmentKey; 059 } 060 061 public void addToTotal(int index, BigDecimal hrs){ 062 BigDecimal total = getTotal().get(index); 063 total = total.add(hrs, TkConstants.MATH_CONTEXT); 064 getTotal().set(index, total); 065 getEarnCodeSection().addToTotal(index, hrs); 066 } 067 068 public void addWeeklyTotal(int index, int weekSize){ 069 BigDecimal weeklyTotal = BigDecimal.ZERO; 070 BigDecimal weeklyAmt = BigDecimal.ZERO; 071 for(int i = index; i >= (index-weekSize) && i >=0;i--){ 072 weeklyTotal = weeklyTotal.add(getTotal().get(i), TkConstants.MATH_CONTEXT); 073 weeklyAmt = weeklyAmt.add(getAmount().get(i), TkConstants.MATH_CONTEXT); 074 } 075 getTotal().set(index,weeklyTotal); 076 getAmount().set(index, weeklyAmt); 077 078 BigDecimal periodTotal = getTotal().get(getTotal().size()-1); 079 periodTotal = periodTotal.add(weeklyTotal, TkConstants.MATH_CONTEXT); 080 getTotal().set(getTotal().size()-1,periodTotal); 081 082 //accumulate amount 083 BigDecimal amountTotal = getAmount().get(getTotal().size()-1); 084 amountTotal = amountTotal.add(weeklyAmt, TkConstants.MATH_CONTEXT); 085 getAmount().set(getAmount().size()-1, amountTotal); 086 } 087 public EarnCodeSection getEarnCodeSection() { 088 return earnCodeSection; 089 } 090 public void setEarnCodeSection(EarnCodeSection earnCodeSection) { 091 this.earnCodeSection = earnCodeSection; 092 } 093 public BigDecimal getPeriodTotal() { 094 return periodTotal; 095 } 096 public void setPeriodTotal(BigDecimal periodTotal) { 097 this.periodTotal = periodTotal; 098 } 099 public List<BigDecimal> getAmount() { 100 return amount; 101 } 102 public void setAmount(List<BigDecimal> amount) { 103 this.amount = amount; 104 } 105 106 public void addToAmount(int index, BigDecimal amount){ 107 if(amount == null){ 108 return; 109 } 110 BigDecimal amtTotal = getAmount().get(index); 111 amtTotal = amtTotal.add(amount, TkConstants.MATH_CONTEXT); 112 getAmount().set(index, amtTotal); 113 } 114 }