1<?php 2 3/** 4 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures 5 * all the essential functionalities required for any enterprise. 6 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com 7 * 8 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of 9 * the GNU General Public License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 * See the GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License along with this program; 17 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA 19 */ 20class viewEmployeeTimesheetAction extends baseTimeAction { 21 22 const NUM_PENDING_TIMESHEETS = 100; 23 private $employeeNumber; 24 private $timesheetService; 25 26 public function getTimesheetService() { 27 28 if (is_null($this->timesheetService)) { 29 30 $this->timesheetService = new TimesheetService(); 31 } 32 33 return $this->timesheetService; 34 } 35 36 public function execute($request) { 37 38 $this->timesheetPermissions = $this->getDataGroupPermissions('time_employee_timesheets'); 39 40 $this->form = new viewEmployeeTimesheetForm(); 41 42 43 if ($request->isMethod("post")) { 44 45 46 $this->form->bind($request->getParameter('time')); 47 48 if ($this->form->isValid()) { 49 50 $this->employeeId = $this->form->getValue('employeeId'); 51 $startDaysListForm = new startDaysListForm(array(), array('employeeId' => $this->employeeId)); 52 $dateOptions = $startDaysListForm->getDateOptions(); 53 54 if ($dateOptions == null) { 55 $this->getContext()->getUser()->setFlash('warning.nofade', __('No Timesheets Found')); 56 $this->redirect('time/createTimesheetForSubourdinate?' . http_build_query(array('employeeId' => $this->employeeId))); 57 } 58 59 $this->redirect('time/viewTimesheet?' . http_build_query(array('employeeId' => $this->employeeId))); 60 } 61 } 62 63 $userRoleManager = $this->getContext()->getUserRoleManager(); 64 65 $properties = array("empNumber","firstName", "middleName", "lastName", "termination_id"); 66 $employeeList = UserRoleManagerFactory::getUserRoleManager() 67 ->getAccessibleEntityProperties('Employee', $properties); 68 69 $this->form->employeeList = $employeeList; 70 71 $this->pendingApprovelTimesheets = $this->getActionableTimesheets($employeeList); 72 } 73 74 public function getActionableTimesheets($employeeList) { 75 $timesheetList = null; 76 77 $accessFlowStateMachinService = new AccessFlowStateMachineService(); 78 $action = array(PluginWorkflowStateMachine::TIMESHEET_ACTION_APPROVE, PluginWorkflowStateMachine::TIMESHEET_ACTION_REJECT); 79 $actionableStatesList = $accessFlowStateMachinService->getActionableStates(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, AdminUserRoleDecorator::ADMIN_USER, $action); 80 81 $empNumbers = array(); 82 83 foreach ($employeeList as $employee) { 84 $empNumbers[] = $employee['empNumber']; 85 } 86 87 if ($actionableStatesList != null) { 88 $timesheetList = $this->getTimesheetService()->getTimesheetListByEmployeeIdAndState($empNumbers, $actionableStatesList, self::NUM_PENDING_TIMESHEETS); 89 } 90 91 return $timesheetList; 92 } 93 94} 95 96