nhance/app/Views/insurer_list.php

255 lines
9.6 KiB
PHP
Executable File

<?php
helper('datatable_view');
$insurerList = $insurerList ?? [];
$ins_header_labels = ['Name', 'Type', 'Action'];
$ins_col_count = count($ins_header_labels);
$ins_col_max_len = array_fill(0, $ins_col_count, 0);
for ($i = 0; $i < $ins_col_count; $i++) {
$ins_col_max_len[$i] = mb_strlen($ins_header_labels[$i]);
}
if (is_array($insurerList)) {
foreach ($insurerList as $row) {
$nameCell = trim(($row['name'] ?? '') . ' ( ' . ($row['short_name'] ?? '') . ' )');
$ins_col_max_len[0] = max($ins_col_max_len[0], mb_strlen($nameCell));
$ins_col_max_len[1] = max($ins_col_max_len[1], mb_strlen((string) ($row['type'] ?? '')));
$ins_col_max_len[2] = max($ins_col_max_len[2], 4);
}
}
$ins_col_min_px = [120, 88, 72];
$ins_col_max_px = [560, 240, 96];
$ins_col_width_px = nhance_dt_column_widths_px($ins_header_labels, $ins_col_max_len, $ins_col_min_px, $ins_col_max_px);
?>
<style>
.btn-color {
background-color: rgba(52, 174, 178, 1);
color: white;
border: 1px solid rgba(52, 174, 178, 1);
}
.btn-color:hover {
background-color: rgba(41, 139, 142, 1);
color: white;
border: 1px solid rgba(41, 139, 142, 1);
}
.dataTables_length label {height: 21px !important;}
.col-12 {
max-width: 98% !important;
}
</style>
<style>
<?php for ($i = 0; $i < $ins_col_count; $i++) : ?>
#insurer-list-table_wrapper .dataTables_scrollHead table thead th:nth-child(<?= $i + 1 ?>),
#insurer-list-table thead th:nth-child(<?= $i + 1 ?>) {
min-width: <?= (int) $ins_col_width_px[$i] ?>px;
width: <?= (int) $ins_col_width_px[$i] ?>px;
box-sizing: border-box;
vertical-align: middle;
overflow: visible !important;
}
#insurer-list-table tbody td:nth-child(<?= $i + 1 ?>) {
width: <?= (int) $ins_col_width_px[$i] ?>px;
max-width: <?= (int) $ins_col_width_px[$i] ?>px;
min-width: <?= (int) $ins_col_width_px[$i] ?>px;
box-sizing: border-box;
vertical-align: middle;
}
<?php endfor; ?>
#insurer-list-table tbody td:not(:last-child) {
overflow: hidden;
text-overflow: ellipsis;
}
#insurer-list-table tbody td:last-child {
overflow: visible;
text-overflow: clip;
}
#insurer-list-table tbody td {
padding: 5px 11px !important;
font-size: 13px;
line-height: 1.25;
}
#insurer-list-table_wrapper .dataTables_scrollHead table thead th,
#insurer-list-table thead th {
padding: 5px 2.35rem 5px 11px !important;
font-size: 13px;
line-height: 1.25;
}
</style>
<div class="container-fluid-min">
<div class="row" id="insurer_list">
<div class="col-12">
<div class="card">
<div class="card-body">
<!-- <div class="row" style="margin-bottom:1rem;">
<div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Insurers</h4>
</div>
</div> -->
<table data-custom-table-css="table" class="table mb-0 nowrap" cellspacing="0"
id="insurer-list-table">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">Name&nbsp;</th>
<th class="font-weight-medium">Type&nbsp;</th>
<th class="font-weight-medium text-center">Action&nbsp;</th>
</tr>
</thead>
<tbody>
<?php if (is_array($insurerList)) {
foreach ($insurerList as $row) { ?>
<tr>
<td><?php echo $row['name']; ?> ( <?php echo $row['short_name']; ?> ) </td>
<td><?php echo $row['type']; ?></td>
<td class="text-center table-action-cell">
<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="<?= base_url("master/insurer/list/"); ?><?= $row['id']; ?>"><i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a class="dropdown-item" data-id="<?= $row['id']; ?>" onclick="removeInsurer(this)"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete</a>
</div>
</div>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
</div>
</div><!-- end col -->
</div>
</div>
<!-- end row -->
<script>
$(document).ready(function() {
nhanceListDataTableBeforeInit();
var table = $('#insurer-list-table').DataTable(nhanceMergeListDataTableOptions({
dom: "<'row'<'col-12 d-flex justify-content-between align-items-center'<'datatable-search dataTables_filter'f><'datatable-buttons dt-buttons'B>>>" +
"<'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]],
buttons: [
{
text: '<i class="mdi mdi-plus" ></i><span class=" btn-custom"> Add </span>',
className: 'btn app-btn-primary mr-2',
action: function() {
window.location.href = "<?= base_url("master/insurer/create"); ?>";
}
},
{
extend: 'collection',
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
className: 'btn app-btn-secondary ',
buttons: [
{
extend: 'csv',
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
className: 'app-btn-primary ',
title: 'InsurerList',
exportOptions: {
columns: ':not(:last-child)'
}
}
]
}
],
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>',
paginate: {
previous: '◄',
next: '►'
}
},
paging: true,
columnDefs: [
<?php for ($i = 0; $i < $ins_col_count; $i++) : ?>
{ targets: <?= $i ?>, width: '<?= (int) $ins_col_width_px[$i] ?>px' },
<?php endfor; ?>
],
}));
nhanceListDataTableAfterInit();
nhanceListDataTableBindAdjust(table);
function applyBottomRowDropup() {
if (!table) return;
const currentRows = table.rows({ page: 'current' }).nodes().toArray();
$('#insurer-list-table tbody tr').removeClass('nh-force-dropup');
$('#insurer-list-table tbody tr td.table-action-cell .btn-group.dropdown').removeClass('dropup');
const targetCount = Math.min(2, currentRows.length);
for (let i = 0; i < targetCount; i++) {
const row = currentRows[currentRows.length - 1 - i];
if (!row) continue;
$(row).addClass('nh-force-dropup');
$(row).find('td.table-action-cell .btn-group.dropdown').addClass('dropup');
}
}
applyBottomRowDropup();
$('#insurer-list-table').on('draw.dt', applyBottomRowDropup);
})
function removeInsurer(element) {
Swal.fire({
title: "Are you sure?",
text: "You need to remove this insurer.",
icon: "info",
showCancelButton: true,
confirmButtonColor: "#3085d6",
confirmButtonText: "Yes",
}).then((result) => {
if (result.isConfirmed) {
var id = element.getAttribute('data-id');
var form_action = '<?= base_url("master/insurer/remove/") ?>' + id;
$.ajax({
url: form_action,
type: "GET",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
// console.log(res.status == true);
if (res) {
if (res.status == true) {
toastr.success('Insurer removed successfully', 'Success');
location.reload();
} else {
toastr.warning('Failed to remove insurer', 'Warning');
}
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
toastr.warning('Failed to remove insurer', 'Warning');
}
});
}
});
}
</script>