1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.batch;
17
18 import java.sql.Timestamp;
19 import java.util.List;
20
21 import org.apache.log4j.Logger;
22 import org.joda.time.DateTime;
23 import org.joda.time.DateTimeZone;
24 import org.kuali.hr.time.assignment.Assignment;
25 import org.kuali.hr.time.assignment.AssignmentDescriptionKey;
26 import org.kuali.hr.time.calendar.CalendarEntries;
27 import org.kuali.hr.time.clocklog.ClockLog;
28 import org.kuali.hr.time.service.base.TkServiceLocator;
29 import org.kuali.hr.time.timesheet.TimesheetDocument;
30 import org.kuali.hr.time.util.TkConstants;
31 import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
32
33 public class PayPeriodEndBatchJobRunnable extends BatchJobEntryRunnable {
34
35 private static final Logger LOG = Logger.getLogger(PayPeriodEndBatchJobRunnable.class);
36
37 public PayPeriodEndBatchJobRunnable(BatchJobEntry entry) {
38 super(entry);
39
40 }
41
42 @Override
43 public void doWork() throws Exception {
44
45 BatchJobEntry payPeriodEndBatchEntry = TkServiceLocator.getBatchJobEntryService().getBatchJobEntry(getTkBatchJobEntryId());
46
47
48 CalendarEntries pe = TkServiceLocator.getCalendarEntriesService().getCalendarEntries(payPeriodEndBatchEntry.getHrPyCalendarEntryId());
49
50 List<ClockLog> openClockLogs = TkServiceLocator.getClockLogService().getOpenClockLogs(pe);
51
52 if (openClockLogs.size() > 0) {
53 for (ClockLog cl : openClockLogs) {
54
55
56
57 DateTime endPeriodDateTime = new DateTime(pe.getEndPeriodDateTime().getTime(), DateTimeZone.forID(cl.getClockTimestampTimezone()));
58 TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(cl.getPrincipalId(), pe.getBeginPeriodDate(), pe.getEndPeriodDate());
59 TimesheetDocument td = TkServiceLocator.getTimesheetService().getTimesheetDocument(tdh.getDocumentId());
60 String assignmentKey = new AssignmentDescriptionKey(cl.getJobNumber(), cl.getWorkArea(), cl.getTask()).toAssignmentKeyString();
61 Assignment assignment = TkServiceLocator.getAssignmentService().getAssignment(td, assignmentKey);
62
63 TkServiceLocator.getClockLogService().processClockLog(new Timestamp(endPeriodDateTime.getMillis()), assignment, pe, cl.getIpAddress(),
64 new java.sql.Date(endPeriodDateTime.getMillis()), td, TkConstants.CLOCK_OUT, cl.getPrincipalId(), TkConstants.BATCH_JOB_USER_PRINCIPAL_ID);
65
66
67 TkServiceLocator.getClockLogService().processClockLog(new Timestamp(endPeriodDateTime.getMillis()), assignment, pe, cl.getIpAddress(),
68 new java.sql.Date(endPeriodDateTime.getMillis()), td, TkConstants.CLOCK_IN, cl.getPrincipalId(), TkConstants.BATCH_JOB_USER_PRINCIPAL_ID);
69 }
70
71 }
72
73 }
74 }