CHANGE_Post_app_having_pre_branch_id - VADIVEL J 2025-09-03

This commit is contained in:
vadivelJ96 2025-10-03 15:52:37 +05:30
parent a58b397e47
commit ae0d624911
8 changed files with 804 additions and 453 deletions

View File

@ -124,6 +124,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) {

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -13,6 +13,9 @@ class HRAccessControlModel extends Model
'pre_hr_id',
'post_hr_id',
'post_client_id',
'pre_client_id',
'pre_branch_id',
'post_branch_id',
'allowed_modules',
'allowed_pre_policies',
'allowed_active_policies',

View File

@ -70,6 +70,13 @@
<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="mdi mdi-format-list-bulleted"
@ -82,7 +89,12 @@
<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="pre_branch_id" id="pre_branch_id"
value="<?= isset($pre_branch_id) ? $pre_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-6">

View File

@ -401,6 +401,57 @@
</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>
let hrAccessControlHtmlAppended = false;
let hrActivityHistoryHtmlAppended = false;
@ -699,7 +750,10 @@
allowed_pre_policies: getCheckedValues(`${userId}_pre_policies`),
allowed_active_policies: getCheckedValues(`${userId}_active_policies`),
allowed_cd: getCheckedValues(`${userId}_cd`),
allowed_claims: getCheckedValues(`${userId}_claims`)
allowed_claims: getCheckedValues(`${userId}_claims`),
pre_branch_id: formData.get(`${userId}_pre_branch_id`),
post_branch_id: formData.get(`${userId}_post_branch_id`),
pre_client_id: formData.get(`${userId}_pre_client_id`)
};
users.push(user);
@ -717,7 +771,10 @@
allowed_pre_policies: user.allowed_pre_policies.length ? `[${user.allowed_pre_policies.join(',')}]` : '[]',
allowed_active_policies: user.allowed_active_policies.length ? `[${user.allowed_active_policies.join(',')}]` : '[]',
allowed_cd: user.allowed_cd.length ? `[${user.allowed_cd.join(',')}]` : '[]',
allowed_claims: user.allowed_claims.length ? `[${user.allowed_claims.join(',')}]` : '[]'
allowed_claims: user.allowed_claims.length ? `[${user.allowed_claims.join(',')}]` : '[]',
pre_client_id: user.pre_client_id || "",
pre_branch_id: user.pre_branch_id || "",
post_branch_id: user.post_branch_id || ""
};
});
@ -971,4 +1028,131 @@
// console.log('--- END ---');
// });
</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>`);
});
$('#pre_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

@ -65,7 +65,10 @@
<div class="row">
<div class="col-12">
<?php if (isset($hr_access_data) && !empty($hr_access_data)) { ?>
<?php if (isset($hr_access_data) && !empty($hr_access_data)) {
$listed_pre = [];
$listed_post = [];
?>
<form id="insuranceForm" onsubmit="submitForm(event)">
<?php foreach ($hr_access_data as $key => $value) {
@ -79,13 +82,17 @@
<input type="hidden" name="<?= 'user' . $key ?>_pre_hr_id" value="<?= $value['pre_hr_id'] ?>">
<input type="hidden" name="<?= 'user' . $key ?>_post_hr_id" value="<?= $value['post_hr_id'] ?>">
<input type="hidden" name="<?= 'user' . $key ?>_post_client_id" value="<?= $value['post_client_id'] ?>">
<input type="hidden" name="<?= 'user' . $key ?>_pre_branch_id" value="<?= $value['pre_branch_id'] ?>">
<input type="hidden" name="<?= 'user' . $key ?>_post_branch_id" value="<?= $value['post_branch_id'] ?>">
<input type="hidden" name="<?= 'user' . $key ?>_pre_client_id" value="<?= $value['pre_client_id'] ?>">
<div class="card-header" onclick="toggleAccordion(this)" style="background-color: #F5FFFF;">
<div class="user-info">
<h5 class="mb-0"><?= $value['hr_name'] ?>
<h5 class="mb-0"> Name -<?= $value['hr_name'] ?>
<!-- <i class="mdi mdi-information-outline" aria-hidden="true" data-id="<?= (!empty($value['pre_hr_id']) ? $value['pre_hr_id'] : 0) . '-' . (!empty($value['post_hr_id']) ? $value['post_hr_id'] : 0) ?>"></i> -->
</h5>
<p class="user-email"><?= $value['hr_mail'] ?></p>
<p style="color: black;"> <b>branch - <?= $value['post_branch_name']?></b></p>
<p class="user-email"> Mail - <?= $value['hr_mail'] ?></p>
</div>
<div class="accordion-icon">
<i class="mdi mdi-chevron-down"></i>
@ -128,6 +135,15 @@
<?php foreach ($pre_policy_data as $key1 => $policies) {
$statusText = $policies['policy_status'] == 1 ? 'Active' : 'In-Active';
$statusClass = $policies['policy_status'] == 1 ? 'active' : 'inactive';
if (
in_array($policies['branch_id'].'-'.$policies['policy_no'], $listed_pre)
&&
$value['pre_branch_id'] != $policies['branch_id']
) {
continue;
} else {
$listed_pre[] = $policies['branch_id'].'-'.$policies['policy_no'];
}
?>
<div class="checkbox-item">
<input type="checkbox" class="policy-checkbox <?= $statusClass ?>" name="<?= 'user' . $key ?>_pre_policies" data-user="<?= $key ?>" data-group="pre" value="<?= $policies['client_policy_id'] ?>"
@ -180,12 +196,26 @@
<?php foreach ($post_policy_data as $key2 => $policies) {
$statusText = $policies['policy_status'] == 1 ? 'Active' : 'In-Active';
$statusClass = $policies['policy_status'] == 1 ? 'active' : 'inactive';
if(
in_array($policies['branch_id'].'-'.$policies['policy_no'] , $listed_post)
&&
$value['post_branch_id'] != $policies['branch_id']
)
{
continue;
}
else
{
$listed_post[] = $policies['branch_id'].'-'.$policies['policy_no'];
}
?>
<div class="checkbox-item">
<input type="checkbox" class="policy-checkbox <?= $statusClass ?>" id="<?= 'user' . $key ?>-gmc2" name="<?= 'user' . $key ?>_active_policies" data-user="<?= $key ?>" data-group="post"
value="<?= $policies['client_policy_id'] ?>" <?php if (in_array($policies['client_policy_id'], $value['allowed_active_policies'])) {
echo 'checked';
} ?>>
&nbsp;&nbsp;
<label for="<?= 'user' . $key ?>-gmc2" style="<?php if ($policies['policy_status'] == 0) {
echo 'color:#ff5757';
} ?>">

View File

@ -1122,6 +1122,29 @@ $(function(){
});
</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>