From ba307555f08f0a2807d799e4e9b704e4400a436a Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Mon, 6 Aug 2018 03:33:18 -0600 Subject: [PATCH] [add] Delete employee --- .../src/application/EmployeeApplication.php | 17 +++++++++++++++++ api-payroll/src/routes.php | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 7ff7d12..6cf237a 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -387,5 +387,22 @@ class EmployeeApplication{ return $response; } + + function disableEmployeeRecord($idEmployee){ + try { + $stmt = $this->pdo->prepare("UPDATE employees + SET + status = 'INACTIVE' + WHERE + id = :idEmployee"); + $this->pdo->beginTransaction(); + $stmt->execute(array(':idEmployee' => $idEmployee)); + $this->pdo->commit(); + + $stmt = null; + } catch( PDOExecption $e ) { + $this->pdo->rollback(); + } + } } ?> \ No newline at end of file diff --git a/api-payroll/src/routes.php b/api-payroll/src/routes.php index def91f3..7c3337e 100644 --- a/api-payroll/src/routes.php +++ b/api-payroll/src/routes.php @@ -57,6 +57,13 @@ $app->put('/api/employee', function ($request, $response) { ->write(json_encode($this->employeeApplication->updateEmployeeData($requestData))); }); +$app->DELETE('/api/employee/{idEmployee}', function (Request $request, Response $response, array $args) { + $idEmployee = $args['idEmployee']; + + return $response->withStatus(200) + ->withHeader('Content-Type', 'application/json') + ->write(json_encode($this->employeeApplication->disableEmployeeRecord($idEmployee))); +}); $app->get('/api/employee/type/{code}', function (Request $request, Response $response, array $args) { $code = $args['code'];