diff --git a/.gitignore b/.gitignore index 2e2d6962..a599a01e 100755 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,8 @@ writable/**/*.sqlite writable/e_card_template/* !writable/e_card_template/.gitkeep +writable/tmp/* +!writable/tmp/.gitkeep vendor/ build/ diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 586665eb..683cc3c1 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1,6 +1,7 @@ policyTransactionModel = new PolicyTransactionModel(); $this->policyTransactionStatusModel = new PolicyTransactionStatusModel(); $this->vehicleModel = new VehicleModel(); - - - - - - - } - + public function Testing() //this function for only tsesting some logics not use for business logic - { - // $empDataServiceController = new EmpDataServiceController(); - // $empDataServiceController->storeEndorsementNumber(23, '00000000000000000560'); + { + $emp_code = 'MGL-004'; + $client_id = 77; + $client_policy_id = 206; + $array_list = []; + + $find = $this->employeeModel->getEmpFamilybyEmpCode(client_policy_id: $client_policy_id, 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(); + + // dd($notification); + + 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; + + // print_r($params);die; + + $wholeData = sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params); + + // print_r($wholeData); die; + + $mail_send_return = MailHelper::send_email($wholeData[0]); + $this->myLogger->logme("info", $mail_send_return); + + if (isset($wholeData[0])) { + + $account_manager_wholeData = sendMailNotification::sendMailNotification('account_maneger_summary_mail', $params); + + // print_r($account_manager_wholeData); die; + + if ($account_manager_wholeData) { + + foreach ($account_manager_wholeData as $key => $value) { + $mail_send_return1 = MailHelper::send_email($value); + $this->myLogger->logme("info", $mail_send_return1); + $this->myLogger->logme("info", $mail_send_return1); + } + } + + $client_hr_wholeData = sendMailNotification::sendMailNotification('client_hr_summary_mail', $params); + + // print_r($client_hr_wholeData); die; + + if ($client_hr_wholeData) { + + foreach ($client_hr_wholeData as $key => $value) { + $mail_send_return2 = MailHelper::send_email($value); + $this->myLogger->logme("info", $mail_send_return2); + } + } + } + } + + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200); } - + public function index() - { - $this->myLogger->logme('error','Client list function called'); + { + $this->myLogger->logme('error', 'Client list function called'); $headerData['page_name'] = 'Client List'; $data['clientList'] = $this->clientModel->getCreatedByUserName(); $data['client_rm'] = $this->clientRMModel->getAllClientRM(); @@ -146,7 +205,6 @@ class ClientController extends AdminController $return = $this->clientPolicyModel->updateStatus(); $this->myLogger->logme('error', 'Client Policy Status Update Count: {data}', ['data' => $return['client']]); $this->myLogger->logme('error', 'Employee Policy Status Update Count: {data}', ['data' => $return['emp']]); - } public function updatePolicyTermsForCorrections() @@ -166,7 +224,7 @@ class ClientController extends AdminController foreach ($results as $key => $result) { $client_policy_id = $result['id']; $policy_terms = json_decode($result['policy_terms'], true); // true to get associative array - + if (isset($policy_terms['family_floaters'])) { $family_floaters = $policy_terms['family_floaters']; $parents = $family_floaters['parents'] ?? 0; @@ -191,12 +249,12 @@ class ClientController extends AdminController } } } - - if(count($client_policy_ids) > 0){ + + if (count($client_policy_ids) > 0) { echo 'There are ' . count($client_policy_ids) . ' records to be updated.'; echo '
'; dd($client_policy_ids); - }else{ + } else { echo 'There is no records to be update.'; } // dd($results); @@ -204,31 +262,29 @@ class ClientController extends AdminController } public function removeClient($id = null) - { - $this->myLogger->logme('error','Client Remove function called'); + { + $this->myLogger->logme('error', 'Client Remove function called'); $client_policy_data = $this->clientPolicyModel - ->where('policy_status', 1) - ->where('Is_active', 1) - ->where('client_id', $id) - ->countAllResults(); - if($client_policy_data == 0){ + ->where('policy_status', 1) + ->where('Is_active', 1) + ->where('client_id', $id) + ->countAllResults(); + if ($client_policy_data == 0) { $data['updated_by'] = get_session_userid(); $data['is_active'] = 0; - $update = $this->clientModel->update($id,$data); - return $this->respond(['status' => true,'code' => 200], 200); + $update = $this->clientModel->update($id, $data); + return $this->respond(['status' => true, 'code' => 200], 200); + } else { - }else{ - - return $this->respond(['status' => false,'code' => 404, 'message' => 'The Client has active policy'], 200); + return $this->respond(['status' => false, 'code' => 404, 'message' => 'The Client has active policy'], 200); } - } public function removeClientBranch($id = null) - { - $this->myLogger->logme('error','Client Branch Remove function called'); + { + $this->myLogger->logme('error', 'Client Branch Remove function called'); $data = [ 'updated_by' => get_session_userid(), @@ -236,56 +292,55 @@ class ClientController extends AdminController ]; $config_count = $this->clientPolicyModel->where('client_branch_id', $id)->countAllResults(); - - if($config_count > 0){ + + if ($config_count > 0) { $update = $this->clientBranchModel->where('id', $id)->set($data)->update(); - if($update){ - return $this->respond(['status' => true,'code' => 200, 'message' => 'Client branch removed successfully'], 200); - }else{ - return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to remove client branch'], 200); + if ($update) { + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Client branch removed successfully'], 200); + } else { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to remove client branch'], 200); } - }else{ + } else { - return $this->respond(['status' => false,'code' => 404, 'message' => 'The client branch configuration with policy cannot be deleted.'], 200); + return $this->respond(['status' => false, 'code' => 404, 'message' => 'The client branch configuration with policy cannot be deleted.'], 200); } } public function clientOnboarding() { - $this->myLogger->logme('error','Client Onboarding function called'); + $this->myLogger->logme('error', 'Client Onboarding function called'); $headerData['page_name'] = 'Client Onboarding'; $data['entity'] = $this->kycEntityTypeModel->findAll(); $data['kyc_docs'] = $this->kycDocsModel->findAll(); $data['police'] = $this->policesModel->findAll(); - $data['insurer'] = $this->insurerBranchModel ->getInsurerBranchesWithInsurerNames(); - $data['tpa'] = $this->tpaBranchModel ->getTpaBranchesWithTpaNames(); + $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); + $data['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames(); $data['state'] = $this->stateModel->getAllStates(); $data['RM'] = $this->userModel->findAll(); $data['policyGridData'] = $this->policyGridModel->findAll(); $data['policy_types'] = $this->policyTypeModel->findAll(); - $data['policy_type'] = ['1'=>'Base Policy', '2' => 'SI Topup', '3' => 'Dependent Addon']; - $data['client_type'] = ['1'=>'Group', '2' => 'Retail']; - + $data['policy_type'] = ['1' => 'Base Policy', '2' => 'SI Topup', '3' => 'Dependent Addon']; + $data['client_type'] = ['1' => 'Group', '2' => 'Retail']; + // echo "
";
         // print_r($data); die;
-        $data['placeHolders'] = ['member_name','nhance_logo','tpa_id','ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
+        $data['placeHolders'] = ['member_name', 'nhance_logo', 'tpa_id', 'ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
 
         // dd($data['placeHolders']);
 
         echo view('layout/header', $headerData);
         echo view('client_onboarding', $data);
         echo view('layout/footer');
-
-    }   
+    }
 
     // In your controller
     public function deposit($id = null)
     {
         $headerData['page_name'] = 'Client Deposit';
 
-        $data['clientName'] = $this->clientModel->where('id',$id)->find();
+        $data['clientName'] = $this->clientModel->where('id', $id)->find();
         $data['clientData'] = $this->clientPolicyModel->getinsurerswithclientid($id);
         $data['depositsummary'] = $this->clientPolicyModel->getDepositlistsummary($id);
 
@@ -297,8 +352,8 @@ class ClientController extends AdminController
         echo view('client_deposit_list', $data);
         echo view('layout/footer');
     }
-   
-    public function view_Deposit($insurerId) 
+
+    public function view_Deposit($insurerId)
     {
         // Load your model to fetch data based on $clientId and $insurerId
         // $subTypeOptions = [
@@ -324,17 +379,17 @@ class ClientController extends AdminController
         $loggedInUserID = get_session_userid();
         // $data['clientData']= $this->clientPolicyModel->getinsurerswithinsurenceid($insurerId);
         $clientId = $this->request->getGet('client_id');
-        $data['insurerName']= $this->insurerModel->getInsurerName($insurerId, $clientId);
-        $data['depositdata']= $this->clientPolicyModel->getdepositData($clientId,$insurerId); 
+        $data['insurerName'] = $this->insurerModel->getInsurerName($insurerId, $clientId);
+        $data['depositdata'] = $this->clientPolicyModel->getdepositData($clientId, $insurerId);
         $data['clientData'] = $this->clientPolicyModel->getClientById($clientId);
-        $data['deposiamount'] = $this->clientPolicyModel->getDepositSummary($clientId, $insurerId);  
-        
+        $data['deposiamount'] = $this->clientPolicyModel->getDepositSummary($clientId, $insurerId);
+
         // dd($data['depositdata']);
-        
+
         // print_r($data['depositdata'] );die;
         // Load the view for the new list page;
         echo view('layout/header', $headerData);
-        echo view('view_deposit',$data);
+        echo view('view_deposit', $data);
         echo view('layout/footer');
     }
 
@@ -347,9 +402,9 @@ class ClientController extends AdminController
         $insurer_id = $this->request->getPost('insurer_id');
 
         $CD_Account_Number = $this->CDMasterModel
-                ->where('client_id', $client_id)
-                ->where('insurer_id', $insurer_id)
-                ->first();
+            ->where('client_id', $client_id)
+            ->where('insurer_id', $insurer_id)
+            ->first();
 
         // Prepare the array with data
         $data = [
@@ -375,22 +430,22 @@ class ClientController extends AdminController
     }
 
     public function editClientOnboarding($id = null)
-    {    
+    {
 
-        $this->myLogger->logme('error','Edit Client Onboarding function called');
+        $this->myLogger->logme('error', 'Edit Client Onboarding function called');
         $headerData['page_name'] = 'Edit Client Onboarding';
 
         $editData['RM']             = $this->userModel->findAll();
-        $editData['tpa']            = $this->tpaBranchModel ->getTpaBranchesWithTpaNames();
+        $editData['tpa']            = $this->tpaBranchModel->getTpaBranchesWithTpaNames();
         $editData['state']          = $this->stateModel->getAllStates();
         $editData['police']         = $this->policesModel->findAll();
         $editData['entity']         = $this->kycEntityTypeModel->findAll();
-        $editData['insurer']        = $this->insurerBranchModel ->getInsurerBranchesWithInsurerNames();
+        $editData['insurer']        = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames();
         $editData['kyc_docs']       = $this->kycDocsModel->findAll();
         $editData['policyGridData'] = $this->policyGridModel->findAll();
         $editData['policy_types'] = $this->policyTypeModel->findAll();
-        $editData['policy_type'] = ['1'=>'Base Policy', '2' => 'SI Topup', '3' => 'Dependent Addon'];
-        $editData['client_type'] = ['1'=>'Group', '2' => 'Retail'];
+        $editData['policy_type'] = ['1' => 'Base Policy', '2' => 'SI Topup', '3' => 'Dependent Addon'];
+        $editData['client_type'] = ['1' => 'Group', '2' => 'Retail'];
 
         // dd($editData['policy_types']);
 
@@ -402,7 +457,7 @@ class ClientController extends AdminController
         $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($id);
 
         foreach ($clientPoliceData as $key => $value) {
-            
+
             $clientPoliceData[$key]->policy_start_date = date('d-M-Y', strtotime($value->policy_start_date));
             $clientPoliceData[$key]->open_date = date('d-M-Y', strtotime($value->open_date));
             $clientPoliceData[$key]->policy_end_date = date('d-M-Y', strtotime($value->policy_end_date));
@@ -411,20 +466,19 @@ class ClientController extends AdminController
 
         $editData['client_policy']    = $clientPoliceData;
         $editData['client_policy']['role'] = get_role_id();
-        $editData['notification'] =$this->notificationModel->select('template_name,enabled')->where('client_id',$id)->findAll();
-        $editData['placeHolders'] = ['member_name','nhance_logo','tpa_id','ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
+        $editData['notification'] = $this->notificationModel->select('template_name,enabled')->where('client_id', $id)->findAll();
+        $editData['placeHolders'] = ['member_name', 'nhance_logo', 'tpa_id', 'ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
 
         // dd($editData);
         echo view('layout/header', $headerData);
         echo view('client_onboarding', $editData);
         echo view('layout/footer');
-
     }
-     
+
     public function createClientGeneralInfo()
     {
 
-        $this->myLogger->logme('error','Client general info function called');
+        $this->myLogger->logme('error', 'Client general info function called');
         $uploadFilePath = ROOTPATH . 'public/uploads/logo/';
         $file_name = file_Upload($this->request->getFile('client_logo'), $uploadFilePath);
         $data   = $this->request->getPost();
@@ -440,27 +494,25 @@ class ClientController extends AdminController
         }
 
         $insert = $this->clientModel->insert($data);
-        if($insert){
+        if ($insert) {
             $client_data = $this->clientModel->where(['id' => $insert, 'is_active' => 1])->first();
-            return $this->respond(['status' => true,'code' => 200,'data' => $client_data], 200);
-
-        }else{
-            return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
-
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $client_data], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
 
     public function editClientGeneralInfo()
     {
-        $this->myLogger->logme('error','edit client general info function called');
+        $this->myLogger->logme('error', 'edit client general info function called');
         $uploadFilePath = ROOTPATH . 'public/uploads/logo/';
         $file_name = file_Upload($this->request->getFile('client_logo'), $uploadFilePath);
         $id                 = $this->request->getPost('PrimaryKey');
 
         $data               = $this->request->getPost();
         $data['updated_by'] = get_session_userid();
-        
-        if(!empty($file_name)){
+
+        if (!empty($file_name)) {
             $data['client_logo'] = $file_name;
         }
 
@@ -469,56 +521,55 @@ class ClientController extends AdminController
         } elseif ($data['is_download_btn']) {
             $data['is_download_btn'] = 1;
         }
-        
+
         // print_r($data);die;
 
-        $update             = $this->clientModel->update($id,$data);
+        $update             = $this->clientModel->update($id, $data);
 
 
-        if($update){
-            return $this->respond(['status' => true,'code' => 200,'data' => $data], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
+        if ($update) {
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
-    
+
 
 
     public function createClientKYCInfo()
     {
-        $this->myLogger->logme('error','create Client kyc function called');  
-        $data = $this->request->getPost();     
+        $this->myLogger->logme('error', 'create Client kyc function called');
+        $data = $this->request->getPost();
         // print_r($data); die;
-        unset($data['file_name']); 
+        unset($data['file_name']);
         $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents';
         $File = file_Upload($this->request->getFile('file_name'), $uploadFilePath);
-        if(!empty($File)){
-            
+        if (!empty($File)) {
+
             $data['file_name'] = $File;
-            $uploadFilePath = $uploadFilePath . '/' .$File;
-            $GoogleDriveController = new GoogleDriveController();
-            $GoogleDriveController->uploadFiletoGdrive(client_id: $data['client_id'], doc_type: 'KYC', file_path: $uploadFilePath, file_name: $data['file_name']);
-    
+            // $uploadFilePath = $uploadFilePath . '/' . $File;
+            // $GoogleDriveController = new GoogleDriveController();
+            // $GoogleDriveController->uploadFiletoGdrive(client_id: $data['client_id'], doc_type: 'KYC', file_path: $uploadFilePath, file_name: $data['file_name']);
         }
 
         $data['created_by'] = get_session_userid();
         $insert = $this->clientKYCDocsModel->insert($data);
-        if($insert){
+        if ($insert) {
 
-            $kycDocs = $this->clientKYCDocsModel->where('client_id',$this->request->getPost('client_id'))->findAll();
-            return $this->respond(['status' => true,'code' => 200,'data' => $kycDocs, 'file_name' => $File], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
+            $kycDocs = $this->clientKYCDocsModel->where('client_id', $this->request->getPost('client_id'))->findAll();
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $kycDocs, 'file_name' => $File], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
 
     public function editClientKYCInfo()
     {
-       
-        $this->myLogger->logme('error','edit client kyc function called');        
+
+        $this->myLogger->logme('error', 'edit client kyc function called');
         $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents';
         $File = file_Upload($this->request->getFile('file_name'), $uploadFilePath);
-        if(!empty($File)){
+        if (!empty($File)) {
             $data['file_name'] = $File;
         }
         $id                 = $this->request->getPost('PrimaryKey');
@@ -526,34 +577,33 @@ class ClientController extends AdminController
         $data['kyc_doc_type_id'] = $this->request->getPost('kyc_doc_id');
         $data['updated_by'] = get_session_userid();
         $insert = $this->clientKYCDocsModel->insert($data);
-        if($insert){
+        if ($insert) {
             $kycDocs = $this->clientKYCDocsModel->getKycDocsName($id);
-            return $this->respond(['status' => true,'code' => 200,'data' => $kycDocs], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
-
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $kycDocs], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
 
-    public function deleteClientKycDocs($id=null)
+    public function deleteClientKycDocs($id = null)
     {
-        
+
         $delete = $this->clientKYCDocsModel->where('kyc_doc_type_id', $id)->delete();
-        if($delete){
-            return $this->respond(['status' => true,'code' => 200,'id' => $id], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
+        if ($delete) {
+            return $this->respond(['status' => true, 'code' => 200, 'id' => $id], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
 
-    public function deleteClientKycOtherDocs($id=null)
+    public function deleteClientKycOtherDocs($id = null)
     {
-        
+
         $delete = $this->clientKYCDocsModel->where('id', $id)->delete();
-        if($delete){
-            return $this->respond(['status' => true,'code' => 200,'id' => $id], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
+        if ($delete) {
+            return $this->respond(['status' => true, 'code' => 200, 'id' => $id], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
 
@@ -562,24 +612,24 @@ class ClientController extends AdminController
     public function createClientRelation()
     {
 
-        $this->myLogger->logme('error','Client relation function called');
+        $this->myLogger->logme('error', 'Client relation function called');
 
         $data['client_id'] = $this->request->getPost('client_id');
         $data['created_by'] = get_session_userid();
-        $inserted = false; 
-        
+        $inserted = false;
+
         if ($this->request->getPost('head')) {
             $data['level'] = "1";
             $data['user_id'] = $this->request->getPost('head');
             $inserted = $this->clientRMModel->insert($data);
         }
-        
+
         if ($this->request->getPost('manager')) {
             $data['level'] = "2";
             $data['user_id'] = $this->request->getPost('manager');
             $inserted = $this->clientRMModel->insert($data);
         }
-        
+
         if ($this->request->getPost('account_manager')) {
             $data['level'] = "3";
             foreach ($this->request->getPost('account_manager') as $value) {
@@ -587,47 +637,47 @@ class ClientController extends AdminController
                 $inserted = $this->clientRMModel->insert($data);
             }
         }
-        
+
         if ($inserted) {
-            return $this->respond(['status' => true,'code' => 200,'data' => $this->request->getPost()], 200);
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $this->request->getPost()], 200);
         } else {
-            return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
 
     public function editClientRelation()
     {
-        $this->myLogger->logme('error','Client relation function called');
-        
+        $this->myLogger->logme('error', 'Client relation function called');
+
         $id                 = $this->request->getPost('PrimaryKey');
         $data['client_id']  = $this->request->getPost('client_id');
         $data['updated_by'] = get_session_userid();
-        $inserted = false; 
-        
+        $inserted = false;
+
         if ($this->request->getPost('head')) {
             $data['user_id'] = $this->request->getPost('head');
             $checkHead = $this->clientRMModel->checkExistenceOfClientRelation($id, $this->request->getPost('head'), 1);
-            if($checkHead){
-                $inserted = $this->clientRMModel->where('client_id', $id )->where('level', 1)->set($data)->update();
-            }else{
+            if ($checkHead) {
+                $inserted = $this->clientRMModel->where('client_id', $id)->where('level', 1)->set($data)->update();
+            } else {
                 $data['level'] = "1";
                 $data['user_id'] = $this->request->getPost('head');
                 $inserted = $this->clientRMModel->insert($data);
             }
         }
-        
+
         if ($this->request->getPost('manager')) {
             $data['user_id'] = $this->request->getPost('manager');
             $checkHead = $this->clientRMModel->checkExistenceOfClientRelation($id, $this->request->getPost('manager'), 2);
-            if($checkHead){
-                $inserted = $this->clientRMModel->where('client_id', $id )->where('level', 2)->set($data)->update();
-            }else{
+            if ($checkHead) {
+                $inserted = $this->clientRMModel->where('client_id', $id)->where('level', 2)->set($data)->update();
+            } else {
                 $data['level'] = "2";
                 $data['user_id'] = $this->request->getPost('manager');
                 $inserted = $this->clientRMModel->insert($data);
             }
         }
-        
+
         if ($this->request->getPost('account_manager')) {
 
             $this->clientRMModel->where('client_id', $id)->where('level', 3)->delete();
@@ -637,21 +687,21 @@ class ClientController extends AdminController
                 $inserted = $this->clientRMModel->insert($data);
             }
         }
-        
+
         $lastQuery = $this->clientRMModel->getLastQuery();
 
         if ($inserted) {
-            return $this->respond(['status' => true,'code' => 200,'data' => $this->request->getPost(), "place" => 'edit'], 200);
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $this->request->getPost(), "place" => 'edit'], 200);
         } else {
-            return $this->respond(['status' => false,'code' => 404,"place" => 'edit', 'message' => 'no data found'], 200);
+            return $this->respond(['status' => false, 'code' => 404, "place" => 'edit', 'message' => 'no data found'], 200);
         }
     }
 
-    
+
     public function createClientBranch()
     {
 
-        $this->myLogger->logme('error','Client branch CREATE function called');
+        $this->myLogger->logme('error', 'Client branch CREATE function called');
         $data   = $this->request->getPost();
         // var_dump($data); die;
         if (!isset($data['sez'])) {
@@ -667,11 +717,11 @@ class ClientController extends AdminController
             $default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-');
             $data['units'] = json_encode([$default_unit]);
         }
-        
+
         $data['created_by'] = get_session_userid();
-        $insert = $this->clientBranchModel->insert($data); 
-        
-        if($insert){
+        $insert = $this->clientBranchModel->insert($data);
+
+        if ($insert) {
             for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
                 // Prepare data to insert
                 $data = [
@@ -687,7 +737,7 @@ class ClientController extends AdminController
             }
         }
 
-        if($insert){
+        if ($insert) {
             $branchData = $this->clientBranchModel->where('client_id', $this->request->getPost('client_id'))->findAll();
             $branchData['role'] = get_role_id();
             return $this->respond([
@@ -696,10 +746,10 @@ class ClientController extends AdminController
                 'data' => $branchData,
                 'message' => 'Client branch created successfully',
             ], 200);
-        }else{
+        } else {
             return $this->respond([
                 'status' => false,
-                'code' => 404, 
+                'code' => 404,
                 'message' => 'Failed to create client branch ',
             ], 200);
         }
@@ -708,7 +758,7 @@ class ClientController extends AdminController
     public function editClientBranch()
     {
 
-        $this->myLogger->logme('error','Client branch EDIT function called');
+        $this->myLogger->logme('error', 'Client branch EDIT function called');
         $id     = $this->request->getPost('branch_id_primarykey');
         $client_id     = $this->request->getPost('client_id');
         $data   = $this->request->getPost();
@@ -718,7 +768,7 @@ class ClientController extends AdminController
         $rr_unit_count = 0;
         $rr_unit_count2 = 0;
         $total_count = 0;
-        
+
         $list_of_branch_units = $this->clientBranchModel->find($id);
         $units = json_decode($list_of_branch_units['units']);
 
@@ -727,14 +777,14 @@ class ClientController extends AdminController
             $default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-');
             $data['units'] = json_encode([$default_unit]);
         }
-        
+
         if (!empty($units)) {
             foreach ($units as $unit) {
                 $emp_unit_count += $this->employeeModel->where('unit', $unit)->countAllResults();
                 $rr_unit_count += $this->policyPremium2Model->where('unit', $unit)->countAllResults();
                 $rr_unit_count2 += $this->policyPremium1Model->where('unit', $unit)->countAllResults();
             }
-        
+
             $total_count = $emp_unit_count + $rr_unit_count + $rr_unit_count2;
         }
 
@@ -742,13 +792,13 @@ class ClientController extends AdminController
 
         if ($total_count > 0) {
             $units = (string) $this->request->getPost('units'); // Assuming 'units' is an array
-        
+
             $list_of_branch_units = $this->clientBranchModel->find($id);
             $branch_units = json_decode($list_of_branch_units['units'], true);
             $units = json_decode($units);
-        
+
             $uncommonValues = array_diff($branch_units, $units);
-        
+
             if (count($uncommonValues) > 0) {
 
                 $branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll();
@@ -758,11 +808,11 @@ class ClientController extends AdminController
                     'code' => 404,
                     'message' => "Deleted unit(s) in use. couldn't complete this operation.",
                     'uncommonValues' => $uncommonValues,
-                    'data' => $branchData, 
+                    'data' => $branchData,
                 ], 200);
             }
         }
-        
+
         if (!isset($data['sez'])) {
             $data['sez'] = 0;
         } elseif ($data['sez']) {
@@ -771,10 +821,10 @@ class ClientController extends AdminController
 
         $data['updated_by'] = get_session_userid();
         $insert = $this->clientBranchModel->update($id, $data);
-        $this->myLogger->logme('error','Client branch EDITED by {data}', ['data' => get_session_userid()]);
+        $this->myLogger->logme('error', 'Client branch EDITED by {data}', ['data' => get_session_userid()]);
 
 
-        if($insert){
+        if ($insert) {
 
             $this->levelContactModel->where('ref_id', $id)->where('contact_type', 'client')->delete();
             for ($i = 0; $i < count($this->request->getPost('name')); $i++) {
@@ -791,13 +841,13 @@ class ClientController extends AdminController
             }
         }
 
-        if($insert){
+        if ($insert) {
             $branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll();
             return $this->respond([
                 'status' => true,
                 'code' => 200,
-                'data' => $branchData, 
-                'emp_unit_count' => $emp_unit_count,  
+                'data' => $branchData,
+                'emp_unit_count' => $emp_unit_count,
                 'rr_unit_count' => $rr_unit_count,
                 'list_of_branch_units' => $list_of_branch_units,
                 'total_count' => $total_count,
@@ -805,8 +855,8 @@ class ClientController extends AdminController
                 'message' => 'Client branch updated successfully'
 
             ], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to update client branch'], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to update client branch'], 200);
         }
     }
 
@@ -818,7 +868,7 @@ class ClientController extends AdminController
         // print_r($this->request->getPost()); die;
 
 
-        $this->myLogger->logme('error','Client policy CREATE function called');
+        $this->myLogger->logme('error', 'Client policy CREATE function called');
 
         $policy_type_id   = $this->request->getPost('policy_type_id');
         $client_branch_id = $this->request->getPost('client_branch_id');
@@ -828,7 +878,7 @@ class ClientController extends AdminController
 
         $insurerValue  = (string) $this->request->getPost('insurer');
         list($insurerBranchId, $insurerId) = explode('-', $insurerValue);
-        
+
 
         $data['insurer_branch_id'] = $insurerBranchId;
         $data['insurer_id']        = $insurerId;
@@ -841,7 +891,7 @@ class ClientController extends AdminController
         } else {
             list($tpaBranchId, $tpaId) = explode('-', $tpaValue);
         }
-        
+
 
         $data['client_id']         = $client_id;
         $data['tpa_branch_id']     = $tpaBranchId;
@@ -852,7 +902,7 @@ class ClientController extends AdminController
         $data['policy_status']                      = $this->request->getPost('policy_status');
         $data['no_of_employees']                    = $this->request->getPost('no_of_employees');
         $data['earned_premium_date']                = change_date_format($this->request->getPost('earned_premium_date'), 'd-m-Y', 'Y-m-d')  ?? null;
-        $data['claims_incurred_date']               = change_date_format($this->request->getPost('claims_incurred_date'), 'd-m-Y', 'Y-m-d') ?? null;        
+        $data['claims_incurred_date']               = change_date_format($this->request->getPost('claims_incurred_date'), 'd-m-Y', 'Y-m-d') ?? null;
         $data['incurred_claims_ratio']              = $this->request->getPost('incurred_claims_ratio');
         $data['no_lives_at_inception']              = $this->request->getPost('no_lives_at_inception');
         $data['premium_paid_at_inception']          = $this->request->getPost('premium_paid_at_inception');
@@ -865,36 +915,35 @@ class ClientController extends AdminController
         $data['client_branch_id']                   = $this->request->getPost('client_branch_id');
         $data['cd_ac_no']                           = $this->request->getPost('cd_ac_no');
         $data['gst']                                = $this->request->getPost('gst');
-        
 
-        if($policy_type_id == 1 || $policy_type_id == 2 || $policy_type_id == 6 || $policy_type_id == 7){
+
+        if ($policy_type_id == 1 || $policy_type_id == 2 || $policy_type_id == 6 || $policy_type_id == 7) {
 
             $data['is_addon'] = 1; // Base Policy
 
-        }else if($policy_type_id == 4 || $policy_type_id == 5){
+        } else if ($policy_type_id == 4 || $policy_type_id == 5) {
 
             $data['is_addon'] = 2; // SI TOPUP
 
-        }else if($policy_type_id == 3){
-           
-            if($base_policy){
+        } else if ($policy_type_id == 3) {
+
+            if ($base_policy) {
                 $data['is_addon'] = 3; // Dependent Addon
-            }else{
+            } else {
                 $data['is_addon'] = 1;
             }
         }
-                    
+
 
         $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d');
         $data['policy_end_date']   = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d');
         $data['policy_no'] = $this->request->getPost('policy_no');
-        if($data['inception_type'] == 2){
+        if ($data['inception_type'] == 2) {
             $data['open_date'] = change_date_format($this->request->getPost('open_date'), 'd-m-Y', 'Y-m-d');
             $data['close_date']   = change_date_format($this->request->getPost('close_date'), 'd-m-Y', 'Y-m-d');
             $data['reminder_date']   = change_date_format($this->request->getPost('reminder_date'), 'd-m-Y', 'Y-m-d');
-
-        }else{
-            $data['open_date'] = null; 
+        } else {
+            $data['open_date'] = null;
             $data['closedate'] = null;
             $data['reminder_date'] = null;
         }
@@ -922,11 +971,11 @@ class ClientController extends AdminController
 
 
         $insert = $this->clientPolicyModel->insert($data);
-        if($insert){
-            
+        if ($insert) {
+
             $policy_tranction_data['client_policy_id'] = $insert;
             $policy_tranction_data_insert = $this->policyTransactionModel->insert($data);
-            if($policy_tranction_data_insert){
+            if ($policy_tranction_data_insert) {
                 $statusData = [
                     'policy_tran_id' => $policy_tranction_data_insert,
                     'status' => 'pending',
@@ -938,16 +987,16 @@ class ClientController extends AdminController
 
             $clientPoliceData =  $this->clientPolicyModel->getClientPolicyByClientId($this->request->getPost('client_id'));
             $clientPoliceData['role'] = get_role_id();
-            return $this->respond(['status' => true,'code' => 200,'data' => $clientPoliceData, 'method' => 'CERATE', 'post_data' => $data], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $clientPoliceData, 'method' => 'CERATE', 'post_data' => $data], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
 
     public function editClientPolicy()
     {
 
-        $this->myLogger->logme('error','Client policy function called');
+        $this->myLogger->logme('error', 'Client policy function called');
 
 
         $id        = $this->request->getPost('PrimaryKey');
@@ -994,13 +1043,13 @@ class ClientController extends AdminController
         $data['gst']                                = $this->request->getPost('gst');
         $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d');
         $data['policy_end_date']   = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d');
-        
-        if($data['inception_type'] == 2){
+
+        if ($data['inception_type'] == 2) {
             $data['open_date'] = change_date_format($this->request->getPost('open_date'), 'd-m-Y', 'Y-m-d');
             $data['close_date']   = change_date_format($this->request->getPost('close_date'), 'd-m-Y', 'Y-m-d');
             $data['reminder_date']   = change_date_format($this->request->getPost('reminder_date'), 'd-m-Y', 'Y-m-d');
-        }else{
-            $data['open_date'] = null; 
+        } else {
+            $data['open_date'] = null;
             $data['close_date'] = null;
             $data['reminder_date'] = null;
         }
@@ -1018,25 +1067,25 @@ class ClientController extends AdminController
         //     $data['is_addon'] = 3;
         // }
 
-        if($policy_type_id == 1 || $policy_type_id == 2 || $policy_type_id == 6 || $policy_type_id == 7){
+        if ($policy_type_id == 1 || $policy_type_id == 2 || $policy_type_id == 6 || $policy_type_id == 7) {
 
             $data['is_addon'] = 1; // Base Policy
 
-        }else if($policy_type_id == 4 || $policy_type_id == 5){
+        } else if ($policy_type_id == 4 || $policy_type_id == 5) {
 
             $data['is_addon'] = 2; // SI TOPUP
 
-        }else if($policy_type_id == 3){
-           
-            if($base_policy){
+        } else if ($policy_type_id == 3) {
+
+            if ($base_policy) {
                 $data['is_addon'] = 3; // Dependent Addon
-            }else{
+            } else {
                 $data['is_addon'] = 1;
             }
         }
-          
 
-        
+
+
         $policy_terms =  $this->clientPolicyModel->where('id', $this->request->getPost('base_policy'))->first();
 
         // if ( $this->request->getPost('is_addon') == 2 || $this->request->getPost('is_addon') == 3) {
@@ -1055,35 +1104,35 @@ class ClientController extends AdminController
         //     } else {
         //         $data['policy_terms'] =  $policy_terms['policy_terms'];
         //     }
-            
-           
+
+
         // } 
 
         // dd($data);
         $data['updated_by'] = get_session_userid();
         // print_r(json_encode($data));die;
-        $insert = $this->clientPolicyModel->update($id,$data);
+        $insert = $this->clientPolicyModel->update($id, $data);
         $lastQuery = $this->clientPolicyModel->getLastQuery();
-        
+
         // echo '
';
         // print_r($data); die;
 
-        if($insert){
+        if ($insert) {
             $clientPoliceData =  $this->clientPolicyModel->getClientPolicyByClientId($client_id);
             $clientPoliceData['role'] = get_role_id();
             // foreach ($clientPoliceData as $key => $value) {
-            
+
             //     $clientPoliceData[$key]->policy_start_date = date('d-M-Y', strtotime($value->policy_start_date));
             //     $clientPoliceData[$key]->policy_end_date = date('d-M-Y', strtotime($value->policy_end_date));
             // }
-            return $this->respond(['status' => true,'code' => 200,'data' => $clientPoliceData, 'method' => 'EDIT'], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $clientPoliceData, 'method' => 'EDIT'], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
 
     public function removePolicy($id = null)
-    {   
+    {
         $this->myLogger->logme('error', 'Client Policy Remove function called');
 
         $data = [
@@ -1092,29 +1141,26 @@ class ClientController extends AdminController
         ];
 
         $emp_details = $this->employeePolicyModel
-                ->join('employees', 'employees.id = employee_polices.employee_id')
-                ->where('client_policy_id', $id)
-                ->where('employee_polices.status', 'active')
-                ->where('employee_polices.is_active', 1)
-                ->where('employees.emp_status', 'active')
-                ->where('employees.is_active', 1)
-                ->countAllResults();
-        if($emp_details == 0){
+            ->join('employees', 'employees.id = employee_polices.employee_id')
+            ->where('client_policy_id', $id)
+            ->where('employee_polices.status', 'active')
+            ->where('employee_polices.is_active', 1)
+            ->where('employees.emp_status', 'active')
+            ->where('employees.is_active', 1)
+            ->countAllResults();
+        if ($emp_details == 0) {
 
             $update = $this->clientPolicyModel->where('id', $id)->set($data)->update();
-        
+
             if ($update) {
                 return $this->respond(['status' => true, 'code' => 200], 200);
             } else {
                 return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to remove policy'], 200);
             }
-    
-        }else{
+        } else {
 
             return $this->respond(['status' => false, 'code' => 404, 'message' => 'The policy has active employees'], 200);
-
         }
-        
     }
 
     public function createClientPolicyPremium()
@@ -1143,7 +1189,7 @@ class ClientController extends AdminController
                 'spouse'        => $this->request->getPost('spouse') ?? 'NA',
                 'childrens'     => $this->request->getPost('childrens') ?? 'NA',
                 'parents'       => $this->request->getPost('parents') ?? 'NA',
-                'parents-in-law'=> $this->request->getPost('parents-in-law') ?? 'NA',
+                'parents-in-law' => $this->request->getPost('parents-in-law') ?? 'NA',
             ];
 
             $relation_data_for_form_submit_check = [
@@ -1152,17 +1198,17 @@ class ClientController extends AdminController
                     'spouse'        => $this->request->getPost('spouse') ?? 'NA',
                     'childrens'     => $this->request->getPost('childrens') ?? 'NA',
                     'parents'       => $this->request->getPost('parents') ?? 'NA',
-                    'parents-in-law'=> $this->request->getPost('parents-in-law') ?? 'NA',
+                    'parents-in-law' => $this->request->getPost('parents-in-law') ?? 'NA',
                 ]
             ];
 
-            if ($policy_grid_id == 1 || $policy_grid_id == 2 ) {
+            if ($policy_grid_id == 1 || $policy_grid_id == 2) {
                 $relation_data = [
                     'self'          => 1,
                     'spouse'        => 'NA',
                     'childrens'     => 'NA',
                     'parents'       => 'NA',
-                    'parents-in-law'=> 'NA',
+                    'parents-in-law' => 'NA',
                 ];
             }
 
@@ -1214,7 +1260,6 @@ class ClientController extends AdminController
 
                         $policyPremium = $this->policyPremium1Model->insert($data);
                     }
-
                 } else if ($si_or_bp == '3') {
 
                     $premium = str_replace(',', '', $this->request->getPost('gpa_sum_premium2[]'));
@@ -1238,8 +1283,7 @@ class ClientController extends AdminController
 
                         $policyPremium = $this->policyPremium1Model->insert($data);
                     }
-
-                }else if ($si_or_bp == '2') {
+                } else if ($si_or_bp == '2') {
 
                     $premium = str_replace(',', '', $this->request->getPost('gpa_basic_premium[]'));
                     $sum_insure = str_replace(',', '', $this->request->getPost('gpa_basic_si[]'));
@@ -1263,8 +1307,7 @@ class ClientController extends AdminController
 
                         $policyPremium = $this->policyPremium1Model->insert($data);
                     }
-
-                }else {
+                } else {
 
                     $data['premium'] = str_replace(',', '', $this->request->getPost('gpa_basic_premium'));
                     $data['si'] = str_replace(',', '', $this->request->getPost('gpa_basic_si'));
@@ -1278,12 +1321,11 @@ class ClientController extends AdminController
 
                 $data = $this->request->getPost();
                 $insert = true;
-
             } else if ($policy_grid_id == '2') {
 
                 $premium = $this->request->getPost('gpa_premium29[]');
                 $sum_insure = $this->request->getPost('gpa_si29[]');
-                $unit = $this->request->getPost('gpa_unit29[]');   
+                $unit = $this->request->getPost('gpa_unit29[]');
 
                 for ($i = 0; $i < count($premium); $i++) {
                     $data['premium'] = str_replace(',', '', $premium[$i]);
@@ -1298,13 +1340,12 @@ class ClientController extends AdminController
 
                 $data = $this->request->getPost();
                 $insert = true;
-
             } else if ($policy_grid_id == '3') {
 
                 $premium = $this->request->getPost('3_premium[]');
                 $sum_insure = $this->request->getPost('3_si[]');
                 $unit = $this->request->getPost('3_unit[]');
-                
+
                 for ($i = 0; $i < count($premium); $i++) {
                     $data['premium'] = str_replace(',', '', $premium[$i]);
                     $data['si'] = str_replace(',', '', $sum_insure[$i]);
@@ -1317,7 +1358,6 @@ class ClientController extends AdminController
                 }
                 $data = $this->request->getPost();
                 $insert = true;
-
             } else if ($policy_grid_id == '4') {
 
                 $premium = $this->request->getPost('4_premium[]');
@@ -1341,10 +1381,8 @@ class ClientController extends AdminController
                 }
                 $data = $this->request->getPost();
                 $insert = true;
-
-
             } else if ($policy_grid_id == '5') {
-                
+
                 $premium = $this->request->getPost('5_premium[]');
                 $sum_insure = $this->request->getPost('5_si[]');
                 $age_from = $this->request->getPost('5_age_from[]');
@@ -1367,7 +1405,6 @@ class ClientController extends AdminController
 
                 $data = $this->request->getPost();
                 $insert = true;
-                
             } else if ($policy_grid_id == '6') {
 
                 $premium = $this->request->getPost('6_premium[]');
@@ -1386,13 +1423,11 @@ class ClientController extends AdminController
                     } else {
                         $data['unit'] = $unit[$i];
                     }
-                    
+
                     $dataa = $this->policyPremium2Model->insert($data);
                 }
                 $data = $this->request->getPost();
                 $insert = true;
-
-
             } else if ($policy_grid_id == '7') {
                 $premium = $this->request->getPost('7_premium[]');
                 $sum_insure = $this->request->getPost('7_si[]');
@@ -1439,7 +1474,7 @@ class ClientController extends AdminController
 
                 $premium = $this->request->getPost('gpa_premium29[]');
                 $sum_insure = $this->request->getPost('gpa_si29[]');
-                $unit = $this->request->getPost('gpa_unit29[]');   
+                $unit = $this->request->getPost('gpa_unit29[]');
 
                 for ($i = 0; $i < count($premium); $i++) {
                     $data['premium'] = str_replace(',', '', $premium[$i]);
@@ -1454,7 +1489,6 @@ class ClientController extends AdminController
 
                 $data = $this->request->getPost();
                 $insert = true;
-
             } else if ($policy_grid_id == '10') {
                 $premium = $this->request->getPost('10_premium[]');
                 $sum_insure = $this->request->getPost('10_si[]');
@@ -1550,13 +1584,12 @@ class ClientController extends AdminController
             }
 
             if ($insert) {
-                return $this->respond(['status' => true, 'code' => 200, 'data' => $data, 'rack_rate_json'=>$json_data_relation_data_for_form_submit_check,], 200);
+                return $this->respond(['status' => true, 'code' => 200, 'data' => $data, 'rack_rate_json' => $json_data_relation_data_for_form_submit_check,], 200);
             } else {
                 return $this->respond(['status' => false, 'code' => 404, 'data' => $data, 'message' => 'no data found'], 200);
             }
-
         } catch (\Exception $e) {
-            echo 'Error: ' . $e->getMessage(). ' at line no ' . $e->getLine();
+            echo 'Error: ' . $e->getMessage() . ' at line no ' . $e->getLine();
         }
     }
 
@@ -1564,27 +1597,27 @@ class ClientController extends AdminController
 
     public function uploadVehicleFile()
     {
-        $this->myLogger->logme('error','uploadVehicleFile function called');  
-        $data = $this->request->getPost();     
+        $this->myLogger->logme('error', 'uploadVehicleFile function called');
+        $data = $this->request->getPost();
         $files = $this->request->getFiles();
         // $data['client_id'] = 12;
         // $data['vehicle_id'] = 1;
 
         // upload path
         $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents';
-        
+
         $insertedDocs = [];
-    
+
         // Check  document names and files
         if (isset($data['other_docs_name']) && isset($files['file_name'])) {
             foreach ($data['other_docs_name'] as $key => $docName) {
                 // Get the corresponding file for this document name
                 $file = $files['file_name'][$key];
-    
+
                 if (!empty($docName) && $file->isValid() && !$file->hasMoved()) {
                     // Upload the file
                     $uploadedFileName = file_Upload($file, $uploadFilePath);
-    
+
                     if ($uploadedFileName) {
                         // Prepare data for each document upload
                         $docData = [
@@ -1594,23 +1627,23 @@ class ClientController extends AdminController
                             'file_name' => $uploadedFileName,
                             'created_by' => get_session_userid(),
                         ];
-    
+
                         // Insert into database
                         $insert = $this->clientKYCDocsModel->insert($docData);
-    
+
                         if ($insert) {
                             $insertedDocs[] = $docData; // Collect successfully inserted docs
                         }
                     }
                 }
             }
-    
+
             if (!empty($insertedDocs)) {
                 // Fetch all documents for the client
                 $vehicleDocs = $this->clientKYCDocsModel
-                            ->where('client_id', $data['client_id'])
-                            ->where('vehicle_id',$data['vehicle_id'])
-                            ->findAll();
+                    ->where('client_id', $data['client_id'])
+                    ->where('vehicle_id', $data['vehicle_id'])
+                    ->findAll();
                 return $this->respond(['status' => true, 'code' => 200, 'vehicle_docs' => $vehicleDocs, 'inserted_docs' => $insertedDocs], 200);
             } else {
                 return $this->respond(['status' => false, 'code' => 400, 'message' => 'No documents uploaded or inserted'], 200);
@@ -1619,98 +1652,88 @@ class ClientController extends AdminController
             return $this->respond(['status' => false, 'code' => 400, 'message' => 'Invalid data submission'], 200);
         }
     }
-    
 
-    public function editUploadVehicleFile()
+
+    public function editUploadVehicleFile() {}
+
+    public function listVehicleFiles() {}
+
+    public function deleteVehicleFiles() {}
+
+
+
+
+
+    public function getKycDocsById($id = null)
     {
 
-    }
-
-    public function listVehicleFiles()
-    {
-
-    }
-
-    public function deleteVehicleFiles(){
-
-    }
-
-
-
-
-    
-    public function getKycDocsById($id=null)
-    {
-
-        $this->myLogger->logme('error','getKycDocsById function called');
-        if($id){
+        $this->myLogger->logme('error', 'getKycDocsById function called');
+        if ($id) {
             $kyc_docs_data = $this->kycDocsModel->where(['kyc_type_id' => $id, 'is_active' => 1])->findAll();
-            $this->myLogger->logme('error','getKycDocs status TRUE');
-            return $this->respond(['status' => true,'code' => 200,'data' => $kyc_docs_data], 200);
-        }else{
-            $this->myLogger->logme('error','getKycDocs status FALSE');
-            return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
+            $this->myLogger->logme('error', 'getKycDocs status TRUE');
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $kyc_docs_data], 200);
+        } else {
+            $this->myLogger->logme('error', 'getKycDocs status FALSE');
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
 
     public function getPolicesByInsurerId($id = null)
     {
-        $this->myLogger->logme('error','getPolicesByInsurerId function called');
-        if($id){
+        $this->myLogger->logme('error', 'getPolicesByInsurerId function called');
+        if ($id) {
             $police_data = $this->policesModel
-            ->select('policies.*, policy_type.policy_type')
-            ->join('policy_type', 'policy_type.id = policies.policy_type_id')
-            ->where(['insurer_id' => $id, 'policies.is_active' => 1])->findAll();
-            return $this->respond(['status' => true,'code' => 200,'data' => $police_data], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
+                ->select('policies.*, policy_type.policy_type')
+                ->join('policy_type', 'policy_type.id = policies.policy_type_id')
+                ->where(['insurer_id' => $id, 'policies.is_active' => 1])->findAll();
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $police_data], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
     }
 
-    public function getSingleBranchDataById($id=null)
+    public function getSingleBranchDataById($id = null)
     {
 
-        $this->myLogger->logme('error','getSingleBranchDataById function called');
-        if($id){
+        $this->myLogger->logme('error', 'getSingleBranchDataById function called');
+        if ($id) {
             $branch_data = $this->clientBranchModel->where(['id' => $id, 'is_active' => 1])->first();
-            $branch_contact_data = $this->levelContactModel->where(['ref_id' => $id, 'contact_type'=>'client', 'is_active' => 1])->findAll();
-            return $this->respond(['status' => true,'code' => 200,'data' => $branch_data, 'contact' => $branch_contact_data], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
+            $branch_contact_data = $this->levelContactModel->where(['ref_id' => $id, 'contact_type' => 'client', 'is_active' => 1])->findAll();
+            return $this->respond(['status' => true, 'code' => 200, 'data' => $branch_data, 'contact' => $branch_contact_data], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
-
     }
 
-    public function getClientPolicyById($id=null)
+    public function getClientPolicyById($id = null)
     {
-        $this->myLogger->logme('error','getClientPolicyById function called');
+        $this->myLogger->logme('error', 'getClientPolicyById function called');
 
-        if($id){
+        if ($id) {
             $client_policy_data = $this->clientPolicyModel->where(['id' => $id, 'is_active' => 1])->first();
             $insurer_id = $client_policy_data['insurer_id'];
             $client_id = $client_policy_data['client_id'];
-            
+
             $polices = $this->policesModel
-                ->select('policies.*, policy_type.policy_type') 
+                ->select('policies.*, policy_type.policy_type')
                 ->join('policy_type', 'policy_type.id = policies.policy_type_id')
                 ->where(['policies.insurer_id' => $insurer_id, 'policies.is_active' => 1])
                 ->findAll();
             $client_policy_list = $this->clientPolicyModel->getPolicyTypeForPolicyBinding($client_id);
             $cd_data = $this->CDMasterModel->where('client_id', $client_id)->where('insurer_id', $insurer_id)->findAll();
-                                   
+
             return $this->respond([
                 'status' => true,
-                'code' => 200, 
-                'data' => $client_policy_data, 
-                'cd_data' => $cd_data, 
-                "insurer_id" => $client_policy_data['insurer_id'], 
-                'policy' => $polices, 
+                'code' => 200,
+                'data' => $client_policy_data,
+                'cd_data' => $cd_data,
+                "insurer_id" => $client_policy_data['insurer_id'],
+                'policy' => $polices,
                 'client_policy_list' =>  $client_policy_list
             ], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 404, 'message' => 'no data found'], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200);
         }
-
     }
 
     public function getpolicyGridData()
@@ -1720,10 +1743,10 @@ class ClientController extends AdminController
         $terms_si_amount_array = $this->getPolicyTerms($client_policy_id);
 
         $record    = $this->clientPolicyModel
-                        ->select('client_policy.*, policy_type.policy_type')
-                        ->join('policy_type', 'policy_type.id = client_policy.policy_type_id')
-                        ->where('client_policy.id', $client_policy_id)
-                        ->first();
+            ->select('client_policy.*, policy_type.policy_type')
+            ->join('policy_type', 'policy_type.id = client_policy.policy_type_id')
+            ->where('client_policy.id', $client_policy_id)
+            ->first();
         $family_floater = '';
         if (isset(json_decode($record['policy_terms'])->family_floater)) {
             $family_floater = json_decode($record['policy_terms'])->family_floater;
@@ -1758,7 +1781,7 @@ class ClientController extends AdminController
         }
 
         $results = $this->policyGridModel->like('policy_type', $search_term)->findAll();
-        $jsonArray = [];       
+        $jsonArray = [];
 
         if ($search_term === 'GPA' || $policy_type_id == 6 || $policy_type_id == 7) {
 
@@ -1773,18 +1796,16 @@ class ClientController extends AdminController
                 ->groupBy('rack_rate_name')
                 ->orderBy('id')
                 ->findAll();
-    
+
             foreach ($rackRateJson as $value) {
                 $jsonArray[$value['rack_rate_name']] = json_decode($value['additional_relationship']);
             }
-        
-
         } else {
 
             $premiumData = "";
         }
 
-        
+
         // echo '
';
         // print_r($premiumData); die;
 
@@ -1856,30 +1877,29 @@ class ClientController extends AdminController
             // print_r($premium2); die;
 
             return $this->respond([
-                'status' => true, 
-                'code' => 200, 
-                'data' => $resultss, 
-                'premiumData' => json_encode($premiumDataa), 
-                'count' => $emp_count,  
-                'family_floater' => $family_floater, 
-                'self' => $self, 
-                'client_policy_id' => $client_policy_id, 
+                'status' => true,
+                'code' => 200,
+                'data' => $resultss,
+                'premiumData' => json_encode($premiumDataa),
+                'count' => $emp_count,
+                'family_floater' => $family_floater,
+                'self' => $self,
+                'client_policy_id' => $client_policy_id,
                 'terms_si_amount_array' => $terms_si_amount_array,
                 'branch_units' => $branch_units,
                 'jsonArray' => $jsonArray,
             ], 200);
-
         } else if ($search_term === 'GPA' || $policy_type_id == 6 || $policy_type_id == 7) {
 
             return $this->respond([
-                'status' => true, 
-                'code' => 200, 
-                'data' => $results, 
-                'premiumData' => json_encode($premiumData), 
-                'count' => $emp_count, 
-                'family_floater' => $family_floater, 
-                'self' => $self, 
-                'client_policy_id' => $client_policy_id, 
+                'status' => true,
+                'code' => 200,
+                'data' => $results,
+                'premiumData' => json_encode($premiumData),
+                'count' => $emp_count,
+                'family_floater' => $family_floater,
+                'self' => $self,
+                'client_policy_id' => $client_policy_id,
                 'terms_si_amount_array' => $terms_si_amount_array,
                 'branch_units' => $branch_units,
                 'jsonArray' => $jsonArray,
@@ -1887,17 +1907,17 @@ class ClientController extends AdminController
         } else {
 
             return $this->respond([
-                'status' => false, 
-                'code' => 200, 
-                'data' => $results, 
-                'premiumData' => json_encode($premiumData), 
-                'count' => $emp_count,  
-                'family_floater' => $family_floater, 
-                'self' => $self, 
+                'status' => false,
+                'code' => 200,
+                'data' => $results,
+                'premiumData' => json_encode($premiumData),
+                'count' => $emp_count,
+                'family_floater' => $family_floater,
+                'self' => $self,
                 'client_policy_id' => $client_policy_id,
                 'terms_si_amount_array' => $terms_si_amount_array,
                 'branch_units' => $branch_units,
-                'jsonArray' => $jsonArray, 
+                'jsonArray' => $jsonArray,
             ], 200);
         }
     }
@@ -1907,194 +1927,194 @@ class ClientController extends AdminController
         try {
             // echo "
";
             // print_r($this->request->getPost());die;
-            $this->myLogger->logme('error','Terms CREATE function called');
-            
+            $this->myLogger->logme('error', 'Terms CREATE function called');
+
             /*** Client Policy Table Primary Key(ID) ***/
             $client_policy_id = $this->request->getPost("client_policy_id");
 
