diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a6cef1ed..920fa023 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -360,6 +360,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('removeInstallments', 'LeadsController::removeInstallments'); $routes->get('viewHrAccessData', 'ClientController::viewHrAccessData'); $routes->post('saveHrAccessData', 'ClientController::saveHrAccessData'); + $routes->post('removeLevelContacts', 'ClientController::removeLevelContacts'); }); $routes->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 4b09e9ae..f2efbf1b 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -143,7 +143,7 @@ class ClientController extends AdminController // Perform the query $builder = $db->table($table); - $isDuplicate = $builder->where($field, $value)->countAllResults() > 0; + $isDuplicate = $builder->where($field, $value)->where('is_active', 1)->countAllResults() > 0; // Return the result return $this->response->setJSON(['isDuplicate' => $isDuplicate]); @@ -1171,6 +1171,40 @@ class ClientController extends AdminController } } + public function removeLevelContacts() + { + $id = $this->request->getGet('id'); + try { + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'message' => 'Invalid ID provided. ID is empty', + 'data' => $id + ], 400); + } + + $updated = $this->levelContactModel->update($id, ['is_active' => 0]); + + if ($updated === false) { + return $this->respond([ + 'status' => false, + 'message' => 'Failed to remove contact' + ], 500); + } + + return $this->respond([ + 'status' => true, + 'message' => 'Contact removed successfully' + ]); + } catch (\Exception $e) { + return $this->respond([ + 'status' => false, + 'message' => 'An error occurred: ' . $e->getMessage() + ], 500); + } + } + + public function createClientPolicy() diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index 708a66df..b8f4cd05 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -580,12 +580,12 @@ $('body').on('click', '.btnBranchEdit', function() { console.log(branch_form_action); }); -$("#remove_btn").click(function() { - $("#name").val(''); - $("#email").val(''); - $("#mobile").val(''); - $("#designation").val(''); -}) +// $("#remove_btn").click(function() { +// $("#name").val(''); +// $("#email").val(''); +// $("#mobile").val(''); +// $("#designation").val(''); +// }) // Initialize the contact count function appendContactHtml(contact = false, reset = false) { @@ -644,21 +644,68 @@ function appendContactHtml(contact = false, reset = false) { } +// function removeContact(button) { +// var uniqueId = button.id.split("_")[0]; +// var contactSection = document.getElementById(uniqueId); + +// if (contactSection) { +// contactSection.parentNode.removeChild(contactSection); +// contactCount--; + +// if (contactCount < 3) { +// var addButton = document.querySelector('.ac'); +// if (addButton) { +// addButton.style.display = 'block'; +// } +// } +// } +// } + function removeContact(button) { + var uniqueId = button.id.split("_")[0]; + console.log('uniqueId', uniqueId); var contactSection = document.getElementById(uniqueId); + console.log('contactSection', contactSection); - if (contactSection) { - contactSection.parentNode.removeChild(contactSection); - contactCount--; + confirmActionSweertAlert("Do you want to remove this contact?", "Yes, Proceed!", "No, Cancel").then((confirmed) => { + if(confirmed){ + if (contactSection) { - if (contactCount < 3) { - var addButton = document.querySelector('.ac'); - if (addButton) { - addButton.style.display = 'block'; + let unique_param = uniqueId + '_branch_table_pk'; + console.log('unique_param', unique_param); + let other_id = $('#' + unique_param).val(); + console.log('other_id', other_id); + + contactSection.parentNode.removeChild(contactSection); + contactCount--; + + if (contactCount < 3) { + var addButton = document.querySelector('.ac'); + if (addButton) { + addButton.style.display = 'block'; + } + } + + if(other_id){ + removeLevelContacts(other_id); + } + + }else{ + + $("#name").val(''); + $("#email").val(''); + $("#mobile").val(''); + $("#designation").val(''); + + let first_id = $('#branch_table_pk').val(); + console.log('first_id', first_id); + if(first_id){ + removeLevelContacts(first_id); + } } } - } + }); } function storeButtonId(id) { @@ -839,6 +886,30 @@ function getContactsData() { return contacts; } +function removeLevelContacts(id){ + + let url = ''; + + let requestData = { + id: id, + }; + + // Send AJAX request + sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) { + + console.log('Data fetched successfully:', response); + if (response.status == true) { + toastr.success(response.message, 'SUCCESS'); + } else { + toastr.warning(response.message, 'WARNING'); + } + + }, function(xhr, status, error) { + console.error('Error fetching data:', error); + console.error(xhr.responseText); + }); +} +