482 lines
20 KiB
PHP
Executable File
482 lines
20 KiB
PHP
Executable File
<style> .card-body{ margin-top: 0px !important; } </style>
|
|
|
|
<div class="tab-pane fade" id="KYC-DOC-tab">
|
|
|
|
<div class="col-lg-12">
|
|
<div class="card" id="collapseOne">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table data-custom-table-css="second-table" id="kyc_table" class="table table-sm mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>S. No</th>
|
|
<th>Document Name</th>
|
|
<th>Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="tbody">
|
|
<?= isset($client_kyc_primary_table) ? $client_kyc_primary_table : "" ?>
|
|
</tbody>
|
|
</table>
|
|
</div> <!-- end table-responsive-->
|
|
|
|
<!-- <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" id="collapseOne" style="margin-left: 12px;margin-right: -12px;">
|
|
<div class="card-body">
|
|
<h3>Additional Documents</h3>
|
|
<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="" />
|
|
<div class="form-group">
|
|
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label for="emp_code">Document Name<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">Save</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" id="collapseOne">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table data-custom-table-css="second-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">
|
|
<?= isset($client_kyc_other_table) ? $client_kyc_other_table : "" ?>
|
|
</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();
|
|
$(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) {
|
|
|
|
console.log('KYC PRIMARY SUBMIT', res);
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
if(res.status == true){
|
|
$('#tbody').empty();
|
|
$('#tbody').append(res.data);
|
|
toastr.success('File uploaded successfully', 'Success');
|
|
}else{
|
|
toastr.warning('File uploaded failed', 'Warning');
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
if (xhr.status === 400) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
let errorMessages = "";
|
|
let seenMessages = []; // Array to store unique messages
|
|
if (response.errors) {
|
|
$.each(response.errors, function (field, message) {
|
|
if (!seenMessages.includes(message)) {
|
|
errorMessages += `• ${message}<br>`;
|
|
seenMessages.push(message); // Mark this message as "seen"
|
|
}
|
|
});
|
|
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
|
} else {
|
|
toastr.warning(response.message || 'Validation failed', 'Warning');
|
|
}
|
|
} else if (xhr.status === 403) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
toastr.error(response.message, 'Security Policy');
|
|
} else if (xhr.status === 404) {
|
|
toastr.warning('Resource not found', 'Warning');
|
|
} else if (xhr.status === 500) {
|
|
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
|
} else {
|
|
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
|
}
|
|
|
|
}
|
|
});
|
|
});
|
|
|
|
})
|
|
|
|
/*** 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]);
|
|
formData.append("form_type", "others");
|
|
|
|
$('.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) {
|
|
|
|
console.log('KYC OTHERS SUBMIT', res);
|
|
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
|
|
if(res.status == true){
|
|
$('#other_docs').empty();
|
|
$('#other_docs').append(res.data);
|
|
toastr.success('File uploaded successfully', 'Success');
|
|
}else{
|
|
toastr.warning('File uploaded failed', 'Warning');
|
|
}
|
|
|
|
$('#kyc_form').trigger('reset');
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
if (xhr.status === 400) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
let errorMessages = "";
|
|
let seenMessages = []; // Array to store unique messages
|
|
if (response.errors) {
|
|
$.each(response.errors, function (field, message) {
|
|
if (!seenMessages.includes(message)) {
|
|
errorMessages += `• ${message}<br>`;
|
|
seenMessages.push(message); // Mark this message as "seen"
|
|
}
|
|
});
|
|
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
|
} else {
|
|
toastr.warning(response.message || 'Validation failed', 'Warning');
|
|
}
|
|
} else if (xhr.status === 403) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
toastr.error(response.message, 'Security Policy');
|
|
} else if (xhr.status === 404) {
|
|
toastr.warning('Resource not found', 'Warning');
|
|
} else if (xhr.status === 500) {
|
|
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
|
} else {
|
|
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
});
|
|
|
|
$('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) {
|
|
|
|
console.log("KYC DOCUMENTS TABLE RSPONSE", 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>${index+1}</td>
|
|
<td>${item.file_name}</td>
|
|
<td id="form_${item.id}">
|
|
<form class="ajax">
|
|
<input class="file-input__input" type="file" name="file_name"
|
|
accept=".pdf,.jpg,.jpeg,.png">
|
|
<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:0px;">Submit</button>
|
|
</form>
|
|
</td>
|
|
<td id="name_${item.id}" style="display:none;"></td>
|
|
<td>
|
|
<a id="download_${item.id}" data-id="${item.id}" class="mdi mdi-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="mdi mdi-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>
|