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.apache.commons.lang.StringUtils;
019 import org.kuali.hr.lm.timeoff.SystemScheduledTimeOff;
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 String holidayDesc = "";
062 TimeBlock timeBlock = TkServiceLocator.getTimeBlockService().getTimeBlock(timeHourDetail.getTkTimeBlockId());
063
064 if ( timeBlock != null ){
065 if(timeBlock.getEarnCode().equals(TkConstants.HOLIDAY_EARN_CODE)) {
066 String documentId = timeBlock.getDocumentId();
067 TimesheetDocumentHeader docHeader = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(documentId);
068 PrincipalHRAttributes principalCalendar = TkServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(docHeader.getPrincipalId(), new java.sql.Date(timeBlock.getBeginDate().getTime()));
069
070 if(principalCalendar != null && StringUtils.isNotEmpty(principalCalendar.getLeavePlan())) {
071 SystemScheduledTimeOff ssto = TkServiceLocator.getSysSchTimeOffService().getSystemScheduledTimeOffByDate(principalCalendar.getLeavePlan(), timeBlock.getBeginDate());
072 if(ssto != null) {
073 holidayDesc = ssto.getDescr();
074 }
075 }
076 }
077 }
078
079 return holidayDesc;
080 }
081
082 public boolean isOvertimeEarnCode() {
083 return overtimeEarnCode;
084 }
085
086 public void setOvertimeEarnCode(boolean overtimeEarnCode) {
087 this.overtimeEarnCode = overtimeEarnCode;
088 }
089
090 }