diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 5c613da1..6c454276 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -112,6 +112,7 @@ $routes->group("/employee", ["filter" => "authMVC"], function($routes){ $routes->get("upload", "EmployeeController::employeesUplodWithEvents"); $routes->post("upload", "EmployeeController::employeesUplodWithEvents"); $routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1"); + $routes->get("endorsement-list", "EmployeeController::endorsementList"); }); @@ -206,6 +207,7 @@ $routes->group("/util", ["filter" => "authMVC"], function($routes){ $routes->get("policy-premium", "ClientController::getpolicyGridData/$1"); $routes->get("update-policy-status", "ClientController::updateClientPolicyStatus/$1"); $routes->get("download-excel/(:any)", "EmployeeController::downloadSampleExcelFile/$1"); + $routes->get("get-emp-endorsement/(:any)", "EmployeeController::getEmpEndoresmentEntry/$1"); $routes->post("import-export", "EmployeeController::importExport"); }); @@ -230,9 +232,6 @@ $routes->group("/api", ["filter" => "authJWT"], function($routes){ $routes->get("/getEmployeeProfile", "EmployeeRestController::getEmployeeProfile/$1"); $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfile"); - - - $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->post("employeeUpload", "EmployeeRestController::employeeUpload"); $routes->get("relationshipList", "EmployeeRestController::relationshipList"); @@ -245,6 +244,9 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("deleteDependence", "EmployeeRestController::deleteDependence"); $routes->get("getEmployeeAndDependenceByClientId", "EmployeeRestController::getEmployeeAndDependenceByClientId"); $routes->get("getClientPolicy", "EmployeeRestController::getClientPolicy"); + $routes->get("getClientDetails", "EmployeeRestController::getClientDetails"); + $routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy"); + $routes->get("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); }); $routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index ee3da98d..1800a38a 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -307,6 +307,8 @@ class ClientController extends AdminController } elseif ($data['is_download_btn']) { $data['is_download_btn'] = 1; } + + // print_r($data);die; $update = $this->clientModel->update($id,$data); @@ -1311,7 +1313,7 @@ class ClientController extends AdminController $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' => 'This Policy does not Create Terms'], 200); + return $this->respond(['status' => false,'code' => 200,'message' => 'Please define policy terms '], 200); } @@ -1338,11 +1340,21 @@ class ClientController extends AdminController if($racRate == 0){ - return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy has no Data for Rac Rate'], 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(); - return $this->respond(['status' => true,'code' => 200, 'message' => 'Policy Status Updated Successfully', 'data' => $termsData, 'racRate' => $racRate], 200); + $json_data =''; + $open_for_enrollment = $this->clientPolicyModel->where('id', $client_policy_id )->set('open_for_enrollment', 1)->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]); + } + + return $this->respond(['status' => true,'code' => 200, 'message' => 'Policy Status Updated Successfully', 'data' => $termsData, 'racRate' => $racRate, 'open_for_enrollment' => $json_data], 200); diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index aca39351..a45837f3 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -162,9 +162,17 @@ class EmpDataServiceController extends BaseController public function generateExcelForCorrection($export_data) { + $ids = []; $objects = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($export_data); - // dd($objects); + + foreach ($objects as $obj) { + $ids[] = $obj->id; + } + + // echo '
';
+            // print_r($objects); die;
+
             $count = count($objects);
             $export_data['count'] = $count;
             $this->myLogger->logme('error','Correction export data count : {data}', ['data'=> $count ]);
