bb_sign/app/Views/share_docs.php
2024-07-18 16:12:30 +05:30

845 lines
38 KiB
PHP
Raw Permalink 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.

<!-- ============================================================== -->
<!-- Start Page Content here -->
<!-- ============================================================== -->
<style>
.select2-container .select2-selection--single{
height: 36px;
border:1px solid #ced4da;
}
.select2-container--default .select2-selection--single .select2-selection__rendered{
line-height: 36px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow{
top:4px;
}
</style>
<div class="loader-mask modal-loader-mask" style="display:none;">
<div class="loader modal-loader" style="display:none;">
Please Wait <img src="<?= base_url() . "public" ?>/assets/images/simple_loader.gif" height="30" width="30" alt="Loading...">
</div>
</div>
<div class="content-page">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Share Documents</h4>
<div class="page-title-right">
<a href="javascript:void(0);" id="share_docs_add" class="btn btn-primary waves-effect waves-light">Share Docs </a>
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<table id="share_docs_table" class="table table-striped dt-responsive nowrap w-100 display">
<thead>
<tr >
<td style="border: none;">
<input class="form-control form-control-sm" type="text" id="searchClientName" placeholder="Search Client Name">
</td>
<td style="border: none;">
<input class="form-control form-control-sm" type="text" id="searchClientBranchName" placeholder="Search Client Branch Name">
</td>
<td style="border: none;">
<input class="form-control form-control-sm" type="text" id="searchServiceGroup" placeholder="Search Service Group">
</td>
<td style="border: none;">
<input class="form-control form-control-sm" type="text" id="searchServiceName" placeholder="Search Service Name">
</td>
<td style="border: none;">
<input class="form-control form-control-sm" type="text" id="searchDocumentName" placeholder="Search Document Name">
</td>
<td style="border: none;">
<input class="form-control form-control-sm" type="text" id="searchDocStatus" placeholder="Search Doc Status">
</td>
<td style="border: none;">
<input class="form-control form-control-sm" type="text" id="searchApproveDate" placeholder="Search Approve Date">
</td>
</tr>
<tr>
<th style="width:10px">Client</th>
<th>Service Group</th>
<th>Service</th>
<th>Document</th>
<th>Doc Status</th>
<th>Approval Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($doc_list as $key => $value) { ?>
<tr>
<td style="width:10px"> <?= $value['client_name']; ?> <?php if (!empty($value['client_branch_name'])): ?>- <?= $value['client_branch_name']; ?><?php endif; ?> </td>
<td> <?php echo $value['group_name']; ?></td>
<td> <?php echo $value['service_name']; ?></td>
<td> <?php echo $value['document_name']; ?></td>
<td>
<?php if ($value['is_active'] == 1){ ?>
<!-- <span style="color:green">Shared</span> -->
<?php if ($value['is_approved'] == 1): ?>
<span style="color:green">Approved</span>
<?php elseif ($value['is_approved'] == 0): ?>
<span style="color:orange">Pending Approval</span>
<?php elseif ($value['is_approved'] == 2): ?>
<span style="color:red">Rejected</span>
<?php endif; ?>
<?php }else if ($value['is_approved'] == 0){ ?>
<span style="color:red">Not Shared</span>
<?php } ?>
</td>
<td>
<?php if(count($value['doc_status']) > 0){ ?>
<span class="formatted-date" data-date="<?php echo $value['doc_status'][0]['doc_created_date']; ?>"></span>
<?php } ?>
</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">
<a class="dropdown-item" href="<?php echo base_url().'client_docs_preview?doc_id='.md5($value['id']); ?>" >
<i class='mdi mdi-eye-outline mr-1' style="margin-right: 16px !important;margin-left: 5px;"></i>Preview
</a>
<?php if ($value['is_approved'] != 1){ ?>
<a class="dropdown-item" href="<?= base_url()."shared_document_edit?doc_id=".md5($value['id']); ?>">
<i class="mdi mdi-pencil-outline mr-2 text-muted font-18 vertical-middle"></i> Edit
</a>
<?php } ?>
<a id="doc_history_button" data-id="<?php echo $value['id']; ?>" class="dropdown-item" data-toggle="modal" data-target="#bike_make_login-modal" data-title="History">
<i class="mdi mdi-history" style="margin-right: 16px !important;"></i>History
</a>
<?php if($value['is_active'] == 1 && $value['is_approved'] == 0){ ?>
<a class="dropdown-item" data-id="<?php echo $value['id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Revert" onclick="statusChange(this)"><i class="mdi mdi-file-undo" style="margin-right: 16px !important;margin-left: 5px;"></i>Revert</a>
<?php } else if($value['is_active'] == 0 ) { ?>
<a class="dropdown-item" data-id="<?php echo $value['id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Share" onclick="statusChange(this)"><i class="mdi mdi-share-all-outline" style="margin-right: 16px !important;margin-left: 5px;"></i>Share</a>
<?php } ?>
<?php if($value['is_active'] == 1 && $value['is_approved'] == 0){ ?>
<a class="dropdown-item" data-id="<?php echo $value['id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Remember" onclick="rememberNotification(this)">
<i class="mdi mdi-email-send" style="margin-right: 16px !important; margin-left: 5px;"></i>Reminder
</a>
<?php } ?>
<?php if($value['is_active'] == 1 && $value['is_approved'] == 0){ ?>
<a class="dropdown-item" data-id="<?php echo $value['id']; ?>" data-isactive="<?php echo $value['is_active']; ?>" title="Create Link" onclick="createSharedLink(this)">
<i class="mdi mdi-link-variant-plus" style="margin-right: 16px !important; margin-left: 5px;"></i>Create Link
</a>
<?php } ?>
<?php if($value['is_active'] == 0 ) { ?>
<a class="dropdown-item" data-id="<?php echo $value['id']; ?>" title="Delete" onclick="DeleteDoc(this)">
<i class="mdi mdi-delete" style="margin-right: 16px !important; margin-left: 5px;"></i>Delete
</a>
<?php } ?>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col-->
</div>
</div> <!-- container -->
</div> <!-- content -->
<div class="modal fade" id="bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Create Docs </h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<form id="share-docs" enctype="multipart/form-data">
<div class="modal-body p-4">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="field-2" class="control-label">Select Client</label>
<select class="select2-dropdown form-control" name="client_branch_id" id="client_branch_id" required>
<option value="">Select Client</option>
<?php foreach ($clientdata as $key => $Value) { ?>
<option value="<?php echo $Value['client_branch_id']; ?>" ><?php echo $Value['name']; if(!empty($Value['client_branch_name'])){ ?> - <?php echo $Value['client_branch_name']; } ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="field-2" class="control-label">Service Group</label>
<select class="select2-dropdown form-control" name="service_group_id" id="service_group_id" required>
<option value="">Select Service</option>
<?php foreach ($serviceGroupData as $key => $Value) { ?>
<option value="<?php echo $Value['service_group_id']; ?>" ><?php echo $Value['group_name']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="field-1" class="control-label">Service</label>
<select class="select2-dropdown form-control" name="service_id" id="service_id" required>
<option value="">Select Service</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="field-1" class="control-label">Template</label>
<select class="select2-dropdown form-control" name="template_id" id="template_id" required>
<option value="">Select Template</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="field-1" class="control-label">Document Name</label>
<input type="text" class=" form-control" name="document_name" id="document_name" required>
</div>
</div>
<input type="hidden" name="is_active" value="0">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect" style="background-color:grey ; color:white;" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-info waves-effect waves-light">Create</button>
</div>
</form>
</div>
</div>
</div><!-- /.modal -->
<div id="client-doc-history-modal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 id="branch_action_type">Doc History</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form id="model_form_data" class="px-4">
<input type="text" id="business_id" value="" hidden>
<input type="text" id="client_id" value="" hidden>
<input type="text" id="branch_id" hidden>
<div class="row">
<div class="col-md-12">
<table class="table table-striped dt-responsive nowrap w-100">
<thead>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<div class="form-group text-right">
<!-- <button class="btn btn-info waves-effect waves-light" type="submit" onclick="submitBranch(this)">Submit</button> -->
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div id="linkModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<p id="generatedLink" style="display:none;"></p>
Copy the document link by clicking the below button
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="copyLinkButton">Copy Link</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- ============================================================== -->
<!-- End Page content -->
<!-- ============================================================== -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
function formatDate(dateString) {
var options = {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: true
};
var date = new Date(dateString);
return date.toLocaleString('en-US', options).replace(',', '').toUpperCase();
}
document.addEventListener('DOMContentLoaded', function() {
// Select all elements with the class 'formatted-date'
var dateElements = document.querySelectorAll('.formatted-date');
// Iterate over the elements and format the date
dateElements.forEach(function(element) {
var dateString = element.getAttribute('data-date');
var formattedDate = formatDate(dateString);
element.textContent = formattedDate;
});
});
</script>
<script>
$('#share_docs_add').click(function () {
var business_id = <?php echo $_SESSION['logged_in_staff_business_id'] ?>;
if(business_id == 0){
toastr.warning('Select a Business', 'Warning');
}else{
$('#bs-example-modal-lg').modal('show');
}
})
function fetchDataAndRedirect(selectedOption) {
// var selectedOption = $('#add_30days_old_dispatched_data').val();
console.log("-------------------");
console.log(selectedOption);
if(selectedOption == 'all_years'){
selectedOption = false;
}else{
selectedOption = true;
}
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: '<?= base_url("set_include_archived_session/") ?>' + selectedOption,
type: 'GET',
data: { include_archived: selectedOption },
success: function(response) {
console.log(response);
// Redirect based on the selected option
setTimeout(() => {
$('.loader').fadeOut();
$('.loader-mask').fadeOut('slow');
}, 2000);
if (selectedOption == false) {
console.log("Redirecting to shared_doc_non_financial_year_to");
window.location.href = '<?= base_url("shared_doc_non_financial_year_to") ?>';
} else {
console.log("Redirecting to shared_docs_list");
window.location.href = '<?= base_url("shared_docs_list") ?>';
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
}
});
}
$('input[type="text"]').on('input', function() {
var searchTextSKU = $('#searchClientName').val().toLowerCase();
var searchTextProductName = $('#searchClientBranchName').val().toLowerCase();
var searchTextManufacturerName = $('#searchServiceGroup').val().toLowerCase();
var searchTextCategory = $('#searchServiceName').val().toLowerCase();
var searchTextUnitPrice = $('#searchDocumentName').val().toLowerCase();
var searchTextRackNo = $('#searchDocStatus').val().toLowerCase();
var searchApproveDate = $('#searchApproveDate').val().toLowerCase();
$('#share_docs_table tbody tr').each(function() {
var cellTextSKU = $(this).find('td:nth-child(1)').text().toLowerCase();
var cellTextProductName = $(this).find('td:nth-child(2)').text().toLowerCase();
var cellTextManufacturerName = $(this).find('td:nth-child(3)').text().toLowerCase();
var cellTextCategory = $(this).find('td:nth-child(4)').text().toLowerCase();
var cellTextUnitPrice = $(this).find('td:nth-child(5)').text().toLowerCase();
var cellTextRackNo = $(this).find('td:nth-child(6)').text().toLowerCase();
var cellTextApproveDate = $(this).find('td:nth-child(7)').text().toLowerCase();
// Show the row if all search fields match
if (cellTextSKU.includes(searchTextSKU) &&
cellTextProductName.includes(searchTextProductName) &&
cellTextManufacturerName.includes(searchTextManufacturerName) &&
cellTextCategory.includes(searchTextCategory) &&
cellTextUnitPrice.includes(searchTextUnitPrice) &&
cellTextRackNo.includes(searchTextRackNo) &&
cellTextApproveDate.includes(searchApproveDate)) {
$(this).show();
} else { $(this).hide();}
});
});
$(document).ready(function() {
datatable_bikeModel = $('#share_docs_table').DataTable({
"order": [[0, 'asc']], // Set initial sorting to descending on the first column
"dom": 'Bfrtip', // Show export buttons
"buttons": [{extend: 'pdfHtml5',title: 'Shared_Documents', text: 'PDF',},
{extend: 'print',title: 'Shared_Documents',text: 'Print',},
{extend: 'copy',text: 'Copy', titleAttr: 'Copy',},
{extend: 'csv',text: 'CSV', title: 'Shared_Documents', }],
"language": {
"search": "Search: " // Customize search label
},
});
$('.select2-dropdown').select2();
$("#service_group_id").on("change", function()
{
var value = $(this).val();
$.ajax({
url: '<?= base_url("get_service_data") ?>?service_group_id=' + value,
type: 'GET',
dataType: 'json', // Expect JSON response
success: function(response) {
if (response.count > 0) {
$('#service_id option:not(:first)').remove();
$.each(response.data, function(index, item) {
$('#service_id').append($('<option>', {
value: item.service_id,
text: item.service_name
}));
});
} else {
toastr.warning('Service not found.', 'Warning');
}
},
error: function(xhr, status, error) {
// Handle error
console.error(xhr.responseText);
toastr.error('Failed to fetch data.', 'Error');
}
});
});
$("#service_id").on("change", function()
{
var value = $(this).val();
$.ajax({
url: '<?= base_url("get_templates") ?>?service_id=' + value,
type: 'GET',
dataType: 'json', // Expect JSON response
success: function(response) {
if (response.count > 0) {
$('#template_id option:not(:first)').remove();
$.each(response.data, function(index, item) {
$('#template_id').append($('<option>', {
value: item.template_id,
text: item.template_name
}));
});
} else {
toastr.warning('Templates not found.', 'Warning');
}
},
error: function(xhr, status, error) {
// Handle error
console.error(xhr.responseText);
toastr.error('Failed to fetch data.', 'Error');
}
});
});
var role= '<?php echo isset($_SESSION['logged_in_staff_role']) ? $_SESSION['logged_in_staff_role'] : ''; ?>';
// Initialize includeArchived based on PHP variable
var includeArchived = <?= isset($includeArchived) && $includeArchived ? 'true' : 'false' ?>;
// Create select element with options
var selectElement = $('<select class="form-control" id="financial_year_data_or_not" style="margin-left: 5px;">' +
'<option value="current_year">Current Financial Year</option>' +
'<option value="all_years">All Years</option>' +
'</select>');
// Set initial selected option based on includeArchived
if (includeArchived) {
selectElement.val('all_years');
} else {
selectElement.val('current_year');
}
// Create label element wrapping the select element
var newElement = $('<label class="dt-buttons btn-group flex-wrap" style="border: 1px solid white; display: flex;"></label>').append(selectElement);
// Check role and append newElement accordingly
if (role == 'Admin') {
$('#share_docs_table_wrapper').children().first().after(newElement);
var includeArchived = <?php echo isset($_SESSION['include_archived']) ? json_encode($_SESSION['include_archived']) : 'false'; ?>;
if (includeArchived) {
if(includeArchived == 'true'){
$('#financial_year_data_or_not').val('current_year');
}else{
$('#financial_year_data_or_not').val('all_years');
}
}else{
$('#financial_year_data_or_not').val('current_year');
}
}
// Handle change event of select element
selectElement.on('change', function() {
var selectedValue = $(this).val();
// Call fetchDataAndRedirect() function with selected value
fetchDataAndRedirect(selectedValue);
});
});
$('#share-docs').submit(function(e) {
e.preventDefault(); // Prevent the form from submitting normally
if(!$('#client_branch_id').val()){
toastr.warning('Select Client');
return;
}
// Create a FormData object
var formData = new FormData(this);
// console.log(formData);
// Make an AJAX POST request
$.ajax({
url: '<?= base_url()."create_docs"; ?>',
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function(response) {
console.log(response);
if(response){
toastr.success('Document created.', 'Success');
window.location.reload();
}else{
toastr.warning('Creation Failed.', 'Warning');
}
},
error: function(xhr, status, error) {
// Handle errors here
console.error(xhr.responseText);
}
});
});
function statusChange(params) {
console.log(params);
var status = params.getAttribute('data-isactive');
var doc_id = params.getAttribute('data-id');
if(status == 1){
var is_active= 0;
}else{
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var is_active= 1;
}
var formData = {
doc_id: doc_id,
is_active: is_active
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."change_doc_status"?>',
data: formData,
dataType: 'json',
success: function(response) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').fadeOut('slow');
}, 1000);
console.log(response);
if (response.data) {
if (response.hasOwnProperty('mail_status')) {
if (response.mail_status == 'success')
{
toastr.success(response.data, 'Success');
toastr.success('Mail Sent To '+response.mail, 'Success');
} else {
toastr.success(response.data, 'Success');
toastr.warning('Failed to sent mail to '+response.mail, 'Warning');
}
} else {
toastr.success(response.data, 'Success');
}
setTimeout(function() { window.location.reload(); }, 2000);
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
function rememberNotification(params) {
var doc_id = params.getAttribute('data-id');
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var formData = {
doc_id: doc_id,
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."rememeber_notification"?>',
data: formData,
dataType: 'json',
success: function(response) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').fadeOut('slow');
}, 1000);
if (response.mail_status == 'success')
{
toastr.success('Mail Send To '+response.mail, 'Success');
} else {
toastr.warning('Failed to send mail to '+response.mail, 'Warning');
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
function createSharedLink(params){
var doc_id = params.getAttribute('data-id');
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var formData = {
doc_id: doc_id,
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."createSharedLink"?>',
data: formData,
dataType: 'json',
success: function(response) {
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').fadeOut('slow');
}, 1000);
if (response.status == 'success')
{
$('#generatedLink').text(response.link);
$('#linkModal').modal('show');
} else {
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
$(document).on('click', '#copyLinkButton', function() {
const textToCopy = $('#generatedLink').text();
// Use the Clipboard API to copy the text
navigator.clipboard.writeText(textToCopy).then(() => {
// Success callback
console.log('Text copied to clipboard');
}).catch(err => {
// Error callback
console.error('Failed to copy text: ', err);
});
});
function DeleteDoc(params) {
var doc_id = params.getAttribute('data-id');
var formData = {
doc_id: doc_id,
};
$.ajax({
type: 'POST',
url: '<?php echo base_url()."delete_doc"?>',
data: formData,
dataType: 'json',
success: function(response) {
console.log(response);
if (response.data) {
window.location.reload();
}
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
}
</script>
<script>
$(document).on('click', '#doc_history_button', function () {
var url = '<?= base_url("client_docs_histroy/"); ?>' + $(this).data('id');
function formatDate(dateString) {
var options = { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hour12: true };
var date = new Date(dateString);
return date.toLocaleString('en-US', options).replace(',', '').toUpperCase();
}
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
success: function(response) {
console.log(response);
// Clear the existing table body
var tbody = $('#client-doc-history-modal .modal-body table tbody');
tbody.empty();
// Iterate over the client_doc_history array and populate the table
response.client_doc_history.forEach(function(item, index) {
var creatorName = item.creator_details ? item.creator_details.name : 'N/A';
var creatorType = item.creator_type ? ucfirst(item.creator_type) : 'N/A';
if(item.status == "Approved"){
var reason_or_ip = ' - IP(';
reason_or_ip_end = ')';
}else if(item.status == "Rejected"){
reason_or_ip = ' - Reason(';
reason_or_ip_end = ')';
}else if(item.status == "Mail Success" || item.status == "Mail Failed"){
reason_or_ip = ' - Email-Id(';
reason_or_ip_end = ')';
}else{
reason_or_ip = '';
reason_or_ip_end = '';
}
var formattedDate = formatDate(item.created_at);
var row = '<tr>' +
'<td>Document ' + item.status + ' by ' + creatorName +' at, '+ formattedDate + reason_or_ip + item.note +reason_or_ip_end+'</td>' +
'</tr>';
tbody.append(row);
});
// Show the modal
$('#client-doc-history-modal').modal('show');
},
error: function(xhr, status, error) {
// Handle error response here
console.error(xhr.responseText);
}
});
});
// Helper function to capitalize the first letter
function ucfirst(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
</script>