View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.calendar;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.hr.lm.timeoff.SystemScheduledTimeOff;
20  import org.kuali.hr.time.principal.PrincipalHRAttributes;
21  import org.kuali.hr.time.service.base.TkServiceLocator;
22  import org.kuali.hr.time.timeblock.TimeBlock;
23  import org.kuali.hr.time.timeblock.TimeHourDetail;
24  import org.kuali.hr.time.util.TKContext;
25  import org.kuali.hr.time.util.TkConstants;
26  import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
27  
28  import java.util.List;
29  
30  public class TimeHourDetailRenderer {
31      private TimeHourDetail timeHourDetail;
32      private boolean overtimeEarnCode;
33  
34      public TimeHourDetailRenderer(TimeHourDetail d) {
35          this.timeHourDetail = d;
36          List<String> ovtEarnCodes = TkServiceLocator.getEarnCodeService().getOvertimeEarnCodesStrs(TKContext.getCurrentTimesheetDocument().getAsOfDate());
37          setOvertimeEarnCode(ovtEarnCodes.contains(d.getEarnCode()));
38      }
39  
40      public TimeHourDetail getTimeHourDetail() {
41          return timeHourDetail;
42      }
43  
44      public String getTkTimeHourDetailId() {
45          return timeHourDetail.getTkTimeHourDetailId();
46      }
47  
48      public String getTitle() {
49          return timeHourDetail.getEarnCode();
50      }
51  
52      public String getHours() {
53          return timeHourDetail.getHours().toString();
54      }
55  
56      public String getAmount() {
57          return timeHourDetail.getAmount().toString();
58      }
59      
60      public String getHolidayName() {
61  		String holidayDesc = "";
62  		TimeBlock timeBlock = TkServiceLocator.getTimeBlockService().getTimeBlock(timeHourDetail.getTkTimeBlockId());
63  		
64  		if ( timeBlock != null ){
65  			if(timeBlock.getEarnCode().equals(TkConstants.HOLIDAY_EARN_CODE)) {
66  				String documentId = timeBlock.getDocumentId();
67  				TimesheetDocumentHeader docHeader = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(documentId);
68  				PrincipalHRAttributes principalCalendar = TkServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(docHeader.getPrincipalId(), new java.sql.Date(timeBlock.getBeginDate().getTime()));
69  				
70  				if(principalCalendar != null && StringUtils.isNotEmpty(principalCalendar.getLeavePlan())) {
71  					SystemScheduledTimeOff ssto = TkServiceLocator.getSysSchTimeOffService().getSystemScheduledTimeOffByDate(principalCalendar.getLeavePlan(), timeBlock.getBeginDate());
72  					if(ssto != null) {
73  						holidayDesc = ssto.getDescr();
74  					}
75  				}
76  			}
77  		}
78  			
79  		return holidayDesc;
80  	}
81  
82  	public boolean isOvertimeEarnCode() {
83  		return overtimeEarnCode;
84  	}
85  
86  	public void setOvertimeEarnCode(boolean overtimeEarnCode) {
87  		this.overtimeEarnCode = overtimeEarnCode;
88  	}
89  
90  }