544 lines
21 KiB
PHP
Executable File
544 lines
21 KiB
PHP
Executable File
<style>
|
|
|
|
</style>
|
|
|
|
|
|
<div class="tab-pane fade" id="KYC-DOC-tab">
|
|
|
|
<div class="col-lg-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table id="kyc_table" class="table table-sm mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>Document Name</th>
|
|
<th>Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="tbody">
|
|
</tbody>
|
|
</table>
|
|
</div> <!-- end table-responsive-->
|
|
|
|
<hr>
|
|
|
|
<button class="btn btn-primary waves-effect waves-light btn-sm" id="btn_other_docs">Other Documents</button>
|
|
|
|
</div>
|
|
</div> <!-- end card -->
|
|
</div> <!-- end col -->
|
|
|
|
<div class="row" id="others">
|
|
<div class="col-12">
|
|
<div class="card" style="margin-left: 12px;margin-right: -12px;">
|
|
<div class="card-body">
|
|
<form role="form" class="parsley-examples" method="post" id="kyc_form"
|
|
enctype="multipart/form-data">
|
|
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
|
|
<input type="hidden" name="PrimaryKey" id="kyc_PrimaryKey" value="<?= isset($client['id']) ? $client['id'] : '' ?>"/>
|
|
<input type="hidden" name="client_id" id="client_id_kyc" value="<?= isset($client['id']) ? $client['id'] : '' ?>"/>
|
|
<input type="hidden" name="kyc_doc_type_id" value="0" />
|
|
<div class="form-group">
|
|
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label for="emp_code">Other Documents<span
|
|
class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="other_docs_name" placeholder="Document Name" name="other_docs_name" required>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="kyc_docs">File<span
|
|
class="text-danger">*</span></label>
|
|
<input class="form-control" type="file" name="file_name" id="kyc_docs_file" required accept=".pdf, .jpeg, .jpg, .png">
|
|
</div>
|
|
<!-- <div class="form-group col-md-4 align-self-end"> -->
|
|
<div class="form-group col-md-4" style="<?= isset($client['id']) ? 'margin-top: 41px;' : 'margin-top: 30px;' ?>">
|
|
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"id="btnSubmit">Upload</button>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div> <!-- end col-->
|
|
</div> <!-- end row -->
|
|
|
|
<div class="col-lg-12" id="other_docs_table">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table id="kyc_table" class="table table-sm mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>Document Name</th>
|
|
<th>File Name</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="other_docs">
|
|
</tbody>
|
|
</table>
|
|
</div> <!-- end table-responsive-->
|
|
|
|
</div>
|
|
</div> <!-- end card -->
|
|
</div> <!-- end col -->
|
|
|
|
</div>
|
|
<!-- end -->
|
|
|
|
<script>
|
|
|
|
var kycPrimaryKey = $('#client_id_kyc').val();
|
|
|
|
$(document).ready(function(){
|
|
|
|
kycPrimaryKey = $('#kyc_PrimaryKey').val();
|
|
|
|
$('#others').hide()
|
|
$('#other_docs_table').hide();
|
|
|
|
$(document).on('click', '.submit', function(e) {
|
|
|
|
e.preventDefault();
|
|
kycPrimaryKey = $('#id_for_kyc_file').val();
|
|
|
|
var form = $(this).closest('form');
|
|
var formData = new FormData(form[0]);
|
|
var fileInputs = form.find('input[type="file"]');
|
|
var allowedExtensions = ['pdf', 'png', 'jpeg', 'jpg'];
|
|
|
|
|
|
if (kycPrimaryKey === '') {
|
|
toastr.error('Client is required', 'Error');
|
|
form.trigger('reset')
|
|
return;
|
|
}
|
|
|
|
var isFormEmpty = true;
|
|
fileInputs.each(function() {
|
|
var files = $(this)[0].files;
|
|
if (files.length > 0) {
|
|
for (var i = 0; i < files.length; i++) {
|
|
var fileName = files[i].name;
|
|
var fileExtension = fileName.split('.').pop().toLowerCase();
|
|
if (allowedExtensions.indexOf(fileExtension) === -1) {
|
|
form.trigger('reset')
|
|
toastr.warning('File type not allowed: ' + fileName, 'Only Allowed pdf, png, jpg and jpeg');
|
|
return;
|
|
}
|
|
}
|
|
isFormEmpty = false;
|
|
return false;
|
|
}
|
|
});
|
|
|
|
if (isFormEmpty) {
|
|
toastr.warning('Form is Empty', 'Warning');
|
|
return;
|
|
}
|
|
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
$.ajax({
|
|
url: '<?= base_url("client/kyc/create"); ?>',
|
|
type: 'POST',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
success: function (res) {
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000);
|
|
// res = JSON.parse(res)
|
|
console.log(res);
|
|
|
|
if(res){
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
toastr.success('File Uploaded successfully', 'Success');
|
|
}, 500);
|
|
}
|
|
|
|
form.trigger('reset')
|
|
$.each(res.data, function (index, item) {
|
|
|
|
$('#name_'+item.kyc_doc_type_id).show();
|
|
$('#name_'+item.kyc_doc_type_id).html(item.file_name);
|
|
$('#form_'+item.kyc_doc_type_id).hide();
|
|
|
|
// var url = "<?= base_url('/downloadGdriveFile'); ?>" +
|
|
// "?client_id=" + item.client_id +
|
|
// "&file_type=kyc" +
|
|
// "&file_name=" + item.file_name +
|
|
// "&client_policy_id=client_policy_id";
|
|
|
|
var url = '<?= base_url('download-kyc-docs/') ?>' + item.file_name;
|
|
|
|
// console.log('step 1')
|
|
|
|
if(item.file_name != null && item.file_name != ""){
|
|
// console.log('step 2')
|
|
|
|
$('#download_'+item.kyc_doc_type_id).show();
|
|
$('#download_' + item.kyc_doc_type_id).attr('href', url);
|
|
$('#delete_'+item.kyc_doc_type_id).show();
|
|
|
|
}
|
|
else{
|
|
// console.log('step 3')
|
|
|
|
$('#download_'+item.kyc_doc_type_id).hide();
|
|
$('#download_' + item.kyc_doc_type_id).attr('href', '#');
|
|
$('#delete_'+item.kyc_doc_type_id).hide();
|
|
|
|
}
|
|
// console.log('step 4')
|
|
|
|
});
|
|
|
|
},
|
|
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 Wrong!', 'Warning');
|
|
}, 1000);
|
|
|
|
}
|
|
});
|
|
});
|
|
|
|
if(kycPrimaryKey !== ''){
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
var entity_type_id = '<?= isset($client['entity_type_id']) ? $client['entity_type_id'] : '' ?>'
|
|
var client_id = '<?= isset($client['id']) ? $client['id'] : '' ?>'
|
|
getKYCEntityDocument(entity_type_id, client_id);
|
|
|
|
var data = <?= isset($client_kyc) ? json_encode($client_kyc) : '[]' ?>;
|
|
appendKycTableListData(data)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
$('#btn_other_docs').click(function(){
|
|
$('#others').toggle();
|
|
$('#other_docs_table').toggle();
|
|
});
|
|
|
|
/*** for Others documents form submit ***/
|
|
$("#kyc_form").submit(function(event) {
|
|
event.preventDefault();
|
|
|
|
var isValid = $('#kyc_form').parsley().validate();
|
|
var rowHtml = '';
|
|
var form_action = '';
|
|
if (isValid) {
|
|
|
|
if(kycPrimaryKey === ''){
|
|
form_action = '<?= base_url("client/kyc/create"); ?>';
|
|
}else{
|
|
form_action = '<?= base_url("client/kyc/edit"); ?>';
|
|
}
|
|
var formData = new FormData($('#kyc_form')[0]);
|
|
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
$.ajax({
|
|
data: formData,
|
|
url: '<?= base_url("client/kyc/create"); ?>',
|
|
type: "POST",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(res) {
|
|
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000);
|
|
// console.log(res);
|
|
$('#kyc_form').trigger('reset');
|
|
if(res){
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
var message = (kycPrimaryKey === '') ? 'KYC Other Docs Uploaded successfully' : 'KYC Other Docs Uploaded successfully';
|
|
toastr.success(message, 'Success');
|
|
}, 500);
|
|
}
|
|
|
|
var other_docs_count = 0;
|
|
|
|
$('#other_docs tr').remove();
|
|
$.each(res.data, function(index, item) {
|
|
|
|
if(item.other_docs_name != ""){
|
|
|
|
other_docs_count++;
|
|
}
|
|
|
|
// var url = "<?= base_url('/downloadGdriveFile'); ?>" +
|
|
// "?client_id=" + item.client_id +
|
|
// "&file_type=kyc" +
|
|
// "&file_name=" + item.file_name +
|
|
// "&client_policy_id=client_policy_id";
|
|
|
|
|
|
var url = '<?= base_url('download-kyc-docs/') ?>' + item.file_name;
|
|
|
|
// console.log("Current item:", item);
|
|
if (item.kyc_doc_type_id == '0') {
|
|
// console.log("Appending item:", item);
|
|
var rowHtml = `
|
|
<tr id="kyc-${item.id}">
|
|
<td>${item.other_docs_name}</td>
|
|
<td>${item.file_name}</td>
|
|
<td>
|
|
<a href = "${url}" data-id="${item.id}" class="fa fa-download" style="font-size:18px;" download></a>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
}
|
|
$('#other_docs').append(rowHtml);
|
|
|
|
//<i data-id="${item.id}" class="mdi mdi-delete btnKycOtherDelete" style="font-size:18px;"></i>
|
|
|
|
|
|
if(other_docs_count > 0){
|
|
$('#others').show()
|
|
$('#other_docs_table').show();
|
|
}
|
|
});
|
|
},
|
|
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 Wrong!', 'Warning');
|
|
}, 1000);
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
});
|
|
|
|
$('body').on('click', '.btnKycDelete', function () {
|
|
|
|
Swal.fire({
|
|
title: "Are you sure?",
|
|
text: "You won't be able to revert this!",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#3085d6",
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonText: "Yes, delete it!"
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
|
|
var kyc_id = $(this).attr('data-id');
|
|
$.get('<?php echo base_url('client/kyc/delete/');?>'+kyc_id, function (data) {
|
|
// console.log('kyc-'+ kyc_id)
|
|
// console.log(data)
|
|
if(data){
|
|
$('#form_'+kyc_id).show();
|
|
$('#name_'+kyc_id).hide();
|
|
}
|
|
})
|
|
}
|
|
});
|
|
});
|
|
|
|
$('body').on('click', '.btnKycOtherDelete', function () {
|
|
|
|
Swal.fire({
|
|
title: "Are you sure?",
|
|
text: "You won't be able to revert this!",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#3085d6",
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonText: "Yes, delete it!"
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
|
|
var kyc_id = $(this).attr('data-id');
|
|
$.get('<?php echo base_url('util/kyc-other-docs-delete/');?>'+kyc_id, function (data) {
|
|
// console.log('kyc-'+ kyc_id)
|
|
if(data){
|
|
$('#kyc-'+ kyc_id).remove();
|
|
}
|
|
})
|
|
}
|
|
});
|
|
});
|
|
|
|
function getKYCEntityDocument(entity_type_id, client_id){
|
|
|
|
$.ajax({
|
|
url: '<?= base_url("client/kyc/list/"); ?>' + entity_type_id,
|
|
type: "GET",
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
success: function (res) {
|
|
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000);
|
|
|
|
var tbody = $('#tbody');
|
|
tbody.empty();
|
|
|
|
$.each(res.data, function(index, item) {
|
|
var row = `<tr>
|
|
<td>${item.file_name}</td>
|
|
<td id="form_${item.id}">
|
|
<form class="ajax">
|
|
<input class="file-input__input" type="file" name="file_name">
|
|
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>">
|
|
<input type="hidden" class="form-control" value="${item.id}" name="kyc_doc_type_id">
|
|
<input type="hidden" name="client_id" value="${client_id}">
|
|
<button class="btn btn-sm btn-primary submit" style="position: relative; right: 80px;">Submit</button>
|
|
</form>
|
|
</td>
|
|
<td id="name_${item.id}" style="display:none;"></td>
|
|
<td>
|
|
<a id="download_${item.id}" data-id="${item.id}" class="fa fa-download" style="font-size:18px; display: none" download></a>
|
|
</td>
|
|
</tr>`;
|
|
tbody.append(row);
|
|
});
|
|
//<i id="delete_${item.id}" data-id="${item.id}" class="mdi mdi-delete btnKycDelete" style="font-size:18px; display: none"></i>
|
|
},
|
|
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 Wrong!', 'Warning');
|
|
}, 1000);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
function appendKycTableListData(data){
|
|
|
|
// console.log('-----------------------------------------------------------')
|
|
// console.log('appendKycTableListData function called')
|
|
// console.log('-----------------------------------------------------------')
|
|
|
|
var table = '';
|
|
|
|
$('#other_docs tr').remove();
|
|
|
|
var other_docs_count = 0;
|
|
|
|
$.each(data, function(index, item) {
|
|
|
|
if(item.other_docs_name != ""){
|
|
|
|
other_docs_count++;
|
|
}
|
|
|
|
|
|
// var url = "<?= base_url('/downloadGdriveFile'); ?>" +
|
|
// "?client_id=" + item.client_id +
|
|
// "&file_type=kyc" +
|
|
// "&file_name=" + item.file_name +
|
|
// "&client_policy_id=client_policy_id";
|
|
|
|
var url = '<?= base_url('download-kyc-docs/') ?>' + item.file_name;
|
|
|
|
|
|
if(item.kyc_doc_type_id == '0'){
|
|
table += `
|
|
<tr id="kyc-${item.id}">
|
|
<td>${item.other_docs_name}</td>
|
|
<td>${item.file_name}</td>
|
|
<td>
|
|
<a href = "${url}" data-id="${item.id}" class="fa fa-download" style="font-size:18px;" target="_blank"></a>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
|
|
}
|
|
// <i data-id="${item.id}" class="mdi mdi-delete btnKycOtherDelete" style="font-size:18px;"></i>
|
|
|
|
});
|
|
|
|
$('#other_docs').append(table);
|
|
|
|
if(other_docs_count > 0){
|
|
$('#others').show()
|
|
$('#other_docs_table').show();
|
|
}
|
|
|
|
$.each(data, function(index, item) {
|
|
// console.log(item.kyc_doc_type_id);
|
|
// console.log('name_' + item.kyc_doc_type_id);
|
|
// console.log(document.getElementById('name_' + item.kyc_doc_type_id));
|
|
setTimeout(function() {
|
|
$('#name_'+item.kyc_doc_type_id).show();
|
|
$('#name_'+item.kyc_doc_type_id).html(item.file_name);
|
|
$('#form_'+item.kyc_doc_type_id).hide();
|
|
|
|
// console.log('step 1')
|
|
|
|
// var url = "<?= base_url('/downloadGdriveFile'); ?>" +
|
|
// "?client_id=" + item.client_id +
|
|
// "&file_type=kyc" +
|
|
// "&file_name=" + item.file_name +
|
|
// "&client_policy_id=client_policy_id";
|
|
|
|
var url = '<?= base_url('download-kyc-docs/') ?>' + item.file_name;
|
|
|
|
|
|
if(item.file_name != null && item.file_name != ""){
|
|
// console.log('step 2')
|
|
|
|
$('#download_'+item.kyc_doc_type_id).show();
|
|
$('#download_' + item.kyc_doc_type_id).attr('href', url).attr('target', '_blank');;
|
|
$('#delete_'+item.kyc_doc_type_id).show();
|
|
}
|
|
else{
|
|
// console.log('step 3')
|
|
|
|
$('#download_'+item.kyc_doc_type_id).hide();
|
|
$('#download_' + item.kyc_doc_type_id).attr('href', '#');
|
|
$('#delete_'+item.kyc_doc_type_id).hide();
|
|
|
|
|
|
}
|
|
// console.log('step 4')
|
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|