FEAT_REMOVE_API_LEVEL_CONTEACT : RV

This commit is contained in:
VENKATESHWARAN 2025-07-15 11:12:58 +05:30
parent d145e926e3
commit 6b3df8e8dc
3 changed files with 105 additions and 16 deletions

View File

@ -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');
});

View File

@ -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()

View File

@ -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 = '<?= base_url('util/removeLevelContacts') ?>';
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);
});
}
</script>
<script>