From 3ad687f797b8930bc2d283e82252bf9c9960f7ec Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Wed, 15 Aug 2018 00:31:18 -0600 Subject: [PATCH] [add] Data loaded to be edited --- api-payroll/public/html/registerWorkDays.php | 10 +++- api-payroll/public/js/registerWorkDays.js | 53 ++++++++++++++++++- .../src/application/EmployeeApplication.php | 18 ++++++- 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/api-payroll/public/html/registerWorkDays.php b/api-payroll/public/html/registerWorkDays.php index 0bd287b..7725ab5 100644 --- a/api-payroll/public/html/registerWorkDays.php +++ b/api-payroll/public/html/registerWorkDays.php @@ -10,12 +10,20 @@
- +
+
+
+ +
+ +
+
+
diff --git a/api-payroll/public/js/registerWorkDays.js b/api-payroll/public/js/registerWorkDays.js index 83bda05..4a175a9 100644 --- a/api-payroll/public/js/registerWorkDays.js +++ b/api-payroll/public/js/registerWorkDays.js @@ -7,7 +7,7 @@ $(document).ready(function(){ loadEmployeeTypesForWorkDays(); $('.datepicker').datepicker({ - format: "yyyy/mm/dd", + format: "yyyy-mm-dd", autoclose: true }); @@ -252,4 +252,53 @@ function saveNewWorkDay(){ } }, }); -} \ No newline at end of file +} + +/** + * If the search by date field is changed from its default empty status it'll + * load the data of the given work day and enable the update mode + */ +$('#workDaysSearchByDate').on("change", function(data){ + console.log($(this).val()); + let baseUrl = getbaseUrl(); + let date = $(this).val(); + let code = $('#hidenEmployeeCodeForWorkDaysCode').val(); + + // The employee hasn't been picked + if (code === ''){ + $('#modalServerResponseError').modal('show'); + document.getElementById('modalResponseError').innerHTML = 'Please select an employee in the search form first.'; + return false; // Exits the function + } + + $.ajax({ + url: baseUrl + '/api/employee/salary/date/' + date + '/code/' + code, + type: 'GET', + dataType: 'json', + success:function(data){ + $('#workDaysEmployeeRol').val(data['idEmployeeType']); + $('#workDaysEmployeeContractType').val(data['contractType']); + $('#workDaysEmployeeWorkedDay').val(date); + $('#workDaysEmployeeDeliveries').val(data['deliveries']); + $('#workDaysEmployeePerformedRol').val(data['idEmployeeTypePerformed']); + }, + 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'); + } + }, + }); +}); \ No newline at end of file diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 2fb7df6..ba70cb0 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -915,11 +915,25 @@ class EmployeeApplication{ $results = $stmt->fetchAll(); if(!$results){ - throw new Exception("No data of the work day was found.."); + throw new Exception("No data of the work day was found."); } $stmt = null; - return $results; + foreach($results as $row){ + $data = array( + 'idPaymentPerEmployeePerDay' => (int)$row['idPaymentPerEmployeePerDay'], + 'idEmployeeType' => (int)$row['idEmployeeType'], + 'idEmployeeTypePerformed' => (int)$row['idEmployeeTypePerformed'], + 'contractType' => $row['contractType'], + 'hoursWorked' => (int)$row['hoursWorked'], + 'paymentPerHour' => (int)$row['paymentPerHour'], + 'bonusPerHour' => (int)$row['bonusPerHour'], + 'deliveries' => (int)$row['deliveries'], + 'paymentPerDelivery' => (int)$row['paymentPerDelivery'] + ); + } + + return $data; } /**