diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 86ec33ce..2a41fda8 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -124,6 +124,8 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->post("edit", "ClientController::editClientBranch"); $routes->get("list/(:any)", "ClientController::getSingleBranchDataById/$1"); $routes->get("remove/(:any)", "ClientController::removeClientBranch/$1"); + $routes->post("auto_fetch_branch","ClientController::auto_fetch_branch"); + $routes->post("auto_fetch_branch_details","ClientController::auto_fetch_branch_details"); }); $routes->group("relation", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 2260bfc8..34830575 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -143,9 +143,9 @@ class ClientController extends AdminController // Perform the query $builder = $db->table($table); - if(is_array($value)){ + if (is_array($value)) { $isDuplicate = $builder->where($value)->where('is_active', 1)->countAllResults() > 0; - }else{ + } else { $isDuplicate = $builder->where($field, $value)->where('is_active', 1)->countAllResults() > 0; } @@ -154,9 +154,9 @@ class ClientController extends AdminController } public function smapletest() - { + { $headers = [ - 'S.No', + 'S.No', 'NAME OF EMP/DEP', 'EMP ID', // 'EMP/DEP TYPE', @@ -177,13 +177,13 @@ class ClientController extends AdminController 'PRO RATA PREMIUM', 'GST', 'TOTAL AMOUNT' - ]; + ]; $filePath = generateExcelWithHeader($headers); - echo "Excel file created at: $filePath"; + echo "Excel file created at: $filePath"; } public function testMailAttachments($email = 'venkateshraman786@gmail.com') - { + { $message = '

Request for Quotation (RFQ)

Dear {{RECIPIENT_NAME}},

We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.

RFQ Details

Client name{{CLIENT_NAME}}
Coverage Type{{POLICY_LONG_NAME}}
Policy Start Date{{POLICY_START_DATE}}
Policy Duration{{DURATION}}
Please note: Additional terms and details are included in the attachment for your reference.

Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.

Best regards,

Nhance India Pvt Ltd

'; // $attachments = [ @@ -192,8 +192,8 @@ class ClientController extends AdminController // ["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"] // ]; $attachments = []; - $res = MailHelper::send_email(['mail' => $email, 'subject' => 'Mail Via Attachment Testing URL', 'message' => $message,'attachments' => $attachments]); - + $res = MailHelper::send_email(['mail' => $email, 'subject' => 'Mail Via Attachment Testing URL', 'message' => $message, 'attachments' => $attachments]); + print_rr($res); echo '------------------------------------------------------------------------------------------'; // print_rr($attachments); @@ -205,21 +205,20 @@ class ClientController extends AdminController // dd($client_id, $emp_code, $policy_id, $mail_active); - if(empty($policy_id)){ + if (empty($policy_id)) { $client_policy_ids = $this->employeeModel - ->select('employee_polices.client_policy_id') - ->join('employee_polices', 'employees.id = employee_polices.employee_id') - ->where('employees.client_id', $client_id ) - ->where('employees.emp_code', $emp_code ) - ->where('employee_polices.is_active', 1 ) - ->where('employees.is_active', 1 ) - ->findAll(); + ->select('employee_polices.client_policy_id') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.client_id', $client_id) + ->where('employees.emp_code', $emp_code) + ->where('employee_polices.is_active', 1) + ->where('employees.is_active', 1) + ->findAll(); $client_policy_ids2 = array_column($client_policy_ids, 'client_policy_id'); $client_policy_id = array_unique($client_policy_ids2); - - }else{ + } else { $client_policy_id = json_decode($policy_id, true); } @@ -233,39 +232,37 @@ class ClientController extends AdminController $mail_send_return1 = ''; $mail_send_return2 = ''; - if (!is_null($client_policy_id) && is_array($client_policy_id)) - { + if (!is_null($client_policy_id) && is_array($client_policy_id)) { - $empData = $this->employeeModel->where('emp_code', $emp_code )->where('client_id', $client_id ) ->where('is_active', 1 )->findAll(); + $empData = $this->employeeModel->where('emp_code', $emp_code)->where('client_id', $client_id)->where('is_active', 1)->findAll(); // dd($empData); $filteredEmpData = array_filter($empData, fn($item) => $item['relationship'] === 'Self'); // dd($filteredEmpData); $array_list = []; - foreach ($client_policy_id as $key => $value) - { - $find = $this->employeeModel->getEmpFamilybyEmpCode(client_policy_id: $value,emp_code: $emp_code,client_id: $client_id,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); - if(count($find) > 0){ + foreach ($client_policy_id as $key => $value) { + $find = $this->employeeModel->getEmpFamilybyEmpCode(client_policy_id: $value, emp_code: $emp_code, client_id: $client_id, emp_status: ['draft', 'enrolled'], policy_status: ['draft', 'enrolled']); + if (count($find) > 0) { $array_list[] = $find; } } // dd($array_list); - $notification = $this->notificationModel->where('client_id' ,$client_id)->where('template_name', 'member_review_and_summary_mail')->first(); + $notification = $this->notificationModel->where('client_id', $client_id)->where('template_name', 'member_review_and_summary_mail')->first(); if (isset($notification) && $notification['enabled'] == 1) { - $params ['array_list'] = $array_list; - $params ['client_policy_id'] = $client_policy_id; - $params ['emp_code'] = $emp_code; - $params ['client_id'] = $client_id; - $params ['notification'] = $notification; + $params['array_list'] = $array_list; + $params['client_policy_id'] = $client_policy_id; + $params['emp_code'] = $emp_code; + $params['client_id'] = $client_id; + $params['notification'] = $notification; $params['common'] = [ - 'client_id' => $filteredEmpData[0]['client_id'], - 'client_branch_id' => $filteredEmpData[0]['client_branch_id'], + 'client_id' => $filteredEmpData[0]['client_id'], + 'client_branch_id' => $filteredEmpData[0]['client_branch_id'], 'client_policy_id' => null, 'employee_policy_id' => null, 'employee_id' => $filteredEmpData[0]['id'], @@ -274,16 +271,16 @@ class ClientController extends AdminController // dd($params); - $wholeData =sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params); + $wholeData = sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params); // print_r($wholeData); die; - if($mail_active == 1){ + if ($mail_active == 1) { $mail_send_return = MailHelper::send_email($wholeData[0]); $this->myLogger->logme("error", $mail_send_return); } // if (isset($wholeData)) { - + // $params['common']['mail_type'] = 'account_maneger_summary_mail'; // $account_manager_wholeData =sendMailNotification::sendMailNotification('account_maneger_summary_mail', $params); // // print_r($account_manager_wholeData); die; @@ -322,12 +319,11 @@ class ClientController extends AdminController // } // } - }else{ + } else { $this->myLogger->logme("error", 'Member Review Mail Configuration not Enable for this client'); } - } - + print_r($wholeData); echo '
';
@@ -346,26 +342,25 @@ class ClientController extends AdminController
     {
         // dd($client_id, $emp_code, $policy_id, $mail_active);
 
-        if(empty($policy_id)){
+        if (empty($policy_id)) {
 
             $client_policy_ids = $this->employeeModel
-                                ->select('employee_polices.client_policy_id')
-                                ->join('employee_polices', 'employees.id = employee_polices.employee_id')
-                                ->where('employees.client_id', $client_id ) 
-                                ->where('employees.emp_code', $emp_code )
-                                ->where('employee_polices.is_active', 1 )
-                                ->where('employees.is_active', 1 )
-                                ->findAll();
+                ->select('employee_polices.client_policy_id')
+                ->join('employee_polices', 'employees.id = employee_polices.employee_id')
+                ->where('employees.client_id', $client_id)
+                ->where('employees.emp_code', $emp_code)
+                ->where('employee_polices.is_active', 1)
+                ->where('employees.is_active', 1)
+                ->findAll();
 
             $client_policy_ids2 = array_column($client_policy_ids, 'client_policy_id');
             $client_policy_id = array_unique($client_policy_ids2);
-
-        }else{
+        } else {
             $client_policy_id = json_decode($policy_id, true);
         }
 
         // dd($client_policy_id);
-    
+
         if (!is_null($client_policy_id) && is_array($client_policy_id)) {
 
             $empData = $this->employeeModel
@@ -373,9 +368,9 @@ class ClientController extends AdminController
                 ->where('client_id', $client_id)
                 ->where('is_active', 1)
                 ->findAll();
-    
+
             $filteredEmpData = array_filter($empData, fn($item) => $item['relationship'] === 'Self');
-    
+
             if (empty($filteredEmpData)) {
                 return $this->respond([
                     'status' => 'error',
@@ -383,7 +378,7 @@ class ClientController extends AdminController
                     'message' => 'No active employee data found for the given criteria.',
                 ], 404);
             }
-    
+
             $array_list = [];
             foreach ($client_policy_id as $value) {
                 $find = $this->employeeModel->getEmpFamilybyEmpCode(
@@ -393,17 +388,17 @@ class ClientController extends AdminController
                     emp_status: ['draft', 'enrolled'],
                     policy_status: ['draft', 'enrolled']
                 );
-    
+
                 if (count($find) > 0) {
                     $array_list[] = $find;
                 }
             }
-    
+
             $notification = $this->notificationModel
                 ->where('client_id', $client_id)
                 ->where('template_name', 'member_review_and_summary_mail')
                 ->first();
-    
+
             if ($notification && $notification['enabled'] == 1) {
 
                 $params = [
@@ -421,14 +416,14 @@ class ClientController extends AdminController
                         'mail_type' => 'member_review_and_summary_mail',
                     ],
                 ];
-    
+
                 $wholeData = sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params);
-    
+
                 if ($mail_active == 0) {
 
                     // $mail_send_result = [];
                     $mail_send_result = MailHelper::send_email($wholeData[0]);
-    
+
                     if ($mail_send_result['status'] === 'success') {
                         return $this->respond([
                             'status' => 'success',
@@ -445,7 +440,7 @@ class ClientController extends AdminController
                         ], 500);
                     }
                 }
-    
+
                 return $this->respond([
                     'status' => 'success',
                     'code' => 200,
@@ -453,21 +448,21 @@ class ClientController extends AdminController
                     'data' => $wholeData,
                 ], 200);
             }
-    
+
             return $this->respond([
                 'status' => 'error',
                 'code' => 400,
                 'message' => 'Member Review Mail configuration is not enabled for this client.',
             ], 400);
         }
-    
+
         return $this->respond([
             'status' => 'error',
             'code' => 404,
             'message' => 'No active client policy IDs found.',
         ], 404);
     }
-    
+
 
     //--------------------------------------------------------------------------------------------------------
 
@@ -623,20 +618,24 @@ class ClientController extends AdminController
 
         // dd($data['placeHolders']);
 
+        // auto fetch client list and branch list from pre
+        $data['auto_fetch_client_list'] =  $this->getClientListFromPre();
+
+
         echo view('layout/header', $headerData);
         echo view('client_onboarding', $data);
         echo view('layout/footer');
     }
 
     // In your controller
