diff --git a/api-payroll/public/html/editEmployee.php b/api-payroll/public/html/editEmployee.php index 127bb48..1258af8 100644 --- a/api-payroll/public/html/editEmployee.php +++ b/api-payroll/public/html/editEmployee.php @@ -50,7 +50,7 @@ -
+
@@ -102,7 +102,7 @@
diff --git a/api-payroll/public/js/editEmployee.js b/api-payroll/public/js/editEmployee.js index abae2a8..c51e545 100644 --- a/api-payroll/public/js/editEmployee.js +++ b/api-payroll/public/js/editEmployee.js @@ -6,6 +6,14 @@ $(document).ready(function(){ loadEmployeeTypes(); + $('.datepicker').datepicker({ + format: "yyyy/mm/dd", + autoclose: true + }); + + // Not to be edited + $("#hidenEmployeeCode").hide(); + // Setting up bloodhound typeahead let employeesList = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace("name"), @@ -130,24 +138,25 @@ function updateEmployee(){ let baseUrl = getbaseUrl(); let parameters = { - "firstName":$('#newEmployeeFirstName').val(), - "middleName":$('#newEmployeeMiddleName').val(), - "lastName":$('#newEmployeeLastName').val(), - "birthDate":$('#newEmployeeBirthDate').val(), - "email":$('#newEmployeeEmail').val(), - "phone":$('#newEmployeePhone').val(), - "idEmployeeType":$('#newEmployeeType').val(), - "contractType":$('#NewEmpployyContractType').val() + "firstName":$('#editEmployeeFirstName').val(), + "middleName":$('#editEmployeeMiddleName').val(), + "lastName":$('#editEmployeeLastName').val(), + "birthDate":$('#editEmployeeBirthDate').val(), + "code":$('#editEmployeeCode').val(), + "email":$('#editEmployeeEmail').val(), + "phone":$('#editEmployeePhone').val(), + "idEmployeeType":$('#editEmployeeType').val(), + "contractType":$('#editEmployeeContractType').val() }; $.ajax({ url: baseUrl + '/api/employee', - type: 'POST', + type: 'PUT', dataType: 'json', data: parameters, success:function(data){ $('#modalServerResponseSuccess').modal('show'); - document.getElementById('serverResponseSuccess').innerHTML = 'The employee ' + data['fullName'] + ' has been created with the code ' + data['employeeCode']; + document.getElementById('serverResponseSuccess').innerHTML = 'The employee ' + data['fullName'] + ' has been updated.'; }, error:function(x,e) { let responseText = $.parseJSON(x["responseText"]); diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 4c5f8d1..cc52e32 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -420,15 +420,12 @@ class EmployeeApplication{ */ function updateEmployeeData($requestData){ // Getting and validating the data - $idEmployee = $requestData['idEmployee']; - $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); - - $idPerson = $this->getIdPersonByIdEmployee($idEmployee); - $this->asserts->higherThanZero($idPerson, "idPerson must be higher than 0"); - $code = $requestData['code']; $this->asserts->isNotEmpty($code, "The code can't be empty."); + $idEmployee = $this->getIdEmployeeByCode($code); + $idPerson = $this->getIdPersonByIdEmployee($idEmployee); + $firstName = $requestData['firstName']; $this->asserts->isNotEmpty($firstName, "The first name can't be empty."); $this->asserts->isString($firstName, "The first name must be a string.");