diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 9dce6e34..e0a709a7 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -346,7 +346,6 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { -// $routes->post("getChatResponse", "ChatBotController::getChatResponse"); $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->post("storeFireBase", "EmployeeRestController::storeFireBase"); $routes->post("saveMpin", "RestAuthenticationController::saveMpin"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index ce19ba1e..ed934ed8 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -27,6 +27,7 @@ use App\Models\NotificationModel; use App\Models\UserModel; use App\Models\FEContentModel; use App\Models\AddImgModel; +use App\Models\ClientBranchModel; use App\Controllers\Jobs ; @@ -69,6 +70,8 @@ class EmployeeRestController extends AdminController protected $userModel; protected $feContentModel; protected $addImgModel; + protected $clientBranchModel; + public function __construct() { @@ -90,6 +93,7 @@ class EmployeeRestController extends AdminController $this->userModel = new UserModel(); $this->feContentModel = new FEContentModel(); $this->addImgModel = new AddImgModel(); + $this->clientBranchModel = new ClientBranchModel(); } @@ -208,7 +212,7 @@ class EmployeeRestController extends AdminController public function addEmployeeAndDependence() { - try { + // try { $data = $this->request->getJSON(); @@ -216,6 +220,7 @@ class EmployeeRestController extends AdminController $Count = 0; foreach ($data as $item) { + if (isset($item->id)) { //update old data $id = $item->id; @@ -233,6 +238,8 @@ class EmployeeRestController extends AdminController $item->gender = $this->GenderMap($item->relationship , $item->emp_code); $item->dob = $this->convertDateFormatYMD($item->dob); $item->emp_status = 'draft'; + + $employee = $this->employeeModel->insert($item); if ($employee) { @@ -266,7 +273,7 @@ class EmployeeRestController extends AdminController - $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code); + $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code , $data[0]->client_branch_id); $result = []; @@ -276,9 +283,9 @@ class EmployeeRestController extends AdminController return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 404); } } - } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); - } + // } catch (\Exception $e) { + // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + // } } @@ -317,9 +324,9 @@ class EmployeeRestController extends AdminController return true; } - public function updatePremiumAmount($client_policy_id , $emp_code) + public function updatePremiumAmount($client_policy_id , $emp_code , $client_branch_id) { - $response = $this->calculatePremium($client_policy_id , $emp_code); + $response = $this->calculatePremium($client_policy_id , $emp_code , null , $client_branch_id); if(count($response[$emp_code])) { @@ -1935,12 +1942,13 @@ class EmployeeRestController extends AdminController //Post method - which receives client_policy id and empcode of the family. //Pull records againest emp code and calculate premium // retun array - public function calculatePremium($clientPolicyId = null , $empCode = null, $default_si = null)//family level + public function calculatePremium($clientPolicyId = null , $empCode = null, $default_si = null , $client_branch_id = null)//family level { helper('excel_util_helper'); $client_policy_id = $this->request->getVar('client_policy_id') ?? $clientPolicyId; $emp_code = $this->request->getVar('emp_code') ?? $empCode; $default_si = $this->request->getVar('si') ?? $default_si;// si amt which choosed in add on policy + // dd($client_policy_id); @@ -1969,13 +1977,17 @@ class EmployeeRestController extends AdminController // dd($this->employeeModel->getLastQuery()); // print_r($existing_famility_details);die(); $employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db'); - // print_r(($employee_data_group_by_family));die(); + // print_r(($employee_data_group_by_family));//die(); + + + $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $client_id,client_branch_id: $client_branch_id); + foreach ($employee_data_group_by_family as $emp_id => $family) { $transformed_famility_details = transform_db_data_to_excel($family); - // print_r($transformed_famility_details);die(); - $data = calculate_premium($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si); - // dd($data); + + $data = calculate_premium_new(family_data: $transformed_famility_details,policy_terms:$policy_terms,slab_details:$slab_details,fileArr: $file,existing_units: $existing_units,default_si : $default_si); + $employee_data_group_by_family[$emp_id] = $data; } diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 62b17cea..77ba13b0 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -924,7 +924,19 @@ if (!function_exists('calculate_premium_new')) $is_self_acting_self_set = true; } - $family_data[$val]['temp'] = ['max_age' => max($applicable_members_from_familiy['max_age']),'max_count' => $applicable_members_from_familiy['max_count'],'grid_name' => $key,'grid_master' => $slab['grid_master'],'acting_self' => $acting_self,'premium_type' => $slab['slab_rates'][0]['premium_type']]; + //$family_data[$val]['temp'] = ['max_age' => max($applicable_members_from_familiy['max_age']),'max_count' => $applicable_members_from_familiy['max_count'],'grid_name' => $key,'grid_master' => $slab['grid_master'],'acting_self' => $acting_self,'premium_type' => $slab['slab_rates'][0]['premium_type']]; + $family_data[$val]['temp'] = array_merge( + $family_data[$val]['temp'] ?? [], // existing 'temp' data or an empty array if it doesn't exist + [ + 'max_age' => max($applicable_members_from_familiy['max_age']), + 'max_count' => $applicable_members_from_familiy['max_count'], + 'grid_name' => $key, + 'grid_master' => $slab['grid_master'], + 'acting_self' => $acting_self, + 'premium_type' => $slab['slab_rates'][0]['premium_type'] + ] + ); + } } else @@ -999,7 +1011,6 @@ if (!function_exists('transform_excel_data_to_db')) { function transform_excel_data_to_db($memArr,$actionArr) { - $current_column_action = null; if($actionArr['action'] == 'inception'){ $current_column_action = 'I'; } else if($actionArr['action'] == 'addition'){ $current_column_action = 'A'; }