diff --git a/api-payroll/public/html/registerWorkDays.php b/api-payroll/public/html/registerWorkDays.php index 7725ab5..0750ab9 100644 --- a/api-payroll/public/html/registerWorkDays.php +++ b/api-payroll/public/html/registerWorkDays.php @@ -133,7 +133,7 @@
diff --git a/api-payroll/public/js/registerWorkDays.js b/api-payroll/public/js/registerWorkDays.js index 4a175a9..3f4ee8c 100644 --- a/api-payroll/public/js/registerWorkDays.js +++ b/api-payroll/public/js/registerWorkDays.js @@ -213,6 +213,21 @@ function loadSalaryDetails(code){ }); } +/** + * Bootstraper for the save action + * + * If the search by date function has been used it's then assumed that the + * desired action is to update else the function will attempt to create a new + * record for the worked day + */ +function processSaveActionWorkDay(){ + if($('#workDaysSearchByDate').val() === ''){ + saveNewWorkDay(); + }else { + updateNewWorkDay(); + } +} + function saveNewWorkDay(){ let baseUrl = getbaseUrl(); @@ -254,12 +269,52 @@ function saveNewWorkDay(){ }); } +function updateNewWorkDay(){ + let baseUrl = getbaseUrl(); + + let parameters = { + "code":$('#hidenEmployeeCodeForWorkDaysCode').val(), + "idEmployeeTypePerformed":$('#workDaysEmployeePerformedRol').val(), + "deliveries":$('#workDaysEmployeeDeliveries').val(), + "date":$('#workDaysEmployeeWorkedDay').val(), + }; + + $.ajax({ + url: baseUrl + '/api/employee/workday', + type: 'PUT', + dataType: 'json', + data: parameters, + success:function(data){ + $('#modalServerResponseSuccess').modal('show'); + document.getElementById('serverResponseSuccess').innerHTML = data['message']; + loadSalaryDetails($('#hidenEmployeeCodeForWorkDaysCode').val()); + }, + 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'); + } + }, + }); +} + /** * 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();