-            $data['sum_insured']   =str_replace(',', '',$this->request->getPost("sum_insured"));
-            $data['family_floater']   =$this->request->getPost("family_floater") ? $this->request->getPost("family_floater") : 0;
+            $data['sum_insured']   = str_replace(',', '', $this->request->getPost("sum_insured"));
+            $data['family_floater']   = $this->request->getPost("family_floater") ? $this->request->getPost("family_floater") : 0;
             // $data['corporatebuffer'] = $this->request->getPost("corporatebuffer") ? $this->request->getPost("corporatebuffer") : 0;
-            $data['family_floaters'] = $this->request->getPost("family_floaters") ?? [];        
-            
-            $data['age_ratio']['self']['min'] =  $this->request->getPost("self_min_age") ? $this->request->getPost("self_min_age") :0;
+            $data['family_floaters'] = $this->request->getPost("family_floaters") ?? [];
+
+            $data['age_ratio']['self']['min'] =  $this->request->getPost("self_min_age") ? $this->request->getPost("self_min_age") : 0;
             $data['age_ratio']['self']['max'] = $this->request->getPost("self_max_age") ? $this->request->getPost("self_max_age") : 0;
             $data['age_ratio']['spouse']['min'] = $this->request->getPost("spouse_min_age") ? $this->request->getPost("spouse_min_age") : 0;
             $data['age_ratio']['spouse']['max'] = $this->request->getPost("spouse_max_age") ? $this->request->getPost("spouse_max_age") : 0;
             $data['age_ratio']['child']['min'] = $this->request->getPost("child_min_age") ? $this->request->getPost("child_min_age") : 0;
             $data['age_ratio']['child']['max'] = $this->request->getPost("child_max_age") ? $this->request->getPost("child_max_age") : 0;
