nhance/app/Views/import_export.php

673 lines
24 KiB
PHP
Executable File

<?php helper('datatable_view'); ?>
<style>
.table th,
.table td {
padding: 8px;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
table.dataTable thead th {
padding: 4px 4px !important;
}
/* .dataTables_filter: global listing layout (nhance-datatables-uniform.css) */
.filter-sidebar {
height: 100%;
width: 0;
position: fixed;
z-index: 1001;
top: 0;
right: 0;
background-color: #f8f9fa;
overflow-x: hidden;
transition: 0.5s;
box-shadow: -2px 0 5px rgba(0,0,0,0.1);
display: flex;
flex-direction: column;
}
.filter-sidebar-header {
padding: 15px 20px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #dee2e6;
flex-shrink: 0;
}
.filter-sidebar-header h4 {
font-size: 14px;
line-height: 1.2;
}
/* Reduce filter header height (this view only) */
#filter-sidebar .filter-sidebar-header {
padding: 10px 16px;
}
#filter-sidebar .filter-sidebar-header .closebtn {
font-size: 22px;
line-height: 1;
}
.filter-sidebar-header .closebtn {
font-size: 28px;
text-decoration: none;
color: #6c757d;
}
.filter-sidebar .closebtn:hover {
color: #000;
}
.filter-sidebar-content {
padding: 20px;
flex-grow: 1;
overflow-y: auto;
}
.filter-sidebar-footer {
padding: 15px 20px;
display: flex;
justify-content: flex-end;
border-top: 1px solid #dee2e6;
flex-shrink: 0;
gap: 10px;
}
/* Slightly smaller filter buttons (this view only) */
#filter-sidebar .filter-sidebar-footer {
padding: 12px 16px;
gap: 8px;
}
#filter-sidebar .filter-sidebar-footer .btn {
padding: 4px 10px;
font-size: 12px;
line-height: 1.2;
}
/* Also shrink DataTables toolbar buttons on this page */
.dataTables_wrapper .dt-buttons .btn {
padding: 4px 10px;
font-size: 12px;
line-height: 1.2;
}
.dataTables_wrapper .dt-buttons .btn .btn-custom {
font-size: 12px;
}
.hide-clear-filter{
display: none;
}
</style>
<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 = '';
window.uploadListFilters = window.uploadListFilters || {
client_id: '',
client_branch_id: '',
policy_id: '',
event_type: '',
insurer_or_tpa: '',
action_type: '',
start_date: '',
end_date: '',
use_default_date: '1'
};
function reloadActiveUploadListTable() {
var tabType = String($('#tab_type').val() || '1');
if ((tabType === '2' || tabType === 'kyc_tab') && window.batchListTableInstance) {
window.batchListTableInstance.ajax.reload();
} else if ((tabType === '3' || tabType === 'hr_tab') && window.hrFileTableInstance) {
window.hrFileTableInstance.ajax.reload();
} else if (window.fileListTableInstance) {
window.fileListTableInstance.ajax.reload();
} else if (window.batchListTableInstance) {
window.batchListTableInstance.ajax.reload();
}
}
$(document).ready(function() {
getClientAndBranchAndPolicy();
})
//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;
appendClients(res.client_data);
appendClients2(res.client_data);
appendClients3(res.client_data);
} else {
console.log('No data found');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
}
</script>
<div id="filter-sidebar" class="filter-sidebar">
<div class="filter-sidebar-header">
<h4 class="m-0">Filter</h4>
<a href="javascript:void(0)" class="closebtn" onclick="closeFilterNav()">&times;</a>
</div>
<div class="filter-sidebar-content">
<div class="form-group">
<div class="form-group">
<div class="form-row">
<input type="hidden" id="tab_type" value="1">
<div class="form-group col-md-12">
<label>Client<span class="text-danger"></span></label> <br/>
<select name="client_id" class="form-control" id="client_id_for_filter">
<option value="">Select</option>
</select>
</div>
<div class="form-group col-md-12">
<label>Branch</label> <br />
<select name="client_branch_id" class="form-control" id="client_branch_id_for_filter">
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-12">
<label>Policy<span class="text-danger" id="policy_danger"></span></label> <br />
<select name="client_policy_id" class="form-control" id="policy_id_for_filter">
<option value="">Select</option>
</select>
</div>
<div class="form-group col-md-12">
<label>Event<span class="text-danger"></span></label> <br />
<select name="event_type" class="form-control" id="event_type_for_filter">
<option value="">Select</option>
<?php
if (isset($events) && count($events)) {
foreach ($events as $key => $action) {
echo "<option value='$key'>$action</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-12" id="date_div">
<label>Date<span class="text-danger"></span></label>
<div id="reportrange" class="form-control" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
<i class="mdi mdi-calendar-blank"></i>&nbsp;
<span></span> <i class="mdi mdi-menu-down"></i>
</div>
<input type="hidden" id="startDate">
<input type="hidden" id="endDate">
</div>
<div class="form-group col-md-12 hide_filter_input">
<label>Insurer/TPA Data<span class="text-danger"></span></label> <br />
<select name="insurer_or_tpa" class="form-control" id="insurer_or_tpa_for_filter">
<option value="">Select</option>
<?php
if (isset($insurer_or_tpa) && count($insurer_or_tpa)) {
foreach ($insurer_or_tpa as $key => $action) {
echo "<option value=" . $key . ">" . $action . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-12 hide_filter_input">
<label>Action<span class="text-danger"></span></label> <br />
<select name="action_type" class="form-control" id="action_type_for_filter">
<option value="">Select</option>
<?php
if (isset($import_or_export) && count($import_or_export)) {
foreach ($import_or_export as $key => $action) {
echo "<option value=" . $key . ">" . $action . "</option>";
}
}
?>
</select>
</div>
</div>
</div>
</div>
</div>
<div class="filter-sidebar-footer">
<a href="<?= base_url("/employee/upload"); ?>" class="btn btn-secondary" id="clear-filters">Clear</a>
<a href="<?= base_url("/employee/upload"); ?>" class="btn btn-primary" id="get_base_url" onclick="fetchFilterData(event); closeFilterNav();">Submit</a>
</div>
</div>
<div class="row" id="client_add">
<div class="col-12">
<div class="card-body">
<div class="tab-wrapper position-relative">
<ul class="nav nav-pills navtab-bg " id="myTab">
<li class="nav-item d-flex justify-content-center align-items-center">
<button class="scroll-btn left-btn" type="button">&#9664;</button>
</li>
<li class="nav-item d-flex justify-content-center align-items-center">
<a href="#general-q-tab" data-toggle="tab" aria-expanded="false" class="nav-link px-3 py-2 active-tab active" id="general_tab">
<span class="mr-1"><i class="mdi mdi-contacts"></i></span>
<span class="d-none d-sm-inline-block ">Data From Client</span>
</a>
</li>
<li class="nav-item d-flex justify-content-center align-items-center">
<a href="#KYC-DOC-tab" data-toggle="tab" aria-expanded="true" class="nav-link px-3 py-2" id="kyc_tab">
<span class="mr-1"><i class="mdi mdi-file"></i></span>
<span class="d-none d-sm-inline-block ">Insurer or TPA Data</span>
</a>
</li>
<li class="nav-item d-flex justify-content-center align-items-center">
<a href="#HR-DOC-tab" data-toggle="tab" aria-expanded="true" class="nav-link px-3 py-2" id="hr_tab">
<span class="mr-1"><i class="mdi mdi-file"></i></span>
<span class="d-none d-sm-inline-block ">HR Uploaded Files</span>
</a>
</li>
<li class="nav-item d-flex justify-content-center align-items-center">
<!-- Right Arrow -->
<button class="scroll-btn right-btn" type="button">&#9654;</button>
</li>
</ul>
</div>
<div class="tab-content">
<?php include('employee_upload.php'); ?>
<?php include('insurer_or_tpa_data.php'); ?>
<?php include('hr_file_upload.php'); ?>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
const urlParams = new URLSearchParams(window.location.search);
let tab = urlParams.get('tab_type');
console.log('Detected Tab Parameter:', tab);
// 1. Show/Hide Clear Filter Button
if (tab && tab !== "") {
$('.hide-clear-filter').show();
} else {
$('.hide-clear-filter').hide();
}
// 2. The Tab Switcher Logic
function activateTab(tabId) {
var targetLink = $('#' + tabId);
if (targetLink.length > 0) {
// Try Method A: Bootstrap 4/5 Standard
if (typeof bootstrap !== 'undefined' && bootstrap.Tab) {
var tabTrigger = new bootstrap.Tab(targetLink[0]);
tabTrigger.show();
} else if ($.fn.tab) {
targetLink.tab('show');
}
// Try Method B: Manual Fallback (Force Display)
$('.nav-link').removeClass('active active-tab').attr('aria-expanded', 'false');
targetLink.addClass('active active-tab').attr('aria-expanded', 'true');
var targetPane = targetLink.attr('href');
$('.tab-pane').removeClass('show active');
$(targetPane).addClass('show active');
console.log('Manually activated tab: ' + tabId);
}
}
// Execute with a slight delay to ensure includes are loaded
setTimeout(function() {
if (tab === "2" || tab === "kyc_tab") {
activateTab('kyc_tab');
} else if (tab === "3" || tab === "hr_tab") {
activateTab('hr_tab');
} else {
activateTab('general_tab');
}
}, 200);
// 3. Keep the Sidebar input updated for future filters
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
$('#tab_type').val($(e.target).attr('id'));
});
});
$(document).ready(function(){
$('#client_id_for_filter').select2();
$('#client_branch_id_for_filter').select2();
$('#policy_id_for_filter').select2();
$('#client_id_for_filter').on('change', function() {
let client_id = $(this).val();
console.log('client_id_for_filter', client_id);
if(branch_list != '') {
// console.log(branch_list[client_id]);
let data = branch_list[client_id];
appendBranchForFilter(data);
}
});
$('#client_branch_id_for_filter').on('change', function() {
let branch_id = $(this).val();
console.log("client_branch_id_for_filter", branch_id);
if(policy_list != '' && branch_id != '') {
let data = policy_list[branch_id];
appendPoliciesForFilter(data);
}
});
})
/* Modified by Gemini Code Assist */
function openPolicyFilterNav(input) {
if(input == 2){
$('.hide_filter_input').show();
}else{
$('.hide_filter_input').hide();
}
document.getElementById("filter-sidebar").style.width = "350px";
}
/* Modified by Gemini Code Assist */
function closeFilterNav() {
document.getElementById("filter-sidebar").style.width = "0";
}
$(document).ready(function() {
if (window.location.hash === '#KYC-DOC-tab') {
console.log('url hash :', window.location.hash)
$('#kyc_tab').click();
}
if (window.location.hash === '#HR-DOC-tab') {
console.log('url hash :', window.location.hash)
$('#hr_tab').click();
}
})
function formatTextToCamelCase(str) {
return str
.replace(/_/g, ' ') // replace underscores with spaces
.toLowerCase() // convert everything to lowercase
.replace(/\b\w/g, char => char.toUpperCase()); // capitalize each word
}
function appendBranchForFilter(data) {
$('#client_branch_id_for_filter').empty();
$('#client_branch_id_for_filter').append($('<option>', {
value: '0',
text: 'Select'
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.branch_name
});
if (client_branch_id_param == item.id) {
option.attr('selected', true);
}
$('#client_branch_id_for_filter').append(option);
});
}
function appendPoliciesForFilter(data) {
$('#policy_id_for_filter').empty();
$('#policy_id_for_filter').append($('<option>', {
value: '0',
text: 'Select',
selected: true
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text:`${item.policy_type ?? ''} - ${item.policy_no ?? ''}`
});
if (client_policy_param == item.id) {
option.attr('selected', true);
}
$('#policy_id_for_filter').append(option);
});
}
$(document).ready(function() {
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var activeTabId = $(e.target).attr('id'); // Gets the ID of the clicked tab
var activeTabText = $(e.target).text().trim(); // Gets the text inside the tab
console.log("Tab Changed!");
console.log("Active Tab ID: " + activeTabId);
console.log("Active Tab Name: " + activeTabText);
if(activeTabId == 'kyc_tab'){
$('#tab_type').val(2)
$('.hide_filter_input').show();
}else if(activeTabId == 'hr_tab'){
$('#tab_type').val(3)
$('.hide_filter_input').hide();
}else{
$('#tab_type').val(1)
$('.hide_filter_input').hide();
}
});
});
function fetchFilterData(event)
{
event.preventDefault(); // Prevent default action (navigation)
// 1. Get the current active tab type (from your hidden input)
var tab_type = $('#tab_type').val();
// 2. Get data using the CORRECT IDs from your HTML sidebar
var client_id = $('#client_id_for_filter').val();
var branch_id = $('#client_branch_id_for_filter').val();
var policy_id = $('#policy_id_for_filter').val();
var event_type = $('#event_type_for_filter').val();
var insurer_or_tpa = $('#insurer_or_tpa_for_filter').val();
var action_type = $('#action_type_for_filter').val() || $('#action_type').val();
var start_date = $('#startDate').val() || '';
var end_date = $('#endDate').val() || '';
window.uploadListFilters = window.uploadListFilters || {};
window.uploadListFilters.client_id = client_id || '';
window.uploadListFilters.client_branch_id = (branch_id && branch_id !== '0') ? branch_id : '';
window.uploadListFilters.policy_id = (policy_id && policy_id !== '0') ? policy_id : '';
window.uploadListFilters.event_type = event_type || '';
window.uploadListFilters.insurer_or_tpa = insurer_or_tpa || '';
window.uploadListFilters.action_type = action_type || '';
window.uploadListFilters.start_date = start_date;
window.uploadListFilters.end_date = end_date;
// Legacy: when filters are applied without dates, do not force 90-day default.
window.uploadListFilters.use_default_date = (start_date && end_date) ? '1' : '0';
var queryParams = {
tab_type: tab_type,
client_id: client_id,
branch_id: branch_id,
client_branch_id: branch_id,
policy_id: policy_id,
event_type: event_type,
insurer_or_tpa: insurer_or_tpa,
action_type: action_type,
start_date: start_date,
end_date: end_date
};
const queryString = new URLSearchParams(queryParams).toString();
const baseUrl = $('#get_base_url').attr('href');
if (window.history && window.history.replaceState) {
window.history.replaceState({}, '', baseUrl + '?' + queryString);
}
$('.hide-clear-filter').show();
reloadActiveUploadListTable();
}
function clearFilterData(){
window.uploadListFilters = {
client_id: '',
client_branch_id: '',
policy_id: '',
event_type: '',
insurer_or_tpa: '',
action_type: '',
start_date: '',
end_date: '',
use_default_date: '1'
};
window.hrFileListFilters = {
client_id: '',
client_branch_id: '',
policy_id: '',
file_action: '',
event_type: '',
use_default_date: '1'
};
$('#client_id_for_filter').val('').trigger('change');
$('#client_branch_id_for_filter').val('0').trigger('change');
$('#policy_id_for_filter').val('').trigger('change');
$('#event_type_for_filter').val('');
$('#insurer_or_tpa_for_filter').val('');
$('#action_type_for_filter').val('');
$('#startDate').val('');
$('#endDate').val('');
$('#reportrange span').html('Select Date Range');
const url = $('#get_base_url').attr('href');
if (window.history && window.history.replaceState) {
window.history.replaceState({}, '', url);
}
$('.hide-clear-filter').hide();
reloadActiveUploadListTable();
if (window.fileListTableInstance) {
window.fileListTableInstance.ajax.reload();
}
if (window.batchListTableInstance) {
window.batchListTableInstance.ajax.reload();
}
if (window.hrFileTableInstance) {
window.hrFileTableInstance.ajax.reload();
}
}
$(function() {
// 1. Check if dates exist in URL, otherwise leave them null/empty
const urlParams = new URLSearchParams(window.location.search);
const startDateParam = urlParams.get('start_date');
const endDateParam = urlParams.get('end_date');
var start = startDateParam ? moment(startDateParam, 'DD/MM/YYYY') : null;
var end = endDateParam ? moment(endDateParam, 'DD/MM/YYYY') : null;
function cb(start, end) {
if (start && end) {
$('#reportrange span').html(start.format('D/MM/YYYY') + ' - ' + end.format('D/MM/YYYY'));
$('#startDate').val(start.format('DD/MM/YYYY'));
$('#endDate').val(end.format('DD/MM/YYYY'));
} else {
// Display a placeholder if no date is selected
$('#reportrange span').html('Select Date Range');
$('#startDate').val('');
$('#endDate').val('');
}
}
$('#reportrange').daterangepicker({
autoUpdateInput: false, // CRITICAL: Prevents the picker from forcing a value
startDate: start || moment().subtract(29, 'days'),
endDate: end || moment(),
locale: {
cancelLabel: 'Clear',
format: 'DD/MM/YYYY'
},
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
});
// Handle the "Apply" button click
$('#reportrange').on('apply.daterangepicker', function(ev, picker) {
cb(picker.startDate, picker.endDate);
});
// Handle the "Cancel/Clear" button click
$('#reportrange').on('cancel.daterangepicker', function(ev, picker) {
cb(null, null);
});
// Run once on load
cb(start, end);
$('#clear-filters').on('click', function() {
// ... (your existing dropdown resets) ...
cb(null, null);
});
});
</script>