@@ -201,6 +209,14 @@ class EmpDataServiceController extends BaseController
                 $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
                 if($return){
     
+                    foreach ($ids as $key => $id) {
+                        $group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
+                        if ($group_key) {
+                            $this->empEndorsementModel->where('group_key', $group_key)->set('status', 'inprogress')->update();
+                        }
+                    }
+        
+
                     // Set the appropriate headers for Excel file download
                     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
                     header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
@@ -228,9 +244,15 @@ class EmpDataServiceController extends BaseController
 
         public function generateExcelForSIEnhancement($export_data)
         {
-
+            $ids = [];
             $objects = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($export_data);
             
+            foreach ($objects as $obj) {
+                $ids[] = $obj->endorsement_primarykey;
+            }
+
+            // echo '
';
+            // print_r($ids); die;
             // dd($objects);
             
             $count = count($objects);
@@ -279,6 +301,13 @@ class EmpDataServiceController extends BaseController
             if($value){
                 $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
                 if($return){
+
+                    foreach ($ids as $key => $id) {
+                        $group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
+                        if ($group_key) {
+                            $this->empEndorsementModel->where('group_key', $group_key)->set('status', 'inprogress')->update();
+                        }
+                    }
     
                     // Set the appropriate headers for Excel file download
                     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
@@ -306,8 +335,18 @@ class EmpDataServiceController extends BaseController
 
         public function generateExcelForDeletion($export_data)
         {
-            // dd($export_data['client_id']);
+            $ids = [];
+
             $objects = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($export_data);
+
+            foreach ($objects as $obj) {
+                $ids[] = $obj->endorsement_primarykey;
+            }
+
+            // echo '
';
+            // print_r($ids); 
+            // print_r($objects); die;
+
             $count = count($objects);
             $export_data['count'] = $count;
 
@@ -350,6 +389,13 @@ class EmpDataServiceController extends BaseController
             if($value){
                 $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
                 if( $return){
+
+                    foreach ($ids as $key => $id) {
+                        $group_key = $this->empEndorsementModel->select('group_key')->where('id', $id)->first();
+                        if ($group_key) {
+                            $this->empEndorsementModel->where('group_key', $group_key)->set('status', 'inprogress')->update();
+                        }
+                    }
     
                     // Set the appropriate headers for Excel file download
                     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
@@ -560,7 +606,7 @@ class EmpDataServiceController extends BaseController
 
                         // $this->employeePolicyModel->updateCorrectionData($emp_code, $uhid, $endorsement_id);
 
-                        $queryData =  $this->empEndorsementModel->select('emp_endorsement.*')
+                        $queryData =  $this->empEndorsementModel->select('emp_endorsement.*, employees.id as emp_id')
                                 ->join('employees', 'employees.id = emp_endorsement.pk')
                                 ->join('employee_polices', 'employee_polices.employee_id = employees.id')
                                 ->where('employees.emp_code', $emp_code)
@@ -578,7 +624,11 @@ class EmpDataServiceController extends BaseController
                             $emp_id = $endorsementData['emp_id'];
                             $field_name = $endorsementData['field_name'];
                             $new_value = $endorsementData['new_value'];
-                            $this->empEndorsementModel->where('id', $emp_endoresment_id)->set('endorsement_id', $endorsement_id)->update();
+                            $endoresment_udate_data = [
+                                'endorsement_id' => $endorsement_id,
+                                'status' => 'complete',
+                            ];
+                            $this->empEndorsementModel->where('id', $emp_endoresment_id)->set($endoresment_udate_data)->update();
                             $this->employeeModel->where('id', $emp_id)->set($field_name, $new_value)->update();
                         }
 
@@ -617,7 +667,7 @@ class EmpDataServiceController extends BaseController
             $import_data['created_by'] = get_session_userid();
             $import_data['file_name'] = $filename;
             $insert = $this->batchFileModel->insert($import_data);
-            $batch_file_batch_code = $this->batchFileModel->where('id', 2)->first();
+            $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
 
             $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code'];
             $batch_code_for_batch_list['created_by'] = get_session_userid();
@@ -725,8 +775,6 @@ class EmpDataServiceController extends BaseController
             $this->cashDepositCalculationForSIEnhancement($depositeData);
 
             return 1;
-
-
         }
 
 
@@ -801,18 +849,18 @@ class EmpDataServiceController extends BaseController
                             array_push($employeeIds, $id);
                         }
 
-                        $updateData = [
-                            'emp_code' =>$emp_code,
-                            'client_id' =>$client_id,
-                            'client_policy_id' =>$client_policy_id,
-                            'emp_name' =>$emp_name,
-                            'endorsement_id' =>$endorsement_id,
-                        ];
+                        // $updateData = [
+                        //     'emp_code' =>$emp_code,
+                        //     'client_id' =>$client_id,
+                        //     'client_policy_id' =>$client_policy_id,
+                        //     'emp_name' =>$emp_name,
+                        //     'endorsement_id' =>$endorsement_id,
+                        // ];
 
-                        $this->employeePolicyModel->updateEndoresmentIdForDeletion($updateData);
+                        // $this->employeePolicyModel->updateEndoresmentIdForDeletion($updateData);
 
                         $deletionDataForEmployee = $this->empEndorsementModel
-                        ->select('emp_endorsement.new_value, employees.id')
+                        ->select('emp_endorsement.new_value, emp_endorsement.id as ee_id, employees.id')
                         ->join('employees', 'emp_endorsement.emp_code = employees.emp_code')
                         ->join('employee_polices', 'employee_polices.employee_id = employees.id')
                         ->where('emp_endorsement.emp_code', $emp_code)
@@ -824,6 +872,13 @@ class EmpDataServiceController extends BaseController
 
                         $deletionDataForEmployee['updated_by'] = get_session_userid();
                         $this->employeeModel->save($deletionDataForEmployee);
+
+                        $e_Data = [
+                            'endorsement_id'=> $endorsement_id,
+                            'status'=> 'complete',
+                        ];
+                        $group_key = $this->empEndorsementModel->select('group_key')->where('id', $deletionDataForEmployee['ee_id'])->first();
+                        $this->empEndorsementModel->where('group_key', $group_key)->set($e_Data)->update();
                         
                         $fetchData = [
                             'emp_code'=> $emp_code,
@@ -834,11 +889,6 @@ class EmpDataServiceController extends BaseController
                         $deletionDataForEmployeePolicy = $this->employeePolicyModel->fetchEmpEndorsementData($fetchData);
                         $deletionDataForEmployeePolicy['updated_by'] = get_session_userid();
                         $this->employeePolicyModel->save($deletionDataForEmployeePolicy);
-
-                        // echo '
';
-                        // print_r($deletionDataForEmployeePolicy); die;
-                        
-                        $this->employeePolicyModel->save($deletionDataForEmployeePolicy);
                         
                         // $query = $this->employeePolicyModel->getLastQuery();
                         // echo $query . "
"; @@ -918,6 +968,7 @@ class EmpDataServiceController extends BaseController } + public function cashDepositCalculationForSIEnhancement($arrayData) { if (!empty($arrayData)) { @@ -954,13 +1005,14 @@ class EmpDataServiceController extends BaseController } } + public function cashDepositCalculationForDeletion($arrayData) { // print_r($arrayData); if (!empty($arrayData)) { - echo '
';
-                print_r($arrayData); die;
+                // echo '
';
+                // print_r($arrayData); die;
                 $amount = $this->employeePolicyModel->query("
                 SELECT
                     SUM(ROUND((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.date_of_exit)) / 365, 2) +
@@ -968,7 +1020,7 @@ class EmpDataServiceController extends BaseController
                 FROM employee_polices
                 WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ")
                 ")->getRow();
-                print_r($amount);die;
+
                 $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();       
                 $description = 'The following amount of ' . $amount->total_sum . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
 
@@ -996,11 +1048,175 @@ class EmpDataServiceController extends BaseController
         }
 
 
-        public function getPolicyNameUsingClientPolicyId($client_policy_id){
+
+
+        /**
+         * Below function retrieves the policy name associated with a given client policy ID.
+         *
+         * @param int $client_policy_id The ID of the client policy.
+         * @return mixed Returns the policy name if found, otherwise null.
+         */
+
+        public function getPolicyNameUsingClientPolicyId($client_policy_id)
+        {
             return $this->clientPolicyModel->select('policies.name as policy_name')
             ->join('policies', 'policies.id = client_policy.policy_id')
             ->where('client_policy.id', $client_policy_id)
             ->first();
         }
+
+
+
+
+        /**
+         * Below function converts row data into column data format for SI enhancement.
+         *
+         * This function takes an array of data containing information about SI enhancement
+         * and calculates additional fields such as pro rata premium, GST, and total.
+         *
+         * @param array $data The array of data containing SI enhancement information.
+         * @return array Returns the converted data in column format.
+         */
+        public function convertRowTColumnForSIEnhancement($data)
+        {
+
+            $result = array();
+
+            foreach ($data as $obj) {
+                 
+                $pro_rata_premium = round(($obj->difference_premium * $obj->no_of_days / 365), 2);
+                $gst = round(($pro_rata_premium * 18 / 100), 2);
+                $total = round(($pro_rata_premium + $gst), 2);
+
+                $old_total = round(($obj->old_rata + $obj->old_gst), 2);
+
+
+                $result[] = array(
+                    "field_name" => 'Basic Cover SI',
+                    "old_value" => $obj->old_basic_cover_si,
+                    "new_value" => $obj->new_basic_cover_si
+                );
+    
+                $result[] = array(
+                    "field_name" => 'Premium',
+                    "old_value" => $obj->old_si_premium,
+                    "new_value" => $obj->new_si_premium
+                );
+    
+                $result[] = array(
+                    "field_name" => 'SI Enhancement Date',
+                    "old_value" => change_date_format($obj->old_date, 'Y-m-d', 'd-M-Y'),
+                    "new_value" => change_date_format($obj->date_of_coverage, 'Y-m-d', 'd-M-Y')
+                );
+    
+                $result[] = array(
+                    "field_name" => 'Difference Premium',
+                    "old_value" => ' --- ',
+                    "new_value" => $obj->difference_premium
+                );
+    
+                $result[] = array(
+                    "field_name" => 'No of Days',
+                    "old_value" => $obj->old_days,
+                    "new_value" => $obj->no_of_days
+                );
+    
+                $result[] = array(
+                    "field_name" => 'Pro Rata Premium',
+                    "old_value" => $obj->old_rata,
+                    "new_value" =>  $pro_rata_premium 
+                );
+    
+                $result[] = array(
+                    "field_name" => 'GST(18%)',
+                    "old_value" => $obj->old_gst,
+                    "new_value" => $gst
+                );
+    
+                $result[] = array(
+                    "field_name" => 'Total',
+                    "old_value" => $old_total,
+                    "new_value" => $total
+                );
+    
+            }
+
+            return $result;
+        }
+
+
+
+        /**
+         * Below function converts row data into column data format for deletion records.
+         *
+         * This function takes an array of data containing information about deletion records
+         * and converts it into a column format. It also calculates additional fields such as
+         * period of non-coverage, premium for non-coverage period, GST, total amount, and
+         * claim status based on the exist_reason field.
+         *
+         * @param array $data The array of data containing deletion records information.
+         * @return array Returns the converted data in column format.
+         */
+        public function convertRowTColumnForDeletion($data)
+        {
+
+            $result = array();
+
+            foreach ($data as $obj) {
+
+                $old_total = round(($obj->old_rata + $obj->old_gst), 2);
+
+                $result[] = array(
+                    "field_name" => 'Policy Period',
+                    "data" => change_date_format($obj->start_date, 'Y-m-d', 'd-M-Y') . ' - 
' . change_date_format($obj->end_date, 'Y-m-d', 'd-M-Y'), + ); + + $result[] = array( + "field_name" => 'Exit on', + "data" => change_date_format($obj->date_of_leaving, 'Y-m-d', 'd-M-Y'), + ); + + $result[] = array( + "field_name" => 'Reason', + "data" => $obj->exist_reason, + ); + + + + if($obj->exist_reason != 'death'){ + + $result[] = array( + "field_name" => 'Period of non coverage', + "data" => $obj->no_of_days + ); + + $result[] = array( + "field_name" => 'Premium for non coverage period', + "data" => $obj->pro_rata_premium + ); + + $result[] = array( + "field_name" => 'GST(18%)', + "data" => $obj->gst + ); + + $result[] = array( + "field_name" => 'Total Amount', + "data" => $obj->total + ); + + $result[] = array( + "field_name" => 'Claim', + "data" => '---', + ); + + } + + } + + return $result; + } + + // ----------------------------------------------------------------------------------- } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 643fa3d7..ef969731 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -61,10 +61,12 @@ class EmployeeController extends AdminController { // $model = new UserModel(); $data = []; + $data['status'] = ['draft' => 'Draft', 'active' => 'Active', 'inactive' => 'In-Active', 'expired' => 'Expired']; if(count($this->request->getGet())) { $filterData = $this->request->getGet(); - $data['employees'] = $this->employeePolicyModel->getEmployeePolicy(client_id: $filterData['client_id'],policy_id: $filterData['policy_id']); + $data['employees'] = $this->employeePolicyModel->getEmployeePolicy(client_id: $filterData['client_id'],policy_id: $filterData['policy_id'], status: $filterData['status']); + $data['getData'] = $filterData; } $this->myLogger->logme('error','list called'); @@ -451,4 +453,92 @@ class EmployeeController extends AdminController } // ------------------------------------------------------------------------------------------- + + + /** + * Below function displays the endorsement list page. + * + * This method retrieves filter data from the request and fetches the endorsement list + * based on the provided filters such as client ID, policy ID, and status. + */ + + public function endorsementList() + { + + $data = []; + $data['status'] = ['pending' => 'Pending', 'inprogress' => 'In-Progress', 'complete'=>'Complete']; + if(count($this->request->getGet())) + { + $filterData = $this->request->getGet(); + $data['employees'] = $this->employeePolicyModel->getEmployeeEndorsementList(client_id: $filterData['client_id'],policy_id: $filterData['policy_id'], status: $filterData['status']); + $data['getData'] = $filterData; + // echo "
";
+            // print_r($data); die;
+        }
+        
+        $this->myLogger->logme('error','list called');
+        $this->loadLayout('endorsement_list',$data);
+    }
+
+
+    /**
+     * Beleo function retrieves employee endorsement (emp_endorsement table) data.
+     *
+     * This method fetches endorsement data based on the provided ID.
+     * It determines the type of endorsement action (SI enhancement, deletion, or other),
+     * formats the data accordingly, and returns it as a response.
+     *
+     * @param int|null $id The ID of the endorsement entry to retrieve.
+     * @return \CodeIgniter\HTTP\Response Returns a JSON response containing the endorsement entry data.
+     */
+    public function getEmpEndoresmentEntry($id = null)
+    {
+        // Create instance of EmpDataServiceController
+        $empDataServiceController = new EmpDataServiceController();
+    
+        // Check if $id is provided
+        if ($id) {
+            // Retrieve group key and actions based on $id
+            $group_key_actions = $this->empEndorsementModel->select('group_key, actions')->where('id', $id)->first();
+            $groupedData = $this->empEndorsementModel->where('group_key', $group_key_actions['group_key'])->findAll();
+    
+            // If group key and actions are found
+            if ($group_key_actions) {
+                // Retrieve endorsement data based on actions
+                switch ($group_key_actions['actions']) {
+                    case 'si':
+                        $data = $this->empEndorsementModel->getDataForEnodrsementListinSIEnhancement($group_key_actions['group_key']);
+                        $formatedData = $empDataServiceController->convertRowTColumnForSIEnhancement($data);
+                        break;
+                    case 'd':
+                        $data = $this->empEndorsementModel->getDataForEnodrsementListinDeletion($group_key_actions['group_key']);
+                        $formatedData = $empDataServiceController->convertRowTColumnForDeletion($data);
+                        break;
+                    default:
+                        $formatedData = $groupedData;
+                        $formatedData[0]['field_name'] = remove_underscore_capitalize_first_letter($formatedData[0]['field_name']);
+                        $formatedData[0]['old_value'] = formatDateOrReturn($formatedData[0]['old_value']);
+                        $formatedData[0]['new_value'] = formatDateOrReturn($formatedData[0]['new_value']);
+                        break;
+                }
+                
+                // Return response with data
+                return $this->respond([
+                    'dataStatus' => true,
+                    'code' => 200,
+                    'data' => $formatedData,
+                    'data2' => $groupedData
+                ], 200);
+
+            } else {
+                // Return response if group key and actions are not found
+                return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'no data found'], 200);
+            }
+        } else {
+            // Return response if $id is not provided
+            return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'no data found'], 200);
+        }
+    }
+    
+    
 }
\ No newline at end of file
diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php
index 70abe646..c22adea1 100644
--- a/app/Controllers/EmployeeRestController.php
+++ b/app/Controllers/EmployeeRestController.php
@@ -145,7 +145,7 @@ class EmployeeRestController extends AdminController
 
                 foreach ($data as $item) {
                     $id = $item->id;
-                    $item->dob = $this->convertDateFormat($item->dob);
+                    $item->dob = $this->convertDateFormatYMD($item->dob);
                     $employee = $this->employeeModel->update($id, (array)$item);
                     if ($employee) {
                         $updatedCount++;
@@ -179,7 +179,7 @@ class EmployeeRestController extends AdminController
                         //update old data
                         $id = $item->id;
                         $item->family_floater_key = $this->RelationshipMap($item->relationship);
-                        $item->dob = $this->convertDateFormat($item->dob);
+                        $item->dob = $this->convertDateFormatYMD($item->dob);
                         $employee = $this->employeeModel->update($id, (array)$item);
                         if ($employee) {
                             $Count++;
@@ -187,7 +187,7 @@ class EmployeeRestController extends AdminController
                       }else{
                         //create new data
                         $item->family_floater_key = $this->RelationshipMap($item->relationship);
-                        $item->dob = $this->convertDateFormat($item->dob);
+                        $item->dob = $this->convertDateFormatYMD($item->dob);
                         $employee = $this->employeeModel->insert($item);
                         if ($employee) {
                             $Count++;
@@ -224,24 +224,32 @@ class EmployeeRestController extends AdminController
             }
     }
 
-    private function convertDateFormat($dateString)
+    private function convertDateFormatYMD($dateString)
     {
         // Attempt to create a DateTime object from the provided date string
         $dateTime = \DateTime::createFromFormat('d-m-Y', $dateString);
-
-        // Check if the conversion was successful and the date string is in the format dd-mm-yyyy
         if ($dateTime instanceof \DateTime) {
-            // Format the date to yyyy-mm-dd
             return $dateTime->format('Y-m-d');
         } else {
-            // If the date string is not in the format dd-mm-yyyy, return null
+            return null;
+        }
+    }
+
+    private function convertDateFormatDMY($dateString)
+    {
+        // Attempt to create a DateTime object from the provided date string
+        $dateTime = \DateTime::createFromFormat('Y-m-d', $dateString);
+
+        if ($dateTime instanceof \DateTime) {
+            return $dateTime->format('d-m-Y');
+        } else {
             return null;
         }
     }
     public function deleteDependence()
     {
         try {
-            print_r($this->rquest);die;
+            
             if($this->request->getGet('id'))
             {
                 $delete  = $this->employeeModel->where('id', $this->request->getGet('id'))->delete();
@@ -286,14 +294,23 @@ class EmployeeRestController extends AdminController
     public function getClientPolicy()
     {
         try {
-            $ClientPolicyData =  $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id,policies.policy_type_id as policy_type_id, policies.name as policy_name')
-                                                        ->join('policies', 'client_policy.policy_id = policies.id', 'left')
-                                                        ->where('client_policy.client_id', $this->request->getGet('client_id') )
-                                                        ->findAll();
-
-            $result[] = $ClientPolicyData[0];
-            $result[] = $ClientPolicyData[2];
-            // You probably meant to check $result, not $data
+            $ClientPolicyData =  $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id,policies.policy_type_id as policy_type_id, policies.name as policy_name , client_policy.is_addon as is_addon')
+                                                         ->join('policies', 'client_policy.policy_id = policies.id', 'left')
+                                                         ->where('client_policy.client_id', $this->request->getGet('client_id') )
+                                                         ->findAll();
+            $result = [];
+            foreach ($ClientPolicyData as $key => $value) {
+                $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard( $value['client_policy_id'],$value['client_id']);
+                if($value['is_addon'] == 1){
+                    $value['type'] = 'Add-On';
+                }else{
+                    $value['type'] = $getSlabAndGridData['grid_master']['policy_type'];
+                }
+               
+                 array_push($result,$value);
+                
+                
+            }
             if ($ClientPolicyData) {
                 return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200);
             } else {
@@ -308,134 +325,134 @@ class EmployeeRestController extends AdminController
     }
 
 
-    public function getEmployeePolicy()
-    {            
-        try {
-            $id = $this->request->getGet('id');
-            $emp_code = $this->request->getGet('emp_code');
+    // public function getEmployeePolicy()
+    // {            
+    //     try {
+    //         $id = $this->request->getGet('id');
+    //         $emp_code = $this->request->getGet('emp_code');
           
-            $keysToRemove  = ["removable_keys"];
+    //         $keysToRemove  = ["removable_keys"];
 
-            $empPolicy = $this->employeeModel->getEmployeePolicy($id);
+    //         $empPolicy = $this->employeeModel->getEmployeePolicy($id);
 
-            $empData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
-            if ($empPolicy) {
+    //         $empData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
+    //         if ($empPolicy) {
 
-                $result = [];
-                foreach ($empPolicy as $array) { 
+    //             $result = [];
+    //             foreach ($empPolicy as $array) { 
                     
-                    $decodedArray = json_decode($array->Policy_Terms);
-                    $refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove));
+    //                 $decodedArray = json_decode($array->Policy_Terms);
+    //                 $refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove));
 
                     
-                    $array->Policy_Terms = $refusingData;
-                    $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId);
-                    $array->SlabRates = $getSlabAndGridData['slab_rates'];
-                    $array->GridMaster = $getSlabAndGridData['grid_master'];
+    //                 $array->Policy_Terms = $refusingData;
+    //                 $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId);
+    //                 $array->SlabRates = $getSlabAndGridData['slab_rates'];
+    //                 $array->GridMaster = $getSlabAndGridData['grid_master'];
 
-                    if($getSlabAndGridData['grid_master']['policy_type'] == "GPA"){
-                        $default_si = $array->Policy_Terms->sumInsured2;
-                        $index = -1;
-                        foreach ($array->SlabRates as $key => $value) {
-                            if ($value['si'] == $default_si) {
-                                $index = $key;
-                                break;
-                            }
-                        }
-                        if ($index >= 0) {
-                            $element =$array->SlabRates[$index];
-                            array_splice($array->SlabRates, $index, 1);
-                            array_unshift($array->SlabRates, $element);
-                        }
+    //                 if($getSlabAndGridData['grid_master']['policy_type'] == "GPA"){
+    //                     $default_si = $array->Policy_Terms->sumInsured2;
+    //                     $index = -1;
+    //                     foreach ($array->SlabRates as $key => $value) {
+    //                         if ($value['si'] == $default_si) {
+    //                             $index = $key;
+    //                             break;
+    //                         }
+    //                     }
+    //                     if ($index >= 0) {
+    //                         $element =$array->SlabRates[$index];
+    //                         array_splice($array->SlabRates, $index, 1);
+    //                         array_unshift($array->SlabRates, $element);
+    //                     }
 
-                        $employee_policy = $this->employeePolicyModel->where('employee_id',$id)->where('client_policy_id',$array->ClientPolicyId)->get()->getRow();
-                        if($employee_policy){
-                            $gpaSI['family_floater_key'] = 'self';
-                            $gpaSI['label'] = 'Self';
-                            $gpaSI['employee_id'] =  $employee_policy->employee_id;
-                            $gpaSI['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
-                            $gpaSI['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;
-                            $gpaSI['client_policy_id'] = $array->ClientPolicyId;  
+    //                     $employee_policy = $this->employeePolicyModel->where('employee_id',$id)->where('client_policy_id',$array->ClientPolicyId)->get()->getRow();
+    //                     if($employee_policy){
+    //                         $gpaSI['family_floater_key'] = 'self';
+    //                         $gpaSI['label'] = 'Self';
+    //                         $gpaSI['employee_id'] =  $employee_policy->employee_id;
+    //                         $gpaSI['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
+    //                         $gpaSI['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;
+    //                         $gpaSI['client_policy_id'] = $array->ClientPolicyId;  
 
-                            $array->mapped_family_floaters = $gpaSI;
-                        }else{
-                            $gpaSI['family_floater_key'] = 'self';
-                            $gpaSI['label'] = 'Self';
-                            $gpaSI['employee_id'] =  $id;
-                            $gpaSI['basic_cover_si'] = null;
-                            $gpaSI['premium'] =  null;
-                            $gpaSI['client_policy_id'] = $array->ClientPolicyId;  
+    //                         $array->mapped_family_floaters = $gpaSI;
+    //                     }else{
+    //                         $gpaSI['family_floater_key'] = 'self';
+    //                         $gpaSI['label'] = 'Self';
+    //                         $gpaSI['employee_id'] =  $id;
+    //                         $gpaSI['basic_cover_si'] = null;
+    //                         $gpaSI['premium'] =  null;
+    //                         $gpaSI['client_policy_id'] = $array->ClientPolicyId;  
 
-                            $array->mapped_family_floaters = $gpaSI;
-                        }
+    //                         $array->mapped_family_floaters = $gpaSI;
+    //                     }
 
-                    }else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC"){
+    //                 }else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC"){
 
-                        // re-arranging order of si
-                        $default_si = $array->Policy_Terms->sum_insured;
-                        // Filter the array using the callback function
-                        $getPremium = array_filter($array->SlabRates ,  function ($value) use ($default_si) { return $value['si'] == $default_si;  } );
-                        $default_premium =  $getPremium[0]['premium'];
+    //                     // re-arranging order of si
+    //                     $default_si = $array->Policy_Terms->sum_insured;
+    //                     // Filter the array using the callback function
+    //                     $getPremium = array_filter($array->SlabRates ,  function ($value) use ($default_si) { return $value['si'] == $default_si;  } );
+    //                     $default_premium =  $getPremium[0]['premium'];
 
-                        $index = -1;
-                        foreach ($array->SlabRates as $key => $value) {
-                            if ($value['si'] == $default_si) {
-                                $index = $key;
-                                break;
-                            }
-                        }
-                        if ($index >= 0) {
-                            $element =$array->SlabRates[$index];
-                            array_splice($array->SlabRates, $index, 1);
-                            array_unshift($array->SlabRates, $element);
-                        }
+    //                     $index = -1;
+    //                     foreach ($array->SlabRates as $key => $value) {
+    //                         if ($value['si'] == $default_si) {
+    //                             $index = $key;
+    //                             break;
+    //                         }
+    //                     }
+    //                     if ($index >= 0) {
+    //                         $element =$array->SlabRates[$index];
+    //                         array_splice($array->SlabRates, $index, 1);
+    //                         array_unshift($array->SlabRates, $element);
+    //                     }
 
-                        //map family floates array to employee and dependent
-                        $familyFloates = $array->Policy_Terms->family_floaters;
-                        $data = [];
-                        foreach ($familyFloates as $familyFloatesValue) { 
-                            $dependent =   preg_replace('/\d/', '', $familyFloatesValue);
-                            if(count($empData)){
-                                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)->get()->getRow();
-                                        $temp['family_floater_key'] = $familyFloatesValue;
-                                        $temp['label'] = $value['relationship'];
-                                        $temp['name'] = $value['name'];
-                                        $temp['employee_id'] = $value['id'];
-                                        $temp['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
-                                        $temp['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;
-                                        $temp['client_policy_id'] = $array->ClientPolicyId;               
-                                        array_push($data,$temp);
-                                        unset($empData[$key]);
-                                        break;
-                                    }
-                                }
-                            }
-                        }
-                        $array->mapped_family_floaters = $data;
+    //                     //map family floates array to employee and dependent
+    //                     $familyFloates = $array->Policy_Terms->family_floaters;
+    //                     $data = [];
+    //                     foreach ($familyFloates as $familyFloatesValue) { 
+    //                         $dependent =   preg_replace('/\d/', '', $familyFloatesValue);
+    //                         if(count($empData)){
+    //                             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)->get()->getRow();
+    //                                     $temp['family_floater_key'] = $familyFloatesValue;
+    //                                     $temp['label'] = $value['relationship'];
+    //                                     $temp['name'] = $value['name'];
+    //                                     $temp['employee_id'] = $value['id'];
+    //                                     $temp['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
+    //                                     $temp['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;
+    //                                     $temp['client_policy_id'] = $array->ClientPolicyId;               
+    //                                     array_push($data,$temp);
+    //                                     unset($empData[$key]);
+    //                                     break;
+    //                                 }
+    //                             }
+    //                         }
+    //                     }
+    //                     $array->mapped_family_floaters = $data;
 
-                        $temp2=[];
-                        foreach ($array->SlabRates as $key => $value) {
-                           $value['additional_premium'] = $value['premium'] -  $default_premium;
-                           array_push($temp2,$value);
-                        }
-                        $array->SlabRates  =  $temp2;
+    //                     $temp2=[];
+    //                     foreach ($array->SlabRates as $key => $value) {
+    //                        $value['additional_premium'] = $value['premium'] -  $default_premium;
+    //                        array_push($temp2,$value);
+    //                     }
+    //                     $array->SlabRates  =  $temp2;
 
                        
 
-                    }
+    //                 }
                     
-                    $result[] = $array;
-                }
-                return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);             
-            }else{
-                return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
-            }
-        } catch (\Exception $e) {
-            return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
-        }
-    }
+    //                 $result[] = $array;
+    //             }
+    //             return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);             
+    //         }else{
+    //             return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
+    //         }
+    //     } catch (\Exception $e) {
+    //         return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+    //     }
+    // }
 
     // Get the RelationShip list
 
@@ -451,17 +468,21 @@ class EmployeeRestController extends AdminController
             $checkIfExist = $this->employeePolicyModel->where('employee_id', $value->employee_id)
                                                    ->where('client_policy_id', $value->client_policy_id)
                                                    ->findAll();
+            $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($value->client_policy_id,$value->client_id);
+            $SlabRatesArray = $getSlabAndGridData['slab_rates'];
+            $premium = $this->findPremiumAmount($SlabRatesArray, $value->basic_cover_si);
+
             // dd($checkIfExist);
             if ($checkIfExist) {
 
-                    $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id,  $value->employee_id, $value->basic_cover_si,$value->premium);
+                    $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id,  $value->employee_id, $value->basic_cover_si,$premium);
 
                 }else{
 
                     $data['employee_id']= $value->employee_id;
                     $data['client_policy_id']= $value->client_policy_id;
                     $data['basic_cover_si']= $value->basic_cover_si;
-                    $data['premium']= $value->premium;
+                    $data['premium']= $premium;
             
                     $this->employeePolicyModel->insert($data);
                 }
@@ -473,7 +494,15 @@ class EmployeeRestController extends AdminController
         }
     }
 
