📄 leaverequests.php
字号:
<?php/** * * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures * all the essential functionalities required for any enterprise. * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com * * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of * the GNU General Public License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA * * @copyright 2006 OrangeHRM Inc., http://www.orangehrm.com */require_once ROOT_PATH . '/lib/models/leave/Leave.php';require_once ROOT_PATH . '/lib/models/leave/Holidays.php';require_once ROOT_PATH . '/lib/models/leave/Weekends.php';require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';/** * Leave Request Class * * Mainly involved in displaying leave and populating leave of * multiple days * * @author S.H.Mohanjith <mohanjith@orangehrm.com>, <moha@mohanjith.net> */class LeaveRequests extends Leave { const LEAVEREQUESTS_LEAVELENGTH_RANGE = 9; const LEAVEREQUESTS_MULTIPLESTATUSES = 5; private $leaveFromDate; private $leaveToDate; private $noDays; private $commentsDiffer; public function setLeaveFromDate($leaveFromDate) { $this->leaveFromDate = trim($leaveFromDate); } public function getLeaveFromDate() { return $this->leaveFromDate; } public function setLeaveToDate($leaveToDate) { $this->leaveToDate = trim($leaveToDate); } public function getLeaveToDate() { return $this->leaveToDate; } public function setNoDays($noDays) { $this->noDays = trim($noDays); } public function getNoDays() { return $this->noDays; } public function setCommentsDiffer($differ) { $this->commentsDiffer = $differ; } public function getCommentsDiffer() { return $this->commentsDiffer; } public function __construct() { $weekendObj = new Weekends(); $this->weekends = $weekendObj->fetchWeek(); } /** * Retrieves Leave Request Details of all leave that have been applied for but * not yet taken of the employee. * * @return LeaveRequests[][] $leaveArr A 2D array of the leaves */ public function retriveLeaveRequestsEmployee($employeeId) { $this->setEmployeeId($employeeId); $sqlBuilder = new SQLQBuilder(); $arrFields[0] = '`leave_type_name`'; $arrFields[1] = '`leave_request_id`'; $arrTable = "`hs_hr_leave_requests`"; $selectConditions[1] = "`employee_id` = '".$employeeId."'"; $query = $sqlBuilder->simpleSelect($arrTable, $arrFields, $selectConditions, $arrFields[1], 'ASC'); $dbConnection = new DMLFunctions(); $result = $dbConnection -> executeQuery($query); $leaveArr = $this->_buildObjArr($result); return $leaveArr; } /** * Retrieve leave requests for admin user * * @param $filterLeaveStatus array Array of leave statuses to include. If set, only * leaves with these statuses are returned. * @param $fromDate Date Start date to search * @param $toDate Date End date to search */ public function retriveLeaveRequestsAdmin($filterLeaveStatus = null, $fromDate = null, $toDate = null) { $sqlBuilder = new SQLQBuilder(); $arrFields[0] = 'a.`leave_type_name`'; $arrFields[1] = 'a.`leave_request_id`'; $arrFields[2] = 'b.`emp_firstname`'; $arrFields[3] = 'a.`employee_id`'; $arrFields[4] = 'b.`emp_lastname`'; $arrTables[0] = "`hs_hr_leave_requests` a"; $arrTables[1] = "`hs_hr_employee` b"; $selectConditions[] = "b.`emp_status` IS NULL OR b.`emp_status` != 'EST000'" ; $joinConditions[1] = "a.`employee_id` = b.`emp_number`"; $query = $sqlBuilder->selectFromMultipleTable($arrFields, $arrTables, $joinConditions, $selectConditions); $dbConnection = new DMLFunctions(); $result = $dbConnection->executeQuery($query); $leaveArr = $this->_buildObjArr($result, true, $filterLeaveStatus, $fromDate, $toDate); return $leaveArr; } /** * Retrieves Leave Request Details of all leave that have been applied for but * not yet taken by all supervisor's subordinates. * * @return LeaveRequests[][] $leaveArr A 2D array of the leaves */ public function retriveLeaveRequestsSupervisor($supervisorId) { $sqlBuilder = new SQLQBuilder(); $arrFields[0] = 'a.`leave_type_name`'; $arrFields[1] = 'a.`leave_request_id`'; $arrFields[2] = 'd.`emp_firstname`'; $arrFields[3] = 'a.`employee_id`'; $arrFields[4] = 'd.`emp_lastname`'; $arrTables[0] = "`hs_hr_leave_requests` a"; $arrTables[1] = "`hs_hr_emp_reportto` c"; $arrTables[2] = "`hs_hr_employee` d"; $joinConditions[1] = "a.`employee_id` = c.`erep_sub_emp_number`"; $joinConditions[2] = "a.`employee_id` = d.`emp_number`"; $selectConditions[1] = "c.`erep_sup_emp_number` = '".$supervisorId."'"; $query = $sqlBuilder->selectFromMultipleTable($arrFields, $arrTables, $joinConditions, $selectConditions); $dbConnection = new DMLFunctions(); $result = $dbConnection -> executeQuery($query); $leaveStatuses = array(Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL, Leave::LEAVE_STATUS_LEAVE_APPROVED, Leave::LEAVE_STATUS_LEAVE_REJECTED); $leaveArr = $this->_buildObjArr($result, true, $leaveStatuses); return $leaveArr; }/** * This retrives alreadyt taken leaves. */ public function retriveLeaveTaken() { $sqlBuilder = new SQLQBuilder(); $arrFields[0] = 'a.`leave_id`'; $arrFields[1] = 'a.`leave_date`'; $arrFields[2] = 'b.`emp_firstname`'; $arrFields[3] = 'b.`emp_lastname`'; $arrFields[4] = 'a.`leave_length_hours`'; $arrFields[5] = 'a.`leave_comments`'; $arrFields[6] = 'a.`leave_type_id`'; $arrFields[7] = 'a.`employee_id`'; $arrTables[0] = "`hs_hr_leave` a"; $arrTables[1] = "`hs_hr_employee` b"; $joinConditions[1] = "a.`employee_id` = b.`employee_id`"; $selectConditions[1] = "a.`leave_status` = '3'"; $query = $sqlBuilder->selectFromMultipleTable($arrFields, $arrTables, $joinConditions, $selectConditions); $dbConnection = new DMLFunctions(); $result = $dbConnection -> executeQuery($query); $leaveArr = $this->_buildObjArr($result, true); return $leaveArr; } /** * Calculates required length of leave. * * @param integer $length - leave lenth * @param integer $timeOff - time off for that day * @return integer $reqiredLength - length of leave required. */ protected function _leaveLength($length, $timeOff) { $factor = 1; if ($length < 0) { $factor = 1; } $length = abs($length); if ($timeOff > $length) { return 0; } $requiredLength = $length-$timeOff; return $requiredLength*$factor; } public function cancelLeave($id = null) { return $this->changeLeaveStatus($id); } public function changeLeaveStatus($id = null) { if (isset($id)) { $this->setLeaveRequestId($id); } $newStatus = $this->getLeaveStatus(); $tmpLeave = new Leave(); $tmpLeaveArr = $tmpLeave->retrieveLeave($this->getLeaveRequestId()); $ok = true; if(! is_null($tmpLeaveArr)){ foreach ($tmpLeaveArr as $leave) { $leave->setLeaveStatus($newStatus); $res = $leave->changeLeaveStatus(); if (!$res) { $ok = false; } } } return $ok; } /** * @param $filterLeaveStatus array Array of leave statuses to include. If set, only * leaves with these statuses are returned. * @param $fromDate Date Start date to search * @param $toDate Date End date to search */ protected function _buildObjArr($result, $supervisor=false, $filterLeaveStatus = null, $fromDate = null, $toDate = null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -