1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.timehourdetail;
17
18 import java.util.*;
19
20 import org.apache.commons.collections.CollectionUtils;
21 import org.apache.commons.lang.StringUtils;
22 import org.joda.time.LocalDate;
23 import org.kuali.kpme.core.earncode.EarnCode;
24 import org.kuali.kpme.core.earncode.security.EarnCodeSecurity;
25 import org.kuali.kpme.core.job.Job;
26 import org.kuali.kpme.core.principal.PrincipalHRAttributes;
27 import org.kuali.kpme.core.service.HrServiceLocator;
28 import org.kuali.kpme.core.util.HrConstants;
29 import org.kuali.kpme.core.util.HrContext;
30 import org.kuali.kpme.tklm.api.time.timehourdetail.TimeHourDetailRendererContract;
31 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
32 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
33 import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
34 import org.kuali.kpme.tklm.time.workflow.TimesheetDocumentHeader;
35
36 public class TimeHourDetailRenderer implements TimeHourDetailRendererContract {
37 private TimeHourDetail timeHourDetail;
38 private boolean overtimeEarnCode;
39
40 public TimeHourDetailRenderer(TimeHourDetail d) {
41 this.timeHourDetail = d;
42
43 TimeBlock tb = TkServiceLocator.getTimeBlockService().getTimeBlock(timeHourDetail.getTkTimeBlockId());
44 if(tb != null) {
45 List<EarnCode> overtimeEarnCodeObjs = HrServiceLocator.getEarnCodeService().getOvertimeEarnCodes(LocalDate.now());
46 List<String> overtimeEarnCodeStrings = HrServiceLocator.getEarnCodeService().getOvertimeEarnCodesStrs(tb.getBeginDateTime().toLocalDate());
47 List<String> eligibleOvertimeEarnCodeListStrings = new ArrayList<String>();
48
49 Job job = HrServiceLocator.getJobService().getJob(HrContext.getTargetPrincipalId(), tb.getJobNumber(), tb.getEndDateTime().toLocalDate());
50 if(job != null) {
51 for (EarnCode earnCode : overtimeEarnCodeObjs) {
52 String employee = HrContext.isActiveEmployee() ? "Y" : null;
53 String approver = HrContext.isApprover() ? "Y" : null;
54 String payrollProcessor = HrContext.isPayrollProcessor() ? "Y" : null;
55
56 List<EarnCodeSecurity> securityList = HrServiceLocator.getEarnCodeSecurityService().getEarnCodeSecurityList(job.getDept(), job.getHrSalGroup(), earnCode.getEarnCode(), employee, approver, payrollProcessor, job.getLocation(),
57 "Y", tb.getEndDateTime().toLocalDate());
58 if(CollectionUtils.isNotEmpty(securityList)) {
59 eligibleOvertimeEarnCodeListStrings.add(earnCode.getEarnCode());
60 }
61 }
62 }
63
64
65
66
67
68 if((CollectionUtils.isNotEmpty(eligibleOvertimeEarnCodeListStrings) && CollectionUtils.isNotEmpty(overtimeEarnCodeStrings)) && overtimeEarnCodeStrings.contains(d.getEarnCode()) && (eligibleOvertimeEarnCodeListStrings.size() > 1 || !eligibleOvertimeEarnCodeListStrings.contains(d.getEarnCode()))){
69 setOvertimeEarnCode(true);
70 }
71 }
72 }
73
74 public TimeHourDetail getTimeHourDetail() {
75 return timeHourDetail;
76 }
77
78 public String getTkTimeHourDetailId() {
79 return timeHourDetail.getTkTimeHourDetailId();
80 }
81
82 public String getTitle() {
83 return timeHourDetail.getEarnCode();
84 }
85
86 public String getHours() {
87 return timeHourDetail.getHours().toString();
88 }
89
90 public String getAmount() {
91 return timeHourDetail.getAmount().toString();
92 }
93
94 public String getHolidayName() {
95 String holidayDesc = "";
96 TimeBlock timeBlock = TkServiceLocator.getTimeBlockService().getTimeBlock(timeHourDetail.getTkTimeBlockId());
97
98 if ( timeBlock != null ){
99 if(timeBlock.getEarnCode().equals(HrConstants.HOLIDAY_EARN_CODE)) {
100 String documentId = timeBlock.getDocumentId();
101 TimesheetDocumentHeader docHeader = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(documentId);
102 PrincipalHRAttributes principalCalendar = HrServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(docHeader.getPrincipalId(), timeBlock.getBeginDateTime().toLocalDate());
103
104 if(principalCalendar != null && StringUtils.isNotEmpty(principalCalendar.getLeavePlan())) {
105 holidayDesc = LmServiceLocator.getSysSchTimeOffService().getSSTODescriptionForDate(principalCalendar.getLeavePlan(), timeBlock.getBeginDateTime().toLocalDate());
106 }
107 }
108 }
109
110 return holidayDesc;
111 }
112
113 public boolean isOvertimeEarnCode() {
114 return overtimeEarnCode;
115 }
116
117 public void setOvertimeEarnCode(boolean overtimeEarnCode) {
118 this.overtimeEarnCode = overtimeEarnCode;
119 }
120
121 }