From 17837196bbb7b7e905049adcbb59b84a25fbee45 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 24 May 2024 10:09:12 +0530 Subject: [PATCH] CHANGE_CLIENT_BRANCH_ID_ON_ALL_PLACE : RV --- app/Controllers/ClientController.php | 140 +++-- app/Controllers/EmployeeController.php | 29 +- app/Models/BatchFileModel.php | 1 + app/Models/ClientModel.php | 11 +- app/Models/EmployeeModel.php | 3 +- app/Models/EmployeePolicyModel.php | 33 +- app/Models/FileModel.php | 3 +- app/Views/batch_list.php | 2 + app/Views/employee_list.php | 104 +++- app/Views/employee_upload.php | 169 ++++-- app/Views/endorsement_list.php | 761 ++++++++++++++----------- app/Views/file_list.php | 2 + app/Views/insurer_or_tpa_data.php | 91 ++- 13 files changed, 861 insertions(+), 488 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index e3f7b038..7de442a9 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1962,91 +1962,89 @@ class ClientController extends AdminController -public function transformArray($data, $mapping) { + public function transformArray($data, $mapping) + { - // dd($data); - $transformedData = []; + // dd($data); + $transformedData = []; + + if (!is_array($data)) { + return json_encode($transformedData, JSON_PRETTY_PRINT); + } + + foreach ($data as $key => $value) { + if ($key == 'family_floaters') { + $transformedData[$key] = $this->transformFamilyFloaters($value, $data); + } else if (array_key_exists($key, $mapping)) { + $transformedData[$mapping[$key]] = $value; + } else if ($key == 'special_condition_label') { + + foreach ($value as $key => $value) { + $transformedData[$value] = $data['special_condition_input'][$key]; + } + } else if ($key == 'gpa_special_condition_label') { + + foreach ($value as $key => $value) { + $transformedData[$value] = $data['gpa_special_condition_input'][$key]; + } + } else if ($key == 'age_ratio') { + + if (isset($data['sumInsured2'])) { + + $transformedData['Self'] = "(Min: " . $data['age_ratio']['self']['min'] . ", Max: " . $data['age_ratio']['self']['max'] . ")"; + } + } else { + $transformedData[$key] = $value; + } + } - if (!is_array($data)) { return json_encode($transformedData, JSON_PRETTY_PRINT); } - foreach ($data as $key => $value) { - if ($key == 'family_floaters') { - $transformedData[$key] = $this->transformFamilyFloaters($value, $data); - }else if (array_key_exists($key, $mapping)) { - $transformedData[$mapping[$key]] = $value; - }else if($key == 'special_condition_label'){ - foreach ($value as $key => $value) { - $transformedData[$value] = $data['special_condition_input'][$key]; - } + public function transformFamilyFloaters($familyFloaters, $json) + { + $result = []; - }else if($key == 'gpa_special_condition_label'){ + $min = $json['age_ratio']['self']; + $max = $json['age_ratio']['self']; - foreach ($value as $key => $value) { - $transformedData[$value] = $data['gpa_special_condition_input'][$key]; - } + $spouse_min = $json['age_ratio']['spouse']; + $spouse_max = $json['age_ratio']['spouse']; - }else if($key == 'age_ratio'){ + $child_min = $json['age_ratio']['child']; + $child_max = $json['age_ratio']['child']; - if(isset($data['sumInsured2'])){ + $elders_min = $json['age_ratio']['elders']; + $elders_max = $json['age_ratio']['elders']; - $transformedData['Self'] = "(Min: " . $data['age_ratio']['self']['min'] . ", Max: " . $data['age_ratio']['self']['max'] . ")"; - } - - - }else { - $transformedData[$key] = $value; - } - } - - return json_encode($transformedData, JSON_PRETTY_PRINT); -} - - -public function transformFamilyFloaters($familyFloaters, $json) { - $result = []; - - $min = $json['age_ratio']['self']; - $max = $json['age_ratio']['self']; - - $spouse_min = $json['age_ratio']['spouse']; - $spouse_max = $json['age_ratio']['spouse']; - - $child_min = $json['age_ratio']['child']; - $child_max = $json['age_ratio']['child']; - - $elders_min = $json['age_ratio']['elders']; - $elders_max = $json['age_ratio']['elders']; - - foreach ($familyFloaters as $key => $value) { - if ($value !== 0) { - switch ($key) { - case 'self': - $result[] = "Self (Min: {$min['min']}, Max: {$max['max']})"; - break; - case 'spouse': - $result[] = "Spouse (Min: {$spouse_min['min']}, Max: {$spouse_max['max']})"; - break; - case 'childrens': - $result[] = "Children(s) - $value (Min: {$child_min['min']}, Max: {$child_max['max']})"; - break; - case 'parents': - $result[] = "Parent(s) - $value (Min: {$elders_min['min']}, Max: {$elders_max['max']})"; - break; - case 'parents-in-law': - $result[] = "Parents-in-Law - $value (Min: {$elders_min['min']}, Max: {$elders_max['max']})"; - break; - case 'either-parents-pil': - $result[] = "Either Parents Nor Parents-in-Law - $value (elders_min: {$elders_min['min']}, Max: {$elders_max['max']})"; - break; + foreach ($familyFloaters as $key => $value) { + if ($value !== 0) { + switch ($key) { + case 'self': + $result[] = "Self (Min: {$min['min']}, Max: {$max['max']})"; + break; + case 'spouse': + $result[] = "Spouse (Min: {$spouse_min['min']}, Max: {$spouse_max['max']})"; + break; + case 'childrens': + $result[] = "Children(s) - $value (Min: {$child_min['min']}, Max: {$child_max['max']})"; + break; + case 'parents': + $result[] = "Parent(s) - $value (Min: {$elders_min['min']}, Max: {$elders_max['max']})"; + break; + case 'parents-in-law': + $result[] = "Parents-in-Law - $value (Min: {$elders_min['min']}, Max: {$elders_max['max']})"; + break; + case 'either-parents-pil': + $result[] = "Either Parents Nor Parents-in-Law - $value (elders_min: {$elders_min['min']}, Max: {$elders_max['max']})"; + break; + } } } - } - return implode(", ", $result); -} + return implode(", ", $result); + } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index f6a0dc8f..9e495ea9 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -76,7 +76,13 @@ class EmployeeController extends AdminController $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'], status: $filterData['status']); + $data['employees'] = $this->employeePolicyModel->getEmployeePolicy( + client_id: $filterData['client_id'], + policy_id: $filterData['policy_id'], + status: $filterData['status'], + branch_id: $filterData['branch_id'] + ); + $data['getData'] = $filterData; } @@ -89,6 +95,8 @@ class EmployeeController extends AdminController //echo $this->request->isAJAX();die(); $result = $this->clientModel->clientsWithPolicies(); + // dd($result); + // print_r($result);die(); if (!count($result)) { return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'no data found'], 200); @@ -190,10 +198,11 @@ class EmployeeController extends AdminController $client_id = $this->request->getPost('client_id'); $policy_id = $this->request->getPost('policy_id'); + $branch_id = $this->request->getPost('branch_id'); $action = $this->request->getPost('upload-action-type'); $status = 'inprogress'; - $file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => $action]); //here field policy_id have client_policy_id and not policy id from policy master + $file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => $action, 'client_branch_id' => $branch_id]); //here field policy_id have client_policy_id and not policy id from policy master $this->myLogger->logme("error", '{file_id} uploaded success', ['file_id' => $file_id]); //start validation process @@ -232,6 +241,7 @@ class EmployeeController extends AdminController 'up.first_name', 'pm.name as policy_name', 'c.short_name', + 'cb.branch_name', 'cp.id as client_policy_id', '(SELECT COUNT(*) FROM employees e @@ -244,6 +254,7 @@ class EmployeeController extends AdminController ]) ->join('user_profiles up', 'files.created_by = up.id') ->join('client_policy cp', 'files.policy_id = cp.id', 'left') + ->join('client_branch cb', 'files.client_branch_id = cb.id', 'left') ->join('policies pm', 'cp.policy_id = pm.id', 'left') ->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left') ->where('files.created_by', get_session_userid()) @@ -251,8 +262,9 @@ class EmployeeController extends AdminController ->findAll(); // dd($data['fileList']); - $data['batch_list'] = $this->batchFileModel->select('batch_files.*, policies.name as policy_name, clients.short_name as client_short_name') + $data['batch_list'] = $this->batchFileModel->select('batch_files.*, policies.name as policy_name, clients.short_name as client_short_name, client_branch.branch_name') ->join('client_policy', 'client_policy.id = batch_files.client_policy_id') + ->join('client_branch', 'client_branch.id = batch_files.client_branch_id') ->join('policies', 'policies.id = client_policy.policy_id') ->join('clients', 'clients.id = client_policy.client_id') ->orderBy('batch_files.id', 'desc') @@ -351,6 +363,7 @@ class EmployeeController extends AdminController $client_id = $this->request->getPost('client_id'); $client_policy_id = $this->request->getPost('client_policy_id'); + $client_branch_id = $this->request->getPost('client_branch_id'); $insurer_or_tpa = $this->request->getPost('insurer_or_tpa'); $event_type = $this->request->getPost('event_type'); $actions = $this->request->getPost('action_type'); @@ -362,6 +375,7 @@ class EmployeeController extends AdminController $batch_data = [ 'client_id' => $client_id, 'client_policy_id' => $client_policy_id, + 'client_branch_id' => $client_branch_id, 'insurer_or_tpa' => $insurer_or_tpa, 'event_type' => $event_type, 'actions' => $actions, @@ -544,8 +558,13 @@ class EmployeeController extends AdminController $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; + $data['employees'] = $this->employeePolicyModel->getEmployeeEndorsementList( + client_id: $filterData['client_id'], + policy_id: $filterData['policy_id'], + status: $filterData['status'], + branch_id: $filterData['branch_id'] + ); + $data['getData'] = $filterData; // echo "
";
             // print_r($data); die;
         }
diff --git a/app/Models/BatchFileModel.php b/app/Models/BatchFileModel.php
index 1d2b4a0d..df644790 100644
--- a/app/Models/BatchFileModel.php
+++ b/app/Models/BatchFileModel.php
@@ -24,6 +24,7 @@ class BatchFileModel extends Model
         "amount",
         "status",
         "error_data",
+        "client_branch_id",
     ];
 
           // Callbacks
diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php
index 193b9b71..35beeb4c 100644
--- a/app/Models/ClientModel.php
+++ b/app/Models/ClientModel.php
@@ -4,6 +4,7 @@ namespace App\Models;
 
 use CodeIgniter\Model;
 use App\Models\ClientPolicyModel;
+use App\Models\ClientBranchModel;
 
 class ClientModel extends Model
 {
@@ -41,7 +42,8 @@ class ClientModel extends Model
 
             foreach ($clients as &$client) {
                 $clientPolicyModel = new ClientPolicyModel();
-                $clientPolicies = $clientPolicyModel->select(['client_policy.id','p.name','pt.policy_type'])
+                $clientPolicies = $clientPolicyModel->select(['client_branch.id as branch_id','client_branch.branch_name','client_branch.branch_code', 'client_branch.client_id', 'client_policy.id as client_policy_id','p.name','pt.policy_type',])
+                                  ->join('client_branch', 'client_branch.id = client_policy.client_branch_id') 
                                   ->join('policies p', 'p.id = client_policy.policy_id') 
                                   ->join('policy_type pt','client_policy.policy_type_id = pt.id')
                                   ->where('client_policy.client_id',$client['id'])
@@ -50,6 +52,13 @@ class ClientModel extends Model
                                   ->findAll();
 
                 $client['policies'] = $clientPolicies; 
+
+                $clientBranchModel = new ClientBranchModel();
+                $clientBranchs = $clientBranchModel->select(['client_branch.id','client_branch.branch_name','client_branch.branch_code', 'client_branch.client_id'])
+                                  ->where('client_branch.client_id',$client['id'])
+                                  ->findAll();
+
+                $client['branchs'] = $clientBranchs; 
             }
             //print_r(($clients));die();
             return $clients;
diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php
index 7ec30755..b5c5222c 100644
--- a/app/Models/EmployeeModel.php
+++ b/app/Models/EmployeeModel.php
@@ -37,7 +37,8 @@ class EmployeeModel extends Model
         "is_active",
         "file_id",
         "is_addon_value",
-        "is_createdby_hr"
+        "is_createdby_hr",
+        "client_branch_id"
     ];
 
       // Callbacks
diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php
index 217e2013..b422ccfe 100644
--- a/app/Models/EmployeePolicyModel.php
+++ b/app/Models/EmployeePolicyModel.php
@@ -76,7 +76,7 @@ class EmployeePolicyModel extends Model
     }
 
 // -----------------------------------------------------------------------------------------------------
-   public function getEmployeePolicy($client_id,$policy_id,$status)
+   public function getEmployeePolicy($client_id,$policy_id,$status, $branch_id)
    {
         $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','emp.mobile as mobile'])
                         ->join('employees emp', 'employee_polices.employee_id = emp.id') 
@@ -88,6 +88,7 @@ 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('emp.client_branch_id',$branch_id)
                         ->where('employee_polices.is_active',1)
                         ->where('emp.is_active',1)
                         ->where('employee_polices.client_policy_id',$policy_id)
@@ -592,7 +593,7 @@ class EmployeePolicyModel extends Model
     }
 
 
-    public function getEmployeeEndorsementList($client_id, $policy_id, $status)
+    public function getEmployeeEndorsementList($client_id, $policy_id, $status, $branch_id)
     {   
         $query1 = $this->db->table('emp_endorsement e');
         $query1->select('
@@ -609,14 +610,15 @@ class EmployeePolicyModel extends Model
                     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->join('employee_polices ep', 'ep.id = e.pk');
+                $query1->join('employees', 'employees.id = ep.employee_id');
+                $query1->join('client_policy', 'client_policy.id = ep.client_policy_id');
+                $query1->join('policies', 'policies.id = client_policy.policy_id');
+                $query1->join('insurers', 'insurers.id = policies.insurer_id');
                 $query1->whereIn('e.actions', ['c']);
-                $query1->where('ep.client_policy_id', $client_id);
-                $query1->where('employees.client_id', $policy_id);
+                $query1->where('ep.client_policy_id', $policy_id);
+                $query1->where('employees.client_id', $client_id);
+                $query1->where('employees.client_branch_id', $branch_id);
                 if($status != 0 && !empty($status)){
 
                     $query1->where('e.status', $status);
@@ -640,14 +642,15 @@ class EmployeePolicyModel extends Model
                     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->join('employee_polices ep', 'ep.id = e.pk');
+                $query2->join('employees', 'employees.id = ep.employee_id');
+                $query2->join('client_policy', 'client_policy.id = ep.client_policy_id');
+                $query2->join('policies', 'policies.id = client_policy.policy_id');
+                $query2->join('insurers', 'insurers.id = policies.insurer_id');
                 $query2->whereIn('e.actions', ['si', 'd']);
-                $query2->where('ep.client_policy_id', $client_id);
+                $query2->where('ep.client_policy_id', $policy_id);
                 $query2->where('employees.client_id', $policy_id);
+                $query1->where('employees.client_branch_id', $branch_id);
                 if($status != 0 && !empty($status)){
 
                     $query2->where('e.status', $status);
diff --git a/app/Models/FileModel.php b/app/Models/FileModel.php
index aefbb419..51f397ec 100644
--- a/app/Models/FileModel.php
+++ b/app/Models/FileModel.php
@@ -17,7 +17,8 @@ class FileModel extends Model
         "reason",
         "action",
         "client_id",
-        "policy_id"
+        "policy_id",
+        "client_branch_id",
     ];
 
 
diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php
index 9e73bbd1..04b52ec6 100644
--- a/app/Views/batch_list.php
+++ b/app/Views/batch_list.php
@@ -25,6 +25,7 @@
                             Batch 
Code File Name Client + Client
Branch Client Policy Event
Type Insurer/
TPA @@ -50,6 +51,7 @@ 5 ? substr($file['file_name'], 0, 10) . "..." : $file['file_name'] ?> + diff --git a/app/Views/employee_list.php b/app/Views/employee_list.php index 22db6b78..a9148742 100644 --- a/app/Views/employee_list.php +++ b/app/Views/employee_list.php @@ -29,6 +29,15 @@ table.dataTable tbody td { + + +
+
+ +
+

@@ -80,6 +89,7 @@ $(document).ready(function() { // Initialize select2 $("#clients").select2(); $("#policies").select2(); + $("#branch_id").select2(); // if ($('.select2-selection__arrow').length > 0) { // $('.select2-selection__arrow').removeClass('select2-selection__arrow').addClass('fa fa-chevron-down'); @@ -88,7 +98,12 @@ $(document).ready(function() { // Declare a global variable to store API response data var clientPolicies = []; +var clientPoliciesWithBranch = { + policies: [] +}; var client_id = ''; +var client_branch_id = ''; + $(document).ready(function() { @@ -122,6 +137,14 @@ function fetchClientPolicies() { if (response.code === 200 && response.dataStatus === true && response.data !== "") { try { clientPolicies = (response.data); + + response.data.forEach(policy => { + console.log('policies', policy.policies); + policy.policies.forEach(p => { + clientPoliciesWithBranch.policies.push(p); + }); + }); + console.log('1',clientPolicies); appendClients(clientPolicies); @@ -132,7 +155,24 @@ function fetchClientPolicies() { console.log(typeof item.id) return item.id == client_id; }); - appendPolicies(foundPolicies.policies); + appendBranch(foundPolicies.branchs); + } + }, 500); + + setTimeout(function() { + if (client_branch_id != 0 ) { + + var foundPolicies = clientPoliciesWithBranch.policies.filter(function(item) { + console.log('item', item); + return item.branch_id === client_branch_id; + }); + + if (foundPolicies) { + console.log('foundPolicies', foundPolicies); + appendPolicies(foundPolicies); + } else { + console.log('No policies found for the selected client'); + } } }, 500); //end @@ -170,6 +210,26 @@ function appendClients(data) { } +function appendBranch(data) { + + $('#branch_id').empty(); + $('#branch_id').append($('
+
+
+ +
+

+ + +
+

+ +
+
+ +
+

- $value) { ?> - + $value) { ?> +
@@ -59,9 +64,7 @@ table.dataTable tbody td {
@@ -84,8 +87,7 @@ table.dataTable tbody td { - +
@@ -101,47 +103,45 @@ table.dataTable tbody td { - $employee) { ?> + $employee) { ?> - - - - - - - - - - - - + + + + + + + + + + + +
SNO
( ) - - - - ' . $employee['status'] . ''; - } elseif ($employee['status'] == 'inprogress') { - echo '' . $employee['status'] . ''; - } elseif ($employee['status'] == 'complete') { - echo '' . $employee['status'] . ''; - } - ?> - -
( ) + + + + ' . $employee['status'] . ''; + } elseif ($employee['status'] == 'inprogress') { + echo '' . $employee['status'] . ''; + } elseif ($employee['status'] == 'complete') { + echo '' . $employee['status'] . ''; + } + ?> + +
@@ -153,7 +153,7 @@ table.dataTable tbody td { -