-
+    public function findPremiumAmount($slabArray,$siAmount)
+    {
+       foreach ($slabArray as $key => $value) {
+           if($value['si'] == $siAmount){
+             return $value['premium'];
+             break;
+           }
+       } 
+    }
     public function relationshipList()
     {
         try {
@@ -499,12 +528,17 @@ class EmployeeRestController extends AdminController
             $client_id = $this->request->getPost('client_id');
             $policy_id = $this->request->getPost('policy_id');
 
-            $token = $this->request->headers()['Auth']->getValue();
-            $decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true);
+            $jwt = $this->request->getHeader('Authorization');
+            $jwtParts = explode(' ', $jwt);
+            $token = $jwtParts[1];
 
+            
+            $decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true);
             // get the employee id from token
             $employee_id = $decodedPayload['id'];
 
+
+
             $client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->first();
 
             if ($client_policy) {
@@ -677,6 +711,7 @@ class EmployeeRestController extends AdminController
                         $basic_cover_si[]= $basic_cover_si_value;
                     }
                 }
+                $count = 0;
                 for ($a=0; $a employeeModel->checkExistingEmployee($dataToInsert[$a]);
@@ -753,10 +788,23 @@ class EmployeeRestController extends AdminController
                     $data['policy_name']=$policy['name'];
                     
                     $message = view('mail_welcome', $data);
+
+                    if ($dataToInsert[$a]['relationship'] == 'Self' && $mail != null || $mail != '') {
+                        $count++;
+                        $wholeData[] =  ['mail' => $mail, 'subject' => $subject,'message'=> $message];
+                    }
+
+                    // print_r($wholeData);
                     // if ($dataToInsert[$a]['email_corporate'] != null || $dataToInsert[$a]['email_corporate'] != ''  &&  $dataToInsert[$a]['relationship'] == 'Self') {
-                    //     $job_details  = new Jobs();
-                    //     $r = Jobs::addJob(['job_name' => 'send_email','payload' => ['mail' => $mail, 'subject' => $subject,'message'=> $message]]);    
-                    // }
+                    if($count == 20 || $a == count($dataToInsert)-1){
+                        $job_details  = new Jobs();
+                        $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $wholeData]); 
+                        // $wholeData[]= $r; 
+
+                        // Mailhelper::bulk_mail($wholeData); 
+                        $wholeData = [];
+                        $count = 0;
+                    }
                 
                     // print_r($r);//die();
                     // $jobWorker = new JobWorker();
