From 68723e82febd10a5818c0bd9e8bce335981add4c Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Sun, 12 Aug 2018 22:22:33 -0600 Subject: [PATCH] [add] Searching for full employee data by code Corrected a logical error where the wrong method was being called to get data by code and also made it so the search function only returns names and codes --- .../src/application/EmployeeApplication.php | 43 ++++++++++++++++--- api-payroll/src/settings.php | 1 + 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index efa2a1b..3096abe 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -233,6 +233,33 @@ class EmployeeApplication{ return $results[0]['id']; } + /** + * @param $code string + * @return integer + */ + function getIdEmployeeByCode($code){ + $this->asserts->isNotEmpty($code, "The code can't be empty."); + + $stmt = $this->pdo->prepare("SELECT + COALESCE((SELECT + id + FROM + employees + WHERE + code = :code), + 0) AS id; + "); + + $stmt->execute(array(':code' => $code)); + $results = $stmt->fetchAll(); + if(!$results){ + exit($this->databaseSelectQueryErrorMessage); + } + $stmt = null; + + return $results[0]['id']; + } + /** * Gets the data associated with the employee * @@ -243,18 +270,23 @@ class EmployeeApplication{ $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); $stmt = $this->pdo->prepare("SELECT + e.id AS idEmployee, p.id AS idPerson, p.firstName, p.middleName, IFNULL(p.lastName, '') AS lastName, + p.birthDate, p.email, p.phone, e.code, + et.name AS employeeType, e.contractType FROM employees e INNER JOIN persons p ON p.id = e.idPerson + INNER JOIN + employeeType et ON et.id = e.idEmployeeType WHERE e.id = :idEmployee"); @@ -281,6 +313,7 @@ class EmployeeApplication{ $employeeData = $this->getEmployeeDataById($idEmployee); $response = array( + "idEmployee" => (int)$employeeData['idEmployee'], "idPerson" => (int)$employeeData['idPerson'], "firstName" => $this->cryptographyService->decryptString($employeeData['firstName']), "middleName" => $this->cryptographyService->decryptString($employeeData['middleName']), @@ -289,9 +322,11 @@ class EmployeeApplication{ ? $this->cryptographyService->decryptString($employeeData['lastName']) : '', + "birthDate" => $employeeData['birthDate'], "email" => $this->cryptographyService->decryptString($employeeData['email']), "phone" => $employeeData['phone'], "code" => $employeeData['code'], + "employeeType" => $employeeData['employeeType'], "contractType" => $employeeData['contractType'] ); @@ -306,7 +341,7 @@ class EmployeeApplication{ function getEmployeeDataByCode($code){ $this->asserts->isNotEmpty($code, "The code can't be empty."); - $idEmployee = $this->getIdEmployeeTypeByCode($code); + $idEmployee = $this->getIdEmployeeByCode($code); return $this->proxyGetEmployeeDataById($idEmployee); } @@ -519,14 +554,10 @@ class EmployeeApplication{ $currentEmployee = $this->proxyGetEmployeeDataById($row['id']); $result[] = array( - 'idPerson' => $currentEmployee['idPerson'], 'fullName' => $currentEmployee['firstName']." ". $currentEmployee['middleName']." ". $currentEmployee['lastName'], - 'email' => $currentEmployee['email'], - 'phone' => $currentEmployee['phone'], - 'code' => $currentEmployee['code'], - 'contractType' => $currentEmployee['contractType'] + 'code' => $currentEmployee['code'] ); } diff --git a/api-payroll/src/settings.php b/api-payroll/src/settings.php index 74394c6..4a54cdd 100644 --- a/api-payroll/src/settings.php +++ b/api-payroll/src/settings.php @@ -45,6 +45,7 @@ return [ // Employee settings 'employee' => [ 'codeLength' => '3', + 'contractTypes' => array('INTERNO', 'EXTERNO'), ], ], ];