From 76cc67a417dacfb81ea6df2558d6547723ef174c Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 8 Dec 2025 10:32:32 +0530 Subject: [PATCH] FIX_COPY_ENBABLE --- app/Controllers/EmployeeRestController.php | 11 ++++++-- app/Helpers/utility_helper.php | 32 ++++++++++++++++++++++ app/Models/EmployeeModel.php | 3 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index c2622a0..d12c2a2 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1160,7 +1160,8 @@ class EmployeeRestController extends AdminController if ($empPolicy) { - + + $latest_gmc_policy_id = getLatestGMCPolicy((array)$empPolicy); $result = []; foreach ($empPolicy as $array) { @@ -1259,6 +1260,11 @@ class EmployeeRestController extends AdminController $array->to_be_added_relationship = []; $array->existing_relationship = []; + if(!empty($latest_gmc_policy_id) && $latest_gmc_policy_id == $array->ClientPolicyId){ + $array->copy_dependence_data_enable = true; + }else{ + $array->copy_dependence_data_enable = false; + } // Map family floaters that already exist in the employee table $familyFloates = $array->Policy_Terms->family_floaters; @@ -1453,7 +1459,7 @@ class EmployeeRestController extends AdminController $result[] = $GmcParrentsData; } - if($this->request->getGet('policy') == 'GMC'){ + if($this->request->getGet('policy') == 'GMC' && !$checkGmcParentsPolicyExist){ // return $this->respond(['status' => 'success','code' => 200,'data' => [$array]], 200); $result[] = $array; } @@ -1473,6 +1479,7 @@ class EmployeeRestController extends AdminController }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200); } + } catch (\Exception $e) { $errorData = [ diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 3372200..765b8af 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -666,3 +666,35 @@ if (!function_exists('check_pay_by_employee_or_company')) { } +if (!function_exists('getLatestGMCPolicy')) { + + function getLatestGMCPolicy(array $empPolicy) + { + try{ + $filtered = array_filter($empPolicy, function ($row) { + $type = is_object($row) ? $row->policy_type_id : $row['policy_type_id']; + return isset($type) && (int)$type === 2; + }); + + if (count($filtered) > 1) { + + usort($filtered, function ($a, $b) { + $dateA = is_object($a) ? $a->policy_end_date : $a['policy_end_date']; + $dateB = is_object($b) ? $b->policy_end_date : $b['policy_end_date']; + return strtotime($dateB) <=> strtotime($dateA); + }); + + $row = reset($filtered); + return is_object($row) ? ($row->ClientPolicyId ?? null) : ($row['ClientPolicyId'] ?? null); + } + + return null; + + }catch(\Exception $e){ + log_message('error', 'Exception getLatestGMCPolicy :' . $e->getMessage()); + return null; + } + } + +} + diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 2cfc852..c556bdb 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -166,7 +166,8 @@ class EmployeeModel extends Model client_policy.disclaimer, client_policy.policy_type_id , employee_polices.tpa_id as tpa_id , - employee_polices.rand_string as rand_string + employee_polices.rand_string as rand_string, + client_policy.policy_end_date ', FALSE) // Select all columns from both tables ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') ->join('policy_type', 'policy_type.id = client_policy.policy_type_id')