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