FIX_ONBORDING RV

This commit is contained in:
VENKATESHWARAN 2025-07-15 17:02:09 +05:30
parent 4c95db69ea
commit 90c53d8b02
4 changed files with 137 additions and 23 deletions

View File

@ -584,6 +584,7 @@ $routes->group("/ticket", ["filter" => "authMVC"], function ($routes) {
$routes->post('getPolicyStartDate','TicketController::getPolicyStartDate');
$routes->post("getPoliciesbyEmpID","TicketController::getPoliciesbyEmpID");
$routes->post("getMoreInfo","TicketController::getMoreInfo");
$routes->get("getMoreInfo","TicketController::getMoreInfo");
// $routes->post('ticket_messages','TicketController::getTicketMessage');
});
@ -610,4 +611,5 @@ $routes->get('createEnrollmentBatch','ICICILombardController::createEnrollmentBa
$routes->get('getEnrollmentBatchStatus','ICICILombardController::getEnrollmentBatchStatus');
$routes->get('fetchUHIDDetails','ICICILombardController::fetchUHIDDetails');
$routes->get('testTracelog','TestBusinessController::a');
$routes->get('testTracelog','TestBusinessController::a');
$routes->get("claimView", "EmployeeRestController::claimView");

View File

@ -6,6 +6,7 @@ use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use CodeIgniter\API\ResponseTrait;
use App\Models\UserModel;
@ -18,7 +19,9 @@ use App\Models\UserActivityHistoryModel;
class UserController extends AdminController
{
{
use ResponseTrait;
protected $myLogger;
protected $userModel;
protected $roleModel;
@ -264,23 +267,121 @@ class UserController extends AdminController
}
// public function getUserActivityHistory()
// {
// $user_id = $this->request->getVar('user_id');
// $pre_hr_id = $this->request->getVar('pre_hr_id');
// $user_type = $this->request->getVar('user_type');
// // echo $user_id.' - '.$pre_hr_id;
// $field_for_where_condition = 'user_id';
// if($user_id == 0 || $user_id == NULL)
// {
// $field_for_where_condition = 'pre_hr_id';
// $user_id = $pre_hr_id;
// }
// if($field_for_where_condition == "pre_hr_id"){
// //get login history
// $auth_data = $this->authHistoryModel->where('is_active', 1)->where('user_id',$user_id)->where('user_type', $user_type)->findAll();
// }else{
// $preDB = \Config\Database::connect('preDB');
// $auth_data = $preDB->table('auth_history')->where('is_active', 1)->where('user_id',$user_id)->where('user_type', $user_type)->get()->getResultArray();
// }
// //get activity history
// $activity_data = $this->userActivityHistoryModel->where($field_for_where_condition,$user_id)->where('user_type', $user_type)->findAll();
// }
public function getUserActivityHistory()
{
$user_id = $this->request->getVar('user_id');
$pre_hr_id = $this->request->getVar('pre_hr_id');
// echo $user_id.' - '.$pre_hr_id;
$field_for_where_condition = 'user_id';
if($user_id == 0 || $user_id == NULL)
{
$field_for_where_condition = 'pre_hr_id';
$user_id = $pre_hr_id;
try {
$user_id = $this->request->getVar('user_id');
$pre_hr_id = $this->request->getVar('pre_hr_id');
$user_type = $this->request->getVar('user_type');
if (empty($user_type)) {
return $this->respond(['status' => false,'message' => 'User type is required'], 400);
}
$field_for_where_condition = 'user_id';
if (empty($user_id) || $user_id == 0) {
if (empty($pre_hr_id)) {
return $this->respond(['status' => false,'message' => 'user_id or pre_hr_id must be provided'], 400);
}
$field_for_where_condition = 'pre_hr_id';
$user_id = $pre_hr_id;
}
// Get login/auth history
if ($field_for_where_condition == 'pre_hr_id') {
$auth_data = $this->authHistoryModel
->where('is_active', 1)
->where('user_id', $user_id)
->where('user_type', $user_type)
->orderBy('created_at', 'desc')
->findAll();
} else {
$preDB = \Config\Database::connect('preDB');
$auth_data = $preDB->table('auth_history')
->where('is_active', 1)
->where('user_id', $user_id)
->where('user_type', $user_type)
->orderBy('created_at', 'desc')
->get()
->getResultArray();
}
// Get activity history
$activity_data = $this->userActivityHistoryModel
->where($field_for_where_condition, $user_id)
->where('user_type', $user_type)
->findAll();
$merged_data = $this->getMergedUserHistory($auth_data, $activity_data);
return $this->respond([
'status' => true,
'message' => 'User history fetched successfully',
'auth_history' => $auth_data,
'activity_log' => $activity_data,
'merged_data' => $merged_data,
]);
} catch (\Exception $e) {
$this->myLogger->logme("error", ($e->getMessage().' --- '.$e->getLine() . '----' . $e->getTraceAsString()));
return $this->respond([
'status' => false,
'message' => 'Error: ' . $e->getMessage()
], 500);
}
}
public function getMergedUserHistory($auth_data, $activity_data)
{
// Tag each entry with its source
foreach ($auth_data as &$entry) {
$entry['source'] = 'auth';
}
//get login history
$auth_data = $this->authHistoryModel->where($field_for_where_condition,$user_id);
//get activity history
$activity_data = $this->userActivityHistoryModel->where();
foreach ($activity_data as &$entry) {
$entry['source'] = 'activity';
}
// Merge both arrays
$merged = array_merge($auth_data, $activity_data);
// Sort by 'created_at' descending
usort($merged, function ($a, $b) {
return strtotime($b['created_at']) <=> strtotime($a['created_at']);
});
return $merged;
}
}

View File

@ -552,22 +552,32 @@ body {
function getHrActivityHistory()
{
console.log(event.target.dataset.id);//return;
let url = '<?= base_url('user/getUserActivityHistory?user_id=') ?>' + event.target.dataset.id.split('-')[0] + '&pre_hr_id=' + event.target.dataset.id.split('-')[1];
let ids = event.target.dataset.id.split('-');
console.log('ids', ids)
// let url = '<?= base_url('user/getUserActivityHistory?user_id=') ?>' + event.target.dataset.id.split('-')[0] + '&pre_hr_id=' + event.target.dataset.id.split('-')[1];
let url = '<?= base_url('user/getUserActivityHistory') ?>';
console.log(url);
let user_type = "hr";
sendAjaxRequestForGlobal(url, 'GET', function(response) {
let requestData = {user_id : ids[0], pre_hr_id : ids[1], user_type : user_type};
console.log('requestData', requestData);
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status === true) {
$('#hr_access_append_area').empty();
$('#hr_access_append_area').append(response.data)
toastr.success(response.message, 'SUCCESS');
} else {
console.error(response.message, 'WARNING');
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
console.error('--- AJAX Error Details ---');
console.error('Status Code:', xhr.status);
console.error('Status Text:', xhr.statusText);
console.error('Response Text:', xhr.responseText);
console.error('XHR Object:', xhr);
console.error('jQuery Status:', status);
console.error('Thrown Error:', error);
});
}

View File

@ -18,8 +18,9 @@
<div class="card-header" onclick="toggleAccordion(this)">
<div class="user-info">
<h5 class="mb-0"><?= $value['hr_name'] ?> <i class="fa fa-info-circle" aria-hidden="true" data-id="<?= $value['pre_hr_id'].'-'.$value['post_hr_id'] ?>"></i>
</h5>
<h5 class="mb-0"><?= $value['hr_name'] ?>
<i class="fa fa-info-circle" aria-hidden="true" data-id="<?= (!empty($value['pre_hr_id']) ? $value['pre_hr_id'] : 0) . '-' . (!empty($value['post_hr_id']) ? $value['post_hr_id'] : 0) ?>"></i>
</h5>
<p class="user-email"><?= $value['hr_mail'] ?></p>
</div>
<div class="accordion-icon">