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.approval.web;
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 import java.util.Set;
024
025 import org.apache.commons.lang.StringUtils;
026 import org.kuali.hr.time.service.base.TkServiceLocator;
027 import org.kuali.hr.time.timeblock.TimeBlock;
028 import org.kuali.hr.time.timesheet.TimesheetDocument;
029 import org.kuali.hr.time.timesummary.TimeSummary;
030 import org.kuali.hr.time.util.TKContext;
031 import org.kuali.hr.time.util.TkConstants;
032 import org.kuali.rice.kew.api.KewApiConstants;
033 import org.kuali.rice.kew.api.note.Note;
034 import org.kuali.rice.kew.doctype.SecuritySession;
035 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
036 import org.kuali.rice.kew.service.KEWServiceLocator;
037 import org.kuali.rice.kim.api.identity.Person;
038 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
039
040 public class ApprovalTimeSummaryRow implements Comparable<ApprovalTimeSummaryRow> {
041 private String name;
042 private List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>();
043 /** A Map (Assignment key) of Mapped totals (pay label mapping) */
044 private Map<String, Map<String, BigDecimal>> approverHoursByAssignment;
045 /** A Map (Assignment key) of Mapped totals (pay label mapping) */
046 private Map<String, Map<String, BigDecimal>> otherHoursByAssignment;
047 /** A String (AssignmentDescriptionKey) to Description mapping for all assignments on this summary row */
048 private Map<String,String> assignmentDescriptions; // could refactor out to action level call
049
050 private String approvalStatus;
051 private String approvalStatusMessage;
052 private String documentId;
053 private Map<String,BigDecimal> hoursToPayLabelMap = new HashMap<String,BigDecimal>();
054 private Map<String,BigDecimal> hoursToFlsaPayLabelMap = new HashMap<String,BigDecimal>();
055 private String clockStatusMessage;
056 private String payCalendarGroup;
057 private List<Note> notes = new ArrayList<Note>();
058 private List<String> warnings = new ArrayList<String>();
059 private Set<String> workAreas;
060 private String principalId;
061 private Boolean clockedInOverThreshold = Boolean.FALSE;
062 private String selected = "off";
063 private TimeSummary timeSummary;
064 private BigDecimal periodTotal = BigDecimal.ZERO;
065
066 public String getApprovalStatusMessage() {
067 return approvalStatusMessage;
068 }
069
070 public void setApprovalStatusMessage(String approvalStatusMessage) {
071 this.approvalStatusMessage = approvalStatusMessage;
072 }
073
074 public Map<String, String> getAssignmentDescriptions() {
075 return assignmentDescriptions;
076 }
077
078 public void setAssignmentDescriptions(Map<String, String> assignmentDescriptions) {
079 this.assignmentDescriptions = assignmentDescriptions;
080 }
081
082 public Map<String, Map<String, BigDecimal>> getApproverHoursByAssignment() {
083 return approverHoursByAssignment;
084 }
085
086 public void setApproverHoursByAssignment(Map<String, Map<String, BigDecimal>> approverHoursByAssignment) {
087 this.approverHoursByAssignment = approverHoursByAssignment;
088 }
089
090 public Map<String, Map<String, BigDecimal>> getOtherHoursByAssignment() {
091 return otherHoursByAssignment;
092 }
093
094 public void setOtherHoursByAssignment(Map<String, Map<String, BigDecimal>> otherHoursByAssignment) {
095 this.otherHoursByAssignment = otherHoursByAssignment;
096 }
097
098 public String getName() {
099 return name;
100 }
101 public void setName(String name) {
102 this.name = name;
103 }
104 public List<TimeBlock> getLstTimeBlocks() {
105 return lstTimeBlocks;
106 }
107 public void setLstTimeBlocks(List<TimeBlock> lstTimeBlocks) {
108 this.lstTimeBlocks = lstTimeBlocks;
109 }
110 public String getApprovalStatus() {
111 return approvalStatus;
112 }
113 public void setApprovalStatus(String approvalStatus) {
114 this.approvalStatus = approvalStatus;
115 }
116 public void setDocumentId(String documentId) {
117 this.documentId = documentId;
118 }
119 public String getDocumentId() {
120 return documentId;
121 }
122 public void setHoursToPayLabelMap(Map<String,BigDecimal> hoursToPayLabelMap) {
123 this.hoursToPayLabelMap = hoursToPayLabelMap;
124 }
125 public Map<String,BigDecimal> getHoursToPayLabelMap() {
126 return hoursToPayLabelMap;
127 }
128 public void setHoursToFlsaPayLabelMap(Map<String,BigDecimal> hoursToFlsaPayLabelMap) {
129 this.hoursToFlsaPayLabelMap = hoursToFlsaPayLabelMap;
130 }
131 public Map<String,BigDecimal> getHoursToFlsaPayLabelMap() {
132 return hoursToFlsaPayLabelMap;
133 }
134 public void setClockStatusMessage(String clockStatusMessage) {
135 this.clockStatusMessage = clockStatusMessage;
136 }
137 public String getClockStatusMessage() {
138 return clockStatusMessage;
139 }
140
141 public String getPayCalendarGroup() {
142 return payCalendarGroup;
143 }
144
145 public void setPayCalendarGroup(String payCalendarGroup) {
146 this.payCalendarGroup = payCalendarGroup;
147 }
148
149 /**
150 * Is this record initiated?
151 * @return true if initiated, false otherwise.
152 */
153 public boolean isRoutable() {
154 return StringUtils.equals(getApprovalStatus(), TkConstants.ROUTE_STATUS.INITIATED);
155 }
156
157 /**
158 * Is this record ready to be approved?
159 * @return true if a valid TK_APPROVER / TK_PROCESSOR can approve, false otherwise.
160 */
161 public boolean isApprovable() {
162 boolean isEnroute = StringUtils.equals(getApprovalStatus(), "ENROUTE") ;
163
164 if(isEnroute){
165
166 TimesheetDocument doc = TkServiceLocator.getTimesheetService().getTimesheetDocument(this.documentId);
167 //is there a pending bt doc?
168 if (!TkServiceLocator.getTimesheetService().isReadyToApprove(doc)) {
169 return false;
170 }
171
172 DocumentRouteHeaderValue routeHeader = TkServiceLocator.getTimeApproveService().getRouteHeader(this.getDocumentId());
173 boolean authorized = KEWServiceLocator.getDocumentSecurityService().routeLogAuthorized(TKContext.getPrincipalId(), routeHeader, new SecuritySession(TKContext.getPrincipalId()));
174 if(authorized){
175 List<String> principalsToApprove = KEWServiceLocator.getActionRequestService().getPrincipalIdsWithPendingActionRequestByActionRequestedAndDocId(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, this.getDocumentId());
176 if(!principalsToApprove.isEmpty() && principalsToApprove.contains(TKContext.getPrincipalId())){
177 return true;
178 }
179 }
180 }
181 return false;
182 }
183
184 /**
185 * Helper method to grab the URL parameters for setting target mode for a
186 * user/documentID timesheet. Returns a portion simlar to:
187 *
188 * @return parameter portion of a URL, usable to initiate target mode.
189 */
190 public String getTimesheetUserTargetURLParams() {
191 StringBuffer link = new StringBuffer();
192
193 link.append("methodToCall=changeTargetPerson");
194 link.append("&documentId=").append(this.getDocumentId());
195 Person person = KimApiServiceLocator.getPersonService().getPerson(this.getPrincipalId());
196 link.append("&principalName=").append(person.getPrincipalName());
197
198 return link.toString();
199 }
200
201 public List<Note> getNotes() {
202 return notes;
203 }
204
205 public void setNotes(List<Note> notes) {
206 this.notes = notes;
207 }
208
209 public List<String> getWarnings() {
210 return warnings;
211 }
212
213 public void setWarnings(List<String> warnings) {
214 this.warnings = warnings;
215 }
216
217 public Set<String> getWorkAreas() {
218 return workAreas;
219 }
220
221 public void setWorkAreas(Set<String> workAreas) {
222 this.workAreas = workAreas;
223 }
224
225 public String getPrincipalId() {
226 return principalId;
227 }
228
229 public void setPrincipalId(String principalId) {
230 this.principalId = principalId;
231 }
232 public Boolean getClockedInOverThreshold() {
233 return clockedInOverThreshold;
234 }
235 public void setClockedInOverThreshold(Boolean clockedInOverThreshold) {
236 this.clockedInOverThreshold = clockedInOverThreshold;
237 }
238 public String getSelected() {
239 return selected;
240 }
241
242 public void setSelected(String selected) {
243 this.selected = selected;
244 }
245
246 public TimeSummary getTimeSummary() {
247 return timeSummary;
248 }
249
250 public void setTimeSummary(TimeSummary timeSummary) {
251 this.timeSummary = timeSummary;
252 }
253
254 public BigDecimal getPeriodTotal() {
255 return periodTotal;
256 }
257
258 public void setPeriodTotal(BigDecimal periodTotal) {
259 this.periodTotal = periodTotal;
260 }
261
262 public int compareTo(ApprovalTimeSummaryRow row) {
263 return name.compareToIgnoreCase(row.getName());
264 }
265 }