-            $data['age_ratio']['elders']['min'] = $this->request->getPost("other_member_min_age") ? $this->request->getPost("other_member_min_age") :0;
+            $data['age_ratio']['elders']['min'] = $this->request->getPost("other_member_min_age") ? $this->request->getPost("other_member_min_age") : 0;
             $data['age_ratio']['elders']['max'] = $this->request->getPost("other_member_max_age") ? $this->request->getPost("other_member_max_age") : 0;
 
 
 
-                // if (!in_array("self", $data['family_floaters'])) {
-                //     array_unshift($data['family_floaters'], "self");
-                // }
-                $temp_family_floaters = $data['family_floaters'];
-                $data['family_floaters'] =[];
-                    if (in_array("self",$temp_family_floaters) == 1) {
-                        $data['family_floaters']['self'] =1;
-                    }else{
-                        $data['family_floaters']['self'] =0;
-                    }
-
-                    if (in_array("spouse",$temp_family_floaters) == 1) {
-                        $data['family_floaters']['spouse'] =1;
-                    }else{
-                        $data['family_floaters']['spouse'] =0;
-                    }
-
-                    // $data['family_floaters']['either-parents-pil'] =0;
-
-                    if (count($temp_family_floaters)) {
-                        $children_value = 0;
-                        $value = 0;
-
-                        if(count($temp_family_floaters) == 2){
-                            $children_value = 0;
-                            $value = 1;
-                        }else if(count($temp_family_floaters) == 3){
-                            $children_value = 1;
-                            $value = 2;
-                        }else{
-                            $children_value = 2;
-                            $value = 3;
-                        }
-                        $data['family_floaters']['childrens'] =(int)$temp_family_floaters[$children_value];
-
-                        if ($temp_family_floaters[$value] == '1P') {
-                            $data['family_floaters']['parents'] =1;
-                            $data['family_floaters']['parents-in-law'] =0;
-                            $data['family_floaters']['either-parents-pil'] =0;
-                        }else if($temp_family_floaters[$value] == '2P'){
-                            $data['family_floaters']['parents'] =2;
-                            $data['family_floaters']['parents-in-law'] =0;
-                            $data['family_floaters']['either-parents-pil'] =0;
-                        }else if($temp_family_floaters[$value] == '1PIL'){
-                            $data['family_floaters']['parents'] =0;
-                            $data['family_floaters']['parents-in-law'] =1;
-                            $data['family_floaters']['either-parents-pil'] =0;
-                        }else if($temp_family_floaters[$value] == '2PIL'){
-                            $data['family_floaters']['parents'] =0;
-                            $data['family_floaters']['parents-in-law'] =2;
-                            $data['family_floaters']['either-parents-pil'] =0;
-                        }else if($temp_family_floaters[$value] == '2EPORPIL'){
-                            //Parents or PIL (Any two of Father, Mother, MIl, FIL)
-                            $data['family_floaters']['parents'] =0;
-                            $data['family_floaters']['parents-in-law'] =0;
-                            $data['family_floaters']['either-parents-pil'] =2;
-                        }else if($temp_family_floaters[$value] == 'EPORPIL'){
-                            //Either Parents or PIL (Parents or Parents In Law)
-                            $data['family_floaters']['parents'] =0;
-                            $data['family_floaters']['parents-in-law'] =0;
-                            $data['family_floaters']['either-parents-pil'] =1;
-                        }else if($temp_family_floaters[$value] == '4EPORPIL'){
-                            $data['family_floaters']['parents'] =2;
-                            $data['family_floaters']['parents-in-law'] =2;
-                            $data['family_floaters']['either-parents-pil'] =0;
-                        }else{
-                            $data['family_floaters']['parents'] =0;
-                            $data['family_floaters']['parents-in-law'] =0;
-                            $data['family_floaters']['either-parents-pil'] =0;
-                        }
-                    }
-
-                    $data['family_floaters']['elders_count'] =$this->request->getPost("elder_member_count") ? $this->request->getPost("elder_member_count") : 0;
-
-                    // print_r($data);die;
-
-            $data['waiverofpreexistingdiseases']   =$this->request->getPost("waiverofpreexistingdiseases");
-            if ($data['waiverofpreexistingdiseases'] == 1) {
-                $data['maternitycoverage']   =str_replace(',', '',$this->request->getPost("maternitycoverage"));
-                $data['twindelivery']   =str_replace(',', '',$this->request->getPost("twindelivery"));
-                $data['preandpostnatal']   =str_replace(',', '',$this->request->getPost("preandpostnatal"));
-                $data['babyday1cover']   =str_replace(',', '',$this->request->getPost("babyday1cover"));
-            }else{
-                $data['maternitycoverage']   ="";
-                $data['twindelivery']   ="";
-                $data['preandpostnatal']   ="";
-                $data['babyday1cover']   ="";
+            // if (!in_array("self", $data['family_floaters'])) {
+            //     array_unshift($data['family_floaters'], "self");
+            // }
+            $temp_family_floaters = $data['family_floaters'];
+            $data['family_floaters'] = [];
+            if (in_array("self", $temp_family_floaters) == 1) {
+                $data['family_floaters']['self'] = 1;
+            } else {
+                $data['family_floaters']['self'] = 0;
             }
-            $data['9monthwaitingperiodwaived'] =str_replace(',', '',$this->request->getPost("9monthwaitingperiodwaived"));
-            $data['coverfromthedateofjoining'] =str_replace(',', '',$this->request->getPost("coverfromthedateofjoining"));
-            $data['waiverof1,2,3&4thyearexclusions'] =$this->request->getPost("waiverof1,2,3&4thyearexclusions");
-            $data['waiverof30dayswaitingperiod'] =$this->request->getPost("waiverof30dayswaitingperiod");
-            $data['prehospitalizationcover'] =str_replace(',', '',$this->request->getPost("prehospitalizationcover"));
-            // $data['posthospitalizationcover'] =$this->request->getPost("posthospitalizationcover");
-            $data['congenitaldiseasesinternal'] =str_replace(',', '',$this->request->getPost("congenitaldiseasesinternal"));
-            // $data['congenitaldiseasesexternal'] =$this->request->getPost("congenitaldiseasesexternal");
-            $data['copayzonewisecopay'] =$this->request->getPost("copayzonewisecopay");
-            $data['bioabsorbablestenttoriclensmultifocallens'] =$this->request->getPost("bioabsorbablestenttoriclensmultifocallens");
-            $data['roomrentlimit'] =str_replace(',', '',$this->request->getPost("roomrentlimit"));
-            $data['proportionatedeductionclause'] =str_replace(',', '',$this->request->getPost("proportionatedeductionclause"));
-            // $data['nursingallowance'] =str_replace(',', '',$this->request->getPost("nursingallowance"));
-            $data['ailmentcapping'] =str_replace(',', '',$this->request->getPost("ailmentcapping"));
-            $data['ambulancecharges'] =str_replace(',', '',$this->request->getPost("ambulancecharges"));
-            $data['airambulance'] =str_replace(',', '',$this->request->getPost("airambulance"));
-            $data['familytransportationbenefit'] =str_replace(',', '',$this->request->getPost("familytransportationbenefit"));
-            $data['reasonableandcustomarycharges'] =str_replace(',', '',$this->request->getPost("reasonableandcustomarycharges"));
-            $data['ayudhtreatmentcover'] =str_replace(',', '',$this->request->getPost("ayudhtreatmentcover"));
 
-            $data['congenitaldiseasesexternal'] =str_replace(',', '',$this->request->getPost("congenitaldiseasesexternal"));
-            $data['optionalparentalcopay'] =str_replace(',', '',$this->request->getPost("optionalparentalcopay"));
-            $data['posthospitalizationcover'] =str_replace(',', '',$this->request->getPost("posthospitalizationcover"));
-            $data['corporatebuffer'] =str_replace(',', '',$this->request->getPost("corporatebuffer"));
-            $data['sublimitofcorporatebuffer'] =str_replace(',', '',$this->request->getPost("sublimitofcorporatebuffer"));
+            if (in_array("spouse", $temp_family_floaters) == 1) {
+                $data['family_floaters']['spouse'] = 1;
+            } else {
+                $data['family_floaters']['spouse'] = 0;
+            }
+
+            // $data['family_floaters']['either-parents-pil'] =0;
+
+            if (count($temp_family_floaters)) {
+                $children_value = 0;
+                $value = 0;
+
+                if (count($temp_family_floaters) == 2) {
+                    $children_value = 0;
+                    $value = 1;
+                } else if (count($temp_family_floaters) == 3) {
+                    $children_value = 1;
+                    $value = 2;
+                } else {
+                    $children_value = 2;
+                    $value = 3;
+                }
+                $data['family_floaters']['childrens'] = (int)$temp_family_floaters[$children_value];
+
+                if ($temp_family_floaters[$value] == '1P') {
+                    $data['family_floaters']['parents'] = 1;
+                    $data['family_floaters']['parents-in-law'] = 0;
+                    $data['family_floaters']['either-parents-pil'] = 0;
+                } else if ($temp_family_floaters[$value] == '2P') {
+                    $data['family_floaters']['parents'] = 2;
+                    $data['family_floaters']['parents-in-law'] = 0;
+                    $data['family_floaters']['either-parents-pil'] = 0;
+                } else if ($temp_family_floaters[$value] == '1PIL') {
+                    $data['family_floaters']['parents'] = 0;
+                    $data['family_floaters']['parents-in-law'] = 1;
+                    $data['family_floaters']['either-parents-pil'] = 0;
+                } else if ($temp_family_floaters[$value] == '2PIL') {
+                    $data['family_floaters']['parents'] = 0;
+                    $data['family_floaters']['parents-in-law'] = 2;
+                    $data['family_floaters']['either-parents-pil'] = 0;
+                } else if ($temp_family_floaters[$value] == '2EPORPIL') {
+                    //Parents or PIL (Any two of Father, Mother, MIl, FIL)
+                    $data['family_floaters']['parents'] = 0;
+                    $data['family_floaters']['parents-in-law'] = 0;
+                    $data['family_floaters']['either-parents-pil'] = 2;
+                } else if ($temp_family_floaters[$value] == 'EPORPIL') {
+                    //Either Parents or PIL (Parents or Parents In Law)
+                    $data['family_floaters']['parents'] = 0;
+                    $data['family_floaters']['parents-in-law'] = 0;
+                    $data['family_floaters']['either-parents-pil'] = 1;
+                } else if ($temp_family_floaters[$value] == '4EPORPIL') {
+                    $data['family_floaters']['parents'] = 2;
+                    $data['family_floaters']['parents-in-law'] = 2;
+                    $data['family_floaters']['either-parents-pil'] = 0;
+                } else {
+                    $data['family_floaters']['parents'] = 0;
+                    $data['family_floaters']['parents-in-law'] = 0;
+                    $data['family_floaters']['either-parents-pil'] = 0;
+                }
+            }
+
+            $data['family_floaters']['elders_count'] = $this->request->getPost("elder_member_count") ? $this->request->getPost("elder_member_count") : 0;
+
+            // print_r($data);die;
+
+            $data['waiverofpreexistingdiseases']   = $this->request->getPost("waiverofpreexistingdiseases");
+            if ($data['waiverofpreexistingdiseases'] == 1) {
+                $data['maternitycoverage']   = str_replace(',', '', $this->request->getPost("maternitycoverage"));
+                $data['twindelivery']   = str_replace(',', '', $this->request->getPost("twindelivery"));
+                $data['preandpostnatal']   = str_replace(',', '', $this->request->getPost("preandpostnatal"));
+                $data['babyday1cover']   = str_replace(',', '', $this->request->getPost("babyday1cover"));
+            } else {
+                $data['maternitycoverage']   = "";
+                $data['twindelivery']   = "";
+                $data['preandpostnatal']   = "";
+                $data['babyday1cover']   = "";
+            }
+            $data['9monthwaitingperiodwaived'] = str_replace(',', '', $this->request->getPost("9monthwaitingperiodwaived"));
+            $data['coverfromthedateofjoining'] = str_replace(',', '', $this->request->getPost("coverfromthedateofjoining"));
+            $data['waiverof1,2,3&4thyearexclusions'] = $this->request->getPost("waiverof1,2,3&4thyearexclusions");
+            $data['waiverof30dayswaitingperiod'] = $this->request->getPost("waiverof30dayswaitingperiod");
+            $data['prehospitalizationcover'] = str_replace(',', '', $this->request->getPost("prehospitalizationcover"));
+            // $data['posthospitalizationcover'] =$this->request->getPost("posthospitalizationcover");
+            $data['congenitaldiseasesinternal'] = str_replace(',', '', $this->request->getPost("congenitaldiseasesinternal"));
+            // $data['congenitaldiseasesexternal'] =$this->request->getPost("congenitaldiseasesexternal");
+            $data['copayzonewisecopay'] = $this->request->getPost("copayzonewisecopay");
+            $data['bioabsorbablestenttoriclensmultifocallens'] = $this->request->getPost("bioabsorbablestenttoriclensmultifocallens");
+            $data['roomrentlimit'] = str_replace(',', '', $this->request->getPost("roomrentlimit"));
+            $data['proportionatedeductionclause'] = str_replace(',', '', $this->request->getPost("proportionatedeductionclause"));
+            // $data['nursingallowance'] =str_replace(',', '',$this->request->getPost("nursingallowance"));
+            $data['ailmentcapping'] = str_replace(',', '', $this->request->getPost("ailmentcapping"));
+            $data['ambulancecharges'] = str_replace(',', '', $this->request->getPost("ambulancecharges"));
+            $data['airambulance'] = str_replace(',', '', $this->request->getPost("airambulance"));
+            $data['familytransportationbenefit'] = str_replace(',', '', $this->request->getPost("familytransportationbenefit"));
+            $data['reasonableandcustomarycharges'] = str_replace(',', '', $this->request->getPost("reasonableandcustomarycharges"));
+            $data['ayudhtreatmentcover'] = str_replace(',', '', $this->request->getPost("ayudhtreatmentcover"));
+
+            $data['congenitaldiseasesexternal'] = str_replace(',', '', $this->request->getPost("congenitaldiseasesexternal"));
+            $data['optionalparentalcopay'] = str_replace(',', '', $this->request->getPost("optionalparentalcopay"));
+            $data['posthospitalizationcover'] = str_replace(',', '', $this->request->getPost("posthospitalizationcover"));
+            $data['corporatebuffer'] = str_replace(',', '', $this->request->getPost("corporatebuffer"));
+            $data['sublimitofcorporatebuffer'] = str_replace(',', '', $this->request->getPost("sublimitofcorporatebuffer"));
 
             if ($data['ayudhtreatmentcover'] == 1) {
-                $data['ayushTreatmentCoverData']   = str_replace(',', '',$this->request->getPost("ayushTreatmentCoverData"));
-            }else{
-                $data['ayushTreatmentCoverData']   ="";
+                $data['ayushTreatmentCoverData']   = str_replace(',', '', $this->request->getPost("ayushTreatmentCoverData"));
+            } else {
+                $data['ayushTreatmentCoverData']   = "";
             }
 
-            $data['armdcovered'] =str_replace(',', '',$this->request->getPost("armdcovered"));
-            $data['suminsuredenhancement'] =str_replace(',', '',$this->request->getPost("suminsuredenhancement"));
-            $data['automaticsuminsuredreinstatement'] =str_replace(',', '',$this->request->getPost("automaticsuminsuredreinstatement"));
-            $data['additionalsicknessbenefit'] =str_replace(',', '',$this->request->getPost("additionalsicknessbenefit"));
-            $data['lasiksurgery'] =str_replace(',', '',$this->request->getPost("lasiksurgery"));
-            $data['midterminclusion'] =str_replace(',', '',$this->request->getPost("midterminclusion"));
-            $data['capd'] =str_replace(',', '',$this->request->getPost("capd"));
-            $data['organdonorexpenses'] =str_replace(',', '',$this->request->getPost("organdonorexpenses"));
-            $data['moderntreatmentsasperirdai'] =str_replace(',', '',$this->request->getPost("moderntreatmentsasperirdai"));
-            $data['Wellness'] =str_replace(',', '',$this->request->getPost("Wellness"));
-            $data['days_of_discharge'] =str_replace(',', '',$this->request->getPost("days_of_discharge"));
-            $data['days_from_dod'] =str_replace(',', '',$this->request->getPost("days_from_dod"));
-            $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")) ?? [];
+            $data['armdcovered'] = str_replace(',', '', $this->request->getPost("armdcovered"));
+            $data['suminsuredenhancement'] = str_replace(',', '', $this->request->getPost("suminsuredenhancement"));
+            $data['automaticsuminsuredreinstatement'] = str_replace(',', '', $this->request->getPost("automaticsuminsuredreinstatement"));
+            $data['additionalsicknessbenefit'] = str_replace(',', '', $this->request->getPost("additionalsicknessbenefit"));
+            $data['lasiksurgery'] = str_replace(',', '', $this->request->getPost("lasiksurgery"));
+            $data['midterminclusion'] = str_replace(',', '', $this->request->getPost("midterminclusion"));
+            $data['capd'] = str_replace(',', '', $this->request->getPost("capd"));
+            $data['organdonorexpenses'] = str_replace(',', '', $this->request->getPost("organdonorexpenses"));
+            $data['moderntreatmentsasperirdai'] = str_replace(',', '', $this->request->getPost("moderntreatmentsasperirdai"));
+            $data['Wellness'] = str_replace(',', '', $this->request->getPost("Wellness"));
+            $data['days_of_discharge'] = str_replace(',', '', $this->request->getPost("days_of_discharge"));
+            $data['days_from_dod'] = str_replace(',', '', $this->request->getPost("days_from_dod"));
+            $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")) ?? [];
 
-            $data['cataract'] =str_replace(',', '',$this->request->getPost("cataract"));
+            $data['cataract'] = str_replace(',', '', $this->request->getPost("cataract"));
 
             if ($data['cataract'] == 1) {
-                $data['cataractData']   = str_replace(',', '',$this->request->getPost("cataractData"));
-            }else{
-                $data['cataractData']   ="";
+                $data['cataractData']   = str_replace(',', '', $this->request->getPost("cataractData"));
+            } else {
+                $data['cataractData']   = "";
             }
 
 
-                $jsonData = json_encode($data);
-                $dataa = array(
-                    'policy_terms' => $jsonData,
-                );
+            $jsonData = json_encode($data);
+            $dataa = array(
+                'policy_terms' => $jsonData,
+            );
 
             $record = $this->clientPolicyModel->where('id', $client_policy_id)->first();
 
-           
+
             // print_r($data);die;
             if ($record) {
                 $update = $this->clientPolicyModel->update($client_policy_id, $dataa);
                 if ($update) {
-                    return $this->respond(['status' => true,'code' => 200,'message' => 'Data updated successfully'], 200);
+                    return $this->respond(['status' => true, 'code' => 200, 'message' => 'Data updated successfully'], 200);
                 } else {
-                    return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to update data'], 200);
+                    return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to update data'], 200);
                 }
-            }else{
-                $insert = $this->clientPolicyModel->insert($dataa);        
+            } else {
+                $insert = $this->clientPolicyModel->insert($dataa);
                 if ($insert) {
-                    return $this->respond(['status' => true,'code' => 200,'message' => 'Data stored successfully'], 200);
+                    return $this->respond(['status' => true, 'code' => 200, 'message' => 'Data stored successfully'], 200);
                 } else {
-                    return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to store data'], 200);
+                    return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to store data'], 200);
                 }
             }
         } catch (\Exception $e) {
@@ -2103,9 +2123,8 @@ class ClientController extends AdminController
             // Log the error
             log_message('error', 'Failed to insert data: ' . $e->getMessage());
         }
