示例#1
0
 public function executeAddRow($request)
 {
     $this->backAction = $this->getContext()->getUser()->getFlash('actionName');
     $this->getContext()->getUser()->setFlash('actionName', $this->backAction);
     $startDate = $request->getParameter("startDate");
     $endDate = $request->getParameter("endDate");
     $employeeId = $request->getParameter("employeeId");
     $timesheetId = $request->getParameter("timesheetId");
     $noOfDays = $this->getTimesheetService()->dateDiff($startDate, $endDate);
     $values = array('date' => $startDate, 'employeeId' => $employeeId, 'timesheetId' => $timesheetId, 'noOfDays' => $noOfDays);
     $form = new TimesheetForm(array(), $values);
     $form->addRow($request->getParameter("num"), $values);
     return $this->renderPartial('addRow', array('form' => $form, 'num' => $request->getParameter("num"), 'noOfDays' => $noOfDays));
 }
 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 execute($request)
 {
     /* For highlighting corresponding menu item */
     $request->setParameter('initialActionName', 'viewEmployeeTimesheet');
     $employeeId = $request->getParameter('employeeId');
     $loggedInEmpNumber = $this->getUser()->getEmployeeNumber();
     $this->timesheetPermissions = $this->getDataGroupPermissions('time_employee_timesheets', $employeeId);
     $this->_checkAuthentication($employeeId);
     $userRoleManager = $this->getContext()->getUserRoleManager();
     $user = $userRoleManager->getUser();
     $userId = $user->getId();
     $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('warning', __($this->getContext()->getUser()->getFlash('errorMessage')));
     } else {
         $this->dateForm = new startDaysListForm(array(), array('employeeId' => $employeeId));
         $dateOptions = $this->dateForm->getDateOptions();
         if ($dateOptions == null) {
             $this->messageData = array('warning', __("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()) {
                 $action = $request->getParameter('act');
                 // check if action allowed and get next state
                 $excludeRoles = array();
                 $includeRoles = array();
                 if ($loggedInEmpNumber == $employeeId && $userRoleManager->essRightsToOwnWorkflow()) {
                     $includeRoles = array('ESS');
                 }
                 $entities = array('Employee' => $employeeId);
                 $allowedActions = $userRoleManager->getAllowedActions(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, $excludeRoles, $includeRoles, $entities);
                 if (isset($allowedActions[$action])) {
                     $state = $allowedActions[$action]->getResultingState();
                     $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 ($action == WorkflowStateMachine::TIMESHEET_ACTION_RESET) {
                             $this->setTimesheetActionLog(Timesheet::RESET_ACTION, $comment, $this->timesheet->getTimesheetId(), $userId);
                         } else {
                             $this->setTimesheetActionLog($state, $comment, $this->timesheet->getTimesheetId(), $userId);
                         }
                         if ($action == WorkflowStateMachine::TIMESHEET_ACTION_SUBMIT) {
                             $this->successMessage = array('success', __("Timesheet Submitted"));
                         }
                     }
                 }
             }
         }
         $this->currentState = $this->timesheet->getState();
         $excludeRoles = array();
         $includeRoles = array();
         if ($loggedInEmpNumber == $employeeId && $userRoleManager->essRightsToOwnWorkflow()) {
             $includeRoles = array('ESS');
         }
         $entities = array('Employee' => $employeeId);
         $initialStateActions = $userRoleManager->getAllowedActions(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, PluginTimesheet::STATE_INITIAL, $excludeRoles, $includeRoles, $entities);
         $this->allowedToCreateTimesheets = isset($initialStateActions[WorkflowStateMachine::TIMESHEET_ACTION_CREATE]);
         $this->allowedActions = $userRoleManager->getAllowedActions(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, $excludeRoles, $includeRoles, $entities);
         $this->rowDates = $form->getDatesOfTheTimesheetPeriod($this->timesheet->getStartDate(), $this->timesheet->getEndDate());
         $this->actionLogRecords = $this->getTimesheetService()->getTimesheetActionLogByTimesheetId($this->timesheet->getTimesheetId());
     }
 }
 public function execute($request)
 {
     //timesheetStartDateFromDropDown is from the drop down
     //timesheetStartDate is from the edit timesheet
     //$startDateSelectedFromDropDown set when the user is accessing the view from the search drop down
     //$startDateOfTheTimesheetForUpdates is set when the user performs an action on the timesheet,and it is used to update the timesheet
     $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]'));
     $startDateSelectedFromDropDown = $request->getParameter('timesheetStartDateFromDropDown');
     $this->userObj = $this->getContext()->getUser()->getAttribute('user');
     $userId = $this->userObj->getUserId();
     $this->format = $this->getTimesheetService()->getTimesheetTimeFormat();
     $this->timeService = $this->getTimesheetService();
     $clientTimeZoneOffset = $this->userObj->getUserTimeZoneOffset();
     $serverTimezoneOffset = (int) date('Z');
     $timeStampDiff = $clientTimeZoneOffset * 3600 - $serverTimezoneOffset;
     if ($request->isMethod('post')) {
         if ($request->getParameter('updateActionLog')) {
             $timesheet = $this->setTimesheetState($request);
             $comment = $request->getParameter('Comment');
             if ($request->getParameter('resetAction')) {
                 $this->setTimesheetActionLog(Timesheet::RESET_ACTION, $comment, $timesheet->getTimesheetId(), $userId);
             } else {
                 $this->setTimesheetActionLog($timesheet->getState(), $comment, $timesheet->getTimesheetId(), $userId);
             }
         }
     }
     /* 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 */
     $employeeId = $this->userObj->getEmployeeNumber();
     $this->currentDate = date('Y-m-d');
     $this->actionName = $this->getActionName();
     $submitted = $request->getParameter('submitted');
     if (isset($submitted)) {
         $this->successMessage = array('SUCCESS', __("Timesheet Submitted"));
     }
     $startDateOfTheTimesheetForUpdates = $request->getParameter('timesheetStartDate');
     $this->dateForm = new startDaysListForm(array(), array('employeeId' => $employeeId));
     $dateOptions = $this->dateForm->getDateOptions();
     if (isset($startDateSelectedFromDropDown)) {
         // timesheet is access via the search drop down
         $this->toggleDate = $startDateSelectedFromDropDown;
         $timesheetStartingDate = $startDateSelectedFromDropDown;
     } elseif (isset($startDateOfTheTimesheetForUpdates)) {
         // if the the user is redirecting in the same timesheet(edit,submit)
         $startDatesOfTimeSheetsAccessible = $this->getAcessibleTimesheetStartDates($dateOptions);
         if ($startDatesOfTimeSheetsAccessible == null) {
             $this->messageData = array('NOTICE', __("No Accessible Timesheets"));
             $this->redirect('time/viewMyTimesheet');
         } elseif (in_array($startDateOfTheTimesheetForUpdates, $startDatesOfTimeSheetsAccessible)) {
             $this->toggleDate = $startDateOfTheTimesheetForUpdates;
             $timesheetStartingDate = $startDateOfTheTimesheetForUpdates;
         } else {
             $timesheetStartingDate = $startDatesOfTimeSheetsAccessible[0];
         }
     } else {
         // if the timesheet is access from the menu "My Timesheets"
         if ($dateOptions == null) {
             $statusArray = $this->getTimesheetService()->createTimesheet($employeeId, $this->currentDate);
             switch ($statusArray['state']) {
                 case $statusArray['state'] == 1:
                     $this->redirect('time/overLappingTimesheetError');
                     break;
                 case $statusArray['state'] == 2:
                     $timesheetStartingDate = $statusArray['message'];
                     break;
                 case $statusArray['state'] == 3:
                     $timesheetStartingDate = $statusArray['message'];
                     break;
                 case $statusArray['state'] == 4:
                     $timesheetStartingDate = $statusArray['message'];
                     $this->messageData = array('NOTICE', __("No Accessible Timesheets"));
                     break;
             }
         } else {
             $statusArray = $this->getTimesheetService()->createTimesheet($employeeId, $this->currentDate);
             switch ($statusArray['state']) {
                 case $statusArray['state'] == 1:
                     $this->redirect('time/overLappingTimesheetError');
                     break;
                 case $statusArray['state'] == 2:
                     $timesheetStartingDate = $statusArray['message'];
                     break;
                 case $statusArray['state'] == 3:
                     $timesheetStartingDate = $statusArray['message'];
                     $this->getTimesheetService()->createPreviousTimesheets($timesheetStartingDate, $employeeId);
                     //this creates the timesheets automatically for the past weeks, if the user have not created them
                     break;
                 case $statusArray['state'] == 4:
                     $latestDate = $this->getlatestStartDate($dateOptions);
                     $timesheetStartingDate = $latestDate;
                     break;
             }
         }
     }
     $this->timesheet = $this->getTimesheetService()->getTimesheetByStartDateAndEmployeeId($timesheetStartingDate, $employeeId);
     $this->currentState = $this->timesheet->getState();
     $this->dateForm = new startDaysListForm(array(), array('employeeId' => $employeeId));
     $dateOptions = $this->dateForm->getDateOptions();
     if ($request->getParameter('selectedIndex') != null) {
         $selectedIndex = $request->getParameter('selectedIndex');
     } else {
         $selectedIndex = $this->dateForm->returnSelectedIndex($timesheetStartingDate, $employeeId);
     }
     if (isset($selectedIndex)) {
         $this->dateForm->setDefault('startDates', $selectedIndex);
     }
     $noOfDays = $this->timesheetService->dateDiff($this->timesheet->getStartDate(), $this->timesheet->getEndDate());
     $values = array('date' => $timesheetStartingDate, 'employeeId' => $employeeId, 'timesheetId' => $this->timesheet->getTimesheetId(), 'noOfDays' => $noOfDays);
     $form = new TimesheetForm(array(), $values);
     $this->timesheetRows = $form->getTimesheet($timesheetStartingDate, $employeeId, $this->timesheet->getTimesheetId());
     $this->currentState = $this->timesheet->getState();
     $user = new User();
     $decoratedUser = new EssUserRoleDecorator($user);
     $this->allowedActions = $decoratedUser->getAllowedActions(WorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState);
     $this->allowedToCreateTimesheets = $decoratedUser->getAllowedActions(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, PluginTimesheet::STATE_INITIAL);
     $this->submitNextState = $decoratedUser->getNextState(WorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, WorkflowStateMachine::TIMESHEET_ACTION_SUBMIT);
     $this->approveNextState = $decoratedUser->getNextState(WorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, WorkflowStateMachine::TIMESHEET_ACTION_APPROVE);
     $this->rejectNextState = $decoratedUser->getNextState(WorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, WorkflowStateMachine::TIMESHEET_ACTION_REJECT);
     $this->resetNextState = $decoratedUser->getNextState(WorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, WorkflowStateMachine::TIMESHEET_ACTION_RESET);
     $this->rowDates = $form->getDatesOfTheTimesheetPeriod($this->timesheet->getStartDate(), $this->timesheet->getEndDate());
     $this->actionLogRecords = $this->getTimesheetService()->getTimesheetActionLogByTimesheetId($this->timesheet->getTimesheetId());
     $this->setTemplate("viewTimesheet");
 }
 public function execute($request)
 {
     //timesheetStartDateFromDropDown is from the drop down
     //timesheetStartDate is from the edit timesheet
     //$startDateSelectedFromDropDown set when the user is accessing the view from the search drop down
     //$startDateOfTheTimesheetForUpdates is set when the user performs an action on the timesheet,and it is used to update the timesheet
     $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]'));
     $startDateSelectedFromDropDown = $request->getParameter('timesheetStartDateFromDropDown');
     $userRoleManager = $this->getContext()->getUserRoleManager();
     $user = $userRoleManager->getUser();
     $userId = $user->getId();
     $employeeId = $this->getUser()->getEmployeeNumber();
     $this->timesheetPermissions = $this->getDataGroupPermissions('time_employee_timesheets', $employeeId);
     $this->format = $this->getTimesheetService()->getTimesheetTimeFormat();
     $this->timeService = $this->getTimesheetService();
     if ($request->isMethod('post')) {
         $this->updateTimesheetState($request);
     }
     $this->currentDate = date('Y-m-d');
     $this->actionName = $this->getActionName();
     $startDateOfTheTimesheetForUpdates = $request->getParameter('timesheetStartDate');
     $this->dateForm = new startDaysListForm(array(), array('employeeId' => $employeeId));
     $dateOptions = $this->dateForm->getDateOptions();
     if (isset($startDateSelectedFromDropDown)) {
         // timesheet is access via the search drop down
         $this->toggleDate = $startDateSelectedFromDropDown;
         $timesheetStartingDate = $startDateSelectedFromDropDown;
     } elseif (isset($startDateOfTheTimesheetForUpdates)) {
         // if the the user is redirecting in the same timesheet(edit,submit)
         $startDatesOfTimeSheetsAccessible = $this->getAcessibleTimesheetStartDates($dateOptions);
         if ($startDatesOfTimeSheetsAccessible == null) {
             $this->messageData = array('NOTICE', __("No Accessible Timesheets"));
             $this->redirect('time/viewMyTimesheet');
         } elseif (in_array($startDateOfTheTimesheetForUpdates, $startDatesOfTimeSheetsAccessible)) {
             $this->toggleDate = $startDateOfTheTimesheetForUpdates;
             $timesheetStartingDate = $startDateOfTheTimesheetForUpdates;
         } else {
             $timesheetStartingDate = $startDatesOfTimeSheetsAccessible[0];
         }
     } else {
         // if the timesheet is access from the menu "My Timesheets"
         if ($dateOptions == null) {
             $statusArray = $this->getTimesheetService()->createTimesheet($employeeId, $this->currentDate);
             switch ($statusArray['state']) {
                 case $statusArray['state'] == 1:
                     $this->redirect('time/overLappingTimesheetError');
                     break;
                 case $statusArray['state'] == 2:
                     $timesheetStartingDate = $statusArray['message'];
                     break;
                 case $statusArray['state'] == 3:
                     $timesheetStartingDate = $statusArray['message'];
                     break;
                 case $statusArray['state'] == 4:
                     $timesheetStartingDate = $statusArray['message'];
                     $this->messageData = array('NOTICE', __("No Accessible Timesheets"));
                     break;
             }
         } else {
             $statusArray = $this->getTimesheetService()->createTimesheet($employeeId, $this->currentDate);
             switch ($statusArray['state']) {
                 case $statusArray['state'] == 1:
                     $this->redirect('time/overLappingTimesheetError');
                     break;
                 case $statusArray['state'] == 2:
                     $timesheetStartingDate = $statusArray['message'];
                     break;
                 case $statusArray['state'] == 3:
                     $timesheetStartingDate = $statusArray['message'];
                     $this->getTimesheetService()->createPreviousTimesheets($timesheetStartingDate, $employeeId);
                     //this creates the timesheets automatically for the past weeks, if the user have not created them
                     break;
                 case $statusArray['state'] == 4:
                     $latestDate = $this->getlatestStartDate($dateOptions);
                     $timesheetStartingDate = $latestDate;
                     break;
             }
         }
     }
     $this->timesheet = $this->getTimesheetService()->getTimesheetByStartDateAndEmployeeId($timesheetStartingDate, $employeeId);
     $this->currentState = $this->timesheet->getState();
     $this->dateForm = new startDaysListForm(array(), array('employeeId' => $employeeId));
     $dateOptions = $this->dateForm->getDateOptions();
     if ($request->getParameter('selectedIndex') != null) {
         $selectedIndex = $request->getParameter('selectedIndex');
     } else {
         $selectedIndex = $this->dateForm->returnSelectedIndex($timesheetStartingDate, $employeeId);
     }
     if (isset($selectedIndex)) {
         $this->dateForm->setDefault('startDates', $selectedIndex);
     }
     $noOfDays = $this->timesheetService->dateDiff($this->timesheet->getStartDate(), $this->timesheet->getEndDate());
     $values = array('date' => $timesheetStartingDate, 'employeeId' => $employeeId, 'timesheetId' => $this->timesheet->getTimesheetId(), 'noOfDays' => $noOfDays);
     $form = new TimesheetForm(array(), $values);
     $this->timesheetRows = $form->getTimesheet($timesheetStartingDate, $employeeId, $this->timesheet->getTimesheetId());
     $this->currentState = $this->timesheet->getState();
     $user = new User();
     $decoratedUser = new EssUserRoleDecorator($user);
     $excludeRoles = array();
     $includeRoles = array('ESS');
     $entities = array('Employee' => $employeeId);
     $initialStateActions = $userRoleManager->getAllowedActions(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, PluginTimesheet::STATE_INITIAL, $excludeRoles, $includeRoles, $entities);
     $this->allowedActions = $userRoleManager->getAllowedActions(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, $this->currentState, $excludeRoles, $includeRoles, $entities);
     $this->allowedToCreateTimesheets = isset($initialStateActions[WorkflowStateMachine::TIMESHEET_ACTION_CREATE]);
     $this->rowDates = $form->getDatesOfTheTimesheetPeriod($this->timesheet->getStartDate(), $this->timesheet->getEndDate());
     $this->actionLogRecords = $this->getTimesheetService()->getTimesheetActionLogByTimesheetId($this->timesheet->getTimesheetId());
     $this->setTemplate("viewTimesheet");
 }