001/** 002 * Copyright 2004-2014 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 */ 016package org.kuali.kpme.tklm.time.timesummary; 017 018import java.io.Serializable; 019import java.math.BigDecimal; 020import java.util.HashMap; 021import java.util.Map; 022 023import org.kuali.kpme.core.util.HrConstants; 024import org.kuali.kpme.tklm.api.time.timesummary.AssignmentRowContract; 025 026public class AssignmentRow implements Serializable, AssignmentRowContract { 027 028 private static final long serialVersionUID = 5550424832906084957L; 029 030 private String descr; 031 private String assignmentKey; 032 private String cssClass; 033 034 private EarnCodeSection earnCodeSection; 035 private BigDecimal periodTotal = BigDecimal.ZERO; 036 037 private Map<Integer,AssignmentColumn> assignmentColumns = new HashMap<Integer, AssignmentColumn>(); 038 039 public String getDescr() { 040 return descr; 041 } 042 043 public void setDescr(String descr) { 044 this.descr = descr; 045 } 046 047 public String getAssignmentKey() { 048 return assignmentKey; 049 } 050 051 public void setAssignmentKey(String assignmentKey) { 052 this.assignmentKey = assignmentKey; 053 } 054 055 public String getCssClass() { 056 return cssClass; 057 } 058 059 public void setCssClass(String cssClass) { 060 this.cssClass = cssClass; 061 } 062 063 public EarnCodeSection getEarnCodeSection() { 064 return earnCodeSection; 065 } 066 067 public void setEarnCodeSection(EarnCodeSection earnCodeSection) { 068 this.earnCodeSection = earnCodeSection; 069 } 070 071 public BigDecimal getPeriodTotal() { 072 return periodTotal; 073 } 074 075 public void setPeriodTotal(BigDecimal periodTotal) { 076 this.periodTotal = periodTotal; 077 } 078 079 public Map<Integer, AssignmentColumn> getAssignmentColumns() { 080 return assignmentColumns; 081 } 082 083 public void setAssignmentColumns( 084 Map<Integer, AssignmentColumn> assignmentColumns) { 085 this.assignmentColumns = assignmentColumns; 086 } 087 088 public void addAssignmentColumn(Integer index, AssignmentColumn assignmentColumn) { 089 this.assignmentColumns.put(index,assignmentColumn); 090 } 091 092 public void addToAmount(int index, BigDecimal amount) { 093 if (amount != null) { 094 if (0 <= index && index <= getAssignmentColumns().size()) { 095 AssignmentColumn assignmentColumn = getAssignmentColumns().get(index); 096 BigDecimal newAmount = assignmentColumn.getAmount().add(amount, HrConstants.MATH_CONTEXT); 097 assignmentColumn.setAmount(newAmount); 098 } 099 } 100 } 101 102 public void addToTotal(int index, BigDecimal total) { 103 if (total != null) { 104 if (0 <= index && index <= getAssignmentColumns().size()) { 105 AssignmentColumn assignmentColumn = getAssignmentColumns().get(index); 106 BigDecimal newTotal = assignmentColumn.getTotal().add(total, HrConstants.MATH_CONTEXT); 107 assignmentColumn.setTotal(newTotal); 108 getEarnCodeSection().addToTotal(index-1, total); 109 periodTotal = periodTotal.add(total); 110 } 111 } 112 } 113 114 public void addWeeklyTotal(int index, int weekSize) { 115// BigDecimal weeklyAmount = BigDecimal.ZERO; 116// BigDecimal weeklyTotal = BigDecimal.ZERO; 117// 118// for (ListIterator<AssignmentColumn> iterator = getAssignmentColumns().listIterator(index); iterator.hasPrevious() && iterator.previousIndex() >= (index - weekSize); ) { 119// AssignmentColumn assignmentColumn = iterator.previous(); 120// weeklyAmount = weeklyAmount.add(assignmentColumn.getAmount(), HrConstants.MATH_CONTEXT); 121// weeklyTotal = weeklyTotal.add(assignmentColumn.getTotal(), HrConstants.MATH_CONTEXT); 122// } 123// 124// if (0 <= index && index < getAssignmentColumns().size()) { 125// AssignmentColumn assignmentColumn = getAssignmentColumns().get(index); 126// assignmentColumn.setAmount(weeklyAmount); 127// assignmentColumn.setTotal(weeklyTotal); 128// assignmentColumn.setWeeklyTotal(true); 129// } 130// 131// if (!getAssignmentColumns().isEmpty()) { 132// AssignmentColumn assignmentColumn = getAssignmentColumns().get(getAssignmentColumns().size() - 1); 133// 134// BigDecimal periodTotal = assignmentColumn.getTotal().add(weeklyTotal, HrConstants.MATH_CONTEXT); 135// assignmentColumn.setTotal(periodTotal); 136// 137// BigDecimal periodAmount = assignmentColumn.getAmount().add(weeklyAmount, HrConstants.MATH_CONTEXT); 138// assignmentColumn.setAmount(periodAmount); 139// 140// assignmentColumn.setWeeklyTotal(true); 141// } 142 } 143 144}