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    import java.util.ListIterator;
023    
024    import org.kuali.hr.time.util.TkConstants;
025    
026    public class AssignmentRow implements Serializable {
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 List<AssignmentColumn> assignmentColumns = new ArrayList<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 List<AssignmentColumn> getAssignmentColumns() {
080                    return assignmentColumns;
081            }
082    
083            public void setAssignmentColumns(List<AssignmentColumn> assignmentColumns) {
084                    this.assignmentColumns = assignmentColumns;
085            }
086    
087        public void addAssignmentColumn(AssignmentColumn assignmentColumn) {
088            this.assignmentColumns.add(assignmentColumn);
089        }
090            
091            public void addToAmount(int index, BigDecimal amount) {
092                    if (amount != null) {
093                            if (0 <= index && index < getAssignmentColumns().size()) {
094                                    AssignmentColumn assignmentColumn = getAssignmentColumns().get(index);
095                                    
096                                    BigDecimal newAmount = assignmentColumn.getAmount().add(amount, TkConstants.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                                    
107                                    BigDecimal newTotal = assignmentColumn.getTotal().add(total, TkConstants.MATH_CONTEXT);
108                                    assignmentColumn.setTotal(newTotal);
109                                    getEarnCodeSection().addToTotal(index, 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(), TkConstants.MATH_CONTEXT);
121                            weeklyTotal = weeklyTotal.add(assignmentColumn.getTotal(), TkConstants.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, TkConstants.MATH_CONTEXT);
135                            assignmentColumn.setTotal(periodTotal);
136                            
137                            BigDecimal periodAmount = assignmentColumn.getAmount().add(weeklyAmount, TkConstants.MATH_CONTEXT);
138                            assignmentColumn.setAmount(periodAmount);
139                            
140                            assignmentColumn.setWeeklyTotal(true);
141                    }
142            }
143            
144    }