nhance/app/Views/employee_data_list.php
2026-04-22 11:44:38 +05:30

1056 lines
47 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.

<style>
.badge2 {
box-shadow: none;
}
.badge2-secondary2 {
color: #fff;
background-color: #187607;
}
.badge2 {
display: inline-block;
padding: .25em .4em;
font-size: 75%;
font-weight: 700;
line-height: 1;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border-radius: .25rem;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.table-responsive {
overflow-x: auto;
}
.word-wrap {
word-wrap: break-word;
white-space: normal;
}
.right-align-input {
text-align: right;
}
.readonly-select {
pointer-events: none;
background-color: #f0f0f0;
color: #666;
}
</style>
<style>
/* Timeline Design */
.timeline {
position: relative;
padding-left: 30px;
border-left: 3px solid #007bff;
}
.timeline-item {
position: relative;
margin-bottom: 20px;
padding-left: 20px;
}
.timeline-dot {
position: absolute;
left: -10px;
top: 5px;
width: 15px;
height: 15px;
background: #007bff;
border-radius: 50%;
}
.timeline-content {
background: #f8f9fa;
padding: 10px;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.dataTables_length label {height: 21px !important;}
</style>
<?php
helper('datatable_view');
$getData = $getData ?? null;
$emp_show_client_branch = isset($getData) && $getData['client_id'] == '0' && $getData['policy_id'] == '0' && $getData['branch_id'] == '0' && ($getData['emp_code'] != '' || $getData['emp_name'] != '' || $getData['status'] != '');
$emp_show_branch = isset($getData) && $getData['client_id'] != '0' && $getData['branch_id'] == '0';
$emp_header_labels = ['S.No'];
if ($emp_show_client_branch) {
$emp_header_labels[] = 'Client/Branch';
}
if ($emp_show_branch) {
$emp_header_labels[] = 'Branch';
}
$emp_header_labels = array_merge($emp_header_labels, [
'Name ', 'EMP Code ', 'Relationship ', 'Gender ', 'Email', 'Mobile', 'Date of Birth',
'Policy name ', 'Insurer name ', 'TPA ID ', 'Risk ID ', 'Policy status ',
'(₹)Sum Insured ', '(₹)Premium ', '(₹)Pro Rata Premium ', '(₹)GST ', 'Action ',
]);
$emp_col_count = count($emp_header_labels);
$emp_col_max_len = array_fill(0, $emp_col_count, 0);
for ($i = 0; $i < $emp_col_count; $i++) {
$emp_col_max_len[$i] = mb_strlen($emp_header_labels[$i]);
}
if (isset($employees)) {
foreach ($employees as $key => $employee) {
$ci = 0;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($key + 1)));
$ci++;
if ($emp_show_client_branch) {
$cb = ($employee['client_short_name'] ?? '') . ' - ' . ($employee['client_branch_name'] ?? '');
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen($cb));
$ci++;
}
if ($emp_show_branch) {
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['client_branch_name'] ?? '')));
$ci++;
}
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['name'] ?? '')));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['emp_code'] ?? '')));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['relationship'] ?? '')));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['gender'] ?? '')));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['email_corporate'] ?? '')));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['mobile'] ?? '')));
$ci++;
$dobStr = '';
if (! empty($employee['dob'])) {
$dobStr = date('d/m/Y', strtotime((string) $employee['dob']));
}
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen($dobStr));
$ci++;
$polStr = (isset($employee['policy_type']) ? $employee['policy_type'] : '') . ' - ' . (isset($employee['policy_no']) ? $employee['policy_no'] : '');
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen($polStr));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['insurer_short_name'] ?? '')));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['tpa_id'] ?? '')));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['uhid'] ?? '')));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) ($employee['status'] ?? '')));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) format_indian_number($employee['basic_cover_si'] ?? 0)));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) format_indian_number($employee['premium'] ?? 0)));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) format_indian_number($employee['rata_premimum'] ?? 0)));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], mb_strlen((string) format_indian_number($employee['gst'] ?? 0)));
$ci++;
$emp_col_max_len[$ci] = max($emp_col_max_len[$ci], 4);
}
}
$emp_col_max_len[$emp_col_count - 6] = max($emp_col_max_len[$emp_col_count - 6], mb_strlen('Total'));
$emp_col_min_px = array_fill(0, $emp_col_count, 80);
$emp_col_max_px = array_fill(0, $emp_col_count, 360);
$emp_col_min_px[0] = 64;
$emp_col_max_px[0] = 88;
$emp_dynamic_idx = 1;
if ($emp_show_client_branch || $emp_show_branch) {
$emp_col_min_px[$emp_dynamic_idx] = max($emp_col_min_px[$emp_dynamic_idx], 120);
$emp_col_max_px[$emp_dynamic_idx] = max($emp_col_max_px[$emp_dynamic_idx], 190);
$emp_dynamic_idx++;
}
$emp_col_min_px[$emp_dynamic_idx] = max($emp_col_min_px[$emp_dynamic_idx], 110); // Name
$emp_dynamic_idx++;
$emp_col_min_px[$emp_dynamic_idx] = max($emp_col_min_px[$emp_dynamic_idx], 100); // EMP Code
$emp_col_max_px[$emp_dynamic_idx] = max($emp_col_max_px[$emp_dynamic_idx], 140);
$emp_col_min_px[$emp_col_count - 1] = 72;
$emp_col_max_px[$emp_col_count - 1] = 96;
$emp_col_width_px = nhance_dt_column_widths_px($emp_header_labels, $emp_col_max_len, $emp_col_min_px, $emp_col_max_px);
$pro_rata_total = 0;
$gst_total = 0;
?>
<style>
<?php for ($i = 0; $i < $emp_col_count; $i++) : ?>
#employee-data-list-table_wrapper .dataTables_scrollHead table thead th:nth-child(<?= $i + 1 ?>),
#employee-data-list-table thead th:nth-child(<?= $i + 1 ?>) {
min-width: <?= (int) $emp_col_width_px[$i] ?>px;
width: <?= (int) $emp_col_width_px[$i] ?>px;
box-sizing: border-box;
vertical-align: middle;
overflow: visible !important;
}
#employee-data-list-table tbody td:nth-child(<?= $i + 1 ?>) {
width: <?= (int) $emp_col_width_px[$i] ?>px;
max-width: <?= (int) $emp_col_width_px[$i] ?>px;
min-width: <?= (int) $emp_col_width_px[$i] ?>px;
box-sizing: border-box;
vertical-align: middle;
}
<?php endfor; ?>
#employee-data-list-table,
#employee-data-list-table_wrapper .dataTables_scrollHead table,
#employee-data-list-table_wrapper .dataTables_scrollBody table {
table-layout: fixed !important;
}
#employee-data-list-table tbody td:not(:last-child) {
overflow: hidden;
text-overflow: ellipsis;
}
#employee-data-list-table tbody td:last-child {
overflow: visible;
text-overflow: clip;
}
#employee-data-list-table tbody td {
padding: 5px 11px !important;
font-size: 13px;
line-height: 1.25;
}
#employee-data-list-table thead th {
padding: 5px 2.35rem 5px 11px !important;
font-size: 13px;
line-height: 1.25;
}
#employee-data-list-table_wrapper table.dataTable thead .sorting:before,
#employee-data-list-table_wrapper table.dataTable thead .sorting:after,
#employee-data-list-table_wrapper table.dataTable thead .sorting_asc:before,
#employee-data-list-table_wrapper table.dataTable thead .sorting_asc:after,
#employee-data-list-table_wrapper table.dataTable thead .sorting_desc:before,
#employee-data-list-table_wrapper table.dataTable thead .sorting_desc:after {
right: 0.55rem !important;
opacity: 1 !important;
}
</style>
<div class="row" id="client_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;">Employees</h4>
</div>
</div>
<div class="table-responsive">
<table data-custom-table-css="table" class="table table-hover m-0 table-centered nowrap w-100" cellspacing="0" id="employee-data-list-table">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">S.No&nbsp;</th>
<?php if (isset($getData)) {
if ($getData['client_id'] == '0' && $getData['policy_id'] == '0' && $getData['branch_id'] == '0' && ($getData['emp_code'] != "" || $getData['emp_name'] != "" || $getData['status'] != "")) { ?>
<th class="font-weight-medium">Client/Branch&nbsp;</th>
<?php }
if ($getData['client_id'] != '0' && $getData['branch_id'] == '0') { ?>
<th class="font-weight-medium">Branch&nbsp;</th>
<?php } } ?>
<th class="font-weight-medium">Name&nbsp;</th>
<th class="font-weight-medium">EMP Code&nbsp;</th>
<th class="font-weight-medium">Relationship&nbsp;</th>
<th class="font-weight-medium">Gender&nbsp;</th>
<th class="font-weight-medium">Email&nbsp;</th>
<th class="font-weight-medium">Mobile&nbsp;</th>
<th class="font-weight-medium">Date of Birth&nbsp;</th>
<th class="font-weight-medium">Policy name&nbsp;</th>
<th class="font-weight-medium">Insurer name&nbsp;</th>
<th class="font-weight-medium">TPA ID&nbsp;</th>
<th class="font-weight-medium">Risk ID&nbsp;</th>
<th class="font-weight-medium">Policy status&nbsp;</th>
<th class="font-weight-medium">(₹)Sum Insured&nbsp;</th>
<th class="font-weight-medium">(₹)Premium&nbsp;</th>
<th class="font-weight-medium" id="rata_premium" data-toggle="tooltip" data-placement="top">(₹)Pro Rata Premium&nbsp;</th>
<th class="font-weight-medium" id="gst" data-toggle="tooltip" data-placement="top">(₹)GST&nbsp;</th>
<th class="font-weight-medium" > Action &nbsp;</th>
</tr>
</thead>
<tbody class="font-12">
<?php
if (isset($employees)) {
$pro_rata_total = 0;
$gst_total = 0;
foreach ($employees as $key => $employee) { ?>
<tr>
<td><b><?php echo ($key + 1); ?></b></td>
<?php if (isset($getData)) {
if ($getData['client_id'] == '0' && $getData['policy_id'] == '0' && $getData['branch_id'] == '0' && ($getData['emp_code'] != "" || $getData['emp_name'] != "" || $getData['status'] != "")) { ?>
<td><?php echo $employee['client_short_name'] . ' - ' . $employee['client_branch_name']; ?></td>
<?php }
if ($getData['client_id'] != '0' && $getData['branch_id'] == '0') { ?>
<td><?php echo $employee['client_branch_name']; ?></td>
<?php } } ?>
<td><?php echo $employee['name']; ?></td>
<td><?php echo $employee['emp_code']; ?></td>
<td><?php echo $employee['relationship']; ?></td>
<td><?php echo $employee['gender']; ?></td>
<td><?php echo $employee['email_corporate']; ?></td>
<td><?php echo $employee['mobile']; ?></td>
<td><?php echo date('d/m/Y', strtotime($employee['dob'])); ?></td>
<td><?php echo isset($employee['policy_type']) ? $employee['policy_type'] : ''; ?> - <?php echo isset($employee['policy_no']) ? $employee['policy_no'] : ''; ?></td>
<td><?php echo $employee['insurer_short_name']; ?></td>
<td><?php echo $employee['tpa_id']; ?></td>
<td><?php echo $employee['uhid']; ?></td>
<td>
<?php
switch ($employee['status']) {
case 'draft':
echo '<span class="badge badge-secondary">' . ucfirst($employee['status']) . '</span>';
break;
case 'active':
echo '<span class="badge badge-success">' . ucfirst($employee['status']) . '</span>';
break;
case 'inactive':
echo '<span class="badge badge-warning">' . ucfirst($employee['status']) . '</span>';
break;
case 'expired':
echo '<span class="badge badge-danger">' . ucfirst($employee['status']) . '</span>';
break;
case 'enrolled':
echo '<span class="badge2 badge2-secondary2">' . ucfirst($employee['status']) . '</span>';
break;
default:
echo $employee['status'];
break;
}
?>
</td>
<td><?php echo format_indian_number($employee['basic_cover_si']); ?></td>
<td><?php echo format_indian_number($employee['premium']); ?></td>
<td><?php $pro_rata_total += $employee['rata_premimum']; echo format_indian_number($employee['rata_premimum']); ?></td>
<td><?php $gst_total += $employee['gst']; echo format_indian_number($employee['gst']); ?></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">
<?php
if
(
(in_array($employee['emp_status'], ['draft', 'enrolled', 'active']) && in_array($employee['status'], ['draft', 'enrolled', 'active']))
) {
?>
<a class="dropdown-item" onclick="get_emp_master_data_for_update(this, '<?= $employee['employee_id'];?>', '<?= $employee['status'];?>')" ><i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a class="dropdown-item" onclick="get_emp_history(this, '<?= $employee['employee_id'];?>')" > <i class="mdi mdi-history mr-2 text-muted font-18 vertical-middle"></i>Employee History</a>
<?php } ?>
<?php if(in_array($employee['policy_type_id'], [2,3,4,5]) && in_array($employee['emp_status'], ['active', 'expired']) && in_array($employee['status'], ['active', 'expired']) && !empty($employee['tpa_id'])) { ?>
<!-- <a href="<?= base_url('download-e-card/'). $employee['rand_string'] . "/0/1" ?>" class="dropdown-item" target="_blank"><i class="mdi mdi-eye mr-2 text-muted font-18 vertical-middle"></i>View E-Card</a> -->
<a class="dropdown-item" onclick="viewEcard(<?= $employee['employee_id'] ?>, '<?= $employee['emp_code'] ?>', <?= $employee['client_policy_id'] ?>, '<?= $employee['policy_no'] ?>')"><i class="mdi mdi-eye mr-2 text-muted font-18 vertical-middle"></i>View E-Card</a>
<?php } ?>
<?php if($employee['relationship'] == 'Self' && in_array($employee['policy_type_id'], [2,3,4,5]) && $employee['email_corporate'] != '' && in_array($employee['emp_status'], ['active', 'expired']) && in_array($employee['status'], ['active', 'expired']) && !empty($employee['tpa_id'])) { ?>
<a class="dropdown-item" onclick="send_mail_for_individual_employee_ecard('<?= $employee['id'];?>', '<?= $employee['client_policy_id'];?>')" ><i class="mdi mdi-email-alert mr-2 text-muted font-18 vertical-middle"></i>Send E-Card Mail</a>
<?php } ?>
<?php if($employee['relationship'] == 'Self' && in_array($employee['policy_type_id'], [2,3,4,5]) && in_array($employee['emp_status'], ['active', 'expired']) && in_array($employee['status'], ['active', 'expired']) && !empty($employee['tpa_id'])) { ?>
<a class="dropdown-item" onclick="showReGenerateConfirmation('<?= $employee['client_policy_id'];?>', '<?= $employee['emp_code'];?>')" ><i class="mdi mdi-refresh mr-2 text-muted font-18 vertical-middle"></i>Re-Generate E-Card</a>
<?php } ?>
<?php if($employee['is_addon'] == 3 && $employee['policy_type_id'] == 3 && in_array($employee['emp_status'], ['active', 'expired']) && in_array($employee['status'], ['active', 'expired']) && !empty($employee['tpa_id'])) { ?>
<a class="dropdown-item" onclick="showReGenerateConfirmation('<?= $employee['client_policy_id'];?>', '<?= $employee['emp_code'];?>')" ><i class="mdi mdi-refresh mr-2 text-muted font-18 vertical-middle"></i>Re-Generate E-Card</a>
<?php } ?>
</div>
</div>
</td>
</tr>
<?php } } ?>
</tbody>
<tfoot>
<tr>
<?php for ($i = 0; $i < $emp_col_count; $i++) : ?>
<?php if ($i === ($emp_col_count - 4)) : ?>
<th>Total</th>
<?php elseif ($i === ($emp_col_count - 3)) : ?>
<th><?php echo format_indian_number($pro_rata_total); ?></th>
<?php elseif ($i === ($emp_col_count - 2)) : ?>
<th><?php echo format_indian_number($gst_total); ?></th>
<?php else : ?>
<th></th>
<?php endif; ?>
<?php endfor; ?>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div><!-- end col -->
</div>
<!-- modal content -->
<div id="emp_modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Edit Employee</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body p-4">
<form role="form" class="parsley-examples" id="empForm" onsubmit="update_emp_master_data_submit_function(event, this)" enctype="multipart/form-data">
<input type="hidden" name="employee_primary_id" id="employee_primary_id"/>
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label for="emp_code">Employee Code<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="emp_code_for_edit" placeholder="Enter Code" readonly>
</div>
<div class="form-group col-md-8">
<label for="name">Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="name" id="name" placeholder="Ente Name">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="gender">Gender <span class="text-danger">*</span></label>
<select class="form-control" id="gender" name="gender" required disabled>
<option value="">Select Gender</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</div>
<div class="form-group col-md-6">
<label for="dob">Date of Birth<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="dob" placeholder="Enter DOB" name="dob" required>
</div>
<div class="form-group col-md-12">
<label for="email">Email<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="email_corporate" placeholder="Enter Email" name="email_corporate" data-parsley-trigger="change" data-parsley-type="email" onkeyup="validateInput(this, 'employees', 'email_corporate')" required>
</div>
<div class="form-group col-md-12">
<label for="mobile">Mobile Number<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="mobile" placeholder="Enter Mobile Number" name="mobile" onkeypress = "return onlyNumbers(event)" maxlength="10" minlength="10" onkeyup="validateInput(this, 'employees', 'mobile')" required>
</div>
</div>
</div>
<div class="form-group text-right m-b-0">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="btnSubmit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div><!-- /.modal -->
<!-- Modal content for Emp History -->
<div class="modal fade" id="emp_history_modal" tabindex="-1" aria-labelledby="emp_history_modal_label" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="emp_history_modal_label">Employee History</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div id = "emp_history_content"></div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
var dob = flatpickr("#dob", {
dateFormat: "d/m/Y",
allowInput: false, // Allows manual input
yearSelector: true, // Ensures year can be selected manually
});
})
$(document).ready(function() {
var ticketsTable = $('#employee-data-list-table');
if (ticketsTable.length) {
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 });
var nhEmpDataTable = ticketsTable.DataTable({
dom: "<'row'<'col-sm-6'f><'col-sm-6 text-right'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]],
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.nhEmpHScroll').on('scroll.nhEmpHScroll', function () {
$head.scrollLeft($(this).scrollLeft());
});
$head.off('scroll.nhEmpHScroll').on('scroll.nhEmpHScroll', function () {
$body.scrollLeft($(this).scrollLeft());
});
}
},
buttons: [
{
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: 'Members',
},
{
extend: 'excel',
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
className: 'app-btn-primary ',
title: 'Members',
sheetName: 'Members'
}
]
}
],
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>'
},
paging: true,
pageLength: 25,
autoWidth: false,
responsive: false,
columnDefs: [
<?php for ($i = 0; $i < $emp_col_count; $i++) : ?>
{ targets: <?= $i ?>, width: '<?= (int) $emp_col_width_px[$i] ?>px' },
<?php endfor; ?>
],
});
$.extend($.fn.dataTable.defaults, _dtDefScroll);
nhEmpDataTable.on('draw.dt', function () {
nhEmpDataTable.columns.adjust();
});
$(window).on('resize', function () {
nhEmpDataTable.columns.adjust();
});
setTimeout(function () {
nhEmpDataTable.columns.adjust();
}, 0);
} else {
console.error("Table not found.");
}
});
function get_emp_master_data_for_update(input, id){
get_emp_master_data_for_update_ajax(id)
}
function get_emp_master_data_for_update_ajax(id){
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: '<?php echo base_url('util/get_emp_master_data_for_update/');?>'+id,
type: "GET",
dataType: 'json',
success: function (res) {
console.log('get_emp_master_data_for_update response', res)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
let data = res.data
if(res.status == true){
if(data.relationship == 'Self'){
$('#gender').prop('disabled', false)
}else{
$('#gender').prop('disabled', true)
}
$('#employee_primary_id').val(data.id);
$('#emp_code_for_edit').val(data.emp_code);
$('#name').val(data.name);
$('#gender').val(data.gender);
$('#dob').val(data.formatted_dob);
$('#email_corporate').val(data.email_corporate);
$('#mobile').val(data.mobile);
if(data.emp_status == "active"){
$('#name').prop('disabled', true);
$('#gender').prop('disabled', true);
$('#dob').prop('disabled', true);
}else{
$('#name').prop('disabled', false);
$('#gender').prop('disabled', false);
$('#dob').prop('disabled', false);
}
var myModal = new bootstrap.Modal(document.getElementById('emp_modal'));
myModal.show();
}else{
$('#employee_primary_id').val('');
$('#emp_code_for_edit').val('');
$('#name').val('');
$('#gender').val('');
$('#dob').val('');
$('#email_corporate').val('');
$('#mobile').val('');
$('#name').prop('disabled', false);
$('#gender').prop('disabled', false);
$('#dob').prop('disabled', false);
toastr.warning(res.message, 'Warning');
}
},
error: function (xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.error(xhr.responseText);
console.error(status, error);
}
});
}
function update_emp_master_data_submit_function(event, form){
event.preventDefault(); // Prevent the default form submission
var isValid = $(form).parsley().validate();
if (!isValid) {
console.log('Form is Empty', 'Warning');
return ;
}
const formData = new FormData(form);
const submitButton = form.querySelector('button[type="submit"]');
submitButton.disabled = true;
submitButton.innerText = 'Updating...';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
// AJAX request to update the individual employee
$.ajax({
url: '<?= base_url('/util/update_emp_data') ?>',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
console.log(response)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if(response.status == true){
toastr.success(response.message, 'Success');
$('.close').click();
$('#employee_primary_id').val('');
$('#emp_code_for_edit').val('');
$('#name').val('');
$('#gender').val('');
$('#dob').val('');
$('#email_corporate').val('');
$('#mobile').val('');
// window.location.reload();
fetchEmpolyeeList();
}else{
toastr.error(response.message, 'Error');
}
},
error: function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
// Handle error
console.error('Upload error occurred:');
console.error('Status: ', status); // Status of the request
console.error('Error: ', error); // Specific error message
console.error('XHR Object: ', xhr); // Full XHR object with response details
// Optionally log server response, if available
if (xhr.responseText) {
console.error('Response Text: ', xhr.responseText);
}
if (xhr.status === 400) {
let response = JSON.parse(xhr.responseText);
let errorMessages = "";
let seenMessages = []; // Array to store unique messages
if (response.errors) {
$.each(response.errors, function (field, message) {
if (!seenMessages.includes(message)) {
errorMessages += `• ${message}<br>`;
seenMessages.push(message); // Mark this message as "seen"
}
});
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
} else {
toastr.warning(response.message || 'Validation failed', 'Warning');
}
} else if (xhr.status === 403) {
let response = JSON.parse(xhr.responseText);
toastr.error(response.message, 'Security Policy');
} else if (xhr.status === 500) {
toastr.error('Something went wrong . Please try again later.', 'Server Error');
}
else{ toastr.warning('Error uploading file', 'Warning'); }
},
complete: function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
// Re-enable the submit button and reset its text
submitButton.disabled = false;
submitButton.innerText = 'Submit';
}
});
}
function send_mail_for_individual_employee_ecard(id, client_policy_id){
Swal.fire({
title: "Do you want to send Ecard Mail?",
showDenyButton: true,
showCancelButton: false,
confirmButtonText: "Yes,Send",
denyButtonText: "Don't Send"
}).then((result) => {
if (result.isConfirmed) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: '<?php echo base_url('util/send_mail_for_individual_employee_ecard/');?>'+id + '/' + client_policy_id,
type: "GET",
dataType: 'json',
success: function (res) {
console.log('send_mail_for_individual_employee_ecard response', res)
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if(res.status == true){
toastr.success(res.message, 'Success');
}else{
toastr.error(res.message, 'Error');
}
},
error: function (xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.error(xhr.responseText);
console.error(status, error);
}
});
}
});
}
function validateInput(input, table, field) {
let emp_code = $('#emp_code_for_edit').val();
let client_id = $('#clients').val();
console.log("emp_code", emp_code);
console.log("client_id", client_id);
let value = $(input).val();
let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim();
let message = "Value is duplicate!";
if (label) {
message = label + " already exists!";
}
let data = {};
data["emp_code !="] = emp_code;
data[field] = value;
console.log(data);
checkDuplicateTableFieldValue(table, field, data, function(isDuplicate) {
if (isDuplicate) {
toastr.warning(message, 'Warning');
$("#btnSubmit").prop('disabled', true);
}else{
$("#btnSubmit").prop('disabled', false);
}
});
}
function onlyNumbers(event) {
var charcode;
charcode = event.which || event.keyCode;
if (charcode >= 48 && charcode <= 57 || charcode == 46) return true;
return false;
}
var modalInstance; // Store the modal instance globally
function showModal() {
var myModalEl = document.getElementById('emp_history_modal');
modalInstance = new bootstrap.Modal(myModalEl, {
backdrop: true, // Ensures the backdrop is shown
keyboard: true // Allows closing with the Escape key
});
modalInstance.show();
}
function closeModal() {
if (modalInstance) {
modalInstance.hide(); // Hide the modal and its backdrop
// Manually remove backdrop if it's still visible
setTimeout(function () {
document.querySelector('.modal-backdrop').classList.remove('show');
}, 150); // Wait for animation to finish
}
}
function get_emp_history(input, emp_id) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
let url = '<?= base_url("employee/get_emp_history")?>';
let requestData = { emp_id: emp_id };
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (response.status === true) {
console.log('response data length', response.data.emp_history.length);
// **Clear old data**
$('#emp_history_content').html('');
// **Check if data exists**
if (response.data.emp_history.length > 0) {
let historyTable = `
<div class="card-body">
<div class="table-responsive">
<table data-custom-table-css="table" class="table w-100">
<thead class="bg-light">
<tr>
<th>Field</th>
<th>Change</th>
<th>User</th>
<th>Date/Time</th>
</tr>
</thead>
<tbody>
`;
// **Loop through the data dynamically**
response.data.emp_history.forEach(row => {
historyTable += `
<tr>
<td>${row.field_name}</td>
<td>${row.old_value} => ${row.new_value}</td>
<td>${row.created_by}</td>
<td>${row.created_at}</td>
</tr>
`;
});
historyTable += `
</tbody>
</table>
</div>
</div>
`;
// **Append to modal**
$('#emp_history_content').append(historyTable);
} else {
$('#emp_history_content').html('<p class="text-center text-muted">No history available.</p>');
}
// **Show the modal**
showModal();
} else {
let message = response.message;
toastr.error(message, 'Error');
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
toastr.error('An error occurred while fetching the report page.', 'Error');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
});
}
function viewEcard(emp_id, emp_code, policy_id, policy_no){
console.log({emp_id, emp_code, policy_id, policy_no});
let url_type = 'view';
let url = '<?= base_url('ecardRequest') ?>';
// Data to send in the AJAX request
let requestData = {
id: emp_id,
emp_code: emp_code,
client_policy_id: policy_id,
policy_no: policy_no,
type: url_type,
};
// Convert to JSON
let jsonData = JSON.stringify(requestData);
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
// Send AJAX request
sendAjaxRequestForGlobal(url, 'POST', jsonData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status == true && response.data.eCardDownload) {
console.log(response.data.message || 'Initiating successfully', 'Success');
const newTab = window.open(response.data.eCardDownload, '_blank');
if (newTab) newTab.focus();
} else {
toastr.error(response.data.message || 'Unable to fetch e-card', 'Error');
}
$('.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 CD amount.', 'Error');
});
}
function showReGenerateConfirmation(client_policy_id, emp_code){
Swal.fire({
title: "Do you want to Re-Generate Ecard for this family?",
showDenyButton: true,
showCancelButton: false,
confirmButtonText: "Yes",
denyButtonText: "No"
}).then((result) => {
if (result.isConfirmed) {
reGenerateEcardForSingleFamily(client_policy_id, emp_code)
}
});
}
function reGenerateEcardForSingleFamily(client_policy_id, emp_code)
{
if(!client_policy_id){
toastr.warning('Failed to re-Generate E-card', 'Warning');
}
if(!emp_code){
toastr.warning('Failed to re-Generate E-card', 'Warning');
}
console.log({client_policy_id, emp_code});
let url = '<?= base_url('/employee/bulkGenerateEcardAndStoreinS3') ?>';
// Data to send in the AJAX request
let requestData = {
client_policy_id: client_policy_id,
emp_code: emp_code,
};
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
// Send AJAX request
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.dataStatus == true) {
toastr.success(response.message || 'Initiating successfully.', 'Success');
} else {
toastr.warning(response.status || 'Unable to regenerate e-card.', '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('Unable to regenerate e-card.', 'Error');
});
}
$('#employee-data-list-table tbody').on('click', 'td', function () {
const colIndex = this.cellIndex;
const rowIndex = this.parentElement.rowIndex - 1; // minus header
console.log('Row:', rowIndex, 'Column:', colIndex);
init();
});
</script>