nhance/app/Views/batch_list.php

1125 lines
49 KiB
PHP
Executable File
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.

<?php
helper('datatable_view');
$batch_header_labels = [
'S.No', 'Batch Code', 'File Name', 'Client', 'Client Branch', 'Client Policy',
'Event Type', 'Insurer/ TPA', 'Action', 'Count', '(₹)Amount', 'User/Time', 'Status', 'Action',
];
$batch_col_count = count($batch_header_labels);
$batch_col_max_len = array_fill(0, $batch_col_count, 0);
for ($i = 0; $i < $batch_col_count; $i++) {
$batch_col_max_len[$i] = mb_strlen($batch_header_labels[$i]);
}
$insurer_or_tpa = $insurer_or_tpa ?? [];
$import_or_export = $import_or_export ?? [];
if (!empty($batch_list) && is_array($batch_list)) {
foreach ($batch_list as $key => $file) {
$batch_col_max_len[0] = max($batch_col_max_len[0], mb_strlen((string) ($key + 1)));
$batch_col_max_len[1] = max($batch_col_max_len[1], mb_strlen((string) ($file['batch_code'] ?? '')));
$batch_col_max_len[2] = max($batch_col_max_len[2], mb_strlen((string) ($file['file_name'] ?? '')));
$batch_col_max_len[3] = max($batch_col_max_len[3], mb_strlen((string) ($file['client_short_name'] ?? '')));
$batch_col_max_len[4] = max($batch_col_max_len[4], mb_strlen((string) ($file['branch_name'] ?? '')));
$policy_display_len = trim(
(isset($file['policy_type']) ? $file['policy_type'] : '')
. ' - '
. (isset($file['policy_no']) ? $file['policy_no'] : '')
);
$batch_col_max_len[5] = max($batch_col_max_len[5], mb_strlen($policy_display_len));
$batch_col_max_len[6] = max($batch_col_max_len[6], mb_strlen((string) ($file['event_type'] ?? '')));
$insLabel = $insurer_or_tpa[$file['insurer_or_tpa'] ?? ''] ?? '';
$batch_col_max_len[7] = max($batch_col_max_len[7], mb_strlen((string) $insLabel));
$actKey = $file['actions'] ?? '';
$actLabel = $import_or_export[$actKey] ?? ucfirst((string) $actKey);
$batch_col_max_len[8] = max($batch_col_max_len[8], mb_strlen((string) $actLabel));
$countStr = ($file['count'] ?? null) === null ? '-' : (string) $file['count'];
$batch_col_max_len[9] = max($batch_col_max_len[9], mb_strlen($countStr));
$batch_col_max_len[10] = max($batch_col_max_len[10], mb_strlen((string) format_indian_number($file['amount'])));
$userTime = change_date_format($file['created_at'] ?? '', 'Y-m-d H:i:s', 'd M Y h:i a')
. ' by '
. get_username($file['created_by'] ?? '');
$batch_col_max_len[11] = max($batch_col_max_len[11], mb_strlen($userTime));
$batch_col_max_len[12] = max($batch_col_max_len[12], mb_strlen((string) ($file['status'] ?? '')));
$batch_col_max_len[13] = max($batch_col_max_len[13], 2);
}
}
$batch_col_min_px = [48, 72, 100, 72, 80, 120, 88, 96, 72, 56, 80, 160, 96, 52];
$batch_col_max_px = [64, 220, 480, 240, 240, 640, 200, 200, 140, 110, 160, 560, 320, 64];
$batch_col_width_px = [];
for ($i = 0; $i < $batch_col_count; $i++) {
$chars = max($batch_col_max_len[$i], mb_strlen($batch_header_labels[$i]));
$px = (int) round($chars * 7.0 + 26);
$batch_col_width_px[$i] = min(
$batch_col_max_px[$i],
max($batch_col_min_px[$i], $px)
);
}
?>
<style>
.reload:hover {
cursor: pointer;
}
/* Column widths from max data length (see PHP above).
Avoid table-layout:fixed + identical max-width on TH — it fights DataTables col sizing and skews TH vs TD.
Do not max-width THEAD cells (sort icons use position:absolute; narrow max clips them). */
<?php for ($i = 0; $i < $batch_col_count; $i++) : ?>
#batch-list-table_wrapper .dataTables_scrollHead table thead th:nth-child(<?= $i + 1 ?>),
#batch-list-table thead th:nth-child(<?= $i + 1 ?>) {
min-width: <?= (int) $batch_col_width_px[$i] ?>px;
width: <?= (int) $batch_col_width_px[$i] ?>px;
box-sizing: border-box;
vertical-align: middle;
overflow: visible !important;
}
#batch-list-table tbody td:nth-child(<?= $i + 1 ?>) {
width: <?= (int) $batch_col_width_px[$i] ?>px;
max-width: <?= (int) $batch_col_width_px[$i] ?>px;
min-width: <?= (int) $batch_col_width_px[$i] ?>px;
box-sizing: border-box;
vertical-align: middle;
}
<?php endfor; ?>
#batch-list-table tbody td:nth-child(1),
#batch-list-table tbody td:nth-child(2),
#batch-list-table tbody td:nth-child(3),
#batch-list-table tbody td:nth-child(4),
#batch-list-table tbody td:nth-child(5),
#batch-list-table tbody td:nth-child(6),
#batch-list-table tbody td:nth-child(7),
#batch-list-table tbody td:nth-child(8),
#batch-list-table tbody td:nth-child(9),
#batch-list-table tbody td:nth-child(10),
#batch-list-table tbody td:nth-child(11),
#batch-list-table tbody td:nth-child(12) {
overflow: hidden;
text-overflow: ellipsis;
}
#batch-list-table tbody td:nth-child(13),
#batch-list-table tbody td:nth-child(14) {
overflow: visible;
text-overflow: clip;
}
/* TPA variation modal layout */
#tpa_variation_modal .modal-dialog {
max-width: 95%;
}
#tpa_variation_modal .modal-content {
max-height: 90vh;
}
#tpa_variation_modal .modal-body {
max-height: calc(85vh - 50px);
overflow-y: auto;
direction: ltr;
}
#tpa_variation_modal .table-responsive {
overflow-x: auto;
}
#tpa_variation_modal table {
white-space: nowrap;
font-size: 11px;
}
#tpa_variation_modal table thead th,
#tpa_variation_modal table tbody td {
padding: 2px 6px;
line-height: 1.1;
}
/* Tabs spacing & styling */
#tpa_variation_modal .nav-tabs {
border-bottom: 1px solid #dee2e6;
margin-bottom: 12px;
gap: 6px;
}
#tpa_variation_modal .nav-tabs .nav-item {
margin-right: 6px;
}
#tpa_variation_modal .nav-tabs .nav-link {
padding: 6px 14px;
border-radius: 4px 4px 0 0;
}
#tpa_variation_modal .nav-tabs .nav-link.active {
background-color: #f8f9fa;
border-color: #dee2e6 #dee2e6 transparent;
}
/* Modal footer buttons size */
#tpa_variation_modal .modal-footer .btn {
padding: 4px 12px;
font-size: 12px;
}
/* Keep DataTable controls aligned like reference UI */
#tpa_variation_modal .dataTables_wrapper .dt-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 6px;
}
#tpa_variation_modal .dataTables_wrapper .dt-bottom {
display: flex;
justify-content: flex-end;
align-items: center;
margin-top: 6px;
}
#tpa_variation_modal .dataTables_wrapper .dt-top .dataTables_length,
#tpa_variation_modal .dataTables_wrapper .dt-top .dataTables_filter,
#tpa_variation_modal .dataTables_wrapper .dt-bottom .dataTables_paginate {
float: none;
margin: 0;
}
#tpa_variation_modal .dataTables_wrapper .dt-top .dataTables_filter {
text-align: right;
}
/* Compact tbody; thead must keep padding-right for sort triangles (custom.css uses ~2.35rem). */
#batch-list-table tbody td {
padding: 5px 11px !important;
font-size: 13px;
line-height: 1.25;
}
#batch-list-table_wrapper .dataTables_scrollHead table thead th,
#batch-list-table thead th {
padding: 5px 2.35rem 5px 11px !important;
font-size: 13px;
line-height: 1.25;
}
/* Action dropdown toggle in rows */
#batch-list-table .dropdown-toggle.btn-sm {
padding: 4px 9px !important;
font-size: 13px;
line-height: 1.2;
}
/* DataTables toolbar buttons (Export/Filter/Clear Filter) */
#batch-list-table_wrapper .dt-buttons .btn {
padding: 6px 13px !important;
font-size: 13px;
}
#batch-list-table_wrapper .dt-buttons .btn .btn-custom {
font-size: 13px;
}
/*
* One horizontal scrollbar without breaking thead/tbody width sync:
* - Do NOT set overflow-x:visible on .dataTables_scrollBody — that breaks DataTables
* scrollHead/scrollBody width matching so <th> looks cut off.
* - When there is no .dataTables_scrollBody (scrollX off, single table), outer scrolls.
* - When .dataTables_scrollBody exists (scrollX on), only that inner strip scrolls (custom.css);
* outer .table-responsive stays overflow visible via nh-dt-no-outer-scroll / :has() rules.
*/
#second_page .card-body > .table-responsive:not(:has(.dataTables_scrollBody)) {
overflow-x: auto !important;
-webkit-overflow-scrolling: touch;
max-width: 100%;
}
</style>
<div class="col-12" id="second_page">
<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;">Batch List</h4>
</div>
</div>
<div class="table-responsive">
<table data-custom-table-css="table" id="batch-list-table" class="table table-hover m-0 table-centered nowrap w-100">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">S.No&nbsp;</th>
<th class="font-weight-medium">Batch Code&nbsp;</th>
<th class="font-weight-medium">File Name&nbsp;</th>
<th class="font-weight-medium">Client&nbsp;</th>
<th class="font-weight-medium">Client Branch&nbsp;</th>
<th class="font-weight-medium">Client Policy&nbsp;</th>
<th class="font-weight-medium">Event Type&nbsp;</th>
<th class="font-weight-medium">Insurer/ TPA&nbsp;</th>
<th class="font-weight-medium">Action&nbsp;</th>
<th class="font-weight-medium">Count&nbsp;</th>
<th class="font-weight-medium">(₹)Amount&nbsp;</th>
<th class="font-weight-medium">User/Time&nbsp;</th>
<th class="font-weight-medium">Status&nbsp;</th>
<th class="font-weight-medium">Action&nbsp;</th>
</tr>
</thead>
<tbody class="font-12">
<?php
if (isset($batch_list)) {
foreach ($batch_list as $key => $file) {
?>
<tr>
<td><b><?php echo ($key + 1) ?></b></td>
<td><?php echo $file['batch_code'] ?></td>
<td class="reload batch-file-cell" data-toggle="tooltip" data-placement="top" title="<?php echo htmlspecialchars($file['file_name'] ?? '', ENT_QUOTES, 'UTF-8') ?>">
<?php echo $file['file_name']?>
</td>
<td><?php echo $file['client_short_name'] ?></td>
<td><?php echo $file['branch_name'] ?></td>
<!-- <td><?php echo isset($file['policy_name']) ? $file['policy_name'] : '' ?> - <?php echo isset($file['policy_no']) ? $file['policy_no'] : '' ?> - <?php echo isset($file['policy_type']) ? $file['policy_type'] : '' ?></td> -->
<?php
$policy_display = trim(
(isset($file['policy_type']) ? $file['policy_type'] : '')
. ' - '
. (isset($file['policy_no']) ? $file['policy_no'] : '')
);
?>
<td class="batch-policy-cell reload"
data-toggle="tooltip"
data-placement="top"
title="<?= esc($policy_display) ?>"><?= esc($policy_display) ?></td>
<td><?php echo $file['event_type'] ?></td>
<td><?php echo $insurer_or_tpa[$file['insurer_or_tpa']] ?>
<?php $insurer_or_tpa_display = $insurer_or_tpa[$file['insurer_or_tpa']] == 'TPA' ? $file['tpa_short_name'] : $file['insurer_short_name'] ?>
<a href=""
class="fe-alert-circle" style="color: #000;" aria-hidden="true"
data-toggle="tooltip" data-placement="top" title="<?php echo $insurer_or_tpa_display ?>"></a>
</td>
<td><?php echo $import_or_export[$file['actions']] ?? ucfirst($file['actions']) ?></td>
<td><?php echo $file['count'] == null ? '-' : $file['count'] ?></td>
<td><?php echo format_indian_number($file['amount'])?></td>
<td class="reload">
<?php echo change_date_format($file['created_at'],'Y-m-d H:i:s', 'd M Y h:i a') ?> by <?php echo get_username($file['created_by']) ?>
</td>
<td>
<?php if ($file['status'] == 'failed') { ?>
<?php echo $file['status']; ?>
<a href="<?= base_url('/util/export-import-error-list/') . $file['id'] ?>"
class="fe-alert-circle" style="color: #000;" aria-hidden="true" target="_blank"
data-toggle="tooltip" data-placement="top" title="Click to show the error"></a>
&nbsp;
<?php } else if ($file['status'] == 'partially success') { ?>
<?php echo $file['status']; ?>
<?php if ($file['error_data'] != 0) { ?>
<a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" title="<?= $file['error_data'] ?>"></a>
&nbsp;
<?php } ?>
<?php } else if ($file['status'] == 'in-progress-partially') { ?>
<?php echo $file['status']; ?>
<?php if (!is_json_string($file['error_data'])) { ?>
<a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" title="<?= $file['error_data'] ?>"></a>
&nbsp;
<?php } ?>
<?php } else if ($file['status'] == 'failed-1') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top"
title="<?= $file['event_type'] == 'inception' ? 'The list of employees provided has already been updated with the TPA ID.' : 'The list of employees provided has already been updated with the ENDORSEMENT ID.' ?> "></a>
<?php } else if ($file['status'] == 'failed-2') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top"
title="<?= $file['event_type'] == 'inception' ? 'The list of employees provided has already been updated with the UHID.' : 'The list of employees provided has already been updated with the ENDORSEMENT ID.' ?>"></a>
<?php } else if ($file['status'] == 'failed-3') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top"
title="The Excel record count exceeds the DB record count."></a>
<?php } else if ($file['status'] == 'failed-4') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" title="Physical File Not Found."></a>
<?php } else if ($file['status'] == 'failed-5') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" title="Wrong File Uploaded"></a>
<?php } else if ($file['status'] == 'failed-6') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" title="There is no data to update"></a>
<?php } else if ($file['status'] == 'failed-7') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" title="<?= $file['error_data'] ?? 'Unknown error. Contact system administrator.' ?>"></a>
<?php } else if ($file['status'] == 'failed-8') { ?>
failed
<?php } else { ?>
<?php echo $file['status']; ?>
<?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>
<?php if($file['actions'] != 'export') { ?>
<div class="dropdown-menu dropdown-menu-right">
<?php if (str_starts_with($file['status'], 'failed')) { ?>
<a href="#"
data-id="<?= $file['id'] ?>"
data-client_id="<?= $file['client_id'] ?>"
data-client_policy_id="<?= $file['client_policy_id'] ?>"
data-insurer_or_tpa="<?= $file['insurer_or_tpa'] ?>"
data-event_type="<?= $file['event_type'] ?>"
data-actions="<?= $file['actions'] ?>"
data-client_branch_id="<?= $file['client_branch_id'] ?>"
data-issue_date="<?= $file['policy_issue_date'] ?>"
onclick="getBatchFileData(this)" class="dropdown-item upload_button" ><i class="mdi mdi-upload mr-2 text-muted font-18 vertical-middle"></i>Re-Upload</a>
<?php } ?>
<?php if ($file['actions'] == "import") { ?>
<a href="<?= base_url('/util/download_import_file/') . $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>
<?php } ?>
<?php if ($file['actions'] == "fetch" && $file['status'] == 'partially success') { ?>
<a href="<?= base_url('employee/getTPADataVariationReport/') . $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 TPA Variation report</a>
<a href="#" class="dropdown-item" style="color: #000;" aria-hidden="true" onclick="getTPADataVariationReport(<?= $file['id'] ?>)"><i class="mdi mdi-eye mr-2 text-muted font-18 vertical-middle"></i>View TPA Variation report</a>
<?php } ?>
</div>
<?php } ?>
</div>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
<div>
</div>
</div>
</div><!-- end col -->
</div>
</div>
<!-- Center modal content for reupload file-->
<div class="modal fade" id="batch_file_upload_modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myCenterModalLabel">Re-Upload the file</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form class="parsley-examples" id="re_upload_import_export_excel_form" action="<?php echo base_url() . 'util/import-export' ?>" method="post" enctype="multipart/form-data">
<input type="hidden" id="batch_file_client_id" name="client_id">
<input type="hidden" id="batch_file_policy_id" name="client_policy_id">
<input type="hidden" id="batch_file_branch_id" name="client_branch_id">
<input type="hidden" id="batch_file_insurer_or_tpa" name="insurer_or_tpa">
<input type="hidden" id="batch_file_action_type" name="action_type">
<input type="hidden" id="batch_file_event_type" name="event_type">
<input type="hidden" id="batch_file_issue_date" name="policy_issue_date">
<input type="file" id="import_file_data" name="import_file_data" required
accept=" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet">
<button type="submit" class="btn btn-primary">Upload</button>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- TPA Data Variation Modal -->
<div class="modal fade" id="tpa_variation_modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">TPA Data Variation Report</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<ul class="nav nav-tabs" id="tpaVariationTabs" role="tablist">
<li class="nav-item">
<a class="nav-link active active_tab" id="not-in-nhance-tab" data-toggle="tab" href="#not_in_nhance_tab" role="tab" aria-controls="not_in_nhance_tab" aria-selected="true">Not in Nhance</a>
</li>
<li class="nav-item">
<a class="nav-link" id="not-in-tpa-tab" data-toggle="tab" href="#not_in_tpa_tab" role="tab" aria-controls="not_in_tpa_tab" aria-selected="false">Not in TPA</a>
</li>
<li class="nav-item">
<a class="nav-link" id="need-to-review-tab" data-toggle="tab" href="#need_to_review_tab" role="tab" aria-controls="need_to_review_tab" aria-selected="false">Need to Review</a>
</li>
</ul>
<div class="tab-content pt-3" id="tpaVariationTabContent">
<div class="tab-pane fade show active" id="not_in_nhance_tab" role="tabpanel" aria-labelledby="not-in-nhance-tab">
<div class="table-responsive">
<table class="table table-bordered table-sm" id="not_in_nhance_table">
<thead></thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="tab-pane fade" id="not_in_tpa_tab" role="tabpanel" aria-labelledby="not-in-tpa-tab">
<div class="table-responsive">
<table class="table table-bordered table-sm" id="not_in_tpa_table">
<thead></thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="tab-pane fade" id="need_to_review_tab" role="tabpanel" aria-labelledby="need-to-review-tab">
<div class="table-responsive">
<table class="table table-bordered table-sm" id="need_to_review_table">
<thead></thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Close</button>
<button type="button" id="tpaProceedButton" class="btn btn-primary btn-sm" onclick="handleTPAProceed()">Proceed</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
let currentTPAVariationFileId = null;
const tpaVariationColumns = {
not_in_nhance: [
{ key: 'emp_code', label: 'Employee Code' },
{ key: 'name', label: 'Employee Name' },
{ key: 'relation', label: 'Relation' },
{ key: 'dob', label: 'Date of Birth' },
{ key: 'gender', label: 'Gender' },
{ key: 'age', label: 'Age' },
{ key: 'tpa_id', label: 'TPA Member ID' },
],
not_in_tpa: [
{ key: 'emp_code', label: 'Employee Code' },
{ key: 'name', label: 'Employee Name' },
{ key: 'relationship', label: 'Relation' },
{ key: 'dob', label: 'Date of Birth' },
{ key: 'gender', label: 'Gender' },
{ key: 'mobile', label: 'Mobile No' },
{ key: 'email_corporate', label: 'Corporate Email' },
{ key: 'policy_no', label: 'Policy No' },
{ key: 'tpa_name', label: 'TPA Name' },
{ key: 'change_event', label: 'Change Event' },
],
need_to_review: [
// DB side
{ key: 'emp_code', label: 'Employee Code' },
{ key: 'name', label: 'Employee Name' },
{ key: 'relationship', label: 'Relation' },
{ key: 'dob', label: 'Date of Birth' },
{ key: 'gender', label: 'Gender' },
{ key: 'policy_no', label: 'Policy No' },
{ key: 'uhid', label: 'UHID' },
{ key: 'change_event', label: 'Change Event' },
// TPA side
{ key: 'tpa_emp_code', label: 'TPA Employee Code' },
{ key: 'tpa_name', label: 'TPA Name' },
{ key: 'tpa_relation', label: 'TPA Relation' },
{ key: 'tpa_dob', label: 'TPA Date of Birth' },
{ key: 'tpa_gender', label: 'TPA Gender' },
{ key: 'tpa_tpa_id', label: 'TPA Member ID' },
{ key: 'tpa_age', label: 'TPA Age' },
// Mismatch info
{ key: 'mismatch_fields', label: 'Mismatch Fields' },
],
};
/** Activate a TPA variation tab by id (not-in-nhance-tab, not-in-tpa-tab, need-to-review-tab). Works without jQuery .tab('show'). */
function showTPAVariationTabByLinkId(tabLinkId) {
var paneMap = {
'not-in-nhance-tab': 'not_in_nhance_tab',
'not-in-tpa-tab': 'not_in_tpa_tab',
'need-to-review-tab': 'need_to_review_tab'
};
var paneId = paneMap[tabLinkId];
if (!paneId) {
return;
}
$('#tpaVariationTabs .nav-link').removeClass('active').attr('aria-selected', 'false');
$('#' + tabLinkId).addClass('active').attr('aria-selected', 'true');
$('#tpaVariationTabContent .tab-pane').removeClass('show active');
$('#' + paneId).addClass('show active');
}
function renderVariationTable(tableSelector, rows, columns) {
const $table = $(tableSelector);
const $thead = $table.find('thead');
const $tbody = $table.find('tbody');
$thead.empty();
$tbody.empty();
const headerRow = $('<tr></tr>');
columns.forEach(col => {
headerRow.append($('<th></th>').text(col.label));
});
$thead.append(headerRow);
if (!rows || !rows.length) {
const emptyRow = $('<tr></tr>');
columns.forEach((col, index) => {
const td = $('<td></td>');
if (index === 0) {
td.addClass('text-center text-muted').text('No data found');
}
emptyRow.append(td);
});
$tbody.append(emptyRow);
return;
}
rows.forEach(row => {
const tr = $('<tr></tr>');
columns.forEach(col => {
let value = row[col.key];
if (value === null || value === undefined) {
value = '';
}
tr.append($('<td></td>').text(value));
});
$tbody.append(tr);
});
}
function populateTPAVariationModal(data) {
const notInNhance = data.not_in_nhance || [];
const notInTpa = data.not_in_tpa || [];
const reviewData = (data.mismatch_data || []).map(row => {
let mismatchFields = '';
const match = row.match || {};
const notMatching = match.not_matching || [];
if (Array.isArray(notMatching) && notMatching.length) {
mismatchFields = notMatching.join(', ');
} else if (match.status && match.status !== 'matched') {
mismatchFields = match.status;
}
const tpaRecord = match.tpa_record || {};
return Object.assign({}, row, {
mismatch_fields: mismatchFields,
tpa_emp_code: tpaRecord.emp_code || '',
tpa_name: tpaRecord.name || '',
tpa_relation: tpaRecord.relation || '',
tpa_dob: tpaRecord.dob || '',
tpa_gender: tpaRecord.gender || '',
tpa_tpa_id: tpaRecord.tpa_id || '',
tpa_age: tpaRecord.age || '',
});
});
destroyVariationDataTable('#not_in_nhance_table');
destroyVariationDataTable('#not_in_tpa_table');
destroyVariationDataTable('#need_to_review_table');
renderVariationTable('#not_in_nhance_table', notInNhance, tpaVariationColumns.not_in_nhance);
renderVariationTable('#not_in_tpa_table', notInTpa, tpaVariationColumns.not_in_tpa);
renderVariationTable('#need_to_review_table', reviewData, tpaVariationColumns.need_to_review);
// Default tab: Not in Nhance — select tab and init DataTable for #not_in_nhance_table as soon as data is rendered.
showTPAVariationTabByLinkId('not-in-nhance-tab');
updateTPAProceedButton('not-in-nhance-tab');
adjustVariationTableByTabId('not-in-nhance-tab');
}
function showTPAVariationModal() {
const modalElement = document.getElementById('tpa_variation_modal');
if (!modalElement) {
return;
}
const modal = new bootstrap.Modal(modalElement);
modal.show();
// Ensure proceed button reflects the currently active tab when modal opens
const $activeTab = $('#tpaVariationTabs .nav-link.active');
updateTPAProceedButton($activeTab.attr('id'));
}
function getVariationDataTableConfig() {
return {
dom: "<'dt-top'lf>" +
"rt" +
"<'dt-bottom'p>",
pageLength: 20,
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
searching: true,
paging: true,
ordering: false,
info: false,
autoWidth: false,
language: {
search: `
<div class="datatable-search-wrapper" style="position:relative; display:inline-block;">
_INPUT_
<i class="mdi mdi-magnify datatable-search-icon"
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
<i class="mdi mdi-close-circle datatable-clear-icon"
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none; cursor:pointer;"></i>
</div>`,
searchPlaceholder: "Search"
}
};
}
function bindVariationSearchIcons($table) {
const $wrapper = $table.closest('.dataTables_wrapper');
const $searchInput = $wrapper.find('.dataTables_filter input');
const $magnify = $wrapper.find('.datatable-search-icon');
const $clear = $wrapper.find('.datatable-clear-icon');
if (!$searchInput.length) {
return;
}
$searchInput.off('input.variationSearch').on('input.variationSearch', function () {
const hasValue = !!$(this).val();
$magnify.toggle(!hasValue);
$clear.toggle(hasValue);
});
$clear.off('click.variationSearch').on('click.variationSearch', function () {
$searchInput.val('').trigger('input').trigger('keyup');
});
const hasInitialValue = !!$searchInput.val();
$magnify.toggle(!hasInitialValue);
$clear.toggle(hasInitialValue);
}
function initVariationDataTable(tableSelector) {
const $table = $(tableSelector);
if (!$table.length) {
return;
}
if (!$.fn.DataTable.isDataTable($table)) {
$table.DataTable(getVariationDataTableConfig());
}
const dt = $table.DataTable();
dt.columns.adjust().draw(false);
bindVariationSearchIcons($table);
}
function adjustVariationTableByTabId(tabId) {
const tabToTableMap = {
'not-in-nhance-tab': '#not_in_nhance_table',
'not-in-tpa-tab': '#not_in_tpa_table',
'need-to-review-tab': '#need_to_review_table'
};
const tableSelector = tabToTableMap[tabId];
if (!tableSelector) {
return;
}
initVariationDataTable(tableSelector);
}
function destroyVariationDataTable(tableSelector) {
const $table = $(tableSelector);
if ($.fn.DataTable.isDataTable($table)) {
$table.DataTable().clear().destroy();
}
}
function updateTPAProceedButton(activeId) {
const $button = $('#tpaProceedButton');
if (!$button.length) {
return;
}
// Default: visible
$button.removeClass('d-none');
if (activeId === 'not-in-nhance-tab') {
$button.text('Proceed - Not in Nhance');
} else if (activeId === 'need-to-review-tab') {
$button.text('Proceed - Need to Review');
} else if (activeId === 'not-in-tpa-tab') {
// Hide button for "Not in TPA" section
$button.addClass('d-none');
} else {
$button.text('Proceed');
}
}
$(document).ready(function() {
// Update proceed button label/visibility and ensure datatable is rendered on tab change
$('#tpaVariationTabs a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
const activeId = $(e.target).attr('id');
updateTPAProceedButton(activeId);
adjustVariationTableByTabId(activeId);
});
$('#tpa_variation_modal').on('shown.bs.modal', function () {
// Always show "Not in Nhance" first; re-measure DataTable now that the modal is visible.
showTPAVariationTabByLinkId('not-in-nhance-tab');
updateTPAProceedButton('not-in-nhance-tab');
adjustVariationTableByTabId('not-in-nhance-tab');
});
$('#tpa_variation_modal').on('hidden.bs.modal', function () {
destroyVariationDataTable('#not_in_nhance_table');
destroyVariationDataTable('#not_in_tpa_table');
destroyVariationDataTable('#need_to_review_table');
});
/* footer.php sets scrollX/scrollY on $.fn.dataTable.defaults — force off for this init so DT does not split thead into .dataTables_scrollHead / tbody into .dataTables_scrollBody (only the body strip would scroll horizontally). */
var _dtDefScroll = {
scrollX: $.fn.dataTable.defaults.scrollX,
scrollY: $.fn.dataTable.defaults.scrollY,
scrollCollapse: $.fn.dataTable.defaults.scrollCollapse
};
$.extend($.fn.dataTable.defaults, { scrollX: false, scrollY: false, scrollCollapse: false });
const batchListTable = $('#batch-list-table').DataTable({
dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
"<'row'<'col-sm-12'tr>>" +
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
scrollX: false,
scrollY: false,
scrollCollapse: false,
initComplete: function () {
var $wrap = $(this.api().table().container());
var $body = $wrap.find('.dataTables_scrollBody');
var $head = $wrap.find('.dataTables_scrollHead');
if ($body.length && $head.length) {
$body.off('scroll.nhBatchHScroll').on('scroll.nhBatchHScroll', function () {
$head.scrollLeft($(this).scrollLeft());
});
$head.off('scroll.nhBatchHScroll').on('scroll.nhBatchHScroll', function () {
$body.scrollLeft($(this).scrollLeft());
});
}
},
columnDefs: [
<?php for ($i = 0; $i < $batch_col_count; $i++) : ?>
{ targets: <?= $i ?>, width: '<?= (int) $batch_col_width_px[$i] ?>px' },
<?php endfor; ?>
],
buttons: [
{
extend: 'collection',
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
className: 'btn app-btn-secondary mr-2',
buttons: [
{
extend: 'csv',
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
title: 'Batch List',
className: 'app-btn-primary ',
}
]
},
{
text: '<i class="mdi mdi-filter" ></i><span class=" btn-custom"> Filter </span>',
className: 'btn app-btn-primary mr-2',
action: function(e, dt, node, config) {
openPolicyFilterNav(2);
}
},
{
text: '<i class="mdi mdi-filter-remove"></i><span class="btn-custom"> Clear Filter </span>',
className: 'btn app-btn-info mr-2 hide-clear-filter',
action: function(e, dt, node, config) {
clearFilterData();
}
}
],
language: {
search: `
<div class="datatable-search-wrapper" style="position:relative; display:inline-block;">
_INPUT_
<i class="mdi mdi-magnify datatable-search-icon"
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
<i class="mdi mdi-close-circle datatable-clear-icon"
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none;"></i>
</div>`,
searchPlaceholder: "Search",
emptyTable: '<div class="text-center text-muted">No Data found</div>'
},
autoWidth: false,
paging: true,
responsive: false
});
$.extend($.fn.dataTable.defaults, _dtDefScroll);
// Keep TH and TD widths in sync after any table redraw (search/sort/paginate).
batchListTable.on('draw.dt', function () {
batchListTable.columns.adjust();
});
$(window).on('resize', function () {
batchListTable.columns.adjust();
});
// Initial alignment after DataTable renders buttons/filter layout.
setTimeout(function () {
batchListTable.columns.adjust();
}, 0);
});
// Function to format a number in Indian Rupees format
function formatNumberInIndianRupees(number) {
const maxLength = 16;
let value = number.toString().replace(/\D/g, ''); // Remove non-numeric characters
// Limit the number of digits
value = value.slice(0, maxLength);
// Format the number with commas using Indian numbering system
const formattedNumber = Number(value).toLocaleString('en-IN');
return formattedNumber;
}
// Function to format numbers based on a class
function formatNumbersByClass(className) {
const elements = document.querySelectorAll(`.${className}`);
console.log('element', elements)
elements.forEach(element => {
const number = parseFloat(element.innerText.replace(/,/g, ''));
console.log('number', number)
if (!isNaN(number)) {
console.log(formatNumberInIndianRupees(number))
element.innerText = formatNumberInIndianRupees(number);
}
});
}
// Format numbers when the DOM content is loaded
document.addEventListener("DOMContentLoaded", function() {
setTimeout(() => {
formatNumbersByClass('indian-number');
}, 500);
});
function getBatchFileData(input){
let client_id = $(input).data('client_id')
let client_policy_id = $(input).data('client_policy_id')
let client_branch_id = $(input).data('client_branch_id')
let insurer_or_tpa = $(input).data('insurer_or_tpa')
let event_type = $(input).data('event_type')
let actions = $(input).data('actions')
let issue_date = $(input).data('issue_date')
console.log('client_id', client_id);
console.log('client_policy_id', client_policy_id);
console.log('client_branch_id', client_branch_id);
console.log('insurer_or_tpa', insurer_or_tpa);
console.log('event_type', event_type);
console.log('actions', actions);
console.log('issue_date', issue_date);
$('#batch_file_client_id').val(client_id);
$('#batch_file_policy_id').val(client_policy_id);
$('#batch_file_branch_id').val(client_branch_id);
$('#batch_file_insurer_or_tpa').val(insurer_or_tpa);
$('#batch_file_action_type').val(actions);
$('#batch_file_event_type').val(event_type);
$('#batch_file_issue_date').val(issue_date);
var myModal = new bootstrap.Modal(document.getElementById('batch_file_upload_modal'));
myModal.show();
// $('.loader').fadeIn();
// $('.loader-mask').fadeIn();
// console.log('file_id', file_id);
// let url = '<?= base_url('util/getBatchFileData') ?>';
// // Data to send in the AJAX request
// let requestData = {
// file_id: file_id,
// };
// // Send AJAX request
// sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
// console.log('Data fetched successfully:', response);
// console.log('Data fetched successfully:', response.batch_file_data);
// console.log('response.batch_file_data.client_branch_id:', response.batch_file_data.client_branch_id);
// if (response.status == true) {
// } else {
// toastr.warning(response.message || 'Unable to fetch data', 'WARNING');
// }
// $('.loader').fadeOut();
// $('.loader-mask').delay(350).fadeOut('slow');
// }, function(xhr, status, error) {
// console.error('Error fetching data:', error);
// console.error(xhr.responseText);
// toastr.error('An error occurred while checking the SI amount.', 'ERROR');
// $('.loader').fadeOut();
// $('.loader-mask').delay(350).fadeOut('slow');
// // addRow();
// });
}
function getTPADataVariationReport(file_id) {
currentTPAVariationFileId = file_id;
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
let url = '<?= base_url('employee/getTPADataVariationReportView') ?>/' + file_id;
sendAjaxRequestForGlobal(url, 'GET', {}, function (response) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (response && response.status && response.data) {
populateTPAVariationModal(response.data);
showTPAVariationModal();
} else {
toastr.warning((response && response.message) || 'No data found for variation report.', 'WARNING');
}
}, function (xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.error('Error fetching TPA variation data:', error);
toastr.error('An error occurred while fetching the variation report.', 'ERROR');
});
}
function proceedTPADataVariationNextStep(tabKey) {
if (!currentTPAVariationFileId) {
toastr.warning('Unable to identify the selected file.', 'WARNING');
return;
}
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
const url = '<?= base_url('employee/proceedTPADataVariationNextStep') ?>/' + currentTPAVariationFileId + '?tab=' + encodeURIComponent(tabKey);
sendAjaxRequestForGlobal(url, 'GET', {}, function (response) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (response && response.status) {
toastr.success(response.message || 'Proceed to next step initiated successfully.', 'SUCCESS');
} else {
toastr.warning(response.message || 'Unable to proceed to next step.', 'WARNING');
}
window.location.reload();
}, function (xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.error('An error occurred while proceeding to the next step.', 'ERROR');
console.error(error);
});
}
function proceedNotInNhance() {
proceedTPADataVariationNextStep('not_in_nhance');
}
function proceedNotInTPA() {
proceedTPADataVariationNextStep('not_in_tpa');
}
function proceedNeedToReview() {
proceedTPADataVariationNextStep('need_to_review');
}
function handleTPAProceed() {
const $activeTab = $('#tpaVariationTabs .nav-link.active');
const activeId = $activeTab.attr('id');
if (!activeId) {
toastr.warning('No active tab selected.', 'WARNING');
return;
}
const tabLabel = ($activeTab.text() || '').trim() || 'this tab';
confirmActionSweertAlert(
"Are you sure you want to proceed with the data in this tab?",
"Yes, Proceed",
"Cancel",
"warning"
).then(function(isConfirmed) {
if (!isConfirmed) {
return;
}
if (activeId === 'not-in-nhance-tab') {
proceedNotInNhance();
} else if (activeId === 'not-in-tpa-tab') {
proceedNotInTPA();
} else if (activeId === 'need-to-review-tab') {
proceedNeedToReview();
} else {
toastr.warning('Unknown tab selected.', 'WARNING');
}
});
}
</script>