@@ -778,6 +826,397 @@ class EmployeeRestController extends AdminController
     }
 
 
+//-------------------------------------
 
+public function getEmployeePolicy()
+{            
+    try {
+
+        $id = $this->request->getGet('id');
+        $emp_code = $this->request->getGet('emp_code');
+
+        // This is an array containing keys to be removed from the terms and conditions array
+        $keysToRemove  = ["removable_keys"];
+        // Retrieve employee policy data by passing the employee primary key
+        $empPolicy = $this->employeeModel->getEmployeePolicy($id);
+        // Retrieve employee and dependents data by passing the employee code
+        $employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('is_addon_value',0)->findAll();
+      
+    
+        if ($empPolicy) {
+
+            $result = [];
+            foreach ($empPolicy as $array) { 
+                // Reset employee array
+                $empData = $employeeData;
+
+                // Removes specific keys from the decoded array and assigns the result to $refusingData
+                $decodedArray = json_decode($array->Policy_Terms);
+                $refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove));
+                $array->Policy_Terms = $refusingData;
+
+                // Retrieve slab rate and grid master data by passing the ClientPolicyId and ClientId 
+                $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId);
+                $array->SlabRates = $getSlabAndGridData['slab_rates'];
+                $array->GridMaster = $getSlabAndGridData['grid_master'];
+
+                // Construct value for policy type GPA
+                if($getSlabAndGridData['grid_master']['policy_type'] == "GPA"){
+                  
+                   // Filter employee data where the family_floater_key is 'self'
+                    $selfData = array_filter($empData, fn($arr) => trim(strtolower($arr['family_floater_key'])) === 'self'); 
+                    $self['is_value_exist'] = true;
+                    $self['data']['family_floater_key'] = 'self';
+                    $self['data']['employee_id'] = $id;
+                    $self['data']['relationship'] = 'Self';
+                    $self['data']['name'] = $selfData[0]['name'];
+                    $self['data']['dob'] = $this->convertDateFormatDMY($selfData[0]['dob']);
+                    $self['data']['mobile'] = $selfData[0]['mobile'];
+                    $self['data']['client_policy_id'] = $array->ClientPolicyId; 
+
+                    $array->mapped_family_floaters = $self;
+                    
+                    // Return result
+                    if($this->request->getGet('policy') == 'GPA')
+                    {
+                      return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200);
+                    }
+                
+                // Construct value for policy type GMC
+                }else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC"){
+
+                    
+
+                    // Map family floaters that already exist in the employee table
+                    $familyFloates = $array->Policy_Terms->family_floaters;
+                    // Generate Notes string based on  familyFloates terms
+                    $array->notes = $this->FloterNotesConvertion($familyFloates);
+                    // Convert familyFloaters terms data to plain array 
+                    $floters = $this->FloterConvertion($familyFloates);
+
+                    $data = [];
+                    foreach ($floters as $familyFloatesValue) { 
+                        $dependent =   preg_replace('/\d/', '', $familyFloatesValue);
+                        if(count($empData)){
+                            foreach ($empData as $key => $value) {
+                                if ($value['family_floater_key'] === $dependent) {
+                                    $temp['is_value_exist'] = true;
+                                    $temp['data']['family_floater_key'] = $familyFloatesValue;
+                                    $temp['data']['employee_id'] = $value['id'];
+                                    $temp['data']['relationship'] = $value['relationship'];
+                                    $temp['data']['name'] = $value['name'];
+                                    $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']);
+                                    $temp['data']['client_policy_id'] = $array->ClientPolicyId;   
+                                    $temp['data']['form_type'] = $dependent;            
+                                    array_push($data,$temp);
+                                    unset($empData[$key]);
+                                    $floters = array_diff($floters, [$familyFloatesValue]);
+                                    break;
+                                }
+                            }
+                        }
+                    }
+            
+                    // Remove Unwanted floter key from floters array based on either-parents-pil  term value
+                    if($familyFloates->{'either-parents-pil'} == 1 && count($floters))
+                    {
+                        $count_parent = 0;
+                        $count_parent_in_law = 0;
+                        foreach ($floters as $value) {
+                        if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; }
+                        if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;}
+                        }
+                        if($count_parent != 2) { 
+                            $floters = array_filter($floters, fn($value) => strpos($value, 'parent_in_law') === false);
+                        }
+                        if($count_parent_in_law != 2) { 
+                            $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false);
+                         }
+                    }
+                
+                    // Add family floter buttons placement data for FE validation
+                    if(count($floters)){
+                    foreach ($floters as $familyFloatesValue) {
+
+                        $temp2['is_value_exist'] = false;
+                        $temp2['data']['family_floater_key'] = $familyFloatesValue;
+                        $temp2['data']['client_policy_id'] = $array->ClientPolicyId; 
+                        $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); 
+                        $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue);
+
+                        array_push($data,$temp2);
+
+                    }
+                   }
+
+                    $array->mapped_family_floaters = $data;
+
+                  
+
+                    if($this->request->getGet('policy') == 'GMC'){
+                        return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200);
+                    }
+
+                }
+                
+                $result[] = $array;
+            }
+          
+            
+
+        }else{
+            return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
+        }
+    } catch (\Exception $e) {
+        return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+    }
+}
+
+public function FloterConvertion($array){
+
+        $result = [];
+        foreach ($array as $key => $value) {
+            if ($value > 0) {
+                if ($value != 0 && $key === 'childrens') {
+                    for ($i = 1; $i <= $value; $i++) {
+                        $result[] = "child" . $i;
+                    }
+                } else if($value != 0 && $key ==='parents') {
+                    for ($i = 1; $i <= $value; $i++) {
+                        $result[] = "parent" . $i;
+                    }
+                }else if($value != 0 && $key ==='parents-in-law') {
+                    for ($i = 1; $i <= $value; $i++) {
+                        $result[] = "parent_in_law" . $i;
+                    }
+                }else if($value != 0 && $key ==='either-parents-pil') {
+                    for ($i = 1; $i <= 2; $i++) {
+                        $result[] = "parent" . $i;
+                        $result[] = "parent_in_law" . $i;
+                    }
+                }else {
+                    $result[] = $key;
+                }
+            }
+        }
+
+        return $result;
+}
+
+public function FloterNotesConvertion($array){
+
+    $result = 'Can Add Self ';
+    foreach ($array as $key => $value) {
+        if ($value > 0) {
+            if($value != 0 && $key ==='either-parents-pil') {
+                $result .= ' + Either 2 Parents or 2 Parents in law';
+            }else if($value != 0 && $key ==='spouse') {
+                $string = str_replace('-', ' ', $key);
+                $string = ucwords($string);
+                $result .= ' + '.$string;
+            }else if($value != 0 && $key ==='self') {
+            }else{
+                $string = str_replace('-', ' ', $key);
+                $string = ucwords($string);
+                $result .= ' + '.$value.' '.$string;
+            }
+        }
+    }
+
+    return $result;
+}
+
+public function getClientDetails()
+{            
+    try {
+
+        $client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first(); 
+        if($client) {
+        $client['client_logo'] = base_url().'public/uploads/logo/'.$client['client_logo'];
+        $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll(); 
+        return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$clientPolicy]], 200);
+
+        }else{
+            return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
+        }
+    } catch (\Exception $e) {
+        return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+    }
+}
+
+public function getAddOnPolicy()
+{            
+    try {
+
+        $addOnEmployeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))->where('is_addon_value',1)->findAll();
+        $GMCEmployeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))->where('is_addon_value',0)->findAll();
+       
+
+        $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll(); 
+        //  dd($clientPolicy);
+        if(count($clientPolicy))
+        {
+        $PolicyData = [];
+        foreach ($clientPolicy as $key => $array) {
+
+           
+        $decodedArray = json_decode($array['policy_terms']);
+        $policy_terms = $decodedArray;
+        $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array['id'],$array['client_id']);
+
+        if($array['is_addon'] == 1)
+        {
+                    $responce['policy_name'] =  $this->policesModel->where('id',$array['policy_id'])->get()->getRow()->name;
+                    $responce['SlabRates'] = $getSlabAndGridData['slab_rates'];
+                    $responce['GridMaster'] = $getSlabAndGridData['grid_master'];
+                    $responce['client_id'] = $array['client_id'];
+                    $responce['client_policy_id'] = $array['id'];
+                    $responce['is_addon'] = $array['is_addon'];
+                    $responce['open_for_enrollment'] = $array['open_for_enrollment'];
+                    $responce['policy_terms'] = $decodedArray;
+                    
+
+
+                    // Map family floaters that already exist in the employee table
+                    $familyFloates = $policy_terms->family_floaters;
+                    // Convert familyFloaters terms data to plain array 
+                    $floters = $this->FloterConvertion($familyFloates);
+
+
+                    $data = [];
+                    $dependent_and_si_value = null;
+                    $dependent_and_si_premium_value = null;
+                    foreach ($floters as $familyFloatesValue) { 
+                        $dependent =   preg_replace('/\d/', '', $familyFloatesValue);
+                        if(count($addOnEmployeeData)){
+                            foreach ($addOnEmployeeData as $key => $value) {
+                                if ($value['family_floater_key'] === $dependent) {
+                                    $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->get()->getRow();
+                                    if(isset($employee_policy->basic_cover_si)){  $dependent_and_si_value = $employee_policy->basic_cover_si; }
+                                    if(isset($employee_policy->premium)){   $dependent_and_si_premium_value = $employee_policy->premium;}
+                                    
+                                    $temp['is_value_exist'] = true;
+                                    $temp['data']['family_floater_key'] = $familyFloatesValue;
+                                    $temp['data']['employee_id'] = $value['id'];
+                                    $temp['data']['relationship'] = $value['relationship'];
+                                    $temp['data']['name'] = $value['name'];
+                                    $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']);
+                                    $temp['data']['client_policy_id'] = $array['id'];   
+                                    $temp['data']['form_type'] = $dependent;  
+                                    $temp['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
+                                    $temp['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;          
+                                    array_push($data,$temp);
+                                    unset($addOnEmployeeData[$key]);
+                                    $floters = array_diff($floters, [$familyFloatesValue]);
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                
+                    
+                    //Remove Unwanted floter key from floters array based on either-parents-pil  term value
+                    if($familyFloates->{'either-parents-pil'} == 1 && count($floters))
+                    {
+                        if(count($addOnEmployeeData) == 0)
+                        {
+                            $GMCEmpData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))
+                                                            ->where('is_addon_value',0)
+                                                            ->where('family_floater_key','parent')
+                                                            ->findAll();
+                                            
+                            if(count($GMCEmpData) > 0){
+                                $floters = array_diff($floters, ["parent1","parent2"]);
+                            }else{
+                                $floters = array_diff($floters, ["parent_in_law1","parent_in_law2"]);
+                            }
+                        }else{
+
+                            $count_parent = 0;
+                            $count_parent_in_law = 0;
+                            foreach ($floters as $value) {
+                            if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; }
+                            if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;}
+                            }
+                            if($count_parent != 2) { 
+                                $floters = array_filter($floters, fn($value) => strpos($value, 'parent_in_law') === false);
+                            }
+                            if($count_parent_in_law != 2) { 
+                                $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false);
+                            }
+                        }
+            
+                        
+                    }
+
+
+                
+                    // Add family floter buttons placement data for FE validation
+                    if(count($floters)){
+                    foreach ($floters as $familyFloatesValue) {
+
+                        $temp2['is_value_exist'] = false;
+                        $temp2['data']['family_floater_key'] = $familyFloatesValue;
+                        $temp2['data']['client_policy_id'] = $array['id']; 
+                        $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); 
+                        $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue);
+
+                        array_push($data,$temp2);
+
+                    }
+                    }
+
+                    $responce['family_floaters_of_dependent_and_si_array'] = $data;
+                    $responce['family_floaters_of_dependent_and_si_value'] = $dependent_and_si_value;
+                    $responce['family_floaters_of_dependent_and_si_premium_value'] = $dependent_and_si_premium_value;
+
+
+                    $only_si_array = [];
+                    $only_si_value = null;
+                    $only_si_premium_value = null;
+                    foreach ($GMCEmployeeData as $key => $value) {
+
+                            $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->get()->getRow();
+                            if(isset($employee_policy->basic_cover_si)){  $only_si_value = $employee_policy->basic_cover_si; }
+                            if(isset($employee_policy->premium)){   $only_si_premium_value = $employee_policy->premium;}
+                            $temp3['is_value_exist'] = true;
+                            $temp3['data']['employee_id'] = $value['id'];
+                            $temp3['data']['relationship'] = $value['relationship'];
+                            $temp3['data']['name'] = $value['name'];
+                            $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']);
+                            $temp3['data']['client_policy_id'] = $array['id']; 
+                            $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
+                            $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;          
+                            array_push($only_si_array,$temp3);
+
+                    }
+
+                    $responce['family_floaters_of_only_si_array'] = $only_si_array;
+                    $responce['family_floaters_of_only_si_value'] = $only_si_value;
+                    $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value;
+                
+
+
+
+                array_push($PolicyData, $responce);
+        }
+
+        }
+
+
+        return $this->respond(['status' => 'success','code' => 200,'data' => ['addon_policy'=>$responce]], 200);
+
+        }else{
+            return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
+        }
+    } catch (\Exception $e) {
+        return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+    }
+}
+
+public function iAgreeForAddOn()
+{ 
+    return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200);
+}
 
 }
