From b0a0c6e02e94f6d8b7eb68fed7bfb1a039261c58 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Wed, 3 Jul 2024 17:03:56 +0530 Subject: [PATCH] FEAT_CREATE_FUNCTION_FOR_POLICY_TERMS : RV --- app/Config/Routes.php | 2 + app/Controllers/ClientController.php | 95 +++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f7caabe2..77cf4c62 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -12,6 +12,8 @@ $routes->get('/swagger', 'SwaggerController::index', ['filter' => 'authMVC']); // Reminder Mail Notification $routes->get("reminder_mail", "NotificationController::reminder_mail"); +$routes->get("testing", "ClientController::Testing"); +$routes->get("update-policy-terms-for-corrections", "ClientController::updatePolicyTermsForCorrections"); $routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index b70939c9..77313418 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -106,7 +106,47 @@ class ClientController extends AdminController } + + public function Testing() + { + $results = $this->clientPolicyModel + ->select('id, policy_terms') + ->where('policy_terms IS NOT NULL') + ->where('policy_terms <>', '') + ->whereNotIn('policy_type_id', [1, 6, 7]) + ->orderBy('id', 'desc') + ->get() + ->getResultArray(); + + foreach ($results as $key => $result) { + $client_policy_id = $result['id']; + $policy_terms = json_decode($result['policy_terms'], true); // true to get associative array + + if (isset($policy_terms['family_floaters'])) { + $family_floaters = $policy_terms['family_floaters']; + $parents = $family_floaters['parents'] ?? 0; + $parents_in_law = $family_floaters['parents-in-law'] ?? 0; + + if ($parents == 1 && $parents_in_law == 1) { + $policy_terms['family_floaters']['parents'] = 0; + $policy_terms['family_floaters']['parents-in-law'] = 0; + $policy_terms['family_floaters']['either-parents-pil'] = 2; + + $results[$key]['policy_terms'] = json_encode($policy_terms); + + // Update the policy_terms in the database + $this->clientPolicyModel + ->where('id', $client_policy_id) + ->set('policy_terms', $results[$key]['policy_terms']) + ->update(); + } + } + } + + dd($results); + } + public function index() { $this->myLogger->logme('error','Client list function called'); @@ -123,8 +163,8 @@ class ClientController extends AdminController // $this->loadLayout('client_onboarding', $data); } - - public function updateEmpAndPolicyStatus(){ + public function updateEmpAndPolicyStatus() + { $return = $this->clientPolicyModel->updateStatus(); $this->myLogger->logme('error', 'Client Policy Status Update Count: {data}', ['data' => $return['client']]); @@ -133,6 +173,57 @@ class ClientController extends AdminController } + public function updatePolicyTermsForCorrections(){ + + $results = $this->clientPolicyModel + ->select('id, policy_terms') + ->where('policy_terms IS NOT NULL') + ->where('policy_terms <>', '') + ->whereNotIn('policy_type_id', [1, 6, 7]) + ->orderBy('id', 'desc') + ->get() + ->getResultArray(); + + + $updated_data = []; + foreach ($results as $key => $result) { + $client_policy_id = $result['id']; + $policy_terms = json_decode($result['policy_terms'], true); // true to get associative array + + if (isset($policy_terms['family_floaters'])) { + $family_floaters = $policy_terms['family_floaters']; + $parents = $family_floaters['parents'] ?? 0; + $parents_in_law = $family_floaters['parents-in-law'] ?? 0; + + if ($parents == 1 && $parents_in_law == 1) { + + $updated_data[] = $client_policy_id; + + $policy_terms['family_floaters']['parents'] = 0; + $policy_terms['family_floaters']['parents-in-law'] = 0; + $policy_terms['family_floaters']['either-parents-pil'] = 2; + + + $results[$key]['policy_terms'] = json_encode($policy_terms); + + // Update the policy_terms in the database + $this->clientPolicyModel + ->where('id', $client_policy_id) + ->set('policy_terms', $results[$key]['policy_terms']) + ->update(); + } + } + } + + if(count($updated_data) > 0){ + echo 'There are ' . count($updated_data) . ' records to be updated.'; + }else{ + echo 'There is no records to be update.'; + } + // dd($results); + + } + public function removeClient($id = null) { $this->myLogger->logme('error','Client Remove function called');