/** * @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 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->_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 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; }
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; }