public function getStartAndEndDates($employeeId) { $userEmployeeNumber = null; $timesheetService = new TimesheetService(); $timesheets = $timesheetService->getTimesheetByEmployeeId($employeeId); $dateOptions = array(); $dateOptionsToDrpDwn = array(); $userObj = sfContext::getInstance()->getUser()->getAttribute('user'); $userId = $userObj->getUserId(); $userEmployeeNumber = $userObj->getEmployeeNumber(); if ($userEmployeeNumber == $employeeId) { $user = new User(); $decoratedUser = new EssUserRoleDecorator($user); } else { $userRoleFactory = new UserRoleFactory(); $decoratedUser = $userRoleFactory->decorateUserRole($userId, $employeeId, $userEmployeeNumber); } $i = 0; if ($timesheets != null) { foreach ($timesheets as $timesheet) { $allowedActions = $decoratedUser->getAllowedActions(WorkflowStateMachine::FLOW_TIME_TIMESHEET, $timesheet->getState()); if (in_array(WorkflowStateMachine::TIMESHEET_ACTION_VIEW, $allowedActions)) { $dateOptions[$i] = $timesheet->getStartDate() . " " . __("to") . " " . $timesheet->getEndDate(); $dateOptionsToDrpDwn[$i] = set_datepicker_date_format($timesheet->getStartDate()) . " " . __("to") . " " . set_datepicker_date_format($timesheet->getEndDate()); $i++; } } } $this->dateOptions = array_reverse($dateOptions); return array_reverse($dateOptionsToDrpDwn); }
public function execute($request) { /* Decorated user object in the user session, which can be used only to get user's employee number, user id, employee list and accessible Time menus */ $this->userObj = $this->getContext()->getUser()->getAttribute('user'); $userId = $this->userObj->getUserId(); $userEmployeeNumber = $this->userObj->getEmployeeNumber(); $employeeId = $request->getParameter('employeeId'); $this->employeeName = $this->getEmployeeName($employeeId); $this->createTimesheetForm = new CreateTimesheetForm(); $this->currentDate = date('Y-m-d'); $this->headingText = $this->getTimesheetPeriodService()->getTimesheetHeading(); $this->successMessage = array($request->getParameter('message[0]'), $request->getParameter('message[1]')); $this->timeService = $this->getTimesheetService(); /* This action is called from viewTimesheetAction, when the user serches a previous timesheet, if not finds a start date from * back btn from editTimesheet. */ $selectedTimesheetStartDate = $request->getParameter('timesheetStartDateFromDropDown'); if (!isset($selectedTimesheetStartDate)) { $selectedTimesheetStartDate = $request->getParameter('timesheetStartDate'); } $this->actionName = $this->getActionName(); $this->format = $this->getTimesheetService()->getTimesheetTimeFormat(); /* Error message when there is no timesheet to view */ if ($this->getContext()->getUser()->hasFlash('errorMessage')) { $this->messageData = array('NOTICE', __($this->getContext()->getUser()->getFlash('errorMessage'))); } else { $this->dateForm = new startDaysListForm(array(), array('employeeId' => $employeeId)); $dateOptions = $this->dateForm->getDateOptions(); if ($dateOptions == null) { $this->messageData = array('NOTICE', __("No Accessible Timesheets")); } if ($this->getContext()->getUser()->hasFlash('TimesheetStartDate')) { //this is admin or supervisor accessing the viewTimesheet from by clicking the "view" button $startDate = $this->getContext()->getUser()->getFlash('TimesheetStartDate'); } elseif (!isset($selectedTimesheetStartDate)) { // admin or the supervisor enters the name of the employee and clicks on the view button $startDate = $this->getStartDate($dateOptions); } else { $startDate = $selectedTimesheetStartDate; // this sets the start day as the start date set by the search drop down or the coming back from the edit action } /* This action is checks whether the start date set. If not the current date is set. */ if (isset($startDate)) { $this->toggleDate = $startDate; } $this->timesheet = $this->getTimesheetService()->getTimesheetByStartDateAndEmployeeId($startDate, $employeeId); $this->currentState = $this->timesheet->getState(); if (isset($startDate)) { $selectedIndex = $this->dateForm->returnSelectedIndex($startDate, $employeeId); } if (isset($selectedIndex)) { $this->dateForm->setDefault('startDates', $selectedIndex); } $noOfDays = $this->timesheetService->dateDiff($this->timesheet->getStartDate(), $this->timesheet->getEndDate()); $values = array('date' => $startDate, 'employeeId' => $employeeId, 'timesheetId' => $this->timesheet->getTimesheetId(), 'noOfDays' => $noOfDays); $form = new TimesheetForm(array(), $values); $this->timesheetRows = $form->getTimesheet($startDate, $employeeId, $this->timesheet->getTimesheetId()); $this->formToImplementCsrfToken = new TimesheetFormToImplementCsrfTokens(); if ($request->isMethod('post')) { $this->formToImplementCsrfToken->bind($request->getParameter('time')); if ($this->formToImplementCsrfToken->isValid()) { $state = $request->getParameter('state'); if (isset($state)) { $this->successMessage = array('SUCCESS', __("Timesheet " . ucwords(strtolower($state)))); } $comment = $request->getParameter('Comment'); $this->timesheet->setState($state); $this->timesheet = $this->getTimesheetService()->saveTimesheet($this->timesheet); if ($request->getParameter('updateActionLog')) { if ($request->getParameter('resetAction')) { $this->setTimesheetActionLog(Timesheet::RESET_ACTION, $comment, $this->timesheet->getTimesheetId(), $userId); } else { $this->setTimesheetActionLog($state, $comment, $this->timesheet->getTimesheetId(), $userId); } $submitted = $request->getParameter('submitted'); if (isset($submitted)) { $this->successMessage = array('SUCCESS', __("Timesheet Submitted")); } } } } $this->currentState = $this->timesheet->getState(); //decorate the user according the role that he plays on the employee who timesheet is being viewed. $userRoleFactory = new UserRoleFactory(); $decoratedUser = $userRoleFactory->decorateUserRole($userId, $employeeId, $userEmployeeNumber); $this->allowedToCreateTimesheets = $decoratedUser->getAllowedActions(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, PluginTimesheet::STATE_INITIAL); $this->allowedActions = $decoratedUser->getAllowedActions(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState); $this->submitNextState = $decoratedUser->getNextState(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, PluginWorkflowStateMachine::TIMESHEET_ACTION_SUBMIT); $this->approveNextState = $decoratedUser->getNextState(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, PluginWorkflowStateMachine::TIMESHEET_ACTION_APPROVE); $this->rejectNextState = $decoratedUser->getNextState(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, PluginWorkflowStateMachine::TIMESHEET_ACTION_REJECT); $this->resetNextState = $decoratedUser->getNextState(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, PluginWorkflowStateMachine::TIMESHEET_ACTION_RESET); $this->rowDates = $form->getDatesOfTheTimesheetPeriod($this->timesheet->getStartDate(), $this->timesheet->getEndDate()); $this->actionLogRecords = $this->getTimesheetService()->getTimesheetActionLogByTimesheetId($this->timesheet->getTimesheetId()); } }
public function executeCreateTimesheetForSubourdinate($request) { $this->userObj = $this->getContext()->getUser()->getAttribute('user'); $userId = $this->userObj->getUserId(); $userEmployeeNumber = $this->userObj->getEmployeeNumber(); $this->employeeId = $request->getParameter('employeeId'); $userRoleFactory = new UserRoleFactory(); $decoratedUser = $userRoleFactory->decorateUserRole($userId, $this->employeeId, $userEmployeeNumber); $this->allowedToCreateTimesheets = $decoratedUser->getAllowedActions(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, PluginTimesheet::STATE_INITIAL); $this->createTimesheetForm = new CreateTimesheetForm(); $this->currentDate = date('Y-m-d'); if ($this->getContext()->getUser()->hasFlash('errorMessage')) { $this->messageData = array('NOTICE', __($this->getContext()->getUser()->getFlash('errorMessage'))); } }
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 executeGetRelatedAttendanceRecords($request) { $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(); $this->employeeId = $request->getParameter('employeeId'); $this->date = $request->getParameter('date'); $this->actionRecorder = $request->getParameter('actionRecorder'); if ($this->actionRecorder == "viewEmployee") { $userRoleFactory = new UserRoleFactory(); $decoratedUser = $userRoleFactory->decorateUserRole($userId, $this->employeeId, $userEmployeeNumber); } if ($this->actionRecorder == "viewMy") { $user = new User(); $decoratedUser = new EssUserRoleDecorator($user); } $this->records = $this->getAttendanceService()->getAttendanceRecord($this->employeeId, $this->date); $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_OUT_TIME, PluginWorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_IN_TIME); $actionableStates = $decoratedUser->getActionableAttendanceStates($actions); $recArray = array(); if ($this->records != null) { if ($actionableStates != null) { foreach ($actionableStates as $state) { foreach ($this->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 ($this->records as $record) { if ($state == $record->getState()) { $this->allowedActions['Delete'] = true; break; } } } } foreach ($this->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($this->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; } } }
public function execute($request) { $userObj = sfContext::getInstance()->getUser()->getAttribute('user'); $this->editPunchIn = array(); $this->editPunchOut = array(); $this->employeeId = $request->getParameter('employeeId'); $this->messageData = array($request->getParameter('message[0]'), $request->getParameter('message[1]')); $this->_checkAuthentication($this->employeeId, $userObj); $this->date = $request->getParameter('date'); $this->actionRecorder = $request->getParameter('actionRecorder'); $this->errorRows = $request->getParameter('errorRows'); $userObj = sfContext::getInstance()->getUser()->getAttribute('user'); $userId = $userObj->getUserId(); $userEmployeeNumber = $userObj->getEmployeeNumber(); $this->records = $this->getAttendanceService()->getAttendanceRecord($this->employeeId, $this->date); $totalRows = sizeOf($this->records); $values = array('employeeId' => $this->employeeId, 'date' => $this->date); $this->editAttendanceForm = new EditAttendanceRecordForm(array(), $values); $formSubmitAction = $request->getParameter('formSubmitAction'); if ($this->actionRecorder == "viewEmployee") { $userRoleFactory = new UserRoleFactory(); $decoratedUser = $userRoleFactory->decorateUserRole($userId, $this->employeeId, $userEmployeeNumber); } if ($this->actionRecorder == "viewMy") { $user = new User(); $decoratedUser = new EssUserRoleDecorator($user); } $i = 1; foreach ($this->records as $record) { $allowedActionsForCurrentRecord = $decoratedUser->getAllowedActions(WorkflowStateMachine::FLOW_ATTENDANCE, $record->getState()); if (in_array(WorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_IN_TIME, $allowedActionsForCurrentRecord)) { $this->editPunchIn[$i] = true; } else { $this->editPunchIn[$i] = false; } if (in_array(WorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_OUT_TIME, $allowedActionsForCurrentRecord)) { $this->editPunchOut[$i] = true; } else { $this->editPunchOut[$i] = false; } $i++; } if ($formSubmitAction) { if ($request->isMethod('post')) { $this->editAttendanceForm->bind($request->getParameter('attendance')); if ($this->editAttendanceForm->isValid()) { $errorArray = $this->editAttendanceForm->save($totalRows, $this->editAttendanceForm); if (!empty($errorArray)) { $errorStr = json_encode($errorArray); $this->redirect('attendance/editAttendanceRecord?employeeId=' . $this->employeeId . '&date=' . $this->date . '&actionRecorder=' . $this->actionRecorder . '&errorRows=' . $errorStr); } else { $messageData = array('SUCCESS', __(TopLevelMessages::SAVE_SUCCESS)); if ($this->actionRecorder == "viewMy") { $this->redirect('attendance/viewMyAttendanceRecord' . '?' . http_build_query(array('message' => $messageData, 'actionRecorder' => $this->actionRecorder, 'employeeId' => $this->employeeId, 'date' => $this->date, 'trigger' => true))); } if ($this->actionRecorder == "viewEmployee") { $this->redirect('attendance/viewAttendanceRecord' . '?' . http_build_query(array('message' => $messageData, 'actionRecorder' => $this->actionRecorder, 'employeeId' => $this->employeeId, 'date' => $this->date, 'trigger' => true))); } } } } } }