From be69492e80503a35bb1b76066d6dd17ae798d700 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Thu, 6 Jun 2024 17:19:51 +0530 Subject: [PATCH 01/21] CHANGE_OAUTH_ISSUE : AADHAVAN --- app/Controllers/UserController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 184cbefa..f654dc40 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -71,7 +71,8 @@ class UserController extends AdminController $admin = 0; } foreach ($temp_team as $key => $value) { - if($value == 2){ + $team = $this->teamModel->where('id' , $value)->first(); + if($team['name'] == 'Claims'){ $hdz_staff = [ 'emp_code' => $userData['emp_code'], 'fullname' => $userData['first_name'], From 1a5e6daaf899d2c77d2aebf3f15b7518a84d3e7f Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Fri, 28 Jun 2024 17:02:06 +0530 Subject: [PATCH 02/21] CHANGE_ADVERTISEMENT_JWT_CHANGE: AADHAVAN --- app/Config/Routes.php | 8 + .../AppContentManagementController.php | 96 ++++++++ app/Controllers/EmployeeRestController.php | 29 +-- app/Filters/AuthJWT.php | 50 +++-- app/Helpers/JWTToken.php | 14 +- app/Views/add_image_list.php | 210 ++++++++++++++++++ app/Views/layout/header.php | 29 +++ 7 files changed, 393 insertions(+), 43 deletions(-) create mode 100644 app/Controllers/AppContentManagementController.php create mode 100644 app/Views/add_image_list.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7917751a..402721b0 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -10,8 +10,16 @@ use CodeIgniter\Router\RouteCollection; $routes->get('/swagger', 'SwaggerController::index', ['filter' => 'authMVC']); // Reminder Mail Notification + $routes->get("reminder_mail", "NotificationController::reminder_mail"); + +$routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); +$routes->get("add_image_index", "AppContentManagementController::add_image_index"); +$routes->get("getAdvertiseImage/(:any)", "AppContentManagementController::getAdvertiseImage/$1"); +$routes->get("frontend_content", "AppContentManagementController::frontend_content"); + + // $routes->get('/', 'LoginController::index'); $routes->get('/test', 'Home::index'); $routes->get('/login', 'LoginController::index'); ///auth/google diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php new file mode 100644 index 00000000..300036be --- /dev/null +++ b/app/Controllers/AppContentManagementController.php @@ -0,0 +1,96 @@ +myLogger = \Config\Services::mylogger(); + $this->addImgModel = new AddImgModel(); + $this->feContentModel = new FEContentModel(); + } + public function add_image_index() + { + $this->myLogger->logme('error','Addvertisement Image list function called'); + $headerData['page_name'] = 'Addvertisement Image List'; + $data['addImageList'] = $this->addImgModel->findAll(); + + // dd($data); + + echo view('layout/header', $headerData); + echo view('add_image_list', $data); + echo view('layout/footer'); + + // $this->loadLayout('client_onboarding', $data); + } + + public function add_advertise_image(){ + + // print_r($this->request->getPost());die; + $uploadFilePath = ROOTPATH . 'public/uploads/advertiseImage/'; + $file_name = file_Upload($this->request->getFile('advertise_image'), $uploadFilePath); + $data['id'] = $this->request->getPost('add_image_id'); + // $data['created_by'] = get_session_userid(); + $data['name'] = $file_name; + + if($data['id'] == 0){ + $insert = $this->addImgModel->insert($data); + if($insert){ + return $this->respond(['status' => true,'code' => 200,'data' => "success"], 200); + + }else{ + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); + + } + }else{ + $id = $data['id']; + $update = $this->addImgModel->update($id,$data); + if($update){ + return $this->respond(['status' => true,'code' => 200,'data' => "success"], 200); + + }else{ + return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200); + } + } + } + + public function getAdvertiseImage($image_id){ + + $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first(); + + if($image_data){ + return $image_data['name']; + }else{ + return ; + } + } + + + + // Front End Content Area + public function frontend_content(){ + + $data['test'] = $this->feContentModel->findAll(); + $headerData['page_name'] = 'Front-End Content'; + + echo view('layout/header', $headerData); + echo view('frontend_content_list', $data); + echo view('layout/footer'); + } + +} \ No newline at end of file diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index a14aac42..ef41e1b2 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -622,13 +622,7 @@ class EmployeeRestController extends AdminController // Upload the Employee Detail in DB by Sheet Data public function employeeUpload() { - - - - try { - // echo $this->request->getPost('client_id'); - // die; $file = $this->request->getFile('file'); $client_id = $this->request->getPost('client_id'); $client_branch_id = $this->request->getPost('client_branch_id'); @@ -639,17 +633,12 @@ class EmployeeRestController extends AdminController $jwt = $this->request->getHeader('Authorization'); $jwtParts = explode(' ', $jwt); - // print_r($jwtParts);die; - $token = $jwtParts[2]; - // return "hello"; - + $token = $jwtParts[2]; + $decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true); // get the employee id from token $employee_id = $decodedPayload['id']; - - - $client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->where('client_branch_id', $client_branch_id)->first(); if ($client_policy) { $policy = $this->policesModel->where('id', $client_policy['policy_id'])->first(); @@ -701,13 +690,13 @@ class EmployeeRestController extends AdminController $check_miss_match[]=$data[0][$i]; } } - if (count($check_miss_match) > 0) { return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Column Name's are miss Match's!", 'data'=> $check_miss_match], 200); } } if(count($data[0]) != 11){ + return json_encode($data[0]); return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Uploaded file row count is Not Match!" ], 200); } @@ -734,18 +723,6 @@ class EmployeeRestController extends AdminController } $dataToInsert = []; $basic_cover_si= []; - // if ($extra[9]) { - // $new_array = []; - // for ($i=0; $i < count($extra[9]); $i++) { - // if ($sum_insured_amount_for_check_employee_2 != $extra[9][$i] || $sum_insured_amount_for_check_employee_1 != $extra[9][$i]) { - // $new_array[] = $i+1; - // } - // } - // if (count($new_array) > 0) { - // $count =count($new_array); - // return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "$count Employee Sum Insured is Not Match.. " , 'data' => $new_array], 200); - // } - // } foreach ($extra['0'] as $index => $id) { $relation =''; if ($extra['5'][$index] === 'Mother' || $extra['5'][$index] === 'Father') { diff --git a/app/Filters/AuthJWT.php b/app/Filters/AuthJWT.php index 193ad6ec..b64a2a76 100644 --- a/app/Filters/AuthJWT.php +++ b/app/Filters/AuthJWT.php @@ -13,6 +13,7 @@ use ReflectionClass; require_once('../vendor/autoload.php'); use App\Models\EmployeeModel; +use App\Models\LevelContactModel; class AuthJWT implements FilterInterface @@ -20,7 +21,6 @@ class AuthJWT implements FilterInterface public function before(RequestInterface $request, $arguments = null) { $jwt = $request->getHeader('Authorization'); - $model = new EmployeeModel(); if ($jwt) { if (JWTToken::validateJWT($jwt)) { @@ -28,22 +28,44 @@ class AuthJWT implements FilterInterface $data = json_decode($data); $id = $data->decoded->id; - $user_data = $model->where('id', $id)->first(); + if(isset($data->decoded->emp_code)){ + $model = new EmployeeModel(); + $user_data = $model->where('id', $id)->first(); - if($user_data['token_time_out'] > time()){ - $data =["token_time_out" => time() + getenv('TOKENTIMEOUT') ]; - $model->update($id, $data); - return true; + if($user_data['token_time_out'] > time()){ + $data =["token_time_out" => time() + getenv('TOKENTIMEOUT') ]; + $model->update($id, $data); + return true; + }else{ + $data =["token_time_out" => '']; + $model->update($id, $data); + header('Content-Type: application/json'); + http_response_code(401); + // $error = json_encode(["status" => 401, "message" => $data->message]); + $error = json_encode(["status" => 401, "message" => "Token is Invalid"]); + echo $error; + exit; + } }else{ - $data =["token_time_out" => '']; - $model->update($id, $data); - header('Content-Type: application/json'); - http_response_code(401); - // $error = json_encode(["status" => 401, "message" => $data->message]); - $error = json_encode(["status" => 401, "message" => "Token is Invalid"]); - echo $error; - exit; + $model = new LevelContactModel(); + $hr_data = $model->where('id', $id)->first(); + + if($hr_data['token_time_out'] > time()){ + $data =["token_time_out" => time() + getenv('TOKENTIMEOUT') ]; + $model->update($id, $data); + return true; + }else{ + $data =["token_time_out" => '']; + $model->update($id, $data); + header('Content-Type: application/json'); + http_response_code(401); + // $error = json_encode(["status" => 401, "message" => $data->message]); + $error = json_encode(["status" => 401, "message" => "Token is Invalid"]); + echo $error; + exit; + } } + } } else { header('Content-Type: application/json'); diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php index 592c38f8..5e351c5e 100644 --- a/app/Helpers/JWTToken.php +++ b/app/Helpers/JWTToken.php @@ -13,6 +13,7 @@ use CodeIgniter\HTTP\RequestInterface; use ReflectionClass; use App\Models\EmployeeModel; +use App\Models\LevelContactModel; class JWTToken @@ -25,13 +26,20 @@ class JWTToken try{ $token = JWT::encode($request_data ,$secret_Key,'HS512'); - - $model = new EmployeeModel(); $id = $request_data['id']; $data =[ "token_time_out" => time() + getenv('TOKENTIMEOUT') ]; - $model->update($id, $data); + if(isset($data['emp_code'])){ + $model = new EmployeeModel(); + $model->update($id, $data); + + }else{ + $models = new LevelContactModel(); + $models->update($id, $data); + + } + return $token; } diff --git a/app/Views/add_image_list.php b/app/Views/add_image_list.php new file mode 100644 index 00000000..9658053d --- /dev/null +++ b/app/Views/add_image_list.php @@ -0,0 +1,210 @@ + + +
+
+
+
+
+
+

Advertisement Image List

+
+
+ ADD +
+
+ + + + + + + + + + + + + + + + + + + + +
Advertisement Image NameStatusAction
+ + + +
+
+
+
+
+ + + +
+ + + + + \ No newline at end of file diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 9c6a4795..8461b8ec 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -40,6 +40,7 @@ + /assets/css/jodit.css" rel="stylesheet" type="text/css" /> @@ -69,6 +70,8 @@ } + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ /assets/images/nhance-loader-fast.gif" height="40" width="40" alt="Loading..."> +
+
+ + + +
+ + + + + + +
+ + + + + +
+ + + + + +
+ + +
+ + + + + + +
+
+ + +
\ No newline at end of file From 4e88c48b659d80818b265e3a27409728d9516db6 Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 2 Jul 2024 09:37:11 +0530 Subject: [PATCH 08/21] FIX_CLIENT_UPLOAD_ISSUE --- app/Controllers/EmployeeRestController.php | 52 +++++++++---------- app/Controllers/EmployeeServiceController.php | 3 +- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 2539b119..10aac50d 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -656,7 +656,7 @@ class EmployeeRestController extends AdminController $file_name_with_path = WRITEPATH."/uploads/excel/".$filename; //make an entry in DB - $file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => 'enrollment', 'client_branch_id' => $client_branch_id]); //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' => $employee_id, 'status' => 'draft', 'action' => 'enrollment', 'client_branch_id' => $client_branch_id]); //here field policy_id have client_policy_id and not policy id from policy master $this->myLogger->logme("error", '{file_id} - client uploaded success', ['file_id' => $file_id]); $empServiceController = new EmployeeServiceController(); @@ -689,34 +689,34 @@ class EmployeeRestController extends AdminController $highestRowAndColumn = $sheet->getHighestRowAndColumn(); $data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); - $extractData['file_name']= $filename; - $extractData['client_id']= $client_id; - $extractData['client_branch_id']= $client_branch_id; - $extractData['status']= 'success'; - $extractData['policy_id']= $policy_id; - $extractData['action']= 'enrollment'; - $extractData['created_by']=$employee_id; + // $extractData['file_name']= $filename; + // $extractData['client_id']= $client_id; + // $extractData['client_branch_id']= $client_branch_id; + // $extractData['status']= 'success'; + // $extractData['policy_id']= $policy_id; + // $extractData['action']= 'enrollment'; + // $extractData['created_by']=$employee_id; - $file_data =$this->fileModel->insert($extractData); + // $file_data =$this->fileModel->insert($extractData); - $extra = []; - if (count($data[0]) == 11) { - $value = ['Sno','Emp_Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI','Grade']; - $check_miss_match = []; - for ($i=0; $i 0) { - return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Column Name's are miss Match's!", 'data'=> $check_miss_match], 200); - } - } + // $extra = []; + // if (count($data[0]) == 11) { + // $value = ['Sno','Emp_Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI','Grade']; + // $check_miss_match = []; + // for ($i=0; $i 0) { + // return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Column Name's are miss Match's!", 'data'=> $check_miss_match], 200); + // } + // } - if(count($data[0]) != 11){ - return json_encode($data[0]); - return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Uploaded file row count is Not Match!" ], 200); - } + // if(count($data[0]) != 11){ + // return json_encode($data[0]); + // return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Uploaded file row count is Not Match!" ], 200); + // } //this change the column name into index number for ($i = 0; $i < count($data[0]); $i++) { diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index d5b65670..9ba53688 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -987,8 +987,7 @@ class EmployeeServiceController extends AdminController } } - //check self availbale in uploaded file - if(($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'enrollment') || ($policy_details['policy_type_id'] == 3 && $is_self_available_in_policy_terms)) // 3 is GMC parents dep addon) + if(($policy_details['base_policy'] == null && ($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'enrollment')) || ($policy_details['policy_type_id'] == 3 && $is_self_available_in_policy_terms)) // 3 is GMC parents dep addon) { $res = check_self_available_in_family($family,$file['action']); if(!$res['is_self_found']) From 60e3ed3e9ff771b8afbeece4a981cddc19305cdb Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 2 Jul 2024 20:07:02 +0530 Subject: [PATCH 09/21] FIX_PRIMARY_ACTING_SELF_INTRODUCED --- app/Helpers/excel_util_helper.php | 38 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index a3e4369d..21be120d 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -787,6 +787,22 @@ if (!function_exists('calculate_premimum')) } } + //set primary_rack_rate_acting_self in emp_details_with_empband_max_age_max_count array for policies where self not available and premium type is 1 (i.e.) GMC parents as dep addon policy + $transformed_familiy_member_data['temp']['primary_rack_rate_acting_self'] = false; + if(!isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['primary_rack_rate_acting_self']) && $current_grid_info['type'] == 'primary') + { + if(strtolower($transformed_familiy_member_data['relationship']) == 'self') + { + $transformed_familiy_member_data['temp']['primary_rack_rate_acting_self'] = true; + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['primary_rack_rate_acting_self'] = true; + } + else + { + $transformed_familiy_member_data['temp']['primary_rack_rate_acting_self'] = true; + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['primary_rack_rate_acting_self'] = true; + } + } + //generate relationship code if($transformed_familiy_member_data['temp']['action'] != 'D' && $transformed_familiy_member_data['temp']['action'] != 'C' && $transformed_familiy_member_data['temp']['action'] != 'SI') { @@ -1013,7 +1029,7 @@ if (!function_exists('premium_calculation_manager')) $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1036,7 +1052,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { // dd($slab_value); $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1057,7 +1073,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1077,7 +1093,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { // echo $emp_data['name']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1099,7 +1115,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1121,7 +1137,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1143,7 +1159,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self'])) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self'])) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1170,7 +1186,7 @@ if (!function_exists('premium_calculation_manager')) if( $slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) && (($slab_value['premium_type'] == 1 && - ( (strtolower($emp_data['relationship']) == 'self') || ($emp_data['temp']['additional_rack_rate_acting_self']) )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ) ) + ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self'])) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; $emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']; @@ -1195,7 +1211,7 @@ if (!function_exists('premium_calculation_manager')) { if($slab_value['si'] == $employee_received_si && $slab_value['grade'] == $employee_received_band && (($slab_value['premium_type'] == 1 && - ( (strtolower($emp_data['relationship']) == 'self') || ($emp_data['temp']['additional_rack_rate_acting_self']) )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self'])) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { //calculate premium based on count // echo $emp_data['name']; @@ -1224,7 +1240,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['basic_cover_si'] = null; foreach ($temp_slab_rates as $skey => $slab_value) { - if( $slab_value['si'] == $employee_received_si && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self'] ) )) ) + if( $slab_value['si'] == $employee_received_si && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) )) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; @@ -1249,7 +1265,7 @@ if (!function_exists('premium_calculation_manager')) $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; foreach ($temp_slab_rates as $skey => $slab_value) { - if( $slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) )) ) + if( $slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) )) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; From 6ff39c7f61785086a1b071f88df0d7acf65b262a Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Wed, 3 Jul 2024 14:44:31 +0530 Subject: [PATCH 10/21] FIX_CLIENT_POLICY_CD_NO_ISSUE_AND_OTHERS : RV --- app/Config/Routes.php | 1 + app/Controllers/ClientController.php | 61 ++- app/Helpers/DepositHelper.php | 4 +- app/Helpers/excel_import_export_helper.php | 443 ++++++++++++++++++++- app/Models/ClientPolicyModel.php | 1 + app/Views/client_policy.php | 115 +++--- app/Views/file_list.php | 3 + app/Views/policy_gmc_terms.php | 127 +++--- app/Views/policy_grid.php | 33 +- app/Views/policy_grid_excel.php | 5 +- 10 files changed, 646 insertions(+), 147 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ba34cea6..b2bdee0f 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -249,6 +249,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("getPolicyTerms/(:any)", "ClientController::getPolicyTerms/$1"); $routes->get("getPolicyTermsFormJson/(:any)", "ClientController::getPolicyTermsFormJson/$1"); $routes->get("checkHRNumber/(:any)", "ClientController::checkHRNumber/$1"); + $routes->get("check_addition_premium_JSON/(:any)", "ClientController::checkAdditionPremiumJSON/$1"); }); $routes->cli('cli/processjob', 'JobWorker::processJob'); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 185ff9ce..dc80cc4b 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -669,28 +669,28 @@ class ClientController extends AdminController $policy_terms = $this->clientPolicyModel->where('id', $this->request->getPost('base_policy'))->first(); - if ($this->request->getPost('is_addon') == 2 || $this->request->getPost('is_addon') == 3) { + // if ($this->request->getPost('is_addon') == 2 || $this->request->getPost('is_addon') == 3) { - if ($this->request->getPost('is_addon') == 3) { - $policyTerm = $policy_terms['policy_terms']; - $decoded_policyTerm = json_decode($policyTerm, true); - $decoded_policyTerm['family_floater'] = 0; - $decoded_policyTerm['family_floaters']['self'] = 0; - $decoded_policyTerm['family_floaters']['spouse'] = 0; - $decoded_policyTerm['family_floaters']['childrens'] = 0; - $decoded_policyTerm['family_floaters']['parents'] = 0; - $decoded_policyTerm['family_floaters']['parents-in-law'] = 0; - $decoded_policyTerm['family_floaters']['either-parents-pil'] = 0; + // if ($this->request->getPost('is_addon') == 3) { + // $policyTerm = $policy_terms['policy_terms']; + // $decoded_policyTerm = json_decode($policyTerm, true); + // $decoded_policyTerm['family_floater'] = 0; + // $decoded_policyTerm['family_floaters']['self'] = 0; + // $decoded_policyTerm['family_floaters']['spouse'] = 0; + // $decoded_policyTerm['family_floaters']['childrens'] = 0; + // $decoded_policyTerm['family_floaters']['parents'] = 0; + // $decoded_policyTerm['family_floaters']['parents-in-law'] = 0; + // $decoded_policyTerm['family_floaters']['either-parents-pil'] = 0; - $data['policy_terms'] = json_encode($decoded_policyTerm); - } else { + // $data['policy_terms'] = json_encode($decoded_policyTerm); + // } else { - if ($this->request->getPost('policy_type_id') != 3) { + // if ($this->request->getPost('policy_type_id') != 3) { - $data['policy_terms'] = $policy_terms['policy_terms']; - } - } - } + // $data['policy_terms'] = $policy_terms['policy_terms']; + // } + // } + // } $data['policy_no'] = $this->request->getPost('policy_no'); @@ -1416,9 +1416,9 @@ class ClientController extends AdminController $data['family_floaters']['parents-in-law'] =2; $data['family_floaters']['either-parents-pil'] =0; }else if($temp_family_floaters[$value] == '2EPORPIL'){ - $data['family_floaters']['parents'] =1; - $data['family_floaters']['parents-in-law'] =1; - $data['family_floaters']['either-parents-pil'] =0; + $data['family_floaters']['parents'] =0; + $data['family_floaters']['parents-in-law'] =0; + $data['family_floaters']['either-parents-pil'] =2; }else if($temp_family_floaters[$value] == 'EPORPIL'){ $data['family_floaters']['parents'] =0; $data['family_floaters']['parents-in-law'] =0; @@ -1514,6 +1514,7 @@ class ClientController extends AdminController $record = $this->clientPolicyModel->where('id', $client_policy_id)->first(); + // print_r($data);die; if ($record) { $update = $this->clientPolicyModel->update($client_policy_id, $dataa); @@ -2174,7 +2175,11 @@ class ClientController extends AdminController public function get_cd_ac($client_id, $insurer_id){ - $cd_data = $this->CDMasterModel->where('client_id', $client_id)->where('insurer_id', $insurer_id)->findAll(); + $cd_data = $this->CDMasterModel + ->where('client_id', $client_id) + ->where('insurer_id', $insurer_id) + ->where('is_active', 1) + ->findAll(); if($cd_data){ return $this->respond(['status' => true, 'code' => 200, 'data' => $cd_data], 200); @@ -2303,6 +2308,18 @@ class ClientController extends AdminController return $this->respond(['status' => false, 'data' => 0, 'message' => 'An error occurred while checking the mobile number. Please try again later.'], 500); } } + + public function checkAdditionPremiumJSON($client_id, $client_policy_id){ + + $get_additional_rack_rate_relationship_json = $this->policyPremium2Model + ->where('client_id', $client_id) + ->where('client_policy_id', $client_policy_id) + ->where('is_active', 1) + ->where('additional_relationship IS NOT NULL', null, false) + ->countAllResults(); + + return $this->respond(['status' => true, 'data' => $get_additional_rack_rate_relationship_json, 'message' => "try"], 200); + } } \ No newline at end of file diff --git a/app/Helpers/DepositHelper.php b/app/Helpers/DepositHelper.php index f6d14a7c..3565646e 100644 --- a/app/Helpers/DepositHelper.php +++ b/app/Helpers/DepositHelper.php @@ -94,7 +94,7 @@ class DepositHelper // $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE client_id = ? AND insurer_id = ? ORDER BY created_at DESC LIMIT 1"; // $getLastBalanceParams = [$clientId, $insurerId]; - $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_no = ? ORDER BY created_at DESC LIMIT 1"; + $getLastBalanceQuery = "SELECT balance FROM cash_deposit WHERE cd_ac_no = ? AND is_active = 1 ORDER BY created_at DESC LIMIT 1"; $getLastBalanceParams = [$cd_ac_no]; $lastBalance = $model->query($getLastBalanceQuery, $getLastBalanceParams)->getRow()->balance ?? null; @@ -103,7 +103,7 @@ class DepositHelper $cd_model = new ClientDepositModel(); - $getLastBalanceQuery = "SELECT opening_bal FROM cd_master WHERE client_id = ? AND insurer_id = ? AND cd_ac_no = ? ORDER BY created_at DESC LIMIT 1"; + $getLastBalanceQuery = "SELECT opening_bal FROM cd_master WHERE client_id = ? AND insurer_id = ? AND cd_ac_no = ? AND is_active = 1 ORDER BY created_at DESC LIMIT 1"; $getLastBalanceParams = [$clientId, $insurerId, $cd_ac_no]; $lastBalance = $cd_model->query($getLastBalanceQuery, $getLastBalanceParams)->getRow()->opening_bal ?? 0; diff --git a/app/Helpers/excel_import_export_helper.php b/app/Helpers/excel_import_export_helper.php index 65e44eaa..a86e5d80 100644 --- a/app/Helpers/excel_import_export_helper.php +++ b/app/Helpers/excel_import_export_helper.php @@ -3,6 +3,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use PhpOffice\PhpSpreadsheet\IOFactory; +use PhpOffice\PhpSpreadsheet\Reader\Exception as SpreadsheetReaderException; @@ -280,9 +281,9 @@ if (!function_exists('add_totals_row')) { $totalSum = 0; foreach ($data as $row) { - $gstSum += $row[18]; - $proRataPremiumSum += $row[19]; - $totalSum += $row[20]; + $gstSum += floatval($row[18]); + $proRataPremiumSum += floatval($row[19]); + $totalSum += floatval($row[20]); } // Add a new row with sums @@ -535,3 +536,439 @@ if (!function_exists('format_Excel_BasedOn_Client')) } } + + + +if(!function_exists('generate_excel_second_stage')){ + + function generate_excel_second_stage($headers, $data, $filename, $totals = null) + { + // Create a new Spreadsheet object + $spreadsheet = new Spreadsheet(); + + // Set the active sheet title + $spreadsheet->getActiveSheet()->setTitle('Sheet 1'); + + // Set headers into the spreadsheet + $headerValues = []; + foreach ($headers as $header) { + $headerValues[] = $header['column_name']; + } + $spreadsheet->getActiveSheet()->fromArray([$headerValues], null, 'A1'); + + // Set data into the spreadsheet + $dataValues = []; + $serialNumber = 0; // Initialize serial number + foreach ($data as $row) { + $serialNumber++; // Increment serial number for each row + + $rowData = []; + foreach ($headers as $header) { + $fieldName = $header['header_name']; + + if ($fieldName === 'index') { + $value = $serialNumber; + } else { + $value = $row->$fieldName ?? ''; + } + + $rowData[] = $value; + } + $dataValues[] = $rowData; + } + // dd($dataValues, $headerValues); + $spreadsheet->getActiveSheet()->fromArray($dataValues, null, 'A2'); + + // Add totals if specified + if ($totals === 1) { + // Call function to add totals row for inception + add_totals_row($spreadsheet, $data, $headers); + } else if ($totals === 2) { + // Call function to add totals row for deletion + add_totals_for_deletion($spreadsheet, $data); + } + + // Create Excel writer + $writer = new Xlsx($spreadsheet); + + try { + // Save Excel file to the specified path + $writer->save($filename); + return true; // Return true if file was successfully saved + } catch (\Exception $e) { + // Log or handle the exception + return false; // Return false if there was an error saving the file + } + } +} + + +if(!function_exists('generate_excel_third_stage')){ + + function generate_excel_third_stage($headers, $data, $filename, $totals = null) + { + // Create a new Spreadsheet object + $spreadsheet = new Spreadsheet(); + + // Set the active sheet title + $spreadsheet->getActiveSheet()->setTitle('Sheet 1'); + + $spreadsheet->getActiveSheet()->fromArray([$headers], null, 'A1'); + + $spreadsheet->getActiveSheet()->fromArray($data, null, 'A2'); + + // Add totals if specified + if ($totals === 1) { + // Call function to add totals row for inception + add_totals_row($spreadsheet, $data, $headers); + } else if ($totals === 2) { + // Call function to add totals row for deletion + add_totals_for_deletion($spreadsheet, $data); + } + + // Create Excel writer + $writer = new Xlsx($spreadsheet); + + try { + // Save Excel file to the specified path + $writer->save($filename); + return true; // Return true if file was successfully saved + } catch (\Exception $e) { + // Log or handle the exception + return false; // Return false if there was an error saving the file + } + } +} + + + +if(!function_exists('generate_insurer_based_excel')){ + + function generate_insurer_based_excel($excel_header_array, $excel_need_data){ + + usort($excel_header_array, function($a, $b) { + return $a['column_index'] <=> $b['column_index']; + }); + + + //construct HEADER + $headerValues = []; + foreach ($excel_header_array as $header) { + $headerValues[] = $header['column_name']; + } + + //construct EXCEL DATA + $dataValues = []; + $serialNumber = 0; // Initialize serial number + foreach ($excel_need_data as $row) { + $serialNumber++; + + $rowData = []; + foreach ($excel_header_array as $header) { + $fieldName = $header['header_name']; + + if ($fieldName === 'index') { + $value = $serialNumber; + } else { + $value = $row->$fieldName ?? ''; + } + + $rowData[] = $value; + } + $dataValues[] = $rowData; + } + + return ['header' => $headerValues, 'data' => $dataValues]; + } +} + + +if(!function_exists('read_first_row_of_excel')){ + + function read_first_row_of_excel($file) + { + if ($file->isValid() && !$file->hasMoved()) { + try { + $reader = IOFactory::createReaderForFile($file->getPathname()); + $spreadsheet = $reader->load($file->getPathname()); + + // Get the active sheet + $sheet = $spreadsheet->getActiveSheet(); + + // Initialize the data array + $data = []; + + // Iterate through rows to read data (only the first row) + $row = $sheet->getRowIterator()->current(); // Get the first row + $rowData = []; + foreach ($row->getCellIterator() as $cell) { + $rowData[] = $cell->getValue(); + } + $data = $rowData; // Assign the first row data to $data + + return $data; + + } catch (SpreadsheetReaderException $e) { + error_log('PhpSpreadsheet reader exception: ' . $e->getMessage()); + return $e->getMessage(); + } + } else { + return false; + } + } +} + + +if(!function_exists('query_construct_for_emp_policy_id')){ + function query_construct_for_emp_policy_id($employees, $col_index){ + + // Load the database connection + $db = \Config\Database::connect(); + + // Start building the query + $subQuery = ''; + foreach ($employees as $index => $employee) { + if ($index > 1) { + $subQuery .= " UNION ALL "; + } + if($index == 1){ + $row_id_alise = ' AS row_id,'; + $emp_name_alise = 'AS name,'; + $emp_code_alise = 'AS emp_code,'; + $emp_dob_alise = 'AS emp_dob,'; + $emp_gender_alise = 'AS emp_gender,'; + $pre_existing_alignments_alise = 'AS pre_existing_alignments,'; + $basic_cover_si_alise = 'AS basic_cover_si,'; + $emp_relationship_alise = 'AS emp_relationship,'; + $policy_end_date_alise = 'AS policy_end_date,'; + $days_alise = 'AS days,'; + $premium_alise = 'AS premium,'; + $rata_premimum_alise = 'AS rata_premimum,'; + $gst_alise = 'AS gst'; + }else{ + $row_id_alise = ','; + $emp_name_alise = ','; + $emp_code_alise = ','; + $emp_dob_alise = ','; + $emp_gender_alise = ','; + $pre_existing_alignments_alise = ','; + $basic_cover_si_alise = ','; + $emp_relationship_alise = ','; + $policy_end_date_alise = ','; + $days_alise = ','; + $premium_alise = ','; + $rata_premimum_alise = ','; + $gst_alise = ''; + } + $subQuery .= "SELECT " . intval($index) . $row_id_alise; + $subQuery .= "'" . $employee[$col_index['emp_name']] . "'" . $emp_name_alise; + $subQuery .= "'" . $employee[$col_index['emp_code']] . "'" . $emp_code_alise; + $subQuery .= "'" . $employee[$col_index['emp_dob']] . "'" . $emp_dob_alise; + $subQuery .= "'" . $employee[$col_index['emp_gender']] . "'" . $emp_gender_alise; + $subQuery .= "'" . $employee[$col_index['pre_existing_alignments']] . "'" . $pre_existing_alignments_alise; + $subQuery .= "'" . $employee[$col_index['basic_cover_si']] . "'" . $basic_cover_si_alise; + $subQuery .= "'" . $employee[$col_index['emp_relationship']] . "'" . $emp_relationship_alise; + $subQuery .= "'" . $employee[$col_index['policy_end_date']] . "'" . $policy_end_date_alise; + $subQuery .= "'" . $employee[$col_index['days']] . "'" . $days_alise; + $subQuery .= "'" . $employee[$col_index['premium']] . "'" . $premium_alise; + $subQuery .= "'" . $employee[$col_index['rata_premimum']] . "'" . $rata_premimum_alise; + $subQuery .= "'" . $employee[$col_index['gst']] . "'" . $gst_alise; + } + + // Complete the query + $mainQuery = " + SELECT + c.row_id, + c.emp_code, + c.name, + c.emp_dob, + c.emp_gender , + c.emp_relationship, + c.pre_existing_alignments, + c.basic_cover_si , + c.policy_end_date , + c.days , + c.premium , + c.rata_premimum , + c.gst, + + e.emp_code AS db_emp_code, + e.name AS db_name , + e.dob as db_dob, + e.gender as db_gender, + e.relationship as db_emp_relationship, + ep.pre_existing_alignments as db_pre_existing_alignments, + ep.basic_cover_si as db_basic_cover_si, + ep.policy_end_date as db_policy_end_date, + ep.days as db_days, + ep.premium as db_premium, + ep.rata_premimum as db_rata_premimum, + ep.gst as db_gst + + FROM ({$subQuery}) AS c + LEFT JOIN employees e + ON c.emp_code = e.emp_code + AND c.name = e.name + AND c.emp_dob = e.dob + AND c.emp_gender = e.gender + AND c.emp_relationship = e.relationship + + LEFT JOIN employee_polices ep + ON c.pre_existing_alignments = ep.pre_existing_alignments + AND c.basic_cover_si = ep.basic_cover_si + AND c.policy_end_date = ep.policy_end_date + AND c.days = ep.days + AND c.premium = ep.premium + AND c.rata_premimum = ep.rata_premimum + AND c.gst = ep.gst + + WHERE e.emp_code IS NOT NULL + AND e.name IS NOT NULL + AND e.dob IS NOT NULL + AND e.gender IS NOT NULL + AND e.relationship IS NOT NULL + AND ep.pre_existing_alignments IS NOT NULL + AND ep.basic_cover_si IS NOT NULL + AND ep.policy_end_date IS NOT NULL + AND ep.days IS NOT NULL + AND ep.premium IS NOT NULL + AND ep.rata_premimum IS NOT NULL + AND ep.gst IS NOT NULL + "; + + + // return $mainQuery; + // Execute the query + $query = $db->query($mainQuery); + $result = $query->getResultArray(); + return $result; + } +} + + +if(!function_exists('query_construct_second_stage')){ + function query_construct_second_stage($employees, $col_index){ + + // Load the database connection + $db = \Config\Database::connect(); + + // Start building the query + $subQuery = ''; + foreach ($employees as $index => $employee) { + if ($index > 1) { + $subQuery .= " UNION ALL "; + } + if($index == 1){ + $row_id_alise = ' AS row_id,'; + $emp_name_alise = 'AS name,'; + $emp_code_alise = 'AS emp_code,'; + $emp_dob_alise = 'AS emp_dob,'; + $emp_gender_alise = 'AS emp_gender,'; + $pre_existing_alignments_alise = 'AS pre_existing_alignments,'; + $basic_cover_si_alise = 'AS basic_cover_si,'; + $emp_relationship_alise = 'AS emp_relationship,'; + $policy_end_date_alise = 'AS policy_end_date,'; + $days_alise = 'AS days,'; + $premium_alise = 'AS premium,'; + $rata_premimum_alise = 'AS rata_premimum,'; + $gst_alise = 'AS gst'; + }else{ + $row_id_alise = ','; + $emp_name_alise = ','; + $emp_code_alise = ','; + $emp_dob_alise = ','; + $emp_gender_alise = ','; + $pre_existing_alignments_alise = ','; + $basic_cover_si_alise = ','; + $emp_relationship_alise = ','; + $policy_end_date_alise = ','; + $days_alise = ','; + $premium_alise = ','; + $rata_premimum_alise = ','; + $gst_alise = ''; + } + $subQuery .= "SELECT " . intval($index) . $row_id_alise; + $subQuery .= "'" . $employee[$col_index['emp_name']] . "'" . $emp_name_alise; + $subQuery .= "'" . $employee[$col_index['emp_code']] . "'" . $emp_code_alise; + $subQuery .= "'" . $employee[$col_index['emp_dob']] . "'" . $emp_dob_alise; + $subQuery .= "'" . $employee[$col_index['emp_gender']] . "'" . $emp_gender_alise; + $subQuery .= "'" . $employee[$col_index['pre_existing_alignments']] . "'" . $pre_existing_alignments_alise; + $subQuery .= "'" . $employee[$col_index['basic_cover_si']] . "'" . $basic_cover_si_alise; + $subQuery .= "'" . $employee[$col_index['emp_relationship']] . "'" . $emp_relationship_alise; + $subQuery .= "'" . $employee[$col_index['policy_end_date']] . "'" . $policy_end_date_alise; + $subQuery .= "'" . $employee[$col_index['days']] . "'" . $days_alise; + $subQuery .= "'" . $employee[$col_index['premium']] . "'" . $premium_alise; + $subQuery .= "'" . $employee[$col_index['rata_premimum']] . "'" . $rata_premimum_alise; + $subQuery .= "'" . $employee[$col_index['gst']] . "'" . $gst_alise; + } + + // Complete the query + $mainQuery = " + SELECT + c.row_id, + c.emp_code, + c.name, + c.emp_dob, + c.emp_gender , + c.emp_relationship, + c.pre_existing_alignments, + c.basic_cover_si , + c.policy_end_date , + c.days , + c.premium , + c.rata_premimum , + c.gst, + + e.emp_code AS db_emp_code, + e.name AS db_name , + e.dob as db_dob, + e.gender as db_gender, + e.relationship as db_emp_relationship, + ep.pre_existing_alignments as db_pre_existing_alignments, + ep.basic_cover_si as db_basic_cover_si, + ep.policy_end_date as db_policy_end_date, + ep.days as db_days, + ep.premium as db_premium, + ep.rata_premimum as db_rata_premimum, + ep.gst as db_gst + + FROM ({$subQuery}) AS c + LEFT JOIN employees e + ON c.emp_code = e.emp_code + AND c.name = e.name + AND c.emp_dob = e.dob + AND c.emp_gender = e.gender + AND c.emp_relationship = e.relationship + + LEFT JOIN employee_polices ep + ON c.pre_existing_alignments = ep.pre_existing_alignments + AND c.basic_cover_si = ep.basic_cover_si + AND c.policy_end_date = ep.policy_end_date + AND c.days = ep.days + AND c.premium = ep.premium + AND c.rata_premimum = ep.rata_premimum + AND c.gst = ep.gst + + WHERE e.emp_code IS NULL + AND e.name IS NULL + AND e.dob IS NULL + AND e.gender IS NULL + AND e.relationship IS NULL + AND ep.pre_existing_alignments IS NULL + AND ep.basic_cover_si IS NULL + AND ep.policy_end_date IS NULL + AND ep.days IS NULL + AND ep.premium IS NULL + AND ep.rata_premimum IS NULL + AND ep.gst IS NULL + "; + + + // return $mainQuery; + // Execute the query + $query = $db->query($mainQuery); + $result = $query->getResultArray(); + return $result; + } +} + diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 8d2af103..d0ce5e00 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -195,6 +195,7 @@ class ClientPolicyModel extends Model ->join('policies', 'policies.id = client_policy.policy_id', 'left') ->where('cash_deposit.client_id', $clientId) ->where('cash_deposit.insurer_id', $insurerId) + ->where('cash_deposit.is_active', 1) ->orderBy('cash_deposit.id', 'DESC') ->get() ->getResult(); diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 8690c71b..c69b0cb8 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -762,10 +762,8 @@ success: function(res) { console.log('client_policy_res', res) - console.log('gst', res.data.gst); var gst = (res.data.gst == 0.00) ? 18 : res.data.gst; - console.log(gst); setTimeout(function() { $('.loader').fadeOut(); @@ -792,7 +790,6 @@ } $('#tpa').val(tpaValue).change(); - // $('#policy').val(res.data.policy_id).change(); $('#policy_type').val(res.data.is_addon).change(); $('#base_policy').val(res.data.base_policy); @@ -835,24 +832,6 @@ } - if (res.data.is_addon == 1 && res.data.base_policy > 0) { - - // $("#insurer").next(".select2-container").css({ - // 'pointer-events': 'none', - // }); - // $('#select2-insurer-container').css({ - // 'background-color': '#ebebe0', - // }); - - // $("#tpa").next(".select2-container").css({ - // 'pointer-events': 'none', - // }); - // $('#select2-tpa-container').css({ - // 'background-color': '#ebebe0', - // }); - - } - if (res.data.is_addon == 2 || res.data.is_addon == 3) { @@ -887,40 +866,12 @@ }); } - var policeOptionHTML = ''; - $.each(res.policy, function(index, item) { - policeOptionHTML += ''; - }); - $('#policy').html(policeOptionHTML); - - var OptionsHTML = ''; - OptionsHTML += ''; - $.each(res.client_policy_list, function(index, item) { - - if (item.client_branch_id == res.data.client_branch_id) { - - OptionsHTML += ''; - - } - - }); - $('#base_policy').html(OptionsHTML); - - setTimeout(function() { - $('#policy').val(res.data.policy_id).change(); - $('#base_policy').val(res.data.base_policy); - $('#base_policy').change(); - }, 3000); - setTimeout(function(){ - appendCDACNO(res.cd_data, res.data.cd_ac_no) - }, 3000) + appendCDACNO(res.cd_data, res.data.cd_ac_no) // append and select the current CD Account Number + appendPolicyList(res.policy, res.data.policy_id); // append and select the current policy + appendBasePolicyList(res.client_policy_list, res.data.base_policy, res.data.client_branch_id); // append and select the Base palicy + }, 2000) $('#client_branch').val(res.data.client_branch_id).change(); @@ -1641,5 +1592,63 @@ $('#cd_ac_no').append(option); }); } + + function appendPolicyList(data, select = null, ) { + + console.log('appendPolicyList', 'function called'); + console.log('appendPolicyList data', data); + console.log('appendPolicyList selected value', select); + + $('#policy').empty(); + $('#policy').append($('