/** * save punchRecord * @param AttendanceRecord $attendanceRecord * @return AttendanceRecord */ public function savePunchRecord(AttendanceRecord $attendanceRecord) { try { if ($attendanceRecord->getId() == '') { $idGenService = new IDGeneratorService(); $idGenService->setEntity($attendanceRecord); $attendanceRecord->setId($idGenService->getNextID()); } $attendanceRecord->save(); return $attendanceRecord; } catch (Exception $ex) { throw new DaoException($ex->getMessage()); } }
/** * @group orangehrmAttendancePlugin */ public function testSaveNewPunchRecord() { $punchRecord = new AttendanceRecord(); $punchRecord->setState("PUNCHED IN"); $punchRecord->setEmployeeId(2); $punchRecord->setPunchInUserTime('2011-05-27 12:10:00'); $punchRecord->setPunchInTimeOffset('Asia/Calcutta'); $punchRecord->setPunchInUtcTime('2011-05-27 5:10:23'); $savedRecord = $this->attendanceDao->SavePunchRecord($punchRecord); $this->assertNotNull($savedRecord->getId()); $this->assertEquals($savedRecord->getState(), "PUNCHED IN"); $this->assertEquals($savedRecord->getPunchInUserTime(), '2011-05-27 12:10:00'); $this->assertEquals($savedRecord->getPunchInTimeOffset(), 'Asia/Calcutta'); }
public function parseReportData($postArr) { $parsedObjs = array(); for ($i = 0; $i < $postArr['recordsCount']; $i++) { $attendanceRecordObj = new AttendanceRecord(); $changed = false; if (trim($postArr['txtNewInDate-' . $i]) != $postArr['hdnOldInDate-' . $i]) { $changed = true; } elseif (trim($postArr['txtNewInTime-' . $i]) != $postArr['hdnOldInTime-' . $i]) { $changed = true; } elseif (trim($postArr['txtNewInNote-' . $i]) != $postArr['hdnOldInNote-' . $i]) { $changed = true; } elseif (trim($postArr['txtNewOutDate-' . $i]) != $postArr['hdnOldOutDate-' . $i]) { $changed = true; } elseif (trim($postArr['txtNewOutTime-' . $i]) != $postArr['hdnOldOutTime-' . $i]) { $changed = true; } elseif (trim($postArr['txtNewOutNote-' . $i]) != $postArr['hdnOldOutNote-' . $i]) { $changed = true; } elseif (isset($postArr['chkDeleteStatus-' . $i])) { $attendanceRecordObj->setStatus(AttendanceRecord::STATUS_DELETED); $changed = true; } if ($changed) { /* Even if only one value is changed, setting other properties * is required to carry out functions like checking overlapping */ $attendanceRecordObj->setAttendanceId($postArr['hdnAttendanceId-' . $i]); $attendanceRecordObj->setEmployeeId($postArr['hdnEmployeeId']); $value = trim($postArr['txtNewInDate-' . $i]) . ' ' . trim($postArr['txtNewInTime-' . $i]); $attendanceRecordObj->setInDate($this->_adjustToServerTime('date', $postArr['hdnTimestampDiff-' . $i], $value)); $attendanceRecordObj->setInTime($this->_adjustToServerTime('time', $postArr['hdnTimestampDiff-' . $i], $value)); $attendanceRecordObj->setInNote(trim($postArr['txtNewInNote-' . $i])); $value = trim($postArr['txtNewOutDate-' . $i]) . ' ' . trim($postArr['txtNewOutTime-' . $i]); $attendanceRecordObj->setOutDate($this->_adjustToServerTime('date', $postArr['hdnTimestampDiff-' . $i], $value)); $attendanceRecordObj->setOutTime($this->_adjustToServerTime('time', $postArr['hdnTimestampDiff-' . $i], $value)); $attendanceRecordObj->setOutNote(trim($postArr['txtNewOutNote-' . $i])); $parsedObjs[] = $attendanceRecordObj; } } return $parsedObjs; }
public function executeProxyPunchInPunchOut($request) { /* For highlighting corresponding menu item */ $request->setParameter('initialActionName', 'viewAttendanceRecord'); $this->punchInTime = null; $this->punchInUtcTime = null; $this->punchInNote = null; $this->action = array(); $this->action['PunchIn'] = false; $this->action['PunchOut'] = false; $this->employeeId = $request->getParameter('employeeId'); $this->date = $request->getParameter('date'); $this->actionRecorder = $request->getParameter('actionRecorder'); $userRoleManager = $this->getContext()->getUserRoleManager(); $this->attendancePermissions = $this->getDataGroupPermissions('attendance_records'); $timeZoneOffset = $this->getUser()->getUserTimeZoneOffset(); $timeStampDiff = $timeZoneOffset * 3600 - date('Z'); $this->currentDate = date('Y-m-d', time() + $timeStampDiff); $this->currentTime = date('H:i', time() + $timeStampDiff); $this->timezone = $timeZoneOffset * 3600; $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_IN, PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_OUT); $actionableStates = $userRoleManager->getActionableStates(WorkflowStateMachine::FLOW_ATTENDANCE, $actions, array(), array(), array('Employee' => $this->employeeId)); $attendanceRecord = $this->getAttendanceService()->getLastPunchRecord($this->employeeId, $actionableStates); if (is_null($attendanceRecord)) { $this->action['PunchIn'] = true; } else { $this->action['PunchOut'] = true; } $param = array('timezone' => $timeZoneOffset, 'date' => $this->date); $this->form = new ProxyPunchInPunchOutForm(array(), $param, true); if ($this->action['PunchIn']) { $allowedWorkflowItems = $userRoleManager->getAllowedActions(PluginWorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_INITIAL, array(), array(), array('Employee' => $this->employeeId)); $this->allowedActions = array_keys($allowedWorkflowItems); if (!in_array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_IN, $this->allowedActions)) { $this->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action')); } else { if ($request->getParameter('path')) { if ($request->isMethod('post')) { $attendanceRecord = new AttendanceRecord(); $attendanceRecord->setEmployeeId($this->employeeId); $this->form->bind($request->getParameter('attendance')); if ($this->form->isValid()) { $punchInDate = $this->form->getValue('date'); $punchIntime = $this->form->getValue('time'); $punchInNote = $this->form->getValue('note'); $timeValue = $this->form->getValue('timezone'); $employeeTimezone = $this->getAttendanceService()->getTimezone($timeValue); if ($employeeTimezone == 'GMT') { $employeeTimezone = 0; } $punchInEditModeTime = mktime(date('H', strtotime($punchIntime)), date('i', strtotime($punchIntime)), 0, date('m', strtotime($punchInDate)), date('d', strtotime($punchInDate)), date('Y', strtotime($punchInDate))); $proxyPunchInWorkflowItem = $allowedWorkflowItems[WorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_IN]; $nextState = $proxyPunchInWorkflowItem->getResultingState(); $attendanceRecord->setState($nextState); $attendanceRecord->setPunchInUtcTime(date('Y-m-d H:i', $punchInEditModeTime - $employeeTimezone * 3600)); $attendanceRecord->setPunchInNote($punchInNote); $attendanceRecord->setPunchInUserTime(date('Y-m-d H:i', $punchInEditModeTime)); $attendanceRecord->setPunchInTimeOffset($employeeTimezone); $this->getAttendanceService()->savePunchRecord($attendanceRecord); $this->redirect("attendance/viewAttendanceRecord?employeeId=" . $this->employeeId . "&date=" . $this->date . "&trigger=" . true . "&actionRecorder=" . $this->actionRecorder); } } } } } if ($this->action['PunchOut']) { $allowedWorkflowItems = $userRoleManager->getAllowedActions(PluginWorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_PUNCHED_IN, array(), array(), array('Employee' => $this->employeeId)); $this->allowedActions = array_keys($allowedWorkflowItems); $tempPunchInTime = $attendanceRecord->getPunchInUserTime(); $this->punchInTime = date('Y-m-d H:i', strtotime($tempPunchInTime)); $this->punchInUtcTime = date('Y-m-d H:i', strtotime($attendanceRecord->getPunchInUtcTime())); $this->punchInNote = $attendanceRecord->getPunchInNote(); if (!in_array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_OUT, $this->allowedActions)) { $this->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action')); } else { if ($request->getParameter('path')) { if ($request->isMethod('post')) { $this->form->bind($request->getParameter('attendance')); if ($this->form->isValid()) { $punchOutTime = $this->form->getValue('time'); $punchOutNote = $this->form->getValue('note'); $punchOutDate = $this->form->getValue('date'); $timeValue = $this->form->getValue('timezone'); $employeeTimezone = $this->getAttendanceService()->getTimezone($timeValue); if ($employeeTimezone == 'GMT') { $employeeTimezone = 0; } $punchOutEditModeTime = mktime(date('H', strtotime($punchOutTime)), date('i', strtotime($punchOutTime)), 0, date('m', strtotime($punchOutDate)), date('d', strtotime($punchOutDate)), date('Y', strtotime($punchOutDate))); $proxyPunchOutWorkflowItem = $allowedWorkflowItems[WorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_OUT]; $nextState = $proxyPunchOutWorkflowItem->getResultingState(); $attendanceRecord->setState($nextState); $attendanceRecord->setPunchOutUtcTime(date('Y-m-d H:i', $punchOutEditModeTime - $employeeTimezone * 3600)); $attendanceRecord->setPunchOutNote($punchOutNote); $attendanceRecord->setPunchOutUserTime(date('Y-m-d H:i', $punchOutEditModeTime)); $attendanceRecord->setPunchOutTimeOffset($employeeTimezone); $this->getAttendanceService()->savePunchRecord($attendanceRecord); $this->getUser()->setFlash('templateMessage', array('success', __(TopLevelMessages::SAVE_SUCCESS))); $this->redirect("attendance/viewAttendanceRecord?employeeId=" . $this->employeeId . "&date=" . $this->date . "&trigger=" . true); } } } } } }
public function execute($request) { $this->userObj = $this->getContext()->getUser()->getAttribute('user'); $accessibleMenus = $this->userObj->getAccessibleAttendanceSubMenus(); $hasRight = false; $this->parmetersForListCompoment = array(); $this->showEdit = false; foreach ($accessibleMenus as $menu) { if ($menu->getDisplayName() === __("Employee Records")) { $hasRight = true; break; } } if (!$hasRight) { return $this->renderText(__("You are not allowed to view this page") . "!"); } $this->trigger = $request->getParameter('trigger'); if ($this->trigger) { $this->showEdit = true; } $this->date = $request->getParameter('date'); $this->employeeId = $request->getParameter('employeeId'); $this->employeeService = $this->getEmployeeService(); $values = array('date' => $this->date, 'employeeId' => $this->employeeId, 'trigger' => $this->trigger); $this->form = new AttendanceRecordSearchForm(array(), $values); $this->actionRecorder = "viewEmployee"; $isPaging = $request->getParameter('pageNo'); $pageNumber = $isPaging; $noOfRecords = $noOfRecords = sfConfig::get('app_items_per_page'); $offset = $pageNumber >= 1 ? ($pageNumber - 1) * $noOfRecords : ($request->getParameter('pageNo', 1) - 1) * $noOfRecords; $records = array(); $this->_setListComponent($records, $noOfRecords, $pageNumber, null, $this->showEdit); if (!$this->trigger) { if ($request->isMethod('post')) { $this->form->bind($request->getParameter('attendance')); if ($this->form->isValid()) { $this->allowedToDelete = array(); $this->allowedActions = array(); $this->allowedActions['Delete'] = false; $this->allowedActions['Edit'] = false; $this->allowedActions['PunchIn'] = false; $this->allowedActions['PunchOut'] = false; $this->userObj = $this->getContext()->getUser()->getAttribute('user'); $userId = $this->userObj->getUserId(); $userEmployeeNumber = $this->userObj->getEmployeeNumber(); $post = $this->form->getValues(); if (!$this->employeeId) { $empData = $post['employeeName']; $this->employeeId = $empData['empId']; } if (!$this->date) { $this->date = $post['date']; } if ($this->employeeId) { $this->showEdit = true; } $userRoleFactory = new UserRoleFactory(); $this->decoratedUser = $decoratedUser = $userRoleFactory->decorateUserRole($userId, $this->employeeId, $userEmployeeNumber); $isPaging = $request->getParameter('hdnAction') == 'search' ? 1 : $request->getParameter('pageNo', 1); $pageNumber = $isPaging; $noOfRecords = sfConfig::get('app_items_per_page'); $offset = $pageNumber >= 1 ? ($pageNumber - 1) * $noOfRecords : ($request->getParameter('pageNo', 1) - 1) * $noOfRecords; $empRecords = array(); if (!$this->employeeId) { // $empRecords = $this->employeeService->getEmployeeList('firstName', 'ASC', false); $empRecords = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntities('Employee'); $count = count($empRecords); } else { $empRecords = $this->employeeService->getEmployee($this->employeeId); $empRecords = array($empRecords); $count = 1; } $records = array(); foreach ($empRecords as $employee) { $hasRecords = false; $attendanceRecords = $employee->getAttendanceRecord(); $total = 0; foreach ($attendanceRecords as $attendance) { $from = $this->date . " " . "00:" . "00:" . "00"; $end = $this->date . " " . "23:" . "59:" . "59"; if (strtotime($attendance->getPunchInUserTime()) >= strtotime($from) && strtotime($attendance->getPunchInUserTime()) <= strtotime($end)) { if ($attendance->getPunchOutUtcTime()) { $total = $total + round((strtotime($attendance->getPunchOutUtcTime()) - strtotime($attendance->getPunchInUtcTime())) / 3600, 2); } $records[] = $attendance; $hasRecords = true; } } if ($hasRecords) { $last = end($records); $last->setTotal($total); } else { $attendance = new AttendanceRecord(); $attendance->setEmployee($employee); $attendance->setTotal('---'); $records[] = $attendance; } } $params = array(); $this->parmetersForListCompoment = $params; $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_OUT_TIME, PluginWorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_IN_TIME); $actionableStates = $decoratedUser->getActionableAttendanceStates($actions); $recArray = array(); if ($records != null) { if ($actionableStates != null) { foreach ($actionableStates as $state) { foreach ($records as $record) { if ($state == $record->getState()) { $this->allowedActions['Edit'] = true; break; } } } } $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_DELETE); $actionableStates = $decoratedUser->getActionableAttendanceStates($actions); if ($actionableStates != null) { foreach ($actionableStates as $state) { foreach ($records as $record) { if ($state == $record->getState()) { $this->allowedActions['Delete'] = true; break; } } } } foreach ($records as $record) { $this->allowedToDelete[] = $this->allowedToPerformAction(WorkflowStateMachine::FLOW_ATTENDANCE, PluginWorkflowStateMachine::ATTENDANCE_ACTION_DELETE, $record->getState(), $decoratedUser); $recArray[] = $record; } } else { $attendanceRecord = null; } $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_IN, PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_OUT); $allowedActionsList = array(); $actionableStates = $decoratedUser->getActionableAttendanceStates($actions); if ($actionableStates != null) { if (!empty($recArray)) { $lastRecordPunchOutTime = $recArray[count($records) - 1]->getPunchOutUserTime(); if (empty($lastRecordPunchOutTime)) { $attendanceRecord = ""; } else { $attendanceRecord = null; } } foreach ($actionableStates as $actionableState) { $allowedActionsArray = $decoratedUser->getAllowedActions(PluginWorkflowStateMachine::FLOW_ATTENDANCE, $actionableState); if (!is_null($allowedActionsArray)) { $allowedActionsList = array_unique(array_merge($allowedActionsArray, $allowedActionsList)); } } if (is_null($attendanceRecord) && in_array(WorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_IN, $allowedActionsList)) { $this->allowedActions['PunchIn'] = true; } if (!is_null($attendanceRecord) && in_array(WorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_OUT, $allowedActionsList)) { $this->allowedActions['PunchOut'] = true; } } if ($this->employeeId == '') { $this->showEdit = FALSE; } $this->_setListComponent($records, $noOfRecords, $pageNumber, $count, $this->showEdit, $this->allowedActions); } } } }
public function execute($request) { $this->_checkAuthentication(); $this->editmode = null; $this->userObj = $this->getContext()->getUser()->getAttribute('user'); $this->employeeId = $this->userObj->getEmployeeNumber(); $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_PUNCH_OUT); $actionableStatesList = $this->userObj->getActionableAttendanceStates($actions); $timeZoneOffset = $this->userObj->getUserTimeZoneOffset(); $timeStampDiff = $timeZoneOffset * 3600 - date('Z'); $this->currentDate = date('Y-m-d', time() + $timeStampDiff); $this->currentTime = date('H:i', time() + $timeStampDiff); $this->timezone = $timeZoneOffset * 3600; $localizationService = new LocalizationService(); $inputDatePattern = sfContext::getInstance()->getUser()->getDateFormat(); if ($this->getUser()->hasFlash('templateMessage')) { list($messageType, $message) = $this->getUser()->getFlash('templateMessage'); $this->getUser()->setFlash($messageType, $message); } $attendanceRecord = $this->getAttendanceService()->getLastPunchRecord($this->employeeId, $actionableStatesList); if (is_null($attendanceRecord)) { $this->allowedActions = $this->userObj->getAllowedActions(WorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_INITIAL); } else { $this->redirect("attendance/punchOut"); } $this->punchInTime = null; $this->punchInUtcTime = null; $this->punchInNote = null; $this->actionPunchOut = null; $this->form = new AttendanceForm(); $this->actionPunchIn = $this->getActionName(); $this->attendanceFormToImplementCsrfToken = new AttendanceFormToImplementCsrfToken(); if ($request->isMethod('post')) { $accessFlowStateMachineService = new AccessFlowStateMachineService(); $attendanceRecord = new AttendanceRecord(); $attendanceRecord->setEmployeeId($this->employeeId); if (!in_array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_TIME, $this->allowedActions)) { $this->attendanceFormToImplementCsrfToken->bind($request->getParameter('attendance')); if ($this->attendanceFormToImplementCsrfToken->isValid()) { $punchInDate = $localizationService->convertPHPFormatDateToISOFormatDate($inputDatePattern, $this->request->getParameter('date')); $punchIntime = $this->request->getParameter('time'); $punchInNote = $this->request->getParameter('note'); $timeZoneOffset = $this->request->getParameter('timeZone'); $nextState = $this->userObj->getNextState(WorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_INITIAL, WorkflowStateMachine::ATTENDANCE_ACTION_PUNCH_IN); $punchIndateTime = strtotime($punchInDate . " " . $punchIntime); $attendanceRecord = $this->setAttendanceRecord($attendanceRecord, $nextState, date('Y-m-d H:i', $punchIndateTime - $timeZoneOffset), date('Y-m-d H:i', $punchIndateTime), $timeZoneOffset / 3600, $punchInNote); $this->redirect("attendance/punchOut"); } } else { $this->form->bind($request->getParameter('attendance')); if ($this->form->isValid()) { $punchInDate = $this->form->getValue('date'); $punchIntime = $this->form->getValue('time'); $punchInNote = $this->form->getValue('note'); $timeZoneOffset = $this->request->getParameter('timeZone'); $punchInEditModeTime = mktime(date('H', strtotime($punchIntime)), date('i', strtotime($punchIntime)), 0, date('m', strtotime($punchInDate)), date('d', strtotime($punchInDate)), date('Y', strtotime($punchInDate))); $nextState = $this->userObj->getNextState(WorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_INITIAL, WorkflowStateMachine::ATTENDANCE_ACTION_PUNCH_IN); $attendanceRecord = $this->setAttendanceRecord($attendanceRecord, $nextState, date('Y-m-d H:i', $punchInEditModeTime - $timeZoneOffset), date('Y-m-d H:i', $punchInEditModeTime), $timeZoneOffset / 3600, $punchInNote); $this->redirect("attendance/punchOut"); } } } $this->setTemplate("punchTime"); }
public function executeProxyPunchInPunchOut($request) { $this->punchInTime = null; $this->punchInUtcTime = null; $this->punchInNote = null; $this->action = array(); $this->action['PunchIn'] = false; $this->action['PunchOut'] = false; $this->employeeId = $request->getParameter('employeeId'); $this->date = $request->getParameter('date'); $this->actionRecorder = $request->getParameter('actionRecorder'); $this->userObj = $this->getContext()->getUser()->getAttribute('user'); $timeZoneOffset = $this->userObj->getUserTimeZoneOffset(); $timeStampDiff = $timeZoneOffset * 3600 - date('Z'); $this->currentDate = date('Y-m-d', time() + $timeStampDiff); $this->currentTime = date('H:i', time() + $timeStampDiff); $this->timezone = $timeZoneOffset * 3600; $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_IN, PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_OUT); $actionableStates = $this->userObj->getActionableAttendanceStates($actions); $attendanceRecord = $this->getAttendanceService()->getLastPunchRecord($this->employeeId, $actionableStates); if (is_null($attendanceRecord)) { $this->action['PunchIn'] = true; } else { $this->action['PunchOut'] = true; } $param = array('timezone' => $timeZoneOffset, 'date' => $this->date); $this->form = new ProxyPunchInPunchOutForm(array(), $param, true); if ($this->action['PunchIn']) { $this->allowedActions = $this->userObj->getAllowedActions(WorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_INITIAL); if ($request->getParameter('path')) { if ($request->isMethod('post')) { $accessFlowStateMachineService = new AccessFlowStateMachineService(); $attendanceRecord = new AttendanceRecord(); $attendanceRecord->setEmployeeId($this->employeeId); $this->form->bind($request->getParameter('attendance')); if ($this->form->isValid()) { $punchInDate = $this->form->getValue('date'); $punchIntime = $this->form->getValue('time'); $punchInNote = $this->form->getValue('note'); $timeValue = $this->form->getValue('timezone'); $employeeTimezone = $this->getAttendanceService()->getTimezone($timeValue); if ($employeeTimezone == 'GMT') { $employeeTimezone = 0; } $punchInEditModeTime = mktime(date('H', strtotime($punchIntime)), date('i', strtotime($punchIntime)), 0, date('m', strtotime($punchInDate)), date('d', strtotime($punchInDate)), date('Y', strtotime($punchInDate))); $nextState = $this->userObj->getNextState(WorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_INITIAL, WorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_IN); $attendanceRecord->setState($nextState); $attendanceRecord->setPunchInUtcTime(date('Y-m-d H:i', $punchInEditModeTime - $employeeTimezone * 3600)); $attendanceRecord->setPunchInNote($punchInNote); $attendanceRecord->setPunchInUserTime(date('Y-m-d H:i', $punchInEditModeTime)); $attendanceRecord->setPunchInTimeOffset($employeeTimezone); $this->getAttendanceService()->savePunchRecord($attendanceRecord); $this->redirect("attendance/viewAttendanceRecord?employeeId=" . $this->employeeId . "&date=" . $this->date . "&trigger=" . true . "&actionRecorder=" . $this->actionRecorder); } } } } if ($this->action['PunchOut']) { $this->allowedActions = $this->userObj->getAllowedActions(WorkflowStateMachine::FLOW_ATTENDANCE, AttendanceRecord::STATE_PUNCHED_IN); $tempPunchInTime = $attendanceRecord->getPunchInUserTime(); $this->punchInTime = date('Y-m-d H:i', strtotime($tempPunchInTime)); $this->punchInUtcTime = date('Y-m-d H:i', strtotime($attendanceRecord->getPunchInUtcTime())); $this->punchInNote = $attendanceRecord->getPunchInNote(); if ($request->getParameter('path')) { if ($request->isMethod('post')) { $this->form->bind($request->getParameter('attendance')); if ($this->form->isValid()) { $punchOutTime = $this->form->getValue('time'); $punchOutNote = $this->form->getValue('note'); $punchOutDate = $this->form->getValue('date'); $timeValue = $this->form->getValue('timezone'); $employeeTimezone = $this->getAttendanceService()->getTimezone($timeValue); if ($employeeTimezone == 'GMT') { $employeeTimezone = 0; } $punchOutEditModeTime = mktime(date('H', strtotime($punchOutTime)), date('i', strtotime($punchOutTime)), 0, date('m', strtotime($punchOutDate)), date('d', strtotime($punchOutDate)), date('Y', strtotime($punchOutDate))); $nextState = $this->userObj->getNextState(PluginWorkflowStateMachine::FLOW_ATTENDANCE, PluginAttendanceRecord::STATE_PUNCHED_IN, PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_OUT); $attendanceRecord->setState($nextState); $attendanceRecord->setPunchOutUtcTime(date('Y-m-d H:i', $punchOutEditModeTime - $employeeTimezone * 3600)); $attendanceRecord->setPunchOutNote($punchOutNote); $attendanceRecord->setPunchOutUserTime(date('Y-m-d H:i', $punchOutEditModeTime)); $attendanceRecord->setPunchOutTimeOffset($employeeTimezone); $this->getAttendanceService()->savePunchRecord($attendanceRecord); $this->getUser()->setFlash('templateMessage', array('success', __(TopLevelMessages::SAVE_SUCCESS))); $this->redirect("attendance/viewAttendanceRecord?employeeId=" . $this->employeeId . "&date=" . $this->date . "&trigger=" . true); } } } } }
public function generateAttendanceReport($empId, $from, $to, $messageType = null, $message = null) { $reportType = $_POST['hdnReportType']; $records['fromDate'] = $_POST['txtFromDate']; $records['toDate'] = $_POST['txtToDate']; $records['reportType'] = $reportType; $records['reportView'] = $_POST['optReportView']; $records['messageType'] = $messageType; $records['message'] = $message; $records['empId'] = $empId; $records['empName'] = $_POST['hdnEmpName']; $records['noReports'] = false; $records['userTimeZoneOffset'] = $_SESSION['userTimeZoneOffset']; $records['serverTimeZoneOffset'] = round(date('Z') / 3600, 1); /* Setting 'Back' button to summary view */ if (isset($_POST['hdnFromSummary'])) { $records['hdnFromSummary'] = true; $records['orgFromDate'] = $_POST['orgFromDate']; $records['orgToDate'] = $_POST['orgToDate']; } /* Setting Edit Mode */ if ($this->authorizeObj->isAdmin()) { $records['editMode'] = true; } elseif ($reportType == 'Emp' && $this->authorizeObj->isSupervisor() && Config::getAttendanceSupEditSubmitted()) { $records['editMode'] = true; } elseif ($reportType == 'My' && Config::getAttendanceEmpEditSubmitted()) { $records['editMode'] = true; } else { $records['editMode'] = false; } /* Setting employee list for Auto-Complete */ if ($reportType == 'Emp' && $this->authorizeObj->isAdmin()) { $records['empList'] = EmpInfo::getEmployeeMainDetails(); } elseif ($reportType == 'Emp' && $this->authorizeObj->isSupervisor()) { $records['empList'] = $this->_getSubsForAutoComplete($_SESSION['empID']); } /* Setting AttendanceRecord array */ $attendanceObj = new AttendanceRecord(); if (isset($_POST['pageNo']) && $_POST['hdnFromPaging'] == 'Yes') { // If it's from Generate button, it should always display page 1. $pageNo = $_POST['pageNo']; } else { $pageNo = 1; } $limit = $pageNo * 50 - 50 . ', 50'; $records['recordsArr'] = $attendanceObj->fetchRecords($empId, $from, $to, AttendanceRecord::STATUS_ACTIVE, AttendanceRecord::DB_FIELD_PUNCHIN_TIME, 'ASC', $limit); if (empty($records['recordsArr'])) { $records['noReports'] = true; } $records['recordsCount'] = $attendanceObj->countRecords($empId, $from, $to, AttendanceRecord::STATUS_ACTIVE); $records['pageNo'] = $pageNo; $path = '/templates/time/attendanceReport.php'; $template = new TemplateMerger($records, $path); $template->display(); }
private function _buildRecordObjects($result, $adjustTime = true) { while ($row = mysql_fetch_array($result)) { $attendanceObj = new AttendanceRecord(); $attendanceObj->setAttendanceId($row['attendance_id']); $attendanceObj->setEmployeeId($row['employee_id']); /* $row['punchin_time'] comes in '0000-00-00 00:00:00' format. * We want date in '0000-00-00' format and time in '00:00' format. */ $tmpArr = explode(' ', $row['punchin_time']); $attendanceObj->setInDate($tmpArr[0]); $attendanceObj->setInTime(substr($tmpArr[1], 0, 5)); if ($row['punchout_time'] != null) { $tmpArr = explode(' ', $row['punchout_time']); $attendanceObj->setOutDate($tmpArr[0]); $attendanceObj->setOutTime(substr($tmpArr[1], 0, 5)); // Omiting 'seconds' part is ok since it is always zero } if ($row['in_note'] != null) { $attendanceObj->setInNote($row['in_note']); } if ($row['out_note'] != null) { $attendanceObj->setOutNote($row['out_note']); } $attendanceObj->setTimestampDiff($row['timestamp_diff']); $attendanceObj->setStatus($row['status']); /* Adjusting time according to the timezone of the place * where the record was first entered. */ if ($adjustTime) { /* When saving in the database, timestampDiff is calculated by substracting * server timezone offset from client timezone offset. When showing records * to user this timestampDiff should be added to each date and time shown. */ $value = $attendanceObj->getInDate() . ' ' . $attendanceObj->getInTime(); $date = date('Y-m-d', strtotime($value) + $row['timestamp_diff']); $time = date('H:i', strtotime($value) + $row['timestamp_diff']); $attendanceObj->setInDate($date); $attendanceObj->setInTime($time); if ($row['punchout_time'] != null) { $value = $attendanceObj->getOutDate() . ' ' . $attendanceObj->getOutTime(); $date = date('Y-m-d', strtotime($value) + $row['timestamp_diff']); $time = date('H:i', strtotime($value) + $row['timestamp_diff']); $attendanceObj->setOutDate($date); $attendanceObj->setOutTime($time); } } $attendanceArr[] = $attendanceObj; } return $attendanceArr; }