nhance/app/Views/insurer_or_tpa_data.php
2026-02-09 12:57:17 +05:30

1522 lines
54 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<style>
.select2-container .select2-selection--multiple .select2-selection__choice {
padding: 5px 7px 5px 0 !important;
color: #000000;
}
</style>
<style>
.demo-button {
/* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); */
color: white;
border: none;
padding: 16px 32px;
font-size: 16px;
font-weight: 700;
border-radius: 12px;
cursor: pointer;
font-family: 'Manrope', sans-serif;
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
transition: all 0.3s ease;
letter-spacing: 0.5px;
}
.demo-button:hover {
transform: translateY(-2px);
box-shadow: 0 15px 30px rgba(102, 126, 234, 0.5);
}
/* Modal Overlay */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: var(--bg-overlay);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
backdrop-filter: blur(4px);
}
.modal-overlay.active {
opacity: 1;
visibility: visible;
}
/* Modal Container */
.modal-container {
background: var(--bg-modal);
border-radius: 20px;
box-shadow: var(--shadow-lg);
/* max-width: 600px; */
width: 100%;
max-height: 85vh;
overflow: hidden;
transform: scale(0.9) translateY(20px);
transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
display: flex;
flex-direction: column;
}
.modal-overlay.active .modal-container {
transform: scale(1) translateY(0);
}
/* Modal Header */
.modal-header {
padding: 10px 26px;
border-bottom: 2px solid var(--border-color);
background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
flex-shrink: 0;
}
.modal-title {
font-family: 'Manrope', sans-serif;
font-size: 24px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 8px;
}
.modal-subtitle {
font-size: 14px;
color: var(--text-secondary);
font-weight: 400;
}
/* Toggle Section */
.toggle-section {
padding: 14px 25px;
background: #fefefe;
border-bottom: 1px solid var(--border-color);
flex-shrink: 0;
}
.toggle-container {
display: flex;
align-items: center;
justify-content: space-between;
}
.toggle-label {
font-family: 'Manrope', sans-serif;
font-size: 15px;
font-weight: 600;
color: var(--text-primary);
}
/* Toggle Switch */
.toggle-switch {
position: relative;
width: 54px;
height: 28px;
cursor: pointer;
}
.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-slider {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #cbd5e1;
border-radius: 34px;
transition: all 0.3s ease;
}
.toggle-slider:before {
content: "";
position: absolute;
height: 22px;
width: 22px;
left: 3px;
bottom: 3px;
background-color: white;
border-radius: 50%;
transition: all 0.3s ease;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.toggle-switch input:checked + .toggle-slider {
background: #02a8b5;
}
.toggle-switch input:checked + .toggle-slider:before {
transform: translateX(26px);
}
/* HR List Section */
.hr-list-section {
max-height: 300px;
overflow-y: auto;
padding: 0;
display: none;
flex: 1 1 auto;
min-height: 0;
}
.hr-list-section.active {
display: block;
}
.hr-item {
padding: 5px 32px;
border-bottom: 1px solid var(--border-color);
display: flex;
align-items: center;
transition: background 0.2s ease;
cursor: pointer;
}
.hr-item:hover {
background: #f9fafb;
}
.hr-item:last-child {
border-bottom: none;
}
/* Checkbox Styling */
.hr-checkbox {
position: relative;
display: flex;
align-items: center;
margin-right: 16px;
}
.hr-checkbox input[type="checkbox"] {
position: absolute;
opacity: 0;
cursor: pointer;
}
.checkbox-custom {
width: 22px;
height: 22px;
border: 2px solid #cbd5e1;
border-radius: 6px;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
background: white;
}
.hr-checkbox input:checked ~ .checkbox-custom {
background: #02a8b5;
border-color: #667eea;
}
.checkbox-custom:after {
content: "";
display: none;
width: 6px;
height: 10px;
border: solid white;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
.hr-checkbox input:checked ~ .checkbox-custom:after {
display: block;
}
/* HR Info */
.hr-info {
flex: 1;
}
.hr-name {
font-family: 'Manrope', sans-serif;
font-size: 16px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 4px;
}
.hr-email {
font-size: 13px;
font-weight: 500;
color: var(--text-secondary);
}
/* Modal Footer */
.modal-footer {
padding: 24px 32px;
background: #fafafa;
display: flex;
gap: 12px;
justify-content: flex-end;
flex-shrink: 0;
border-top: 1px solid var(--border-color);
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 10px;
font-size: 15px;
font-weight: 600;
cursor: pointer;
font-family: 'Manrope', sans-serif;
transition: all 0.2s ease;
letter-spacing: 0.3px;
}
.btn-submit {
/* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); */
color: white;
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}
.btn-submit:hover {
transform: translateY(-2px);
box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}
.btn-submit:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
/* Scrollbar Styling */
.hr-list-section::-webkit-scrollbar {
width: 8px;
}
.hr-list-section::-webkit-scrollbar-track {
background: #f1f5f9;
}
.hr-list-section::-webkit-scrollbar-thumb {
background: #cbd5e1;
border-radius: 4px;
}
.hr-list-section::-webkit-scrollbar-thumb:hover {
background: #94a3b8;
}
/* Empty State */
.empty-state {
padding: 60px 32px;
text-align: center;
color: var(--text-secondary);
}
.empty-state-icon {
font-size: 48px;
margin-bottom: 16px;
opacity: 0.5;
}
.empty-state-text {
font-size: 15px;
font-weight: 500;
}
/* Animations */
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.hr-item {
animation: slideIn 0.3s ease;
animation-fill-mode: backwards;
}
.hr-item:nth-child(1) { animation-delay: 0.05s; }
.hr-item:nth-child(2) { animation-delay: 0.1s; }
.hr-item:nth-child(3) { animation-delay: 0.15s; }
.hr-item:nth-child(4) { animation-delay: 0.2s; }
.hr-item:nth-child(5) { animation-delay: 0.25s; }
</style>
<div class="tab-pane fade" id="KYC-DOC-tab">
<div class="row">
<div class="col-xl-12">
<div id="accordion" class="mb-3">
<div class="card mb-1">
<h4 class="m-1">
<span>Filters</span>
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne" aria-expanded="true">
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
</a>
</h4>
<!-- <label id="filterAccordion" class="m-1 d-flex justify-content-between align-items-center">
<span class="font-color-black">Filters</span>
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne" aria-expanded="true">
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
</a>
</label> -->
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
<!-- <div class="text-center"> -->
<form class="parsley-examples" id="import_export_excel_form" action="<?php echo base_url() . 'util/import-export' ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" id="csrf_token">
<input type="hidden" id="event_type_data">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label>Client<span class="text-danger">*</span></label> <br />
<select name="client_id" class="form-control" id="client" required>
<option value="">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Branch</label> <br />
<select name="client_branch_id" class="form-control" id="client_branch_id" required>
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Policy<span class="text-danger" id="policy_danger">*</span></label> <br />
<select name="client_policy_id" class="form-control" id="policy" onchange="checkPolicyTermsAndRackRatesHasDefiend(event); checkWellnessOnboardStatus(event);" required>
<option value="">Select</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form- group col-md-4">
<label>Insurer/TPA Data<span class="text-danger">*</span></label> <br />
<select name="insurer_or_tpa" class="form-control" id="insurer_or_tpa" required>
<option value="">Select</option>
<?php
if (isset($insurer_or_tpa) && count($insurer_or_tpa)) {
foreach ($insurer_or_tpa as $key => $action) {
echo "<option value=" . $key . ">" . $action . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-4">
<label>Action<span class="text-danger">*</span></label> <br />
<select name="action_type" class="form-control" id="action_type" required>
<option value="">Select</option>
<?php
if (isset($import_or_export) && count($import_or_export)) {
foreach ($import_or_export as $key => $action) {
echo "<option value=" . $key . ">" . $action . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-4">
<label>Event<span class="text-danger">*</span></label> <br />
<select name="event_type" class="form-control" id="event_type" required>
<option value="">Select</option>
<?php
if (isset($events) && count($events)) {
foreach ($events as $key => $action) {
echo "<option value='$key'" . ($key == "si_enhancement" ? " class='si-enhancement-option'" : "") . ">$action</option>";
}
}
?>
</select>
</div>
</div>
<div class="form-row policy_issue_date_row" style="display:none;">
<div class="form-group col-md-4">
<label id="policy_issue_date_label">Policy Issue Date</label> <br />
<input type="text" class="form-control" id="policy_issue_date" name="policy_issue_date"
placeholder="Enter Policy Issue Date">
</div>
</div>
<br>
<div class="form-row" id="import_excel_btn">
<div class="form-group col-md-3">
<label>Upload file</label>&nbsp;[ <a id="import_excel_download" data-toggle="tooltip" data-placement="top" title="Download Import Sample Excel" style="display: none;">Sample Excel</a> ]
<input type="file" name="import_file_data" id="import_file" accept=" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet" required>
</div>
<div class="d-flex align-items-center justify-content-start" style="margin-top: 18px;">
<div class="form-group col-md-3">
<button id="emp_form_submit_button" type="submit" class="btn btn-primary waves-effect waves-light justify-content-end">Upload</button>
</div>
</div>
<div class="form-group col-md-4 fetch_tpa" style="margin-top: 30px;">
<a id="fetch_tpa_btn" class="btn btn-primary waves-effect waves-light justify-content-end" onclick="fetchTpaIdFromTpa(this)">Fetch TPA ID</a>
</div>
</div>
<div class="form-row" id="export_excel_btn">
<div class="d-flex align-items-center justify-content-start" style="margin-top: 18px;">
<div class="form-group col-md-3">
<button id="emp_form_submit_button_2" type="submit" class="btn btn-primary waves-effect waves-light justify-content-end">Download</button>
</div>
</div>
</div>
<div class="form-row" id="onboard_div" style="display:none;">
<a href="#"><span id="on_board_btn_txt" onclick="initiateWellnessOnboard(this)"></span></a>
</div>
</div>
</form>
</div>
</div>
<!-- Demo Button -->
<button style="display: none" class="demo-button" onclick="openModal()">Open HR Email Modal</button>
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row" id="file_list">
<?php include('batch_list.php'); ?>
</div>
<!-- end row -->
</div>
<div class="modal fade" id="payout_modal" tabindex="-1" role="dialog" aria-hidden="true" aria-modal="true" data-backdrop="static" data-backdrop="static"
data-keyboard="false"
tabindex="-1">
<div class="modal-dialog modal-lg" style="max-width: 800px;">
<div class="modal-content">
<div class="modal-header" style="background-color: gainsboro;">
<h5 class="modal-title" id="myCenterModalLabel"> Insufficient CD Balance HR Notification</h5>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body" id="modal_body">
<!-- Form -->
<form id="hrEmailForm">
<input type="hidden", id="client_id_for_hr_mail_send" name="client_id" >
<!-- Toggle Section -->
<div class="toggle-section">
<div class="toggle-container">
<label class="toggle-label">Insufficient Balance HR Mail Send</label>
<label class="toggle-switch">
<input type="checkbox" id="mailToggle" onchange="toggleHRList()">
<span class="toggle-slider"></span>
</label>
</div>
</div>
<!-- HR List Section -->
<div class="hr-list-section" id="hrListSection">
<!-- HR items will be dynamically generated here -->
</div>
<!-- Footer Buttons -->
<div class="modal-footer">
<button type="button" class="btn btn-cancel" onclick="cancelModal()">Cancel</button>
<button type="submit" class="btn btn-submit" id="submitBtn">Send Notification</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
var client_id_param2 = 0;
var client_branch_id_param2 = 0;
var client_policy_param2 = 0;
var hr_data = [];
$(document).ready(function() {
// Initialize select2
$("#client").select2();
$("#policy").select2();
$("#client_branch_id").select2();
});
$(document).ready(function() {
var policy_issue_datePicker = flatpickr("#policy_issue_date", {
dateFormat: "d/m/Y",
allowInput: false,
});
$('#insurer_or_tpa, #action_type').on('change', togglePolicyIssueDate);
});
$(document).ready(function() {
<?php if (session()->has('error')) : ?>
toastr.error('<?= session()->getFlashdata('error') ?>', 'Failed');
<?php endif; ?>
<?php if (session()->has('success')) : ?>
toastr.success('<?= session()->getFlashdata('success') ?>', 'Success');
<?php endif; ?>
$('#import_excel_btn').hide();
$('#export_excel_btn').hide();
// for form submit
$("#import_export_excel_forms").submit(function(event) {
var action = "<?php echo base_url() . 'util/import-export' ?>"
// var action = $(this).attr("action");
event.preventDefault(); // Prevent default form submission
console.log('submit called');
var isValid = $('#import_export_excel_form').parsley().validate();
if (!isValid) {
console.log('Form is Empty', 'Warning');
return;
}
// Create FormData object
var formData = new FormData($(this)[0]);
for (var pair of formData.entries()) {
// console.log(pair[0] + ', ' + pair[1]);
}
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: action,
type: "POST",
data: formData,
processData: false, // Prevent jQuery from automatically processing the data
contentType: false, // Let jQuery handle the content type
success: function(response) {
// console.log(response);
if (response.code === 200 && response.status === true) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
$$("#import_export_excel_form")[0].reset()
toastr.success('File Download successs', 'Success');
} else if (response.code === 404 && response.status === false) {
console.error('no data found', response);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
$("#import_export_excel_form")[0].reset()
toastr.error(response.message, 'Failed');
} else {
console.error('Something went wrong!');
// toastr.error('Something went wrong! Try later', 'Error');
// window.location.reload(true);
}
},
error: function(xhr, status, error) {
// Request failed, handle error
console.error("Request failed:", status, error);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
$("#import_export_excel_form")[0].reset()
// toastr.error('Something went wrong! Try later', 'Error');
// window.location.reload(true);
}
});
}); //end
});
$(window).on("load", function() {
// Get the current page URL
const url = window.location.href;
// Create a new URL object
const urlObject = new URL(url);
// Use URLSearchParams to get the query parameters
const params = new URLSearchParams(urlObject.search);
// Get the value of 'client_id' and 'client_policy_id'
client_id_param2 = params.get('client_id');
client_policy_param2 = params.get('client_policy_id');
client_branch_id_param2 = params.get('client_branch_id');
actions = params.get('actions');
insurer_or_tpa = params.get('insurer_or_tpa');
event = params.get('event');
// console.log('client_id2:', client_id_param2);
// console.log('client_policy_id2:', client_policy_param2);
// console.log('actions:', actions);
// console.log('insurer_or_tpa:', insurer_or_tpa);
// console.log('event:', event);
if (inception_param != null) {
$('#action_type').val(actions).change()
$('#event_type').val(event).change()
$('#insurer_or_tpa').val(insurer_or_tpa).change()
var selectedValue = actions;
// console.log(selectedValue);
if (selectedValue == '') {
$('#import_excel_btn').hide();
$('#export_excel_btn').hide();
} else if (selectedValue == 'import') {
$('#import_file').prop('required', true);
$('#import_file').attr('name', 'import_file_data');
$('#import_excel_btn').show();
$('#export_excel_btn').hide();
} else if (selectedValue == 'export') {
$('#import_file').removeAttr('name');
$('#import_file').prop('required', false);
$('#import_excel_btn').hide();
$('#export_excel_btn').show();
}
}
});
// function fetchClientPolicies2() {
// $('#loader').show();
// var apiURL = '<?php echo base_url(); ?>' + 'util/clients-with-policies';
// $.ajax({
// url: apiURL,
// method: 'GET',
// headers: {
// "Content-Type": "application/json",
// "X-Requested-With": "XMLHttpRequest"
// },
// success: function(response) {
// // console.log(response.code);
// // console.log(response.dataStatus);
// // console.log(response.data);
// if (response.code === 200 && response.dataStatus === true && response.data !== "") {
// try {
// clientPolicies = (response.data);
// // console.log(clientPolicies);
// response.data.forEach(policy => {
// // console.log('policies', policy.policies);
// policy.policies.forEach(p => {
// clientPoliciesWithBranch2.policies.push(p);
// });
// });
// appendClients2(clientPolicies);
// setTimeout(function() {
// if (client_branch_id_param2 != null) {
// var foundPolicies = clientPolicies.find(function(item) {
// // console.log(typeof item.id)
// return item.id == client_id_param2;
// });
// appendBranch2(foundPolicies.branchs);
// }
// }, 500);
// setTimeout(function() {
// if (client_id_param2 != null) {
// var foundPolicies = clientPoliciesWithBranch2.policies.filter(function(item) {
// // console.log('item', item);
// return item.branch_id === client_branch_id_param2;
// });
// if (foundPolicies) {
// // console.log('foundPolicies', foundPolicies);
// appendPolicies2(foundPolicies);
// } else {
// console.log('No policies found for the selected client');
// }
// }
// }, 500);
// } catch (error) {
// console.error('Error parsing API response data:', error);
// }
// } else if (response.code === 404 && response.dataStatus === false) {
// console.error('no data found', response);
// } else {
// // console.error('Something went wrong!');
// }
// },
// error: function(xhr, status, error) {
// console.error('Error fetching data from API:', error);
// }
// });
// $('#loader').hide();
// }
function appendClients2(data) {
// console.log('client_id_param2', client_id_param2)
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.client_name
});
if (client_id_param2 == item.id) {
option.attr('selected', true);
}
$('#client').append(option);
});
}
function appendBranch2(data) {
// console.log(data)
$('#client_branch_id').empty();
$('#client_branch_id').append($('<option>', {
value: '0',
text: 'Select'
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.branch_name
});
if (client_branch_id_param2 == item.id) {
option.attr('selected', true);
}
$('#client_branch_id').append(option);
});
}
function appendPolicies2(data) {
$('#policy').empty();
$('#policy').append($('<option>', {
value: '0',
text: 'Select'
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text:`${item.policy_type ?? ''} - ${item.policy_no ?? ''}` ,
'data-pno': item.policy_no ?? '',
'data-tid': item.tpa_id ?? ''
});
if (client_policy_param2 == item.id) {
option.attr('selected', true);
}
$('#policy').append(option);
});
}
// On change document ready functions
$(document).ready(function() {
$('#client').on('change', function() {
let client_id = $(this).val();
console.log('client_id', client_id);
if(branch_list != '') {
// console.log(branch_list[client_id]);
let data = branch_list[client_id];
appendBranch2(data);
}
});
$('#client_branch_id').on('change', function() {
let branch_id = $(this).val();
console.log("branch_id", branch_id);
if(policy_list != '' && branch_id != '') {
let data = policy_list[branch_id];
appendPolicies2(data);
}
});
$('#policy').on('change', function() {
var policy_value = $(this).val()
var insurer_or_tpa = $('insurer_or_tpa').val()
var action_type = $('action_type').val()
if(policy_value == 0 || insurer_or_tpa == 'tpa' || action_type == 'import'){
$("#event_type").removeAttr("multiple");
$("#event_type").attr("name", "event_type");
$("#event_type").select2('destroy');
}
})
/**This function updates the download link based on the selected option in the dropdown menu. **/
$('#event_type').on('change', function() {
var selectedValue = $(this).val();
if (selectedValue !== '') {
$('#import_excel_download').show();
var fullURL = '<?= base_url("util/download_import_excel/"); ?>' + selectedValue;
$('#import_excel_download').attr('href', fullURL);
} else {
$('#import_excel_download').hide();
$('#import_excel_download').removeAttr('href');
}
});
$('#event_type').on('change', function() {
var selectedVal = $(this).val();
var insurer_or_tpa = $('#insurer_or_tpa').val()
var action_type = $('#action_type').val()
console.log({tpa_api_sevice, selectedVal, insurer_or_tpa, action_type});
if (tpa_api_sevice == 0 || action_type == 'export' || insurer_or_tpa == "insurer" || (selectedVal == 'correction' || selectedVal == 'deletion' || selectedVal == 'si_enhancement')) {
$('.fetch_tpa').hide();
} else {
$('.fetch_tpa').show();
}
if (selectedVal === 'correction') {
$('#policy').prop('required', false);
$('#policy_danger').hide();
} else {
$('#policy').prop('required', true);
$('#policy_danger').show();
}
console.log('tpa_api_sevice', tpa_api_sevice);
console.log('tpa_api_sevice type', typeof tpa_api_sevice);
});
$('#action_type').on('change', function() {
var selectedValue = $(this).val();
var insurer_or_tpa = $('#insurer_or_tpa').val()
// console.log(selectedValue);
if (selectedValue == '') {
$('#import_excel_btn').hide();
$('#export_excel_btn').hide();
} else if (selectedValue == 'import') {
$('#import_file').prop('required', true);
$('#import_file').attr('name', 'import_file_data');
$('#import_excel_btn').show();
$('#export_excel_btn').hide();
} else if (selectedValue == 'export') {
$('#import_file').removeAttr('name');
$('#import_file').prop('required', false);
$('#import_excel_btn').hide();
$('#export_excel_btn').show();
}
if (tpa_api_sevice == 0 || selectedValue == 'export' || insurer_or_tpa == "insurer") {
$('.fetch_tpa').hide();
} else {
$('.fetch_tpa').show();
}
});
$('#insurer_or_tpa').on('change', function() {
var insurer_or_tpa = $(this).val()
var policy_value = $('#policy').val()
var event_type_data = $('#event_type_data').val();
var action_type = $('#action_type').val()
var event_string = $('#event_type').val();
console.log({tpa_api_sevice, insurer_or_tpa, policy_value, event_type_data, action_type, event_string});
if (tpa_api_sevice == 0 || action_type == 'export' || insurer_or_tpa == "insurer" || (event_string == 'correction' || event_string == 'deletion' || event_string == 'si_enhancement')) {
$('.fetch_tpa').hide();
} else {
$('.fetch_tpa').show();
}
// if(insurer_or_tpa == 'tpa' || event_type_data == 0){
if(insurer_or_tpa == 'tpa'){
$("#event_type").removeAttr("multiple");
$("#event_type").attr("name", "event_type");
$("#event_type").select2('destroy');
}else if(insurer_or_tpa == 'insurer' && action_type == 'import'){
$("#event_type").removeAttr("multiple");
$("#event_type").attr("name", "event_type");
$("#event_type").select2('destroy');
}else if(insurer_or_tpa == 'insurer' && action_type == 'export' && event_type_data == 1){
$("#event_type").attr("multiple", "multiple");
$("#event_type").attr("name", "event_type[]");
$("#event_type").select2();
}else if(insurer_or_tpa == 'insurer' && action_type == 'export' && event_type_data == 0){
$("#event_type").removeAttr("multiple");
$("#event_type").attr("name", "event_type");
$("#event_type").select2('destroy');
}else{
if(policy_value != 0){
$("#event_type").attr("multiple", "multiple");
$("#event_type").attr("name", "event_type[]");
$("#event_type").select2();
}
}
});
$('#action_type').on('change', function() {
var action_type = $(this).val()
var policy_value = $('#policy').val()
var insurer_or_tpa = $('#insurer_or_tpa').val()
var event_string = $('#event_type').val();
var event_type_data = $('#event_type_data').val();
console.log({tpa_api_sevice, action_type, policy_value, insurer_or_tpa, event_string, event_type_data})
if (tpa_api_sevice == 0 || action_type == 'export' || insurer_or_tpa == "insurer" || (event_string == 'correction' || event_string == 'deletion' || event_string == 'si_enhancement')) {
$('.fetch_tpa').hide();
} else {
$('.fetch_tpa').show();
}
if(action_type == 'import'){
$("#event_type").removeAttr("multiple");
$("#event_type").attr("name", "event_type");
$("#event_type").select2('destroy');
} else if(action_type == 'export' && insurer_or_tpa == 'tpa'){
$("#event_type").removeAttr("multiple");
$("#event_type").attr("name", "event_type");
$("#event_type").select2('destroy');
}else if(action_type == 'export' && insurer_or_tpa == 'insurer' && event_type_data == 1){
$("#event_type").attr("multiple", "multiple");
$("#event_type").attr("name", "event_type[]");
$("#event_type").select2();
}else if(action_type == 'export' && insurer_or_tpa == 'insurer' && event_type_data == 0){
$("#event_type").removeAttr("multiple");
$("#event_type").attr("name", "event_type");
$("#event_type").select2('destroy');
}else{
if(policy_value != 0){
$("#event_type").attr("multiple", "multiple");
$("#event_type").attr("name", "event_type[]");
$("#event_type").select2();
}
}
});
});
// Function to convert object to query parameters
function objectToQueryString2(obj) {
return Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&');
}
function fetchEmpolyeeList2(event) {
event.preventDefault(); // Prevent default action
var client_id = $('#client').val();
var policy_id = $('#policy').val();
// console.log(client_id + '-' + policy_id);
if (client_id == '0' || policy_id == '0') {
alert('Please select values in both dropdowns.');
return;
}
var queryParams = {
client_id: client_id,
policy_id: policy_id
};
const queryString = objectToQueryString2(queryParams);
const apiURL = $('#get-emp-list').attr('href') + "?" + queryString;
// console.log(apiURL);
window.location.href = apiURL;
}
//--------------------------------------------------------------------------------------
document.getElementById('toggleIcon').addEventListener('click', function() {
var icon = document.getElementById('icon');
icon.classList.toggle('mdi-chevron-down');
icon.classList.toggle('mdi-chevron-up');
});
//------------------------------------------------------------------------------------------------------
$('#import_excel_download').click(function() {
// Check if the element with ID "import_excel_download" has the href attribute set
if (!$(this).attr('href')) {
// If href attribute is not set, show an error message
toastr.warning('Please select an Action to download a sample Excel.', 'Warning');
} else {
// console.log('Download action triggered.');
}
});
//------------- CHECK CD BALANCE in SESSION -----------------------------------------------------------------------------------------
// Global variables
var submitInterval = null;
var messageShown = false; // Flag to prevent duplicate messages
//function for checking the session
function checkCDBalanceOld() {
const get_cd_balance = <?= json_encode(get_cd_balance()) ?>;
console.log({ get_cd_balance });
<?php if (session()->has('cd_balance')): ?>
var cdBalance = <?php echo json_encode(session()->get('cd_balance')); ?>;
var cdAmount = <?php echo json_encode(session()->get('cd_amount')); ?>;
var excel_file_amt = <?php echo json_encode(session()->get('excel_file_amt')); ?>;
hr_data = <?php echo json_encode(session()->get('hr_data')); ?>;
console.log({cdBalance, cdAmount, excel_file_amt, hr_data})
// Only show message once and if status is false
if (get_cd_balance?.cd_balance === false && !messageShown) {
// toastr.warning('Insufficient CD Balance deducated. Please wait the file will be downloaded', 'Warning');
var message1 = 'Insufficient CD Balance deducted. Please wait the file will be downloaded<br>' +
'<strong>CD Amount:</strong> ₹' + (cdAmount || 0) + '<br>' +
'<strong>Total Amount:</strong> ₹' + (excel_file_amt || 0);
toastr.warning(message1, 'Warning', {
allowHtml: true,
timeOut: 10000,
extendedTimeOut: 3000
});
messageShown = true; // Prevent showing message again
stopInterval();
openModal();
} else if (cdBalance === true) {
console.log("CD Balance is sufficient");
stopInterval();
}
<?php
session()->remove('cd_balance');
session()->remove('cd_amount');
session()->remove('excel_file_amt');
?>
<?php else: ?>
console.log("No cd_balance session found");
<?php endif; ?>
}
async function checkCDBalance() {
try {
// 1. Fetch the LATEST session data from the server
const response = await fetch('checkSessionStatus');
const cdData = await response.json();
console.log('Current Session Data:', cdData);
// 2. Check if cd_balance_info exists and isn't empty
if (cdData.has_cd_balance && cdData.cd_balance_info) {
if(cdData.cd_balance === 'sufficient'){
stopInterval(); // Stop checking once we find the error
console.log("CD Balance is sufficient");
return;
}
let cd_balance_info = JSON.parse(cdData.cd_balance_info) ?? null;
let hr_info = cdData.hr_data ? JSON.parse(cdData.hr_data) : null;
// If balance is marked as false (insufficient)
if (cd_balance_info.cd_balance === false) {
stopInterval(); // Stop checking once we find the error
toastr.warning(
`Insufficient CD Balance.<br>Balance: ₹${cd_balance_info.cd_amount}`,
'Warning',
{ allowHtml: true }
);
if(hr_info) {
$('#client_id_for_hr_mail_send').val(hr_info.client_id);
window.hr_data = hr_info.hr_data;
}
openModal();
// 3. Clear the session now that we've handled it
fetch('clearCdSession');
}
}
} catch (error) {
console.error('Error checking CD balance:', error);
}
}
// Start the interval
function startInterval() {
if (!submitInterval) {
messageShown = false; // Reset message flag
submitInterval = setInterval(function() {
checkCDBalance();
}, 2000);
console.log("Checking CD balance started...");
}
}
// Stop the interval
function stopInterval() {
if (submitInterval) {
clearInterval(submitInterval);
submitInterval = null;
<?php
session()->remove('cd_balance');
session()->remove('cd_amount');
session()->remove('excel_file_amt');
?>
console.log("Interval stopped.");
}
}
// When click the button to start the interval
$(document).ready(function() {
$('#emp_form_submit_button_2').on('click', function() {
console.log("Submit button clicked, starting interval...");
startInterval();
});
});
//------------------------------------------------------------------------------------------------------
</script>
<script>
function togglePolicyIssueDate() {
let insurer = $('#insurer_or_tpa').val();
let action = $('#action_type').val();
if (insurer === 'insurer' && action === 'import') {
$('.policy_issue_date_row').show();
$('#policy_issue_date').attr('required', true);
$('#policy_issue_date_label').html('Policy Issue Date <span class="text-danger">*</span>');
} else {
$('.policy_issue_date_row').hide();
$('#policy_issue_date').removeAttr('required').val('');
$('#policy_issue_date_label').text('Policy Issue Date');
}
}
function fetchTpaIdFromTpa(){
let user_confirm = confirm('Are you sure you want to initiate the TPA fetch? This may take a while.');
if(!user_confirm)
{
return false;
}
let event = $('#event_type').val();
let client_id = $('#client').val();
let branch_id = $('#client_branch_id').val();
let policy_id = $('#policy').val();
let tpa_id = $('#policy option:selected').data('tid');
let policy_no = $('#policy option:selected').data('pno');
let checks = [
{val: client_id, msg: 'Please select the client'},
{val: branch_id, msg: 'Please select the client branch'},
{val: policy_id, msg: 'Please select the policy'},
{val: event, msg: 'Please select the event'},
{val: tpa_id, msg: 'TPA id empty'},
{val: policy_no, msg: 'Policy No empty'},
];
for (let c of checks) {
if (!c.val || c.val == 0) {
toastr.warning(c.msg, 'Warning');
return;
}
}
let url = '<?= base_url('getTPAID') ?>';
// Data to send in the AJAX request
let requestData = {
policy_no: policy_no,
tpa_id: tpa_id,
client_id: client_id,
client_branch_id: branch_id,
client_policy_id: policy_id,
};
// Send AJAX request
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status == true) {
toastr.success(response.message || 'Initiating successafully', 'Success');
} else {
toastr.error(response.message || 'Unable to fetch data', 'Error');
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
toastr.error('An error occurred while checking the CD amount.', 'Error');
});
}
</script>
<script>
// Sample HR data (replace this with your actual data source)
const hrData = [
{ id: 1, name: 'Rajesh Kumar', email: 'rajesh.kumar@company.com' },
{ id: 2, name: 'Priya Sharma', email: 'priya.sharma@company.com' },
{ id: 3, name: 'Arun Patel', email: 'arun.patel@company.com' },
{ id: 4, name: 'Arun Patel', email: 'arun.patel@company.com' },
{ id: 5, name: 'Arun Patel', email: 'arun.patel@company.com' },
];
// Open Modal
function openModal() {
// document.getElementById('hrModal').classList.add('active');
var myModal = new bootstrap.Modal(document.getElementById('payout_modal'));
myModal.show();
}
// Toggle HR List
function toggleHRList() {
const toggle = document.getElementById('mailToggle');
const hrListSection = document.getElementById('hrListSection');
if (toggle.checked) {
hrListSection.classList.add('active');
renderHRList();
} else {
hrListSection.classList.remove('active');
}
}
// Render HR List
function renderHRList() {
const hrListSection = document.getElementById('hrListSection');
if (hr_data.length === 0) {
hrListSection.innerHTML = `
<div class="empty-state">
<div class="empty-state-icon">📭</div>
<div class="empty-state-text">No HR contacts available</div>
</div>
`;
return;
}
hrListSection.innerHTML = hr_data.map(hr => `
<div class="hr-item" onclick="toggleCheckbox(${hr.id}, event)">
<label class="hr-checkbox">
<input type="checkbox" name="hr_emails[]" value="${hr.id}" data-email="${hr.email}" data-name="${hr.name}" id="hr_${hr.id}">
<span class="checkbox-custom"></span>
</label>
<div class="hr-info">
<div class="hr-name">${hr.name}</div>
<div class="hr-email">${hr.email}</div>
</div>
</div>
`).join('');
}
// Toggle checkbox when clicking on the item
function toggleCheckbox(hrId, event) {
// Prevent double toggle if clicking directly on checkbox
if (event && event.target.tagName === 'INPUT') {
return;
}
const checkbox = document.getElementById(`hr_${hrId}`);
checkbox.checked = !checkbox.checked;
}
// Cancel Modal with Confirmation
function cancelModal() {
// document.getElementById('confirmDialog').classList.add('active');
Swal.fire({
title: "Cancel Confirmation",
text: "Are you sure you want to cancel? No emails will be sent to HR.",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, Procced!"
}).then((result) => {
if(result.isConfirmed){
confirmCancel()
}else{
return false
}
});
}
// Confirm Cancel
function confirmCancel() {
setTimeout(() => {
$('.close').click();
resetForm();
}, 300);
}
// Reset Form
function resetForm() {
document.getElementById('hrEmailForm').reset();
document.getElementById('hrListSection').classList.remove('active');
}
$('#hrEmailForm').on('submit', function (e) {
e.preventDefault();
const client_id = $('#client_id_for_hr_mail_send').val();
const mailToggle = $('#mailToggle');
const selectedHRs = $('input[name="hr_emails[]"]:checked');
if (!mailToggle.is(':checked')) {
toastr.warning('Please Enable the mail option.', 'Warning');
return;
}
if (selectedHRs.length === 0) {
toastr.warning('Please select at least one HR.', 'Warning');
return;
}
// Prepare mails object
const sendingMails = {};
selectedHRs.each(function () {
const hrId = $(this).val();
const hrEmail = $(this).data('email');
const hrName = $(this).data('name');
sendingMails[hrId] = {
mail: hrEmail,
name: hrName
};
});
const formData = {
mails: sendingMails,
client_id: client_id,
mail_enable_key: mailToggle.is(':checked') ? 1 : 0
};
console.log('Form Data:', formData);
const $submitBtn = $('#submitBtn');
$submitBtn.prop('disabled', true).text('Sending...');
const url = '<?= base_url('util/insufficientCdBalanceHrMailSend') ?>';
$.ajax({
url: url,
type: 'POST',
data: JSON.stringify(formData),
contentType: 'application/json',
dataType: 'json',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') || ''
},
success: function (data) {
console.log('Response Success:', data);
if (data.status === true) {
toastr.success(data.message, 'Success');
} else {
toastr.warning(data.message, 'Warning');
}
},
error: function (xhr, status, error) {
console.error('Response Error:', error);
toastr.error('Something went wrong. Please try again.', 'Error');
},
complete: function () {
// Reset button state
$submitBtn.prop('disabled', false).text('Send Notification');
confirmCancel();
}
});
});
const modal = document.getElementById('payout_modal');
const modalDialog = modal.querySelector('.modal-dialog');
modal.addEventListener('mousedown', function (e) {
if (!modalDialog.contains(e.target)) {
e.preventDefault();
e.stopImmediatePropagation();
return false;
}
}, true); // 👈 capture phase
</script>