diff --git a/app/Controllers/Employeedetails.php b/app/Controllers/Employeedetails.php index 88889d22..e20da99c 100755 --- a/app/Controllers/Employeedetails.php +++ b/app/Controllers/Employeedetails.php @@ -452,7 +452,15 @@ class Employeedetails extends BaseController $emailId = $this->request->getPost('emailId'); //print_r($id); - $response = $this->employeedetails_model->checkMailExists($emailId); + $result = $this->employeedetails_model->checkMailExists($emailId); + + $result = $result->getResultArray(); + + $response = [ + "message" => "success", + "data" => $result + ]; + return $this->response->setJSON($response); } @@ -463,8 +471,14 @@ class Employeedetails extends BaseController $panNo = $this->request->getPost('panNo'); //print_r($id); - $response = $this->employeedetails_model->checkPANExists($panNo); - + $result = $this->employeedetails_model->checkPANExists($panNo); + + $result = $result->getResultArray(); + + $response = [ + "message" => "success", + "data" => $result + ]; return $this->response->setJSON($response); @@ -477,7 +491,14 @@ class Employeedetails extends BaseController $aadharNo = $this->request->getPost('aadharNo'); //print_r($id); - $response = $this->employeedetails_model->checkAadharExists($aadharNo); + $result = $this->employeedetails_model->checkAadharExists($aadharNo); + + $result = $result->getResultArray(); + + $response = [ + "message" => "success", + "data" => $result + ]; return $this->response->setJSON($response); } diff --git a/app/Models/Employeedetails_model.php b/app/Models/Employeedetails_model.php index 19decefd..37fcc01a 100755 --- a/app/Models/Employeedetails_model.php +++ b/app/Models/Employeedetails_model.php @@ -139,11 +139,7 @@ class Employeedetails_model extends Model } $query = $builder->get(); - if ($query->getNumRows() > 0) { - return true; - }else{ - return false; - } + return $query; } function checkAadharExists($aadharNo, $Empid = '') @@ -156,30 +152,22 @@ class Employeedetails_model extends Model } $query = $builder->get(); - if ($query->getNumRows() > 0) { - return true; - }else{ - return false; - } + return $query; } - function checkPANExists($PANNo, $Empid = '') + function checkPANExists($panNo, $Empid = '') { $builder = $this->db->table('t_employee_details')->select('PANNo') - ->where('PANNo', $PANNo); + ->where('PANNo', $panNo); if ($Empid != '') { $builder->where('EmpID !=', $Empid); } $query = $builder->get(); - if ($query->getNumRows() > 0) { - return true; - }else{ - return false; - } + return $query; } diff --git a/app/Views/addEmployeenew.php b/app/Views/addEmployeenew.php index 7a05d1a5..f9ab09cf 100755 --- a/app/Views/addEmployeenew.php +++ b/app/Views/addEmployeenew.php @@ -1244,59 +1244,70 @@ } $("#emailid").change(function() { - var emailId = $('#emailid').val(); + var emailId = $('#emailid').val(); - // Validate email before proceeding - if (validateEmail()) { - $('#loader').show(); // Show loader before sending AJAX request + // Validate email before proceeding + if (validateEmail()) { + $('#loader').show(); // Show loader before sending AJAX request - $.ajax({ - data: { - emailId - }, - type: "POST", - url: "employeeEmailExist", - - // Success callback for handling a successful response - success: function(data) { - if (data) { + $.ajax({ + data: { + emailId + }, + type: "POST", + url: "employeeEmailExist", + + // Success callback for handling a successful response + success: function(response) { $('#loader').hide(); // Hide the loader after a successful response + alert(response.message); + console.log(response.data[0]); + console.log(response); + + let responseCheck = response.data[0]; + let responseEmail=response.data[0].EmailId; - // Confirmation dialogue when email already exists - var answer = confirm("Employee mail Id already exists in the database. Kindly Provide us another Email id"); + if(responseCheck ){ + if ( responseEmail == emailId) { + + + // Confirmation dialogue when email already exists + var answer = confirm("Employee mail Id already exists in the database. Kindly Provide us another Email id"); + + + $('#emailid').val(''); // Clear email input if user wants to change + $('#emailid').focus(); // Set focus back to email input - - $('#emailid').val(''); // Clear email input if user wants to change - $('#emailid').focus(); // Set focus back to email input - - } else { - $('#loader').hide(); // Hide loader if no data returned + } else { + $('#loader').hide(); // Hide loader if no data returned + } + } + + }, + + // Error callback to handle any errors in the request + error: function(xhr, status, error) { + $('#loader').hide(); // Ensure the loader is hidden on error + console.log("AJAX Error: ", error); // Log the error for debugging + console.log("Response Status: ", status); // Log status + console.log("XHR Object: ", xhr); // Log full XHR object to see details + alert('An error occurred while checking the email. Please try again.'); // Alert user of the error + }, + + // Complete callback that always runs after the request (whether success or error) + complete: function() { + $('#loader').hide(); // Ensure the loader is always hidden after the request completes } - }, - - // Error callback to handle any errors in the request - error: function(xhr, status, error) { - $('#loader').hide(); // Ensure the loader is hidden on error - console.log("AJAX Error: ", error); // Log the error for debugging - console.log("Response Status: ", status); // Log status - console.log("XHR Object: ", xhr); // Log full XHR object to see details - alert('An error occurred while checking the email. Please try again.'); // Alert user of the error - }, - - // Complete callback that always runs after the request (whether success or error) - complete: function() { - $('#loader').hide(); // Ensure the loader is always hidden after the request completes - } - }); - } + }); + } }); $('#panno').change(function() { var panNo = $('#panno').val(); - if (panNo != '') { + if (validatePAN()) { $('#loader').show(); $.ajax({ data: { @@ -1305,9 +1316,20 @@ type: "POST", url: "employeePANExist", - success: function(data) { + success: function(response) { $('#loader').hide(); - if (data) { + + console.log(panNo); + alert(response.message); + console.log(response.data[0]); + console.log(response); + + + let responseCheck = response.data[0]; + let responsePanNo=response.data[0].PANNo; + + if(responseCheck ){ + if (responsePanNo == panNo) { // alert( data+""+" Employee already exists in the database.Please Change the Pan Card Number"); // $('#panno').val(''); // $('#panno').focus(); @@ -1322,25 +1344,22 @@ } + } + }, complete: function() { $('#loader').hide(); // Ensure the loader is always hidden after the request completes } }); - } else { - //alert(); - alert('Please enter the PAN Number'); - $('#panno').focus(); - return false; - } + } }); // $('#aadharno').change(function() { var aadharNo = $('#aadharno').val(); - if (aadharNo) { + if (ValidateAadhar()) { $('#loader').show(); $.ajax({ data: { @@ -1349,34 +1368,42 @@ type: "POST", url: "employeecheckAadharNoExist", - success: function(data) { + success: function(response) { $('#loader').hide(); - console.log(data); - if (data) { + + console.log(aadharNo); + alert(response.message); + console.log(response.data[0]); + console.log(response); + + let responseCheck = response.data[0]; + let responseAadharNo=response.data[0].AadharNo; + + + //let response=response.data[0]; + if(responseCheck ){ + if ( responseAadharNo == aadharNo) { - var answer = confirm( - " Aadhar details is already exists !!.Kindly Change Aadhar Details" - ) - - $('#aadharno').val(''); - $('#aadharno').focus(); - return false; - + var answer = confirm( + " Aadhar details is already exists !!.Kindly Change Aadhar Details" + ) + + $('#aadharno').val(''); + $('#aadharno').focus(); + return false; + - } + } + } + }, complete: function() { $('#loader').hide(); // Ensure the loader is always hidden after the request completes } }); - } else { - //alert(); - alert('Please enter the Aadhar Number'); - $('#aadharno').focus(); - return false; - } + } }); diff --git a/app/Views/editEmployeenew.php b/app/Views/editEmployeenew.php index 973f5357..36932061 100755 --- a/app/Views/editEmployeenew.php +++ b/app/Views/editEmployeenew.php @@ -353,9 +353,9 @@ if (!empty($EmpDetails)) {
- + *
@@ -913,9 +913,9 @@ if (!empty($EmpDetails)) { value="" title=" : 12 digit number">
- + * employeeEmailExist", - success: function(data) { - $('#loader').hide(); + success: function(response) { + $('#loader').hide(); // Hide the loader after a successful response - if (data != emailId) { - alert(data + "" + + alert(response.message); + console.log(response.data[0]); + console.log(response); + + let responseCheck = response.data[0]; + let responseEmail=response.data[0].EmailId; + + if(responseCheck ){ + if ( responseEmail == emailId) { + alert( "Another Employee already exists !!.Please Change the mail id"); + $("#email").val(''); + $("#email").focus(); return false; + } } }, @@ -1614,7 +1625,7 @@ if (!empty($EmpDetails)) { $('#panno').change(function() { var panNo = $('#panno').val(); - if (panNo != '') { + if (validatePAN() && panNo != "" ) { $('#loader').show(); $.ajax({ data: { @@ -1623,16 +1634,28 @@ if (!empty($EmpDetails)) { type: "POST", url: "employeePANExist", - success: function(data) { + success: function(response) { $('#loader').hide(); - if (data != panNo ) { + + console.log(panNo); + alert(response.message); + console.log(response.data[0]); + console.log(response); + + + let responseCheck = response.data[0]; + let responsePanNo=response.data[0].PANNo; + + if(responseCheck ){ + if (responsePanNo == panNo) { alert( " Employee with this pan number already exists in the database.Please Change the Pan Card Number" ); $('#panno').val(''); $('#panno').focus(); - } + } + } } , @@ -1646,7 +1669,7 @@ if (!empty($EmpDetails)) { $('#aadharno').change(function() { var aadharNo = $('#aadharno').val(); - if (aadharNo != '') { + if (ValidateAadhar() && aadharNo != "" ) { $('#loader').show(); $.ajax({ data: { @@ -1654,9 +1677,21 @@ if (!empty($EmpDetails)) { }, type: "POST", url: "employeecheckAadharNoExist", - success: function(data) { + success: function(response) { $('#loader').hide(); - if (data != aadharNo) { + + console.log(aadharNo); + alert(response.message); + console.log(response.data[0]); + console.log(response); + + let responseCheck = response.data[0]; + let responseAadharNo=response.data[0].AadharNo; + + + //let response=response.data[0]; + if(responseCheck ){ + if ( responseAadharNo == aadharNo) { alert( "Another Employee with this aadhar number already exists ..!!.Please Change the Aadhar card Number" ); @@ -1665,6 +1700,7 @@ if (!empty($EmpDetails)) { } } + } , complete: function() { $('#loader').hide(); // Ensure the loader is always hidden after the request completes