334 lines
13 KiB
PHP
334 lines
13 KiB
PHP
<div class="tab-pane fade active show" id="KYC-DOC-tab">
|
|
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<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">
|
|
<div class="form-group">
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label>Client</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>Policy</label> <br />
|
|
<select name="client_policy_id" class="form-control" id="policy" required>
|
|
<option value="">Select</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label>Insurer/TPA Data</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>
|
|
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-4">
|
|
<label>Action</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</label> <br />
|
|
<select name="event_type" class="form-control" id="upload-action-type" required>
|
|
<option value="">Select</option>
|
|
<?php
|
|
if(isset($events) && count($events))
|
|
{
|
|
foreach($events as $key => $action)
|
|
{
|
|
echo "<option value=".$key.">".$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>
|
|
<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>
|
|
|
|
|
|
<script>
|
|
// Declare a global variable to store API response data
|
|
var clientPolicies = [];
|
|
|
|
$(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();
|
|
});
|
|
|
|
|
|
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);
|
|
appendClients2(clientPolicies);
|
|
} 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) {
|
|
$.each(data, function(index, item) {
|
|
$('#client').append($('<option>', {
|
|
value: item.id,
|
|
text: item.client_name
|
|
}));
|
|
});
|
|
}
|
|
|
|
function appendPolicies2(data) {
|
|
$('#policy').empty();
|
|
$('#policy').append($('<option>', {
|
|
value: '',
|
|
text: 'Select'
|
|
}));
|
|
|
|
$.each(data, function(index, item) {
|
|
$('#policy').append($('<option>', {
|
|
value: item.id,
|
|
text: item.name
|
|
}));
|
|
});
|
|
}
|
|
|
|
$('#client').on('change', function() {
|
|
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.policies);
|
|
appendPolicies2(foundPolicies.policies);
|
|
});
|
|
|
|
// 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();
|
|
}
|
|
});
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
</script>
|