-        
     }
-    
+
     public function getterms()
     {
         $client_policy_id = $this->request->getVar('client_policy_id');
@@ -2118,86 +2137,88 @@ class ClientController extends AdminController
         //     ->countAllResults();
 
         $emp_count_by_policy = $this->employeePolicyModel
-                        ->where('client_policy_id',$client_policy_id)
-                        ->where("status", 'active')
-                        ->where('is_active',1)
-                        ->countAllResults();
-        
+            ->where('client_policy_id', $client_policy_id)
+            ->where("status", 'active')
+            ->where('is_active', 1)
+            ->countAllResults();
+
 
         if ($record) {
-            return $this->respond([
-                'Status' => true,
-                'code' => 200,        
-                'data' => $record['policy_terms'],  
-                'policy_addon' => $record['is_addon'], 
-                'emp_count_by_policy'=>$emp_count_by_policy],
-            200);
+            return $this->respond(
+                [
+                    'Status' => true,
+                    'code' => 200,
+                    'data' => $record['policy_terms'],
+                    'policy_addon' => $record['is_addon'],
+                    'emp_count_by_policy' => $emp_count_by_policy
+                ],
+                200
+            );
         } else {
-            return $this->respond(['Status' => false,'code' => 200,'message' => 'Record not found.'], 200);
+            return $this->respond(['Status' => false, 'code' => 200, 'message' => 'Record not found.'], 200);
         }
-
     }
 
     public function policyGPATerms()
-    {   
+    {
         try {
-            $this->myLogger->logme('error','Policy GPA Terms CREATE function called');
+            $this->myLogger->logme('error', 'Policy GPA Terms CREATE function called');
 
             /*** Client Policy Table Primary Key(ID) ***/
             $client_policy_id = $this->request->getPost("client_policy_id");
 
-            $data['sumInsured2']   =str_replace(',', '', $this->request->getPost("sumInsured2"));
-            $data['totalSumInsured'] =str_replace(',', '',$this->request->getPost("totalSumInsured"));
+            $data['sumInsured2']   = str_replace(',', '', $this->request->getPost("sumInsured2"));
+            $data['totalSumInsured'] = str_replace(',', '', $this->request->getPost("totalSumInsured"));
             $data['age_ratio']['self']['min'] = $this->request->getPost("self_min_age");
             $data['age_ratio']['self']['max'] = $this->request->getPost("self_max_age");
-            $data['accidentalDeathBenefit'] =str_replace(',', '',$this->request->getPost("accidentalDeathBenefit"));
-            $data['permanentTotalDisablement'] =str_replace(',', '',$this->request->getPost("permanentTotalDisablement"));
-            $data['permanentPartialDisablement'] =$this->request->getPost("permanentPartialDisablement");
-            $data['temporaryTotalDisablementBenefit'] =$this->request->getPost("temporaryTotalDisablementBenefit");
-            $data['accidentalHospitalizationExpenses'] =str_replace(',', '',$this->request->getPost("accidentalHospitalizationExpenses"));
-            $data['childrenEducationWelfareFund'] =str_replace(',', '',$this->request->getPost("childrenEducationWelfareFund"));
+            $data['accidentalDeathBenefit'] = str_replace(',', '', $this->request->getPost("accidentalDeathBenefit"));
+            $data['permanentTotalDisablement'] = str_replace(',', '', $this->request->getPost("permanentTotalDisablement"));
+            $data['permanentPartialDisablement'] = $this->request->getPost("permanentPartialDisablement");
+            $data['temporaryTotalDisablementBenefit'] = $this->request->getPost("temporaryTotalDisablementBenefit");
+            $data['accidentalHospitalizationExpenses'] = str_replace(',', '', $this->request->getPost("accidentalHospitalizationExpenses"));
+            $data['childrenEducationWelfareFund'] = str_replace(',', '', $this->request->getPost("childrenEducationWelfareFund"));
 
-            $data['compassionateVisitExpenses']   =$this->request->getPost("compassionateVisitExpenses");
+            $data['compassionateVisitExpenses']   = $this->request->getPost("compassionateVisitExpenses");
             if ($data['compassionateVisitExpenses'] == 1) {
-                $data['compassionateVisitExpensesData']   =$this->request->getPost("compassionateVisitExpensesData");
-            }else{
-                $data['compassionateVisitExpensesData']   ="";
+                $data['compassionateVisitExpensesData']   = $this->request->getPost("compassionateVisitExpensesData");
+            } else {
+                $data['compassionateVisitExpensesData']   = "";
             }
 
-            $data['brokenBoneExpenses']   = str_replace(',', '',$this->request->getPost("brokenBoneExpenses"));
+            $data['brokenBoneExpenses']   = str_replace(',', '', $this->request->getPost("brokenBoneExpenses"));
             if ($data['brokenBoneExpenses'] == 1) {
-                $data['brokenBoneExpensesData']   = str_replace(',', '',$this->request->getPost("brokenBoneExpensesData"));
-            }else{
-                $data['brokenBoneExpensesData']   ="";
+                $data['brokenBoneExpensesData']   = str_replace(',', '', $this->request->getPost("brokenBoneExpensesData"));
+            } else {
+                $data['brokenBoneExpensesData']   = "";
             }
 
-            $data['ambulanceCharges']   =str_replace(',', '',$this->request->getPost("ambulanceCharges"));
+            $data['ambulanceCharges']   = str_replace(',', '', $this->request->getPost("ambulanceCharges"));
             if ($data['ambulanceCharges'] == 1) {
-                $data['ambulanceChargesData']   =str_replace(',', '',$this->request->getPost("ambulanceChargesData"));
-            }else{
-                $data['ambulanceChargesData']   ="";
+                $data['ambulanceChargesData']   = str_replace(',', '', $this->request->getPost("ambulanceChargesData"));
+            } else {
+                $data['ambulanceChargesData']   = "";
             }
 
             $data['burnExpenses']   = $this->request->getPost("burnExpenses");
             if ($data['burnExpenses'] == 1) {
                 $data['burnExpensesData']   = $this->request->getPost("burnExpensesData");
-            }else{
+            } else {
                 $data['burnExpensesData']   = "";
             }
 
             $data['carriageOfDeadBody']   = $this->request->getPost("carriageOfDeadBody");
             if ($data['carriageOfDeadBody'] == 1) {
                 $data['carriageOfDeadBodyData']   = $this->request->getPost("carriageOfDeadBodyData");
-            }else{
+            } else {
                 $data['carriageOfDeadBodyData']   = "";
             }
 
             $data['animalSnakeInsectBite'] = $this->request->getPost("animalSnakeInsectBite");
             $data['terrorism']             = $this->request->getPost("terrorism");
             $data['worldwideCover']        = $this->request->getPost("worldwideCover");
-            $data['gpa_special_condition_label'] = str_replace(',', '',$this->request->getPost("gpa_special_condition_label")) ?? [];
-            $data['gpa_special_condition_input'] = str_replace(',', '',$this->request->getPost("gpa_special_condition_input")) ?? [];
-            $data['multiple_sum_insured'] = str_replace(',', '',$this->request->getPost("multiple_sum_insured")) ?? [];
+            $data['gpa_special_condition_label'] = str_replace(',', '', $this->request->getPost("gpa_special_condition_label")) ?? [];
+            $data['gpa_special_condition_input'] = str_replace(',', '', $this->request->getPost("gpa_special_condition_input")) ?? [];
+            $data['multiple_sum_insured'] = str_replace(',', '', $this->request->getPost("multiple_sum_insured")) ?? [];
 
 
 
@@ -2212,14 +2233,14 @@ class ClientController extends AdminController
                 if ($update) {
                     return $this->respond(['status' => true, 'code' => 200, 'message' => 'Data updated successfully', 'client_policy_id' => $client_policy_id], 200);
                 } else {
-                    return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to update data'], 200);
+                    return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to update data'], 200);
                 }
-            }else{
-                $insert = $this->clientPolicyModel->insert($dataa);        
+            } else {
+                $insert = $this->clientPolicyModel->insert($dataa);
                 if ($insert) {
-                    return $this->respond(['status' => true,'code' => 200,'message' => 'Data stored successfully', 'client_policy_id' => $client_policy_id], 200);
+                    return $this->respond(['status' => true, 'code' => 200, 'message' => 'Data stored successfully', 'client_policy_id' => $client_policy_id], 200);
                 } else {
-                    return $this->respond(['status' => false,'code' => 404, 'message' => 'Failed to store data'], 200);
+                    return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to store data'], 200);
                 }
             }
         } catch (\Exception $e) {
@@ -2227,10 +2248,10 @@ class ClientController extends AdminController
             echo "Failed to insert data: " . $e->getMessage();
             log_message('error', 'Failed to insert data: ' . $e->getMessage());
         }
-        
     }
 
-    public function getPolicyGPATerms(){
+    public function getPolicyGPATerms()
+    {
 
         $client_id = $this->request->getVar('client_id');
         $policy_id = $this->request->getVar('policy_id');
@@ -2238,11 +2259,9 @@ class ClientController extends AdminController
 
         if ($record) {
             echo $record['policy_terms'];
-            
         } else {
             echo "Record not found.";
         }
-
     }
 
     public function updateClientPolicyStatus()
@@ -2252,74 +2271,74 @@ class ClientController extends AdminController
         $message = 'Policy updated Successfully';
 
 
-            $record    = $this->clientPolicyModel->where('id', $client_policy_id)->first();
+        $record    = $this->clientPolicyModel->where('id', $client_policy_id)->first();
 
-            if ($record['open_for_enrollment'] == 0) {
-                $open_for_enrollment_update_value = 1;
-                $message = 'Enrolment Opened  Successfully';
-            } else if ($record['open_for_enrollment'] == 1) {
-                $open_for_enrollment_update_value = 0;
-                $message = 'Enrolment Closed Successfully';
-            }
+        if ($record['open_for_enrollment'] == 0) {
+            $open_for_enrollment_update_value = 1;
+            $message = 'Enrolment Opened  Successfully';
+        } else if ($record['open_for_enrollment'] == 1) {
+            $open_for_enrollment_update_value = 0;
+            $message = 'Enrolment Closed Successfully';
+        }
 
-            $data = $this->policesModel->getPolicyPremium($client_policy_id);
-            $pattern = '/gmc/i';
-            $subject = $data[0]->policy_type;
-            if (preg_match($pattern, $subject)) {
-                $search_term = 'GMC';
-            } else {
-                $search_term = 'GPA';
-            }
+        $data = $this->policesModel->getPolicyPremium($client_policy_id);
+        $pattern = '/gmc/i';
+        $subject = $data[0]->policy_type;
+        if (preg_match($pattern, $subject)) {
+            $search_term = 'GMC';
+        } else {
+            $search_term = 'GPA';
+        }
 
-            if ($search_term === 'GPA') {
-                $racRate = $this->policyPremium1Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults();
-            } else if ($search_term === 'GMC') {
-                $racRate = $this->policyPremium2Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults();
-            }
+        if ($search_term === 'GPA') {
+            $racRate = $this->policyPremium1Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults();
+        } else if ($search_term === 'GMC') {
+            $racRate = $this->policyPremium2Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults();
+        }
 
-            $termsData = $this->clientPolicyModel->where(['id' => $client_policy_id, 'is_active' => 1])->first();
-            if (empty($termsData['policy_terms'])) {
-                return $this->respond(['status' => false, 'code' => 200, 'message' => 'Please define policy terms '], 200);
-            }
+        $termsData = $this->clientPolicyModel->where(['id' => $client_policy_id, 'is_active' => 1])->first();
+        if (empty($termsData['policy_terms'])) {
+            return $this->respond(['status' => false, 'code' => 200, 'message' => 'Please define policy terms '], 200);
+        }
 
 
-            $termsData = json_decode($termsData['policy_terms']);
+        $termsData = json_decode($termsData['policy_terms']);
 
-            if (isset($termsData->sum_insured) && empty($termsData->sum_insured)) {
-                return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty', 'data' => $record], 200);
-            }
+        if (isset($termsData->sum_insured) && empty($termsData->sum_insured)) {
+            return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty', 'data' => $record], 200);
+        }
 
-            if (isset($termsData->SumInsured) && empty($termsData->sum_insured)) {
-                return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty'], 200);
-            }
+        if (isset($termsData->SumInsured) && empty($termsData->sum_insured)) {
+            return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty'], 200);
+        }
 
-            // Check if 'family_floater' key exists and has a value
-            if (isset($termsData->family_floater) && $termsData->family_floater === null) {
-                return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Family Floater field is empty', 'termsData' => $termsData , 'family_floater' => $termsData->family_floater], 200);
-            }
+        // Check if 'family_floater' key exists and has a value
+        if (isset($termsData->family_floater) && $termsData->family_floater === null) {
+            return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Family Floater field is empty', 'termsData' => $termsData, 'family_floater' => $termsData->family_floater], 200);
+        }
 
-            // Check if 'family_floaters' key exists and has a value
-            if (isset($termsData->family_floaters) && is_array($termsData->family_floaters) && count($termsData->family_floaters) <= 0) {
-                return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Family Members field is empty'], 200);
-                $familyFloatersCount = count($termsData->family_floaters);
-            }
+        // Check if 'family_floaters' key exists and has a value
+        if (isset($termsData->family_floaters) && is_array($termsData->family_floaters) && count($termsData->family_floaters) <= 0) {
+            return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Family Members field is empty'], 200);
+            $familyFloatersCount = count($termsData->family_floaters);
+        }
 
-            if ($racRate == 0) {
+        if ($racRate == 0) {
 
-                return $this->respond(['status' => false, 'code' => 200, 'message' => 'Please define  policy premium'], 200);
-            }
+            return $this->respond(['status' => false, 'code' => 200, 'message' => 'Please define  policy premium'], 200);
+        }
 
-            // $policy_status = $this->clientPolicyModel->where('id', $client_policy_id )->set('policy_status', 1)->update();
+        // $policy_status = $this->clientPolicyModel->where('id', $client_policy_id )->set('policy_status', 1)->update();
 
-            $json_data = '';
-            $open_for_enrollment = $this->clientPolicyModel->where('id', $client_policy_id)->set('open_for_enrollment', $open_for_enrollment_update_value)->update();
-            if ($open_for_enrollment) {
-                $open_for_enrollment_1 = $this->clientPolicyModel->where('id', $client_policy_id)->find();
-                $open_for_enrollment_value = $open_for_enrollment_1[0]['open_for_enrollment'];
-                $client_policy_id_value = $client_policy_id;
+        $json_data = '';
+        $open_for_enrollment = $this->clientPolicyModel->where('id', $client_policy_id)->set('open_for_enrollment', $open_for_enrollment_update_value)->update();
+        if ($open_for_enrollment) {
+            $open_for_enrollment_1 = $this->clientPolicyModel->where('id', $client_policy_id)->find();
+            $open_for_enrollment_value = $open_for_enrollment_1[0]['open_for_enrollment'];
+            $client_policy_id_value = $client_policy_id;
 
-                $json_data = json_encode(['open_for_enrollment' => $open_for_enrollment_value, 'client_policy_id' => $client_policy_id_value]);
-            }
+            $json_data = json_encode(['open_for_enrollment' => $open_for_enrollment_value, 'client_policy_id' => $client_policy_id_value]);
+        }
 
 
 
@@ -2329,14 +2348,13 @@ class ClientController extends AdminController
     public function getClientPolicyList($client_id = null)
     {
 
-        $record = $this->clientPolicyModel->getpolicyWithPattern( $client_id);
+        $record = $this->clientPolicyModel->getpolicyWithPattern($client_id);
 
         if ($record) {
-            return $this->respond(['Status' => true,'code' => 200,'data' => $record], 200);
+            return $this->respond(['Status' => true, 'code' => 200, 'data' => $record], 200);
         } else {
-            return $this->respond(['Status' => false,'code' => 200,'message' => 'Record not found.'], 200);
+            return $this->respond(['Status' => false, 'code' => 200, 'message' => 'Record not found.'], 200);
         }
-
     }
 
     public function fetchPolicyDataForPolicyType($client_policy_id)
@@ -2348,29 +2366,26 @@ class ClientController extends AdminController
         $client_id = $this->clientPolicyModel->where('id', $client_policy_id)->first();
         $insurer_id = $client_id['insurer_id'];
 
-        if( $policy_type == 2 ){
+        if ($policy_type == 2) {
 
             $polices = $this->policesModel
-                            ->select('policies.*')
-                            ->join('policy_type', 'policy_type.id = policies.policy_type_id')
-                            ->where('policy_type.policy_type', 'GMC - Top-up')
-                            ->where(['policies.insurer_id' => $insurer_id, 'policies.is_active' => 1])->findAll();
-        }else  if( $policy_type == 3 ){
+                ->select('policies.*')
+                ->join('policy_type', 'policy_type.id = policies.policy_type_id')
+                ->where('policy_type.policy_type', 'GMC - Top-up')
+                ->where(['policies.insurer_id' => $insurer_id, 'policies.is_active' => 1])->findAll();
+        } else  if ($policy_type == 3) {
 
             $polices = $this->policesModel
-                            ->select('policies.*')
-                            ->join('policy_type', 'policy_type.id = policies.policy_type_id')
-                            ->whereIn('policy_type.policy_type', ['GMC - Parents', 'GMC - Top-up(Parents)'])
-                            ->where(['policies.insurer_id' => $insurer_id, 'policies.is_active' => 1])->findAll();
-
+                ->select('policies.*')
+                ->join('policy_type', 'policy_type.id = policies.policy_type_id')
+                ->whereIn('policy_type.policy_type', ['GMC - Parents', 'GMC - Top-up(Parents)'])
+                ->where(['policies.insurer_id' => $insurer_id, 'policies.is_active' => 1])->findAll();
         }
 
 
         $data = $this->clientPolicyModel->getClientPolicyByPolicyType($client_id['client_id'], $policy_type);
 
-        return $this->respond(['Status' => true,'code' => 200,'data' => $data, 'client_policy_id' => $client_policy_id, 'policy' => $polices], 200);
-
-
+        return $this->respond(['Status' => true, 'code' => 200, 'data' => $data, 'client_policy_id' => $client_policy_id, 'policy' => $polices], 200);
     }
 
     public function downloadKYCDocument($file_name)
@@ -2388,12 +2403,12 @@ class ClientController extends AdminController
     public function getClientBranch($client_id)
     {
 
-         $branchs = $this->clientBranchModel
-                ->select('*')
-                ->where('client_id',$client_id)
-                ->findAll();
+        $branchs = $this->clientBranchModel
+            ->select('*')
+            ->where('client_id', $client_id)
+            ->findAll();
 
-        return $this->respond(['status' => true,'code' => 200, 'data' => $branchs], 200);
+        return $this->respond(['status' => true, 'code' => 200, 'data' => $branchs], 200);
     }
 
     public function getClientAllDetailsByUsingClientID($client_id)
@@ -2460,7 +2475,7 @@ class ClientController extends AdminController
         $builder->where('policy_type.is_active', 1);
         $builder->where('client_policy.policy_status', 1);
         $builder->where('clients.id', $client_id);
-        
+
         $query = $builder->get();
         $client_policy = $query->getResultArray();
 
@@ -2531,17 +2546,17 @@ class ClientController extends AdminController
             "terrorism" => "Terrorism",
             "worldwideCover" => "Worldwide Cover"
         ];
