nhance-enrollment/app/Views/file_list.php

523 lines
22 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>
.modal-full-width {
width: 95% !important;
max-width: none;
}
.reload:hover {
cursor: pointer;
}
</style>
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row" style="padding-bottom: 10px;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Files</h4>
</div>
</div>
<table class="table table-hover m-0 table-centered dt-responsive w-100" cellspacing="0"
id="tickets-table">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">SNO</th>
<th class="font-weight-medium">File name</th>
<th class="font-weight-medium">Client</th>
<th class="font-weight-medium">Client Branch</th>
<th class="font-weight-medium">Policy</th>
<th class="font-weight-medium">Event</th>
<th class="font-weight-medium">User/Time</th>
<th class="font-weight-medium">Status</th>
<th class="font-weight-medium">Action</th>
</tr>
</thead>
<tbody class="font-12">
<?php
if (isset($fileList)) {
foreach ($fileList as $key => $file) { //print_r((json_decode($file['reason'])));
// $reason = json_decode(($file['reason']));
// $reason = "{'date':'value data kbckl kcn/aksl'}";
// echo $reason;
?>
<td class="reload truncate"
data-toggle="tooltip"
data-placement="top"
data-html="true"
title="<?php
echo 'Enrollment Open Date : ' .
(!empty($file['enrollment_open_date'])
? change_date_format($file['enrollment_open_date'], 'Y-m-d', 'd/m/Y')
: 'N/A'
) .
'<br>' .
'Enrollment Close Date : ' .
(!empty($file['enrollment_close_date'])
? change_date_format($file['enrollment_close_date'], 'Y-m-d', 'd/m/Y')
: 'N/A'
);
?>">
<b>
<?php echo ($key + 1) ?>
</b></td>
<td style="overflow: hidden;" class="reload truncate" data-toggle="tooltip" data-placement="top" title="<?php echo $file['file_name'] ?>">
<?php echo $file['file_name']?>
</td>
<td><?php echo $file['short_name'] ?></td>
<td><?php echo $file['branch_name'] ?></td>
<!-- <td><?php echo isset($file['policy_name']) ? $file['policy_name'] : '' ?> - <?php echo isset($file['policy_no']) ? $file['policy_no'] : '' ?> - <?php echo isset($file['policy_type']) ? $file['policy_type'] : '' ?></td> -->
<td><?php echo isset($file['policy_type']) ? $file['policy_type'] : '' ?> - <?php echo isset($file['policy_no']) ? $file['policy_no'] : '' ?></td>
<td><?= $file['action'] == 'enrollment' ? 'Enrolment' : $file['action'] ?></td>
<td><?php echo change_date_format($file['created_at'],'Y-m-d H:i:s', 'd M Y h:i a') . ' by <strong>' . $file['first_name'] . '</strong>' ?>
</td>
<td>
<?php
if ($file['status'] == 'failed') {
echo $file['status'] . " <span class='col-xl-3 col-lg-4 col-sm-6'> <i class='fe-alert-circle' data-toggle='modal' data-target='#file-err-modal' data-err=" . $file['id'] . "></i></span>";
} else if ($file['status'] == 'inprogress') {
if ($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addtion') {
$tool_tip_text = "Live(s) : {$file['employee_count']}" . " | Total premium : ₹ " . format_indian_number($file['total'], 2, ',') . " | Click to reload";
echo '<a data-toggle="tooltip" data-placement="top" data-id="' . $file['status'] . '" class="reload" title="' . $tool_tip_text . '" href="#">' . $file['status'] . '</a>';
}else{
echo '<a data-id="' . $file['status'] . '" class="reload" href="#">' . $file['status'] . '</a>';
}
} else if ($file['status'] == 'Success') {
if ($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addtion') {
$tool_tip_text = "Live(s) : {$file['employee_count']}" . " | Total premium : ₹ " . format_indian_number($file['total'], 2, ',');
// $tool_tip_text = "dssd";
// Total Amount : $file['total']";
echo '<span data-toggle="tooltip" data-placement="top" data-id="' . $file['status'] . '" title=" ' . $tool_tip_text . ' ">' . $file['status'] . '</span>';
}else{
echo '<span data-id="' . $file['status'] . '" >' . $file['status'] . '</span>';
}
}else{
echo '<span data-id="' . $file['status'] . '" >' . $file['status'] . '</span>';
}
?>
</td>
<td>
<div class="btn-group dropdown">
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm"
data-toggle="dropdown" aria-expanded="false"><i
class="mdi mdi-dots-horizontal"></i></a>
<div class="dropdown-menu dropdown-menu-right">
<?php if ($file['status'] == 'failed') { ?>
<a data-id="<?=
htmlspecialchars(json_encode([
'client_id' => $file['client_id'],
'client_policy_id' => $file['client_policy_id'],
'client_branch_id' => $file['client_branch_id'],
'enrollment_open_date' => change_date_format($file['enrollment_open_date'] , 'Y-m-d', 'd/m/Y'),
'enrollment_close_date' => change_date_format($file['enrollment_close_date'], 'Y-m-d', 'd/m/Y' ),
'action' => $file['action']
]))
?>" data-toggle="modal" data-target="#file-upload-modal" class="dropdown-item upload_button" href="#"><i class="mdi mdi-upload mr-2 text-muted font-18 vertical-middle"></i>Re-Upload</a>
<?php } ?>
<a class="dropdown-item" href="<?= base_url("util/download-file-list/") . $file['id']; ?>"><i class="mdi mdi-download mr-2 text-muted font-18 vertical-middle"></i>Download</a>
<a data-id="<?php echo $file['id'] ?>" data-toggle="modal" data-target="#full-width-modal-emp-list" class="dropdown-item view_emp_list" href="#"><i class="mdi mdi-eye mr-2 text-muted font-18 vertical-middle"></i>View</a>
<?php if ($file['status'] == 'Success') { ?>
<a data-id="<?php echo $file['id'] ?>" class="dropdown-item truncate2" href="#"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Truncate</a>
<?php } ?>
</div>
</div>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
</div>
</div><!-- end col -->
<div id="full-width-modal-emp-list" 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">Upload Employee List <span
id="title_header_name"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body" id="emp_data_success">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Center modal content for reupload file-->
<div class="modal fade" id="file-upload-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">ReUpload the file</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form class="parsley-examples" id="uploadForm" action="<?php echo base_url() . 'employee/upload' ?>"
enctype="multipart/form-data">
<input type="hidden" id="file_client_id" name="client_id">
<input type="hidden" id="file_policy_id" name="policy_id">
<input type="hidden" id="file_branch_id" name="branch_id">
<input type="hidden" id="file_enrollment_open_date" name="enrollment_open_date">
<input type="hidden" id="file_enrollment_close_date" name="enrollment_close_date">
<input type="hidden" id="file_upload_actions" name="upload-action-type">
<input type="file" id="fileInput" name="emplist" required
accept=" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet">
<button type="submit" class="btn btn-primary">Upload</button>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
$('body').on('click', '.view_emp_list', function() {
console.log('file_id', 'file_id');
$('#emp_data_success').empty();
$('#title').html(' ');
var file_id = $(this).attr('data-id');
console.log(file_id);
var queryParams = {
file_id: file_id,
};
console.log('queryParams', queryParams)
const queryString = objectToQueryString(queryParams);
console.log('queryString', queryString)
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var uri = '<?= base_url('util/view-success-emp-list') ?>?' + queryString
console.log(uri)
$.ajax({
url: uri,
data: {
file_id: file_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);
}
var title = " - ";
if (res.file_data) {
title += (res.file_data.file_name || "") + " - ";
title += (res.file_data.short_name || "") + " - ";
title += (res.file_data.policy_name || "") + " - ";
title += (res.file_data.action || "") + " - ";
title += (res.file_data.status || "");
}
$('#title_header_name').html(title);
$('#emp_data_success').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);
}
});
})
$('body').on('click', '.upload_button', function() {
$('#uploadForm')[0].reset();
console.log('file_id');
var fileId = JSON.parse(this.getAttribute('data-id'));
console.log(fileId); // Use fileId as needed
$('#file_client_id').val(fileId.client_id)
$('#file_policy_id').val(fileId.client_policy_id)
$('#file_branch_id').val(fileId.client_branch_id)
$('#file_enrollment_open_date').val(fileId.enrollment_open_date)
$('#file_enrollment_close_date').val(fileId.enrollment_close_date)
$('#file_branch_id').val(fileId.client_branch_id)
$('#file_upload_actions').val(fileId.action)
})
$('body').on('click', '.truncate2', function(event) {
event.preventDefault();
// console.log(event);
var fileId = JSON.parse(this.getAttribute('data-id'));
console.log('Truncate File ID' + fileId);
Swal.fire({
title: "Do you want to truncate data from uploaded file?",
showCancelButton: true,
confirmButtonText: "Delete",
confirmButtonColor: "#ff3333",
}).then((result) => {
console.log(result);
if (result.isConfirmed) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var apiURL = '<?php echo base_url(); ?>employee/truncate/' + fileId;
// console.log('Truncate API URL : ', apiURL);
$.ajax({
url: apiURL,
method: 'GET',
headers: {
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
// console.log('Truncate Response', response)
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
if (response.code === 200 && response.dataStatus === true && response.data !== "") {
Swal.fire({
title: "Deleted!",
icon: "success"
});
} else if (response.code === 404 && response.dataStatus === false) {
console.error('No data found', response);
handleNoDataFound(response, fileId);
} else {
Swal.fire({
title: "Failed!",
text: 'Something went wrong! Try later',
icon: "error"
});
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
console.error('Error fetching data from API:', error);
toastr.error('Something went wrong! Try later', 'Error');
}
});
}
});
})
function handleNoDataFound(response, fileId) {
if (response.role == 1 || response.role == 5) {
Swal.fire({
title: response.message,
showCancelButton: true,
confirmButtonText: "Delete",
confirmButtonColor: "#ff3333",
}).then((result) => {
console.log(result);
if (result.isConfirmed) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var apiURL = '<?php echo base_url(); ?>employee/truncate/' + fileId + '/' + <?= get_role_id(); ?>;
$.ajax({
url: apiURL,
method: 'GET',
headers: {
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
if (response.code === 200 && response.dataStatus === true && response.data !== "") {
Swal.fire({
title: "Deleted!",
icon: "success"
});
} else if (response.code === 404 && response.dataStatus === false) {
console.error('No data found', response);
Swal.fire({
title: "Failed!",
text: response.message,
icon: "error"
});
} else {
Swal.fire({
title: "Failed!",
text: 'Something went wrong! Try later',
icon: "error"
});
}
},
error: function(xhr, status, error) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
console.error('Error fetching data from API:', error);
console.error('Something went wrong! Try later', 'Error');
}
});
}
});
} else {
Swal.fire({
title: "Failed!",
text: response.message,
icon: "error"
});
}
}
$('#uploadForm').submit(function() {
var isValid = $('#uploadForm').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]);
}
// 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) {
console.log(response);
$('#uploadForm')[0].reset();
if (response.code === 200 && response.dataStatus === true && response
.data !== "") {
toastr.success(
'File upload successs, Data validation is in-progress',
'Success');
$('.close').click()
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');
$('#uploadForm')[0].reset();
window.location.reload(true);
}
});
})
$('body').on('click', '.reload', function() {
console.log('status');
status = this.getAttribute('data-id')
console.log(status);
if (status == 'inprogress') {
window.location.reload(true);
}
})
$(document).ready(function() {
$('#tickets-table').DataTable({
dom: "<'row'<'col-sm-0'f><'col-sm-9 text-right'B>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
"buttons": [{
"extend": 'csv',
"text": 'CSV',
"title": 'Employee-Upload-List',
"className": 'my_class',
"exportOptions": {
"columns": ':not(:last-child)'
},
}],
"initComplete": function(settings, json) {
$('.my_class').css({
"position": "relative",
"left": "79px"
});
},
language: {
search: "_INPUT_",
searchPlaceholder: "Search..."
},
paging: true,
});
});
</script>