public function testBulkAssignLeaveEntitlements() { $this->fixture = sfConfig::get('sf_plugins_dir') . '/orangehrmLeavePlugin/test/fixtures/LeaveEntitlement.yml'; TestDataService::populate($this->fixture); $dao = new LeaveEntitlementDao(); $limit = 5000; $empList = array(); $employeeService = new EmployeeService(); $employeeService->setEmployeeDao(new EmployeeDao()); for ($i = 0; $i < $limit; $i++) { $employee = new Employee(); $employee->setFirstName($i); $employee = $employeeService->saveEmployee($employee); array_push($empList, $employee->getEmpNumber()); } $start_time = microtime(true); $leaveEntitlement = new LeaveEntitlement(); $leaveEntitlement->setLeaveTypeId(1); $leaveEntitlement->setCreditedDate(date('Y-m-d')); $leaveEntitlement->setEntitlementType(LeaveEntitlement::ENTITLEMENT_TYPE_ADD); $leaveEntitlement->setDeleted(0); $leaveEntitlement->setNoOfDays(2); $leaveEntitlement->setFromDate('2012-01-01'); $leaveEntitlement->setToDate('2012-08-01'); $result = $dao->bulkAssignLeaveEntitlements($empList, $leaveEntitlement); $deference = microtime(true) - $start_time; $this->assertEquals(count($empList), $result, "Time Deference - " . $deference); echo "Add Entitlement 5000 Time " . $deference; }
public function testSearchEmployeeList() { $parameterHolder = new EmployeeSearchParameterHolder(); $employee1 = new Employee(); $employee1->setLastName('Last Name'); $employee1->setFirstName('First Name'); $employee2 = new Employee(); $employee2->setLastName('Last Name'); $employee2->setFirstName('First Name'); $list = array($employee1, $employee2); $mockDao = $this->getMock('EmployeeDirectoryDao'); $mockDao->expects($this->once())->method('searchEmployees')->with($parameterHolder)->will($this->returnValue($list)); $this->employeeDirectoryService->setEmployeeDirectoryDao($mockDao); $result = $this->employeeDirectoryService->searchEmployees($parameterHolder); $this->assertEquals($list, $result); }
public function testGetAccessibleEmployees() { $mockService = $this->getMock('EmployeeService'); $employeeList = new Doctrine_Collection('Employee'); for ($i = 0; $i < 2; $i++) { $employee = new Employee(); $employee->setEmployeeId($i + 1); $employee->setEmpNumber($i + 1); $employee->setFirstName("test name" . $i + 1); $employeeList->add($employee); } $mockService->expects($this->once())->method('getSubordinateList')->with(1, true)->will($this->returnValue($employeeList)); $this->supervisorUserRole->setEmployeeNumber(1); $this->supervisorUserRole->setEmployeeService($mockService); $employees = $this->supervisorUserRole->getAccessibleEmployees(); $this->assertEquals(2, count($employees)); for ($i = 0; $i < 2; $i++) { $this->assertEquals($employees[$i + 1], $employeeList[$i]); } }
/** * @covers CorporateDirectoryWebServiceHelper::getCorporateDirectoryEmployeeDetailsAsArray */ public function testGetCorporateDirectoryEmployeeDetailsAsArrayWithLoationsAndSubunits() { $location = new Location(); $location->setId(1); $locationCollection = new Doctrine_Collection('Location'); $locationCollection->add($location); $employee = new Employee(); $employee->setEmpNumber(1); $employee->setFirstName('testEmpFirstName'); $employee->setLastName('testEmpLastName'); $employee->setLocations($locationCollection); $count = 1; $employees = array($employee); $employeeDirectoryServiceMock = $this->getMock('EmployeeDirectoryService'); $employeeDirectoryServiceMock->expects($this->once())->method('searchEmployees')->will($this->returnValue($employees)); $employeeDirectoryServiceMock->expects($this->once())->method('getSearchEmployeeCount')->will($this->returnValue($count)); $this->corporateDirectoryWebServiceHelper->setEmployeeDirectoryService($employeeDirectoryServiceMock); $employeeDetails = $this->corporateDirectoryWebServiceHelper->getCorporateDirectoryEmployeeDetailsAsArray(); $this->assertEquals(1, count($employeeDetails)); $this->assertNotNull($employeeDetails[0]['location_id']); $this->assertEquals(1, $employeeDetails[0]['location_id']); }
public function getEmployeeListForAttendanceTotalSummaryReport() { $employeeList = $this->getEmployeeService()->getEmployeeList('empNumber', 'ASC', true); $employee = new Employee(); $employee->setEmpNumber('-1'); $employee->setFirstName("All"); if ($employeeList[0]->getEmpNumber() == null) { $employeeList->add($employee); return $employeeList; } else { $employeeList->add($employee); return $employeeList; } }
/** * Get employee list after sorting and filtering using given parameters. * * @param EmployeeSearchParameterHolder $parameterHolder */ public function searchEmployees(EmployeeSearchParameterHolder $parameterHolder) { $sortField = $parameterHolder->getOrderField(); $sortOrder = $parameterHolder->getOrderBy(); $offset = $parameterHolder->getOffset(); $limit = $parameterHolder->getLimit(); $filters = $parameterHolder->getFilters(); $returnType = $parameterHolder->getReturnType(); $select = ''; $query = ''; $bindParams = array(); $orderBy = ''; $this->_getEmployeeListQuery($select, $query, $bindParams, $orderBy, $sortField, $sortOrder, $filters); $completeQuery = $select . ' ' . $query . ' ' . $orderBy; if (!is_null($offset) && !is_null($limit)) { $completeQuery .= ' LIMIT ' . $offset . ', ' . $limit; } if (sfConfig::get('sf_logging_enabled')) { $msg = $completeQuery; if (count($bindParams) > 0) { $msg .= ' (' . implode(',', $bindParams) . ')'; } sfContext::getInstance()->getLogger()->info($msg); } $conn = Doctrine_Manager::connection(); $statement = $conn->prepare($completeQuery); $result = $statement->execute($bindParams); if ($returnType == EmployeeSearchParameterHolder::RETURN_TYPE_OBJECT) { $employees = new Doctrine_Collection(Doctrine::getTable('Employee')); if ($result) { while ($row = $statement->fetch()) { $employee = new Employee(); $employee->setEmpNumber($row['empNumber']); $employee->setEmployeeId($row['employeeId']); $employee->setFirstName($row['firstName']); $employee->setMiddleName($row['middleName']); $employee->setLastName($row['lastName']); $employee->setTerminationId($row['terminationId']); $jobTitle = new JobTitle(); $jobTitle->setId($row['jobTitleId']); $jobTitle->setJobTitleName($row['jobTitle']); $jobTitle->setIsDeleted($row['isDeleted']); $employee->setJobTitle($jobTitle); $employeeStatus = new EmploymentStatus(); $employeeStatus->setId($row['employeeStatusId']); $employeeStatus->setName($row['employeeStatus']); $employee->setEmployeeStatus($employeeStatus); $workStation = new SubUnit(); $workStation->setName($row['subDivision']); $workStation->setId($row['subDivisionId']); $employee->setSubDivision($workStation); $supervisorList = isset($row['supervisors']) ? $row['supervisors'] : ''; if (!empty($supervisorList)) { $supervisors = new Doctrine_Collection(Doctrine::getTable('Employee')); $supervisorArray = explode(',', $supervisorList); foreach ($supervisorArray as $supervisor) { list($first, $middle, $last) = explode('##', $supervisor); $supervisor = new Employee(); $supervisor->setFirstName($first); $supervisor->setMiddleName($middle); $supervisor->setLastName($last); $employee->supervisors[] = $supervisor; } } $locationList = $row['locationIds']; if (!empty($locationList)) { // $locations = new Doctrine_Collection(Doctrine::getTable('EmpLocations')); $locationArray = explode(',', $locationList); foreach ($locationArray as $location) { list($id, $name) = explode('##', $location); $empLocation = new Location(); $empLocation->setId($id); $empLocation->setName($name); $employee->locations[] = $empLocation; } } $employees[] = $employee; } } } else { return $statement->fetchAll(); } return $employees; }
public function import($data) { if ($data[0] == "" || $data[2] == "" || strlen($data[0]) > 30 || strlen($data[2]) > 30) { return false; } $employee = new Employee(); $employee->setFirstName($data[0]); if (strlen($data[1]) <= 30) { $employee->setMiddleName($data[1]); } $employee->setLastName($data[2]); if (strlen($data[3]) <= 50) { $employee->setEmployeeId($data[3]); } if (strlen($data[4]) <= 30) { $employee->setOtherId($data[4]); } if (strlen($data[5]) <= 30) { $employee->setLicenseNo($data[5]); } if ($this->isValidDate($data[6])) { $employee->setEmpDriLiceExpDate($data[6]); } if (strtolower($data[7]) == 'male') { $employee->setEmpGender('1'); } else { if (strtolower($data[7]) == 'female') { $employee->setEmpGender('2'); } } if (strtolower($data[8]) == 'single') { $employee->setEmpMaritalStatus('Single'); } else { if (strtolower($data[8]) == 'married') { $employee->setEmpMaritalStatus('Married'); } else { if (strtolower($data[8]) == 'other') { $employee->setEmpMaritalStatus('Other'); } } } $nationality = $this->isValidNationality($data[9]); if (!empty($nationality)) { $employee->setNationality($nationality); } if ($this->isValidDate($data[10])) { $employee->setEmpBirthday($data[10]); } if (strlen($data[11]) <= 70) { $employee->setStreet1($data[11]); } if (strlen($data[12]) <= 70) { $employee->setStreet2($data[12]); } if (strlen($data[13]) <= 70) { $employee->setCity($data[13]); } if (strlen($data[15]) <= 10) { $employee->setEmpZipcode($data[15]); } $code = $this->isValidCountry($data[16]); if (!empty($code)) { $employee->setCountry($code); if (strtolower($data[16]) == 'united states') { $code = $this->isValidProvince($data[14]); if (!empty($code)) { $employee->setProvince($code); } } else { if (strlen($data[14]) <= 70) { $employee->setProvince($data[14]); } } } if (strlen($data[17]) <= 25 && $this->isValidPhoneNumber($data[17])) { $employee->setEmpHmTelephone($data[17]); } if (strlen($data[18]) <= 25 && $this->isValidPhoneNumber($data[18])) { $employee->setEmpMobile($data[18]); } if (strlen($data[19]) <= 25 && $this->isValidPhoneNumber($data[19])) { $employee->setEmpWorkTelephone($data[19]); } if ($this->isValidEmail($data[20]) && strlen($data[20]) <= 50 && $this->isUniqueEmail($data[20])) { $employee->setEmpWorkEmail($data[20]); } if ($this->isValidEmail($data[21]) && strlen($data[21]) <= 50 && $this->isUniqueEmail($data[21])) { $employee->setEmpOthEmail($data[21]); } $empService = new EmployeeService(); $empService->addEmployee($employee); return true; }
public function import($data) { set_time_limit(90); if ($data[0] == "" || strlen($data[0]) > 30) { return false; } $createUser = false; $empService = new EmployeeService(); $employee = $empService->getEmployeeByEmployeeId($data[0]); if (empty($employee)) { $employee = new Employee(); $createUser = true; } if (strlen($data[0]) <= 50) { $employee->setEmployeeId($data[0]); } $employee->setFirstName($data[1]); if (strlen($data[2]) <= 30) { $employee->setMiddleName($data[2]); } $employee->setLastName($data[3]); if (strlen($data[4]) <= 30) { $employee->setOtherId($data[4]); } if (strlen($data[5]) <= 30) { $employee->setBloodGroup($data[5]); } if ($data[6] != "") { $dob = $this->formatDate($data[6]); $employee->setEmpBirthday($dob); } if (strtolower($data[7]) == 'male') { $employee->setEmpGender('1'); } else { if (strtolower($data[7]) == 'female') { $employee->setEmpGender('2'); } } if (strtolower($data[8]) == 'single') { $employee->setEmpMaritalStatus('Single'); } else { if (strtolower($data[8]) == 'married') { $employee->setEmpMaritalStatus('Married'); } else { if (strtolower($data[8]) == 'other') { $employee->setEmpMaritalStatus('Other'); } } } $nationality = $this->isValidNationality($data[9]); if (!empty($nationality)) { $employee->setNationality($nationality); } if (strlen($data[10]) <= 70) { $employee->setFatherName($data[10]); } if (strlen($data[11]) <= 70) { $employee->setHusbandName($data[11]); } if (strlen($data[12]) <= 70) { $employee->setStreet1($data[12]); } if (strlen($data[13]) <= 70) { $employee->setStreet2($data[13]); } if (strlen($data[14]) <= 70) { $employee->setCity($data[14]); } if (strlen($data[16]) <= 10) { $employee->setEmpZipcode($data[16]); } $code = $this->isValidCountry($data[17]); if (!empty($code)) { $employee->setCountry($code); if (strtolower($data[17]) == 'united states') { $code = $this->isValidProvince($data[15]); if (!empty($code)) { $employee->setProvince($code); } } else { if (strlen($data[15]) <= 70) { $employee->setProvince($data[15]); } } } if (strlen($data[18]) <= 100) { $employee->setPermanentAddress($data[18]); } if ($this->isValidEmail($data[19]) && strlen($data[19]) <= 50 && $this->isUniqueEmail($data[19])) { $employee->setEmpWorkEmail($data[19]); } if ($this->isValidEmail($data[20]) && strlen($data[20]) <= 50) { $employee->setEmpOthEmail($data[20]); } if ($this->isValidEmail($data[21]) && strlen($data[21]) <= 50) { $employee->setEmpPersonalEmail($data[21]); } if (strlen($data[22]) <= 25 && $this->isValidPhoneNumber($data[22])) { $employee->setEmpMobile($data[22]); } if (strlen($data[23]) <= 25 && $this->isValidPhoneNumber($data[23])) { $employee->setEmpWorkTelephone($data[23]); } if (strlen($data[24]) <= 25 && $this->isValidPhoneNumber($data[24])) { $employee->setEmpHmTelephone($data[24]); } if (strlen($data[25]) <= 50) { $employee->setEmpPhoneAccesscode($data[25]); } if (strlen($data[26]) <= 50) { $employee->setEmpSkypeId($data[26]); } if ($data[27] != "") { $joinedDate = $this->formatDate($data[27]); $employee->setJoinedDate($joinedDate); } $jobTitle = $this->isValidJobTitle($data[28]); if (!empty($jobTitle)) { $employee->setJobTitleCode($jobTitle); } if ($data[29] != "" && is_numeric($data[29])) { $employee->setTotalExperience($data[29]); } if ($data[30] != "" && is_numeric($data[30])) { $employee->setCurrentExperience($data[30]); } if ($data[31] != "" && is_numeric($data[31])) { $employee->setNoticePeriod($data[31]); } if (strlen($data[32]) <= 50) { $employee->setProject($data[32]); } if (strlen($data[33]) <= 50) { $employee->setReferredBy($data[33]); } if (strlen($data[34]) <= 50) { $employee->setCustom4($data[34]); } if (strlen($data[38]) <= 50) { $employee->setCustom2($data[38]); } if (strlen($data[39]) <= 50) { $employee->setCustom3($data[39]); } if (strlen($data[40]) <= 50) { $employee->setCustom1($data[40]); } $employee = $empService->saveEmployee($employee); if ($data[35] != "" && $data[36] != "") { $employeeSalary = new EmployeeSalary(); $employeeSalary->setSalaryName("CTC"); $employeeSalary->setPayPeriodId("4"); $employeeSalary->setCurrencyCode($data[36]); $employeeSalary->setAmount($data[35]); $employeeSalary->setEmpNumber($employee); $empDirectDebit = new EmpDirectdebit(); $empDirectDebit->setAccount($data[37]); $empDirectDebit->setAccountType("SAVINGS"); $employeeSalary->setDirectDebit($empDirectDebit); $empService->saveEmployeeSalary($employeeSalary); } if ($data[41] != "" && strlen($data[41]) <= 50) { $empPassport = new EmployeeImmigrationRecord(); $empPassport->setEmployee($employee); $empPassport->setNumber($data[41]); $empPassport->setCountryCode($data[42]); if ($data[43] != "") { $expiryDate = $this->formatDate($data[43]); $empPassport->setExpiryDate($expiryDate); } $empPassport->setType(1); $empService->saveEmployeeImmigrationRecord($empPassport); } if ($data[44] != "" && strlen($data[44]) <= 50) { $empVisaDetails = new EmployeeImmigrationRecord(); $empVisaDetails->setEmployee($employee); $empVisaDetails->setNumber($data[44]); if ($data[45] != "") { $visaExpiryDate = $this->formatDate($data[45]); $empVisaDetails->setExpiryDate($visaExpiryDate); } $empVisaDetails->setType(2); $empService->saveEmployeeImmigrationRecord($empVisaDetails); } if ($data[46] != "" && $data[46] != '0' && strlen($data[46]) <= 50) { $sequence1 = 1; //$this->getDependentSeqNo($employee->getEmpNumber()); $dependent1 = $this->getEmployeeDependent($employee->getEmpNumber(), $sequence1); $dependent1->setEmployee($employee); $dependent1->setSeqno($sequence1); $dependent1->setName($data[46]); if ($data[47] != "") { $dependent1->setDateOfBirth($this->formatDate($data[47])); } $dependent1->setRelationshipType($data[48]); $dependent1->setRelationship($data[49]); $dependent1->save(); } if ($data[50] != "" && $data[50] != '0' && strlen($data[50]) <= 50) { $sequence2 = 2; //$this->getDependentSeqNo($employee->getEmpNumber()); $dependent2 = $this->getEmployeeDependent($employee->getEmpNumber(), $sequence2); $dependent2->setEmployee($employee); $dependent2->setSeqno($sequence2); $dependent2->setName($data[50]); if ($data[51] != "") { $dependent2->setDateOfBirth($this->formatDate($data[51])); } $dependent2->setRelationshipType($data[52]); $dependent2->setRelationship($data[53]); $dependent2->save(); } if ($data[54] != "" && $data[54] != '0' && strlen($data[54]) <= 50) { $sequence3 = 3; //$this->getDependentSeqNo($employee->getEmpNumber()); $dependent3 = $this->getEmployeeDependent($employee->getEmpNumber(), $sequence3); $dependent3->setEmployee($employee); $dependent3->setSeqno($sequence3); $dependent3->setName($data[54]); if ($data[55] != "") { $dependent3->setDateOfBirth($this->formatDate($data[55])); } $dependent3->setRelationshipType($data[56]); $dependent3->setRelationship($data[57]); $dependent3->save(); } if ($createUser && $data[58] != "" && $data[59] != "") { $user = new SystemUser(); $user->setDateEntered(date('Y-m-d H:i:s')); //$user->setCreatedBy($sfUser->getAttribute('user')->getUserId()); $user->setUserName($data[58]); $user->setUserPassword(md5($data[59])); $user->setEmployee($employee); $user->setUserRoleId(2); $this->getUserService()->saveSystemUser($user); } return true; }
public function testGetCorporateDirectoryEmployeeDetailsAsArrayWithNullProfilePicture() { $employee = new Employee(); $employee->setEmpNumber(1); $employee->setFirstName('testEmpFirstName'); $employee->setLastName('testEmpLastName'); $count = 1; $employees = array($employee); $employeeDirectoryServiceMock = $this->getMock('EmployeeDirectoryService'); $employeeDirectoryServiceMock->expects($this->once())->method('searchEmployees')->will($this->returnValue($employees)); $employeeDirectoryServiceMock->expects($this->once())->method('getSearchEmployeeCount')->will($this->returnValue($count)); $employeeServiceMock = $this->getMock('EmployeeService'); $employeeServiceMock->expects($this->once())->method('getEmployeePicture')->will($this->returnValue(null)); $this->corporateDirectoryWebServiceHelper->setEmployeeDirectoryService($employeeDirectoryServiceMock); $this->corporateDirectoryWebServiceHelper->setEmployeeService($employeeServiceMock); $employeeDetails = $this->corporateDirectoryWebServiceHelper->getCorporateDirectoryEmployeeDetailsAsArray(); $this->assertNull($employeeDetails[0]['profile_picture']); }
/** * This test checks for the Leave Overlapping and failure in apply */ public function testApplyLeaveFailLeaveOverlap() { // Set post parameters $parameters = array('txtFromDate' => '2010-11-23', 'txtToDate' => '2010-11-24', 'txtEmpID' => '0001', 'txtLeaveType' => 'LT001'); $request = $this->context->request; $request->setPostParameters($parameters); // Set request to POST method $request->setMethod(sfRequest::POST); //mocking employee service $employeeService = $this->getMock('EmployeeService', array('getEmployee')); $employee = new Employee(); $employee->setEmployeeId('0001'); $employee->setFirstName("rand name"); $employeeService->expects($this->once())->method('getEmployee')->will($this->returnValue($employee)); //mocking LeaveRequestService $leaveRequestService = $this->getMock('LeaveRequestService', array('getEmployeeAllowedToApplyLeaveTypes', 'getOverlappingLeave')); $leaveTypes = TestDataService::loadObjectList('LeaveType', $this->fixture, 'LeaveTypes'); $leaves = TestDataService::loadObjectList('Leave', $this->fixture, 'Leave'); $leaveRequestService->expects($this->once())->method('getOverlappingLeave')->will($this->returnValue($leaves)); $leaveRequestService->expects($this->once())->method('getEmployeeAllowedToApplyLeaveTypes')->will($this->returnValue($leaveTypes)); $applyLeaveAction = new applyLeaveAction($this->context, "leave", "execute"); $applyLeaveAction->setEmployeeNumber('0001'); $applyLeaveAction->setEmployeeService($employeeService); $applyLeaveAction->setLeaveRequestService($leaveRequestService); //mocking the form $form = $this->getMock('ApplyLeaveForm', array('isValid')); $form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $applyLeaveAction->setForm($form); try { $applyLeaveAction->execute($request); $this->assertTrue(!isset($applyLeaveAction->templateMessage['SUCCESS'])); $this->assertTrue(isset($applyLeaveAction->overlapLeaves)); } catch (Exception $e) { } }