FEAT_EMP_HISTORY_SRI

This commit is contained in:
Srinivas-Saravanan 2025-02-15 17:49:38 +05:30
parent c388877b3f
commit 392362fb0d
3 changed files with 153 additions and 0 deletions

View File

@ -161,6 +161,7 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) {
$routes->get("test-rack-rate", "EmployeeController::testRackRate");
$routes->post("test-rack-rate", "EmployeeController::testRackRate");
$routes->get('test_members_list', 'EmployeeController::test_members_list');
$routes->post('get_emp_history','EmployeeController::getEmpHistory');
});
$routes->group("/master", ["filter" => "authMVC"], function ($routes) {

View File

@ -25,6 +25,7 @@ use App\Models\InsurerExcelExportTemplateModel;
use App\Models\InsurerModel;
use App\Models\ClientDepositModel;
use App\Models\PolicyPremium2Model;
use App\Models\AuditHistoryModel;
use App\Controllers\Jobs;
@ -64,6 +65,7 @@ class EmployeeController extends AdminController
protected $insurerModel;
protected $cashDepositModel;
protected $PolicyPremium2Model;
protected $auditHistory;
public function __construct()
{
@ -84,6 +86,7 @@ class EmployeeController extends AdminController
$this->insurerModel = new InsurerModel();
$this->cashDepositModel = new ClientDepositModel();
$this->PolicyPremium2Model = new PolicyPremium2Model();
$this->auditHistory = new AuditHistoryModel();
}
public function list()
@ -2725,4 +2728,18 @@ class EmployeeController extends AdminController
}
}
public function getEmpHistory(){
$emp_id = $this->request->getPost('emp_id');
$data['emp_history'] = $this->auditHistory->select('field_name,old_value,new_value,created_by,created_at')->where('pk',$emp_id)->where('table_name','employees')->findAll();
$emp_pol_pk = $this->employeePolicyModel->select('id')->where('employee_id',$emp_id)->first()['id'];
$data['emp_pol_history'] = $this->auditHistory->select('field_name,old_value,new_value,created_by,created_at')->where('pk',$emp_pol_pk)->where('table_name','employee_polices')->findAll();
return $this->respond(['status' => true, 'data' => $data],200);
}
}

View File

@ -46,6 +46,38 @@
</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);
}
</style>
<?php $pro_rata_total = 0; $gst_total = 0 ?>
<div class="row" id="client_list">
@ -154,6 +186,8 @@
) {
?>
<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]) && $employee['emp_status'] == 'active' && $employee['status'] == 'active' && !empty($employee['tpa_id'])) { ?>
@ -270,6 +304,20 @@
</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="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div id = "emp_history_content"></div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
@ -543,5 +591,92 @@
if (charcode >= 48 && charcode <= 57 || charcode == 46) return true;
return false;
}
function showModal() {
var myModal = new bootstrap.Modal(document.getElementById('emp_history_modal'));
myModal.show();
}
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 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 closeModal(){
var myModalEl = document.getElementById('emp_history_modal');
var modalInstance = bootstrap.Modal.getInstance(myModalEl);
if (modalInstance) {
modalInstance.hide();
}
}
</script>