bb_sign/app/Views/share_docs.php
2024-06-13 09:39:08 +05:30

454 lines
19 KiB
PHP
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.

<!-- ============================================================== -->
<!-- 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="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);" data-toggle="modal" data-target="#bs-example-modal-lg" 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="datatable-buttons" class="table table-striped dt-responsive nowrap w-100 display">
<thead>
<tr>
<th>Client Name</th>
<th>Client Branch Name</th>
<th>Service Group</th>
<th>Service Name</th>
<th>Document Name</th>
<th>Doc Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($doc_list as $key => $value) { ?>
<tr>
<td> <?php echo $value['client_name']; ?></td>
<td> <?php echo $value['client_branch_name']; ?></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>
<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='.$value['id']; ?>" > <i class='mdi mdi-eye-outline mr-1' style="margin-right: 16px !important;margin-left: 5px;"></i>Preview</a>
<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="Share"><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 } ?>
</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['client_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" 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 -->
<!-- ============================================================== -->
<!-- End Page content -->
<!-- ============================================================== -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.1.0/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('.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');
}
});
});
});
$('#share-docs').submit(function(e) {
e.preventDefault(); // Prevent the form from submitting normally
// 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) {
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{
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) {
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{
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>