\ No newline at end of file
diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php
index 2a80bc2e..6977a94b 100644
--- a/app/Controllers/JobWorker.php
+++ b/app/Controllers/JobWorker.php
@@ -14,7 +14,7 @@ class JobWorker extends AdminController
      * Constructs the class
      */
 
-    private  static $event_class_mapping = ['add' => ['type' => 'HC','handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' =>  ['type' => 'CC','handler' => 'App\\Controllers\\Jobs\SubJob'],'fancy_date_time_format' => [ 'type' => 'HF','handler' => 'fancy_date_time_format'],'addNumber' => ['type' => 'HC','handler' => 'App\\Model\\HttpRequestHelper'],'excelFileFormatValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'excelFileDataValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'employeeOnboard' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'send_email' => ['type' => 'HC','handler' => 'App\\Helpers\\MailHelper']];
+    private  static $event_class_mapping = ['add' => ['type' => 'HC','handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' =>  ['type' => 'CC','handler' => 'App\\Controllers\\Jobs\SubJob'],'fancy_date_time_format' => [ 'type' => 'HF','handler' => 'fancy_date_time_format'],'addNumber' => ['type' => 'HC','handler' => 'App\\Model\\HttpRequestHelper'],'excelFileFormatValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'excelFileDataValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'employeeOnboard' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'send_email' => ['type' => 'HC','handler' => 'App\\Helpers\\MailHelper'],'bulk_mail' => ['type' => 'HC','handler' => 'App\\Helpers\\MailHelper']];
     public function __construct()
     {
         // echo 'HiC';//die();
@@ -199,4 +199,7 @@ class JobWorker extends AdminController
         }
     }
 
+
+
+
 }
