📄 timesheet.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 * */require_once ROOT_PATH . '/lib/dao/DMLFunctions.php';require_once ROOT_PATH . '/lib/dao/SQLQBuilder.php';require_once ROOT_PATH . '/lib/logs/LogFileWriter.php';require_once ROOT_PATH . '/lib/confs/sysConf.php';require_once ROOT_PATH . '/lib/models/time/TimesheetSubmissionPeriod.php';require_once ROOT_PATH . '/lib/common/UniqueIDGenerator.php';/** * */class Timesheet { /** * Class constants */ const TIMESHEET_DB_TABLE_TIMESHEET = "hs_hr_timesheet"; const TIMESHEET_DB_FIELD_TIMESHEET_ID = "timesheet_id"; const TIMESHEET_DB_FIELD_EMPLOYEE_ID = "employee_id"; const TIMESHEET_DB_FIELD_TIMESHEET_PERIOD_ID = "timesheet_period_id"; const TIMESHEET_DB_FIELD_START_DATE = "start_date"; const TIMESHEET_DB_FIELD_END_DATE = "end_date"; const TIMESHEET_DB_FIELD_STATUS = "status"; const TIMESHEET_DB_FIELD_COMMENT = "comment"; const TIMESHEET_DIRECTION_NEXT = 1; const TIMESHEET_DIRECTION_PREV = -1; const TIMESHEET_STATUS_NOT_SUBMITTED=0; const TIMESHEET_STATUS_SUBMITTED=10; const TIMESHEET_STATUS_APPROVED=20; const TIMESHEET_STATUS_REJECTED=30; /** * Class atributes */ private $timesheetId; private $employeeId; private $timesheetPeriodId; private $startDate; private $endDate; private $status; private $comment; private $statuses; /** * Class atribute setters and getters */ public function setTimesheetId($timesheetId) { $this->timesheetId=$timesheetId; } public function getTimesheetId() { return $this->timesheetId; } public function setEmployeeId($employeeId) { $this->employeeId=$employeeId; } public function getEmployeeId() { return $this->employeeId; } public function setTimesheetPeriodId($timesheetPeriodId) { $this->timesheetPeriodId=$timesheetPeriodId; } public function getTimesheetPeriodId() { return $this->timesheetPeriodId; } public function setStartDate($startDate) { $this->startDate=$startDate; } public function getStartDate() { return $this->startDate; } public function setEndDate($endDate) { $this->endDate=$endDate; } public function getEndDate() { return $this->endDate; } public function setStatus($status) { $this->status=$status; } public function getStatus() { return $this->status; } public function setComment($comment) { $this->comment=$comment; } public function getComment() { return $this->comment; } /** * Special atribute setters * * For searching for multiple statuses */ public function setStatuses($statuses) { $this->statuses=$statuses; } public function getStatuses() { return $this->statuses; } public function __construct() { //nothing to do } public function __distruct() { //nothing to do } /** * Generates the current timesheet start date and end date * * This will be called if start date of a time sheet is not set */ private function _getNewDates() { $timesheetSubmissionPeriodObj = new TimesheetSubmissionPeriod(); $timesheetSubmissionPeriods = $timesheetSubmissionPeriodObj->fetchTimesheetSubmissionPeriods(); if ($this->getStartDate() == null) { /** * Here days should be in following values * Mo=1, Tu=2, We=3, Th=4, Fr=5, Sa=6, Su=7 */ if (date('w') == 0) { // If it is Sunday $day = 7; } else { $day = date('w'); } $diff=$timesheetSubmissionPeriods[0]->getStartDay()-$day; if ($diff > 0) { $diff-=7; } $this->setStartDate(date('Y-m-d', time()+($diff*3600*24))); $diff1=$timesheetSubmissionPeriods[0]->getEndDay()-$day; if (($diff1-$diff) <= 6) { $diff1+=6-($diff1-$diff); } $this->setEndDate(date('Y-m-d', time()+($diff1*3600*24))." 23:59:59"); $this->setTimesheetPeriodId($timesheetSubmissionPeriods[0]->getTimesheetPeriodId()); } } /** * Add a new timesheet * * Status will be overwritten */ public function addTimesheet() { $newId = UniqueIDGenerator::getInstance()->getNextID(self::TIMESHEET_DB_TABLE_TIMESHEET, self::TIMESHEET_DB_FIELD_TIMESHEET_ID); $this->setTimesheetId($newId); $this->_getNewDates(); $this->setStatus(self::TIMESHEET_STATUS_NOT_SUBMITTED); $sql_builder = new SQLQBuilder(); $insertTable = self::TIMESHEET_DB_TABLE_TIMESHEET; $insertFields[0] = "`".self::TIMESHEET_DB_FIELD_TIMESHEET_ID."`"; $insertFields[1] = "`".self::TIMESHEET_DB_FIELD_EMPLOYEE_ID."`"; $insertFields[2] = "`".self::TIMESHEET_DB_FIELD_TIMESHEET_PERIOD_ID."`"; $insertFields[3] = "`".self::TIMESHEET_DB_FIELD_START_DATE."`"; $insertFields[4] = "`".self::TIMESHEET_DB_FIELD_END_DATE."`"; $insertFields[5] = "`".self::TIMESHEET_DB_FIELD_STATUS."`"; $insertValues[0] = $this->getTimesheetId(); $insertValues[1] = $this->getEmployeeId(); $insertValues[2] = $this->getTimesheetPeriodId(); $insertValues[3] = "'".$this->getStartDate()."'"; $insertValues[4] = "'".$this->getEndDate()."'"; $insertValues[5] = $this->getStatus(); $insertValues = $sql_builder->quoteCorrect($insertValues); $query = $sql_builder->simpleInsert($insertTable, $insertValues, $insertFields); $dbConnection = new DMLFunctions(); $result = $dbConnection->executeQuery($query); if ($result && (mysql_affected_rows() > 0)) { return true; } return false; } /** * Submit timesheet * * @param boolean superior Whether the request is coming from a supervisor or a HR Admin * @return boolean Submitted/Not */ public function submitTimesheet($superior=false) { if (!($superior || ($this->getStatus() == self::TIMESHEET_STATUS_NOT_SUBMITTED) || ($this->getStatus() == self::TIMESHEET_STATUS_REJECTED))) { return false; } $this->setStatus(self::TIMESHEET_STATUS_SUBMITTED); return $this->_changeTimesheetStatus(); } /** * Approve timesheet */ public function approveTimesheet() { if ($this->getStatus() != self::TIMESHEET_STATUS_SUBMITTED) { return false; } $this->setStatus(self::TIMESHEET_STATUS_APPROVED); $this->setComment($this->getComment()); return $this->_changeTimesheetStatus(); } /** * Cancel timesheet */ public function cancelTimesheet() { if (($this->getStatus() != self::TIMESHEET_STATUS_SUBMITTED) && ($this->getStatus() != self::TIMESHEET_STATUS_REJECTED)) { return false; } $this->setStatus(self::TIMESHEET_STATUS_NOT_SUBMITTED); $this->setComment($this->getComment()); return $this->_changeTimesheetStatus(); } /** * Reject timesheet */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -