diff --git a/api-payroll/public/html/editEmployee.php b/api-payroll/public/html/editEmployee.php index 1258af8..9106a66 100644 --- a/api-payroll/public/html/editEmployee.php +++ b/api-payroll/public/html/editEmployee.php @@ -103,9 +103,11 @@
Update + Clear + Delete
- \ No newline at end of file + diff --git a/api-payroll/public/html/newEmployee.php b/api-payroll/public/html/newEmployee.php index 99bb0e6..6280575 100644 --- a/api-payroll/public/html/newEmployee.php +++ b/api-payroll/public/html/newEmployee.php @@ -85,9 +85,10 @@
Create + Clear
- \ No newline at end of file + diff --git a/api-payroll/public/html/registerWorkDays.php b/api-payroll/public/html/registerWorkDays.php index 0750ab9..94c02fd 100644 --- a/api-payroll/public/html/registerWorkDays.php +++ b/api-payroll/public/html/registerWorkDays.php @@ -134,6 +134,7 @@
Save + Clear
diff --git a/api-payroll/public/js/editEmployee.js b/api-payroll/public/js/editEmployee.js index 2416684..525b885 100644 --- a/api-payroll/public/js/editEmployee.js +++ b/api-payroll/public/js/editEmployee.js @@ -134,6 +134,43 @@ function loadEmployeeData(code){ }); } +/** + * Will change the status of an employee to remove them from the + * active employee list + */ +function deleteEmployee(){ + let baseUrl = getbaseUrl(); + let code = $('#editEmployeeCode').val(); + + $.ajax({ + url: baseUrl + '/api/employee/' + code, + type: 'DELETE', + dataType: 'json', + success:function(data){ + $('#modalServerResponseSuccess').modal('show'); + document.getElementById('serverResponseSuccess').innerHTML = 'The employee ' + data['firstName'] + ' ' + data['middleName'] + ' ' + data['lastName'] + ' has been deleted.'; + }, + error:function(x,e) { + let responseText = $.parseJSON(x["responseText"]); + + if (x.status==0) { + $('#modalErrorInternetConnection').modal('show'); + } else if(x.status==404) { + $('#modalError404').modal('show'); + } else if(x.status==500) { + $('#modalServerResponseError').modal('show'); + document.getElementById('modalResponseError').innerHTML = responseText['message']; + } else if(e=='parsererror') { + $('#modalErrorParsererror').modal('show'); + } else if(e=='timeout'){ + $('#modalErrorTimeout').modal('show'); + } else { + $('#modalErrorOther').modal('show'); + } + }, + }); +} + function updateEmployee(){ let baseUrl = getbaseUrl(); diff --git a/api-payroll/public/js/landing.js b/api-payroll/public/js/landing.js index 9bb9850..087fa2b 100644 --- a/api-payroll/public/js/landing.js +++ b/api-payroll/public/js/landing.js @@ -1,3 +1,6 @@ +// will contain the current loaded view +let currentView; + /** * Destorys the session for the current user and redirects * back to the login form @@ -59,6 +62,8 @@ function loadView(requestedView){ url: baseUrl + '/html/' + requestedView, type: 'get', success:function(data){ + currentView = requestedView; + $("#newViewBody").hide().html(data).show('slow'); }, error:function(x,e) { @@ -80,4 +85,12 @@ function loadView(requestedView){ } }, }); -} \ No newline at end of file +} + +/** +* Reloads the last view that was accessed as a way of fully clearing and +* resetting the values of the form +*/ +function clearView(view){ + loadView(view); +} diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 3391ea3..bfd6810 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -518,9 +518,19 @@ class EmployeeApplication{ return $response; } - function disableEmployeeRecord($idEmployee){ + /** + * @param $code string + * @return array + * @throws Exception + */ + function disableEmployeeRecord($code){ + $this->asserts->isNotEmpty($code, "The code can't be empty."); + + $idEmployee = $this->getIdEmployeeByCode($code); $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); + $employeeData = $this->proxyGetEmployeeDataById($idEmployee); + try { $stmt = $this->pdo->prepare("UPDATE employees SET @@ -532,8 +542,12 @@ class EmployeeApplication{ $this->pdo->commit(); $stmt = null; + + return $employeeData; + } catch( PDOExecption $e ) { $this->pdo->rollback(); + throw new Exception("The employee you tried to delete could not be found."); } } diff --git a/api-payroll/src/routes.php b/api-payroll/src/routes.php index ee0cd6f..2925699 100644 --- a/api-payroll/src/routes.php +++ b/api-payroll/src/routes.php @@ -65,12 +65,12 @@ $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']; +$app->DELETE('/api/employee/{code}', function (Request $request, Response $response, array $args) { + $code = $args['code']; return $response->withStatus(200) ->withHeader('Content-Type', 'application/json') - ->write(json_encode($this->employeeApplication->disableEmployeeRecord($idEmployee))); + ->write(json_encode($this->employeeApplication->disableEmployeeRecord($code))); }); $app->get('/api/employee/type/{code}', function (Request $request, Response $response, array $args) {