1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.batch;
17
18 import java.util.List;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.joda.time.DateTime;
22 import org.kuali.kpme.core.batch.BatchJob;
23 import org.kuali.kpme.core.calendar.Calendar;
24 import org.kuali.kpme.core.calendar.entry.CalendarEntry;
25 import org.kuali.kpme.core.principal.PrincipalHRAttributes;
26 import org.kuali.kpme.core.service.HrServiceLocator;
27 import org.kuali.kpme.tklm.common.TkConstants;
28 import org.kuali.kpme.tklm.time.missedpunch.MissedPunchDocument;
29 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
30 import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
31 import org.kuali.kpme.tklm.time.workflow.TimesheetDocumentHeader;
32 import org.kuali.rice.kew.api.KewApiServiceLocator;
33 import org.kuali.rice.kew.api.document.DocumentStatus;
34 import org.kuali.rice.kew.service.KEWServiceLocator;
35 import org.quartz.Job;
36 import org.quartz.JobDataMap;
37 import org.quartz.JobExecutionContext;
38 import org.quartz.JobExecutionException;
39
40 public class MissedPunchApprovalJob extends BatchJob {
41
42 public void execute(JobExecutionContext context) throws JobExecutionException {
43 JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
44
45 String hrCalendarEntryId = jobDataMap.getString("hrCalendarEntryId");
46
47 CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry(hrCalendarEntryId);
48 Calendar calendar = HrServiceLocator.getCalendarService().getCalendar(calendarEntry.getHrCalendarId());
49 DateTime beginDate = calendarEntry.getBeginPeriodFullDateTime();
50 DateTime endDate = calendarEntry.getEndPeriodFullDateTime();
51
52 List<TimesheetDocumentHeader> timesheetDocumentHeaders = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeaders(beginDate, endDate);
53 for (TimesheetDocumentHeader timesheetDocumentHeader : timesheetDocumentHeaders) {
54 if(timesheetDocumentHeader != null) {
55 String timeDocId = timesheetDocumentHeader.getDocumentId();
56 TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService().getTimesheetDocument(timeDocId);
57 if(timesheetDocument != null
58 && TkConstants.MISSEDPUNCH_APPROVAL_TIME_DOC_STATUS.contains(KEWServiceLocator.getRouteHeaderService().getDocumentStatus(timeDocId))) {
59 PrincipalHRAttributes phraRecord = HrServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(timesheetDocument.getPrincipalId(), endDate.toLocalDate());
60 if(phraRecord != null && StringUtils.isNotBlank(phraRecord.getPayCalendar()) && phraRecord.getPayCalendar().equals(calendar.getCalendarName())) {
61 List<MissedPunchDocument> missedPunchDocuments = TkServiceLocator.getMissedPunchService().getMissedPunchDocumentsByTimesheetDocumentId(timeDocId);
62 for (MissedPunchDocument missedPunchDocument : missedPunchDocuments) {
63 if(missedPunchDocument != null
64 && DocumentStatus.ENROUTE.equals(KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatus(missedPunchDocument.getDocumentNumber())) ){
65 TkServiceLocator.getMissedPunchService().approveMissedPunchDocument(missedPunchDocument);
66 }
67 }
68 }
69 }
70 }
71 }
72 }
73
74 }