View Javadoc

1   /**
2    * Copyright 2004-2014 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.kpme.tklm.leave.block;
17  
18  import java.math.BigDecimal;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.joda.time.DateTime;
22  import org.kuali.kpme.core.service.HrServiceLocator;
23  import org.kuali.kpme.core.util.HrConstants;
24  import org.kuali.kpme.tklm.api.leave.block.LeaveBlockRendererContract;
25  import org.kuali.kpme.tklm.common.LMConstants;
26  import org.kuali.kpme.tklm.common.TkConstants;
27  import org.kuali.kpme.tklm.leave.block.LeaveBlock;
28  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
29  import org.kuali.rice.krad.util.ObjectUtils;
30  
31  public class LeaveBlockRenderer implements LeaveBlockRendererContract {
32      private LeaveBlock leaveBlock;
33      private String assignmentClass;
34      //private boolean readOnly;
35  
36      public  LeaveBlockRenderer(LeaveBlock leaveBlock) {
37          this.leaveBlock = leaveBlock;
38      }
39   
40      public LeaveBlock getLeaveBlock() {
41          return leaveBlock;
42      }
43  
44      public BigDecimal getHours() {
45          return leaveBlock.getLeaveAmount();
46      }
47  
48      public String getEarnCode() {
49          return leaveBlock.getEarnCode();
50      }
51  
52      public String getLeaveBlockId() {
53          return leaveBlock.getLmLeaveBlockId();
54      }
55  
56      public String getDocumentId() {
57          return leaveBlock.getDocumentId();
58      }
59  
60  	public String getAssignmentTitle() {
61  		return leaveBlock.getAssignmentTitle();
62  	}
63  
64      public boolean isEditable() {
65          return leaveBlock.isEditable();
66      }
67  
68      public boolean isDeletable() {
69          return leaveBlock.isDeletable();
70      }
71  
72  	public String getAssignmentClass() {
73  		return assignmentClass;
74  	}
75  
76  	public void setAssignmentClass(String assignmentClass) {
77  		this.assignmentClass = assignmentClass;
78  	}
79  
80      public String getRequestStatusClass() {
81          return this.leaveBlock.getRequestStatusString().toLowerCase();
82      }
83  
84      public String getLeaveBlockDetails() {
85          if (this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.ACCRUAL_SERVICE)) {
86  //            return "accrual";
87          	if(ObjectUtils.isNotNull(leaveBlock.getScheduleTimeOffId()))
88          		return LmServiceLocator.getSysSchTimeOffService().getSystemScheduledTimeOff(this.leaveBlock.getScheduleTimeOffId()).getDescr();
89          	else
90          		return "accrual";
91          }
92          else if(this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.CARRY_OVER_ADJUSTMENT)) {
93          	if(this.leaveBlock.getDescription().equals(LMConstants.MAX_CARRY_OVER_ADJUSTMENT))
94          		return "carryover adjustment";
95          	else
96  	 	 	 		return "adjustment";
97          }
98          else if(this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.BALANCE_TRANSFER)) {
99          	if(this.leaveBlock.getDescription().contains("Forfeited"))
100         		return "transfer forfeiture";
101         	else if(this.leaveBlock.getDescription().contains("Amount transferred"))
102         		return "amount transferred";
103         	else if(this.leaveBlock.getDescription().contains("Transferred amount"))
104         		return "transferred amount";
105         	else
106         		return "balance transfer";
107         }
108         else if(this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_PAYOUT)) {
109         	if(this.leaveBlock.getDescription().contains("Forfeited"))
110         		return "payout forfeiture";
111         	else if(this.leaveBlock.getDescription().contains("Amount paid out"))
112         		return "amount paid out";
113         	else if(this.leaveBlock.getDescription().contains("Payout amount"))
114         		return "payout amount";
115         	else
116         		return "leave payout";
117         }
118         else
119         	if(!this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_CALENDAR) &&
120         			!this.leaveBlock.getLeaveBlockType().equals(LMConstants.LEAVE_BLOCK_TYPE.TIME_CALENDAR))
121         		return LMConstants.LEAVE_BLOCK_TYPE_MAP.get(this.leaveBlock.getLeaveBlockType()).toLowerCase();
122         	else
123         		return getRequestStatusClass();
124         
125     }
126     
127     public String getDescription() {
128     	return leaveBlock.getDescription();
129     }
130 
131        
132     public String getTimeRange() {
133         StringBuilder b = new StringBuilder();
134 
135         if(leaveBlock.getBeginTimestamp() != null && leaveBlock.getEndTimestamp() != null) {
136         	String earnCodeType = HrServiceLocator.getEarnCodeService().getEarnCodeType(leaveBlock.getEarnCode(), leaveBlock.getBeginDateTime().toLocalDate());
137         	if(StringUtils.equals(earnCodeType, HrConstants.EARN_CODE_TIME)) {
138 	        	DateTime start = leaveBlock.getBeginDateTime();
139 	        	DateTime end = leaveBlock.getEndDateTime();
140 	            b.append(start.toString(TkConstants.DT_BASIC_TIME_FORMAT));
141 	            b.append(" - ");
142 	            b.append(end.toString(TkConstants.DT_BASIC_TIME_FORMAT));
143         	}
144         }
145         return b.toString();
146     }
147 }