-          
+
 
         foreach ($client_policy as $key => $value) {
 
             $policy_terms = json_decode($value['policy_terms'], true);
-       
+
             $mapping = $gmc_keys;
             if ($value['policy_type'] == 'GPA') {
                 $mapping = $gpa_keys;
             }
-        
+
             $client_policy[$key]['policy_terms'] = $this->transformArray($policy_terms, $mapping);
         }
 
@@ -2569,40 +2584,39 @@ class ClientController extends AdminController
             ->get()->getResultArray();
 
 
-       $data['client'] = $this->clientModel->where('clients.id', $client_id)->first();   
-        
-        
-       $client_rm = $this->clientRMModel
-       ->select('client_rm.*, user_profiles.first_name as user_name')
-       ->join('user_profiles', 'user_profiles.id = client_rm.user_id')
-       ->where('client_id', $client_id)->get()->getResultArray();   
-       
-       
-       $account_managers = [];
-       $managers = [];
-       $heads = [];
-       
-       foreach ($client_rm as $key => $value) {
-           if ($value['level'] == 3) {
-               $account_managers[] = $value['user_name'];
-           } elseif ($value['level'] == 2) {
-               $managers[] = $value['user_name'];
-           } elseif ($value['level'] == 1) {
-               $heads[] = $value['user_name'];
-           }
-       }
+        $data['client'] = $this->clientModel->where('clients.id', $client_id)->first();
 
-       $data['account_managers'] = $account_managers;
-       $data['managers'] = $managers;
-       $data['heads'] = $heads;
+
+        $client_rm = $this->clientRMModel
+            ->select('client_rm.*, user_profiles.first_name as user_name')
+            ->join('user_profiles', 'user_profiles.id = client_rm.user_id')
+            ->where('client_id', $client_id)->get()->getResultArray();
+
+
+        $account_managers = [];
+        $managers = [];
+        $heads = [];
+
+        foreach ($client_rm as $key => $value) {
+            if ($value['level'] == 3) {
+                $account_managers[] = $value['user_name'];
+            } elseif ($value['level'] == 2) {
+                $managers[] = $value['user_name'];
+            } elseif ($value['level'] == 1) {
+                $heads[] = $value['user_name'];
+            }
+        }
+
+        $data['account_managers'] = $account_managers;
+        $data['managers'] = $managers;
+        $data['heads'] = $heads;
 
         // dd($data);
         // $this->loadLayout('client_info', $data);
 
 
-       $html = view('client_info', $data);
-       return $this->respond(['status' => true,'code' => 200, 'data' => $html], 200);
-
+        $html = view('client_info', $data);
+        return $this->respond(['status' => true, 'code' => 200, 'data' => $html], 200);
     }
 
     public function transformArray($data, $mapping)
