diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f8bed9c..cbb5b40 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -144,6 +144,7 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->group("others", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "ClientController::createOtherTabContent"); + $routes->post('check-duplicate', 'ClientController::validateDuplicateByClientBranch'); }); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 9c0edf4..d2eb167 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -151,6 +151,16 @@ class ClientController extends AdminController return $this->response->setJSON(['isDuplicate' => $isDuplicate]); } + public function validateDuplicateByClientBranch() + { + $value = $this->request->getPost('value'); + $clientId = $this->request->getPost('client_id'); + $branchId = $this->request->getPost('branch_id'); + $field = $this->request->getPost('field'); + $isDuplicate = $this->clientModel->isDuplicateByClientBranch($value, $field, $clientId, $branchId); + return $this->response->setJSON(['isDuplicate' => $isDuplicate]); + } + public function smapletest() { $headers = [ diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index feca6fd..564fc92 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -761,36 +761,45 @@ class EmployeeController extends AdminController } - public function empby_client_clientbranch($client_id, $branch_id) - { - - $results = $this->clientModel->select('employees.id as employee_id, employees.name as employee_name, - employees.relationship, employees.emp_code, - employees.emp_status, auth_history.user_type') - ->join('employees', $client_id .'= employees.client_id AND ' . $branch_id . '= employees.client_branch_id', 'left') - ->join('auth_history', 'employees.id = auth_history.user_id AND "employee" = auth_history.user_type', 'left') - ->where('employees.is_active', 1) - ->where('employees.emp_status !=', 'truncated') - ->groupBy('employees.id') - ->findAll(); - + public function empby_client_clientbranch($client_id, $branch_id, $client_policy_id) + { + + $results = $this->clientModel->select(' + employees.id as employee_id, + employees.name as employee_name, + employees.relationship, + employees.emp_code, + employees.emp_status, + auth_history.user_type + ') + ->join('employees', $client_id . '= employees.client_id AND ' . $branch_id . '= employees.client_branch_id', 'left') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->join('auth_history', 'employees.id = auth_history.user_id AND "employee" = auth_history.user_type', 'left') + ->where('employees.is_active', 1) + ->where('employees.emp_status !=', 'truncated') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.is_active', 1) + ->where('employee_polices.status !=', 'truncated') + ->groupBy('employees.id') + ->findAll(); + $groupedData = []; $employeeId = ''; foreach ($results as $row) { - if($employeeId != $row['employee_id']){ + if ($employeeId != $row['employee_id']) { $employeeId = $row['employee_id']; - }else{ + } else { $employeeId = null; } - $employeeName = $row['employee_name'] ; - $employeeRelationship = $row['relationship'] ; - $employeeEmpCode = $row['emp_code'] ; + $employeeName = $row['employee_name']; + $employeeRelationship = $row['relationship']; + $employeeEmpCode = $row['emp_code']; $employeeEmpStatus = $row['emp_status']; $employeeUserType = $row['user_type']; - - + + // if ($employeeId !== null && $employeeRelationship == 'Self') { if ($employeeId !== null) { // Append employee info to the branch's employees list @@ -802,16 +811,16 @@ class EmployeeController extends AdminController 'emp_status' => $employeeEmpStatus, 'user_type' => $employeeUserType ]; - } $employeeId = $row['employee_id']; } - - - return json_encode($groupedData); - } - + // print_r($groupedData); die; + + return json_encode($groupedData); + } + + /** diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 9bab925..904f54a 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1774,53 +1774,28 @@ class EmployeeRestController extends AdminController public function getClientDetails() { - log_message('error', 'STEP 1: getClientDetails called'); - try { - // STEP 2: Extract Authorization header - $jwt = $this->request->getHeaderLine('Authorization'); - log_message('error', 'STEP 2: Authorization header: ' . $jwt); + $pre_client_id = $this->request->getGet('pre_client_id'); + $pre_branch_id = $this->request->getGet('pre_branch_id'); + $post_client_id = $this->request->getGet('post_client_id'); + $post_branch_id = $this->request->getGet('post_branch_id'); + - $jwtParts = explode(' ', $jwt); - if (count($jwtParts) < 2) { - log_message('error', 'STEP 2.1: Invalid Authorization header format'); - return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'Invalid Authorization header'], 400); - } + if ($pre_client_id != null) { + - $token = $jwtParts[1]; - log_message('error', 'STEP 3: Extracted JWT token'); - - $tokenParts = explode('.', $token); - if (count($tokenParts) !== 3) { - log_message('error', 'STEP 3.1: Invalid JWT structure'); - return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'Invalid JWT token'], 400); - } - - $decodedPayload = json_decode(base64_decode($tokenParts[1]), true); - log_message('error', 'STEP 4: Decoded JWT payload: ' . json_encode($decodedPayload)); - - $token_type = $decodedPayload['token_type'] ?? null; - log_message('error', 'STEP 5: Token type = ' . $token_type); - - $client_id = $this->request->getGet('client_id'); - $client_branch_id = $this->request->getGet('client_branch_id'); - log_message('error', 'STEP 6: Query params - client_id: ' . $client_id . ', client_branch_id: ' . $client_branch_id); - - if ($token_type === 'pre') { - log_message('error', 'STEP 7: Handling "pre" token type'); - - $client = $this->clientModel->where('id', $client_id)->first(); + $client = $this->clientModel->where('id', $pre_client_id)->first(); if ($client) { - log_message('error', 'STEP 8: Found client: ' . json_encode($client)); + $client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo']; $clientPolicy = $this->clientPolicyModel - ->where('client_id', $client_id) - ->where('client_branch_id', $client_branch_id) + ->where('client_id', $pre_client_id) + ->where('client_branch_id', $pre_branch_id) ->findAll(); - log_message('error', 'STEP 9: Found client policy count: ' . count($clientPolicy)); + return $this->respond([ 'status' => 'success', @@ -1831,33 +1806,34 @@ class EmployeeRestController extends AdminController ] ], 200); } else { - log_message('error', 'STEP 10: No client found for client_id: ' . $client_id); + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404); } - } elseif ($token_type === 'post') { - log_message('error', 'STEP 11: Handling "post" token type'); + } elseif ($post_client_id != null) { + $restAuthController = new RestAuthenticationController; $queryParams = [ - 'client_id' => $client_id, - 'client_branch_id' => $client_branch_id + 'client_id' => $post_client_id, + 'client_branch_id' => $post_branch_id ]; - log_message('error', 'STEP 12: Calling post enrollment API with params: ' . json_encode($queryParams)); + return $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails'); - return $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails', ['token' => $jwt]); } else { - log_message('error', 'STEP 13: Unknown token_type: ' . $token_type); + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404); } } catch (\Exception $e) { - log_message('error', 'STEP 14: Exception occurred - ' . $e->getMessage()); + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500); } } + + public function getSiMappedArray($policy_id,$base_policy_id) { $selfGMC = $this->employeeModel->select('employees.name , employee_polices.basic_cover_si') diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index cdd35ad..89c77d6 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -214,5 +214,19 @@ class ClientModel extends Model return $result; } + public function isDuplicateByClientBranch($value, $field, $clientId, $branchId) + { + $builder = $this->db->table('level_contacts lc') + ->select('lc.id') + ->join('client_branch cb', 'lc.ref_id = cb.id', 'left') + ->where('lc.'.$field, $value) + ->where('lc.contact_type', 'client') + ->where('cb.client_id', $clientId) + ->where('lc.ref_id', $branchId) + ->get(); + + return $builder->getNumRows() > 0 ? true : false; + } + } diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index 1e4ee40..fc524c9 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -207,12 +207,12 @@