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