View Javadoc

1   /**
2    * Copyright 2004-2012 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.kuali.hr.time.holidaycalendar.HolidayCalendar;
19  import org.kuali.hr.time.holidaycalendar.HolidayCalendarDateEntry;
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  		HolidayCalendarDateEntry holidayCalendarDateEntry = null;
62  		String holidayDesc = "";
63  		TimeBlock timeBlock = TkServiceLocator.getTimeBlockService().getTimeBlock(timeHourDetail.getTkTimeBlockId());
64  		
65  		if ( timeBlock != null ){
66  			if(timeBlock.getEarnCode().equals(TkConstants.HOLIDAY_EARN_CODE)) {
67  				String documentId = timeBlock.getDocumentId();
68  				TimesheetDocumentHeader docHeader = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(documentId);
69  				PrincipalHRAttributes principalCalendar = TkServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(docHeader.getPrincipalId(), new java.sql.Date(timeBlock.getBeginDate().getTime()));
70  				
71  				if ( principalCalendar.getHolidayCalendarGroup() != null ){
72  					HolidayCalendar holidayCalendar = TkServiceLocator.getHolidayCalendarService().getHolidayCalendarByGroup(principalCalendar.getHolidayCalendarGroup());
73  					
74  					if ( holidayCalendar != null ){
75  						holidayCalendarDateEntry = TkServiceLocator.getHolidayCalendarService().getHolidayCalendarDateEntryByDate(holidayCalendar.getHrHolidayCalendarId(), timeBlock.getBeginDate());
76  						
77  						if(holidayCalendarDateEntry != null) {
78  							holidayDesc = holidayCalendarDateEntry.getHolidayDescr();
79  						}
80  					}
81  				}
82  			}
83  		}
84  			
85  		return holidayDesc;
86  	}
87  
88  	public boolean isOvertimeEarnCode() {
89  		return overtimeEarnCode;
90  	}
91  
92  	public void setOvertimeEarnCode(boolean overtimeEarnCode) {
93  		this.overtimeEarnCode = overtimeEarnCode;
94  	}
95  
96  }