526 lines
22 KiB
PHP
Executable File
526 lines
22 KiB
PHP
Executable File
<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') . ' 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 -->
|
||
|
||
|
||
<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">ReUpload the file</h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<!-- Added data-parsley-validate for auto initialization -->
|
||
<form class="parsley-examples" id="uploadForm" enctype="multipart/form-data" data-parsley-validate>
|
||
<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="client_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">
|
||
|
||
<div class="form-group mb-3">
|
||
<label for="fileInput">Choose Excel File</label>
|
||
<input type="file" id="fileInput" name="emplist" class="form-control-file" required
|
||
accept=".xlsx, .xls, .ods">
|
||
</div>
|
||
|
||
<div class="text-right">
|
||
<button type="submit" id="uploadBtn" class="btn btn-primary">Upload Now</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<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').on('submit', function(e) {
|
||
// 1. STOP the default page reload
|
||
e.preventDefault();
|
||
|
||
// 2. Validate using Parsley
|
||
var form = $(this);
|
||
var isValid = form.parsley().validate();
|
||
|
||
if (!isValid) {
|
||
console.warn('Form validation failed');
|
||
return false;
|
||
}
|
||
|
||
// 3. UI Feedback (Disable button to prevent multiple clicks)
|
||
var $btn = $('#uploadBtn');
|
||
$btn.prop('disabled', true).text('Uploading...');
|
||
|
||
// 4. Prepare Data
|
||
var formData = new FormData(this);
|
||
|
||
// 5. API Call
|
||
$.ajax({
|
||
url: '<?= base_url("employee/upload") ?>',
|
||
type: "POST",
|
||
data: formData,
|
||
processData: false,
|
||
contentType: false,
|
||
headers: {
|
||
"X-Requested-With": "XMLHttpRequest"
|
||
},
|
||
success: function(response) {
|
||
console.log('API Response:', response);
|
||
|
||
if (response.code == 200 && response.dataStatus == true) {
|
||
toastr.success('File upload success, Data validation is in-progress', 'Success');
|
||
$('.close').click(); // Close Modal
|
||
form[0].reset(); // Clear Form
|
||
} else {
|
||
toastr.error(response.message || 'Upload failed', 'Error');
|
||
$btn.prop('disabled', false).text('Upload'); // Re-enable if failed
|
||
}
|
||
},
|
||
error: function(xhr) {
|
||
console.error("Critical Error:", xhr.responseText);
|
||
toastr.error('Something went wrong on the server', 'Error');
|
||
$btn.prop('disabled', false).text('Upload');
|
||
},
|
||
complete: function() {
|
||
// This ensures the reload only happens AFTER the API process is totally done
|
||
console.log("Process complete. Reloading...");
|
||
setTimeout(function() {
|
||
window.location.reload();
|
||
}, 500);
|
||
}
|
||
});
|
||
});
|
||
|
||
$('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>
|