-    public function deposit($id = null , $requestFrom = null , $policyId = null)
+    public function deposit($id = null, $requestFrom = null, $policyId = null)
     {
         $headerData['tab_name'] = 'Client Deposit';
         $headerData['page_name'] = 'Clients';
-        
+
         $data['clientName'] = $this->clientModel->where('id', $id)->find();
-        $data['clientData'] = $this->clientPolicyModel->getinsurerswithclientid($id,$policyId);
-        
+        $data['clientData'] = $this->clientPolicyModel->getinsurerswithclientid($id, $policyId);
+
         $data['depositsummary'] = $this->clientPolicyModel->getDepositlistsummary($id);
 
         // Fetch associated insurer names and balances
@@ -644,14 +643,16 @@ class ClientController extends AdminController
         $data['balances'] = $balances;
 
         // dd($data);
-        if($requestFrom == 'rest'){ return $data; }
+        if ($requestFrom == 'rest') {
+            return $data;
+        }
 
         echo view('layout/header', $headerData);
         echo view('client_deposit_list', $data);
         echo view('layout/footer');
     }
 
-    public function view_Deposit($insurerId , $requestFrom = null , $param = null)
+    public function view_Deposit($insurerId, $requestFrom = null, $param = null)
     {
         // Load your model to fetch data based on $clientId and $insurerId
         // $subTypeOptions = [
@@ -677,23 +678,24 @@ class ClientController extends AdminController
         $headerData['page_name'] = 'Clients';
         $loggedInUserID = get_session_userid();
         // $data['clientData']= $this->clientPolicyModel->getinsurerswithinsurenceid($insurerId);
-        if($requestFrom == 'rest')
-        { 
+        if ($requestFrom == 'rest') {
             $clientId = $param['client_id'];
             $cd_ac_pk = $param['cd_ac_pk'];
-        }else{
+        } else {
             $clientId = $this->request->getGet('client_id');
             $cd_ac_pk = $this->request->getGet('cd_ac_pk');
         }
-        
+
         $data['insurerName'] = $this->insurerModel->getInsurerName($insurerId, $clientId);
         $data['depositdata'] = $this->clientPolicyModel->getdepositData($clientId, $insurerId, $cd_ac_pk, $subTypeOptions);
         $data['clientData'] = $this->clientPolicyModel->getClientById($clientId);
         $data['deposiamount'] = $this->clientPolicyModel->getDepositSummary($clientId, $insurerId, $cd_ac_pk);
         $data['cd_ac_pk'] = $cd_ac_pk;
 
-        if($requestFrom == 'rest'){ return $data; }
-        
+        if ($requestFrom == 'rest') {
+            return $data;
+        }
+
         // Load the view for the new list page;
         echo view('layout/header', $headerData);
         echo view('view_deposit', $data);
@@ -715,12 +717,12 @@ class ClientController extends AdminController
             ->where('is_active', 1)
             ->first();
 
-        
-        if(!empty($record_date)){
+
+        if (!empty($record_date)) {
             // Prepare the array with data
             $date = \DateTime::createFromFormat('d/m/Y', $record_date);
             $record_date = $date->format('Y-m-d');
-        }else{
+        } else {
             $record_date = null;
         }
 
@@ -796,8 +798,12 @@ class ClientController extends AdminController
         $editData['client_policy']['role'] = get_role_id();
         $editData['notification'] = $this->notificationModel->select('template_name,enabled')->where('client_id', $id)->findAll();
         $editData['placeHolders'] = ['member_name', 'member_mobile', 'nhance_logo', 'tpa_id', 'ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
-        $editData['api_data'] = $this->clientApi->where("client_id", $id)->where("is_active",1)->first();
+        $editData['api_data'] = $this->clientApi->where("client_id", $id)->where("is_active", 1)->first();
         // dd($editData);
+
+        $editData['auto_fetch_client_list'] =  $this->getClientListFromPre();
+
+
         echo view('layout/header', $headerData);
         echo view('client_onboarding', $editData);
         echo view('layout/footer');
@@ -821,7 +827,7 @@ class ClientController extends AdminController
             $data['is_download_btn'] = 1;
         }
 
-        if(empty($data['parent_client_id'])){
+        if (empty($data['parent_client_id'])) {
             $data['parent_client_id'] = null;
         }
 
@@ -855,7 +861,7 @@ class ClientController extends AdminController
             $data['is_download_btn'] = 1;
         }
 
-        if(empty($data['parent_client_id'])){
+        if (empty($data['parent_client_id'])) {
             $data['parent_client_id'] = null;
         }
         // print_r($data);die;
@@ -894,9 +900,9 @@ class ClientController extends AdminController
         $insert = $this->clientKYCDocsModel->insert($data);
         if ($insert) {
             // $kycDocs = $this->clientKYCDocsModel->where('client_id', $this->request->getPost('client_id'))->findAll();
-            if($form_type == "others"){
+            if ($form_type == "others") {
                 $kycDocs = $this->generateKycOthersTable($this->request->getPost('client_id'));
-            }else{
+            } else {
                 $kycDocs = $this->generateKycPrimaryTable($this->request->getPost('client_id'));
             }
             return $this->respond(['status' => true, 'code' => 200, 'data' => $kycDocs, 'file_name' => $File], 200);
@@ -924,9 +930,9 @@ class ClientController extends AdminController
 
         if ($insert) {
             // $kycDocs = $this->clientKYCDocsModel->getKycDocsName($id);
-            if($form_type == "others"){
+            if ($form_type == "others") {
                 $kycDocs = $this->generateKycOthersTable($this->request->getPost('client_id'));
-            }else{
+            } else {
                 $kycDocs = $this->generateKycPrimaryTable($this->request->getPost('client_id'));
             }
             return $this->respond(['status' => true, 'code' => 200, 'data' => $kycDocs], 200);
@@ -1074,7 +1080,7 @@ class ClientController extends AdminController
 
         $this->myLogger->logme('error', 'Client branch CREATE function called');
         $data   = $this->request->getPost();
-        // var_dump($data); die;
+
         if (!isset($data['sez'])) {
             $data['sez'] = 0;
         } elseif ($data['sez']) {
@@ -1126,9 +1132,9 @@ class ClientController extends AdminController
         $units   = $this->request->getPost('units');
 
         $emp_unit_count = 0;
-        $rr_unit_count = 0;
+        $rr_unit_count  = 0;
         $rr_unit_count2 = 0;
-        $total_count = 0;
+        $total_count    = 0;
 
         $list_of_branch_units = $this->clientBranchModel->find($id);
         $units = json_decode($list_of_branch_units['units']);
@@ -1387,9 +1393,9 @@ class ClientController extends AdminController
         $data['insurer_id']        = $insurerId;
 
         $tpaValue                  = (string) $this->request->getPost('tpa');
-        if(!empty($tpaValue) || $tpaValue !== ''){
+        if (!empty($tpaValue) || $tpaValue !== '') {
             list($tpaBranchId, $tpaId) = explode('-', $tpaValue);
-        }else{
+        } else {
             $tpaBranchId = null;
             $tpaId = null;
         }
@@ -1465,7 +1471,7 @@ class ClientController extends AdminController
             $clientPoliceData =  $this->clientPolicyModel->getClientPolicyByClientId($client_id);
             $clientPoliceData['role'] = get_role_id();
 
-            if($policy_transaction_data > 0){
+            if ($policy_transaction_data > 0) {
                 $r = Jobs::addJob(['job_name' => 'updatePolicyTransactionDataWhileClinetPolicyUpdate', 'payload' => [
                     'old_client_policy_data' => $old_client_policy_data ?? null,
                     'new_client_policy_data' => $new_client_policy_data ?? null,
@@ -1501,14 +1507,13 @@ class ClientController extends AdminController
             $update = $this->clientPolicyModel->where('id', $id)->set($data)->update();
 
             if ($update) {
-                
+
                 $policy_transaction_update = $this->deactivatePolicyTransactionsPolicy($id);
 
                 return $this->respond(['status' => true, 'code' => 200], 200);
             } else {
                 return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to remove policy'], 200);
             }
-
         } else {
 
             return $this->respond(['status' => false, 'code' => 404, 'message' => 'The policy has active employees'], 200);
@@ -1540,7 +1545,7 @@ class ClientController extends AdminController
         }
     }
 
-    
+
 
     // Save Rack Rate function
     public function createClientPolicyPremium()
@@ -1994,8 +1999,15 @@ class ClientController extends AdminController
 
             // Check differences and prepare update data
             $fields_to_check = [
-                'client_branch_id', 'policy_type', 'insurer_id', 'insurer_branch_id',
-                'cd_ac_pk', 'policy_end_date', 'policy_start_date', 'tpa_id', 'tpa_branch_id'
+                'client_branch_id',
+                'policy_type',
+                'insurer_id',
+                'insurer_branch_id',
+                'cd_ac_pk',
+                'policy_end_date',
+                'policy_start_date',
+                'tpa_id',
+                'tpa_branch_id'
             ];
 
             foreach ($fields_to_check as $field) {
@@ -2043,18 +2055,16 @@ class ClientController extends AdminController
                 }
 
                 $this->myLogger->logme("error", "Policy transaction(s) updated successfully. Updated IDs: " . json_encode($updated_pt_ids));
-                
+
                 return [
                     'status' => "Success",
                     'message' => "Policy transaction(s) updated.",
                     'updated_ids' => $updated_pt_ids
                 ];
-
             } else {
                 $this->myLogger->logme("error", "No active policy_transaction records found for update.");
                 return ['status' => "Failed", 'message' => "No active policy_transaction records found."];
             }
-
         } catch (\Throwable $e) {
             $this->myLogger->logme("error", "Exception during policy_transaction update: " . $e->getMessage());
             return [
@@ -2100,7 +2110,6 @@ class ClientController extends AdminController
                         $errors[] = "No change or failed update for ID {$row['id']}";
                     }
                 }
-
             } catch (\Exception $e) {
                 $errors[] = "Error updating pt_id {$pt_id}: " . $e->getMessage();
             }
@@ -2189,7 +2198,8 @@ class ClientController extends AdminController
         }
     }
 
-    public function generateKycPrimaryTable($client_id){
+    public function generateKycPrimaryTable($client_id)
+    {
 
         $db = db_connect();
         $builder = $db->table('kyc_docs kd');
@@ -2214,16 +2224,17 @@ class ClientController extends AdminController
 
     }
 
-    public function generateKycOthersTable($client_id){
-        
+    public function generateKycOthersTable($client_id)
+    {
+
         $result['data'] = $this->clientKYCDocsModel
-                ->where('is_active', 1)
-                ->where('client_id', $client_id)
-                ->groupStart()
-                    ->where('kyc_doc_type_id', null)
-                    ->orWhere('kyc_doc_type_id', 0)
-                ->groupEnd()
-                ->findAll();
+            ->where('is_active', 1)
+            ->where('client_id', $client_id)
+            ->groupStart()
+            ->where('kyc_doc_type_id', null)
+            ->orWhere('kyc_doc_type_id', 0)
+            ->groupEnd()
+            ->findAll();
 
         $result['client_id'] = $client_id;
         $table = view('client_kyc_other_table', $result);
@@ -2651,7 +2662,7 @@ class ClientController extends AdminController
             // $data['special_condition_label'] = str_replace(',', '', $this->request->getPost("special_condition_label")) ?? [];
             // $data['special_condition_input'] = str_replace(',', '', $this->request->getPost("special_condition_input")) ?? [];
             // $data['multiple_sum_insured'] = str_replace(',', '', $this->request->getPost("multiple_sum_insured")) ?? [];
-            
+
             $fields = [
                 'waiverofpreexistingdiseases' => false,
                 'waiverof1,2,3&4thyearexclusions' => false,
@@ -2698,17 +2709,17 @@ class ClientController extends AdminController
                 'special_condition_input' => true,
                 'multiple_sum_insured' => true,
             ];
-                       
+
             foreach ($fields as $field => $needsCleanup) {
                 $value = $this->request->getPost($field);
-            
+
                 if ($value !== null && $value !== '') {
                     $data[$field] = $needsCleanup ? str_replace(',', '', $value) : $value;
-                }else{
-                     $data[$field] = $value;
+                } else {
+                    $data[$field] = $value;
                 }
             }
-            
+
             $data['enrollment_display_key'] = $this->enrollmentGMCDisplayValueTransform();
             $this->myLogger->logme('error', "contructed post data : " . json_encode($data ?? []));
             // print_r($data);die;
@@ -2751,11 +2762,11 @@ class ClientController extends AdminController
     //     if ($this->request->getPost("waiverofpreexistingdiseases_display")) {
     //         $data['Waiver of Pre-existing Diseases'] = $this->request->getPost("waiverofpreexistingdiseases");
     //     }
-        
+
     //     if ($this->request->getPost("waiverof1234thyearexclusions_display")) {
     //         $data['Waiver of 1, 2, 3 & 4th year Exclusions'] = $this->request->getPost("waiverof1,2,3&4thyearexclusions");
     //     }
-        
+
     //     if ($this->request->getPost("waiverof30dayswaitingperiod_display")) {
     //         $data['Waiver of 30 days waiting period'] = $this->request->getPost("waiverof30dayswaitingperiod");
     //     }
@@ -2763,157 +2774,157 @@ class ClientController extends AdminController
     //     if ($this->request->getPost("suminsuredenhancement_display")) {
     //         $data['Sum Insured Enhancement'] = $this->request->getPost("suminsuredenhancement");
     //     }
-        
+
     //     if ($this->request->getPost("waiver_of_90_days_waiting_period_display")) {
     //         $data['Waiver of 90 Days Waiting Period'] = $this->request->getPost("waiver_of_90_days_waiting_period");
     //     }
-        
+
     //     if ($this->request->getPost("waiver_of_other_waiting_periods_display")) {
     //         $data['Waiver of Other Waiting Periods'] = $this->request->getPost("waiver_of_other_waiting_periods");
     //     }
-        
+
     //     if ($this->request->getPost("maternity_benefit_display")) {
     //         $data['Maternity Benefit'] = $this->request->getPost("maternity_benefit");
     //     }
-        
+
     //     if ($this->request->getPost("9monthwaitingperiodwaived_display")) {
     //         $data['9-month waiting Period - waived'] = $this->request->getPost("9monthwaitingperiodwaived");
     //     }
-        
+
     //     if ($this->request->getPost("maternitycoverage_display")) {
     //         $data['Maternity Coverage'] = $this->request->getPost("maternitycoverage");
     //     }
-        
+
     //     if ($this->request->getPost("twindelivery_display")) {
     //         $data['Twin Delivery'] = $this->request->getPost("twindelivery");
     //     }
-        
+
     //     if ($this->request->getPost("well_baby_well_mother_expenses_display")) {
     //         $data['Well baby / Well Mother Expenses'] = $this->request->getPost("well_baby_well_mother_expenses");
     //     }
-        
+
     //     if ($this->request->getPost("preandpostnatal_display")) {
     //         $data['Pre and Post natal'] = $this->request->getPost("preandpostnatal");
     //     }
-        
+
     //     if ($this->request->getPost("infertility_treatment_coverage_display")) {
     //         $data['Infertility Treatment Coverage'] = $this->request->getPost("infertility_treatment_coverage");
     //     }
-        
+
     //     if ($this->request->getPost("babyday1cover_display")) {
     //         $data['Baby Day 1 Cover'] = $this->request->getPost("babyday1cover");
     //     }
-        
+
     //     if ($this->request->getPost("coverfromthedateofjoining_display")) {
     //         $data['Cover from the date of Joining'] = $this->request->getPost("coverfromthedateofjoining");
     //     }
-        
+
     //     if ($this->request->getPost("mid_term_addition_of_new_born_newly_wedded_spouse_display")) {
     //         $data['Mid Term Addition of New Born / Newly Wedded Spouse'] = $this->request->getPost("mid_term_addition_of_new_born_newly_wedded_spouse");
     //     }
-        
+
     //     if ($this->request->getPost("prehospitalizationcover_display")) {
     //         $data['Pre Hospitalization Cover'] = $this->request->getPost("prehospitalizationcover");
     //     }
-        
+
     //     if ($this->request->getPost("posthospitalizationcover_display")) {
     //         $data['Post Hospitalization Cover'] = $this->request->getPost("posthospitalizationcover");
     //     }
-        
+
     //     if ($this->request->getPost("congenitaldiseasesinternal_display")) {
     //         $data['Congenital Diseases - Internal'] = $this->request->getPost("congenitaldiseasesinternal");
     //     }
-        
+
     //     if ($this->request->getPost("congenitaldiseasesexternal_display")) {
     //         $data['Congenital Diseases - External'] = $this->request->getPost("congenitaldiseasesexternal");
     //     }
-        
+
     //     if ($this->request->getPost("copayzonewisecopay_display")) {
     //         $data['Co-Pay/Zone wise Co Pay'] = $this->request->getPost("copayzonewisecopay");
     //     }
-        
+
     //     if ($this->request->getPost("roomrentlimit_display")) {
     //         $data['Room Rent Limit'] = $this->request->getPost("roomrentlimit");
     //     }
-        
+
     //     if ($this->request->getPost("icu_limit_display")) {
     //         $data['ICU Limit'] = $this->request->getPost("icu_limit");
     //     }
-        
+
     //     if ($this->request->getPost("proportionatedeductionclause_display")) {
     //         $data['Proportionate Deduction Clause'] = $this->request->getPost("proportionatedeductionclause");
     //     }
-        
+
     //     if ($this->request->getPost("ailmentcapping_display")) {
     //         $data['Ailment capping'] = $this->request->getPost("ailmentcapping");
     //     }
-        
+
     //     if ($this->request->getPost("ailment_capping_details_display")) {
     //         $data['Ailment capping Details'] = $this->request->getPost("ailment_capping_details");
     //     }
-        
+
     //     if ($this->request->getPost("corporatebuffer_display")) {
     //         $data['Corporate Buffer'] = $this->request->getPost("corporatebuffer");
     //     }
-        
+
     //     if ($this->request->getPost("non_admissible_contingency_corporate_buffer_display")) {
     //         $data['Non-Admissible / Contingency Corporate Buffer'] = $this->request->getPost("non_admissible_contingency_corporate_buffer");
     //     }
-        
+
     //     if ($this->request->getPost("ambulancecharges_display")) {
     //         $data['Ambulance Charges'] = $this->request->getPost("ambulancecharges");
     //     }
-        
+
     //     if ($this->request->getPost("airambulance_display")) {
     //         $data['Air Ambulance'] = $this->request->getPost("airambulance");
     //     }
-        
+
     //     if ($this->request->getPost("reasonableandcustomarycharges_display")) {
     //         $data['Reasonable and Customary Charges'] = $this->request->getPost("reasonableandcustomarycharges");
     //     }
-        
+
     //     if ($this->request->getPost("daycaretreatment_display")) {
     //         $data['Day Care Treatment'] = $this->request->getPost("daycaretreatment");
     //     }
-        
+
     //     if ($this->request->getPost("lasiksurgery_display")) {
     //         $data['Lasik Surgery'] = $this->request->getPost("lasiksurgery");
     //     }
-        
+
     //     if ($this->request->getPost("ayushtreatmentcover_display")) {
     //         $data['AYUSH treatment cover'] = $this->request->getPost("ayudhtreatmentcover");
     //     }
-        
+
     //     if ($this->request->getPost("moderntreatmentsasperirdai_display")) {
     //         $data['Modern treatments as per IRDAI'] = $this->request->getPost("moderntreatmentsasperirdai");
     //     }
-        
+
     //     if ($this->request->getPost("opd_treatment_display")) {
     //         $data['OPD Treatment'] = $this->request->getPost("opd_treatment");
     //     }
-        
+
     //     if ($this->request->getPost("days_of_discharge_display")) {
     //         $data['Claim Intimation Clause'] = $this->request->getPost("days_of_discharge");
     //     }
-        
+
     //     if ($this->request->getPost("days_from_dod_display")) {
     //         $data['Claim Submission'] = $this->request->getPost("days_from_dod");
     //     }
-        
+
     //     if ($this->request->getPost("terrorism_display")) {
     //         $data['Terrorism'] = $this->request->getPost("terrorism");
     //     }
-        
+
     //     if ($this->request->getPost("widower_cover_display")) {
     //         $data['Widower Cover'] = $this->request->getPost("widower_cover");
     //     }
-        
+
     //     if ($this->request->getPost("breavement_cover_display")) {
     //         $data['Breavement Cover'] = $this->request->getPost("breavement_cover");
     //     }
 
     //     if ($this->request->getPost("special_condition_display_value")) {
-            
+
     //         $specialConditionKeyValue = $this->request->getPost("special_condition_display_value") ?? [];
     //         $specialConditionKeyValue = json_decode($specialConditionKeyValue, true);
 
@@ -2922,14 +2933,14 @@ class ClientController extends AdminController
     //             $data = array_merge($data, $mergedArray);
     //         }
     //     }
-        
+
     //     if(isset($data) && !empty($data)){
     //         return $data;
     //     }else{
     //         $data = [];
     //         return $data;
     //     }
-    
+
     // }
 
     public function enrollmentGMCDisplayValueTransform()
@@ -3096,7 +3107,7 @@ class ClientController extends AdminController
                 'gpa_special_condition_input',
                 'multiple_sum_insured',
             ];
-            
+
             $fieldsWithoutCommaRemoval = [
                 'permanentPartialDisablement',
                 'temporaryTotalDisablementBenefit',
@@ -3113,27 +3124,27 @@ class ClientController extends AdminController
                 'animalSnakeInsectBite',
                 'air_ambulance'
             ];
-            
+
             // Remove commas and assign if present
             foreach ($fieldsWithCommaRemoval as $field) {
                 $value = $this->request->getPost($field);
                 if ($value !== null) {
                     $data[$field] = str_replace(',', '', $value);
-                }else{
-                     $data[$field] = $value;
+                } else {
+                    $data[$field] = $value;
                 }
             }
-            
+
             // Direct assign if present
             foreach ($fieldsWithoutCommaRemoval as $field) {
                 $value = $this->request->getPost($field);
                 if ($value !== null) {
                     $data[$field] = $value;
-                }else{
-                     $data[$field] = $value;
+                } else {
+                    $data[$field] = $value;
                 }
             }
-            
+
             $data['enrollment_display_key'] = $this->enrollmentGPADisplayValueTransform();
 
             // print_r($data); die;
@@ -3823,10 +3834,10 @@ class ClientController extends AdminController
 
         $cd_data = array_merge($cd_data, $client_cd_data);
 
-        if($return_type == "internal"){
-            if(!empty($cd_data)){
+        if ($return_type == "internal") {
+            if (!empty($cd_data)) {
                 return $cd_data;
-            }else{
+            } else {
                 return [];
             }
         }
@@ -3854,7 +3865,7 @@ class ClientController extends AdminController
 
         $client_policy_id = $this->request->getPost("client_policy_id");
         $policy_terms = $this->request->getPost("policy_terms");
-        $policy_terms = json_decode($policy_terms, true); 
+        $policy_terms = json_decode($policy_terms, true);
 
         $data = [];
 
@@ -3862,12 +3873,11 @@ class ClientController extends AdminController
 
             if (str_ends_with($key, '_display')) {
 
-                $original_key = substr($key, 0, -8); 
+                $original_key = substr($key, 0, -8);
 
                 $newKey = implode(' ', array_map('ucfirst', explode('_', $original_key)));
 
                 $data['enrollment_display_key'][$newKey] = $policy_terms[$original_key] ?? " ";
-
             } else {
 
                 $data[$key] = $value;
@@ -3875,10 +3885,10 @@ class ClientController extends AdminController
         }
 
         if (!empty($data)) {
-            $policy_terms['is_payable_employee']['self'] = 0; 
-            $policy_terms = json_encode($data); 
+            $policy_terms['is_payable_employee']['self'] = 0;
+            $policy_terms = json_encode($data);
         }
-        
+
 
         $record = $this->clientPolicyModel->where('id', $client_policy_id)->first();
 
@@ -4300,9 +4310,9 @@ class ClientController extends AdminController
         // -----------for vehicle ---------------------------------------------------------------------------
 
         $vehicles = $this->vehicleModel
-        ->select('vehicle.*, clients.client_type')
-        ->join('clients', 'clients.id=vehicle.owner')
-        ->where('vehicle.is_active', 1)->findAll();
+            ->select('vehicle.*, clients.client_type')
+            ->join('clients', 'clients.id=vehicle.owner')
+            ->where('vehicle.is_active', 1)->findAll();
 
         // -----------for Insurer ---------------------------------------------------------------------------
 
@@ -4425,12 +4435,12 @@ class ClientController extends AdminController
         $cd_data = array_merge($cd_data, $client_cd_data);
 
         if (!empty($cd_data)) {
-            return $this->respond([ 'status' => true,'code' => 200, 'data' => $cd_data], 200);
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $cd_data], 200);
         } else {
-            return $this->respond(['status' => false,'code' => 404,'client_id' => $client_id,'insurer_id' => $insurer_id,'insurer_branch_id' => $insurer_branch_id ], 200);
+            return $this->respond(['status' => false, 'code' => 404, 'client_id' => $client_id, 'insurer_id' => $insurer_id, 'insurer_branch_id' => $insurer_branch_id], 200);
         }
     }
-    
+
     // public function getCDAccNoByClientAndInsurer($client, $insurer, $insurer_branch_id)
     // {
     //     $cdmData = $this->CDMasterModel
@@ -4465,7 +4475,7 @@ class ClientController extends AdminController
         // Add additional fields if client type is 2
         if ($client_type == 2) {
             $client_data = array_merge($client_data, [
-                'dob' => change_date_format($postData['dob'],'d/m/Y','Y-m-d'),
+                'dob' => change_date_format($postData['dob'], 'd/m/Y', 'Y-m-d'),
                 'aadhar' => $postData['aadhar'],
                 'phone' => $postData['phone'],
                 'entity_type_id' => 7
@@ -4523,7 +4533,7 @@ class ClientController extends AdminController
         $client_type = $postData['client_type'] ?? null;
 
         $client_insert = null;
-        if($client_type == 2){
+        if ($client_type == 2) {
 
             $client_data = [
                 'client_type' => $postData['client_type'],
@@ -4534,8 +4544,7 @@ class ClientController extends AdminController
             ];
 
             $client_insert = $this->clientModel->insert($client_data);
-
-        }else if($client_type == 1){
+        } else if ($client_type == 1) {
 
             $client_data = [
                 'client_type' => $postData['client_type'],
@@ -4543,10 +4552,10 @@ class ClientController extends AdminController
                 'short_name' => $postData['short_name'] ?? $postData['client_name'],
                 'client_code' => generate_client_code(),
                 'entity_type_id' => 2
-            ]; 
-        
-             $client_insert = $this->clientModel->insert($client_data);
-        }        
+            ];
+
+            $client_insert = $this->clientModel->insert($client_data);
+        }
 
         if (!$client_insert) {
             return $this->respond(['status' => false, 'message' => 'Failed to create client'], 200);
@@ -4586,7 +4595,7 @@ class ClientController extends AdminController
             ->where('client_id', $client_insert)
             ->where('is_active', 1)
             ->findAll();
-            
+
         return $this->respond([
             'status' => true,
             'data' => $postData,
@@ -4617,12 +4626,12 @@ class ClientController extends AdminController
             $vehicle_insert = $this->vehicleModel->insert($data);
 
             if ($vehicle_insert) {
-                
+
                 // $vehicles = $this->vehicleModel->where('is_active', 1)->findAll();
                 $vehicles = $this->vehicleModel->select('vehicle.*, clients.client_type')
-                            ->join('clients', 'clients.id=vehicle.owner')
-                            ->where('vehicle.is_active', 1)
-                            ->findAll();
+                    ->join('clients', 'clients.id=vehicle.owner')
+                    ->where('vehicle.is_active', 1)
+                    ->findAll();
 
                 return $this->respond([
                     'status' => true,
@@ -4660,7 +4669,6 @@ class ClientController extends AdminController
                 ];
 
                 $client_insert = $this->clientModel->insert($client_data);
-
             } else if ($client_type == 1) {
 
                 $client_data = [
@@ -4721,7 +4729,7 @@ class ClientController extends AdminController
                     ->where('is_active', 1)
                     ->findAll();
 
-                    // Fetch branches in a single query
+                // Fetch branches in a single query
                 $branches = $this->clientBranchModel
                     ->where('client_id', $client_insert)
                     ->where('is_active', 1)
@@ -4738,11 +4746,9 @@ class ClientController extends AdminController
                     'vehicles' => $vehicles,
                     'message' => 'Vehicle created successfully'
                 ], 200);
-
             } else {
                 return $this->respond(['status' => false, 'message' => 'Failed to created vehicle'], 200);
             }
-
         } else if (isset($data['owner']) && !empty($data['owner'])) {
 
             $vehicle_data = [
@@ -4754,7 +4760,7 @@ class ClientController extends AdminController
             ];
 
             $vehicle_insert = $this->vehicleModel->insert($vehicle_data);
-            
+
             $vehicles = $this->vehicleModel->select('vehicle.*, clients.client_type')
                 ->join('clients', 'clients.id = vehicle.owner')
                 ->where('vehicle.is_active', 1)
@@ -4765,7 +4771,7 @@ class ClientController extends AdminController
                 ->where('is_active', 1)
                 ->findAll();
 
-                // Fetch branches in a single query
+            // Fetch branches in a single query
             $branches = $this->clientBranchModel
                 ->where('client_id', $data['owner'])
                 ->where('is_active', 1)
@@ -4784,7 +4790,6 @@ class ClientController extends AdminController
                     'vehicles' => $vehicles,
                     'message' => 'Vehicle created successfully'
                 ], 200);
-                
             } else {
                 return $this->respond(['status' => false, 'message' => 'Failed to created vehicle'], 200);
             }
@@ -4932,7 +4937,7 @@ class ClientController extends AdminController
     //                 return $this->respond(['status' => true, 'code' => 409, "message" => $message, 'received_data' => $received_data, 'db_data' => $data], 200);
     //             }
     //         }
-            
+
     //     } else {
     //         return $this->respond(['status' => false, 'message' => 'No Data Found', 'code' => 404, 'received_data' => $received_data], 200);
     //     }
@@ -4948,10 +4953,10 @@ class ClientController extends AdminController
         $client_type = $this->request->getGet('client_type');
 
         $data = $this->policyTransactionModel
-                        ->where('is_active', 1)
-                        ->where('action_type', 'inception')
-                        ->where('policy_no', $policy_no)
-                        ->countAllResults();
+            ->where('is_active', 1)
+            ->where('action_type', 'inception')
+            ->where('policy_no', $policy_no)
+            ->countAllResults();
 
         if ($data > 0) {
             return $this->respond(['status' => true, 'message' => 'This policy number is already linked to another client', 'data' => $data, 'code' => 409, 'received_data' => $received_data], 200);
@@ -4961,7 +4966,7 @@ class ClientController extends AdminController
     }
 
     public function get_client_policy_data_using_policy_no_and_endo_no()
-    {   
+    {
         $policy_no = $this->request->getGet('policy_no');
         $endorsement_no = $this->request->getGet('endorsement_no');
 
@@ -4984,10 +4989,10 @@ class ClientController extends AdminController
     {
         if ($id) {
             $branch_data = $this->clientBranchModel
-                    ->select('client_branch.*, clients.pan')
-                    ->join('clients', 'client_branch.client_id = clients.id')
-                    ->where(['client_branch.id' => $id, 'client_branch.is_active' => 1])
-                    ->first();
+                ->select('client_branch.*, clients.pan')
+                ->join('clients', 'client_branch.client_id = clients.id')
+                ->where(['client_branch.id' => $id, 'client_branch.is_active' => 1])
+                ->first();
             $branch_contact_data = $this->levelContactModel->where(['ref_id' => $id, 'contact_type' => 'client', 'is_active' => 1])->findAll();
             // print_rr($branch_contact_data);die();
             return $this->respond(['status' => true, 'code' => 200, 'data' => $branch_data, 'contact' => $branch_contact_data], 200);
@@ -4997,7 +5002,7 @@ class ClientController extends AdminController
     }
 
     public function getClientData()
-    {   
+    {
         $client_id = $this->request->getGet('client_id') ?? null;
         $result = $this->clientModel->getClientData($client_id);
         dd($result);
@@ -5014,17 +5019,17 @@ class ClientController extends AdminController
             ->where("policy_terms IS NOT NULL AND policy_terms <> ''")
             ->where('is_active', 1);
 
-        
+
         if (!empty($client_id)) {
             $query->where('client_id', $client_id);
         }
-        
+
         if (!empty($policy_type_id)) {
             $query->where('policy_type_id', $policy_type_id);
         }
-        
+
         $data = $query->findAll();
-        
+
         for ($i = 0; $i < count($data); $i++) {
 
             // dd($data[$i]);
@@ -5040,30 +5045,28 @@ class ClientController extends AdminController
             $is_addon = $data[$i]['is_addon'];
 
             $payable_arr = [];
-            if (in_array($data[$i]['policy_type_id'], [2,3]) && $is_addon == 1) {
-
-                $payable_arr = [ "self" => 0, "spouse" => 0, "childern" => 0, "elders" => 0, ];
+            if (in_array($data[$i]['policy_type_id'], [2, 3]) && $is_addon == 1) {
 
+                $payable_arr = ["self" => 0, "spouse" => 0, "childern" => 0, "elders" => 0,];
             } else if ($data[$i]['policy_type_id'] == 3 && $is_addon == 3) {
 
-                $payable_arr = ["self" => 1,"spouse" => 1,"childern" => 1,"elders" => 1,];
-
+                $payable_arr = ["self" => 1, "spouse" => 1, "childern" => 1, "elders" => 1,];
             } else if (in_array($data[$i]['policy_type_id'], [4, 5])) {
 
-                $payable_arr = ["self" => 1,"spouse" => 1,"childern" => 1,"elders" => 1,];
+                $payable_arr = ["self" => 1, "spouse" => 1, "childern" => 1, "elders" => 1,];
             }
 
             // Initialize an empty array for the ordered policy terms
             $orderedPolicyTerms = [];
 
-            if(in_array($data[$i]['policy_type_id'], [2,3,4,5])){
+            if (in_array($data[$i]['policy_type_id'], [2, 3, 4, 5])) {
 
                 // Set default value of copayzonewisecopay to "empty"
                 // $ans = isset($policyTerms['copayzonewisecopay']) ? $policyTerms['copayzonewisecopay'] : 'empty';
 
                 // add is_payable_employee for the GMC Policy
                 if (isset($policyTerms['age_ratio'])) {
-                    if(!isset($policyTerms['is_payable_employee'])){
+                    if (!isset($policyTerms['is_payable_employee'])) {
                         $aliment_index = array_search('age_ratio', array_keys($policyTerms));
                         $orderedPolicyTerms[] = [
                             "key" => "is_payable_employee",
@@ -5101,7 +5104,7 @@ class ClientController extends AdminController
 
                 // Add ailmentcapping and ailmentcappingdata if they exist
                 if (isset($policyTerms['ailmentcapping'])) {
-                    if(!isset($policyTerms['ailment_capping_details'])){
+                    if (!isset($policyTerms['ailment_capping_details'])) {
                         $aliment_index = array_search('ailmentcapping', array_keys($policyTerms));
                         $orderedPolicyTerms[] = [
                             "key" => "ailment_capping_details",
@@ -5110,12 +5113,11 @@ class ClientController extends AdminController
                         ];
                     }
                 }
-
-            }else {
+            } else {
 
                 // add is_payable_employee for the GMC Policy
                 if (isset($policyTerms['age_ratio'])) {
-                    if(!isset($policyTerms['is_payable_employee'])){
+                    if (!isset($policyTerms['is_payable_employee'])) {
                         $aliment_index = array_search('age_ratio', array_keys($policyTerms));
                         $orderedPolicyTerms[] = [
                             "key" => "is_payable_employee",
@@ -5125,9 +5127,9 @@ class ClientController extends AdminController
                             "position" => $aliment_index + 1,
                         ];
                     }
-                }else{
+                } else {
 
-                    if(!isset($policyTerms['is_payable_employee'])){
+                    if (!isset($policyTerms['is_payable_employee'])) {
                         $orderedPolicyTerms[] = [
                             "key" => "is_payable_employee",
                             "value" => [
@@ -5137,7 +5139,6 @@ class ClientController extends AdminController
                         ];
                     }
                 }
-
             }
 
             foreach ($orderedPolicyTerms as $term) {
@@ -5159,12 +5160,12 @@ class ClientController extends AdminController
                 }
             }
 
-            if(in_array($data[$i]['policy_type_id'], [2,3,4,5])){
+            if (in_array($data[$i]['policy_type_id'], [2, 3, 4, 5])) {
 
                 if (!isset($policyTerms['waiver_of_90_days_waiting_period'])) {
                     $policyTerms['waiver_of_90_days_waiting_period'] = "";
                 }
-                
+
                 if (!isset($policyTerms['waiver_of_other_waiting_periods'])) {
                     $policyTerms['waiver_of_other_waiting_periods'] = "";
                 }
@@ -5172,7 +5173,7 @@ class ClientController extends AdminController
                 if (!isset($policyTerms['maternity_benefit'])) {
                     $policyTerms['maternity_benefit'] = "";
                 }
-                
+
                 if (!isset($policyTerms['well_baby_well_mother_expenses'])) {
                     $policyTerms['well_baby_well_mother_expenses'] = "";
                 }
@@ -5200,61 +5201,59 @@ class ClientController extends AdminController
                 if (!isset($policyTerms['widower_cover'])) {
                     $policyTerms['widower_cover'] = "";
                 }
-                
+
                 if (!isset($policyTerms['breavement_cover'])) {
                     $policyTerms['breavement_cover'] = "";
                 }
-                
+
                 if (!isset($policyTerms['enrollment_display_key'])) {
                     $policyTerms['enrollment_display_key'] = $this->existingGMCDisplayValueTransform($policyTerms);
                 }
-
-            } else if($data[$i]['policy_type_id'] == 1){
+            } else if ($data[$i]['policy_type_id'] == 1) {
 
                 if (!isset($policyTerms['medical_expenses_medical_extension'])) {
                     $policyTerms['medical_expenses_medical_extension'] = "";
                 }
-                
+
                 if (!isset($policyTerms['opd_treatment_cover'])) {
                     $policyTerms['opd_treatment_cover'] = "";
                 }
-                
+
                 if (!isset($policyTerms['repatriation_of_mortal_remains'])) {
                     $policyTerms['repatriation_of_mortal_remains'] = "";
                 }
-                
+
                 if (!isset($policyTerms['family_transportation_benefits'])) {
                     $policyTerms['family_transportation_benefits'] = "";
                 }
-                
+
                 if (!isset($policyTerms['fractures_dislocation_burns'])) {
                     $policyTerms['fractures_dislocation_burns'] = "";
                 }
-                
+
                 if (!isset($policyTerms['coma'])) {
                     $policyTerms['coma'] = "";
                 }
-                
+
                 if (!isset($policyTerms['travel_expenses_for_medical_treatment'])) {
                     $policyTerms['travel_expenses_for_medical_treatment'] = "";
                 }
-                
+
                 if (!isset($policyTerms['daily_cash_allowance'])) {
                     $policyTerms['daily_cash_allowance'] = "";
                 }
-                
+
                 if (!isset($policyTerms['artifical_limb_and_prosthesis'])) {
                     $policyTerms['artifical_limb_and_prosthesis'] = "";
                 }
-                
+
                 if (!isset($policyTerms['air_ambulance'])) {
                     $policyTerms['air_ambulance'] = "";
                 }
-                                
+
                 if (!isset($policyTerms['enrollment_display_key'])) {
                     $policyTerms['enrollment_display_key'] = $this->existingGPADisplayValueTransform($policyTerms);
                 }
-                
             }
 
             // dd($policyTerms);
@@ -5435,7 +5434,7 @@ class ClientController extends AdminController
     }
 
     public function existingGPADisplayValueTransform($data)
-    {   
+    {
         $transformedData = [];
 
         if (isset($data["accidentalDeathBenefit"])) {
@@ -5478,7 +5477,7 @@ class ClientController extends AdminController
             $transformedData['Fractures / Dislocation / Burns'] = $data["fractures_dislocation_burns"];
         }
         if (isset($data["coma"])) {
-            $transformedData['Coma'] = $data["coma"]; 
+            $transformedData['Coma'] = $data["coma"];
         }
         if (isset($data["carriageofDeadBody"])) {
             $transformedData['Carriage of Dead Body'] = $data["carriageofDeadBody"];
@@ -5513,24 +5512,24 @@ class ClientController extends AdminController
             ->where('is_active', 1)
             ->get()
             ->getResultArray();
-    
+
         $days = [];
         foreach ($data as $value) {
 
             $reminderDate = strtotime($value['reminder_date']);
             if ($reminderDate) {
                 $date_of_date = date('d', $reminderDate);
-                $days[] = $date_of_date; 
+                $days[] = $date_of_date;
                 $days[] = $value['reminder_date'];
                 db_connect()->table('client_policy')->where('id', $value['id'])->set('reminder_date', $date_of_date)->update();
-            } 
+            }
         }
-    
+
         dd($days);
     }
 
     public function sendextraparam()
-    {   
+    {
         //     $data = db_connect()->table('jobs')->where('id', 1677)->get()->getRowArray();
         //     // dd($data);
         //    $return = $this->updatePolicyTransactionDataWhileClinetPolicyUpdate(json_decode($data['payload'], true));
@@ -5561,7 +5560,7 @@ class ClientController extends AdminController
         // $res = $empServiceController->employeesSIEnhanceProcess(['file_id' => '978']);
         // $res = $empServiceController->employeeDisembark(['file_id' => '1681']); 
         // $res = $empServiceController->employeesCorrectionProcess(['file_id' => '2033']); 
-        dd( $res); 
+        dd($res);
 
         $EmployeeMultiEventServiceController = new EmployeeMultiEventServiceController();
         // $res = $EmployeeMultiEventServiceController->constructMultiEventData(['file_id' => '1069']); 
@@ -5592,7 +5591,7 @@ class ClientController extends AdminController
             'event_type' => "correction",
             'actions' => "export",
             'file_name' => "deletion_enhancement_test_file.xlsx",
-        ]; 
+        ];
 
         // $batch_data = [
         //     'client_id' => 20,
@@ -5614,7 +5613,7 @@ class ClientController extends AdminController
 
         // $emp_data = $this->employeePolicyModel->getEmployeePolicyForEcard(12);
         // $ids = array_column($emp_data, 'id');
-        
+
         $EmpDataServiceController = new EmpDataServiceController();
         // $res = $EmpDataServiceController->generateExcelForDeletion($batch_data); dd($return); die;
         // $res = $EmpDataServiceController->generateExcelForSIEnhancement($batch_data); die;
@@ -5640,7 +5639,7 @@ class ClientController extends AdminController
         // ];
         // $res = $EmpDataServiceController->makeEntryForBDSPolicyTransaction($params);
         // dd($res);
-        
+
         // $array = [
         //         "employeeIds" => ["12800", "12798", "12797", "12799"],
         //         "client_id" => "159",
@@ -5653,7 +5652,7 @@ class ClientController extends AdminController
         //         "policy_name" => "GMC",
         //         "user_id" => "1"
         // ];
-        
+
         // $EmpDataServiceController->cashDepositCalculationForDeletion($array);
 
         // $result = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($batch_data);
@@ -5683,11 +5682,11 @@ class ClientController extends AdminController
         // dd($res);
 
         // -----------BDS REPORT CONTROLLER---------------------------------------------------------------------------------
-        
+
         // $BDSReportController = new BDSReportController();
 
         // $data['data'] = $BDSReportController->getBAPInsurerData();
-        
+
         // return $this->loadLayout('irda_bap_insurer_report_list', $data);
 
         // $data['data'] = $BDSReportController->getBAPClientData();
@@ -5704,7 +5703,7 @@ class ClientController extends AdminController
         // $email_id = 'venkateshraman786@gmail.com';
         // $common = ['mail_type'=>'test_mail_cli'];
         // $bcc = "vitvelz@gmail.com";
-        
+
         // $data = db_connect()
         // ->table('jobs')
         // ->where('id', 2264)
@@ -5712,7 +5711,7 @@ class ClientController extends AdminController
         // ->getResultArray();
 
         // $data = json_decode($data[0]['payload'], true);
-        
+
         // // dd($data);
         // // Send email and get response
         // $result = MailHelper::send_email($data[0]);
@@ -5726,7 +5725,7 @@ class ClientController extends AdminController
         // print_rr($reportData);
         // $this->loadLayout('tat_report_band_wise_list', $reportData);
         // $data = $ticketModel->getTATReport(1);
-        
+
         // $empmodel = new EmployeeModel();
         // $data = $empmodel->getEmployeePolicy(348);
         // dd($data);
@@ -5790,7 +5789,7 @@ class ClientController extends AdminController
         // $return_value = check_cd_entry_exist($baseWhere);
         // dd($return_value);
 
-        
+
 
 
         // $param = 9715454901;
@@ -5811,7 +5810,7 @@ class ClientController extends AdminController
     }
 
     // -------------------------------------------------------------------------------------------------------
-    
+
 
     public function createOtherTabContent()
     {
@@ -5834,20 +5833,16 @@ class ClientController extends AdminController
     // -------------------------------------------------------------------------------------------------------
 
     public function enrollmentAddonSIAmountDropdown($client_policy_id)
-    {   
-        if(!empty($client_policy_id)){
+    {
+        if (!empty($client_policy_id)) {
             $client_policy_details = $this->clientPolicyModel->where('id', $client_policy_id)->where('policy_status', 1)->where('is_active', 1)->first();
 
-            if(!empty($client_policy_details) && $client_policy_details['policy_type_id'] == 3 && $client_policy_details['is_addon'] == 3){
+            if (!empty($client_policy_details) && $client_policy_details['policy_type_id'] == 3 && $client_policy_details['is_addon'] == 3) {
 
                 $base_policy_id = $client_policy_details['base_policy'] ?? 0;
 
-                if(!empty($base_policy_id)){
-
-                    
-                    
+                if (!empty($base_policy_id)) {
                 }
-
             }
         }
     }
@@ -5857,12 +5852,12 @@ class ClientController extends AdminController
         $cd_ac_pk = $this->request->getGet('cd_ac_pk');
 
         $cd_amount = $this->clientDepositModel
-                ->where('is_active', 1)
-                ->where('cd_ac_pk', $cd_ac_pk)
-                ->orderBy('id', 'desc')
-                ->first();
+            ->where('is_active', 1)
+            ->where('cd_ac_pk', $cd_ac_pk)
+            ->orderBy('id', 'desc')
+            ->first();
 
-        if($cd_amount){
+        if ($cd_amount) {
             return $this->respond(['status' => true, 'code' => 200, 'data' => $cd_amount], 200);
         } else {
             return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
@@ -5911,9 +5906,9 @@ class ClientController extends AdminController
             ->getResultArray();
 
         // print_r(db_connect()->getLastQuery()); die;
-       
+
         $dataForClientAndInsurer = $this->clientPolicyModel
-                ->select("
+            ->select("
                         clients.id AS client_id,
                         clients.client_name,
                         insurers.id AS insurer_id,
@@ -5921,12 +5916,12 @@ class ClientController extends AdminController
                         tpa.id AS tpa_id,
                         tpa.name AS tpa_name,
                     ")
-                ->join('clients', 'client_policy.client_id = clients.id', 'left')
-                ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left')
-                ->join('tpa', 'client_policy.tpa_id = tpa.id', 'left')
-                ->where('client_policy.id', $param)
-                ->first();
-                
+            ->join('clients', 'client_policy.client_id = clients.id', 'left')
+            ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left')
+            ->join('tpa', 'client_policy.tpa_id = tpa.id', 'left')
+            ->where('client_policy.id', $param)
+            ->first();
+
         $memberData = [];
 
         // Respond based on the query result
@@ -6101,9 +6096,9 @@ class ClientController extends AdminController
     {
         $db = db_connect();
         $renewalData = $db->table('old_renewal_data_copy')
-        ->where('client_id IS NOT NULL')
-        ->where('is_inserted != 1')
-        ->get()
+            ->where('client_id IS NOT NULL')
+            ->where('is_inserted != 1')
+            ->get()
             ->getResultArray();
         // dd($renewalData);
 
@@ -6127,8 +6122,8 @@ class ClientController extends AdminController
 
             // Update is_inserted field in DB
             $db->table('old_renewal_data_copy')
-            ->where('id', $value['id'])
-            ->set(['is_inserted' => 1])
+                ->where('id', $value['id'])
+                ->set(['is_inserted' => 1])
                 ->update();
 
             $successData[] = ['id' => $value['id'], 'client' => $value['insured']];
@@ -6141,8 +6136,8 @@ class ClientController extends AdminController
     {
         $db = db_connect();
         $renewalData = $db->table('old_renewal_data_copy')
-        ->where('insurer_id IS NULL')
-        ->get()
+            ->where('insurer_id IS NULL')
+            ->get()
             ->getResultArray();
         // dd($renewalData);
 
@@ -6169,11 +6164,11 @@ class ClientController extends AdminController
 
             // Update is_inserted field in DB
             $db->table('old_renewal_data_copy')
-            ->where('id', $value['id'])
-            ->set([
-                'insurer_id' => $value['insurer_id'],
-                'insurer_branch_id' => $value['insurer_branch_id'],
-            ])
+                ->where('id', $value['id'])
+                ->set([
+                    'insurer_id' => $value['insurer_id'],
+                    'insurer_branch_id' => $value['insurer_branch_id'],
+                ])
                 ->update();
 
             $successData[] = ['id' => $value['id'], 'insurer' => $value['insurer_name'], 'insurer_id' => $value['insurer_id'], 'insurer_branch_id' => $value['insurer_branch_id'],];
@@ -6188,9 +6183,9 @@ class ClientController extends AdminController
         $group = $this->request->getGet('group') ?? 2;
         $db = db_connect();
         $renewalData = $db->table('old_renewal_data_copy')
-        ->where('client_id IS NULL')
-        ->where('is_inserted = 0')
-        ->where('client_type_id', $group)
+            ->where('client_id IS NULL')
+            ->where('is_inserted = 0')
+            ->where('client_type_id', $group)
             // ->limit($limit)
             ->get()
             ->getResultArray();
@@ -6225,8 +6220,8 @@ class ClientController extends AdminController
 
             // Update is_inserted field in DB
             $db->table('old_renewal_data_copy')
-            ->where('id', $value['id'])
-            ->set(['is_inserted' => 1])
+                ->where('id', $value['id'])
+                ->set(['is_inserted' => 1])
                 ->update();
 
             $successData[] = ['id' => $value['id'], 'client' => $value['insured'], 'vehicle_id' => $value['vehicle_id']];
@@ -6317,8 +6312,8 @@ class ClientController extends AdminController
         }
 
         $vehicleData = $VehicleModel->where('owner', $renewalData['client_id'])
-        ->where('is_active', 1)
-        ->findAll();
+            ->where('is_active', 1)
+            ->findAll();
 
         if (!empty($vehicleData)) {
             $increment = count($vehicleData);
@@ -6558,17 +6553,17 @@ class ClientController extends AdminController
         return $id;
     }
 
-    private function reorderProposalsByInsurerTotal(array $data): array 
+    private function reorderProposalsByInsurerTotal(array $data): array
     {
 
         Kint::dump($data);
         if (!isset($data['premium_data']['data'])) return $data;
-    
+
         $original = $data['premium_data']['data'];
         $proposals = [];
         $others = [];
         $emptyKeyData = [];
-    
+
         foreach ($original as $key => $value) {
             // Match only keys that look like 'Proposal X'
             if (preg_match('/^Proposal\s+\d+$/', $key)) {
@@ -6577,7 +6572,7 @@ class ClientController extends AdminController
                     if ($subKey !== 'Quote Asked' && isset($subVal['Total'])) {
                         $proposals[$key] = $value;
                         break;
-                    }else{
+                    } else {
                         $proposals[$key] = $value;
                     }
                 }
@@ -6586,51 +6581,50 @@ class ClientController extends AdminController
                 if ($key === '' && isset($value['']) && is_array($value[''])) {
                     // Capture empty key to push it later
                     $emptyKeyData[$key] = $value;
-                }else{
+                } else {
                     $others[$key] = $value;
-
                 }
             }
         }
-    
+
         // dd($proposals, $others, $emptyKeyData);
         // Sort proposals by their insurer's total
-        uasort($proposals, function($a, $b) {
+        uasort($proposals, function ($a, $b) {
             $totalA = 0;
             $totalB = 0;
-    
+
             foreach ($a as $key => $val) {
                 if ($key !== 'Quote Asked' && isset($val['Total'])) {
                     $totalA = floatval($val['Total']);
                     break;
                 }
             }
-    
+
             foreach ($b as $key => $val) {
                 if ($key !== 'Quote Asked' && isset($val['Total'])) {
                     $totalB = floatval($val['Total']);
                     break;
                 }
             }
-    
+
             return $totalA <=> $totalB;
         });
-    
+
         // Merge back the sorted proposals into the full structure
         $data['premium_data']['data'] = array_merge($others, $proposals, $emptyKeyData);
         $data = $this->reorderProposalDataByPremiumOrder($data);
         return $data;
     }
 
-    private function reorderProposalDataByPremiumOrder(array $data): array 
+    private function reorderProposalDataByPremiumOrder(array $data): array
     {
         if (!isset($data['premium_data']['data'], $data['proposal_data']['over_all_column_data'])) {
             return $data;
         }
-    
+
         $premiumProposals = array_keys($data['premium_data']['data']);
         $filteredProposals = [];
-    
+
         // Collect proposal keys that match the pattern "Proposal X"
         foreach ($premiumProposals as $key) {
             if (preg_match('/^Proposal\s+\d+$/', $key) && isset($data['proposal_data']['over_all_column_data'][$key])) {
@@ -6639,13 +6633,13 @@ class ClientController extends AdminController
         }
 
         // dd($premiumProposals, $filteredProposals);
-    
+
         $data['proposal_data']['over_all_column_data'] = $filteredProposals;
         $data = $this->reorderProposalInHeaderAndData($data);
         return $data;
     }
-    
-    private function reorderProposalInHeaderAndData(array $data): array 
+
+    private function reorderProposalInHeaderAndData(array $data): array
     {
 
         // Kint::dump($data);
@@ -6653,7 +6647,7 @@ class ClientController extends AdminController
         $sortedProposalOrder = $data['proposal_data']['over_all_column_data'];
         $headers = $tableData['headers'] ?? [];
         $dataRows = $tableData['data'] ?? [];
-    
+
         // Step 1: Separate static and proposal headers
         $staticHeaders = [];
         $proposalHeaders = [];
@@ -6662,16 +6656,16 @@ class ClientController extends AdminController
             if (in_array($header['parentHeader'], array_keys($sortedProposalOrder))) {
                 $proposalHeaders[$header['parentHeader']] = $header;
             } else {
-                if($header['parentHeader'] == "Action"){
+                if ($header['parentHeader'] == "Action") {
                     $actionHeader[] = $header;
-                }else{
+                } else {
                     $staticHeaders[] = $header;
                 }
             }
         }
-    
+
         // dd($staticHeaders, $proposalHeaders, $sortedProposalOrder);
-        
+
         // Step 2: Reorder headers
         $reorderedHeaders = [];
         foreach ($sortedProposalOrder as $proposalKey => $proposalValue) {
@@ -6685,29 +6679,29 @@ class ClientController extends AdminController
             $value['parentHeader'] = 'Proposal ' . ($key + 1);
         }
         unset($value);
-        
+
 
         $reorderedHeaders = array_merge($staticHeaders, $reorderedHeaders, $actionHeader);
 
-    
+
         // Step 3: Reorder each row's `data` by matching parentth
         foreach ($dataRows as $dataRowIndex => &$row) {
             $staticData = [];
             $proposalData = [];
             $actionData = [];
-    
+
             foreach ($row['data'] as $entry) {
                 if (in_array($entry['parentth'], array_keys($sortedProposalOrder))) {
                     $proposalData[$entry['parentth']][] = $entry;
                 } else {
-                    if($entry['parentth'] == "Action"){
+                    if ($entry['parentth'] == "Action") {
                         $actionData[] = $entry;
-                    }else{
+                    } else {
                         $staticData[] = $entry;
                     }
                 }
             }
-    
+
             $reorderedProposalData = [];
             foreach ($sortedProposalOrder as $proposalKey => $proposalValue) {
                 if (isset($proposalData[$proposalKey])) {
@@ -6721,19 +6715,19 @@ class ClientController extends AdminController
             $increament = 0;
             foreach ($reorderedProposalData as $key => &$value) {
 
-                if($dubParTh == $value['parentth']){
+                if ($dubParTh == $value['parentth']) {
                     $value['parentth'] = 'Proposal ' . ($increament);
-                }else{
+                } else {
                     $dubParTh = $value['parentth'];
                     $increament = $increament + 1;
                     $value['parentth'] = 'Proposal ' . ($increament);
                 }
             }
             unset($value);
-    
+
             $row['data'] = array_merge($staticData, $reorderedProposalData, $actionData);
         }
-    
+
         $data['table_data']['headers'] = $reorderedHeaders;
         $data['table_data']['data'] = $dataRows;
 
@@ -6742,15 +6736,15 @@ class ClientController extends AdminController
         $updatedDataSet = $this->renumberProposalKeys($data['premium_data']['data']);
         $data['proposal_data']['over_all_column_data'] =  !empty($renumberedArray) ? $renumberedArray : $data['proposal_data']['over_all_column_data'];
         $data['premium_data']['data'] = !empty($updatedDataSet) ? $updatedDataSet : $data['premium_data']['data'];
-        
+
         return $data;
     }
-     
-    private function renumberProposalKeys(array $input): array 
+
+    private function renumberProposalKeys(array $input): array
     {
         $result = [];
         $counter = 1;
-    
+
         foreach ($input as $key => $value) {
             if (strpos($key, 'Proposal') === 0) {
                 $newKey = 'Proposal ' . $counter++;
@@ -6759,7 +6753,7 @@ class ClientController extends AdminController
                 $result[$key] = $value;
             }
         }
-    
+
         return $result;
     }
 
@@ -6768,20 +6762,18 @@ class ClientController extends AdminController
 
         $receivedData = $this->request->getPost();
 
-        if (!empty($receivedData['id'])){
+        if (!empty($receivedData['id'])) {
             $status = $this->clientApi->save($receivedData);
-
-        }else{
+        } else {
             $status = $this->clientApi->insert($receivedData);
         }
 
 
-        if ($status){
-            return $this->respond(['status'=>"Sucesss",'message'=>"Submitted Successfully"],200);
-        }else{
-            return $this->respond(['status'=>"Failed",'message'=>"Submission Faild"],500);
+        if ($status) {
+            return $this->respond(['status' => "Sucesss", 'message' => "Submitted Successfully"], 200);
+        } else {
+            return $this->respond(['status' => "Failed", 'message' => "Submission Faild"], 500);
         }
-
     }
 
     public function sendToken()
@@ -6791,17 +6783,17 @@ class ClientController extends AdminController
 
         $token = ClientTokenHelper::generateKey($client_id);
 
-        if ($token){
-            return $this->respond(['status' => 'success', 'token' => $token,'message' => "Token Generated Successfully"],200);
-        }else{
-            return $this->respond(['status' => "Failed","message"=>"Token Generation Failed, Try Again After some time"],500);
+        if ($token) {
+            return $this->respond(['status' => 'success', 'token' => $token, 'message' => "Token Generated Successfully"], 200);
+        } else {
+            return $this->respond(['status' => "Failed", "message" => "Token Generation Failed, Try Again After some time"], 500);
         }
     }
-    
+
     // ---------------- HR ACCESS CONTROL -----------------------------------------------------------------------------------
 
     public function viewHrAccessData()
-    {   
+    {
         $client_id = $this->request->getGet('client_id');
         $data = $this->getHrAccessData($client_id);
         // $data = [];
@@ -6821,7 +6813,8 @@ class ClientController extends AdminController
         $post_client_data = $this->clientModel->where('id', $client_id)->where('is_active', 1)->first();
 
         $hrAccessData['post_hr_data'] = $this->clientBranchModel
-            ->select('lc.id as post_hr_id, lc.name as hr_name, lc.mobile as hr_mobile, lc.email as hr_mail')
+            ->select('lc.id as post_hr_id, lc.name as hr_name, lc.mobile as hr_mobile, lc.email as hr_mail , 
+            client_branch.id as post_branch_id , client_branch.branch_name as post_branch_name')
             ->join('level_contacts lc', 'client_branch.id = lc.ref_id')
             ->where('client_branch.is_active', 1)
             ->where('lc.is_active', 1)
@@ -6830,7 +6823,7 @@ class ClientController extends AdminController
             ->findAll();
 
         $hrAccessData['post_policy_data'] = $this->clientPolicyModel
-            ->select('client_policy.id as client_policy_id, client_policy.policy_no as policy_no, policy_type.policy_type, client_policy.policy_status')
+            ->select('client_policy.id as client_policy_id, client_policy.policy_no as policy_no, policy_type.policy_type, client_policy.policy_status , client_policy.client_branch_id as branch_id')
             ->join('policy_type', 'client_policy.policy_type_id = policy_type.id')
             ->where('client_policy.is_active', 1)
             ->where('client_policy.client_id', $client_id)
@@ -6859,22 +6852,23 @@ class ClientController extends AdminController
 
             $hrAccessData['pre_hr_data'] = [];
             $hrAccessData['pre_policy_data'] = [];
-            $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id);
+            $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id , $pre_client_data['id']??'');
             return $combinedHrAccessData;
         }
 
         $pre_client_data = $db2->table('clients')->where('is_active', 1)->where('short_name', $post_client_data['short_name'])->get()->getRowArray();
 
-        if(empty($pre_client_data)){
+        if (empty($pre_client_data)) {
 
             $hrAccessData['pre_hr_data'] = [];
             $hrAccessData['pre_policy_data'] = [];
-            $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id);
+            $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id , $pre_client_data['id']??'');
             return $combinedHrAccessData;
         }
 
         $hrAccessData['pre_hr_data'] = $db2->table('client_branch')
-            ->select('lc.id as pre_hr_id, lc.name as hr_name, lc.mobile as hr_mobile, lc.email as hr_mail')
+            ->select('lc.id as pre_hr_id, lc.name as hr_name, lc.mobile as hr_mobile, lc.email as hr_mail 
+            , client_branch.id as pre_branch_id , client_branch.branch_name as pre_branch_name ' )
             ->join('level_contacts lc', 'client_branch.id = lc.ref_id')
             ->where('client_branch.is_active', 1)
             ->where('lc.is_active', 1)
@@ -6882,9 +6876,9 @@ class ClientController extends AdminController
             ->where('client_branch.client_id', $pre_client_data['id'])
             ->get()
             ->getResultArray();
-
+        
         $hrAccessData['pre_policy_data'] = $db2->table('client_policy')
-            ->select('client_policy.id as client_policy_id, client_policy.policy_no as policy_no, policy_type.policy_type, client_policy.policy_status')
+            ->select('client_policy.id as client_policy_id, client_policy.policy_no as policy_no, policy_type.policy_type, client_policy.policy_status , client_policy.client_branch_id as branch_id')
             ->join('policy_type', 'client_policy.policy_type_id = policy_type.id')
             ->where('client_policy.is_active', 1)
             ->where('client_policy.client_id',  $pre_client_data['id'])
@@ -6892,16 +6886,16 @@ class ClientController extends AdminController
             ->orderBy('client_policy.policy_status', 'desc')
             ->get()
             ->getResultArray();
-
         // dd($hrAccessData);
 
-        $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id);
+        $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id ,$pre_client_data['id']);
         return $combinedHrAccessData;
     }
 
-    public function constructHrAccessData($data, $client_id)
-    {   
-        // dd($data);
+    public function constructHrAccessData($data, $client_id , $pre_client_id)
+    {
+        // print_rr($data);die;
+
         $preHrs = $data['pre_hr_data'];
         $postHrs = $data['post_hr_data'];
         $hrAccessTableData = $data['hr_access_table_data'];
@@ -6917,7 +6911,10 @@ class ClientController extends AdminController
                         'post_hr_id' => $post['post_hr_id'],
                         'hr_name' => $post['hr_name'],
                         'hr_mobile' => $post['hr_mobile'],
-                        'hr_mail' => $post['hr_mail']
+                        'hr_mail' => $post['hr_mail'],
+                        'pre_branch_id' => $pre['pre_branch_id'] ?? null,
+                        'post_branch_id'   => $post['post_branch_id'] ?? null,
+                        'post_branch_name' => $post['post_branch_name'] ?? null 
                     ];
                     unset($preHrs[$index]); // remove matched pre_hr
                     $found = true;
@@ -6931,7 +6928,10 @@ class ClientController extends AdminController
                     'post_hr_id' => $post['post_hr_id'],
                     'hr_name' => $post['hr_name'],
                     'hr_mobile' => $post['hr_mobile'],
-                    'hr_mail' => $post['hr_mail']
+                    'hr_mail' => $post['hr_mail'],
+                    'pre_branch_id' => $pre['pre_branch_id'] ?? null,
+                    'post_branch_id' => $post['post_branch_id'] ?? null ,
+                    'post_branch_name' => $post['post_branch_name'] ?? null
                 ];
             }
         }
@@ -6943,7 +6943,10 @@ class ClientController extends AdminController
                 'post_hr_id' => null,
                 'hr_name' => $pre['hr_name'],
                 'hr_mobile' => $pre['hr_mobile'],
-                'hr_mail' => $pre['hr_mail']
+                'hr_mail' => $pre['hr_mail'],
+                'pre_branch_id' => $pre['pre_branch_id'] ?? null,
+                'post_branch_id' => $post['post_branch_id'] ?? null ,
+                'post_branch_name' => $post['post_branch_name'] ?? null
             ];
         }
 
@@ -6968,81 +6971,90 @@ class ClientController extends AdminController
                     'hr_name' => $hr['hr_name'] ?? null,
                     'hr_mobile' => $hr['hr_mobile'] ?? null,
                     'hr_mail' => $hr['hr_mail'] ?? null,
+                    'pre_branch_id' => $hr['pre_branch_id'] ?? null,
+                    'post_branch_id' => $hr['post_branch_id'] ?? null ,
+                    'post_branch_name' => $hr['post_branch_name'] ?? null ,
+                    'pre_client_id'    => $pre_client_id ?? null
                 ];
             }
-
         } else {
-                    // First create a map of HR data by post_hr_id for quick lookup
-                    $hrMap = [];
-                    foreach ($merged as $hr) {
-                        $hrMap[$hr['post_hr_id']] = $hr;
-                    }
-                    
-                    // Process access data first
-                    foreach ($hrAccessTableData as $access) {
-                        $post_hr_id = $access['post_hr_id'];
-                        
-                        // Check if this HR exists in our merged data
-                        if (isset($hrMap[$post_hr_id])) {
-                            $hr = $hrMap[$post_hr_id];
-                            $temp_arr_key = $hr['hr_mobile'] . $hr['hr_mail'];
-                            
-                            // Parse allowed modules
-                            $allowed_modules = json_decode($access['allowed_modules'], true) ?? null;
-                            $allowed_pre_modules = $allowed_modules['pre'] ?? [];
-                            $allowed_post_modules = $allowed_modules['post'] ?? [];
-                            
-                            $result[$temp_arr_key] = [
-                                'hr_access_table_pk' => $access['id'] ?? null,
-                                'post_client_id' => $access['post_client_id'] ?? null,
-                                'pre_hr_id' => $hr['pre_hr_id'] ?? null,
-                                'post_hr_id' => $hr['post_hr_id'] ?? null,
-                                'allowed_pre_modules' => $allowed_pre_modules,
-                                'allowed_post_modules' => $allowed_post_modules,
-                                'allowed_pre_policies' => json_decode($access['allowed_pre_policies'], true) ?? [],
-                                'allowed_active_policies' => json_decode($access['allowed_active_policies'], true) ?? [],
-                                'allowed_cd' => json_decode($access['allowed_cd'], true) ?? [],
-                                'hr_name' => $hr['hr_name'],
-                                'hr_mobile' => $hr['hr_mobile'],
-                                'hr_mail' => $hr['hr_mail']
-                            ];
-                            
-                            // Remove from map so we know it's been processed
-                            unset($hrMap[$post_hr_id]);
-                        }
-                    }
-                    
-                    // Now process any remaining HRs that didn't have access records
-                    foreach ($hrMap as $hr) {
-                        $temp_arr_key = $hr['hr_mobile'] . $hr['hr_mail'];
-                        
-                        $result[$temp_arr_key] = [
-                            'hr_access_table_pk' => null,
-                            'post_client_id' => $client_id ?? null,
-                            'pre_hr_id' => $hr['pre_hr_id'] ?? null,
-                            'post_hr_id' => $hr['post_hr_id'] ?? null,
-                            'allowed_pre_modules' => [],
-                            'allowed_post_modules' => [],
-                            'allowed_pre_policies' => [],
-                            'allowed_active_policies' => [],
-                            'allowed_cd' => [],
-                            'hr_name' => $hr['hr_name'] ?? null,
-                            'hr_mobile' => $hr['hr_mobile'] ?? null,
-                            'hr_mail' => $hr['hr_mail'] ?? null,
-                        ];
-                    }
-        }
-        
+            // First create a map of HR data by post_hr_id for quick lookup
+            $hrMap = [];
+            foreach ($merged as $hr) {
+                $hrMap[$hr['post_hr_id']] = $hr;
+            }
 
-        $resultData['hr_access_data'] = array_values($result);
-        $resultData['pre_policy_data'] = $data['pre_policy_data'];
+            // Process access data first
+            foreach ($hrAccessTableData as $access) {
+                $post_hr_id = $access['post_hr_id'];
+
+                // Check if this HR exists in our merged data
+                if (isset($hrMap[$post_hr_id])) {
+                    $hr = $hrMap[$post_hr_id];
+                    $temp_arr_key = $hr['hr_mobile'] . $hr['hr_mail'];
+
+                    // Parse allowed modules
+                    $allowed_modules = json_decode($access['allowed_modules'], true) ?? null;
+                    $allowed_pre_modules = $allowed_modules['pre'] ?? [];
+                    $allowed_post_modules = $allowed_modules['post'] ?? [];
+
+                    $result[$temp_arr_key] = [
+                        'hr_access_table_pk' => $access['id'] ?? null,
+                        'post_client_id' => $access['post_client_id'] ?? null,
+                        'pre_hr_id' => $hr['pre_hr_id'] ?? null,
+                        'post_hr_id' => $hr['post_hr_id'] ?? null,
+                        'allowed_pre_modules' => $allowed_pre_modules,
+                        'allowed_post_modules' => $allowed_post_modules,
+                        'allowed_pre_policies' => json_decode($access['allowed_pre_policies'], true) ?? [],
+                        'allowed_active_policies' => json_decode($access['allowed_active_policies'], true) ?? [],
+                        'allowed_cd' => json_decode($access['allowed_cd'], true) ?? [],
+                        'hr_name' => $hr['hr_name'],
+                        'hr_mobile' => $hr['hr_mobile'],
+                        'hr_mail' => $hr['hr_mail'],
+                        'pre_branch_id' => $hr['pre_branch_id'] ?? null,
+                        'post_branch_id' => $hr['post_branch_id'] ?? null ,
+                        'post_branch_name' => $hr['post_branch_name'] ?? null ,
+                        'pre_client_id'    => $pre_client_id ?? null
+                    ];
+
+                    // Remove from map so we know it's been processed
+                    unset($hrMap[$post_hr_id]);
+                }
+            }
+
+            // Now process any remaining HRs that didn't have access records
+            foreach ($hrMap as $hr) {
+                $temp_arr_key = $hr['hr_mobile'] . $hr['hr_mail'];
+
+                $result[$temp_arr_key] = [
+                    'hr_access_table_pk' => null,
+                    'post_client_id' => $client_id ?? null,
+                    'pre_hr_id' => $hr['pre_hr_id'] ?? null,
+                    'post_hr_id' => $hr['post_hr_id'] ?? null,
+                    'allowed_pre_modules' => [],
+                    'allowed_post_modules' => [],
+                    'allowed_pre_policies' => [],
+                    'allowed_active_policies' => [],
+                    'allowed_cd' => [],
+                    'hr_name' => $hr['hr_name'] ?? null,
+                    'hr_mobile' => $hr['hr_mobile'] ?? null,
+                    'hr_mail' => $hr['hr_mail'] ?? null,
+                    'pre_branch_id' => $hr['pre_branch_id'] ?? null,
+                    'post_branch_id' => $hr['post_branch_id'] ?? null ,
+                    'post_branch_name' => $hr['post_branch_name'] ?? null ,
+                    'pre_client_id'    => $pre_client_id ?? null
+                ];
+            }
+        }
+
+
+        $resultData['hr_access_data']   = array_values($result);
+        $resultData['pre_policy_data']  = $data['pre_policy_data'];
         $resultData['post_policy_data'] = $data['post_policy_data'];
-        $resultData['post_cd_data'] = $data['post_cd_data'];
-        // echo '**********************************************';
-        // print_rr($resultData);die();
+        $resultData['post_cd_data']     = $data['post_cd_data'];
 
         return $resultData;
-    }
+    }       
 
     public function saveHrAccessData()
     {
@@ -7082,6 +7094,10 @@ class ClientController extends AdminController
 
                     // INSERT or UPDATE
                     if (empty($value['pk']) || (int)$value['pk'] === 0) {
+                        print_rr("inside insert block");
+                        print_rr($value);die;
+
+
                         unset($value['pk']); // Prevent insert error
                         $insertedId = $this->HRAccessControlModel->insert($value);
                         if ($insertedId === false) {
@@ -7090,6 +7106,9 @@ class ClientController extends AdminController
                         $success[] = "Inserted row at index {$index} with ID {$insertedId}.";
                     } else {
                         $update = $this->HRAccessControlModel->update($value['pk'], $value);
+                        print_rr("inside update block");
+                        print_rr($value);die;
+
                         if ($update === false) {
                             throw new \Exception('Update failed for ID ' . $value['pk'] . ': ' . json_encode($this->HRAccessControlModel->errors()));
                         }
@@ -7123,7 +7142,6 @@ class ClientController extends AdminController
                     'details' => $success,
                     'data' => $html,
                 ], 200);
-
             } else {
                 return $this->respond([
                     'status' => false,
@@ -7461,6 +7479,84 @@ class ClientController extends AdminController
 
         return $this->respond(['status' => true, 'message' => 'Demo client data wiped successfully'], 200);
     }
+
+    private function getClientlistFromPre (){
+        $db2 = \Config\Database::connect('preDB');
+
+        $auto_fetch_client_list = $db2->table('clients')
+        ->select('id,client_name')
+        ->where('is_active',1)
+        ->get()->getResultArray()??[];
+
+        return $auto_fetch_client_list;
+
+    }
+
+    public function auto_fetch_branch(){
+
+        $data = $this->request->getPost();
+
+        $db2 = \Config\Database::connect('preDB');
+
+        $auto_fetch_branch_list = $db2->table('client_branch')
+        ->select('id,branch_name')
+        ->where('client_id',$data['client_id'])
+        ->where('is_active',1)
+        ->get()->getResultArray()??[];
+
+        return 
+
+        empty($auto_fetch_branch_list)
+
+        ? $this->response->setJSON([
+                'status' => false,
+                'message' => 'branch list is empty',
+                'data' => []
+            ])->setStatusCode(400)
+        
+        :   $this->response->setJSON([
+                'status' => true,
+                'message' => 'branch list is found' ,
+                 'data' => $auto_fetch_branch_list
+            ])->setStatusCode(200);
+    }
+
+    public function auto_fetch_branch_details(){
+
+        $data = $this->request->getPost();
+
+        $db2 = \Config\Database::connect('preDB');
+
+        $auto_fetch_branch_details = $db2->table('client_branch')
+                                        ->where('client_id',$data['client_id'])
+                                        ->where('id',$data['branch_id'])
+                                        ->where('is_active',1)
+                                        ->get()->getResultArray()??[];
+
+        return empty($auto_fetch_branch_details)
+
+                    ? $this->response->setJSON([
+                            'status' => false,
+                            'message' => 'branch details is empty',
+                            'data' => []
+                        ])->setStatusCode(400)
+                    
+                    :   $this->response->setJSON([
+                            'status' => true,
+                            'message' => 'branch details found' ,
+                            'data' => $auto_fetch_branch_details
+                        ])->setStatusCode(200);
+
+    }
+
+
+
+
+
+
+
+
+
+
+
 }
-
-
diff --git a/app/Models/ClientBranchModel.php b/app/Models/ClientBranchModel.php
index 100f503d..a813221a 100755
--- a/app/Models/ClientBranchModel.php
+++ b/app/Models/ClientBranchModel.php
@@ -25,6 +25,7 @@ class ClientBranchModel extends Model
         "gst",
         "sez",
         "units",
+        "pre_branch_id"
     ];
 
     public function getBranchAndContactByBranchId($branch_id){
diff --git a/app/Models/HRAccessControlModel.php b/app/Models/HRAccessControlModel.php
index a9a4e2c7..a754536d 100644
--- a/app/Models/HRAccessControlModel.php
+++ b/app/Models/HRAccessControlModel.php
@@ -13,6 +13,9 @@ class HRAccessControlModel extends Model
         'pre_hr_id',
         'post_hr_id',
         'post_client_id',
+        'pre_client_id',
+        'pre_branch_id',
+        'post_branch_id',
         'allowed_modules',
         'allowed_pre_policies',
         'allowed_active_policies',
diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php
index 33314cc9..5db4a112 100755
--- a/app/Views/client_branch.php
+++ b/app/Views/client_branch.php
@@ -70,6 +70,13 @@
     
+ + +
+ +
+
+
+ +
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/app/Views/hr_access_controll.php b/app/Views/hr_access_controll.php index 1cf40c7a..cbd2838e 100644 --- a/app/Views/hr_access_controll.php +++ b/app/Views/hr_access_controll.php @@ -65,7 +65,10 @@
- +
$value) { @@ -79,13 +82,17 @@ + + +
@@ -128,6 +135,15 @@ $policies) { $statusText = $policies['policy_status'] == 1 ? 'Active' : 'In-Active'; $statusClass = $policies['policy_status'] == 1 ? 'active' : 'inactive'; + if ( + in_array($policies['branch_id'].'-'.$policies['policy_no'], $listed_pre) + && + $value['pre_branch_id'] != $policies['branch_id'] + ) { + continue; + } else { + $listed_pre[] = $policies['branch_id'].'-'.$policies['policy_no']; + } ?>
$policies) { $statusText = $policies['policy_status'] == 1 ? 'Active' : 'In-Active'; $statusClass = $policies['policy_status'] == 1 ? 'active' : 'inactive'; + if( + in_array($policies['branch_id'].'-'.$policies['policy_no'] , $listed_post) + && + $value['post_branch_id'] != $policies['branch_id'] + ) + { + continue; + } + else + { + $listed_post[] = $policies['branch_id'].'-'.$policies['policy_no']; + } + ?>
> +