CHANGE_Pre_app_having_post_branch_id - VADIVEL J 2025-09-03

This commit is contained in:
vadivelJ96 2025-10-03 18:18:13 +05:30
parent ecd0fcf756
commit 537cdf834e
6 changed files with 328 additions and 0 deletions

View File

@ -97,6 +97,8 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) {
$routes->post("edit", "ClientController::editClientBranch");
$routes->get("list/(:any)", "ClientController::getSingleBranchDataById/$1");
$routes->get("remove/(:any)", "ClientController::removeClientBranch/$1");
$routes->post("auto_fetch_branch","ClientController::auto_fetch_branch");
$routes->post("auto_fetch_branch_details","ClientController::auto_fetch_branch_details");
});
$routes->group("relation", ["filter" => "authMVC"], function ($routes) {

View File

@ -481,6 +481,10 @@ class ClientController extends AdminController
// dd($data['placeHolders']);
// auto fetch client list and branch list from pre
$data['auto_fetch_client_list'] = $this->getClientListFromPost();
echo view('layout/header', $headerData);
echo view('client_onboarding', $data);
echo view('layout/footer');
@ -620,6 +624,8 @@ class ClientController extends AdminController
$editData['client_policy']['role'] = get_role_id();
$editData['notification'] = $this->notificationModel->select('template_name,enabled')->where('client_id', $id)->findAll();
$editData['placeHolders'] = ['member_name', 'member_mobile', 'nhance_logo', 'tpa_id', 'ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
$editData['auto_fetch_client_list'] = $this->getClientListFromPost();
// dd($editData);
echo view('layout/header', $headerData);
@ -5129,4 +5135,102 @@ class ClientController extends AdminController
return $this->respond(['status' => true, 'message' => 'Demo client data wiped successfully'], 200);
}
private function getClientListFromPost (){
$db2 = \Config\Database::connect('postDB');
$auto_fetch_client_list = $db2->table('clients')
->select('id,client_name')
->where('is_active',1)
->get()->getResultArray()??[];
return $auto_fetch_client_list;
}
public function auto_fetch_branch(){
$data = $this->request->getPost();
$db2 = \Config\Database::connect('postDB');
$auto_fetch_branch_list = $db2->table('client_branch')
->select('id,branch_name')
->where('client_id',$data['client_id'])
->where('is_active',1)
->get()->getResultArray()??[];
return
empty($auto_fetch_branch_list)
? $this->response->setJSON([
'status' => false,
'message' => 'branch list is empty',
'data' => []
])->setStatusCode(400)
: $this->response->setJSON([
'status' => true,
'message' => 'branch list is found' ,
'data' => $auto_fetch_branch_list
])->setStatusCode(200);
}
public function auto_fetch_branch_details(){
$data = $this->request->getPost();
$db2 = \Config\Database::connect('postDB');
$auto_fetch_branch_details = $db2->table('client_branch')
->where('client_id',$data['client_id'])
->where('id',$data['branch_id'])
->where('is_active',1)
->get()->getResultArray()??[];
return empty($auto_fetch_branch_details)
? $this->response->setJSON([
'status' => false,
'message' => 'branch details is empty',
'data' => []
])->setStatusCode(400)
: $this->response->setJSON([
'status' => true,
'message' => 'branch details found' ,
'data' => $auto_fetch_branch_details
])->setStatusCode(200);
}
}

View File

@ -25,6 +25,7 @@ class ClientBranchModel extends Model
"gst",
"sez",
"units",
"post_branch_id"
];
public function getBranchAndContactByBranchId($branch_id){

View File

@ -70,6 +70,12 @@
<div class="row" id="add_branch">
<div class="col-12">
<div class="card-body">
<div class="row float-left" style="position: relative; bottom: 20px; left: 13px;">
<button type="button" id="btnAutoBranchFetch"
class="btn btn-primary waves-effect waves-light btn-sm "> Auto Fetch branch Details</button>
</div>
<div class="row float-right" style="position: relative; bottom: 20px; right: 13px;">
<button type="button" id="btnBranchBack"
class="btn btn-primary waves-effect waves-light btn-sm btnBack"><span class="fa fa-list"
@ -79,10 +85,22 @@
<hr>
<form role="form" class="parsley-examples" method="post" id="branch_form" enctype="multipart/form-data">
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<input type="hidden" name="client_id" id="client_id_branch"
value="<?= isset($client['id']) ? $client['id'] : '' ?>" />
<input type="hidden" name="post_branch_id" id="post_branch_id"
value="<?= isset($post_branch_id) ? $post_branch_id : '' ?>" />
<input type="hidden" name="branch_id_primarykey" id="branch_id_primarykey" />
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">

View File

@ -110,6 +110,57 @@ body {
</div>
<div class="modal fade" id="autoFetchBranchModal" tabindex="-1" role="dialog" aria-labelledby="autoFetchBranchModalLabel" accesskey=""
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" style="margin-left: 400px !important;">
<div class="modal-content modal-lg">
<div class="modal-header">
<h5 class="modal-title" id="autoFetchBranchModalLabel">Auto Fetch Branch Details</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" style="min-height:auto !important;">
<div class="row">
<div class="col-md-6">
<div class="form-group col-md-12">
<label for="auto_fetch_client">Client List<span class="text-danger">*</span></label>
<select class="form-control" id="auto_fetch_client" name="auto_fetch_client" required>
<option value="">Select Client</option>
<?php if (!empty($auto_fetch_client_list)): ?>
<?php foreach ($auto_fetch_client_list as $client_list): ?>
<option value="<?= esc($client_list['id']) ?>">
<?= esc($client_list['client_name']) ?>
</option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group col-md-12">
<label for="auto_fetch_branch">Branch List<span class="text-danger">*</span></label>
<select class="form-control" id="auto_fetch_branch" name="auto_fetch_branch" required>
<option value="">Select Branch</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn cancel-btn" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary submit-btn" id="submitAutoFetch">Submit</button>
</div>
</div>
</div>
</div>
</div>
<script>
// $(document).ready(function(){
@ -250,3 +301,132 @@ body {
</script>
<script>
$('#btnAutoBranchFetch').click(function() {
var myModal = new bootstrap.Modal(document.getElementById('autoFetchBranchModal'));
myModal.show();
})
</script>
<script>
$('#auto_fetch_client').change(function() {
$('#auto_fetch_branch').html(`<option value="">Select Branch</option>`);
$.ajax({
url: "<?php echo base_url('client/branch/auto_fetch_branch'); ?>",
type: "POST",
data: {
client_id: $('#auto_fetch_client').val()
},
dataType: "json",
success: function(response, textStatus, xhr) {
if (xhr.status === 200) {
let options = `<option value="">Select Branch</option>`;
response.data.forEach((data) => {
options += `<option value="${data.id}">${data.branch_name}</option>`;
});
$('#auto_fetch_branch').html(options);
} else {
$('#auto_fetch_branch').html('<option value="">No Branch Found</option>');
}
},
error: function(xhr, status, error) {
console.error("Error occurred:", status, error);
},
complete: function() {
console.log("auto_fetch_client call is completed..!!");
}
});
});
</script>
<script>
$('#submitAutoFetch').click(function() {
let client_id = $('#auto_fetch_client').val();
let branch_id = $('#auto_fetch_branch').val();
if (client_id == "" || branch_id == "") {
Swal.fire({
icon: 'warning',
title: 'Missing Data',
text: 'Please select both Client and its Branch!',
confirmButtonText: 'OK'
});
return;
}
$.ajax({
url: "<?php echo base_url('client/branch/auto_fetch_branch_details'); ?>",
type: "POST",
data: {
client_id,
branch_id
},
dataType: "json",
success: function(response, textStatus, xhr) {
if (xhr.status === 200) {
let result = response.data[0]??[];
if(response.data[0] == []){
console.log("Empty array ..!!!");
return;
}
let units = JSON.parse(result['units']);
let $select = $('#selected');
$select.empty();
units.forEach(unit => {
// If you want to mark them as selected, set 'selected' attribute
$select.append(`<option value="${unit}" selected>${unit}</option>`);
});
$('#post_branch_id').val(branch_id);
$('#branch_name').val(result['branch_name']??'');
$('#branch_code').val(result['branch_code']??'');
$('#address1').val(result['address1']??'');
$('#address2').val(result['address2']??'');
$('#state').val(result['state']??'');
$('#district').val(result['district']??'');
$('#branch_city').val(result['city']??'');
$('#pincode').val(result['pincode']??'');
$('#gst').val(result['gst']??'');
$('#sez').val(result['sez']??'');
} else {
console.log("User Error thrown");
console.log("status" + xhr.status);
}
closeModalById('autoFetchBranchModal');
},
error: function(xhr, status, error) {
console.error("Error occurred:", status, error);
},
complete: function() {
console.log("auto_fetch_branch_details call is completed..!!");
}
})
})
</script>

View File

@ -932,6 +932,29 @@ function confirmActionSweertAlert(message = "Are you sure?", confirmText = "Yes,
</script>
<script>
function closeModalById(modalId) {
// Get the modal element
var modal = document.getElementById(modalId);
if (!modal) return; // Exit if no modal found
// Hide it by removing "show" or "in" classes and setting display:none
modal.style.display = 'none';
modal.classList.remove('in', 'show'); // 'in' for BS3, 'show' for BS4/5
modal.setAttribute('aria-hidden', 'true');
modal.removeAttribute('aria-modal'); // optional
modal.removeAttribute('role'); // optional
// Remove backdrop if present
var backdrop = document.querySelector('.modal-backdrop');
if (backdrop) backdrop.remove();
// Allow page scrolling again
document.body.classList.remove('modal-open');
}
</script>
</body>
</html>