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 java.math.BigDecimal;
019
020 import org.apache.commons.lang.StringUtils;
021 import org.joda.time.DateTime;
022 import org.kuali.hr.lm.LMConstants;
023 import org.kuali.hr.lm.leaveblock.LeaveBlock;
024 import org.kuali.hr.time.service.base.TkServiceLocator;
025 import org.kuali.hr.time.util.TkConstants;
026 import org.kuali.rice.krad.util.ObjectUtils;
027
028 import static org.kuali.hr.time.service.base.TkServiceLocator.*;
029
030 public class LeaveBlockRenderer {
031 private LeaveBlock leaveBlock;
032 private String assignmentClass;
033 //private boolean readOnly;
034
035 public LeaveBlockRenderer(LeaveBlock leaveBlock) {
036 this.leaveBlock = leaveBlock;
037 }
038
039 public LeaveBlock getLeaveBlock() {
040 return leaveBlock;
041 }
042
043 public BigDecimal getHours() {
044 return leaveBlock.getLeaveAmount();
045 }
046
047 public String getEarnCode() {
048 return leaveBlock.getEarnCode();
049 }
050
051 public String getLeaveBlockId() {
052 return leaveBlock.getLmLeaveBlockId();
053 }
054
055 public String getDocumentId() {
056 return leaveBlock.getDocumentId();
057 }
058
059 public String getAssignmentTitle() {
060 return leaveBlock.getAssignmentTitle();
061 }
062
063 public boolean getEditable() {
064 return leaveBlock.isEditable();
065 }
066
067 public boolean getDeletable() {
068 return leaveBlock.isDeletable();
069 }
070
071 public String getAssignmentClass() {
072 return assignmentClass;
073 }
074
075 public void setAssignmentClass(String assignmentClass) {
076 this.assignmentClass = assignmentClass;
077 }
078
079 public String getRequestStatusClass() {
080 return this.leaveBlock.getRequestStatusString().toLowerCase();
081 }
082
083 public String getLeaveBlockDetails() {
084 if (this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE)) {
085 // return "accrual";
086 if(ObjectUtils.isNotNull(leaveBlock.getScheduleTimeOffId()))
087 return TkServiceLocator.getSysSchTimeOffService().getSystemScheduledTimeOff(this.leaveBlock.getScheduleTimeOffId()).getDescr();
088 else
089 return "accrual";
090 }
091 else if(this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.BALANCE_TRANSFER)) {
092 if(this.leaveBlock.getDescription().contains("Forfeited"))
093 return "transfer forfeiture";
094 else if(this.leaveBlock.getDescription().contains("Amount transferred"))
095 return "amount transferred";
096 else if(this.leaveBlock.getDescription().contains("Transferred amount"))
097 return "transferred amount";
098 else
099 return "balance transfer";
100 }
101 else if(this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_PAYOUT)) {
102 if(this.leaveBlock.getDescription().contains("Forfeited"))
103 return "payout forfeiture";
104 else if(this.leaveBlock.getDescription().contains("Amount paid out"))
105 return "amount paid out";
106 else if(this.leaveBlock.getDescription().contains("Payout amount"))
107 return "payout amount";
108 else
109 return "leave payout";
110 }
111 else
112 if(!this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_CALENDAR) &&
113 !this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.TIME_CALENDAR))
114 return LMConstants.LEAVE_BLOCK_TYPE_MAP.get(this.leaveBlock.getLeaveBlockType()).toLowerCase();
115 else
116 return getRequestStatusClass();
117
118 }
119
120 public String getDescription() {
121 return leaveBlock.getDescription();
122 }
123
124
125 public String getTimeRange() {
126 StringBuilder b = new StringBuilder();
127
128 if(leaveBlock.getBeginTimestamp() != null && leaveBlock.getEndTimestamp() != null) {
129 String earnCodeType = TkServiceLocator.getEarnCodeService().getEarnCodeType(leaveBlock.getEarnCode(), new java.sql.Date(leaveBlock.getBeginTimestamp().getTime()));
130 if(StringUtils.equals(earnCodeType, TkConstants.EARN_CODE_TIME)) {
131 DateTime start = new DateTime(leaveBlock.getBeginTimestamp().getTime());
132 DateTime end = new DateTime(leaveBlock.getEndTimestamp().getTime());
133 b.append(start.toString(TkConstants.DT_BASIC_TIME_FORMAT));
134 b.append(" - ");
135 b.append(end.toString(TkConstants.DT_BASIC_TIME_FORMAT));
136 }
137 }
138 return b.toString();
139 }
140 }