nhance-enrollment/app/Views/employee_upload.php

1115 lines
43 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>
option:disabled {
color: gray !important; /* Set text color to gray */
background-color: lightgray !important;}
</style>
<div class="tab-pane fade active show" id="general-q-tab">
<div class="row">
<div class="col-xl-12">
<div id="accordion1" class="mb-3">
<div class="card mb-1">
<h5 class="m-1">
<a id="toggleIcon1" class="text-dark float-right" data-toggle="collapse" href="#collapseTwo"
aria-expanded="true">
<i id="icon1" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
</a>
</h5>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion1">
<div class="card-body">
<!-- <div class="text-center"> -->
<form class="parsley-examples" id="emp-upload-form" action="<?php echo base_url().'employee/upload'?>" 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_id" required>
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Branch</label> <br />
<select name="branch_id" class="form-control" id="branch_id" required>
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Policy</label> <br />
<select name="policy_id" class="form-control" id="policy_id" onchange="checkPolicyTermsAndRackRatesHasDefiend(event)" required>
<option value="0">Select</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label>Event</label> <br />
<select name="upload-action-type" class="form-control"
id="upload-action-type" required>
<!-- <option value="">Select</option> -->
<?php
if(isset($actions) && count($actions))
{
foreach($actions as $key => $action)
{
// echo "<option value='$key'" . ($key == "si_enhancement" ? " class='si-enhancement-option'" : "") . ">$action</option>";
echo "<option selected value='$key'>$action</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-4">
<label for="open_date">Enrollment Open Date<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Open Date " name="enrollment_open_date" id="enrollment_open_date" required>
</div>
<div class="form-group col-md-4">
<label for="close_date">Enrollment Close Date<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Close Date " name="enrollment_close_date" id="enrollment_close_date" required>
</div>
</div>
<hr>
<div class="form-row" id="file_upload">
<div class="form-group col-md-4">
<label>Upload file</label> &nbsp;[ <a id="excel_download"
data-toggle="tooltip" data-placement="top"
title="Download Sample Excel">Sample Excel</a> ]
<input type="file" name="emplist" id="emplist"
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-11">
<!-- Adjusted the width to 11 columns -->
<div class="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-group col-md-2"
style="margin-top: 26px;position: relative;left: 65px;"> OR </div>
<div class="form-group col-md-4" style="margin-top: 18px;">
<a class="btn btn-primary waves-effect waves-light justify-content-end"
id="fetch_enrolled_data" data-toggle="modal"
data-target="#full-width-modal" title="Download Sample Excel">Fetch
Enrolled Data</a>
</div> -->
</div>
</div>
</form>
<!-- </div> -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row" id="file_list">
<?php include('file_list.php');?>
</div>
<!-- end row -->
</div>
<div id="full-width-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="fullWidthModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="fullWidthModalLabel">Enrolled Employee List</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body" id="emp_data">
</div>
<div class="modal-footer">
<a id="fetch_btn" class="btn btn-primary">Initiate Emp Onboard</a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Center modal content -->
<div class="modal fade" id="file-err-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myCenterModalLabel">File Rejected Reason</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
</div>
</div>
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
$('#file_upload').hide();
$(document).ready(function() {
<?php if (session()->has('success1')): ?>
toastr.success('<?= session()->getFlashdata('success1') ?>', 'Success');
<?php endif; ?>
// Initialize select2
$("#client_id").select2();
$("#policy_id").select2();
$("#branch_id").select2();
var enrollment_open_date = flatpickr("#enrollment_open_date", {
dateFormat: "d/m/Y",
allowInput: false,
minDate: "today",
onChange: function (selectedDates) {
if (selectedDates.length) {
enrollment_close_date.setDate(
new Date(selectedDates[0].getTime() + 15 * 24 * 60 * 60 * 1000),
true
);
}
}
});
var enrollment_close_date = flatpickr("#enrollment_close_date", {
dateFormat: "d/m/Y",
allowInput: false,
minDate: "today"
});
});
// Declare a global variable to store API response data
var clientPolicies = [];
var clientPoliciesWithBranch = {
policies: []
};
var client_id_param = 0;
var client_branch_id_param = 0;
var client_policy_param = 0;
$(document).ready(function() {
// console.log("document loaded");
//fetchClientPolicies();
//for modal pop up
$('#file-err-modal').on('show.bs.modal', function(event) {
// console.log(event.relatedTarget);
var myVal = $(event.relatedTarget).data('err');
// console.log(myVal);
var loader =
'<div style="text-align: center;"><img src="<?php echo base_url()?>public/assets/images/simple_loader.gif" height="50px" width="50px" ></div>';
$('#file-err-modal').find(".modal-body").html(loader);
var model_data = fetchFileError(myVal);
// console.log('data received.');
// console.log(model_data);
});
//for form submit
$("#emp-upload-form").submit(function(event) {
event.preventDefault(); // Prevent default form submission
// console.log('submit called');
if(checkValues() == 'client'){
toastr.warning('Client is Required', 'Warning')
return false;
}else if(checkValues() == 'policy'){
toastr.warning('Policy is Required', 'Warning')
return false;
}else if(checkValues() == 'branch'){
toastr.warning('Branch is Required', 'Warning')
return false;
}else if(checkValues() == 'event'){
toastr.warning('Event is Required', 'Warning')
return false;
}else{
}
$('#client_id').val()
$('#policy_id').val()
$('#branch_id').val()
$('#upload-action-type').val()
var isValid = $('#emp-upload-form').parsley().validate();
console.log('isValid', isValid)
if (!isValid) {
console.log('Form is Empty', 'Warning');
return;
}
var action_item = $('#upload-action-type').val();
var policy_id = $('#policy_id').val();
// console.log('action_item - ' + action_item);
if (action_item != 'correction' && policy_id == "") {
// $('#policy_id').attr('required', true);
// $('#policy_id').prop('title', 'plz choose policy');
// $('#policy_id').mouseover();
console.log('required');
// alert('please choose policy for this uploaing event ');
toastr.warning('please choose policy for this uploaing event', 'Warning')
return false;
} else {
$('#policy_id').attr('required', false);
console.log('not required');
}
// Create FormData object
var formData = new FormData($(this)[0]);
for (var pair of formData.entries()) {
// console.log(pair[0] + ', ' + pair[1]);
}
// console.log(formData);
$('#emp_form_submit_button').prop('disabled', true);
$('#emp_form_submit_button').html(
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Loading...'
);
// return false;
$.ajax({
url: $(this).attr("action"),
type: "POST",
data: formData,
processData: false, // Prevent jQuery from automatically processing the data
contentType: false, // Let jQuery handle the content type
headers: {
// "Content-Type":"multipart/form-data",
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
// Request successful, handle response
$('#policy_id').attr('required', false);
// console.log(response);
if (response.code === 200 && response.dataStatus === true && response
.data !== "") {
toastr.success(
'File upload successs, Data validation is in-progress',
'Success');
window.location.reload(true);
} else if (response.code === 404 && response.dataStatus === false) {
console.error('no data found', response);
// alert(response.message);
toastr.error(response.message, 'Failed');
window.location.reload(true);
} else {
console.error('Something went wrong!');
// alert('Something went wrong! Try later');
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);
toastr.error('Something went wrong! Try later', 'Error');
window.location.reload(true);
}
});
}); //end
});
$(window).on("load", function() {
console.log("window loaded");
fetchClientPolicies();
// 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_param = params.get('client_id');
client_policy_param = params.get('client_policy_id');
client_branch_id_param = params.get('client_branch_id');
// inception_param = params.get('actions');
inception_param = $('#upload-action-type').val()
// console.log('client_id:', client_id_param);
// console.log('client_policy_id:', client_policy_param);
console.log('inception_param:', inception_param);
if(inception_param != null){
// $('#upload-action-type').val('inception').change()
var selectedValue = inception_param;
if (selectedValue !== '') {
$('#file_upload').show();
var fullURL = '<?= base_url("util/download-excel/"); ?>' + selectedValue;
$('#excel_download').attr('href', fullURL);
} else {
$('#file_upload').hide();
$('#excel_download').removeAttr('href');
}
}
});
function fetchClientPolicies() {
$('#loader').show();
var apiURL = '<?php echo base_url();?>' + 'util/clients-with-policies';
// console.log('fetchClientPolicies');
// console.log(apiURL);
$.ajax({
url: apiURL,
method: 'GET',
headers: {
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
console.log(response);
// 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 => {
clientPoliciesWithBranch.policies.push(p);
});
});
// console.log(clientPoliciesWithBranch);
appendClients(clientPolicies);
setTimeout(function() {
if (client_id_param != null ) {
var foundPolicies = clientPolicies.find(function(item) {
// console.log(typeof item.id)
return item.id == client_id_param;
});
appendBranch(foundPolicies.branchs);
}
}, 500);
setTimeout(function() {
if (client_branch_id_param != null ) {
var foundPolicies = clientPoliciesWithBranch.policies.filter(function(item) {
// console.log('item', item);
return item.branch_id === client_branch_id_param;
});
if (foundPolicies) {
// console.log('foundPolicies', foundPolicies);
appendPolicies(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);
console.error(xhr.responseText);
}
});
$('#loader').hide();
}
function fetchFileError(file_id) {
$('#loader').show();
var apiURL = '<?php echo base_url();?>' + 'util/get-file-error/' + file_id;
// console.log('fetchFileError');
// console.log(apiURL);
$.ajax({
url: apiURL,
method: 'GET',
headers: {
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
$(this).find(".modal-body").html("");
if (response.code === 200 && response.dataStatus === true && response.data !== "") {
try {
// console.log((JSON.parse(response.data)));
var file_error_data = (JSON.parse(response.data));
var file_error_html = "";
for (var key in file_error_data['error_summary']) {
// console.log(key);
var err_id = parseInt(key);
var err_count = file_error_data['error_summary'][key];
switch (err_id) {
case 0:
file_error_html +=
"<strong>"+file_error_data['error_data']+"</strong>";
break;
case 1:
file_error_html +=
"<strong>Mandatory values missing</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
case 2:
file_error_html +=
"<strong>Values not in expected format</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
case 3:
file_error_html +=
"<strong>Field contains not allowed values</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
case 4:
file_error_html +=
"<strong>Rule Conflict</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
case 5:
file_error_html += "<strong>" + file_error_data['error_data'] + "</strong>";
break;
case 6:
file_error_html += "<strong>" + file_error_data['error_data'] + "</strong>";
break;
case 7:
file_error_html +=
"<strong>Duplicate entry in file</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
case 8:
file_error_html += "to be config";
break;
case 9:
file_error_html +=
"<strong>Duplicate entry</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
case 10:
file_error_html +=
"<strong>Duplicate entry in file</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
case 11:
file_error_html +=
"<strong>Rule conflict: Dependents not allowed</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
case 12:
file_error_html +=
"<strong>Rule conflict: Dependent count greater than allowed dependent count</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
case 13:
file_error_html +=
"<strong>Rule conflict: Twofold relationship found within family</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
case 26:
file_error_html +=
"<strong>Duplicate Employee code found</strong> <span class='badge badge-danger float-right'>" +
err_count + "</span>";
break;
default:
file_error_html += "";
break;
}
// console.log('file_error_html_1', file_error_html)
// file_error_html += (err_id == 1 ?
// "<strong>Mandatory values missing</strong> <span class='badge badge-danger float-right'>" +
// err_count + "</span>" : (err_id == 2 ?
// "<strong>Values not in expected format</strong> <span class='badge badge-danger float-right'>" +
// err_count + "</span>" : (err_id == 3 ?
// "<strong>Field contains not allowed values</strong> <span class='badge badge-danger float-right'>" +
// err_count + "</span>" : (err_id == 4 ?
// "<strong>Rule Conflict</strong> <span class='badge badge-danger float-right'>" +
// err_count + "</span>" : (err_id == 5 ? "<strong>" +
// file_error_data['error_data'] + "</strong>" : (err_id ==
// 6 ?
// "<strong>" + file_error_data['error_data'] +
// "</strong>" : ""))))));
file_error_html += '<br/>';
// // }
// console.log('file_error_html_2', file_error_html)
}
if (err_id != 5 && err_id != 6 && err_id != 0) {
file_error_html += (file_error_html != "" ?
"<a href ='<?php echo base_url()?>" +
"employee/excel_error/" + file_id +
"' target=_blank>click here to more details...</a>" : "");
}
// console.log(file_error_html);
$('#file-err-modal').find(".modal-body").html(file_error_html);
return file_error_html;
} 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 appendClients(data) {
// console.log('client_id_param', client_id_param)
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.client_name
});
if (client_id_param == item.id) {
option.attr('selected', true);
}
$('#client_id').append(option);
});
}
function appendBranch(data) {
$('#branch_id').empty();
$('#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_param == item.id) {
option.attr('selected', true);
}
$('#branch_id').append(option);
});
}
function appendPolicies(data) {
// console.log(data)
$('#policy_id').empty();
$('#policy_id').append($('<option>', {
value: '0',
text: 'Select',
selected: true
}));
$.each(data, function(index, item) {
// console.log(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_param == item.client_policy_id) {
option.attr('selected', true);
}
$('#policy_id').append(option);
});
}
$(document).ready(function() {
$('#client_id').on('change', function() {
$('#policy_id').empty();
$('#policy_id').append($('<option>', {
value: '',
text: 'Select'
}));
var selectedClient = $(this).val();
// console.log('selectedClient', 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', foundPolicies.branchs);
appendBranch(foundPolicies.branchs);
});
});
$(document).ready(function() {
$('#branch_id').on('change', function() {
var selectedClient = $(this).val();
// console.log('selectedBranch', selectedClient);
// console.log('clientPolicies', clientPoliciesWithBranch);
var foundPolicies = clientPoliciesWithBranch.policies.filter(function(item) {
// console.log('item', item);
return item.branch_id === selectedClient;
});
if (Array.isArray(foundPolicies) && foundPolicies.length === 0) {
appendPolicies(foundPolicies);
toastr.warning('No policies found for the selected client branch.');
} else {
// console.log('foundPolicies', foundPolicies);
appendPolicies(foundPolicies);
}
});
});
// Function to convert object to query parameters
function objectToQueryString(obj) {
return Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&');
}
function fetchEmpolyeeList(event) {
event.preventDefault(); // Prevent default action
var client_id = $('#client_id').val();
var policy_id = $('#policy_id').val();
// console.log(client_id + '-' + policy_id);
if (client_id == '0' || policy_id == '0') {
toastr.warning('Please select values in both dropdowns.');
return;
}
var queryParams = {
client_id: client_id,
policy_id: policy_id
};
const queryString = objectToQueryString(queryParams);
const apiURL = $('#get-emp-list').attr('href') + "?" + queryString;
// console.log(apiURL);
window.location.href = apiURL;
// var apiURL2 = $('#get-emp-list').attr('href'); // Get href attribute value
// console.log(apiURL);
// $.ajax({
// url: apiURL,
// method: 'GET',
// data: queryParams,
// success: function(response) {
// // Assuming response is a JSON array
// // displayDataTables(response);
// console.log(response);
// },
// error: function(xhr, status, error) {
// console.error('Error:', error);
// }
// });
}
//--------------------------------------------------------------------------------------
/**This function updates the download link based on the selected option in the dropdown menu. **/
$('#upload-action-type').change(function() {
var selectedValue = $(this).val();
if (selectedValue !== '') {
$('#file_upload').show();
var fullURL = '<?= base_url("util/download-excel/"); ?>' + selectedValue;
$('#excel_download').attr('href', fullURL);
} else {
$('#file_upload').hide();
$('#excel_download').removeAttr('href');
}
});
/** This function verifies if the download link (#excel_download) has its href attribute set,
** ensuring proper link configuration. **/
$('#excel_download').click(function() {
// Check if the element with ID "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.');
}
});
document.getElementById('toggleIcon1').addEventListener('click', function() {
var icon = document.getElementById('icon1');
icon.classList.toggle('mdi-chevron-down');
icon.classList.toggle('mdi-chevron-up');
});
$('#fetch_enrolled_data').click(function()
{
var policy_id = $('#policy_id').val();
var uri = '<?= base_url('util/init-Emp-onboard/') ?>' + policy_id;
// console.log(policy_id);
// console.log(uri);
$('#fetch_btn').attr('href', uri);
$('#emp_data').empty();
var client_id = $('#client_id').val();
var policy_id = $('#policy_id').val();
var action = $('#upload-action-type').val();
// console.log(client_id + '-' + policy_id);
if (client_id == '0' || policy_id == '0') {
toastr.warning('please select the client and policy for this uploaing event', 'Warning')
$('#full-width-modal').modal('hide');
return;
}
var queryParams = {
client_id: client_id,
policy_id: policy_id,
action: action
};
// console.log('queryParams', queryParams)
const queryString = objectToQueryString(queryParams);
// console.log('queryString', queryString)
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var uri = '<?= base_url('util/featch-emp-list')?>?' + queryString
// console.log(uri)
$.ajax({
url: uri,
data: {
client_id: client_id,
policy_id: policy_id
},
type: "GET",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
// console.log(res);
if (res) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
}
$('#emp_data').html(res.data);
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Something went wrong', 'Warning');
}, 1000);
}
});
})
// $(document).ready(function() {
// $('#policy_id').change(function(){
// var selectedpolicy = $(this).val();
// console.log('selectedpolicy',selectedpolicy)
// $('#upload-action-type').val('').change();
// $('#file_upload').hide();
// $('#excel_download').removeAttr('href');
// var apiURL = '<?php echo base_url();?>' + 'util/fetch-emp-count/' + selectedpolicy;
// // console.log(apiURL);
// $.ajax({
// url: apiURL,
// method: 'GET',
// headers: {
// "Content-Type": "application/json",
// "X-Requested-With": "XMLHttpRequest"
// },
// success: function(response) {
// console.log('responce data emp_count', response);
// if (response.code === 200 && response.dataStatus === true && response.data !== "") {
// try {
// console.log(response.emp_count.length)
// if(response.emp_count > 0){
// var select = document.getElementById("upload-action-type");
// for (var i = 0; i < select.options.length; i++) {
// select.options[i].disabled = false;
// if (select.options[i].value === "inception") {
// select.options[i].disabled = true;
// // break;
// }
// }
// }else {
// var select = document.getElementById("upload-action-type");
// for (var i = 0; i < select.options.length; i++) {
// select.options[i].disabled = true;
// if (select.options[i].value === "inception" || select.options[i].value === "enrollment") {
// select.options[i].disabled = false;
// }
// if (select.options[i].value === "" || select.options[i].value === "enrollment") {
// select.options[i].disabled = false;
// }
// }
// }
// } 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);
// var select = document.getElementById("upload-action-type");
// for (var i = 0; i < select.options.length; i++) {
// if (select.options[i].value === "inception" || select.options[i].value === "enrollment" ) {
// select.options[i].disabled = false;
// break;
// }
// }
// }
// });
// if($('#policy_id').val() == 0){
// var select = document.getElementById("upload-action-type");
// console.log('select', select)
// for (var i = 0; i < select.options.length; i++) {
// select.options[i].disabled = false;
// console.log(select.options[i])
// }
// }
// })
// })
function checkPolicyTermsAndRackRatesHasDefiend(event)
{
// console.log(event.target.id);
var policy_id = (event.target.value);
console.log('checkPolicyTermsAndRackRatesHasDefiend called ' + policy_id);
if(policy_id != 0 && policy_id != " " && policy_id != undefined)
{
var apiURL = '<?php echo base_url();?>' + 'util/has_policy_config_completed/' + policy_id;
// console.log(apiURL);
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: apiURL,
method: 'GET',
headers: {
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 300);
console.log('check policy responce', response);
if (response.hasOwnProperty('si_enhancement') && response.si_enhancement == 0) {
$('.si-enhancement-option').hide();
} else {
$('.si-enhancement-option').show();
}
var event = response.insurer_multi_event ;
$('#event_type_data').val(response.insurer_multi_event);
if(event == 1){
$("#event_type").attr("multiple", "multiple");
$("#event_type").attr("name", "event_type[]");
$("#event_type").select2();
}else{
$("#event_type").removeAttr("multiple");
$("#event_type").attr("name", "event_type");
if ($('event_type').data('select2')) {
$('event_type').select2('destroy');
}
// $("#event_type").select2('destroy');
}
if (response.code === 200 && response.dataStatus === true && response.message !== null) {
toastr.error(response.message, 'Error');
$('#emp_form_submit_button').prop('disabled', true);
return false;
}
else if(response.code === 200 && response.dataStatus === true && response.message == null)
{
// toastr.error('Policy Terms or rack rate not defined!', 'Error');
$('#emp_form_submit_button').prop('disabled', false);
return true;
}
else
{
toastr.error('Policy Terms or rack rate not defined!', 'Error');
return false;
}
},
error: function(xhr, status, error) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 300);
// toastr.error('Something went wrong! Try Later', 'Error');
console.error('Error fetching data from checkPolicyTermsAndRackRatesHasDefiend API:', error);
return false;
}
});
}
}
function checkValues() {
var clientId = $('#client_id').val();
var policyId = $('#policy_id').val();
var branchId = $('#branch_id').val();
var uploadActionType = $('#upload-action-type').val();
if (!clientId || clientId == '0') {
// alert('Client ID is empty or zero');
return 'client';
}
if (!branchId || branchId == '0') {
// alert('Branch ID is empty or zero');
return 'branch';
}
if (!policyId || policyId == '0') {
// alert('Policy ID is empty or zero');
return 'policy';
}
if (!uploadActionType || uploadActionType == '0') {
// alert('Upload action type is empty or zero');
return 'event';
}
// If all values are valid, return true
// return true;
}
//---------------------------------------------------------------------------------------------------------
</script>