From 6b3df8e8dc4e59bf7a43a5c0fcc6889aff006b8e Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Tue, 15 Jul 2025 11:12:58 +0530 Subject: [PATCH] FEAT_REMOVE_API_LEVEL_CONTEACT : RV --- app/Config/Routes.php | 2 +- app/Controllers/ClientController.php | 35 +++++++++++- app/Views/client_branch.php | 84 +++++++++++++++++++++++----- 3 files changed, 105 insertions(+), 16 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 84a7478..b19ad2e 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -344,7 +344,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->post('saveSIMapping','ClientController::saveSIMapping'); $routes->post('checkSIMapping','ClientController::checkSIMapping'); $routes->post('deleteMapping','ClientController::deleteMapping'); - + $routes->get('removeLevelContacts','ClientController::removeLevelContacts'); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index db83cc7..e1523c0 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -138,7 +138,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]); @@ -1034,6 +1034,39 @@ 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 875de04..9ef5c5a 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -509,6 +509,8 @@ $('body').on('click', '.btnBranchEdit', function() { dataType: 'json', success: function(res) { + console.log('client branch edit data response : ', res); + setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); @@ -582,12 +584,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) { @@ -647,20 +649,50 @@ function appendContactHtml(contact = false, reset = false) { } 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) { @@ -841,6 +873,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); + }); +} +