From 71bae2149c50470d432d892ac78a74666abc1387 Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 30 Jul 2024 11:37:05 +0530 Subject: [PATCH] FEAT_TEST_RACK_RATE_UI --- app/Config/Routes.php | 1 + app/Controllers/EmployeeController.php | 106 ++++- app/Controllers/EmployeeServiceController.php | 2 +- app/Helpers/excel_util_helper.php | 2 +- app/Models/ClientModel.php | 2 +- app/Views/rack_rate_test.php | 405 ++++++++++++++++-- tests/unit/PremiumCalculationTestNew.php | 2 +- 7 files changed, 469 insertions(+), 51 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 80babc57..a0106507 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -146,6 +146,7 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { $routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1"); $routes->get("test-rack-rate", "EmployeeController::testRackRate"); $routes->post("test-rack-rate", "EmployeeController::testRackRate"); + $routes->post("test-dependent", "EmployeeController::testCheckDependentConflict"); }); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 42bd37bd..a347a929 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -1507,6 +1507,7 @@ class EmployeeController extends AdminController public function testRackRate() { + helper('excel_util_helper'); if ($this->request->getMethod() == 'get') { $filterData = $this->request->getGet('client_policy_id'); //just load UI only @@ -1557,26 +1558,99 @@ class EmployeeController extends AdminController } // print_r($family_details); - return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $family_details], 200); + // return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $family_details], 200); //get policy details - $policy_details = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']); + $policy_details = $this->clientPolicyModel->getPolicyDetails($client_id,$policy_id); + $policy_details = (array)$policy_details[0]; + // ~dd($policy_details[0]->policy_start_date); //get rack rates - $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); + $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($policy_id,$client_id); //get file array or construnct dummy file array here - $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception','client_branch_id' => 1,'created_by' => 1]; + $file = ['id' => null,'client_id' => $client_id,'policy_id' => $policy_id,'action' => 'inception','client_branch_id' => $branch_id,'created_by' => 1]; + //get existing units in the current branch + $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $client_id,client_branch_id: $branch_id); //get familiy details in inception file format array from post method - $family_details = [ - [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', NULL, '', '', 'G', '', '', '', '', '', '',''], - [1,'TEST001','Jane Doe', '01-Jan-1985', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', '0', '', '', ''], - - // [3,'TEST001','Peter Doe', '01-Jan-1955', 'M', 'Father', '', NULL, '', '', '', '', '', '', '', '', '',''], - [4,'TEST001','Mary Doe', '01-Jan-1953', 'F', 'Mother', '', NULL, '', '', '', '', '', '', '', '', '',''], - [5,'TEST001','Grace Doe', '01-Jan-1954', 'F', 'Mother in law', '', NULL, '', '', '', '', '', '', '', '', '',''], - //[6,'TEST001','George Doe', '01-Jan-1948', 'M', 'Father in law', '', NULL, '', '', '', '', '', '', '', '', '',''], - [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', '',''], - [6,'TEST001','Bob Doe', '01-Jan-1993', 'M', 'son', '50000', NULL, '', '', '', '', '', '', '', '', '',''], - ]; - $data = calculate_premimum_new($family_details,$policy_details,$all_rack_rates,$file); + $data = calculate_premium_new(family_data: $family_details,policy_terms:$policy_details,slab_details:$slab_details,fileArr: $file,existing_units: $existing_units); + + foreach($data as $key => $member ) + { + // ~dd($member); + $data[$key]['policy_details']['no_of_days'] = $member['policy_details']['date_coverage'] ? (calculate_days_bw_dates($member['policy_details']['date_coverage'],$member['policy_details']['policy_end_date'])->days + 1) : ''; + } + + return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $data], 200); + } + } + + + public function testCheckDependentConflict() + { + helper('excel_util_helper'); + if ($this->request->getMethod() == 'get') { + $filterData = $this->request->getGet('client_policy_id'); + //just load UI only + $this->loadLayout('rack_rate_test'); + } + + + if ($this->request->getMethod() == 'post') { + $json = $this->request->getJSON(); + // return $this->respond(['dataStatus' => false, 'code' => 200, 'data' => $data], 200); + // $data = (json_decode(json_encode($data),true)); + $client_id = $json->client_id; + $policy_id = $json->policy_id; + $branch_id = $json->branch_id; + $tabledata = $json->data; + + if(count($tabledata)) + { + $family_details = []; + foreach($tabledata as $key => $row) + { + $row = (array)$row; + if(!$row['column12']) + { + + $temp[0] = $row['column1'];//sno + $temp[1] = $row['column2'];//emp code + $temp[2] = $row['column3'];//name + $temp[3] = $row['column4'];//DOB + $temp[4] = strtoupper($row['column5']);//Gender + $temp[5] = $row['column6'];//relation + $temp[6] = $row['column7'];//SI + $temp[7] = $row['column8'];//DOC + $temp[8] = '';//DOJ + $temp[9] = $row['column9'];//BP + $temp[10] = $row['column10'];//band + $temp[11] = '';//designation + $temp[12] = '';//mobile + $temp[13] = '';//EMail + $temp[14] = '';//CE + $temp[15] = '';//RFE + $temp[16] = '';//DOE + $temp[17] = '';//Unit + $temp[18] = $row['column11'];//unit + $family_details[] = $temp; + } + } + } + + // print_r($family_details); + // return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $family_details], 200); + //get policy details + $policy_details = $this->clientPolicyModel->getPolicyDetails($client_id,$policy_id); + $policy_terms = (array)$policy_details[0]; + // dd($policy_terms); + $policy_terms = json_decode($policy_terms['policy_terms']); + $policy_terms = (array) $policy_terms;// convert obj to array + + //get file array or construnct dummy file array here + $file = ['id' => null,'client_id' => $client_id,'policy_id' => $policy_id,'action' => 'inception','client_branch_id' => $branch_id,'created_by' => 1]; + //get familiy details in inception file format array from post method + $result = check_dependent_conflict($family_details, $policy_terms, $file['action']); + + + return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => ['policy_terms' => $policy_terms['family_floaters'],'result' => $result] ], 200); } } diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 4ddd51e6..4eea7b8f 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1273,7 +1273,7 @@ class EmployeeServiceController extends AdminController // die(); - return (($employee_data_group_by_family)); + return (count($employee_data_group_by_family)); } diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 4f81d9d3..de35a7e3 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -1008,7 +1008,7 @@ if (!function_exists('transform_excel_data_to_db')) // $policy['reason_for_exit'] = $memArr[17]; $policy['client_policy_id'] = $actionArr['policy_id']; - $policy['date_coverage'] = isset($memArr[7]) ? convert_string_to_date($memArr[7],'Y-m-d') : NULL; + $policy['date_coverage'] = isset($memArr[7]) && $memArr[7] != '' ? convert_string_to_date($memArr[7],'Y-m-d') : NULL; $policy['policy_end_date'] = null; $policy['days'] = null; $policy['premium'] = null; diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index a43c1812..b6101356 100644 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -82,7 +82,7 @@ class ClientModel extends Model $client['policies'] = $clientPolicies; $clientBranchModel = new ClientBranchModel(); - $clientBranchs = $clientBranchModel->select(['client_branch.id','client_branch.branch_name','client_branch.branch_code', 'client_branch.client_id']) + $clientBranchs = $clientBranchModel->select(['client_branch.id','client_branch.branch_name','client_branch.branch_code', 'client_branch.client_id','client_branch.units']) ->where('client_branch.client_id',$client['id']) ->findAll(); diff --git a/app/Views/rack_rate_test.php b/app/Views/rack_rate_test.php index 39fe5512..a144444a 100644 --- a/app/Views/rack_rate_test.php +++ b/app/Views/rack_rate_test.php @@ -46,7 +46,7 @@
-
+

+
+
+ +
-
+