FIX_COPY_ENBABLE
This commit is contained in:
parent
2bb38af974
commit
76cc67a417
@ -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 = [
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -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')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user