nhance/app/Views/hr_file_upload.php

383 lines
15 KiB
PHP

<style>
.select2-container .select2-selection--multiple .select2-selection__choice {
padding: 5px 7px 5px 0 !important;
color: #000000;
}
</style>
<div class="tab-pane fade" id="HR-DOC-tab">
<div class="row">
<div class="col-xl-12">
<div id="accordion" class="mb-3">
<div class="card mb-1">
<h5 class="m-1">
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne" aria-expanded="true">
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
</a>
</h5>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
<!-- <div class="text-center"> -->
<form class="parsley-examples" id="hr_file_upload_search" >
<input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" id="csrf_token">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label>Client</label> <br />
<select name="client_id" class="form-control" id="client2" >
<option value="">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Branch</label> <br />
<select name="client_branch_id" class="form-control" id="client_branch_id2" >
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Policy</label> <br />
<select name="client_policy_id" class="form-control" id="policy2" >
<option value="">Select</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label>Event<span class="text-danger">*</span></label> <br />
<select name="file_action" class="form-control" id="event_type" required>
<option value="">Select</option>
<?php
if (isset($events) && count($events)) {
foreach ($events as $key => $action) {
echo "<option value='$key'" . ($key == "si_enhancement" ? " class='si-enhancement-option'" : "") . ">$action</option>";
}
}
?>
</select>
</div>
</div>
<div class="form-row" id="">
<div class="d-flex align-items-center justify-content-start" style="margin-top: 18px;">
<div class="form-group col-md-3">
<button type="submit" class="btn btn-primary waves-effect waves-light justify-content-end">Search</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row" id="hr_file_list">
<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="hr_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($HRfileList)) { foreach ($fileList as $key => $file) { ?>
<tr>
<td><b><?php echo ($key + 1) ?></b></td>
<td 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 $file['policy_no'] ?></td>
<td><?php echo $file['file_action'] ?></td>
<td><?php echo change_date_format($file['created_at'],'Y-m-d H:i:s', 'd M Y h:i a') . ' by <strong>' . $file['first_name'] . '</strong>' ?></td>
<td><?php echo $file['status']; ?> </td>
<td> </td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
</div>
</div><!-- end col -->
</div>
<!-- end row -->
</div>
<script>
var client_list = ''; // local variable for storing the client branch list
var branch_list = ''; // local variable for storing the client branch list
var policy_list = ''; // local variable for storing the client policy list
var branch_policy = '';
$(document).ready(function(){
//initialize the get client, branch, and policy
getClientAndBranchAndPolicy();
//client change to get the Client Branch
$('#client2').change(function(){
let client_id = $(this).val();
console.log('client_id', client_id);
if(branch_list != '') {
// console.log(branch_list[client_id]);
let data = branch_list[client_id];
appendBranch3(data);
}
})
//change the client branch than change the client policy
$('#client_branch_id2').change(function(){
let branch_id = $(this).val();
console.log("branch_id", branch_id);
if(policy_list != '' && branch_id != '') {
let data = policy_list[branch_id];
appendPolicy3(data);
}
});
})
$(document).ready(function() {
// Initialize select2
$("#client2").select2();
$("#policy2").select2();
$("#client_branch_id2").select2();
// Form submit event
$("#hr_file_upload_search").on("submit", function (e) {
e.preventDefault(); // stop normal form submit
let formData = $(this).serialize(); // serialize form with csrf
$.ajax({
url: "<?= base_url('hrFileList') ?>",
type: "POST",
data: formData,
dataType: "json",
beforeSend: function () {
// optional loader
$("#hr_tickets_table tbody").html(
"<tr><td colspan='9' class='text-center'>Loading...</td></tr>"
);
},
success: function (res) {
let tbody = "";
if (res.status === "success" && res.data.length > 0) {
$.each(res.data, function (index, file) {
tbody += `
<tr>
<td><b>${index + 1}</b></td>
<td id="${file.id}" class="reload truncate" title="${file.file_name}">${file.file_name}</td>
<td>${file.short_name ?? ""}</td>
<td>${file.branch_name ?? ""}</td>
<td>${file.policy_no ?? ""}</td>
<td>${file.file_action ?? ""}</td>
<td>${file.created_at} by <strong>${file.first_name ?? ""}</strong></td>
<td>${file.status}</td>
<td>
</td>
</tr>
`;
});
} else {
tbody = `<tr><td colspan="9" class="text-center">No records found</td></tr>`;
}
$("#hr_tickets_table tbody").html(tbody);
},
error: function (xhr, status, error) {
console.error("Error:", error);
$("#hr_tickets_table tbody").html(
`<tr><td colspan="9" class="text-center text-danger">Something went wrong</td></tr>`
);
},
});
});
});
// <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 href="${baseUrl}/hrFileUploadMasters?id=${file.id}" class="dropdown-item" style="color: #000;" aria-hidden="true" target="_blank" ><i class="mdi mdi-download mr-2 text-muted font-18 vertical-middle"></i>Download</a>
// </div>
// </div>
//featch client and branch and policy
function getClientAndBranchAndPolicy()
{
$.ajax({
url: '<?= base_url("/util/getClientAndBranchAndPolicy") ?>',
type: "GET",
dataType: 'json',
success: function(res) {
console.log('getClientAndBranchAndPolicy', res);
if(res.status == true){
client_list = res.client_data;
branch_list = res.branch_data;
policy_list = res.policy_data;
vehicle_list = res.vehicle_data;
unit_list = res.unit_data;
appendClients3(res.client_data);
}else{
console.log('No data found');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
}
// ------------ Append Functions are Below ----------------------------------------------------------------------------------
function appendClients3(data)
{
$('#client2').empty();
$('#client2').append($('<option>', {
value: '',
text: 'Select Client'
}));
$.each(data, function(index, item) {
let client_show_name = item.client_name;
if (item.client_type == 2) {
client_show_name = item.client_name + (item.dob ? ('- (' + item.dob + ' )' ) : '') + (item.pan ? ('- ' + item.pan ) : '');
// console.log(client_show_name);
}
var option = $('<option>', {
value: item.id,
text: client_show_name,
'data-cn': item.client_name,
'data-ct': item.client_type,
});
$('#client2').append(option);
});
}
function appendBranch3(data)
{
$('#client_branch_id2').empty();
$('#client_branch_id2').append($('<option>', {
value: '',
text: 'Select Branch'
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.branch_name
});
$('#client_branch_id2').append(option);
});
}
function appendPolicy3(data)
{
console.log('policy2', data);
console.log('policy2', $('#policy2'));
$('#policy2').empty();
$('#policy2').append($('<option>', {
value: '',
text: 'Select Policy',
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.policy_no,
text: item.policy_type + '-' + item.policy_no,
});
$('#policy2').append(option);
});
}
// ----------------------------------------------------------------------------------------------
$(document).ready(function() {
$('#hr_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>