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.calendar; 017 018 import org.kuali.hr.time.holidaycalendar.HolidayCalendar; 019 import org.kuali.hr.time.holidaycalendar.HolidayCalendarDateEntry; 020 import org.kuali.hr.time.principal.PrincipalHRAttributes; 021 import org.kuali.hr.time.service.base.TkServiceLocator; 022 import org.kuali.hr.time.timeblock.TimeBlock; 023 import org.kuali.hr.time.timeblock.TimeHourDetail; 024 import org.kuali.hr.time.util.TKContext; 025 import org.kuali.hr.time.util.TkConstants; 026 import org.kuali.hr.time.workflow.TimesheetDocumentHeader; 027 028 import java.util.List; 029 030 public class TimeHourDetailRenderer { 031 private TimeHourDetail timeHourDetail; 032 private boolean overtimeEarnCode; 033 034 public TimeHourDetailRenderer(TimeHourDetail d) { 035 this.timeHourDetail = d; 036 List<String> ovtEarnCodes = TkServiceLocator.getEarnCodeService().getOvertimeEarnCodesStrs(TKContext.getCurrentTimesheetDocument().getAsOfDate()); 037 setOvertimeEarnCode(ovtEarnCodes.contains(d.getEarnCode())); 038 } 039 040 public TimeHourDetail getTimeHourDetail() { 041 return timeHourDetail; 042 } 043 044 public String getTkTimeHourDetailId() { 045 return timeHourDetail.getTkTimeHourDetailId(); 046 } 047 048 public String getTitle() { 049 return timeHourDetail.getEarnCode(); 050 } 051 052 public String getHours() { 053 return timeHourDetail.getHours().toString(); 054 } 055 056 public String getAmount() { 057 return timeHourDetail.getAmount().toString(); 058 } 059 060 public String getHolidayName() { 061 HolidayCalendarDateEntry holidayCalendarDateEntry = null; 062 String holidayDesc = ""; 063 TimeBlock timeBlock = TkServiceLocator.getTimeBlockService().getTimeBlock(timeHourDetail.getTkTimeBlockId()); 064 065 if ( timeBlock != null ){ 066 if(timeBlock.getEarnCode().equals(TkConstants.HOLIDAY_EARN_CODE)) { 067 String documentId = timeBlock.getDocumentId(); 068 TimesheetDocumentHeader docHeader = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(documentId); 069 PrincipalHRAttributes principalCalendar = TkServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(docHeader.getPrincipalId(), new java.sql.Date(timeBlock.getBeginDate().getTime())); 070 071 if ( principalCalendar.getHolidayCalendarGroup() != null ){ 072 HolidayCalendar holidayCalendar = TkServiceLocator.getHolidayCalendarService().getHolidayCalendarByGroup(principalCalendar.getHolidayCalendarGroup()); 073 074 if ( holidayCalendar != null ){ 075 holidayCalendarDateEntry = TkServiceLocator.getHolidayCalendarService().getHolidayCalendarDateEntryByDate(holidayCalendar.getHrHolidayCalendarId(), timeBlock.getBeginDate()); 076 077 if(holidayCalendarDateEntry != null) { 078 holidayDesc = holidayCalendarDateEntry.getHolidayDescr(); 079 } 080 } 081 } 082 } 083 } 084 085 return holidayDesc; 086 } 087 088 public boolean isOvertimeEarnCode() { 089 return overtimeEarnCode; 090 } 091 092 public void setOvertimeEarnCode(boolean overtimeEarnCode) { 093 this.overtimeEarnCode = overtimeEarnCode; 094 } 095 096 }