512 lines
22 KiB
PHP
512 lines
22 KiB
PHP
<?php //echo fancy_date_time_format('2024-01-01 15:40:32');echo '<br>';?>
|
||
<?php //echo fancy_date_time_format('2024-02-01 15:40:32');echo '<br>';?>
|
||
<!-- <?php echo fancy_date_time_format('2024-02-10 15:40:32');echo '<br>';?> -->
|
||
<!-- <?php echo fancy_date_time_format('2024-02-13 14:40:32');echo '<br>';?> -->
|
||
<!-- <?php echo fancy_date_time_format('2024-02-13 14:58:00');echo '<br>';?> -->
|
||
|
||
|
||
|
||
<div class="tab-pane fade active show" id="general-q-tab">
|
||
<div class="row">
|
||
<div class="col-xl-6">
|
||
<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 id="emp-upload-form" action="<?php echo base_url().'employee/upload'?>" method="post">
|
||
<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="">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">
|
||
<option value="">Select</option>
|
||
</select>
|
||
</div>
|
||
|
||
<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.">".$action."</option>";
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<hr>
|
||
|
||
<div class="form-row" id="file_upload">
|
||
|
||
<div class="form-group col-md-4">
|
||
<label>Upload file</label> [ <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>
|
||
|
||
</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>
|
||
|
||
|
||
|
||
<!-- 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();
|
||
|
||
// Declare a global variable to store API response data
|
||
var clientPolicies = [];
|
||
|
||
$(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');
|
||
|
||
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 ');
|
||
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();
|
||
|
||
|
||
|
||
});
|
||
|
||
|
||
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.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);
|
||
appendClients(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 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 = key;
|
||
var err_count = file_error_data['error_summary'][key];
|
||
switch (err_id) {
|
||
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;
|
||
|
||
default:
|
||
file_error_html += "";
|
||
break;
|
||
}
|
||
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/>';
|
||
// }
|
||
|
||
}
|
||
if (err_id != 5 && err_id != 6) {
|
||
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) {
|
||
$.each(data, function(index, item) {
|
||
$('#client_id').append($('<option>', {
|
||
value: item.id,
|
||
text: item.client_name
|
||
}));
|
||
});
|
||
}
|
||
|
||
function appendPolicies(data) {
|
||
$('#policy_id').empty();
|
||
$('#policy_id').append($('<option>', {
|
||
value: '',
|
||
text: 'Select'
|
||
}));
|
||
|
||
$.each(data, function(index, item) {
|
||
$('#policy_id').append($('<option>', {
|
||
value: item.id,
|
||
text: item.name
|
||
}));
|
||
});
|
||
}
|
||
|
||
$('#client_id').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);
|
||
appendPolicies(foundPolicies.policies);
|
||
});
|
||
|
||
// 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') {
|
||
alert('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');
|
||
});
|
||
//--------------------------------------------------------------------------------------
|
||
</script>
|