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.CARRY_OVER_ADJUSTMENT)) {
092 if(this.leaveBlock.getDescription().equals(LMConstants.MAX_CARRY_OVER_ADJUSTMENT))
093 return "carryover adjustment";
094 else
095 return "adjustment";
096 }
097 else if(this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.BALANCE_TRANSFER)) {
098 if(this.leaveBlock.getDescription().contains("Forfeited"))
099 return "transfer forfeiture";
100 else if(this.leaveBlock.getDescription().contains("Amount transferred"))
101 return "amount transferred";
102 else if(this.leaveBlock.getDescription().contains("Transferred amount"))
103 return "transferred amount";
104 else
105 return "balance transfer";
106 }
107 else if(this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_PAYOUT)) {
108 if(this.leaveBlock.getDescription().contains("Forfeited"))
109 return "payout forfeiture";
110 else if(this.leaveBlock.getDescription().contains("Amount paid out"))
111 return "amount paid out";
112 else if(this.leaveBlock.getDescription().contains("Payout amount"))
113 return "payout amount";
114 else
115 return "leave payout";
116 }
117 else
118 if(!this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_CALENDAR) &&
119 !this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.TIME_CALENDAR))
120 return LMConstants.LEAVE_BLOCK_TYPE_MAP.get(this.leaveBlock.getLeaveBlockType()).toLowerCase();
121 else
122 return getRequestStatusClass();
123
124 }
125
126 public String getDescription() {
127 return leaveBlock.getDescription();
128 }
129
130
131 public String getTimeRange() {
132 StringBuilder b = new StringBuilder();
133
134 if(leaveBlock.getBeginTimestamp() != null && leaveBlock.getEndTimestamp() != null) {
135 String earnCodeType = TkServiceLocator.getEarnCodeService().getEarnCodeType(leaveBlock.getEarnCode(), new java.sql.Date(leaveBlock.getBeginTimestamp().getTime()));
136 if(StringUtils.equals(earnCodeType, TkConstants.EARN_CODE_TIME)) {
137 DateTime start = new DateTime(leaveBlock.getBeginTimestamp().getTime());
138 DateTime end = new DateTime(leaveBlock.getEndTimestamp().getTime());
139 b.append(start.toString(TkConstants.DT_BASIC_TIME_FORMAT));
140 b.append(" - ");
141 b.append(end.toString(TkConstants.DT_BASIC_TIME_FORMAT));
142 }
143 }
144 return b.toString();
145 }
146 }