示例#1
0
 /**
  * Display leave information
  *
  * @param boolean $admin Show admin view or ess user view
  * @param Exception $exception Exception class (used to display any errors from previous apply/assign)
  */
 public function displayLeaveInfo($admin = false, $exception = null)
 {
     $authorizeObj = $this->authorize;
     if ($admin) {
         if ($authorizeObj->getIsAdmin() == 'Yes') {
             $empObj = new EmpInfo();
             $tmpObjs[0] = array(true);
         } else {
             if ($authorizeObj->isSupervisor()) {
                 $empRepToObj = new EmpRepTo();
                 $tmpObjs[0] = $empRepToObj->getEmpSubDetails($authorizeObj->getEmployeeId());
             }
         }
         $roles = array(authorize::AUTHORIZE_ROLE_ADMIN, authorize::AUTHORIZE_ROLE_SUPERVISOR);
         $role = $authorizeObj->firstRole($roles);
         $previousLeave = null;
         if (isset($_GET['id'])) {
             $leaveObj = new Leave();
             $previousLeaves = $leaveObj->retrieveLeave($_GET['id']);
             $previousLeave = $previousLeaves[0];
             if ($authorizeObj->getIsAdmin() != 'Yes' && $authorizeObj->isSupervisor() && !$authorizeObj->isTheSupervisor($previousLeave->getEmployeeId())) {
                 $previousLeave = null;
             }
         }
         $this->setId($_SESSION['empID']);
         $tmpObj = new LeaveType();
         $tmpObjs[1] = $tmpObj->fetchLeaveTypes();
         $tmpObjs[2] = $role;
         $tmpObjs[3] = $previousLeave;
         $tmpObjs['allEmpWorkshits'] = Workshift::getWorkshiftForAllEmployees();
     } else {
         $this->setId($_SESSION['empID']);
         $tmpObj = new LeaveQuota();
         $tmpObj->setYear(date('Y'));
         $tmpObjs[1] = $tmpObj->fetchLeaveQuota($this->getId());
         $workShift = Workshift::getWorkshiftForEmployee($this->getId());
         $shiftLength = isset($workShift) ? $workShift->getHoursPerDay() : Leave::LEAVE_LENGTH_FULL_DAY;
         $tmpObjs['shiftLength'] = $shiftLength;
     }
     $this->setObjLeave($tmpObjs);
     $path = "/templates/leave/leaveApply.php";
     if (!empty($exception)) {
         $tmpObjs['exception'] = $exception;
     }
     $template = new TemplateMerger($tmpObjs, $path);
     $template->display();
 }
示例#2
0
 /**
  * Test method for getWorkshiftForEmployee
  */
 public function testGetWorkshiftForEmployee()
 {
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('1' , 'New Test Shift', '5')"));
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('2' , 'Workshift 2', '10')"));
     $this->assertTrue(mysql_query("INSERT INTO " . Workshift::WORKSHIFT_TABLE . " VALUES ('3' , 'Workshift 3', '11')"));
     $this->assertTrue(mysql_query("INSERT INTO hs_hr_employee_workshift(workshift_id, emp_number) VALUES (1, 1)"));
     $this->assertTrue(mysql_query("INSERT INTO hs_hr_employee_workshift(workshift_id, emp_number) VALUES (2, 2)"));
     // Invalid employee id
     try {
         Workshift::getWorkshiftForEmployee('sdf');
         $this->fail("Invalid employee number should throw exception");
     } catch (WorkshiftException $e) {
         $this->assertEquals(WorkshiftException::INVALID_ID, $e->getCode());
     }
     // Get workshift for non-existant employee
     $this->assertNull(Workshift::getWorkshiftForEmployee(4));
     // Get workshift for employee without assigned workshift
     $this->assertNull(Workshift::getWorkshiftForEmployee(3));
     // Get workshift for employee with workshift assigned
     $shift = Workshift::getWorkshiftForEmployee(1);
     $this->assertNotNull($shift);
     $this->assertEquals("New Test Shift", $shift->getName());
     $this->assertEquals(5, $shift->getHoursPerDay());
     $this->assertEquals(1, $shift->getWorkshiftId());
 }
示例#3
0
文件: Leave.php 项目: noikiy/owaspbwa
 protected function _adjustLeaveLength()
 {
     $timeOff = $this->_timeOffLength($this->getLeaveDate());
     $shift = Leave::LEAVE_LENGTH_FULL_DAY;
     $workShift = Workshift::getWorkshiftForEmployee($this->getEmployeeId());
     if (isset($workShift)) {
         $shift = $workShift->getHoursPerDay();
     }
     $hours = $shift;
     $days = 1;
     if ($this->getLeaveLengthHours() != null) {
         $hours = $this->getLeaveLengthHours() - $timeOff * $shift;
         /* For handling leaves applied in half days: Begins
          * This assumes that employee request the leave in available working time
          * */
         if ($timeOff > 0 && $timeOff < 1) {
             if ($hours <= 0) {
                 $hours = $this->getLeaveLengthHours();
             } else {
                 $hours = $timeOff * $shift;
             }
         }
         /* For handling leaves applied in half days: Ends */
         $days = round($hours / $shift, 2);
     } else {
         if ($this->getLeaveLengthDays() != null) {
             $hours = ($this->getLeaveLengthDays() - $timeOff) * $shift;
             $days = round($hours / $shift, 2);
         }
     }
     if (0 > $hours) {
         $hours = 0;
     }
     if (0 > $days) {
         $days = 0;
     }
     $this->setLeaveLengthHours($hours);
     $this->setLeaveLengthDays($days);
 }