@@ -2621,13 +2635,12 @@ class ClientController extends AdminController
             } else if (array_key_exists($key, $mapping)) {
                 $transformedData[$mapping[$key]] = $value;
             } else if ($key == 'special_condition_label') {
-            
+
                 if (is_array($value)) {
                     foreach ($value as $key => $value) {
                         $transformedData[$value] = $data['special_condition_input'][$key];
                     }
                 }
-
             } else if ($key == 'gpa_special_condition_label') {
                 if (is_array($value)) {
                     foreach ($value as $key => $value) {
@@ -2705,36 +2718,34 @@ class ClientController extends AdminController
                 ->where('rack_rate_type', $rack_rate_type)
                 ->set('is_active', 0)
                 ->update();
-    
+
             if (!$result) {
 
-                return $this->respond(['status' => false,'code' => 200, 'message' => 'Failed to update the record.'], 200);
+                return $this->respond(['status' => false, 'code' => 200, 'message' => 'Failed to update the record.'], 200);
             }
         } catch (\Exception $e) {
 
             log_message('error', $e->getMessage());
-            return $this->respond(['status' => false,'code' => 200, 'message' => 'Failed to update the record.'], 200);
-
+            return $this->respond(['status' => false, 'code' => 200, 'message' => 'Failed to update the record.'], 200);
         }
-    
-        return $this->respond(['status' => true,'code' => 200, 'message' => 'Additionaly Rack Rate Data Remove Successfully'], 200);
+
+        return $this->respond(['status' => true, 'code' => 200, 'message' => 'Additionaly Rack Rate Data Remove Successfully'], 200);
     }
-    
+
     public function get_cd_ac($client_id, $insurer_id)
     {
 
         $cd_data = $this->CDMasterModel
-                        ->where('client_id', $client_id)
-                        ->where('insurer_id', $insurer_id)
-                        ->where('is_active', 1)
-                        ->findAll();
+            ->where('client_id', $client_id)
+            ->where('insurer_id', $insurer_id)
+            ->where('is_active', 1)
+            ->findAll();
 
-        if($cd_data){
+        if ($cd_data) {
             return $this->respond(['status' => true, 'code' => 200, 'data' => $cd_data], 200);
-        }else{
+        } else {
             return $this->respond(['status' => false, 'code' => 404, 'insurer_id' => $insurer_id, 'client_id' => $client_id], 200);
         }
-
     }
 
     public function otherPolicyTermsFormSubmit()
@@ -2764,34 +2775,32 @@ class ClientController extends AdminController
     {
 
         $policyCount = $this->clientPolicyModel
-        ->where('policy_type_id', $policy_type_id) 
-        ->where('client_branch_id', $client_branch_id)
-        ->where('client_id', $client_id)
-        ->countAllResults(); 
+            ->where('policy_type_id', $policy_type_id)
+            ->where('client_branch_id', $client_branch_id)
+            ->where('client_id', $client_id)
+            ->countAllResults();
 
-        if($policyCount > 0 ){
+        if ($policyCount > 0) {
             $clientPoliceData =  $this->clientPolicyModel->getClientPolicyByClientId($client_id);
-            return $this->respond(['status' => true,'code' => 200, 'count' =>  $policyCount, 'data' => $clientPoliceData, 'method' => 'CERATE' ,'client_id' => $client_id, 'client_branch_id' => $client_branch_id, 'policy_type_id' => $policy_type_id], 200);
-        }else{
-            return $this->respond(['status' => false,'code' => 200,'client_id' => $client_id, 'client_branch_id' => $client_branch_id, 'policy_type_id' => $policy_type_id], 200);
+            return $this->respond(['status' => true, 'code' => 200, 'count' =>  $policyCount, 'data' => $clientPoliceData, 'method' => 'CERATE', 'client_id' => $client_id, 'client_branch_id' => $client_branch_id, 'policy_type_id' => $policy_type_id], 200);
+        } else {
+            return $this->respond(['status' => false, 'code' => 200, 'client_id' => $client_id, 'client_branch_id' => $client_branch_id, 'policy_type_id' => $policy_type_id], 200);
         }
-
     }
 
     public function getPolicyTerms($client_policy_id)
     {
         $policy_terms = $this->clientPolicyModel->where('id', $client_policy_id)->first();
-    
+
         if (!$policy_terms) {
             // return $this->respond(['status' => false, 'error' => 'Policy not found'], 404);
             return [];
         }
-    
+
         if (is_array($policy_terms)) {
             if (!isset($policy_terms['policy_terms'])) {
                 // return $this->respond(['status' => false, 'error' => 'Policy terms not found in array'], 500);
                 return [];
-
             }
             $JSON = json_decode($policy_terms['policy_terms']);
         } elseif (is_object($policy_terms)) {
@@ -2804,20 +2813,20 @@ class ClientController extends AdminController
             // return $this->respond(['status' => false, 'error' => 'Unexpected data type for policy terms'], 500);
             return [];
         }
-    
+
         if (!$JSON) {
             // return $this->respond(['status' => false, 'error' => 'Invalid JSON format in policy terms'], 500);
             return [];
         }
-    
+
         $multi_si = [];
-    
+
         if (isset($JSON->sum_insured) && !empty($JSON->sum_insured)) {
             $multi_si[] = $JSON->sum_insured;
         } elseif (isset($JSON->sumInsured2) && !empty($JSON->sumInsured2)) {
             $multi_si[] = $JSON->sumInsured2;
         }
-    
+
         if (isset($JSON->multiple_sum_insured) && is_array($JSON->multiple_sum_insured)) {
             foreach ($JSON->multiple_sum_insured as $msi) {
                 if (!empty($msi)) {
@@ -2825,11 +2834,11 @@ class ClientController extends AdminController
                 }
             }
         }
-    
+
         // return $this->respond(['status' => true, 'data' => $multi_si], 200);
         return $multi_si;
     }
-    
+
     public function getPolicyTermsFormJson($policy_type_id)
     {
 
@@ -2847,21 +2856,21 @@ class ClientController extends AdminController
     {
         try {
             $mobileNumberCount = $this->levelContactModel
-                            ->join('client_branch', 'client_branch.id = level_contacts.ref_id')
-                            ->join('clients', 'clients.id = client_branch.client_id')
-                            ->where('clients.is_active', 1)
-                            ->where('client_branch.is_active', 1)
-                            ->where('level_contacts.is_active', 1)
-                            ->where('level_contacts.contact_type', 'client')
-                            ->where('level_contacts.mobile', $mobileNumber)
-                            ->countAllResults();
+                ->join('client_branch', 'client_branch.id = level_contacts.ref_id')
+                ->join('clients', 'clients.id = client_branch.client_id')
+                ->where('clients.is_active', 1)
+                ->where('client_branch.is_active', 1)
+                ->where('level_contacts.is_active', 1)
+                ->where('level_contacts.contact_type', 'client')
+                ->where('level_contacts.mobile', $mobileNumber)
+                ->countAllResults();
             return $this->respond(['status' => true, 'data' => $mobileNumberCount, 'message' => "try"], 200);
         } catch (\Exception $e) {
             log_message('error', 'Error checking mobile number: ' . $e->getMessage());
             return $this->respond(['status' => false, 'data' => 0, 'message' => 'An error occurred while checking the mobile number. Please try again later.'], 500);
         }
     }
- 
+
     public function checkAdditionPremiumJSON($client_id, $client_policy_id)
     {
 
@@ -2872,20 +2881,19 @@ class ClientController extends AdminController
             ->where('additional_relationship IS NOT NULL', null, false)
             ->countAllResults();
 
-        return $this->respond(['status' => true, 'data' => $get_additional_rack_rate_relationship_json, 'message' => "try"], 200);    
+        return $this->respond(['status' => true, 'data' => $get_additional_rack_rate_relationship_json, 'message' => "try"], 200);
     }
 
     public function getPolicyTypeForBasePolicy($client_id)
     {
 
-     $result = $this->clientPolicyModel->getPolicyTypeForPolicyBinding($client_id);   
-     return $this->respond(['status' => true, 'data' => $result], 200);
-
+        $result = $this->clientPolicyModel->getPolicyTypeForPolicyBinding($client_id);
+        return $this->respond(['status' => true, 'data' => $result], 200);
     }
 
     public function getClientDetails($client_id)
     {
-        $result = $this->clientModel->where('id', $client_id)->first();   
+        $result = $this->clientModel->where('id', $client_id)->first();
         return $this->respond(['status' => true, 'data' => $result], 200);
     }
 
@@ -2894,16 +2902,15 @@ class ClientController extends AdminController
 
         $units = $this->clientBranchModel->select('units')->where('id', $branch_id)->first();
 
-        if($units){
+        if ($units) {
             return $units['units'];
-        }else{
+        } else {
             return [];
         }
-
     }
 
     public function updateRackRateJson()
-    {   
+    {
         // $client_policy_id = 12;
 
         $results = $this->policyPremium2Model
@@ -2913,7 +2920,7 @@ class ClientController extends AdminController
             ->groupBy('client_policy_id')
             ->get()
             ->getResultArray();
-       
+
 
         $results2 = $this->policyPremium1Model
             ->select('*')
@@ -2922,29 +2929,27 @@ class ClientController extends AdminController
             ->groupBy('client_policy_id')
             ->get()
             ->getResultArray();
-       
+
         // dd($results, $results2);
 
         $client_policy_ids = [];
         $json = [];
         $json1 = [];
 
-        foreach ($results as $key => $result) 
-        {
+        foreach ($results as $key => $result) {
             $client_policy_id = $result['client_policy_id'];
             $client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first();
             $policy_terms = [];
-            
-            if(isset($client_policy_data['policy_terms'])) 
-            {
+
+            if (isset($client_policy_data['policy_terms'])) {
                 $policy_terms = json_decode($client_policy_data['policy_terms'], true);
-            } 
-                        
+            }
+
             if (isset($policy_terms['family_floaters'])) {
                 $family_floaters = $policy_terms['family_floaters'];
-               
-                if(isset($family_floaters['self']) && isset($family_floaters['spouse']) && isset($family_floaters['childrens']) && isset($family_floaters['parents']) && isset($family_floaters['parents-in-law']) && isset($family_floaters['either-parents-pil']) && isset($family_floaters['elders_count'])) {
-                   
+
+                if (isset($family_floaters['self']) && isset($family_floaters['spouse']) && isset($family_floaters['childrens']) && isset($family_floaters['parents']) && isset($family_floaters['parents-in-law']) && isset($family_floaters['either-parents-pil']) && isset($family_floaters['elders_count'])) {
+
                     $json1[] = $family_floaters;
 
                     $self = 1;
@@ -2953,19 +2958,19 @@ class ClientController extends AdminController
                     $parents = 'any';
                     $parents_in_law = 'any';
 
-                    if($family_floaters['self'] == 0){
+                    if ($family_floaters['self'] == 0) {
                         $self = 'NA';
                     }
-                    if($family_floaters['spouse'] == 0){
+                    if ($family_floaters['spouse'] == 0) {
                         $spouse = 'NA';
                     }
-                    if($family_floaters['childrens'] == 0){
+                    if ($family_floaters['childrens'] == 0) {
                         $childrens = 'NA';
                     }
-                    if($family_floaters['parents'] == 0){
+                    if ($family_floaters['parents'] == 0) {
                         $parents = 'NA';
                     }
-                    if($family_floaters['parents-in-law'] == 0){
+                    if ($family_floaters['parents-in-law'] == 0) {
                         $parents_in_law = 'NA';
                     }
 
@@ -2976,13 +2981,13 @@ class ClientController extends AdminController
                         "parents" =>  $parents,
                         "parents-in-law" => $parents_in_law,
                     ];
-                    
+
                     $formatedJSON = json_encode($transformed_family_floaters);
                     $json[] = $formatedJSON;
 
                     $forUpdateData = [
-                            "additional_relationship" => $formatedJSON,
-                            "rack_rate_name" => 'Primary',
+                        "additional_relationship" => $formatedJSON,
+                        "rack_rate_name" => 'Primary',
                     ];
 
                     $this->policyPremium2Model
@@ -2995,14 +3000,13 @@ class ClientController extends AdminController
             }
         }
 
-        foreach ($results2 as $key => $result) 
-        {
+        foreach ($results2 as $key => $result) {
             $client_policy_id = $result['client_policy_id'];
             $client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first();
 
             // dd($client_policy_data);
 
-            if(isset($client_policy_data) && $client_policy_data['policy_terms']){
+            if (isset($client_policy_data) && $client_policy_data['policy_terms']) {
 
                 $self = 1;
                 $spouse = 'NA';
@@ -3017,7 +3021,7 @@ class ClientController extends AdminController
                     "parents" =>  $parents,
                     "parents-in-law" => $parents_in_law,
                 ];
-                
+
                 $formatedJSON = json_encode($transformed_family_floaters);
                 $json[] = $formatedJSON;
 
@@ -3027,23 +3031,22 @@ class ClientController extends AdminController
                 ];
 
                 $this->policyPremium1Model
-                        ->where('client_policy_id', $client_policy_id)
-                        ->set($forUpdateData)
-                        ->update();
+                    ->where('client_policy_id', $client_policy_id)
+                    ->set($forUpdateData)
+                    ->update();
             }
         }
 
         $client_policy_ids[] = $client_policy_id;
-        
 
-        if(count($client_policy_ids) > 0){
+
+        if (count($client_policy_ids) > 0) {
             echo 'There are ' . count($client_policy_ids) . ' records to be updated.';
             echo '
'; dd($client_policy_ids); - }else{ + } else { echo 'There is no records to be update.'; } - } public function removeRackRate($rack_rate_name = null, $client_policy_id = null) @@ -3056,12 +3059,12 @@ class ClientController extends AdminController ]; $rackRateData = $this->policyPremium2Model - ->where('rack_rate_name', $rack_rate_name) - ->where('client_policy_id', $client_policy_id) - ->where('is_active',1) - ->countAllResults(); - - if($rackRateData > 0){ + ->where('rack_rate_name', $rack_rate_name) + ->where('client_policy_id', $client_policy_id) + ->where('is_active', 1) + ->countAllResults(); + + if ($rackRateData > 0) { $update = $this->policyPremium2Model ->where('rack_rate_name', $rack_rate_name) ->where('client_policy_id', $client_policy_id) @@ -3072,11 +3075,10 @@ class ClientController extends AdminController } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to remove Rack Rate', 'rr_count' => $rackRateData], 200); } - }else{ + } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'Rack Rate not available', 'rr_count' => $rackRateData], 200); - } - + } } public function renameRackRateTab($rack_rate_name = null, $new_rack_rate_name = null, $client_policy_id = null) @@ -3089,16 +3091,16 @@ class ClientController extends AdminController ]; $rackRateData = $this->policyPremium2Model - ->where('rack_rate_name', $rack_rate_name) - ->where('client_policy_id', $client_policy_id) - ->where('is_active',1) - ->countAllResults(); - - if($rackRateData > 0){ + ->where('rack_rate_name', $rack_rate_name) + ->where('client_policy_id', $client_policy_id) + ->where('is_active', 1) + ->countAllResults(); + + if ($rackRateData > 0) { $update = $this->policyPremium2Model ->where('rack_rate_name', $rack_rate_name) ->where('client_policy_id', $client_policy_id) - ->where('is_active',1) + ->where('is_active', 1) ->set($data) ->update(); @@ -3109,31 +3111,30 @@ class ClientController extends AdminController } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to rename Rack Rate', 'rr_count' => $affectedRows], 200); } - }else{ + } else { - return $this->respond(['status' => false, 'code' => 404, 'message' => 'Rack Rate not available', 'rr_count' => $rackRateData, 'rack_rate_name' => $rack_rate_name, 'client_policy_id' => $client_policy_id, 'new_rack_rate_name' => $new_rack_rate_name, ], 200); - } + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Rack Rate not available', 'rr_count' => $rackRateData, 'rack_rate_name' => $rack_rate_name, 'client_policy_id' => $client_policy_id, 'new_rack_rate_name' => $new_rack_rate_name,], 200); + } } public function getBranchByClientID($client_id) { $branch_list = $this->clientBranchModel->where('client_id', $client_id)->where('is_active', 1)->findAll(); $policy_list = []; - foreach ($branch_list as $value) - { + foreach ($branch_list as $value) { $policy_data = $this->clientPolicyModel - ->select('client_policy.*, policy_type.policy_type') - ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') - ->where('client_policy.client_id', $value['client_id']) - ->where('client_policy.client_branch_id', $value['id']) - ->where('client_policy.is_active', 1) - ->findAll(); + ->select('client_policy.*, policy_type.policy_type') + ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') + ->where('client_policy.client_id', $value['client_id']) + ->where('client_policy.client_branch_id', $value['id']) + ->where('client_policy.is_active', 1) + ->findAll(); $policy_list[$value['id']] = $policy_data; } - - if($branch_list){ + + if ($branch_list) { return $this->respond(['status' => true, 'data' => $branch_list, 'policy_data' => $policy_list], 200); - }else{ + } else { return $this->respond(['status' => false], 200); } } @@ -3142,17 +3143,17 @@ class ClientController extends AdminController { $clients = $this->clientModel->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(); + ->select('vehicle.*, clients.client_type') + ->join('clients', 'clients.id=vehicle.owner') + ->where('vehicle.is_active', 1)->findAll(); $clientIds = array_column($clients, 'id'); - + // Fetch branches in a single query $branches = $this->clientBranchModel ->whereIn('client_id', $clientIds) ->where('is_active', 1) ->findAll(); - + // Fetch policies in a single query $policies = $this->clientPolicyModel ->select(" @@ -3170,17 +3171,17 @@ class ClientController extends AdminController ->whereIn('client_policy.client_id', $clientIds) ->where('client_policy.is_active', 1) ->findAll(); - + $branchList = []; $policyList = []; $policyListByClient = []; $unitList = []; - + foreach ($branches as $branch) { $branchList[$branch['client_id']][] = $branch; $unitList[$branch['id']][] = json_decode($branch['units']); } - + foreach ($policies as $policy) { $policyList[$policy['client_branch_id']][] = $policy; $policyListByClient[$policy['client_id']][] = $policy; @@ -3190,17 +3191,17 @@ class ClientController extends AdminController $policyCount[$policy['client_id']] = 1; } } - + foreach ($clients as &$client) { $client['client_policy_count'] = $policyCount[$client['id']] ?? 0; } - + if (!empty($branchList)) { return $this->respond([ - 'status' => true, - 'client_data' => $clients, - 'vehicle_data' => $vehicles, - 'branch_data' => $branchList, + 'status' => true, + 'client_data' => $clients, + 'vehicle_data' => $vehicles, + 'branch_data' => $branchList, 'policy_data' => $policyList, 'policyListByClient' => $policyListByClient, 'unit_data' => $unitList, @@ -3209,22 +3210,22 @@ class ClientController extends AdminController return $this->respond(['status' => false], 200); } } - + public function getCDAccNoByClientAndInsurer($client, $insurer) { $cdmData = $this->CDMasterModel->where('client_id', $client)->where('insurer_id', $insurer)->findAll(); - if($cdmData){ + if ($cdmData) { return $this->respond(['status' => true, 'data' => $cdmData], 200); - }else{ + } else { return $this->respond(['status' => false], 200); } } public function createClientWithMinimalData() - { + { $postData = $this->request->getPost(); // print_r($postData); die; $client_type = $postData['client_type']; @@ -3235,9 +3236,9 @@ class ClientController extends AdminController 'pan' => $postData['pan'], 'client_code' => generate_client_code(), ]; - + // Add additional fields if client type is 2 - if($client_type == 2) { + if ($client_type == 2) { $client_data = array_merge($client_data, [ 'dob' => $postData['dob'], 'aadhar' => $postData['aadhar'], @@ -3248,16 +3249,16 @@ class ClientController extends AdminController } else { $client_data['entity_type_id'] = $postData['entity_type_id']; } - + // Insert client data $client_insert = $this->clientModel->insert($client_data); - - if(!$client_insert) { + + if (!$client_insert) { return $this->respond(['status' => false, 'message' => 'Failed to create client'], 200); } - + // Additional logic for non-individual clients (client_type != 2) - if($client_type != 2) { + if ($client_type != 2) { $unit = $postData['short_name'] . '-' . $postData['branch_code']; $branch_data = [ 'client_id' => $client_insert, @@ -3266,7 +3267,7 @@ class ClientController extends AdminController 'gst' => $postData['gst'], 'units' => $unit, ]; - + $branch_insert = $this->clientBranchModel->insert($branch_data); if ($branch_insert) { $contact_data = [ @@ -3278,47 +3279,47 @@ class ClientController extends AdminController $this->levelContactModel->insert($contact_data); } } - + return $this->respond([ - 'status' => true, - 'data' => $postData, - 'client_id' => $client_insert, - 'branch_id' => $branch_insert ?? null, + 'status' => true, + 'data' => $postData, + 'client_id' => $client_insert, + 'branch_id' => $branch_insert ?? null, 'message' => 'Client created successfully' ], 200); } - + public function createVehicleWithMinimalData() { $data = $this->request->getPost(); $id = $this->request->getPost('vehicle_primary_key'); - if($id){ + if ($id) { $vehicle_update = $this->vehicleModel->where('id', $id)->set($data)->update(); - if($vehicle_update){ + if ($vehicle_update) { return $this->respond(['status' => true, 'message' => 'Vehicle details updated successfully'], 200); - }else{ + } else { return $this->respond(['status' => false, 'message' => 'Failed to update vehicle details'], 200); } - - }else{ + } else { $vehicle_insert = $this->vehicleModel->insert($data); - if($vehicle_insert){ + if ($vehicle_insert) { $vehicles = $this->vehicleModel->where('is_active', 1)->findAll(); return $this->respond([ - 'status' => true, - 'vehicle_id' => $vehicle_insert, - 'owner_id' => $data['owner'], - 'owner_branch_id' => $data['branch_id'] ?? null, - 'owner_type' => $data['Owner_type'], - 'vehicles' => $vehicles, - 'message' => 'Vehicle created successfully - '], 200); - }else{ + 'status' => true, + 'vehicle_id' => $vehicle_insert, + 'owner_id' => $data['owner'], + 'owner_branch_id' => $data['branch_id'] ?? null, + 'owner_type' => $data['Owner_type'], + 'vehicles' => $vehicles, + 'message' => 'Vehicle created successfully + ' + ], 200); + } else { return $this->respond(['status' => false, 'message' => 'Failed to created vehicle'], 200); } } @@ -3330,7 +3331,7 @@ class ClientController extends AdminController $insurerValue = (string) $this->request->getPost('insurer'); list($insurerBranchId, $insurerId) = explode('-', $insurerValue); - + $data['insurer_branch_id'] = $insurerBranchId; $data['insurer_id'] = $insurerId; $data['policy_status'] = 1; @@ -3343,7 +3344,7 @@ class ClientController extends AdminController $insert = $this->clientPolicyModel->insert($data); - if($insert){ + if ($insert) { $policies = $this->clientPolicyModel ->select('client_policy.*, policy_type.policy_type') @@ -3354,13 +3355,13 @@ class ClientController extends AdminController ->findAll(); return $this->respond(['status' => true, 'data' => $policies, 'client_policy_id' => $insert, 'message' => 'Client policy created successfully'], 200); - }else{ + } else { return $this->respond(['status' => false, 'message' => 'Failed to created client policy'], 200); } } public function getPolicyDetailsByPolicyId($id) - { + { $policies = $this->clientPolicyModel ->select('client_policy.*, policy_type.policy_type') ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') @@ -3368,9 +3369,9 @@ class ClientController extends AdminController ->where('client_policy.is_active', 1) ->findAll(); - if($policies){ + if ($policies) { return $this->respond(['status' => true, 'data' => $policies, 'message' => 'Client policy created successfully'], 200); - }else{ + } else { return $this->respond(['status' => false, 'message' => 'Failed to created client policy'], 200); } } @@ -3382,9 +3383,9 @@ class ClientController extends AdminController ->where('is_active', 1) ->findAll(); - if($uniqueAC != null){ + if ($uniqueAC != null) { return $this->respond(['status' => true, 'message' => 'The Cost Center is Already Exist', 'code' => 200], 200); - }else{ + } else { return $this->respond(['status' => false, 'code' => 404], 200); } } @@ -3396,9 +3397,9 @@ class ClientController extends AdminController ->where('is_active', 1) ->findAll(); - if($uniqueAC != null){ + if ($uniqueAC != null) { return $this->respond(['status' => true, 'message' => 'The Policy Number is Already Exist', 'code' => 200], 200); - }else{ + } else { return $this->respond(['status' => false, 'code' => 404], 200); } } @@ -3412,9 +3413,9 @@ class ClientController extends AdminController ->where('client_policy.is_active', 1) ->first(); - if($data){ - return $this->respond(['status' => true, 'data'=> $data, 'code' => 200], 200); - }else{ + if ($data) { + return $this->respond(['status' => true, 'data' => $data, 'code' => 200], 200); + } else { return $this->respond(['status' => false, 'message' => 'No Data Found', 'code' => 404], 200); } } @@ -3429,11 +3430,10 @@ class ClientController extends AdminController ->where('client_policy.is_active', 1) ->first(); - if($data){ - return $this->respond(['status' => true, 'data'=> $data, 'code' => 200], 200); - }else{ + if ($data) { + return $this->respond(['status' => true, 'data' => $data, 'code' => 200], 200); + } else { return $this->respond(['status' => false, 'message' => 'No Data Found', 'code' => 404], 200); } } - -} \ No newline at end of file +} diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 4786af5f..079e4d35 100755 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -165,8 +165,9 @@ class DashboardController extends AdminController $data['financeTeamCount'] = count($financeTeamData) ?? 0; // print_r($data);die; + $data['page_name'] = 'Dashboard'; - echo view('layout/header'); + echo view('layout/header', $data); echo view('DashBoard', $data); echo view('layout/footer'); } @@ -201,59 +202,71 @@ class DashboardController extends AdminController public function updatePolicyEnrollmentStatus() { - $clientModel = new ClientModel(); $clientPolicyModel = new ClientPolicyModel(); - $notificationModel = new NotificationModel(); - $employeePolicyModel = new EmployeePolicyModel(); $myLogger = \Config\Services::mylogger(); - - // $myLogger->logme('error', 'enrollment_status function called'); - - $client_policy_data = $clientPolicyModel->getPolicyDetailsForRemainder(); - $myLogger->logme('error', 'Fetched client policy data'); + + $client_policy_data = $clientPolicyModel->getPolicyDetailsForEnrollment(); + $myLogger->logme('error', 'Fetched client policy data for Enrollment Status update'); // dd($client_policy_data); - $currentDate = date('d'); - // $myLogger->logme('error', 'Current date: ' . $currentDate); + $currentDate = date('d-m-Y'); + $openEnrollment = []; + $closeEnrollment = []; // Update policy status based on start and end dates foreach ($client_policy_data as $client_policy) { $id = $client_policy['id']; - $openDate = date('d', strtotime($client_policy['open_date'])); - $closeDate = date('d', strtotime($client_policy['close_date'])); - - // $myLogger->logme('error', 'Processing client policy ID: ' . $id); - // $myLogger->logme('error', 'Open date: ' . $openDate . ', Close date: ' . $closeDate); - + $openDate = date('d-m-Y', strtotime($client_policy['open_date'])); + $closeDate = date('d-m-Y', strtotime($client_policy['close_date'])); + if ($currentDate == $openDate) { $clientPolicyModel->update($id, ['open_for_enrollment' => 1]); + $openEnrollment[] = $id; $myLogger->logme('error', 'Updated policy ID ' . $id . ' to open for enrollment.'); } if ($closeDate < $currentDate) { $clientPolicyModel->update($id, ['open_for_enrollment' => 0]); + $closeEnrollment[] = $id; $myLogger->logme('error', 'Updated policy ID ' . $id . ' to close for enrollment.'); } } + + $myLogger->logme('error', 'enrollment_status function completed'); + return $this->respond([ + 'status' => true, + 'message' => 'updated Policy Enrollment Status', + 'open_policy_count' => count($openEnrollment), + 'close_policy_count' => count($closeEnrollment), + 'open_policy_ids' => $openEnrollment, + 'close_policy_ids' => $closeEnrollment, + ]); + + } + + public function sendCroneRemainderMail() + { + $clientPolicyModel = new ClientPolicyModel(); + $myLogger = \Config\Services::mylogger(); + + + $client_policy_data = $clientPolicyModel->getPolicyDetailsForRemainder(); + $myLogger->logme('error', 'Fetched client policy data'); + // dd($client_policy_data); // Mail send function - // $myLogger->logme('error', 'Calling sendRemainderMail function'); - if( $currentDate == date('d', strtotime($client_policy['reminder_date']))){ - $result = $this->sendRemainderMail($client_policy_data); - }else{ - $result = false; - } - - // $myLogger->logme('error', 'enrollment_status function completed'); + $result = $this->sendRemainderMail($client_policy_data, 'crone'); + + $myLogger->logme('error', 'sendCroneRemainderMail function completed'); + if($result){ return json_encode(['status' => true, 'message' => 'Mail send successfully']); }else{ return json_encode(['status' => false, 'message' => 'There is no data to send']); } } - public function featch_dashboard_data($type) { @@ -291,65 +304,133 @@ class DashboardController extends AdminController return $this->respond(['status' => true, 'data' => $data], 200); } - - public function sendRemainderMail($client_policy_data) + public function sendRemainderMail($client_policy_data, $send_mail_for_manual_or_crone = null) { // $this->myLogger->logme('error', 'sendRemainderMail function called'); + // dd($client_policy_data, $send_mail_for_manual_or_crone); + $reminder_whole_mail = []; foreach ($client_policy_data as $client_policy) { - - // Fetch client data - $client_data = $this->clientModel->find($client_policy['client_id']); - - // Fetch notification settings - $notification_data = $this->notificationModel - ->where('client_id', $client_policy['client_id']) - ->where('template_name', 'member_reminder_mail') - ->first(); - // $this->myLogger->logme('error', 'Notification data fetched: ' . json_encode($notification_data)); - - // Check if notification should be sent - if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { - $this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']); - - // Fetch all employees related to the client policy - $employees = $this->employeePolicyModel - ->select('employees.*') - ->join('employees', 'employee_polices.employee_id = employees.id', 'left') - ->where('employee_polices.client_policy_id', $client_policy['id']) - ->where('employees.emp_status', 'draft') - ->where('employees.is_active', 1) - ->where('employee_polices.status', 'draft') - ->where('employee_polices.is_active', 1) - ->where('employees.relationship', 'Self') - ->findAll(); - - // Process each employee - foreach ($employees as $employee) { - - if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') { - $this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']); - - // Mail params - $params['emp_data'] = $employee; - $params['client_data'] = $client_data; - $params['notification_data'] = $notification_data; - - // Send the mail notification - $mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params); - // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); - $reminder_whole_mail[] = $mail_result; + if(empty($send_mail_for_manual_or_crone)){ + + // echo '1'; + + // Fetch client data + $client_data = $this->clientModel->find($client_policy['client_id']); + + // Fetch notification settings + $notification_data = $this->notificationModel + ->where('client_id', $client_policy['client_id']) + ->where('template_name', 'member_reminder_mail') + ->first(); + + // $this->myLogger->logme('error', 'Notification data fetched: ' . json_encode($notification_data)); + + // Check if notification should be sent + if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { + $this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']); + + // Fetch all employees related to the client policy + $employees = $this->employeePolicyModel + ->select('employees.*') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.emp_status', 'draft') + ->where('employees.is_active', 1) + ->where('employee_polices.status', 'draft') + ->where('employee_polices.is_active', 1) + ->where('employees.relationship', 'Self') + ->findAll(); + + // Process each employee + foreach ($employees as $employee) { + + if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') { + $this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']); + + // Mail params + $params['emp_data'] = $employee; + $params['client_data'] = $client_data; + $params['notification_data'] = $notification_data; + + // Send the mail notification + $mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params); + // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); + $reminder_whole_mail[] = $mail_result; + } + } + } else { + $this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']); + } + + } else { + + // echo '2'; + + $currentDate = date('d-m-Y'); + + if($currentDate == date('d-m-Y', strtotime($client_policy['reminder_date']))){ + + // echo '3'; + + $client_data = $this->clientModel->find($client_policy['client_id']); + + // Fetch notification settings + $notification_data = $this->notificationModel + ->where('client_id', $client_policy['client_id']) + ->where('template_name', 'member_reminder_mail') + ->first(); + + // Check if notification should be sent + if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { + + // echo '4'; + + $this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']); + + // Fetch all employees related to the client policy + $employees = $this->employeePolicyModel + ->select('employees.*') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.emp_status', 'draft') + ->where('employees.is_active', 1) + ->where('employee_polices.status', 'draft') + ->where('employee_polices.is_active', 1) + ->where('employees.relationship', 'Self') + ->findAll(); + + // Process each employee + foreach ($employees as $employee) { + + if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') { + $this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']); + + // Mail params + $params['emp_data'] = $employee; + $params['client_data'] = $client_data; + $params['notification_data'] = $notification_data; + + // Send the mail notification + $mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params); + // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); + $reminder_whole_mail[] = $mail_result; + } + } + } else { + // echo '5'; + $this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']); } } - } else { - $this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']); } } - $this->myLogger->logme('error', 'Whole email, count: ' . $reminder_whole_mail); + // dd($reminder_whole_mail); + + // $this->myLogger->logme('error', 'Whole email, count: ' . $reminder_whole_mail); // Process and queue bulk emails $temp_whole_data = []; @@ -386,7 +467,6 @@ class DashboardController extends AdminController } - public function sendManualRemainder($client_id, $client_branch_id) { $this->myLogger->logme('error', "sendManualRemainder called with client_id: {$client_id}, client_branch_id: {$client_branch_id}"); @@ -413,7 +493,6 @@ class DashboardController extends AdminController return $this->respond(['status' => false, 'code' => 200, 'message' => 'There is no data to send', 'message2' => 'No policy data found to send'], 200); } } - - + } diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 4ea1ce46..09e81058 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -1811,6 +1811,7 @@ class EmpDataServiceController extends BaseController $file_data = $this->getDataByFileId($file_id, 'success'); $this->setPullNotification($file_data); + //import file to upload Google Drive // if(excelFileGDriveUpload($file_id, 'batch_file')){ // $this->myLogger->logme('error', 'Inception Update Google Drive File Upload -- File Uploaded Successfully'); // }else{ @@ -2233,6 +2234,13 @@ class EmpDataServiceController extends BaseController $this->setPullNotification($file_data); + //import file to upload Google Drive + // if(excelFileGDriveUpload($file_id, 'batch_file')){ + // $this->myLogger->logme('error', 'Correction File Update Google Drive File Upload -- File Uploaded Successfully'); + // }else{ + // $this->myLogger->logme('error', 'Correction File Update Google Drive File Upload -- File Uploaded Field'); + // } + return 'Import Correction Updated '. $status_val . '- Updated Count : ' . $emp_count; } @@ -2847,6 +2855,13 @@ class EmpDataServiceController extends BaseController 'user_id' => $user_id, ]]); + //import file to upload Google Drive + // if(excelFileGDriveUpload($file_id, 'batch_file')){ + // $this->myLogger->logme('error', 'SI Enhancement File Update Google Drive File Upload -- File Uploaded Successfully'); + // }else{ + // $this->myLogger->logme('error', 'SI Enhancement File Update Google Drive File Upload -- File Uploaded Field'); + // } + return 'SI Enhancement Update Endorsement ID -- ' . $status_val . '-- Updated Count : ' . $emp_count; } @@ -3368,6 +3383,13 @@ class EmpDataServiceController extends BaseController 'user_id' => $user_id, ]]); + //import file to upload Google Drive + // if(excelFileGDriveUpload($file_id, 'batch_file')){ + // $this->myLogger->logme('error', 'Deletion File Update Google Drive File Upload -- File Uploaded Successfully'); + // }else{ + // $this->myLogger->logme('error', 'Deletion File Update Google Drive File Upload -- File Uploaded Field'); + // } + return 'Deletion Update Endorsement ID -- ' . $status_val . '-- Updated Count : ' . $emp_count; } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 9554fe4d..8d6ace5c 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -212,7 +212,7 @@ class EmployeeRestController extends AdminController public function addEmployeeAndDependence() { - // try { + try { $data = $this->request->getJSON(); @@ -254,20 +254,13 @@ class EmployeeRestController extends AdminController if(isset($data[0]->id)) { - if(!isset($data[0]->is_addon_value)) - { - $this->createEmployeePolicyData($data[0]->id , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id); - }else{ + $this->createEmployeePolicyData($data[0]->id , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id , $data[0]->basic_cover_si); - } - + }else{ - if(!isset($data[0]->is_addon_value)) - { - $this->createEmployeePolicyData($employee , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id); - }else{ + $this->createEmployeePolicyData($employee , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id , $data[0]->basic_cover_si); - } + } @@ -283,9 +276,9 @@ class EmployeeRestController extends AdminController return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 404); } } - // } catch (\Exception $e) { - // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); - // } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } } @@ -446,6 +439,29 @@ class EmployeeRestController extends AdminController try { $requestData = $this->request->getJSON(); + foreach ($requestData as $key => $value) + { + + $checkIfExist = $this->employeePolicyModel->where('employee_id', $value->employee_id) + ->where('client_policy_id', $value->client_policy_id) + ->where('is_active', 1 ) + ->findAll(); + + + if ($checkIfExist) { + + $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id, $value->employee_id, $value->basic_cover_si); + + }else{ + + $data['employee_id']= $value->employee_id; + $data['client_policy_id']= $value->client_policy_id; + $data['basic_cover_si']= $value->basic_cover_si; + $data['status'] = 'draft'; + + $this->employeePolicyModel->insert($data); + } + } if(count($requestData)) { $this->updatePremiumAmount($requestData[0]->client_policy_id , $requestData[0]->emp_code , $requestData[0]->client_branch_id); @@ -1006,7 +1022,7 @@ class EmployeeRestController extends AdminController $self['data']['dob'] = $this->convertDateFormatDMY($selfData[0]['dob']); $self['data']['mobile'] = $selfData[0]['mobile']; $self['data']['client_policy_id'] = $array->ClientPolicyId; - $self['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + $self['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : 0; $array->mapped_family_floaters = $self; $array->type = 'GPA'; @@ -1063,6 +1079,7 @@ class EmployeeRestController extends AdminController foreach ($empData as $key => $value) { if ($value['family_floater_key'] === $dependent) { $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array->ClientPolicyId)->where('is_active', 1 )->get()->getRow(); + $temp['is_value_exist'] = true; $temp['data']['family_floater_key'] = $familyFloatesValue; $temp['data']['employee_id'] = $value['id']; @@ -1071,7 +1088,7 @@ class EmployeeRestController extends AdminController $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); $temp['data']['client_policy_id'] = $array->ClientPolicyId; $temp['data']['form_type'] = $dependent; - $temp['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + $temp['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : 0; $temp['data']['age_validation'] = $this->getAgeRange($decodedArray,$familyFloatesValue); @@ -1171,7 +1188,7 @@ class EmployeeRestController extends AdminController return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200); } } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getLine()], 500); } } @@ -1267,7 +1284,7 @@ class EmployeeRestController extends AdminController $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); $temp['data']['client_policy_id'] = $array->ClientPolicyId; $temp['data']['form_type'] = $dependent; - $temp['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + $temp['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : 0; $temp['data']['age_validation'] = $this->getAgeRange($array->Policy_Terms,$familyFloatesValue); @@ -1374,7 +1391,7 @@ class EmployeeRestController extends AdminController $self['data']['dob'] = $this->convertDateFormatDMY($selfData[0]['dob']); $self['data']['mobile'] = $selfData[0]['mobile']; $self['data']['client_policy_id'] = $array->ClientPolicyId; - $self['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + $self['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : 0; $array->mapped_family_floaters = $self; if($array->enrolment_visibility == 1) @@ -1507,9 +1524,7 @@ class EmployeeRestController extends AdminController if(count($clientPolicy)) { - $self = $this->employeeModel - ->join('employee_polices', 'employees.id = employee_polices.employee_id') - ->where('employees.is_active', 1) + $self = $this->employeeModel->where('employees.is_active', 1) ->where('employees.emp_code', $this->request->getGet('emp_code')) ->where('employees.client_id', $this->request->getGet('client_id')) ->where('employees.client_branch_id', $this->request->getGet('client_branch_id')) @@ -1560,6 +1575,7 @@ class EmployeeRestController extends AdminController $responce['OpenForEnrollment'] = $array['open_for_enrollment']; $responce['policy_terms'] = $decodedArray; $responce['policy_type_id'] = $array['policy_type_id']; + $responce['disclaimer'] = $array['disclaimer']; $tpaArray = $this->employeeModel->select('employees.name as name , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') ->join('employee_polices', 'employee_polices.employee_id = employees.id') @@ -1593,8 +1609,18 @@ class EmployeeRestController extends AdminController if($array['is_addon'] == 3 && $array['policy_type_id'] == 3)//dependent add on policy { - - $selfSi = $self->basic_cover_si; + $selfGMC = $this->employeeModel->select('employees.name , employee_polices.basic_cover_si') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id AND client_policy.policy_type_id = 2') + ->where('employees.is_active', 1) + ->where('employees.emp_code', $this->request->getGet('emp_code')) + ->where('employees.client_id', $this->request->getGet('client_id')) + ->where('employees.client_branch_id', $this->request->getGet('client_branch_id')) + ->where('employees.family_floater_key', 'self') + ->get() + ->getRow(); + + $selfSi = $selfGMC->basic_cover_si; $filteredSlabRates = array_filter($responce['SlabRates'], function ($rate) use ($selfSi) { return $rate['si'] === $selfSi; }); @@ -1889,6 +1915,8 @@ class EmployeeRestController extends AdminController $mail_send_return1 = MailHelper::send_email($value); $this->myLogger->logme("info", $mail_send_return1); } + }else{ + $this->myLogger->logme("error", 'Account Manager Mail Configuration not Enable for this client'); } $client_hr_wholeData =sendMailNotification::sendMailNotification('client_hr_summary_mail', $params); @@ -1899,8 +1927,12 @@ class EmployeeRestController extends AdminController $mail_send_return2 = MailHelper::send_email($value); $this->myLogger->logme("info", $mail_send_return2); } + }else{ + $this->myLogger->logme("error", 'Client HR Mail Configuration not Enable for this client'); } } + }else{ + $this->myLogger->logme("error", 'Member Review Mail Configuration not Enable for this client'); } } diff --git a/app/Controllers/GoogleDriveController.php b/app/Controllers/GoogleDriveController.php index 5af27b9f..bf689112 100644 --- a/app/Controllers/GoogleDriveController.php +++ b/app/Controllers/GoogleDriveController.php @@ -266,7 +266,7 @@ class GoogleDriveController extends BaseController 'fields' => 'id' // Specify fields to return ]); - if($createdFile->id) + if($createdFile->id && $doc_type !== 'UPLOADS') { unlink($file_path); } diff --git a/app/Controllers/NotificationController.php b/app/Controllers/NotificationController.php index 2c050523..ff666cef 100755 --- a/app/Controllers/NotificationController.php +++ b/app/Controllers/NotificationController.php @@ -18,18 +18,20 @@ use App\Models\EmployeeModel; use App\Models\UserModel; use App\Helpers\sendMailNotification; - +use App\Helpers\MailHelper; class NotificationController extends AdminController { use ResponseTrait; protected $myLogger; protected $notificationModel; + protected $clientModel; public function __construct() { $this->myLogger = \Config\Services::mylogger(); $this->notificationModel = new NotificationModel(); + $this->clientModel = new ClientModel(); } // This is for Template Name Camel Case to Snake Case for store in DB @@ -88,6 +90,8 @@ class NotificationController extends AdminController $id =$this->request->getPost('client_id'); $clientData['common_mails'] = $this->request->getPost('nhance_team_mail_ids'); $clientData['hr_mails'] = $this->request->getPost('hr_mail_id'); + $clientData['reply_to'] = $this->request->getPost('reply_to'); + $clientData['mail_domain'] = $this->request->getPost('mail_domain'); $clientModel->update($id,$clientData); foreach ($data as $key => $value) @@ -159,4 +163,39 @@ class NotificationController extends AdminController } } } + + // This function for sent a mail for testing + public function sentTestMail($template_id, $test_mail) + { + $notification_data = $this->notificationModel->where('id', $template_id)->where('enabled', 1)->first(); + $client_data = $this->clientModel->where('id', $notification_data['client_id'])->where('is_active', 1)->first(); + + if(!empty($notification_data)){ + + $params = [ + 'client_data' => $client_data, + 'notification_data' => $notification_data, + 'test_mail' => $test_mail + ]; + + $testMailData = sendMailNotification::sendMailNotificationForTesting($notification_data['template_name'], $params); + // print_r($testMailData); die; + if (!empty($testMailData)) { + + $mail_send_return1 = MailHelper::send_email($testMailData); + $this->myLogger->logme("info", $mail_send_return1); + $this->myLogger->logme("info", $mail_send_return1); + + return $this->respond(['status' => true,'code' => 200, 'respond' => json_decode($mail_send_return1)]); + + }else{ + + return $this->respond(['status' => false,'code' => 200, 'message' => 'Test Mail Data Does Not Exist']); + } + }else{ + + return $this->respond(['status' => false,'code' => 200, 'message' => 'Notification Template not enabled']); + + } + } } \ No newline at end of file diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index c927ac44..1eacb67f 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -29,6 +29,8 @@ use App\Models\UserModel; use App\Models\EmployeePolicyModel; use App\Models\InsurerStatements; use App\Models\InvPaymentDetailsModel; +use App\Models\BatchFileModel; +use App\Models\FileModel; use Kint; class PolicyTransactionController extends BaseController @@ -58,6 +60,8 @@ class PolicyTransactionController extends BaseController protected $insurerStatements; protected $invoiceStatus; protected $invPaymentDetailsModel; + protected $batchFileModel; + protected $filesModel; public function __construct() { @@ -85,6 +89,8 @@ class PolicyTransactionController extends BaseController $this->employeePolicyModel = new EmployeePolicyModel(); $this->insurerStatements = new InsurerStatements(); $this->invPaymentDetailsModel = new InvPaymentDetailsModel(); + $this->batchFileModel = new BatchFileModel(); + $this->filesModel = new FileModel(); $this->invoiceStatus = [ 'pending' => 'Pending', 'generated' => 'Generated', @@ -1498,6 +1504,8 @@ class PolicyTransactionController extends BaseController ->findAll(); // dd( $this->insurerStatements->getLastQuery()); + $data['page_name'] = 'Statement Upload'; + $this->loadLayout('insurer_statement_list', $data); } @@ -1969,12 +1977,17 @@ class PolicyTransactionController extends BaseController $policy_doc_name = $this->request->getPost('policy_doc_name'); $pt_files = []; $kyc_files = []; + $batch_files = []; + $files = []; // print_r($jsonData);die(); if($policy_id != "") { //get policy docs from policy transation related tables $pt_files = $this->PTFileModel->getPolicyDriveFilesIndex($policy_id,$policy_doc_name); - // ~dd($this->PTFileModel->getLastQuery()); + $batch_files = $this->batchFileModel->getBatchFilesDataForDocumentSearch($policy_id,$policy_doc_name); + $files = $this->filesModel->getFilesDataForDocumentSearch($policy_id,$policy_doc_name); + // dd($files); + // dd($this->PTFileModel->getLastQuery()); // ~dd($pt_files); } if($customer_id != "") @@ -1984,11 +1997,12 @@ class PolicyTransactionController extends BaseController // !dd($kyc_files); } - $data['files'] = array_merge($pt_files,$kyc_files); - // dd($data['files']); + $data['files'] = array_merge($pt_files,$kyc_files,$batch_files,$files); + // dd($data['files']); } - + $data['page_name'] = 'Documents Search'; + $data['customers'] = $this->clientModel->select('id,client_name,short_name as display_value')->where('is_active',1)->get()->getResultarray(); $data['policies'] = $this->clientPolicyModel->select("client_policy.id,client_policy.policy_no,policy_type.policy_type,concat(policy_type.policy_type,' - ',client_policy.policy_no) as display_value") ->join('policy_type','client_policy.policy_type_id = policy_type.id') @@ -1999,5 +2013,4 @@ class PolicyTransactionController extends BaseController } - } \ No newline at end of file diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 9ff6a624..bddd1a49 100755 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -93,6 +93,8 @@ class MailHelper $emaill = $params['mail']; $subject = $params['subject']; $message = $params['message']; + + //check BCC mail if (isset($params['bcc'])) { $bcc = $params['bcc']; $bcc = explode(',', $bcc); @@ -100,16 +102,23 @@ class MailHelper $bcc = []; } + //check CC mail if (isset($params['cc'])) { $cc = $params['cc']; $cc = explode(',', $cc); }else{ $cc = []; } + + //check REPLY TO mail + $reply_to = ""; + if(isset($params['reply_to']) && !empty($params['reply_to'])){ + $reply_to = $params['reply_to']; + } + try { - - $res = $gmailapi->sendMessage($emaill, $subject, $message, 'info@nhanceindia.in', 'info@nhanceindia.in', $cc, $bcc); + $res = $gmailapi->sendMessage($emaill, $subject, $message, 'info@nhanceindia.in', $reply_to, $cc, $bcc); if($res['status']) { diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 311ccd47..91907824 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -14,6 +14,7 @@ class sendMailNotification { $wholeData =[]; if ($action == 'member_welcome_mail') { + $dataToInsert = $params['dataToInsert']; $notification = $params['notification']; $client_data = $params['client_data']; @@ -33,10 +34,13 @@ class sendMailNotification $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); if ($dataToInsert['relationship'] == 'Self' && $mail != null || $mail != '') { - $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails']]; + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; } + return $wholeData; + } else if($action == 'member_reminder_mail'){ + $EmployeeModel = new EmployeeModel(); $emp_data = $params['emp_data']; $notification_data = $params['notification_data']; @@ -46,9 +50,12 @@ class sendMailNotification $app_link = $_ENV['App_Url']; $mail_content = $notification_data['mail_content']; $nhance_logo = $_ENV['NHANCE_LOGO']; + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); + $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); if ($emp_data && (isset($notification_data) && $notification_data['enabled'] == 1)) { if(isset($emp_data['relationship'])){ @@ -72,9 +79,11 @@ class sendMailNotification } if (isset($mail) && !empty($mail)) { - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; } + }else{ + foreach ($emp_data as $key => $value) { if ($value['relationship'] != 'Self') { $emp_data = $EmployeeModel->where('client_id', $client_data['id'])->where('emp_code', $value['emp_code'])->where('is_active',1)->findAll(); @@ -96,7 +105,7 @@ class sendMailNotification $mail = $value['email_corporate']; } if (isset($mail) && !empty($mail)) { - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; } } } @@ -104,10 +113,13 @@ class sendMailNotification if (count($wholeData) < 1) { $wholeData = []; } + return $wholeData; + // }else{ // return "false"; // } + } else if($action == 'member_ecard_mail'){ $notification = $params['notification']; @@ -144,9 +156,10 @@ class sendMailNotification // $mail_content = str_replace("[[tpa_id]]", $tpa_id, $mail_content); $mail_content = str_replace("[[ecard_download_link]]", "Download Insurance Card", $mail_content); $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); - $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails']]; + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; return $wholeData; + } else if($action == 'member_review_and_summary_mail'){ $array_list = $params['array_list'];//employeee lst @@ -160,7 +173,10 @@ class sendMailNotification $client_data =$clientModel->where('id', $client_id)->first(); $notification_data = $notificationModel->where('client_id' ,$client_id)->where('template_name', $action)->first(); + // dd($notification_data); + if (isset($notification_data) && $notification_data['enabled'] == 1) { + $mail_content = $notification_data['mail_content']; $subject = $notification_data['subject']; $app_link = $_ENV['App_Url']; @@ -183,71 +199,141 @@ class sendMailNotification $Addon_list = []; $name = ''; $emp_code = ''; + foreach ($array_list as $item) { - if(count($item) != 0){ - $table_content .= '

Policy Name : '; - $temp_data =''; - $policy_name =''; - $is_addon =''; - foreach ($item as $inner_item) { - $policy_name = $inner_item['policy_name']; - $temp_data .= '' . $inner_item['name'] . ''.$inner_item['relationship'].''. \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') .'₹'.format_indian_number($inner_item['basic_cover_si']).'₹'.format_indian_number($inner_item['premium']).'₹'. format_indian_number($inner_item['gst']) .''; - if($inner_item['relationship'] == 'Self' || $inner_item['relationship'] == 'self'){ - $mail = $inner_item['email_corporate']; - $name = $inner_item['name']; - $emp_code = $inner_item['emp_code']; - } - $is_addon = $inner_item['is_addon']; - - if($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3){ - $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; - $gst = $inner_item['gst'] + $gst; - } - } - // echo $policy_name;die; - $table_content .= $policy_name.'

GST'; - $table_content .= $temp_data; - $table_content .= '
NameRelationDate Of BirthSum InsurePremium
'; - if ($is_addon == 2 || $is_addon == 3) { - $addon_list_array = [ - 'policy_name'=>$policy_name, - 'addtional_premium'=>$addtional_premium, - 'gst'=>$gst - ]; - $Addon_list[]= $addon_list_array; + if (count($item) != 0) { + $table_content .= '

Policy Name : '; + $temp_data = ''; + $policy_name = ''; + $is_addon = ''; - } + foreach ($item as $inner_item) { + $policy_name = $inner_item['policy_name']; + + if ($inner_item['relationship'] == 'Self') { + $emp_code = ' (' . $inner_item['emp_code'] . ')'; + } else { + $emp_code = ''; + } - - $temp_data = ''; - $addtional_premium = 0; - $gst = 0; + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . $emp_code . ''; + $temp_data .= '' . $inner_item['relationship'] . ''; + $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + $temp_data .= '₹' . format_indian_number($inner_item['basic_cover_si']) . ''; + + // Only Display SI Topup and Dependent Addon + if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + $temp_data .= '₹' . format_indian_number(round($inner_item['premium'])) . ''; + $temp_data .= '₹' . format_indian_number(round($inner_item['gst'])) . ''; + } + + $temp_data .= ''; + + $is_addon = $inner_item['is_addon']; + + if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + $gst = $inner_item['gst'] + $gst; + } + } + + $table_content .= $policy_name . '

'; + $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if ($is_addon == 2 || $is_addon == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + if ($is_addon == 2 || $is_addon == 3) { + $addon_list_array = [ + 'policy_name' => $policy_name, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + $Addon_list[] = $addon_list_array; + } + + $temp_data = ''; + $addtional_premium = 0; + $gst = 0; } - } - if(count($Addon_list) != 0 && count($Addon_list) > 0){ - $table_content .='
'; - $sum_tolal = 0; + + if (count($Addon_list) > 0) { + $table_content .= '
'; + $table_content .= '
Policy Name Additional PremiumGSTTotal
'; + + // Center align for table header and body + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $sum_total = 0; foreach ($Addon_list as $key => $value) { - $sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal; - $table_content .= ''; + $total_addon = $value['gst'] + $value['addtional_premium']; + $sum_total += $total_addon; + + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; } - $sum_total_words = numberToWords($sum_tolal); - $table_content .= ''; - $table_content .= '
Policy NameAdditional PremiumGSTTotal
'.$value['policy_name'].'₹'.$value['addtional_premium'].''.$value['gst'].''.$value['gst'] + $value['addtional_premium'] .'
' . $value['policy_name'] . '₹' . format_indian_number($value['addtional_premium']) . '₹' . format_indian_number($value['gst']) . '₹' . format_indian_number($total_addon) . '

Total

'.format_indian_number($sum_tolal).'
'; - $table_content .= '
'. $sum_total_words .'
'; - + + $sum_total_words = numberToWords($sum_total); + $table_content .= ''; + $table_content .= 'Total'; + $table_content .= '₹' . format_indian_number($sum_total) . ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + // $table_content .= '
' . $sum_total_words . '
'; } + + + + // print_r($table_content); die; + $mail_content = str_replace("[[member_name]]", $name . ' (' . $emp_code . ')' , $mail_content); $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); + + // print_r($mail_content); die; + // $mail = "aadhavanvalli@gmail.com"; // if (isset($mail) && !empty($mail)) { - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; // } return $wholeData; } + } else if($action == 'account_maneger_summary_mail'){ $client_id = $params['client_id']; @@ -259,7 +345,8 @@ class sendMailNotification $client_data =$clientModel->where('id', $client_id)->first(); $notification_data = $notificationModel->where('client_id' ,$client_id)->where('template_name', $action)->first(); - if (isset($notification_data) && $notification_data['enabled'] == 1) { + if (isset($notification_data) && $notification_data['enabled'] == 1) { + $client_rm_data= $clientRMModel->where('client_id', $client_id)->where('is_active',1)->findAll(); $user_list= []; foreach ($client_rm_data as $key => $value) { @@ -270,8 +357,6 @@ class sendMailNotification } } - - $mail_content = $notification_data['mail_content']; $subject = $notification_data['subject']; $app_link = $_ENV['App_Url']; @@ -293,64 +378,124 @@ class sendMailNotification $gst = 0; $array_list = $params['array_list']; $Addon_list = []; + foreach ($array_list as $item) { - if(count($item) != 0){ - $table_content .= '

Policy Name : '; - $temp_data =''; - $policy_name =''; - $is_addon =''; - foreach ($item as $inner_item) { - $policy_name = $inner_item['policy_name']; - if($inner_item['relationship'] == 'Self'){ - $emp_code = ' ('. $inner_item['emp_code'] . ')'; - }else{ - $emp_code =''; - } - $temp_data .= '' . $inner_item['name'] . $emp_code . ''.$inner_item['relationship'].''. \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') .'₹'.format_indian_number($inner_item['basic_cover_si']).'₹'.format_indian_number($inner_item['premium']).'₹'. format_indian_number($inner_item['gst']) .''; - $is_addon = $inner_item['is_addon']; - - if($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3){ + if (count($item) != 0) { + $table_content .= '

Policy Name : '; + $temp_data = ''; + $policy_name = ''; + $is_addon = ''; + + foreach ($item as $inner_item) { + $policy_name = $inner_item['policy_name']; - - $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; - $gst = $inner_item['gst'] + $gst; + if ($inner_item['relationship'] == 'Self') { + $emp_code = ' (' . $inner_item['emp_code'] . ')'; + } else { + $emp_code = ''; + } + + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . $emp_code . ''; + $temp_data .= '' . $inner_item['relationship'] . ''; + $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + $temp_data .= '₹' . format_indian_number($inner_item['basic_cover_si']) . ''; + + // Only Display SI Topup and Dependent Addon + if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + $temp_data .= '₹' . format_indian_number(round($inner_item['premium'])) . ''; + $temp_data .= '₹' . format_indian_number(round($inner_item['gst'])) . ''; + } + + $temp_data .= ''; + + $is_addon = $inner_item['is_addon']; + + if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + $gst = $inner_item['gst'] + $gst; + } } + + $table_content .= $policy_name . '

'; + $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if ($is_addon == 2 || $is_addon == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + if ($is_addon == 2 || $is_addon == 3) { + $addon_list_array = [ + 'policy_name' => $policy_name, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + $Addon_list[] = $addon_list_array; + } + + $temp_data = ''; + $addtional_premium = 0; + $gst = 0; } - $table_content .= $policy_name.'

GST'; - $table_content .= $temp_data; - $table_content .= '
NameRelationDate Of BirthSum InsurePremium
'; - if ($is_addon == 2 || $is_addon == 3) { - $addon_list_array = [ - 'policy_name'=>$policy_name, - 'addtional_premium'=>$addtional_premium, - 'gst'=>$gst - ]; - $Addon_list[]= $addon_list_array; - - } - - - $temp_data = ''; - $addtional_premium = 0; - $gst = 0; - } - - } - if(count($Addon_list) != 0 && count($Addon_list) > 0){ - - $table_content .='
'; - $sum_tolal = 0; + + if (count($Addon_list) > 0) { + $table_content .= '
'; + $table_content .= '
Policy Name Additional PremiumGSTTotal
'; + + // Center align for table header and body + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $sum_total = 0; foreach ($Addon_list as $key => $value) { - $sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal; - $table_content .= ''; + $total_addon = $value['gst'] + $value['addtional_premium']; + $sum_total += $total_addon; + + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; } - $sum_total_words = numberToWords($sum_tolal); - $table_content .= ''; - $table_content .= '
Policy NameAdditional PremiumGSTTotal
'.$value['policy_name'].'₹'.$value['addtional_premium'].''.$value['gst'].''.$value['gst'] + $value['addtional_premium'] .'
' . $value['policy_name'] . '₹' . format_indian_number($value['addtional_premium']) . '₹' . format_indian_number($value['gst']) . '₹' . format_indian_number($total_addon) . '

Total

'.format_indian_number($sum_tolal).'
'; - $table_content .= '
'. $sum_total_words .'
'; - + + $sum_total_words = numberToWords($sum_total); + $table_content .= ''; + $table_content .= 'Total'; + $table_content .= '₹' . format_indian_number($sum_total) . ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + // $table_content .= '
' . $sum_total_words . '
'; } + + $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); $account_manager_mail_list = []; @@ -359,7 +504,7 @@ class sendMailNotification $full_name = $value['first_name'] .' ' .$value['last_name']; $mail_content = str_replace("[[member_name]]", $full_name , $mail_content); - $wholeData[] = ['mail' => $value['email'], 'subject' => $subject,'message'=> $mail_content]; + $wholeData[] = ['mail' => $value['email'], 'subject' => $subject,'message'=> $mail_content, 'reply_to' => $client_data['reply_to']]; // $wholeData[] = ['mail' => $value['email'], 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; } return $wholeData; @@ -412,55 +557,121 @@ class sendMailNotification $Addon_list = []; foreach ($array_list as $item) { - $table_content .= '

Policy Name : '; - $temp_data =''; - foreach ($item as $inner_item) { - $policy_name = $inner_item['policy_name']; - if($inner_item['relationship'] == 'Self'){ - $emp_code = ' ('. $inner_item['emp_code'] . ')'; - }else{ - $emp_code =''; + if (count($item) != 0) { + $table_content .= '

Policy Name : '; + $temp_data = ''; + $policy_name = ''; + $is_addon = ''; + + foreach ($item as $inner_item) { + $policy_name = $inner_item['policy_name']; + + if ($inner_item['relationship'] == 'Self') { + $emp_code = ' (' . $inner_item['emp_code'] . ')'; + } else { + $emp_code = ''; + } + + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . $emp_code . ''; + $temp_data .= '' . $inner_item['relationship'] . ''; + $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + $temp_data .= '₹' . format_indian_number($inner_item['basic_cover_si']) . ''; + + // Only Display SI Topup and Dependent Addon + if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + $temp_data .= '₹' . format_indian_number(round($inner_item['premium'])) . ''; + $temp_data .= '₹' . format_indian_number(round($inner_item['gst'])) . ''; + } + + $temp_data .= ''; + + $is_addon = $inner_item['is_addon']; + + if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + $gst = $inner_item['gst'] + $gst; + } } - $temp_data .= '' . $inner_item['name'] . $emp_code . ''.$inner_item['relationship'].''. \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') .'₹'.format_indian_number($inner_item['basic_cover_si']).'₹'.format_indian_number($inner_item['premium']).'₹'. format_indian_number($inner_item['gst']) .''; - $is_addon = $inner_item['is_addon']; - - if($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3){ - $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; - $gst = $inner_item['gst'] + $gst; + + $table_content .= $policy_name . '

'; + $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if ($is_addon == 2 || $is_addon == 3) { + $table_content .= ''; + $table_content .= ''; } + + $table_content .= ''; + $table_content .= ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + if ($is_addon == 2 || $is_addon == 3) { + $addon_list_array = [ + 'policy_name' => $policy_name, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + $Addon_list[] = $addon_list_array; + } + + $temp_data = ''; + $addtional_premium = 0; + $gst = 0; } - $table_content .= $policy_name.'

GST'; - $table_content .= $temp_data; - $table_content .= '
NameRelationDate Of BirthSum InsurePremium
'; - - if ($is_addon == 2 || $is_addon == 3) { - $addon_list_array = [ - 'policy_name'=>$policy_name, - 'addtional_premium'=>$addtional_premium, - 'gst'=>$gst - ]; - $Addon_list[]= $addon_list_array; - - } - - - $temp_data = ''; - $addtional_premium = 0; - $gst = 0; - } - if(count($Addon_list) != 0 && count($Addon_list) > 0){ - $table_content .='
'; - $sum_tolal = 0; + + if (count($Addon_list) > 0) { + $table_content .= '
'; + $table_content .= '
Policy Name Additional PremiumGSTTotal
'; + + // Center align for table header and body + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $sum_total = 0; foreach ($Addon_list as $key => $value) { - $sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal; - $table_content .= ''; + $total_addon = $value['gst'] + $value['addtional_premium']; + $sum_total += $total_addon; + + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; } - $sum_total_words = numberToWords($sum_tolal); - $table_content .= ''; - $table_content .= '
Policy NameAdditional PremiumGSTTotal
'.$value['policy_name'].'₹'.$value['addtional_premium'].''.$value['gst'].''.$value['gst'] + $value['addtional_premium'] .'
' . $value['policy_name'] . '₹' . format_indian_number($value['addtional_premium']) . '₹' . format_indian_number($value['gst']) . '₹' . format_indian_number($total_addon) . '

Total

'.format_indian_number($sum_tolal).'
'; - $table_content .= '
'. $sum_total_words .'
'; + + $sum_total_words = numberToWords($sum_total); + $table_content .= ''; + $table_content .= 'Total'; + $table_content .= '₹' . format_indian_number($sum_total) . ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + // $table_content .= '
' . $sum_total_words . '
'; } + $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); @@ -469,7 +680,7 @@ class sendMailNotification $mail_array = array_map('trim', $mail_array); $wholeData = []; foreach ($mail_array as $key => $value) { - $wholeData[] = ['mail' => $value, 'subject' => $subject,'message'=> $mail_content]; + $wholeData[] = ['mail' => $value, 'subject' => $subject,'message'=> $mail_content, 'reply_to' => $client_data['reply_to']]; // $wholeData[] = ['mail' => $value, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; } @@ -478,4 +689,555 @@ class sendMailNotification } } + + public static function sendMailNotificationForTesting($action, $params) + { + $wholeData =[]; + + if ($action == 'member_welcome_mail') { + + $clientModel = new ClientModel(); + + $notification = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + $mail_content = $notification['mail_content']; + $subject = $notification['subject']; + + $employee_name = 'John Doe'; + + $app_link = $_ENV['App_Url']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); + $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); + $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + + $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); + + if ($mail != null || $mail != '') { + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; + } + + return $wholeData; + + } else if($action == 'member_reminder_mail'){ + + $notification_data = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + $mail_content = $notification_data['mail_content']; + $subject = $notification_data['subject']; + + $nhance_logo = $_ENV['NHANCE_LOGO']; + $app_link = $_ENV['App_Url']; + + $employee_name = 'John Doe'; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); + $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); + $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); + + if ((isset($notification_data) && $notification_data['enabled'] == 1)) { + + if (isset($mail) && !empty($mail)) { + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; + } + + } + + return $wholeData; + + + } else if($action == 'member_ecard_mail'){ + + $notification = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + $mail_content = $notification['mail_content']; + $subject = $notification['subject']; + + $rand_string = 'HX3kUh'; + $link = generate_download_link($rand_string); + + $name = 'John Doe'; + + $nhance_logo = $_ENV['NHANCE_LOGO']; + $app_link = $_ENV['App_Url']; + $post_enrollment_app_link = $_ENV['POST_ENROLLMENT_APP_LINK']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); + $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); + + $mail_content = str_replace("[[member_name]]", $name, $mail_content); + $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); + $mail_content = str_replace("[[post_enrollment_app_link]]", "Review Details", $mail_content); + $mail_content = str_replace("[[ecard_download_link]]", "Download Insurance Card", $mail_content); + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; + + return $wholeData; + + } else if($action == 'member_review_and_summary_mail'){ + + $array_list = [ + 'policy_name' => 'Health Insurance Plan', + 'emp_code' => 'E12345', + 'name' => 'John Doe', + 'relationship' => 'Self', + 'dob' => '1985-05-15', + 'basic_cover_si' => 500000, + 'premium' => 12000, + 'gst' => 2160, + 'rata_premimum' => 12000, + 'is_addon' => 2 + ]; + + + $notification_data = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + if (isset($notification_data) && $notification_data['enabled'] == 1) { + + $mail_content = $notification_data['mail_content']; + $subject = $notification_data['subject']; + + $app_link = $_ENV['App_Url']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); + $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); + + $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); + + // Step 1: Replace the placeholder with an HTML table structure + $table_content = ''; + $addtional_premium = 0; + $gst = 0; + $Addon_list = []; + $name = $array_list['name']; + $emp_code = ''; + + if (!empty($array_list)) { + + $table_content .= '

Policy Name : '; + + $policy_name = $array_list['policy_name']; + + if ($array_list['relationship'] == 'Self') { + $emp_code = ' (' . $array_list['emp_code'] . ')'; + } else { + $emp_code = ''; + } + + // Start table row + $table_content .= $policy_name . '

'; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Table body with details + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
' . $array_list['name'] . $emp_code . '' . $array_list['relationship'] . '' . \DateTime::createFromFormat('Y-m-d', $array_list['dob'])->format('d-m-Y') . '₹' . format_indian_number($array_list['basic_cover_si']) . '₹' . format_indian_number(round($array_list['premium'])) . '₹' . format_indian_number(round($array_list['gst'])) . '
'; + + // Calculate additional premium and GST if applicable + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $addtional_premium = $array_list['rata_premimum']; + $gst = $array_list['gst']; + + // Prepare addon summary + $addon_list_array = [ + 'policy_name' => $policy_name, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + + $Addon_list[] = $addon_list_array; + } + + // Generate summary table for addon if applicable + if (count($Addon_list) > 0) { + $table_content .= '
'; + $table_content .= ''; + + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $total_addon = $Addon_list[0]['gst'] + $Addon_list[0]['addtional_premium']; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $sum_total_words = numberToWords($total_addon); + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= '
Policy NameAdditional PremiumGSTTotal
' . $Addon_list[0]['policy_name'] . '₹' . format_indian_number($Addon_list[0]['addtional_premium']) . '₹' . format_indian_number($Addon_list[0]['gst']) . '₹' . format_indian_number($total_addon) . '
Total₹' . format_indian_number($total_addon) . '
'; + } + } + + $mail_content = str_replace("[[member_name]]", $name . ' (' . $emp_code . ')' , $mail_content); + $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); + + + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; + + return $wholeData; + + } + + } else if($action == 'account_maneger_summary_mail'){ + + $array_list = [ + 'policy_name' => 'Health Insurance Plan', + 'emp_code' => 'E12345', + 'name' => 'John Doe', + 'relationship' => 'Self', + 'dob' => '1985-05-15', + 'basic_cover_si' => 500000, + 'premium' => 12000, + 'gst' => 2160, + 'rata_premimum' => 12000, + 'is_addon' => 2 + ]; + + $notification_data = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + if (isset($notification_data) && $notification_data['enabled'] == 1) { + + $mail_content = $notification_data['mail_content']; + $subject = $notification_data['subject']; + + $app_link = $_ENV['App_Url']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); + $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); + + $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); + + // Step 1: Replace the placeholder with an HTML table structure + $table_content = ''; + $addtional_premium = 0; + $gst = 0; + $Addon_list = []; + $name = $array_list['name']; + $emp_code = ''; + + if (!empty($array_list)) { + $table_content .= '

Policy Name : '; + + $policy_name = $array_list['policy_name']; + + if ($array_list['relationship'] == 'Self') { + $emp_code = ' (' . $array_list['emp_code'] . ')'; + } else { + $emp_code = ''; + } + + // Start table row + $table_content .= $policy_name . '

'; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Table body with details + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
' . $array_list['name'] . $emp_code . '' . $array_list['relationship'] . '' . \DateTime::createFromFormat('Y-m-d', $array_list['dob'])->format('d-m-Y') . '₹' . format_indian_number($array_list['basic_cover_si']) . '₹' . format_indian_number(round($array_list['premium'])) . '₹' . format_indian_number(round($array_list['gst'])) . '
'; + + // Calculate additional premium and GST if applicable + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $addtional_premium = $array_list['rata_premimum']; + $gst = $array_list['gst']; + + // Prepare addon summary + $addon_list_array = [ + 'policy_name' => $policy_name, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + + $Addon_list[] = $addon_list_array; + } + + // Generate summary table for addon if applicable + if (count($Addon_list) > 0) { + $table_content .= '
'; + $table_content .= ''; + + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $total_addon = $Addon_list[0]['gst'] + $Addon_list[0]['addtional_premium']; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $sum_total_words = numberToWords($total_addon); + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= '
Policy NameAdditional PremiumGSTTotal
' . $Addon_list[0]['policy_name'] . '₹' . format_indian_number($Addon_list[0]['addtional_premium']) . '₹' . format_indian_number($Addon_list[0]['gst']) . '₹' . format_indian_number($total_addon) . '
Total₹' . format_indian_number($total_addon) . '
'; + } + } + + $mail_content = str_replace("[[member_name]]", $name . ' (' . $emp_code . ')' , $mail_content); + $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); + + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'reply_to' => $client_data['reply_to']]; + + return $wholeData; + } + + } else if($action == 'client_hr_summary_mail'){ + + $array_list = [ + 'policy_name' => 'Health Insurance Plan', + 'emp_code' => 'E12345', + 'name' => 'John Doe', + 'relationship' => 'Self', + 'dob' => '1985-05-15', + 'basic_cover_si' => 500000, + 'premium' => 12000, + 'gst' => 2160, + 'rata_premimum' => 12000, + 'is_addon' => 2 + ]; + + $notification_data = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + if (isset($notification_data['enabled']) && $notification_data['enabled'] == 1) { + + $mail_content = $notification_data['mail_content']; + $subject = $notification_data['subject']; + + $app_link = $_ENV['App_Url']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); + $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + + $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); + + // Step 1: Replace the placeholder with an HTML table structure + $table_content = ''; + $addtional_premium = 0; + $gst = 0; + $Addon_list = []; + $name = $array_list['name']; + $emp_code = ''; + + if (!empty($array_list)) { + + $table_content .= '

Policy Name : '; + + $policy_name = $array_list['policy_name']; + + if ($array_list['relationship'] == 'Self') { + $emp_code = ' (' . $array_list['emp_code'] . ')'; + } else { + $emp_code = ''; + } + + // Start table row + $table_content .= $policy_name . '

'; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Table body with details + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
' . $array_list['name'] . $emp_code . '' . $array_list['relationship'] . '' . \DateTime::createFromFormat('Y-m-d', $array_list['dob'])->format('d-m-Y') . '₹' . format_indian_number($array_list['basic_cover_si']) . '₹' . format_indian_number(round($array_list['premium'])) . '₹' . format_indian_number(round($array_list['gst'])) . '
'; + + // Calculate additional premium and GST if applicable + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $addtional_premium = $array_list['rata_premimum']; + $gst = $array_list['gst']; + + // Prepare addon summary + $addon_list_array = [ + 'policy_name' => $policy_name, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + + $Addon_list[] = $addon_list_array; + } + + // Generate summary table for addon if applicable + if (count($Addon_list) > 0) { + + $table_content .= '
'; + $table_content .= ''; + + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $total_addon = $Addon_list[0]['gst'] + $Addon_list[0]['addtional_premium']; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $sum_total_words = numberToWords($total_addon); + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= '
Policy NameAdditional PremiumGSTTotal
' . $Addon_list[0]['policy_name'] . '₹' . format_indian_number($Addon_list[0]['addtional_premium']) . '₹' . format_indian_number($Addon_list[0]['gst']) . '₹' . format_indian_number($total_addon) . '
Total₹' . format_indian_number($total_addon) . '
'; + } + } + + $mail_content = str_replace("[[member_name]]", $name . ' (' . $emp_code . ')' , $mail_content); + $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); + + + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'reply_to' => $client_data['reply_to']]; + + return $wholeData; + } + + } + } } \ No newline at end of file diff --git a/app/Models/BatchFileModel.php b/app/Models/BatchFileModel.php index df644790..b8ebc8e9 100755 --- a/app/Models/BatchFileModel.php +++ b/app/Models/BatchFileModel.php @@ -59,5 +59,25 @@ class BatchFileModel extends Model return $data; } + + public function getBatchFilesDataForDocumentSearch($policy_id, $policy_doc_name) + { + $this->select(' + "Imported Insurer or TPA Files" as doc_name, + batch_files.file_name, + batch_files.client_id, + batch_files.client_policy_id, + "uploads" as file_type + ') + ->where('batch_files.client_policy_id', $policy_id) + ->where('batch_files.is_active', 1); + + if (!empty($policy_doc_name)) { + $this->like('batch_files.file_name', $policy_doc_name); + } + + return $this->get()->getResultArray(); + } + } diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index ce5481d3..e188b5bd 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -37,6 +37,8 @@ class ClientModel extends Model "reference", "phone", "email", + "reply_to", + "mail_domain", ]; diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 470bbb0a..1aa5bf2d 100755 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -49,6 +49,7 @@ class ClientPolicyModel extends Model "cd_ac_no", "gst", "enrolment_visibility", + "disclaimer", "is_active", ]; @@ -404,9 +405,24 @@ public function getPolicyDetailsForRemainder($client_id = null, $branch_id = nul } return $builder->get()->getResultArray(); +} +//for this using in CRONE JOB +public function getPolicyDetailsForEnrollment($client_id = null, $branch_id = null) +{ + $builder = $this->table('client_policy') + ->where('client_policy.is_active', 1) + ->where('client_policy.policy_status', 1) + ->where('client_policy.open_date IS NOT NULL') + ->where('client_policy.close_date IS NOT NULL'); + if ($client_id && $branch_id) { + $builder->where('client_policy.client_id', $client_id) + ->where('client_policy.client_branch_id', $branch_id); } + return $builder->get()->getResultArray(); +} + } diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index a5f36f5d..b84b96a9 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -106,10 +106,10 @@ class EmployeeModel extends Model public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,array $emp_status = [],array $policy_status = [],array $relationship = [],array $client_branch_id = []) { - $result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employees.unit','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policies.name as policy_name','client_policy.is_addon']) + $result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employees.unit','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policy_type.long_name as policy_name','client_policy.is_addon']) ->join('employee_polices', 'employee_polices.employee_id = employees.id') ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') - ->join('policies', 'policies.id = client_policy.policy_id','left') + ->join('policy_type', 'policy_type.id = client_policy.policy_type_id','left') ->where('employees.is_active',1) ->when($client_policy_id, function($query) use ($client_policy_id){ return $query->where('employee_polices.client_policy_id',$client_policy_id); diff --git a/app/Models/FileModel.php b/app/Models/FileModel.php index 9262e796..c6f04f63 100755 --- a/app/Models/FileModel.php +++ b/app/Models/FileModel.php @@ -23,4 +23,24 @@ class FileModel extends Model ]; + + public function getFilesDataForDocumentSearch($policy_id, $policy_doc_name) + { + $this->select(' + files.action as doc_name, + files.file_name, + files.client_id, + files.policy_id as client_policy_id, + "uploads" as file_type + ') + ->where('files.policy_id', $policy_id) + ->where('files.is_active', 1); + + if (!empty($policy_doc_name)) { + $this->like('files.action', $policy_doc_name); + } + + return $this->get()->getResultArray(); + } + } diff --git a/app/Views/DashBoard.php b/app/Views/DashBoard.php index b931e838..89a5406f 100755 --- a/app/Views/DashBoard.php +++ b/app/Views/DashBoard.php @@ -1,3 +1,142 @@ + + + + + + + + + + + + + + + + + -
+
diff --git a/app/Views/client_kyc.php b/app/Views/client_kyc.php index 995dd16f..99bab2b1 100755 --- a/app/Views/client_kyc.php +++ b/app/Views/client_kyc.php @@ -174,13 +174,13 @@ $('#name_'+item.kyc_doc_type_id).html(item.file_name); $('#form_'+item.kyc_doc_type_id).hide(); - var url = "" + - "?client_id=" + item.client_id + - "&file_type=kyc" + - "&file_name=" + item.file_name + - "&client_policy_id=client_policy_id"; + // var url = "" + + // "?client_id=" + item.client_id + + // "&file_type=kyc" + + // "&file_name=" + item.file_name + + // "&client_policy_id=client_policy_id"; - // var url = '' + item.file_name; + var url = '' + item.file_name; // console.log('step 1') @@ -293,14 +293,14 @@ other_docs_count++; } - var url = "" + - "?client_id=" + item.client_id + - "&file_type=kyc" + - "&file_name=" + item.file_name + - "&client_policy_id=client_policy_id"; + // var url = "" + + // "?client_id=" + item.client_id + + // "&file_type=kyc" + + // "&file_name=" + item.file_name + + // "&client_policy_id=client_policy_id"; - // var url = '' + item.file_name; + var url = '' + item.file_name; // console.log("Current item:", item); if (item.kyc_doc_type_id == '0') { @@ -465,13 +465,13 @@ } - var url = "" + - "?client_id=" + item.client_id + - "&file_type=kyc" + - "&file_name=" + item.file_name + - "&client_policy_id=client_policy_id"; + // var url = "" + + // "?client_id=" + item.client_id + + // "&file_type=kyc" + + // "&file_name=" + item.file_name + + // "&client_policy_id=client_policy_id"; - // var url = '' + item.file_name; + var url = '' + item.file_name; if(item.kyc_doc_type_id == '0'){ @@ -508,13 +508,13 @@ // console.log('step 1') - var url = "" + - "?client_id=" + item.client_id + - "&file_type=kyc" + - "&file_name=" + item.file_name + - "&client_policy_id=client_policy_id"; + // var url = "" + + // "?client_id=" + item.client_id + + // "&file_type=kyc" + + // "&file_name=" + item.file_name + + // "&client_policy_id=client_policy_id"; - // var url = '' + item.file_name; + var url = '' + item.file_name; if(item.file_name != null && item.file_name != ""){ diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index f20c8e05..6ced70eb 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -128,7 +128,6 @@
-
@@ -143,18 +142,27 @@
+
+
+
+ +
+ + +
+
- +
@@ -152,6 +152,26 @@ $(document).ready(function() { }) +// Datatable document ready +$(document).ready(function() { + +var ticketsTable = $('#scroll-horizontal-datatable'); + +if (ticketsTable.length) { + ticketsTable.DataTable({ + scrollX: true, + language: { + search: "_INPUT_", + searchPlaceholder: "Search..." + }, + paging: true, // Enable pagination + pageLength: 25, // Set default number of rows per page (optional) + }); +} else { + console.error("Table not found."); +} +}); + function showSuggestions(inputID, suggestionBoxID,hiddenInputID,suggestions) { // console.log('showSuggestions'); diff --git a/app/Views/enrollment_dash.php b/app/Views/enrollment_dash.php index 17fe0f9d..88d9fda6 100755 --- a/app/Views/enrollment_dash.php +++ b/app/Views/enrollment_dash.php @@ -1,143 +1,3 @@ - - - - - - - - - - - - - - - - - -
diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 88f3ad4b..e2538907 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -655,7 +655,7 @@
- +
diff --git a/app/Views/notification.php b/app/Views/notification.php index 09c95038..6b15116a 100755 --- a/app/Views/notification.php +++ b/app/Views/notification.php @@ -5,6 +5,10 @@ .preview_button{ display:none; } + + .scrollb { + overflow-y: auto !important; + }
@@ -56,16 +60,29 @@ ?>

+
- +
- +
+ +
+
+ + +
+
+ + +
+
+
@@ -156,6 +173,7 @@
+
@@ -176,7 +194,7 @@
S.No