nhance-enrollment/app/Views/insurer_or_tpa_data.php

685 lines
27 KiB
PHP
Executable File

<style>
.select2-container .select2-selection--multiple .select2-selection__choice {
padding: 5px 7px 5px 0 !important;
color: #000000;
}
</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">
<h5 class="m-1">
<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>
</h5>
<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)" 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>
<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>
<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>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row" id="file_list">
<?php include('batch_list.php'); ?>
</div>
<!-- end row -->
</div>
<script>
$(document).ready(function() {
// Initialize select2
$("#client").select2();
$("#policy").select2();
$("#client_branch_id").select2();
});
// Declare a global variable to store API response data
var clientPolicies = [];
var clientPoliciesWithBranch2 = {
policies: []
};
var client_id_param2 = 0;
var client_branch_id_param2 = 0;
var client_policy_param2 = 0;
$(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() {
fetchClientPolicies2();
// 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.client_policy_id,
// text: `${item.name ?? ''} - ${item.policy_no ?? ''} - ${item.policy_type ?? ''}`
text:`${item.policy_type ?? ''} - ${item.policy_no ?? ''}`
});
if (client_policy_param2 == item.client_policy_id) {
option.attr('selected', true);
}
$('#policy').append(option);
});
}
$(document).ready(function() {
$('#client').on('change', function() {
$('#policy').empty();
$('#policy').append($('<option>', {
value: '0',
text: 'Select'
}));
var selectedClient = $(this).val();
// console.log(selectedClient);
// $('#selectedOptionInfo').text('Selected option: ' + selectedOption);
// Check if the selected option exists in apiData
var foundPolicies = clientPolicies.find(function(item) {
return item.id === selectedClient;
});
// console.log(foundPolicies.branchs);
appendBranch2(foundPolicies.branchs);
});
});
$(document).ready(function() {
$('#client_branch_id').on('change', function() {
var selectedClient = $(this).val();
// console.log('selectedBranch', selectedClient);
// console.log('clientPolicies', clientPoliciesWithBranch2);
var foundPolicies = clientPoliciesWithBranch2.policies.filter(function(item) {
return item.branch_id === selectedClient;
});
if (Array.isArray(foundPolicies) && foundPolicies.length === 0) {
appendPolicies2(foundPolicies);
toastr.warning('No policies found for the selected client branch.');
} else {
// console.log('foundPolicies', foundPolicies);
appendPolicies2(foundPolicies);
}
});
});
// 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;
}
//--------------------------------------------------------------------------------------
$('#action_type').change(function() {
var selectedValue = $(this).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();
}
});
document.getElementById('toggleIcon').addEventListener('click', function() {
var icon = document.getElementById('icon');
icon.classList.toggle('mdi-chevron-down');
icon.classList.toggle('mdi-chevron-up');
});
$(document).ready(function() {
$('#event_type').change(function() {
var selectedVal = $(this).val();
// console.log(selectedVal);
if (selectedVal === 'correction') {
$('#policy').prop('required', false);
$('#policy_danger').hide();
} else {
$('#policy').prop('required', true);
$('#policy_danger').show();
}
});
});
//--------------------------------------------------------------------------------------
$('#insurer_or_tpa').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_type_data = $('#event_type_data').val();
console.log('policy_value', policy_value)
// 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').change(function(){
var action_type = $(this).val()
var policy_value = $('#policy').val()
var insurer_or_tpa = $('#insurer_or_tpa').val()
var event_type_data = $('#event_type_data').val();
console.log('policy_value', policy_value)
// if(insurer_or_tpa == 'import' || event_type_data == 0){
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();
}
}
});
$(document).ready(function(){
$('#policy').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');
}
})
});
//------------------------------------------------------------------------------------------------------
$('#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.');
}
});
/**This function updates the download link based on the selected option in the dropdown menu. **/
$('#event_type').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');
}
});
</script>