diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 2e14ab2e..9d214746 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -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'); \ No newline at end of file +$routes->get('testTracelog','TestBusinessController::a'); +$routes->get("claimView", "EmployeeRestController::claimView"); diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 8d9071a4..e9440c1b 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -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; } + + } \ No newline at end of file diff --git a/app/Views/client_onboarding.php b/app/Views/client_onboarding.php index 26966afb..8e858801 100755 --- a/app/Views/client_onboarding.php +++ b/app/Views/client_onboarding.php @@ -552,22 +552,32 @@ body { function getHrActivityHistory() { console.log(event.target.dataset.id);//return; - let url = '' + 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 = '' + event.target.dataset.id.split('-')[0] + '&pre_hr_id=' + event.target.dataset.id.split('-')[1]; + let url = ''; 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); }); } diff --git a/app/Views/hr_access_controll.php b/app/Views/hr_access_controll.php index c9b64ae4..06a89347 100644 --- a/app/Views/hr_access_controll.php +++ b/app/Views/hr_access_controll.php @@ -18,8 +18,9 @@
-
-
+
+ +