nhance/app/Views/client_onboarding.php
2026-03-12 15:25:56 +05:30

1181 lines
43 KiB
PHP
Executable File

<style>
body {
.multiselect-native-select {
position: relative;
/* bottom: 32px; */
select {
border: 0 !important;
clip: rect(0 0 0 0) !important;
height: 1px !important;
margin: -1px -1px -1px -3px !important;
overflow: hidden !important;
padding: 0 !important;
position: absolute !important;
width: 1px !important;
left: 50%;
top: 30px;
}
}
.multiselect-container {
width: 100% !important;
}
.multiselect-selected-text {
float: left !important;
}
}
.readonly-select {
pointer-events: none;
/* background-color: #f0f0f0; */
background-color: #e0e0e0;
color: #666;
}
</style>
<style>
body {
background-color: #f8f9fa;
font-size: 14px;
}
.user-card {
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(77, 77, 77, 0.3);
margin-bottom: 12px;
overflow: hidden;
transition: all 0.3s ease;
}
.user-card:hover {
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.card-header {
background: #d6d6d6;
color: white;
padding: 12px 18px;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
transition: background 0.3s ease;
}
.card-header:hover {
background: #b4bec5;
}
.user-info h5 {
margin-bottom: 2px;
font-size: 1.1em;
color: #121212;
}
.user-email {
font-size: 0.85em;
opacity: 0.9;
margin: 0;
color: rgb(56, 55, 55);
}
.accordion-icon {
font-size: 1.2em;
transition: transform 0.3s ease;
color: #121212;
}
.accordion-icon.active {
transform: rotate(180deg);
}
.card-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.4s ease;
background: white;
}
.card-content.active {
max-height: 500px;
overflow-y: auto;
}
.content-inner {
padding: 18px;
}
.section {
background: #d6dce1;
border-radius: 6px;
padding: 12px;
border: 1px solid #e9ecef;
margin-bottom: 12px;
transition: all 0.3s ease;
}
.section:hover {
border-color: #667eea;
box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}
.section-title {
font-weight: 600;
margin-bottom: 8px;
color: #121212;
font-size: 0.95em;
display: flex;
align-items: center;
}
.main-checkbox {
margin-right: 8px;
transform: scale(1.1);
cursor: pointer;
}
.checkbox-group {
margin-left: 24px;
transition: all 0.3s ease;
max-height: 225px;
overflow-y: auto;
padding-right: 8px;
overflow-x: hidden;
}
.checkbox-group::-webkit-scrollbar {
width: 4px;
}
.checkbox-group::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 2px;
}
.checkbox-group::-webkit-scrollbar-thumb {
background: #667eea;
border-radius: 2px;
}
.checkbox-group::-webkit-scrollbar-thumb:hover {
background: #5a6fd8;
}
.checkbox-item {
display: flex;
align-items: center;
padding: 4px 8px;
border-radius: 4px;
transition: background 0.2s ease;
/* margin-bottom: 3px; */
margin-bottom: -7px;
}
.checkbox-item:hover {
background: rgba(102, 126, 234, 0.1);
}
.checkbox-item input[type="checkbox"] {
transform: scale(1.05);
cursor: pointer;
margin-right: 6px;
}
.checkbox-item label {
cursor: pointer;
user-select: none;
margin: 0;
font-size: 0.9em;
}
.hidden {
opacity: 0;
max-height: 0 !important;
overflow: hidden;
margin: 0;
padding: 0;
}
.policy-number {
font-family: monospace;
font-size: 0.8em;
color: #6c757d;
}
.submit-container {
background: white;
padding: 18px;
border-radius: 8px;
/* box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); */
margin-top: 20px;
text-align: right;
}
/* .btn-submit {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
padding: 10px 30px;
font-weight: 600;
border-radius: 25px;
transition: all 0.3s ease;
}
.btn-submit:hover {
background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
} */
.output-container {
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 15px;
margin-top: 20px;
display: none;
}
.output-table {
font-family: monospace;
font-size: 0.85em;
white-space: pre-wrap;
background: white;
padding: 10px;
border-radius: 4px;
border: 1px solid #dee2e6;
}
#hr_activity_history_append_area {
padding-top: 0;
margin-top: 0;
background-color: #F5FFFF !important;
border: 2px solid #F5FFFF;
border-radius: 10px;
box-shadow: 0px 4px 4px 0px #00000040;
}
#hr_activity_history_append_area tbody tr {
background-color: white !important;
}
</style>
<div class="row" id="client_add">
<div class="col-12">
<div class="card">
<div class="card-body">
<script>
var pageSubTitle = 'Client Onboarding <span id="client_heading"><?php if (isset($client)) { echo ' - ' . addslashes($client['client_name']); } ?></span>';
var pageBackButton = '<a href="<?= base_url("client/list"); ?>" aria-label="Back to list"><i class="mdi mdi-arrow-left" style="font-size: 17px;"></i></a>';
</script>
<!-- <div class="row" style="padding-bottom: 10px;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Client Onboarding <span id="client_heading"><?php if (isset($client)) { echo ' - ' . $client['client_name']; } ?></span> </h4>
</div>
<div class="col-6" style="text-align: right;">
<a href="<?= base_url("client/list"); ?>"><i class="mdi mdi-arrow-left" style="font-size: 17px;"></i></a>
</div>
</div> -->
<br>
<div class="tab-wrapper position-relative">
<!-- Left Arrow -->
<ul class="nav nav-pills navtab-bg" id="myTab">
<li class="nav-item ">
<button class="scroll-btn left-btn" type="button">&#9664;</button>
</li>
<li class="nav-item">
<a href="#general-q-tab" data-toggle="tab" aria-expanded="false"
class="nav-link px-3 py-2 active" id="general_tab">
<span class="mr-1"><i class="mdi mdi-contacts"></i></span>
<span class="d-none d-sm-inline-block">General</span>
</a>
</li>
<li class="nav-item">
<a href="#KYC-DOC-tab" data-toggle="tab" aria-expanded="true" class="nav-link px-3 py-2" id="kyc_tab">
<span class="mr-1"><i class="mdi mdi-file"></i></span>
<span class="d-none d-sm-inline-block">KYC Docs</span>
</a>
</li>
<li class="nav-item">
<a href="#RM-tab" data-toggle="tab" aria-expanded="true" class="nav-link px-3 py-2" id="RM_tab">
<span class="mr-1"><i class="mdi mdi-account-switch"></i></span>
<span class="d-none d-sm-inline-block"> Relationship Manager</span>
</a>
</li>
<li class="nav-item">
<a href="#branch-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="branch_tab">
<span class="mr-1"><i class="mdi mdi-source-branch"></i></span>
<span class="d-none d-sm-inline-block">Branch & Contacts</span>
</a>
</li>
<li class="nav-item">
<a href="#notification-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="notification_tab">
<span class="mr-1"><i class="mdi mdi-bell"></i></span>
<span class="d-none d-sm-inline-block">Notifications</span>
</a>
</li>
<li class="nav-item">
<a href="#police-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="policy_tab">
<span class="mr-1"><i class="mdi mdi-book-open-page-variant"></i></span>
<span class="d-none d-sm-inline-block">Policies</span>
</a>
</li>
<li class="nav-item">
<a href="#hr-access-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="hr_access_tab" onclick="appendHrAccessControllHtml(this)">
<span class="mr-1"><i class="mdi mdi-book-open-page-variant"></i></span>
<span class="d-none d-sm-inline-block">Client Access Control</span>
<!-- Name Changed "HR Access Controll" into "Client Access Control" -->
</a>
</li>
<li class="nav-item">
<a href="#hr-activity-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="hr_activity_tab" onclick="appendHrActivityHistoryHtml(this)">
<span class="mr-1"><i class="mdi mdi-book-open-page-variant"></i></span>
<span class="d-none d-sm-inline-block">HR Activity</span>
</a>
</li>
<!-- <li class="nav-item">
<a href="#api-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="api_tab">
<span class="mdi mdi-api"></span>
<span class="d-none d-sm-inline-block">API</span>
</a>
</li> -->
<!-- <li class="nav-item">
<a href="#others-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2" id="others_tab">
<span class="mr-1"><i class="mdi mdi-tag-text-outline"></i></span>
<span class="d-none d-sm-inline-block">Others</span>
</a>
</li> -->
<li class="nav-item">
<button class="scroll-btn right-btn" type="button">&#9654;</button>
</li>
</ul>
</div>
<div class="tab-content">
<div class="tab-pane fade" id="hr-access-tab">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body" id="hr_access_append_area">
</div>
</div>
</div> <!-- end col -->
</div>
</div>
<div class="tab-pane fade" id="hr-activity-tab">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body" id="hr_activity_history_append_area">
</div>
</div>
</div> <!-- end col -->
</div>
</div>
<?php include("client_api.php"); ?>
<?php // include('client_others_tab.php');
?>
<?php include('notification.php'); ?>
<?php include('client_basic_info.php'); ?>
<?php include('client_kyc.php'); ?>
<?php include('client_rm.php'); ?>
<?php include('client_branch.php'); ?>
<?php include('client_policy.php'); ?>
</div>
</div>
</div>
</div>
</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">Fetch Client Branch (Pre-Enrolment)</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 select2" 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 select2" 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;
let newBranchSavedPeaseCallTheHrAccessFormApi = false;
function client_kyc_docs() {
var check_client_id = $('#general_PrimaryKey');
if (check_client_id[0].value == '' || check_client_id[0].value == null || check_client_id[0].value == 0) {
$('#btnBranchAdd').hide();
toastr.warning('Please Add the Client!', 'Warning', {
timeOut: 2000
});
} else {
if ($('#btnBranchBack')[0].style.display == 'none') {
$('#btnBranchAdd').show();
}
}
}
function client_relationship_manager() {
var check_client_id = $('#general_PrimaryKey');
if (check_client_id[0].value == '' || check_client_id[0].value == null || check_client_id[0].value == 0) {
$('#relation_form').hide();
toastr.warning('Please Add the Client!', 'Warning', {
timeOut: 2000
});
} else {
$('#relation_form').show();
}
}
function client_policies() {
var check_client_id = $('#general_PrimaryKey').val();
if (check_client_id == '' || check_client_id == null || check_client_id == 0) {
$('#BtnAdd').hide();
toastr.warning('Please Add the Client!', 'Warning', {
timeOut: 2000
});
} else {
if ($('#btnPolicyBack')[0].style.display == 'none') {
$('#BtnAdd').show();
}
}
}
function client_branch_contact() {
var check_client_id = $('#general_PrimaryKey');
if (check_client_id[0].value == '' || check_client_id[0].value == null || check_client_id[0].value == 0) {
$('#btnBranchAdd').hide();
toastr.warning('Please Add the Client!', 'Warning', {
timeOut: 2000
});
} else {
if ($('#btnBranchBack')[0].style.display == 'none') {
$('#btnBranchAdd').show();
}
}
}
function client_notification() {
var check_client_id = $('#general_PrimaryKey');
if (check_client_id[0].value == '' || check_client_id[0].value == null || check_client_id[0].value == 0) {
$('#notification-tab').hide();
toastr.warning('Please Add the Client!', 'Warning', {
timeOut: 2000
});
} else {
if ($('#notification-tab')[0].style.display == 'none') {
$('#notification-tab').show();
}
}
}
document.getElementById("kyc_tab").addEventListener("click", function(event) {
event.preventDefault();
client_kyc_docs();
});
document.getElementById("RM_tab").addEventListener("click", function(event) {
event.preventDefault();
client_relationship_manager();
});
document.getElementById("policy_tab").addEventListener("click", function(event) {
event.preventDefault();
client_policies();
});
document.getElementById("branch_tab").addEventListener("click", function(event) {
event.preventDefault();
client_branch_contact();
});
document.getElementById("notification_tab").addEventListener("click", function(event) {
event.preventDefault();
client_notification();
});
//HR Access Controll also know as "Client Access Control"
function appendHrAccessControllHtml(input) {
console.log(input.id);
let client_id = $('#general_PrimaryKey').val();
console.log('client_id ', client_id);
let url = '<?= base_url('util/viewHrAccessData') ?>';
let requestData = {
client_id: client_id
};
console.log({hrActivityHistoryHtmlAppended, newBranchSavedPeaseCallTheHrAccessFormApi});
if (hrAccessControlHtmlAppended == false || newBranchSavedPeaseCallTheHrAccessFormApi == true) {
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status === true) {
$('#hr_access_append_area').empty();
$('#hr_access_append_area').append(response.data)
hrAccessControlHtmlAppended = true;
} else {
console.log(response.message, 'WARNING');
hrAccessControlHtmlAppended = false;
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
hrAccessControlHtmlAppended = false;
});
} else {
console.log('Already HTML appended');
}
}
//HR Activity History
function appendHrActivityHistoryHtml(input, submit = false) {
console.log(input.id);
let client_id = $('#general_PrimaryKey').val();
let startDate = $('#startDate').val();
let endDate = $('#endDate').val();
console.log('client_id ', client_id);
console.log('startDate ', startDate);
console.log('endDate ', endDate);
if (submit) {
hrActivityHistoryHtmlAppended = false;
}
let url = '<?= base_url('user/getUserActivityHistory') ?>';
let requestData = {
client_id: client_id,
startDate: startDate,
endDate: endDate
};
if (hrActivityHistoryHtmlAppended == false) {
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status === true) {
$('#hr_activity_history_append_area').empty();
$('#hr_activity_history_append_area').append(response.data)
hrActivityHistoryHtmlAppended = true;
} else {
console.log(response.message, 'WARNING');
hrActivityHistoryHtmlAppended = false;
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
hrActivityHistoryHtmlAppended = false;
});
} else {
console.log('Already HTML appended');
}
}
</script>
<script>
function toggleAccordion(header) {
if (event.target.classList.contains('fa-info-circle') ||
event.target.parentElement.classList.contains('fa-info-circle')) {
getHrActivityHistory();
return; // Do nothing if click was on the info icon
}
const card = header.parentElement;
const content = card.querySelector('.card-content');
const icon = header.querySelector('.accordion-icon i');
// Close all other accordions
document.querySelectorAll('.user-card').forEach(otherCard => {
if (otherCard !== card) {
const otherContent = otherCard.querySelector('.card-content');
const otherIcon = otherCard.querySelector('.accordion-icon i');
otherIcon.setAttribute('class', 'mdi mdi-chevron-down');
}
});
// Toggle current accordion
content.classList.toggle('active');
if (content.classList.contains('active')) {
icon.classList.setAttribute('class', 'mdi mdi-chevron-up');
} else {
icon.classList.setAttribute('class', 'mdi mdi-chevron-down');
}
}
function toggleSection(checkbox, sectionId) {
const section = document.getElementById(sectionId);
const checkboxes = section.querySelectorAll('input[type="checkbox"]');
if (checkbox.checked) {
section.classList.remove('hidden');
checkboxes.forEach(cb => {
cb.disabled = false;
});
} else {
section.classList.add('hidden');
checkboxes.forEach(cb => {
cb.checked = false;
cb.disabled = true;
});
}
}
function getCheckedValues(name) {
const checkboxes = document.querySelectorAll(`input[name="${name}"]:checked`);
return Array.from(checkboxes).map(cb => parseInt(cb.value));
}
function getHrActivityHistory() {
console.log(event.target.dataset.id); //return;
let ids = event.target.dataset.id.split('-');
console.log('ids', ids)
let client_id = $('#general_PrimaryKey').val();
// let url = '<?= base_url('user/getUserActivityHistory?user_id=') ?>' + event.target.dataset.id.split('-')[0] + '&pre_hr_id=' + event.target.dataset.id.split('-')[1];
let url = '<?= base_url('user/getUserActivityHistory') ?>';
console.log(url);
let user_type = "hr";
let requestData = {
user_id: ids[1],
pre_hr_id: ids[0],
user_type: user_type,
client_id: client_id
};
console.log('requestData', requestData);
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status === true) {
toastr.success(response.message, 'Success');
} else {
console.error(response.message, 'Warning');
}
}, function(xhr, status, error) {
console.error('--- AJAX Error Details ---');
console.error('Status Code:', xhr.status);
console.error('Status Text:', xhr.statusText);
console.error('Response Text:', xhr.responseText);
console.error('XHR Object:', xhr);
console.error('jQuery Status:', status);
console.error('Thrown Error:', error);
});
}
function submitForm(event) {
event.preventDefault();
let client_id = $('#general_PrimaryKey').val();
const formData = new FormData(document.getElementById('insuranceForm'));
const users = [];
// Loop through each .user-card
document.querySelectorAll('.user-card').forEach(card => {
const userId = card.getAttribute('data-user-id'); // e.g., "user1", "user2"
const user = {
pk: formData.get(`${userId}_pk`),
pre_hr_id: formData.get(`${userId}_pre_hr_id`),
post_hr_id: formData.get(`${userId}_post_hr_id`),
post_client_id: formData.get(`${userId}_post_client_id`),
allowed_modules: getCheckedValues(`${userId}_modules`),
allowed_pre_policies: getCheckedValues(`${userId}_pre_policies`),
allowed_active_policies: getCheckedValues(`${userId}_active_policies`),
allowed_cd: getCheckedValues(`${userId}_cd`),
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);
});
console.log("users array", users);
const jsonOutput = users.map(user => {
return {
pk: parseInt(user.pk) || 0,
pre_hr_id: user.pre_hr_id || "",
post_hr_id: user.post_hr_id || "",
post_client_id: user.post_client_id || "",
allowed_modules: user.allowed_modules.length ? `[${user.allowed_modules.join(',')}]` : '[]',
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(',')}]` : '[]',
pre_client_id: user.pre_client_id || "",
pre_branch_id: user.pre_branch_id || "",
post_branch_id: user.post_branch_id || ""
};
});
const output = JSON.stringify(jsonOutput, null, 1);
// Display the output
const outputElement = document.getElementById('outputTable');
if (outputElement) {
outputElement.textContent = output;
}
// Copy to clipboard
if (navigator.clipboard) {
navigator.clipboard.writeText(output).then(() => {
console.log('Output copied to clipboard');
}).catch(err => {
console.error('Failed to copy to clipboard:', err);
});
}
console.log(output);
let url = '<?= base_url('util/saveHrAccessData') ?>';
let requestData = {
json: output,
client_id: client_id
};
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status === true) {
$('#hr_access_append_area').empty();
$('#hr_access_append_area').append(response.data)
toastr.success(response.message, 'Success');
} else {
console.error(response.message, 'WARNING');
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
});
}
// Helper function to get checked checkbox values (if not already defined)
function getCheckedValues(namePrefix) {
const checkboxes = document.querySelectorAll(`input[name^="${namePrefix}"]:checked`);
return Array.from(checkboxes).map(cb => cb.value);
}
$(document).on('change', '.select-all', function() {
let $this = $(this);
let type = $this.data('type');
let user = $this.data('user');
let group = $this.data('group');
console.log('--- SELECT-ALL CHANGED ---');
console.log('Type:', type); // all / active / inactive
console.log('User:', user); // user index
console.log('Group:', group); // pre / post
// Step 1: Uncheck other "select-all" checkboxes in the same user/group
$('.select-all[data-user="' + user + '"][data-group="' + group + '"]').not(this).prop('checked', false);
console.log('Unchecked other master checkboxes in same group');
// Step 2: Build full selector
let baseSelector = '.policy-checkbox[data-user="' + user + '"][data-group="' + group + '"]';
let targetSelector = baseSelector;
if (type === 'active') {
targetSelector += '.active';
console.log('Targeting ACTIVE checkboxes only');
} else if (type === 'inactive') {
targetSelector += '.inactive';
console.log('Targeting INACTIVE checkboxes only');
} else {
console.log('Targeting ALL checkboxes');
}
// Step 3: Uncheck all policy checkboxes in that group
$(baseSelector).prop('checked', false);
console.log('Unchecked all checkboxes for user', user, 'group', group);
// Step 4: If this master is checked, apply checking to relevant ones
if ($this.is(':checked')) {
$(targetSelector).prop('checked', true);
console.log('Checked selector:', targetSelector);
} else {
console.log('Master checkbox was unchecked — no checkboxes set');
}
console.log('--- END ---');
});
//----------------------------------------------------------------------------------------------------------------------
// function submitForm(event) {
// event.preventDefault();
// const formData = new FormData(document.getElementById('insuranceForm'));
// const users = [];
// // Process User 1
// const user1 = {
// pk: formData.get('user1_pk'),
// pre_hr_id: formData.get('user1_pre_hr_id'),
// post_hr_id: formData.get('user1_post_hr_id'),
// allowed_modules: getCheckedValues('user1_modules'),
// allowed_pre_policies: getCheckedValues('user1_pre_policies'),
// allowed_active_policies: getCheckedValues('user1_active_policies'),
// allowed_cd: getCheckedValues('user1_cd'),
// allowed_claims: getCheckedValues('user1_claims')
// };
// // Process User 2
// const user2 = {
// pk: formData.get('user2_pk'),
// pre_hr_id: formData.get('user2_pre_hr_id'),
// post_hr_id: formData.get('user2_post_hr_id'),
// allowed_modules: getCheckedValues('user2_modules'),
// allowed_pre_policies: getCheckedValues('user2_pre_policies'),
// allowed_active_policies: getCheckedValues('user2_active_policies'),
// allowed_cd: getCheckedValues('user2_cd'),
// allowed_claims: getCheckedValues('user2_claims')
// };
// users.push(user1, user2);
// // Generate JSON format
// const jsonOutput = users.map(user => {
// const modules = user.allowed_modules.length > 0 ? `[${user.allowed_modules.join(',')}]` : '[]';
// const prePolicies = user.allowed_pre_policies.length > 0 ? `[${user.allowed_pre_policies.join(',')}]` : '[]';
// const activePolicies = user.allowed_active_policies.length > 0 ? `[${user.allowed_active_policies.join(',')}]` : '[]';
// const cdPolicies = user.allowed_cd.length > 0 ? `[${user.allowed_cd.join(',')}]` : '[]';
// const claims = user.allowed_claims.length > 0 ? `[${user.allowed_claims.join(',')}]` : '[]';
// return {
// pk: parseInt(user.pk) || 0,
// pre_hr_id: user.pre_hr_id || "",
// post_hr_id: user.post_hr_id || "",
// allowed_modules: modules,
// allowed_pre_policies: prePolicies,
// allowed_active_policies: activePolicies,
// allowed_cd: cdPolicies,
// allowed_claims: claims
// };
// });
// const output = JSON.stringify(jsonOutput, null, 1);
// // Display the output (you can modify this part based on your needs)
// console.log(output);
// // Optional: Display in a textarea or pre element
// const outputElement = document.getElementById('output');
// if (outputElement) {
// outputElement.textContent = output;
// }
// // Optional: Copy to clipboard
// if (navigator.clipboard) {
// navigator.clipboard.writeText(output).then(() => {
// console.log('Output copied to clipboard');
// }).catch(err => {
// console.error('Failed to copy to clipboard:', err);
// });
// }
// }
//----------------------------------------------------------------------------------------------------------------------
// $(document).on('change', '.select-all', function () {
// let type = $(this).data('type');
// let user = $(this).data('user');
// let group = $(this).data('group');
// let selector = '.policy-checkbox[data-user="' + user + '"][data-group="' + group + '"]';
// if (type === 'active') {
// selector += '.active';
// } else if (type === 'inactive') {
// selector += '.inactive';
// }
// $(selector).prop('checked', this.checked);
// });
//----------------------------------------------------------------------------------------------------------------------
// $(document).on('change', '.post-select-all', function () {
// let $this = $(this);
// let type = $this.data('type');
// let user = $this.data('user');
// let group = $this.data('group');
// console.log('--- POST SELECT-ALL CHANGED ---');
// console.log('Type:', type); // all / active / inactive
// console.log('User:', user); // user index
// console.log('Group:', group); // pre / post
// // Step 1: Uncheck other "select-all" checkboxes in the same user/group
// $('.post-select-all[data-user="' + user + '"][data-group="' + group + '"]').not(this).prop('checked', false);
// console.log('Unchecked other master checkboxes in same group');
// // Step 2: Build selector for post policy checkboxes
// // Note: Post policy checkboxes use name="userX_active_policies" not class="policy-checkbox"
// let baseSelector = 'input[name="user' + user + '_active_policies"][data-user="' + user + '"][data-group="' + group + '"]';
// let targetSelector = baseSelector;
// if (type === 'active-post') {
// // Target checkboxes that have 'active' in their class or are associated with active policies
// targetSelector = baseSelector + ':not(.inactive)';
// console.log('Targeting ACTIVE checkboxes only');
// } else if (type === 'inactive-post') {
// // Target checkboxes that have 'inactive' in their class
// targetSelector = baseSelector + '.inactive';
// console.log('Targeting INACTIVE checkboxes only');
// } else {
// console.log('Targeting ALL checkboxes');
// }
// // Step 3: Uncheck all policy checkboxes in that group first
// $(baseSelector).prop('checked', false);
// console.log('Unchecked all checkboxes for user', user, 'group', group);
// // Step 4: If this master is checked, apply checking to relevant ones
// if ($this.is(':checked')) {
// if (type === 'active') {
// // Check all checkboxes that don't have 'inactive' class
// $(baseSelector).each(function() {
// if (!$(this).hasClass('inactive')) {
// $(this).prop('checked', true);
// }
// });
// } else if (type === 'inactive') {
// // Check all checkboxes that have 'inactive' class
// $(baseSelector + '.inactive').prop('checked', true);
// } else {
// // Check all checkboxes
// $(baseSelector).prop('checked', true);
// }
// console.log('Applied checking based on type:', type);
// } else {
// console.log('Master checkbox was unchecked — no checkboxes set');
// }
// console.log('--- END ---');
// });
</script>
<script>
$('#btnAutoBranchFetch').click(function() {
var myModal = new bootstrap.Modal(document.getElementById('autoFetchBranchModal'));
myModal.show();
})
</script>
<script>
$(document).ready(function() {
$('#auto_fetch_client').select2();
$('#auto_fetch_branch').select2();
$('#auto_fetch_client').change(function() {
$('#auto_fetch_branch').html(`<option value="">Select Branch</option>`);
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.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() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
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>