diff --git a/app/Filters/AuthJWT.php b/app/Filters/AuthJWT.php
index 0bd204ad..a9b6911f 100644
--- a/app/Filters/AuthJWT.php
+++ b/app/Filters/AuthJWT.php
@@ -18,15 +18,7 @@ class AuthJWT implements FilterInterface
 {
     public function before(RequestInterface $request, $arguments = null)
     {
-
-        $jwt ='';
-
-        if($request->headers()['Auth']){
-            $jwt = $request->headers()['Auth'];
-        }else{
-            $jwt = $request->getHeader('Authorization');
-        }
-
+        $jwt = $request->getHeader('Authorization');
 
         if ($jwt) {
             if (JWTToken::validateJWT($jwt)) {
diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php
index 9709de46..212d78d9 100644
--- a/app/Helpers/MailHelper.php
+++ b/app/Helpers/MailHelper.php
@@ -9,6 +9,8 @@ use PHPMailer\PHPMailer\PHPMailer;
 use PHPMailer\PHPMailer\SMTP;
 use PHPMailer\PHPMailer\Exception;
 
+use App\Models\JobModel;
+
 
 class MailHelper
 {
@@ -18,6 +20,7 @@ class MailHelper
         $subject = $params['subject'];
         $message = $params['message'];
         try {
+            
             $email = \Config\Services::email();
             $email->setMailType('html');
             $email->setFrom('bbone@venbait.in', 'Nhance');
@@ -37,5 +40,26 @@ class MailHelper
             return json_encode(['status' => 'failed','code' => 500,'data' => $emaill],500);
         }  
     }
+
+
+    public static function bulk_mail(array $mails = [])
+    {
+        $model = new JobModel();
+        $start = microtime(true);
+        $runtime= 0;
+       try {
+        foreach ( $mails as $index=>$mail) {
+                $runtime = microtime(true) - $start;
+                $send_mail = self::send_email($mail);   
+        }
+        
+        return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...'],200);
+
+       } catch (\Throwable $th) {
+        return json_encode(['status' => 'failed','code' => 500],500);
+       }
+    }
+
+
 }
 ?>
\ No newline at end of file
diff --git a/app/Helpers/excel_import_export_helper.php b/app/Helpers/excel_import_export_helper.php
index b6bf615a..af0b8e07 100644
--- a/app/Helpers/excel_import_export_helper.php
+++ b/app/Helpers/excel_import_export_helper.php
@@ -394,7 +394,27 @@ if (! function_exists('generate_filename')) {
 if (!function_exists('remove_underscore_capitalize_first_letter')) {
     function remove_underscore_capitalize_first_letter($word) {
         // Remove underscore and capitalize first letter of each word
+        $pattern = '/dob/i'; 
+        if (preg_match($pattern, $word)) {
+            $formattedEvent = 'DOB';
+            return $formattedEvent;
+        } 
         $formattedEvent = ucwords(str_replace('_', ' ', $word));
         return $formattedEvent;
     }
+}
+
+if (!function_exists('formatDateOrReturn')) {
+    function formatDateOrReturn($value)
+    {
+        // Check if the value is a valid date
+        $timestamp = strtotime($value);
+        if ($timestamp !== false) {
+            // Format the date
+            return date('d-M-Y', $timestamp);
+        } else {
+            // Return the original value
+            return $value;
+        }
+    }
 }
\ No newline at end of file
diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php
index 26c7aa08..2ac23d6f 100644
--- a/app/Helpers/utility_helper.php
+++ b/app/Helpers/utility_helper.php
@@ -86,31 +86,34 @@ if (!function_exists('compressImage')) {
 if (!function_exists('fancy_date_time_format')) 
 {
     function fancy_date_time_format($datetime,$return_type = 'fancy') {
+        date_default_timezone_set('Asia/Kolkata');
+
         $currentDateTime = new DateTime();
         $passedDateTime = new DateTime($datetime);
-
-
-            // Calculate the interval between the current time and the passed datetime
-            $interval = $currentDateTime->diff($passedDateTime);
-            // return change_date_format($datetime,'Y-m-d H:i:s','d M Y h:i a');
-                // If the interval is more than 1 month, return the original datetime
-            if ($interval->m > 1 || $interval->y > 0) {
-                if($return_type = 'fancy'){ return change_date_format($datetime,'Y-m-d H:i:s','d M Y h:i a'); }
-                return $datetime;
-            } elseif ($interval->m == 1 && $interval->y == 0) {
-                return "1 month ago";
-            } elseif ($interval->d >= 7) {
-                $weeks = floor($interval->d / 7);
-                return $weeks == 1 ? "1 week ago" : "$weeks weeks ago";
-            } elseif ($interval->d >= 1) {
-                return $interval->d == 1 ? "1 day ago" : $interval->d . " days ago";
-            } elseif ($interval->h >= 1) {
-                return $interval->h == 1 ? "1 hour ago" : $interval->h . " hours ago";
-            } elseif ($interval->i >= 1) {
-                return $interval->i == 1 ? "1 minute ago" : $interval->i . " minutes ago";
-            } else {
-                return "Just now";
+    
+        // Calculate the interval between the current time and the passed datetime
+        $interval = $currentDateTime->diff($passedDateTime);
+    
+        // If the interval is more than 1 month or the year is different, return the original datetime
+        if ($interval->m > 1 || $interval->y != 0) {
+            if ($return_type == 'fancy') {
+                return change_date_format($datetime, 'Y-m-d H:i:s', 'd M Y h:i a');
             }
+            return $datetime;
+        } elseif ($interval->m == 1 && $interval->y == 0) {
+            return "1 month ago";
+        } elseif ($interval->d >= 7) {
+            $weeks = floor($interval->d / 7);
+            return $weeks == 1 ? "1 week ago" : "$weeks weeks ago";
+        } elseif ($interval->d >= 1) {
+            return $interval->d == 1 ? "1 day ago" : $interval->d . " days ago";
+        } elseif ($interval->h >= 1) {
+            return $interval->h == 1 ? "1 hour ago" : $interval->h . " hours ago";
+        } elseif ($interval->i >= 1) {
+            return $interval->i == 1 ? "1 minute ago" : $interval->i . " minutes ago";
+        } else {
+            return "Just now";
+        }
     }
 
 }
@@ -129,3 +132,5 @@ if(!function_exists('check_string_date'))
 
 
 
+
+
diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php
index 01bc2a2c..8008ad8d 100644
--- a/app/Models/ClientPolicyModel.php
+++ b/app/Models/ClientPolicyModel.php
@@ -71,12 +71,13 @@ class ClientPolicyModel extends Model
         ->select('policy_type.policy_type as policy_type_name') 
         ->select('insurer_branch.branch_name as insurer_branch_name, insurer_branch.branch_code as insurer_branch_code')
         ->select('tpa_branch.branch_name as tpa_branch_name, tpa_branch.branch_code as tpa_branch_code')
+        ->select('policy_type.policy_type as policy_type_name')
         ->join('insurers', 'insurers.id = client_policy.insurer_id')
         ->join('insurer_branch', 'client_policy.insurer_branch_id = insurer_branch.id')
         ->join('tpa', 'tpa.id = client_policy.tpa_id')
         ->join('tpa_branch', 'client_policy.tpa_branch_id = tpa_branch.id')
         ->join('policies', 'policies.id = client_policy.policy_id')
-        ->join('policy_type', 'policy_type.id = policies.policy_type_id') 
+        ->join('policy_type', 'policy_type.id = policies.policy_type_id')
         ->where('client_policy.client_id', $client_id)
         ->get()
         ->getResult();
diff --git a/app/Models/EmpEndorsementModel.php b/app/Models/EmpEndorsementModel.php
index b6956259..8be6c38c 100644
--- a/app/Models/EmpEndorsementModel.php
+++ b/app/Models/EmpEndorsementModel.php
@@ -11,6 +11,7 @@ class EmpEndorsementModel extends Model
     protected $allowedFields    = [
         'id',
         'pk',
+        'group_key',
         'endorsement_id',
         'emp_code',
         'table_name',
@@ -27,4 +28,173 @@ class EmpEndorsementModel extends Model
         "remarks"
     ];
 
+     // Callbacks
+     protected $allowCallbacks       = true;
+     protected $beforeInsert         = [];
+     protected $afterInsert          = [];
+     protected $beforeUpdate         = [];
+     protected $afterUpdate          = [];
+     protected $beforeFind           = [];
+     protected $afterFind            = [];
+     protected $beforeDelete         = [];
+     protected $afterDelete          = [];
+
+
+    //  protected function afterFind(array $data)
+    //  {
+    //      foreach ($data as &$row) {
+    //          // Format date_of_coverage field to Indian date format
+    //          if (isset($row['field_name'])) {
+    //              $row['field_name'] = remove_underscore_capitalize_first_letter($row['field_name']);
+    //          }
+    //      }
+ 
+    //      return $data;
+    //  }
+
+
+    public function getDataForEnodrsementListinSIEnhancement($group_key){
+        $query = "
+            SELECT 
+            employee_polices.days as old_days,
+            employee_polices.rata_premimum as old_rata,
+            employee_polices.gst as old_gst,
+            client_policy.policy_start_date as old_date,
+
+            MAX(CASE WHEN emp_endorsement.field_name = 'basic_cover_si' THEN emp_endorsement.new_value ELSE NULL END) AS new_basic_cover_si,
+            MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.new_value ELSE NULL END) AS new_si_premium,
+            MAX(CASE WHEN emp_endorsement.field_name = 'si_enhancement_date' THEN emp_endorsement.new_value ELSE NULL END) AS date_of_coverage,
+            MAX(CASE WHEN emp_endorsement.field_name = 'basic_cover_si' THEN emp_endorsement.old_value ELSE NULL END) AS old_basic_cover_si,
+            MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.old_value ELSE NULL END) AS old_si_premium,
+
+            (MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.new_value ELSE NULL END) - MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.old_value ELSE NULL END)) AS difference_premium,
+
+            DATEDIFF(employee_polices.policy_end_date, MAX(CASE WHEN emp_endorsement.field_name = 'si_enhancement_date' THEN emp_endorsement.new_value END)) + 1 AS no_of_days,
+
+            ROUND(
+                (
+                    (
+                        MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.new_value END) - 
+                        MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.old_value END)
+                    ) * 
+                    DATEDIFF(
+                        employee_polices.policy_end_date, 
+                        MAX(CASE WHEN emp_endorsement.field_name = 'si_enhancement_date' THEN emp_endorsement.new_value END)
+                    ) / 365
+                ),
+                2
+            ) AS pro_rata_premimum,
+
+            ROUND(((MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.new_value ELSE NULL END) - MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.old_value ELSE NULL END)) * DATEDIFF(employee_polices.policy_end_date, MAX(CASE WHEN emp_endorsement.field_name = 'si_enhancement_date' THEN emp_endorsement.new_value ELSE NULL END)) / 365) * 0.18, 2) AS gst,
+            ROUND(((MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.new_value ELSE NULL END) - MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.old_value ELSE NULL END)) * DATEDIFF(employee_polices.policy_end_date, MAX(CASE WHEN emp_endorsement.field_name = 'si_enhancement_date' THEN emp_endorsement.new_value ELSE NULL END)) / 365), 2) + 
+            ROUND(((MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.new_value ELSE NULL END) - MAX(CASE WHEN emp_endorsement.field_name = 'premium' THEN emp_endorsement.old_value ELSE NULL END)) * DATEDIFF(employee_polices.policy_end_date, MAX(CASE WHEN emp_endorsement.field_name = 'si_enhancement_date' THEN emp_endorsement.new_value ELSE NULL END)) / 365) * 0.18, 2) AS total
+       
+            FROM emp_endorsement
+        JOIN employee_polices ON employee_polices.id = emp_endorsement.pk
+        JOIN client_policy ON client_policy.id = employee_polices.client_policy_id
+        WHERE group_key = '{$group_key}'
+        ";
+
+        $results = $this->db->query($query)->getResult();
+        return $results;
+
+    }
+
+
+    public function getDataForEnodrsementListinDeletion($group_key){
+        $query = "
+                SELECT 
+            
+                employee_polices.days as old_days,
+                employee_polices.rata_premimum as old_rata,
+                employee_polices.gst as old_gst,
+                employee_polices.policy_end_date as end_date,
+                client_policy.policy_start_date as start_date,
+            
+                MAX(CASE WHEN a.field_name = 'date_of_exit' THEN a.new_value ELSE NULL END) AS date_of_leaving,
+                MAX(CASE WHEN a.field_name = 'reason_for_exit' THEN a.new_value ELSE NULL END) AS exist_reason,
+                DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) AS no_of_days,
+                ROUND((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365, 2) AS pro_rata_premium,
+                ROUND(((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18, 2) AS gst,
+                ROUND(((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) + (((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18), 2) AS total
+            FROM 
+                emp_endorsement a
+            LEFT JOIN 
+                employees ON a.emp_code = employees.emp_code 
+            LEFT JOIN 
+                employee_polices ON employees.id = employee_polices.employee_id 
+            LEFT JOIN 
+                client_policy ON client_policy.id = employee_polices.client_policy_id 
+            LEFT JOIN (
+                SELECT 
+                    aa.emp_code, 
+                    aa.new_value AS 'empstatus', 
+                    bb.new_value AS 'changeevent', 
+                    cc.new_value AS 'dateofexit', 
+                    dd.new_value AS 'reasonforexit', 
+                    ee.new_value AS 'status' 
+                FROM 
+                    (
+                        SELECT  
+                            a1.emp_code, 
+                            a1.field_name, 
+                            a1.new_value 
+                        FROM 
+                            emp_endorsement AS a1 
+                        WHERE 
+                            a1.field_name = 'emp_status'
+                    ) aa 
+                LEFT JOIN 
+                    (
+                        SELECT  
+                            b1.emp_code, 
+                            b1.field_name, 
+                            b1.new_value 
+                        FROM 
+                            emp_endorsement AS b1 
+                        WHERE 
+                            b1.field_name = 'change_event'
+                    ) bb ON aa.emp_code = bb.emp_code 
+                LEFT JOIN
+                    (
+                        SELECT  
+                            c1.emp_code, 
+                            c1.field_name, 
+                            c1.new_value 
+                        FROM 
+                            emp_endorsement AS c1  
+                        WHERE 
+                            c1.field_name = 'date_of_exit'
+                    ) cc ON aa.emp_code = cc.emp_code
+                LEFT JOIN
+                    (
+                        SELECT  
+                            d1.emp_code, 
+                            d1.field_name, 
+                            d1.new_value 
+                        FROM 
+                            emp_endorsement AS d1  
+                        WHERE 
+                            d1.field_name = 'reason_for_exit'
+                    ) dd ON aa.emp_code = dd.emp_code 
+                LEFT JOIN
+                    (
+                        SELECT  
+                            e1.emp_code, 
+                            e1.field_name, 
+                            e1.new_value 
+                        FROM 
+                            emp_endorsement AS e1  
+                        WHERE 
+                            e1.field_name = 'status'
+                    ) ee ON aa.emp_code = ee.emp_code
+            ) AS deletiondata ON a.emp_code = deletiondata.emp_code 
+            WHERE group_key = '{$group_key}';
+            ";
+
+        $results = $this->db->query($query)->getResult();
+        return $results;
+
+    }
+
 }
diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php
index 914c623b..5f2bd65f 100644
--- a/app/Models/EmployeeModel.php
+++ b/app/Models/EmployeeModel.php
@@ -35,7 +35,8 @@ class EmployeeModel extends Model
         "updated_by",
         "updated_at",
         "is_active",
-        "file_id"
+        "file_id",
+        "is_addon_value"
     ];
 
       // Callbacks
diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php
index 94a6e80e..8340dbf5 100644
--- a/app/Models/EmployeePolicyModel.php
+++ b/app/Models/EmployeePolicyModel.php
@@ -67,7 +67,7 @@ class EmployeePolicyModel extends Model
     }
 
 // -----------------------------------------------------------------------------------------------------
-   public function getEmployeePolicy($client_id,$policy_id)
+   public function getEmployeePolicy($client_id,$policy_id,$status)
    {
         $result =  $this->select(['employee_polices.*','pm.name as policy_name','im.short_name as insurer_short_name','ib.branch_name as insurer_branch_name','ib.branch_code as insurer_branch_code','tpam.name as tpa_name','tpam.short_name as tpa_short_name','tpab.branch_code as tpa_branch_code','cm.client_name','cm.short_name as client_short_name','emp.relationship','emp.relationship_code','emp.change_event','emp.emp_code','emp.name','emp.email_corporate','emp.dob','emp.gender','emp.emp_status','emp.is_active as emp_is_active'])
                         ->join('employees emp', 'employee_polices.employee_id = emp.id') 
@@ -79,8 +79,13 @@ class EmployeePolicyModel extends Model
                         ->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id') //tpab - tpa brach
                         ->join('clients cm', 'cp.client_id = cm.id') //cm - client master
                         ->where('emp.client_id',$client_id)
-                        ->where('employee_polices.client_policy_id',$policy_id)
-                        ->findAll();
+                        ->where('employee_polices.client_policy_id',$policy_id);
+                        
+        if($status != 0 && !empty($status)){
+            $result->where('employee_polices.status', $status);
+        }
+        
+        $result = $result->findAll();        
         return ($result);
    }
 
@@ -230,6 +235,7 @@ class EmployeePolicyModel extends Model
 
         $query = $this->db->query("
                 SELECT 
+                    a.id as endorsement_primarykey,
                     employee_polices.id AS primaryKey,
                     employees.name AS emp_name,
                     employees.emp_code AS emp_code,
@@ -336,6 +342,7 @@ class EmployeePolicyModel extends Model
 
             $query = $this->db->query("
             SELECT 
+                a.id as endorsement_primarykey,
                 employee_polices.id as primaryKey, 
                 employees.name AS emp_name,
                 employees.emp_code AS emp_code,
@@ -451,7 +458,7 @@ class EmployeePolicyModel extends Model
             UPDATE emp_endorsement 
             JOIN employees ON employees.id = emp_endorsement.pk
             JOIN employee_polices ON employees.id = employee_polices.employee_id
-            SET emp_endorsement.endorsement_id = '$endorsement_id'
+            SET emp_endorsement.endorsement_id = '$endorsement_id', emp_endorsement.status = 'complete'
             WHERE employees.emp_code = '$emp_code'
             AND employee_polices.uhid = '$uhid'
         ";
@@ -463,15 +470,15 @@ class EmployeePolicyModel extends Model
         
         $client_id = $update_data['client_id'];
         $client_policy_id = $update_data['client_policy_id'];
-        $emp_name = $update_data['name'];
+        $emp_name = $update_data['emp_name'];
         $emp_code = $update_data['emp_code'];
-        $endorsement_id = $update_data['uhid'];
+        $endorsement_id = $update_data['endorsement_id'];
 
         $sql = "
                 UPDATE emp_endorsement
                 JOIN employee_polices ON employee_polices.id = emp_endorsement.pk
                 JOIN employees ON employee_polices.employee_id = employees.id
-                SET emp_endorsement.endorsement_id = '$endorsement_id'
+                SET emp_endorsement.endorsement_id = '$endorsement_id', emp_endorsement.status = 'complete'
                 WHERE emp_endorsement.emp_code = '$emp_code'
                 AND employees.client_id = '$client_id'
                 AND employee_polices.client_policy_id = '$client_policy_id'
@@ -483,19 +490,20 @@ class EmployeePolicyModel extends Model
     }
 
 
-    public function updateEndoresmentIdForDeletion($update_data){
+    public function updateEndoresmentIdForDeletion($update_data)
+    {
         
         $client_id = $update_data['client_id'];
         $client_policy_id = $update_data['client_policy_id'];
-        $emp_name = $update_data['name'];
+        $emp_name = $update_data['emp_name'];
         $emp_code = $update_data['emp_code'];
-        $endorsement_id = $update_data['uhid'];
+        $endorsement_id = $update_data['endorsement_id'];
 
         $sql = "
                 UPDATE emp_endorsement
                 JOIN employee_polices ON employee_polices.id = emp_endorsement.pk
                 JOIN employees ON employee_polices.employee_id = employees.id
-                SET emp_endorsement.endorsement_id = '$endorsement_id'
+                SET emp_endorsement.endorsement_id = '$endorsement_id', emp_endorsement.status = 'complete'
                 WHERE employees.emp_code = '$emp_code'
                 AND employees.client_id = '$client_id'
                 AND employee_polices.client_policy_id = '$client_policy_id'
@@ -508,7 +516,7 @@ class EmployeePolicyModel extends Model
     public function fetchEmpEndorsementData($fetch_data)
     {
         $client_policy_id = $fetch_data['client_policy_id'];
-        $emp_name = $fetch_data['name'];
+        $emp_name = $fetch_data['emp_name'];
         $emp_code = $fetch_data['emp_code'];
 
         // Your raw SQL query
@@ -560,6 +568,79 @@ class EmployeePolicyModel extends Model
         $this->query($query);
     }
 
-    //------------------------------------------------------------------
 
-}
+    public function getEmployeeEndorsementList($client_id, $policy_id, $status)
+    {   
+        $query1 = $this->db->table('emp_endorsement e');
+        $query1->select('
+                    e.id, 
+                    e.pk, 
+                    e.emp_code, 
+                    e.name, 
+                    e.actions, 
+                    e.status, 
+                    e.remarks, 
+                    e.endorsement_id, 
+                    ep.client_policy_id, 
+                    policies.name as policy_name,
+                    insurers.short_name as insurer_short_name
+                ');
+                $query1->distinct();
+                $query1->join('employee_polices ep', 'ep.id = e.pk', 'left');
+                $query1->join('employees', 'employees.id = ep.employee_id', 'left');
+                $query1->join('client_policy', 'client_policy.id = ep.client_policy_id', 'left');
+                $query1->join('policies', 'policies.id = client_policy.policy_id', 'left');
+                $query1->join('insurers', 'insurers.id = policies.insurer_id', 'left');
+                $query1->whereIn('e.actions', ['c']);
+                $query1->where('ep.client_policy_id', $client_id);
+                $query1->where('employees.client_id', $policy_id);
+                if($status != 0 && !empty($status)){
+
+                    $query1->where('e.status', $status);
+                }
+                $query1->orderBy('e.id', 'desc'); 
+    
+        $results1 = $query1->get()->getResultArray();
+        
+        $query2 = $this->db->table('emp_endorsement e');
+
+            $query2->select('
+                    e.id, 
+                    e.pk, 
+                    e.emp_code, 
+                    e.name, 
+                    e.actions, 
+                    e.status, 
+                    e.endorsement_id, 
+                    e.remarks, 
+                    ep.client_policy_id, 
+                    policies.name as policy_name,
+                    insurers.short_name as insurer_short_name
+                ');
+                $query2->join('employee_polices ep', 'ep.id = e.pk', 'left');
+                $query2->join('employees', 'employees.id = ep.employee_id', 'left');
+                $query2->join('client_policy', 'client_policy.id = ep.client_policy_id', 'left');
+                $query2->join('policies', 'policies.id = client_policy.policy_id', 'left');
+                $query2->join('insurers', 'insurers.id = policies.insurer_id', 'left');
+                $query2->whereIn('e.actions', ['si', 'd']);
+                $query2->where('ep.client_policy_id', $client_id);
+                $query2->where('employees.client_id', $policy_id);
+                if($status != 0 && !empty($status)){
+
+                    $query2->where('e.status', $status);
+                }
+                $query2->groupBy('e.emp_code, e.name, e.actions');
+                $query2->orderBy('e.id', 'desc'); 
+        
+        $results2 = $query2->get()->getResultArray();
+        
+        $results = array_merge($results1, $results2);
+        
+        return $results;
+    
+        
+    }
+    
+    //----------------------------------------------------------------------------------------------
+
+}
\ No newline at end of file
diff --git a/app/Views/UserList.php b/app/Views/UserList.php
index bb36986f..a4d5afdc 100644
--- a/app/Views/UserList.php
+++ b/app/Views/UserList.php
@@ -1,5 +1,4 @@
 
 
diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php
index a4e893ab..45b5cd9d 100644
--- a/app/Views/client_policy.php
+++ b/app/Views/client_policy.php
@@ -36,8 +36,8 @@
                 
- - + +
@@ -94,12 +94,10 @@
- +
-
-
@@ -159,6 +157,7 @@ $('.btnAdd').click(function(){ + $('#policy_form')[0].reset(); $('#add_form').show(); $('#table_list').hide(); $('.btnBack').show(); @@ -170,14 +169,13 @@ $('#policy').html(''); $('#is_addon').prop('checked', false); $('#policy_form_action').val(''); + $('#policy_status_field').hide() }) $('.btnBack').click(function(){ - - $('#GMC').remove(); - $('#GPA').remove(); + $('#policy_form')[0].reset(); $('#add_form').hide(); $('#table_list').show(); $('.btnBack').hide(); @@ -194,10 +192,22 @@ if (policy_PrimaryKey !== '') { var policyTable = ''; var data = ; + // console.log('client_policy_data',data) data.forEach(function(item) { - // console.log("----------------------------"); + console.log(item.open_for_enrollment); + var patternGMC = /gmc/i; // Case insensitive pattern for 'gmc' + var patternGPA = /gpa/i; // Case insensitive pattern for 'gpa' + var subject = item.policy_type_name; - // console.log(item); + if (patternGMC.test(subject)) { + search_term = 'GMC'; + } else if (patternGPA.test(subject)) { + search_term = 'GPA'; + } else { + search_term = subject; // Set default value if neither 'GMC' nor 'GPA' exists + } + + console.log('search_term :', search_term) policyTable += ` @@ -211,10 +221,15 @@ + Terms + Rac Rate + `; + if (item.open_for_enrollment == 0) { + policyTable +=`Open Enrollment `; + }else{ + policyTable +=`Open Enrollment `; + } + policyTable += `
@@ -271,7 +286,7 @@ success: function(res) { console.log(res); - + $('#policy_form')[0].reset(); if (res.status === false) { toastr.error('Policy Dose Not Create', 'Error'); return; @@ -295,10 +310,25 @@ $('#policy_table tr').remove(); var policyTable = ''; $.each(res.data, function(index, item) { + + var patternGMC = /gmc/i; // Case insensitive pattern for 'gmc' + var patternGPA = /gpa/i; // Case insensitive pattern for 'gpa' + var subject = item.policy_type_name; + + if (patternGMC.test(subject)) { + search_term = 'GMC'; + } else if (patternGPA.test(subject)) { + search_term = 'GPA'; + } else { + search_term = subject; // Set default value if neither 'GMC' nor 'GPA' exists + } + + console.log('search_term :', search_term) + policyTable += ` ${item.insurer_short} - ${item.insurer_branch_name} - ${item.policy_name} + ${item.policy_name} (${item.policy_type_name}) ${item.tpa_short} - ${item.tpa_branch_code} ${rearrangeDateFormat(item.policy_start_date)} - ${rearrangeDateFormat(item.policy_end_date)} ${checkDateStatus(item.policy_end_date, 1)} @@ -307,8 +337,8 @@ @@ -482,13 +512,28 @@ client_policy_id : client_policy_id, }, success: function(res) { - // console.log(res); + console.log(res); if(res) { + if (res.open_for_enrollment) { + var json_decode=JSON.parse(res.open_for_enrollment); + var open_for_enrollment=json_decode.open_for_enrollment; + var client_policy_id=json_decode.client_policy_id; + if (open_for_enrollment == 1) { + // console.log($('[data-id="' + client_policy_id + '"]'); + $('.btnOpenEnroll').each(function(index, element) { + if ($(element).data('id') == client_policy_id) { + $(element).css({'background-color': 'lightgrey', 'pointer-events': 'none'}); + } + }); + } + + } setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); if(res.status === true){ toastr.success(res.message, 'Success'); + }else if(res.status === false){ toastr.warning(res.message, 'Warning'); } diff --git a/app/Views/employee_list.php b/app/Views/employee_list.php index db203bcd..02b28c13 100644 --- a/app/Views/employee_list.php +++ b/app/Views/employee_list.php @@ -22,23 +22,34 @@ table.dataTable tbody td {
-
-
-
-
- -
+
+
+
+
-
-
-
- -
+ +
+
+
+ +
+
+ +
+
@@ -98,7 +109,19 @@ table.dataTable tbody td { - active + + ' . $employee['status'] . ''; + } elseif ($employee['status'] == 'active') { + echo '' . $employee['status'] . ''; + } elseif ($employee['status'] == 'inactive') { + echo '' . $employee['status'] . ''; + }elseif ($employee['status'] == 'expired') { + echo '' . $employee['status'] . ''; + } + ?> +