From 3b7c690f3b77e84903c7c794ceccb5b08cb0aebc Mon Sep 17 00:00:00 2001 From: velz Date: Fri, 5 Jul 2024 15:27:19 +0530 Subject: [PATCH 01/29] CHANGE_ENROLLMENT_KEY_IN_GROUP_FAMILIY --- app/Controllers/EmployeeServiceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 9ba53688..fdeca4c1 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -942,7 +942,7 @@ class EmployeeServiceController extends AdminController if(in_array($file['action'],['inception','addition','dependent_addition','deletion','correction','si_enhancement','enrollment']))// the below funcitons are only for I,DA,A { - $employee_data_group_by_family = data_group_by_family($excel_data,'excel','enrollment'); + $employee_data_group_by_family = data_group_by_family($excel_data,'excel',($file['action'] == 'enrollment' ? 'enrollment' : '')); // dd($employee_data_group_by_family); $is_self_available_in_policy_terms = false; if($policy_details['policy_type_id'] == 3) // GMC parents From f71ea394c689e03c46399d03acf905aea73f541a Mon Sep 17 00:00:00 2001 From: velz Date: Sat, 6 Jul 2024 14:43:55 +0530 Subject: [PATCH 02/29] CHANGE_CDMASTER2CDTRAN_ENTRY&FIX_UAT_DATE_ISSUE --- app/Controllers/ClientController.php | 2 + app/Controllers/MasterController.php | 99 +++++++++++++--------------- app/Helpers/excel_util_helper.php | 7 +- app/Models/ClientPolicyModel.php | 30 +++------ app/Views/cd_master_list.php | 4 +- app/Views/view_deposit.php | 5 +- 6 files changed, 67 insertions(+), 80 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index e7e80b36..7a406e62 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -318,6 +318,7 @@ class ClientController extends AdminController 4 => 'Debit', 5 => 'Non EB', 6 => 'Refund By Insurer', + 7 => 'Opening Amount', ]; $data['subTypeOptions'] = $subTypeOptions; @@ -330,6 +331,7 @@ class ClientController extends AdminController $data['clientData'] = $this->clientPolicyModel->getClientById($clientId); $data['deposiamount'] = $this->clientPolicyModel->getDepositSummary($clientId, $insurerId); + // dd($data['depositdata']); // print_r($data['depositdata'] );die; // Load the view for the new list page diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 0d7fde57..18e73a8e 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -9,6 +9,8 @@ use Psr\Log\LoggerInterface; use CodeIgniter\API\ResponseTrait; use CodeIgniter\Files\File; +use App\Helpers\DepositHelper; + use App\Models\UserModel; use App\Models\ClientModel; use App\Models\ClientBranchModel; @@ -26,6 +28,7 @@ use App\Models\TPAModel; use App\Models\StateModel; use App\Models\PolicyTypeModel; use App\Models\CDMasterModel; +use App\Models\ClientDepositModel; class MasterController extends AdminController { @@ -48,6 +51,7 @@ class MasterController extends AdminController protected $policyTypeModel; protected $CDMasterModel; protected $clientModel; + protected $clientDepositModel; @@ -74,9 +78,12 @@ class MasterController extends AdminController $this->policyTypeModel = new PolicyTypeModel(); $this->CDMasterModel = new CDMasterModel(); $this->clientModel = new ClientModel(); + $this->clientDepositModel = new ClientDepositModel(); } + + //start insurer public function insurerList() { $this->myLogger->logme('error','Insurer list function called'); @@ -108,7 +115,6 @@ class MasterController extends AdminController } } - public function removeInsurerBranch($id = null) { $this->myLogger->logme('error','Insurer Branch Remove function called'); @@ -124,7 +130,6 @@ class MasterController extends AdminController } } - public function editInsurerOnboarding($id = null) { @@ -156,7 +161,6 @@ class MasterController extends AdminController } - public function insurerOnboarding() { @@ -187,7 +191,6 @@ class MasterController extends AdminController } - public function createInsurerGeneralInfo() { @@ -244,7 +247,6 @@ class MasterController extends AdminController } } - public function insurerBranchList($id = null) { $this->myLogger->logme('error','Edit Insurer Onboarding function called'); @@ -257,9 +259,6 @@ class MasterController extends AdminController exit(); } - - - public function editInsurerGeneralInfo() { $this->myLogger->logme('error','edit Insurer general info function called'); @@ -289,7 +288,6 @@ class MasterController extends AdminController } } - public function editInsurerGet($id = null) { $this->myLogger->logme('error','Edit TPA Onboarding function called'); @@ -339,15 +337,12 @@ class MasterController extends AdminController } } - - -// Insurer Ends + // Insurer Ends -// TPA Start - + // TPA Start public function tpaList() { @@ -707,7 +702,6 @@ class MasterController extends AdminController } } - public function removeKYCDocs($id = null) { $this->myLogger->logme('error','KYC Docs Remove function called'); @@ -748,9 +742,6 @@ class MasterController extends AdminController } - - - public function createKYCInfo() { @@ -767,9 +758,6 @@ class MasterController extends AdminController } } - - - public function createKycDocs() { @@ -794,7 +782,6 @@ class MasterController extends AdminController } } - public function editKYCOnboarding($id = null) { @@ -814,9 +801,6 @@ class MasterController extends AdminController } - - - public function kycDocsList($id = null) { @@ -831,8 +815,6 @@ class MasterController extends AdminController exit(); } - - public function editKYCInfo() { $this->myLogger->logme('error','edit KYC general info function called'); @@ -847,7 +829,6 @@ class MasterController extends AdminController } } - public function editKYCGet($id = null) { $this->myLogger->logme('error','Edit KYC Onboarding function called'); @@ -860,8 +841,6 @@ class MasterController extends AdminController exit(); } - - public function editKYCDocs() { $this->myLogger->logme('error','edit KYC Docs function called'); @@ -875,16 +854,12 @@ class MasterController extends AdminController echo json_encode(array("status" => false)); } } - - - - - //Ends KYC - //Start Policy + //Start Policy + public function policyTypeList() { $this->myLogger->logme('error','Policy Type list function called'); @@ -901,7 +876,6 @@ class MasterController extends AdminController // $this->loadLayout('insurer_onboarding', $data); } - public function policyTypeRemove($id = null) { $this->myLogger->logme('error','Policy Type Remove function called'); @@ -956,9 +930,6 @@ class MasterController extends AdminController } - - - public function createPolicies() { $this->myLogger->logme('error','Policies CREATE function called'); @@ -980,9 +951,6 @@ class MasterController extends AdminController } } - - - public function createPolicyType() { $this->myLogger->logme('error','Policy Type CREATE function called'); @@ -999,7 +967,6 @@ class MasterController extends AdminController } } - public function editPolicyTypeOnboarding($id = null) { @@ -1020,7 +987,6 @@ class MasterController extends AdminController } - public function editPolicyType() { $this->myLogger->logme('error','edit Policy general info function called'); @@ -1035,7 +1001,6 @@ class MasterController extends AdminController } } - public function policesList($id = null) { $this->myLogger->logme('error','Edit Policies Onboarding function called'); @@ -1066,8 +1031,6 @@ class MasterController extends AdminController exit(); } - - public function editPoliciesGet($id = null) { $this->myLogger->logme('error','Edit Policies Onboarding function called'); @@ -1078,7 +1041,6 @@ class MasterController extends AdminController exit(); } - public function editPolicies() { $this->myLogger->logme('error','edit Policy general info function called'); @@ -1093,9 +1055,11 @@ class MasterController extends AdminController echo json_encode(array("status" => false)); } } + + //end policies - + //start CD Master list public function CDMasterList() { @@ -1105,7 +1069,6 @@ class MasterController extends AdminController $this->loadLayout('cd_master_list', $data); } - public function createCDMasterData() { @@ -1113,13 +1076,30 @@ class MasterController extends AdminController $date = (string) $this->request->getPost('opening_date'); $data['opening_date'] = date('Y-m-d', strtotime($date)); + // Prepare the array with data + $cd_tranction_data = [ + 'amount' => $data['opening_bal'], + 'sub_type_id' => 7, + 'client_id' => $data['client_id'], + 'client_policy_id' => null, + 'cd_ac_no' => $data['cd_ac_no'], + 'endorsement_no' => null, + 'insurer_id' => $data['insurer_id'], + 'description' => 'opening Amount', + 'transaction_type' => 'Credit', + 'updated_by' => 1, + ]; + $loggedInUserID = get_session_userid(); + if ($data) { $insert = $this->CDMasterModel->insert($data); if ($insert) { + $response = DepositHelper::saveDeposit($cd_tranction_data, $loggedInUserID); + session()->setFlashdata('success', "Cash Deposite Master Added Successfully"); return redirect()->to(base_url('/master/cash_deposite/list')); } else { @@ -1134,7 +1114,6 @@ class MasterController extends AdminController } } - public function editCDMasterData($id = null) { @@ -1147,6 +1126,18 @@ class MasterController extends AdminController $insert = $this->CDMasterModel->where('id', $id)->set($data)->update(); + $cd_transaction_updated_data = [ + 'balance' => $data['opening_bal'], + 'amount' => $data['opening_bal'] + ]; + + $cd_tranction = $this->clientDepositModel + ->where('client_id', $data['client_id']) + ->where('insurer_id', $data['insurer_id']) + ->where('cd_ac_no', $data['cd_ac_no']) + ->where('sub_type', 7) + ->set($cd_transaction_updated_data)->update(); + if ($insert) { session()->setFlashdata('success', "Cash Deposite Master Updated Successfully"); @@ -1187,8 +1178,8 @@ class MasterController extends AdminController } } - - public function removeCDMaster($id){ + public function removeCDMaster($id) + { $this->myLogger->logme('error','CDMaster Remove function called'); $data['updated_by'] = get_session_userid(); diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 21be120d..d14d71a7 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -10,9 +10,10 @@ if(!function_exists('calculate_days_bw_dates')) function calculate_days_bw_dates(string $from_date = "", string $to_date ="",bool $include_start_date = true) { if($to_date == ""){ $currentDateTime = new DateTime(); } - else{ $currentDateTime = new DateTime($to_date); } + else{ $to_date = convert_string_to_date($to_date); $currentDateTime = new DateTime($to_date); } + if($from_date == ""){ $passedDateTime = new DateTime(); } - else{ $passedDateTime = new DateTime($from_date); } + else{ $from_date = convert_string_to_date($from_date); $passedDateTime = new DateTime($from_date); } $interval = $currentDateTime->diff($passedDateTime); // $totalDays = $interval->days; @@ -246,7 +247,7 @@ if(!function_exists('check_si')) } // check age slab - if(in_array(strtoupper($row['current_action']), ['I','A','DA']) && strtolower($row['5']) == 'self') + if(in_array(strtoupper($row['current_action']), ['I','A','DA']) && (($slab_value['premium_type'] == 1 && strtolower($row['5']) == 'self' ) || ($slab_value['premium_type'] == 2) ) ) { if($row[3] != '' && $row[3] != null)// dob { diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index b75ca69c..65bb32cd 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -187,13 +187,15 @@ class ClientPolicyModel extends Model ->select('cash_deposit.*') ->select('insurers.name as insurer_name, insurers.short_name as insurer_short') ->select('clients.client_name as clientname, clients.short_name as clientshort') - ->select('policies.name as policy_name') + // ->select('policies.name as policy_name') + ->select('policy_type.policy_type') ->select('user_profiles.first_name as username') ->join('user_profiles', 'user_profiles.id = cash_deposit.created_by', 'left') ->join('insurers', 'insurers.id = cash_deposit.insurer_id', 'left') ->join('clients', 'clients.id = cash_deposit.client_id', 'left') ->join('client_policy', 'client_policy.id = cash_deposit.client_policy_id', 'left') - ->join('policies', 'policies.id = client_policy.policy_id', 'left') + // ->join('policies', 'policies.id = client_policy.policy_id', 'left') + ->join('policy_type', 'policy_type.id = client_policy.policy_type_id', 'left') ->where('cash_deposit.client_id', $clientId) ->where('cash_deposit.insurer_id', $insurerId) ->where('cash_deposit.is_active', 1) @@ -263,25 +265,13 @@ public function getBalances($clientId) public function getDepositlistsummary($id) { - // return $this->db->table('cash_deposit') - // ->select('insurer_id') - // ->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance') - // ->where('client_id', $id) - // ->groupBy('insurer_id') - // ->get() - // ->getResult(); - return $this->db->table('cash_deposit') - ->select('cash_deposit.insurer_id, cash_deposit.cd_ac_no') - ->select('(SUM(CASE WHEN cash_deposit.transaction_type = \'Credit\' THEN cash_deposit.amount ELSE -cash_deposit.amount END) + cd_master.opening_bal) AS balance') - ->join('cd_master', 'cd_master.cd_ac_no = cash_deposit.cd_ac_no') - ->where('cash_deposit.client_id', $id) - ->groupBy(['cash_deposit.insurer_id', 'cash_deposit.cd_ac_no', 'cd_master.opening_bal']) - ->orderBy('cash_deposit.insurer_id', 'DESC') - ->orderBy('cash_deposit.cd_ac_no', 'DESC') - ->get() - ->getResult(); - + ->select('insurer_id') + ->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance') + ->where('client_id', $id) + ->groupBy('insurer_id') + ->get() + ->getResult(); } diff --git a/app/Views/cd_master_list.php b/app/Views/cd_master_list.php index 6f781f49..30c848f6 100644 --- a/app/Views/cd_master_list.php +++ b/app/Views/cd_master_list.php @@ -60,7 +60,9 @@ table.dataTable thead th { '; $table_content .= $temp_data; $table_content .= '
NameMobile NumberSum InsureDate Of Birth
'; - + $Addon_list = []; if ($is_addon == 2 || $is_addon == 3) { $addon_list_array = [ 'policy_name'=>$policy_name, From 277c156035e9a41f9a70658a286b3c9b9e3d5e26 Mon Sep 17 00:00:00 2001 From: Venba Date: Thu, 11 Jul 2024 08:56:19 +0000 Subject: [PATCH 13/29] FIX_UNWANTED_CHAR_REMOVED --- app/Controllers/EmployeeController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 050df9cc..db9b306c 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -681,7 +681,7 @@ class EmployeeController extends AdminController ->first(); $empServiceController = new EmployeeServiceController(); - $res = $empServiceController->employeesOnboardPreprocess(['client_policy_id' => $client_policy_id,',client_branch_id' => $client_data['client_branch_id']]); + $res = $empServiceController->employeesOnboardPreprocess(['client_policy_id' => $client_policy_id,'client_branch_id' => $client_data['client_branch_id']]); // dd($res); $count = count($res); From ce4312fc8db9959b084fbe327554294b3f6f4760 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 11 Jul 2024 14:58:30 +0530 Subject: [PATCH 14/29] CHANGE_ mpin status api : GWM --- app/Config/Routes.php | 1 + .../RestAuthenticationController.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f4df6e62..4778427f 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -272,6 +272,7 @@ $routes->get("processjob", "JobWorker::processJob"); $routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber"); $routes->post("/employeeRest/getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); $routes->post("/employeeRest/verifyMpin", "RestAuthenticationController::verifyMpin"); +$routes->post("/employeeRest/checkMpin", "RestAuthenticationController::checkMpin"); //HR login api's $routes->post("/employeeRest/verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber"); $routes->post("/employeeRest/getVerifiedHrData", "RestAuthenticationController::getVerifiedHrData"); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 4e5cf279..7c7358f7 100644 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -310,6 +310,25 @@ class RestAuthenticationController extends AdminController } } + public function checkMpin() + { + try { + $mobile_number = $this->request->getJSON()->mobile_number; + + + $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + + if ($employeeData && $employeeData["mpin"] != null) { + + return $this->respond(['status' => 'success','code' => 200,'data' => "Mpin - exist"],200); + } else { + return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found"],200); + } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); + } + } + } \ No newline at end of file From ecfda34fbca9e9dfe827e70a1e23bd470815a05c Mon Sep 17 00:00:00 2001 From: bitbucket Date: Mon, 15 Jul 2024 12:07:55 +0530 Subject: [PATCH 15/29] CHANGE_ mpin check api change : GWM --- app/Controllers/RestAuthenticationController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 7c7358f7..6efaa163 100644 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -320,9 +320,9 @@ class RestAuthenticationController extends AdminController if ($employeeData && $employeeData["mpin"] != null) { - return $this->respond(['status' => 'success','code' => 200,'data' => "Mpin - exist"],200); + return $this->respond(['status' => 'success','code' => 200,'data' => "Mpin - exist" , 'Mpin' =>$employeeData["mpin"]],200); } else { - return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found"],200); + return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found", 'Mpin' =>null],200); } } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); From f19ccf660167c5fb31ccae49cff044f92762f853 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Tue, 16 Jul 2024 15:13:03 +0530 Subject: [PATCH 16/29] CHANGE_ in getEmployeePolicy model function : GWM --- app/Models/EmployeePolicyModel.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index a94410f5..3dfe16ec 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -101,6 +101,9 @@ class EmployeePolicyModel extends Model 'emp.emp_status', 'emp.is_active as emp_is_active', 'emp.mobile as mobile', + 'emp.doj', + 'emp.basic_pay', + 'emp.band as grade', 'policy_type.policy_type', 'cp.policy_no', ]) From 59dc24596bf3030261b15b6431bfdca80e1a8ce1 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Tue, 16 Jul 2024 17:48:11 +0530 Subject: [PATCH 17/29] CHANGE_Member_Review_And_Summary_Mail : AADHAVAN --- app/Helpers/sendMailNotification.php | 74 ++++++++++++++++------------ app/Helpers/session_helper.php | 6 +++ app/Helpers/utility_helper.php | 61 +++++++++++++++++++++++ 3 files changed, 110 insertions(+), 31 deletions(-) diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 84c8a13d..d5f6e885 100644 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -165,7 +165,7 @@ class sendMailNotification $is_addon =''; foreach ($item as $inner_item) { $policy_name = $inner_item['policy_name']; - $temp_data .= '' . $inner_item['name'] . ''.$inner_item['mobile'].'₹'.number_format($inner_item['basic_cover_si'], 2, '.', ',').''.\DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y').''; + $temp_data .= '' . $inner_item['name'] . ''.$inner_item['relationship'].''. \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') .'₹'.format_indian_number($inner_item['basic_cover_si']).'₹'.format_indian_number($inner_item['premium']).'₹'. format_indian_number($inner_item['gst']) .''; if($inner_item['relationship'] == 'Self' || $inner_item['relationship'] == 'self'){ $mail = $inner_item['email_corporate']; $name = $inner_item['name']; @@ -179,10 +179,10 @@ class sendMailNotification } } // echo $policy_name;die; - $table_content .= $policy_name.''; + $table_content .= $policy_name.'
NameMobile NumberSum InsureDate Of Birth
GST'; $table_content .= $temp_data; $table_content .= '
NameRelationDate Of BirthSum InsurePremium
'; - + $Addon_list = []; if ($is_addon == 2 || $is_addon == 3) { $addon_list_array = [ 'policy_name'=>$policy_name, @@ -200,17 +200,20 @@ class sendMailNotification } } + if(count($Addon_list) != 0 && count($Addon_list) > 0){ + $table_content .='
'; + $sum_tolal = 0; + foreach ($Addon_list as $key => $value) { + $sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal; + $table_content .= ''; + } + $sum_total_words = numberToWords($sum_tolal); + $table_content .= ''; + $table_content .= '
Policy Name Additional PremiumGSTTotal
'.$value['policy_name'].'₹'.$value['addtional_premium'].''.$value['gst'].''.$value['gst'] + $value['addtional_premium'] .'

Total

'.format_indian_number($sum_tolal).'
'; + $table_content .= '
'. $sum_total_words .'
'; - $table_content .='
'; - $sum_tolal = 0; - foreach ($Addon_list as $key => $value) { - $sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal; - $table_content .= ''; } - $table_content .= ''; - $table_content .= '
Policy Name Additional PremiumGSTTotal
'.$value['policy_name'].'₹'.$value['addtional_premium'].''.$value['gst'].''.$value['gst'] + $value['addtional_premium'] .'

Total

'.$sum_tolal.'
'; $mail_content = str_replace("[[member_name]]", $name, $mail_content); - $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); // $mail = "aadhavanvalli@gmail.com"; // if (isset($mail) && !empty($mail)) { @@ -276,7 +279,7 @@ class sendMailNotification $is_addon =''; foreach ($item as $inner_item) { $policy_name = $inner_item['policy_name']; - $temp_data .= '' . $inner_item['name'] . ''.$inner_item['mobile'].'₹'.number_format($inner_item['basic_cover_si'], 2, '.', ',').''.\DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y').''; + $temp_data .= '' . $inner_item['name'] . ''.$inner_item['mobile'].'₹'.format_indian_number($inner_item['basic_cover_si']).''.\DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y').''; // print_r($inner_item);die; $is_addon = $inner_item['is_addon']; @@ -288,7 +291,7 @@ class sendMailNotification $table_content .= $policy_name.''; $table_content .= $temp_data; $table_content .= '
NameMobile NumberSum InsureDate Of Birth
'; - + $Addon_list = []; if ($is_addon == 2 || $is_addon == 3) { $addon_list_array = [ 'policy_name'=>$policy_name, @@ -307,16 +310,20 @@ class sendMailNotification } + if(count($Addon_list) != 0 && count($Addon_list) > 0){ + + $table_content .='
'; + $sum_tolal = 0; + foreach ($Addon_list as $key => $value) { + $sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal; + $table_content .= ''; + } + $sum_total_words = numberToWords($sum_tolal); + $table_content .= ''; + $table_content .= '
Policy Name Additional PremiumGSTTotal
'.$value['policy_name'].'₹'.$value['addtional_premium'].''.$value['gst'].''.$value['gst'] + $value['addtional_premium'] .'

Total

'.format_indian_number($sum_tolal).'
'; + $table_content .= '
'. $sum_total_words .'
'; - $table_content .='
'; - $sum_tolal = 0; - foreach ($Addon_list as $key => $value) { - $sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal; - $table_content .= ''; } - $table_content .= ''; - $table_content .= '
Policy Name Additional PremiumGSTTotal
'.$value['policy_name'].'₹'.$value['addtional_premium'].''.$value['gst'].''.$value['gst'] + $value['addtional_premium'] .'

Total

'.$sum_tolal.'
'; - $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); $account_manager_mail_list = []; @@ -383,7 +390,7 @@ class sendMailNotification $temp_data =''; foreach ($item as $inner_item) { $policy_name = $inner_item['policy_name']; - $temp_data .= '' . $inner_item['name'] . ''.$inner_item['mobile'].'₹'.number_format($inner_item['basic_cover_si'], 2, '.', ',').''.\DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y').''; + $temp_data .= '' . $inner_item['name'] . ''.$inner_item['mobile'].'₹'.format_indian_number($inner_item['basic_cover_si']).''.\DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y').''; // print_r($inner_item);die; $is_addon = $inner_item['is_addon']; @@ -395,6 +402,7 @@ class sendMailNotification $table_content .= $policy_name.''; $table_content .= $temp_data; $table_content .= '
NameMobile NumberSum InsureDate Of Birth
'; + $Addon_list = []; if ($is_addon == 2 || $is_addon == 3) { $addon_list_array = [ @@ -412,16 +420,18 @@ class sendMailNotification $gst = 0; } - - $table_content .='
'; - $sum_tolal = 0; - foreach ($Addon_list as $key => $value) { - $sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal; - $table_content .= ''; + if(count($Addon_list) != 0 && count($Addon_list) > 0){ + $table_content .='
Policy Name Additional PremiumGSTTotal
'.$value['policy_name'].'₹'.$value['addtional_premium'].''.$value['gst'].''.$value['gst'] + $value['addtional_premium'] .'
'; + $sum_tolal = 0; + foreach ($Addon_list as $key => $value) { + $sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal; + $table_content .= ''; + } + $sum_total_words = numberToWords($sum_tolal); + $table_content .= ''; + $table_content .= '
Policy Name Additional PremiumGSTTotal
'.$value['policy_name'].'₹'.$value['addtional_premium'].''.$value['gst'].''.$value['gst'] + $value['addtional_premium'] .'

Total

'.format_indian_number($sum_tolal).'
'; + $table_content .= '
'. $sum_total_words .'
'; } - $table_content .= '

Total

'.$sum_tolal.''; - $table_content .= ''; - $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); @@ -439,4 +449,6 @@ class sendMailNotification } } + + } \ No newline at end of file diff --git a/app/Helpers/session_helper.php b/app/Helpers/session_helper.php index ce6a0f56..92f443d2 100644 --- a/app/Helpers/session_helper.php +++ b/app/Helpers/session_helper.php @@ -139,3 +139,9 @@ if (!function_exists('get_session_context')) { return $session->get('context'); } } + + + + + + diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 87945e48..da3f5f4c 100644 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -248,3 +248,64 @@ if (!function_exists('get_role_id')) { } +function numberToWords($number) +{ + $words = array( + '0' => 'Zero', + '1' => 'One', + '2' => 'Two', + '3' => 'Three', + '4' => 'Four', + '5' => 'Five', + '6' => 'Six', + '7' => 'Seven', + '8' => 'Eight', + '9' => 'Nine', + '10' => 'Ten', + '11' => 'Eleven', + '12' => 'Twelve', + '13' => 'Thirteen', + '14' => 'Fourteen', + '15' => 'Fifteen', + '16' => 'Sixteen', + '17' => 'Seventeen', + '18' => 'Eighteen', + '19' => 'Nineteen', + '20' => 'Twenty', + '30' => 'Thirty', + '40' => 'Forty', + '50' => 'Fifty', + '60' => 'Sixty', + '70' => 'Seventy', + '80' => 'Eighty', + '90' => 'Ninety' + ); + + if ($number < 21) { + return $words[$number]; + } + + if ($number < 100) { + $tens = (int)($number / 10) * 10; + $units = $number % 10; + return $words[$tens] . ($units ? ' ' . $words[$units] : ''); + } + + if ($number < 1000) { + $hundreds = (int)($number / 100); + $remainder = $number % 100; + return $words[$hundreds] . ' Hundred' . ($remainder ? ' and ' . numberToWords($remainder) : ''); + } + + $levels = array('', ' Thousand', ' Million', ' Billion', ' Trillion', ' Quadrillion', ' Quintillion'); + + for ($i = 0, $unit = 1; $i < count($levels); $i++, $unit *= 1000) { + if ($number < $unit * 1000) { + $current = (int)($number / $unit); + $remainder = $number % $unit; + return numberToWords($current) . $levels[$i] . ($remainder ? ' ' . numberToWords($remainder) : ''); + } + } + + return $number; // Fallback for numbers beyond the supported range +} From 7e69a77b8afe5a004b3ecbc7ac50d877a84df7d0 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Wed, 17 Jul 2024 17:01:27 +0530 Subject: [PATCH 18/29] CHANGE_ in iAgreeForAddOn API status change : GWM --- app/Controllers/EmployeeRestController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 6dcd79c2..1edfc878 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1765,21 +1765,29 @@ public function iAgreeForAddOn() ->where('is_active', 1 ) ->set(array('emp_status'=>'enrolled')) ->update(); + + $empData = $this->employeeModel->where('emp_code', $emp_code )->where('client_id', $client_id ) ->where('is_active', 1 )->findAll(); if (!is_null($client_policy_id) && is_array($client_policy_id)) { $array_list = []; foreach ($client_policy_id as $key => $value) { - $this->employeePolicyModel->where('client_policy_id', $value ) + foreach ($empData as $empDataKey => $empDataValue) + { + $this->employeePolicyModel->where('client_policy_id', $value ) ->where('is_active', 1 ) + ->where('employee_id', $empDataValue['id'] ) ->set(array('status'=>'enrolled')) ->update(); + } + $find = $this->employeeModel->getEmpFamilybyEmpCode(client_policy_id: $value,emp_code: $emp_code,client_id: $client_id,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); if(count($find) > 0){ $array_list[] = $find; } } + $notification = $this->notificationModel->where('client_id' ,$client_id)->where('template_name', 'member_review_and_summary_mail')->first(); From 420a07364f5a8831af223d841095161121b2156f Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Thu, 18 Jul 2024 16:53:54 +0530 Subject: [PATCH 19/29] CHANGE_MAIL_CONTENT_ISSUE_FIX : AADHAVAN --- app/Controllers/EmpDataServiceController.php | 6 ++-- app/Controllers/EmployeeRestController.php | 2 -- app/Helpers/sendMailNotification.php | 30 +++++++++++--------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 96537b76..f1d6f143 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -3600,6 +3600,7 @@ class EmpDataServiceController extends BaseController public function sendMailForDownloadingECard(array $ids) { + $this->myLogger->logme('error', 'sendMailForDownloadingECard - function called'); if (count($ids) > 0) { @@ -3655,14 +3656,15 @@ class EmpDataServiceController extends BaseController $params['get_emp_email_and_other_details'] = $get_emp_email_and_other_details; // $this->myLogger->logme('error', 'sendMailForDownloadingECard - Send Bulk Mail function end ',); - if (isset($get_emp_email_and_other_details['email_corporate']) && !empty($get_emp_email_and_other_details['email_corporate']) && $get_emp_email_and_other_details['relationship'] === 'Self') { + if (isset($get_emp_email_and_other_details['email_corporate']) && !empty($get_emp_email_and_other_details['email_corporate']) && $get_emp_email_and_other_details['relationship'] == 'Self') { $wholeData[] = sendMailNotification::sendMailNotification('member_ecard_mail', $params); + // print_r($wholeData);die; $count++; } + $counts++; - if ($count == 20 || $counts == count($ids) - 1) { if(count($wholeData) > 0){ diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 6dcd79c2..eb7067ee 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -661,7 +661,6 @@ class EmployeeRestController extends AdminController $empServiceController = new EmployeeServiceController(); $result = $empServiceController->excelFileFormatValidation(['file_id' => $file_id]); - if(isset($result['error_summary']) && count($result['error_summary'])) { $result = $empServiceController->getExcelErrorData($file_id); @@ -1789,7 +1788,6 @@ public function iAgreeForAddOn() $params ['emp_code'] = $emp_code; $params ['client_id'] = $client_id; $params ['notification'] = $notification; - $wholeData =sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params); MailHelper::send_email($wholeData[0]); diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index d5f6e885..68c4927b 100644 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -100,11 +100,16 @@ class sendMailNotification $mail_content = $notification['mail_content']; $mail = $get_emp_email_and_other_details['email_corporate']; $subject = $notification['subject']; + $link = generate_download_link($rand_string); + $app_link = $_ENV['App_Url']; $name = $get_emp_email_and_other_details['name']; $mail_content = $notification['mail_content']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + // dd("3333333333333"); + $post_enrollment_app_link = $_ENV['POST_ENROLLMENT_APP_LINK']; $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; @@ -119,7 +124,6 @@ class sendMailNotification // $mail_content = str_replace("[[tpa_id]]", $tpa_id, $mail_content); $mail_content = str_replace("[[ecard_download_link]]", "Download Insurance Card", $mail_content); $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); - $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails']]; return $wholeData; @@ -157,6 +161,7 @@ class sendMailNotification $table_content = ''; $addtional_premium = 0; $gst = 0; + $Addon_list = []; foreach ($array_list as $item) { if(count($item) != 0){ $table_content .= '

Policy Name : '; @@ -182,7 +187,6 @@ class sendMailNotification $table_content .= $policy_name.'

GST'; $table_content .= $temp_data; $table_content .= '
NameRelationDate Of BirthSum InsurePremium
'; - $Addon_list = []; if ($is_addon == 2 || $is_addon == 3) { $addon_list_array = [ 'policy_name'=>$policy_name, @@ -190,7 +194,7 @@ class sendMailNotification 'gst'=>$gst ]; $Addon_list[]= $addon_list_array; - + } @@ -270,7 +274,8 @@ class sendMailNotification $addtional_premium = 0; $gst = 0; $array_list = $params['array_list']; - + $Addon_list = []; + // print_r($array_list);die; foreach ($array_list as $item) { if(count($item) != 0){ $table_content .= '

Policy Name : '; @@ -279,19 +284,20 @@ class sendMailNotification $is_addon =''; foreach ($item as $inner_item) { $policy_name = $inner_item['policy_name']; - $temp_data .= '' . $inner_item['name'] . ''.$inner_item['mobile'].'₹'.format_indian_number($inner_item['basic_cover_si']).''.\DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y').''; + $temp_data .= '' . $inner_item['name'] . ''.$inner_item['relationship'].''. \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') .'₹'.format_indian_number($inner_item['basic_cover_si']).'₹'.format_indian_number($inner_item['premium']).'₹'. format_indian_number($inner_item['gst']) .''; // print_r($inner_item);die; $is_addon = $inner_item['is_addon']; if($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3){ + + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; $gst = $inner_item['gst'] + $gst; } } - $table_content .= $policy_name.'

'; + $table_content .= $policy_name.'
NameMobile NumberSum InsureDate Of Birth
GST'; $table_content .= $temp_data; $table_content .= '
NameRelationDate Of BirthSum InsurePremium
'; - $Addon_list = []; if ($is_addon == 2 || $is_addon == 3) { $addon_list_array = [ 'policy_name'=>$policy_name, @@ -384,13 +390,14 @@ class sendMailNotification $addtional_premium = 0; $gst = 0; $array_list = $params['array_list']; + $Addon_list = []; foreach ($array_list as $item) { $table_content .= '

Policy Name : '; $temp_data =''; foreach ($item as $inner_item) { $policy_name = $inner_item['policy_name']; - $temp_data .= '' . $inner_item['name'] . ''.$inner_item['mobile'].'₹'.format_indian_number($inner_item['basic_cover_si']).''.\DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y').''; + $temp_data .= '' . $inner_item['name'] . ''.$inner_item['relationship'].''. \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') .'₹'.format_indian_number($inner_item['basic_cover_si']).'₹'.format_indian_number($inner_item['premium']).'₹'. format_indian_number($inner_item['gst']) .''; // print_r($inner_item);die; $is_addon = $inner_item['is_addon']; @@ -399,10 +406,9 @@ class sendMailNotification $gst = $inner_item['gst'] + $gst; } } - $table_content .= $policy_name.'

'; + $table_content .= $policy_name.'
NameMobile NumberSum InsureDate Of Birth
GST'; $table_content .= $temp_data; $table_content .= '
NameRelationDate Of BirthSum InsurePremium
'; - $Addon_list = []; if ($is_addon == 2 || $is_addon == 3) { $addon_list_array = [ @@ -448,7 +454,5 @@ class sendMailNotification } } - } - - + } } \ No newline at end of file From 3ef0a7aff3010a875ccc41814075f34a28f293f1 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Thu, 18 Jul 2024 16:58:43 +0530 Subject: [PATCH 20/29] CHANGE_MAIL_CONTENT_ISSUE_FIX_IN_NAME_ADD : AADHAVAN --- app/Helpers/sendMailNotification.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 68c4927b..57cb5051 100644 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -162,6 +162,7 @@ class sendMailNotification $addtional_premium = 0; $gst = 0; $Addon_list = []; + $name = ''; foreach ($array_list as $item) { if(count($item) != 0){ $table_content .= '

Policy Name : '; From e24992023b1f6d0b10f059e556f9a327baf8192c Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Thu, 18 Jul 2024 17:34:57 +0530 Subject: [PATCH 21/29] CHANGE_MAIL_NOT_RECIVE_IN_DEV_ADD_LOG : AADHAVAN --- app/Controllers/EmployeeRestController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index dfdfd3d5..d7379215 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1797,20 +1797,23 @@ public function iAgreeForAddOn() $params ['client_id'] = $client_id; $params ['notification'] = $notification; $wholeData =sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params); - MailHelper::send_email($wholeData[0]); + $mail_send_return = MailHelper::send_email($wholeData[0]); + $this->myLogger->logme("info", $mail_send_return); if (isset($wholeData[0])) { $account_manager_wholeData =sendMailNotification::sendMailNotification('account_maneger_summary_mail', $params); foreach ($account_manager_wholeData as $key => $value) { - MailHelper::send_email($value); + $mail_send_return1 = MailHelper::send_email($value); + $this->myLogger->logme("info", $mail_send_return1); } $client_hr_wholeData =sendMailNotification::sendMailNotification('client_hr_summary_mail', $params); foreach ($client_hr_wholeData as $key => $value) { - MailHelper::send_email($value); + $mail_send_return2 = MailHelper::send_email($value); + $this->myLogger->logme("info", $mail_send_return2); } } } From fd30391caca75ac1cc422b47bcc2c878570b95d0 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Thu, 18 Jul 2024 17:42:24 +0530 Subject: [PATCH 22/29] CHANGE_MAIL_CONFIG_CHANGE : AADHAVAN --- app/Config/Email.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Config/Email.php b/app/Config/Email.php index f7e3ae01..0876c49e 100644 --- a/app/Config/Email.php +++ b/app/Config/Email.php @@ -28,17 +28,17 @@ class Email extends BaseConfig /** * SMTP Server Hostname */ - public string $SMTPHost = 'mail.venbait.in'; + public string $SMTPHost = 'smtp.gmail.com'; /** * SMTP Username */ - public string $SMTPUser = 'bbone@venbait.in'; + public string $SMTPUser = 'venbatechnologies@gmail.com'; /** * SMTP Password */ - public string $SMTPPass = 'xk!L(N_-R#};'; + public string $SMTPPass = 'dsfllmxdzxxkcxgz'; /** * SMTP Port From ba4ad6bb62605d0f3d1fb51c3efc23894e02bbda Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Fri, 19 Jul 2024 09:57:30 +0530 Subject: [PATCH 23/29] CHANGE_MAIL_NOTIFICATION_CHECK : AADHAVAN --- app/Controllers/EmployeeRestController.php | 3 ++- app/Helpers/sendMailNotification.php | 30 ++++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d7379215..d7ba79f2 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1754,7 +1754,7 @@ public function iAgreeForAddOn() { $postData = json_decode($this->request->getBody(), true); $client_policy_id = $postData['client_policy_id']; - + sort($client_policy_id); // Alternatively, you can use echo to see the type $emp_code = $postData['emp_code']; $client_id = $postData['client_id']; @@ -1796,6 +1796,7 @@ public function iAgreeForAddOn() $params ['emp_code'] = $emp_code; $params ['client_id'] = $client_id; $params ['notification'] = $notification; + // print_r($params);die; $wholeData =sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params); $mail_send_return = MailHelper::send_email($wholeData[0]); $this->myLogger->logme("info", $mail_send_return); diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 57cb5051..5a35ccd2 100644 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -12,6 +12,7 @@ class sendMailNotification { public static function sendMailNotification($action, $params) { + print_r($params);die; if ($action == 'member_welcome_mail') { $dataToInsert = $params['dataToInsert']; $notification = $params['notification']; @@ -37,7 +38,6 @@ class sendMailNotification return $wholeData; } else if($action == 'member_reminder_mail'){ - // print_r($params);die; $EmployeeModel = new EmployeeModel(); $emp_data = $params['emp_data']; $notification_data = $params['notification_data']; @@ -157,12 +157,12 @@ class sendMailNotification // Step 1: Replace the placeholder with an HTML table structure $mail = ''; - // print_r($array_list);die; $table_content = ''; $addtional_premium = 0; $gst = 0; $Addon_list = []; $name = ''; + $emp_code = ''; foreach ($array_list as $item) { if(count($item) != 0){ $table_content .= '

Policy Name : '; @@ -175,8 +175,8 @@ class sendMailNotification if($inner_item['relationship'] == 'Self' || $inner_item['relationship'] == 'self'){ $mail = $inner_item['email_corporate']; $name = $inner_item['name']; + $emp_code = $inner_item['emp_code']; } - // print_r($inner_item);die; $is_addon = $inner_item['is_addon']; if($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3){ @@ -218,7 +218,7 @@ class sendMailNotification $table_content .= '
'. $sum_total_words .'
'; } - $mail_content = str_replace("[[member_name]]", $name, $mail_content); + $mail_content = str_replace("[[member_name]]", $name . ' (' . $emp_code . ')' , $mail_content); $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); // $mail = "aadhavanvalli@gmail.com"; // if (isset($mail) && !empty($mail)) { @@ -228,7 +228,6 @@ class sendMailNotification return $wholeData; } - // print_r($wholeData);die; } else if($action == 'account_maneger_summary_mail'){ $client_id = $params['client_id']; @@ -250,7 +249,6 @@ class sendMailNotification $user_list[]=$user_data; } } - // print_r($client_rm_data);die; @@ -270,13 +268,11 @@ class sendMailNotification // Step 1: Replace the placeholder with an HTML table structure $mail = ''; - // print_r($array_list);die; $table_content = ''; $addtional_premium = 0; $gst = 0; $array_list = $params['array_list']; $Addon_list = []; - // print_r($array_list);die; foreach ($array_list as $item) { if(count($item) != 0){ $table_content .= '

Policy Name : '; @@ -285,8 +281,12 @@ class sendMailNotification $is_addon =''; foreach ($item as $inner_item) { $policy_name = $inner_item['policy_name']; - $temp_data .= '' . $inner_item['name'] . ''.$inner_item['relationship'].''. \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') .'₹'.format_indian_number($inner_item['basic_cover_si']).'₹'.format_indian_number($inner_item['premium']).'₹'. format_indian_number($inner_item['gst']) .''; - // print_r($inner_item);die; + if($inner_item['relationship'] == 'Self'){ + $emp_code = ' ('. $inner_item['emp_code'] . ')'; + }else{ + $emp_code =''; + } + $temp_data .= '' . $inner_item['name'] . $emp_code . ''.$inner_item['relationship'].''. \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') .'₹'.format_indian_number($inner_item['basic_cover_si']).'₹'.format_indian_number($inner_item['premium']).'₹'. format_indian_number($inner_item['gst']) .''; $is_addon = $inner_item['is_addon']; if($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3){ @@ -334,7 +334,6 @@ class sendMailNotification $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); $account_manager_mail_list = []; - // print_r($user_list);die; if(isset($user_list)){ foreach ($user_list as $key => $value) { $full_name = $value['first_name'] .' ' .$value['last_name']; @@ -386,7 +385,6 @@ class sendMailNotification // Step 1: Replace the placeholder with an HTML table structure $mail = ''; - // print_r($array_list);die; $table_content = ''; $addtional_premium = 0; $gst = 0; @@ -398,8 +396,12 @@ class sendMailNotification $temp_data =''; foreach ($item as $inner_item) { $policy_name = $inner_item['policy_name']; - $temp_data .= '' . $inner_item['name'] . ''.$inner_item['relationship'].''. \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') .'₹'.format_indian_number($inner_item['basic_cover_si']).'₹'.format_indian_number($inner_item['premium']).'₹'. format_indian_number($inner_item['gst']) .''; - // print_r($inner_item);die; + if($inner_item['relationship'] == 'Self'){ + $emp_code = ' ('. $inner_item['emp_code'] . ')'; + }else{ + $emp_code =''; + } + $temp_data .= '' . $inner_item['name'] . $emp_code . ''.$inner_item['relationship'].''. \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') .'₹'.format_indian_number($inner_item['basic_cover_si']).'₹'.format_indian_number($inner_item['premium']).'₹'. format_indian_number($inner_item['gst']) .''; $is_addon = $inner_item['is_addon']; if($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3){ From 5e3c126b0b9f6dd7b049c9432865bdc529dbb31e Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Sat, 20 Jul 2024 09:57:35 +0530 Subject: [PATCH 24/29] CHANGE_ADD_NEW_API_FIREBASE_TOKEN_API_EMP_REST : AADHAVAN --- app/Config/Routes.php | 2 + app/Controllers/EmployeeRestController.php | 2605 ++++++++++---------- 2 files changed, 1332 insertions(+), 1275 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4778427f..06888fcb 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -136,6 +136,7 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { $routes->post("upload", "EmployeeController::employeesUplodWithEvents"); $routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1"); $routes->get("endorsement-list", "EmployeeController::endorsementList"); + $routes->get("enrollment-list", "EmployeeController::enrollmentList"); $routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1"); }); @@ -287,6 +288,7 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { $routes->get("getChatResponse", "ChatBotController::getChatResponse"); $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { + $routes->post("storeFireBase", "EmployeeRestController::storeFireBase"); $routes->post("saveMpin", "RestAuthenticationController::saveMpin"); $routes->post("updateMpin", "RestAuthenticationController::updateMpin"); $routes->get("getChatResponse", "ChatBotController::getChatResponse"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d7ba79f2..40d6f8b5 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -928,634 +928,154 @@ class EmployeeRestController extends AdminController } -//------------------------------------- -public function getAgeRange($terms,$familyFloatesValue) -{ - - $ageRangeArray = ['self' => ['min' => 18, 'max' => 60] , 'spouse' => ['min' => 18, 'max' => 60] , 'child' => ['min' => 0, 'max' => 25] , 'elders' => ['min' => 18, 'max' => 60] ]; - - $ageKey = (preg_replace('/\d/', '', $familyFloatesValue) == 'parent' || preg_replace('/\d/', '', $familyFloatesValue) == 'parent_in_law') ? 'elders' : preg_replace('/\d/', '', $familyFloatesValue); - if(isset($terms->age_ratio)){ - return $terms->age_ratio->$ageKey; - }else{ - return $ageRangeArray[$ageKey]; - } - - -} - -public function getEmployeePolicy() -{ - // try { - - $id = $this->request->getGet('id'); - $emp_code = $this->request->getGet('emp_code'); - $client_id = $this->request->getGet('client_id'); - $client_branch_id = $this->request->getGet('client_branch_id'); - - // This is an array containing keys to be removed from the terms and conditions array - $keysToRemove = ["removable_keys"]; - // Retrieve employee policy data by passing the employee primary key - $empPolicy = $this->employeeModel->getEmployeePolicy($id); - - // Retrieve employee and dependents data by passing the employee code - $employeeData = $this->employeeModel->where('emp_code',$emp_code) - ->where('client_id',$client_id) - ->where('client_branch_id',$client_branch_id) - ->where('is_active', 1 ) - ->where('is_addon_value',0)->findAll(); - - - if ($empPolicy) { - - $result = []; - foreach ($empPolicy as $array) { - // Reset employee array - $empData = $employeeData; - - - // Removes specific keys from the decoded array and assigns the result to $refusingData - $decodedArray = json_decode($array->Policy_Terms); - $refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove)); - $array->Policy_Terms = $refusingData; - - // Retrieve slab rate and grid master data by passing the ClientPolicyId and ClientId - $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId); - $array->SlabRates = $getSlabAndGridData['slab_rates']; - $array->GridMaster = $getSlabAndGridData['grid_master']; - - if($array->tpa_id != null){ - $array->eCardDownload = base_url('download-e-card/') . $array->rand_string; - }else{ $array->eCardDownload = null; } - - - // Construct value for policy type GPA - if($getSlabAndGridData['grid_master']['policy_type'] == "GPA" && $this->request->getGet('policy') == 'GPA'){ - - // Filter employee data where the family_floater_key is 'self' - $selfData = array_filter($empData, fn($arr) => trim(strtolower($arr['family_floater_key'])) === 'self'); - $employee_policy = $this->employeePolicyModel->where('employee_id',$selfData[0]['id'])->where('client_policy_id',$array->ClientPolicyId)->where('is_active', 1 )->get()->getRow(); - - $self['is_value_exist'] = true; - $self['data']['family_floater_key'] = 'self'; - $self['data']['employee_id'] = $id; - $self['data']['relationship'] = 'Self'; - $self['data']['name'] = $selfData[0]['name']; - $self['data']['dob'] = $this->convertDateFormatDMY($selfData[0]['dob']); - $self['data']['mobile'] = $selfData[0]['mobile']; - $self['data']['client_policy_id'] = $array->ClientPolicyId; - $self['data']['basic_cover_si'] = $employee_policy->basic_cover_si; - - $array->mapped_family_floaters = $self; - - // Return result - if($this->request->getGet('policy') == 'GPA') - { - return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200); - } - - // Construct value for policy type GMC - }else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC" && $this->request->getGet('policy') == 'GMC' ){ - - - - // Map family floaters that already exist in the employee table - $familyFloates = $array->Policy_Terms->family_floaters; - - // Generate Notes string based on familyFloates terms - $array->notes = $this->FloterNotesConvertion($familyFloates); - - if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) - { - $array->floter_text_heading = 'Floater Sum Insured'; - $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.'; - }else{ - $array->floter_text_heading = 'Sum Insured'; - $array->floter_text_description = ''; - } - - // remove parent and parent-in-law from familyFloaters - if($familyFloates->{'either-parents-pil'} != 0){ - unset($familyFloates->parents); - unset($familyFloates->parents_in_law); - } - $floters = $this->FloterConvertion($familyFloates); - - $data = []; - foreach ($floters as $familyFloatesValue) { - $dependent = preg_replace('/\d/', '', $familyFloatesValue); - - if(count($empData)){ - foreach ($empData as $key => $value) { - if ($value['family_floater_key'] === $dependent) { - $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array->ClientPolicyId)->where('is_active', 1 )->get()->getRow(); - $temp['is_value_exist'] = true; - $temp['data']['family_floater_key'] = $familyFloatesValue; - $temp['data']['employee_id'] = $value['id']; - $temp['data']['relationship'] = $value['relationship']; - $temp['data']['name'] = $value['name']; - $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); - $temp['data']['client_policy_id'] = $array->ClientPolicyId; - $temp['data']['form_type'] = $dependent; - $temp['data']['basic_cover_si'] = $employee_policy->basic_cover_si; - - - $temp['data']['age_validation'] = $this->getAgeRange($decodedArray,$familyFloatesValue); - - array_push($data,$temp); - unset($empData[$key]); - $floters = array_diff($floters, [$familyFloatesValue]); - break; - } - } - } - } - - - - // Remove Unwanted floter key from floters array based on either-parents-pil term value - if($familyFloates->{'either-parents-pil'} == 1 && count($floters)) - { - $count_parent = 0; - $count_parent_in_law = 0; - foreach ($floters as $value) { - if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } - if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;} - } - if($count_parent != 2) { - $floters = array_filter($floters, fn($value) => strpos($value, 'parent_in_law') === false); - } - if($count_parent_in_law != 2) { - $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false); - } - } - else if($familyFloates->{'either-parents-pil'} == 2 && count($floters)) - { - $count_parent = 0; - $count_parent_in_law = 0; - foreach ($floters as $value) { - if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } - if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;} - } - if(($count_parent + $count_parent_in_law) == 2) { - $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false); - } - - } - - - // Add family floter buttons placement data for FE validation - if(count($floters)){ - foreach ($floters as $familyFloatesValue) { - - $temp2['is_value_exist'] = false; - $temp2['data']['family_floater_key'] = $familyFloatesValue; - $temp2['data']['client_policy_id'] = $array->ClientPolicyId; - $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); - $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue); - - - $temp2['data']['age_validation'] = $this->getAgeRange($decodedArray,$familyFloatesValue); - - array_push($data,$temp2); - - } - } - - $array->mapped_family_floaters = $data; - $array->type = "Group Medical Coverage"; - - $checkGmcParentsPolicyExist = $this->clientPolicyModel->select('client_policy.id as ClientPolicyId , client_policy.client_id as ClientId, policies.id as PolicyId , client_policy.policy_type_id as policy_type_id, policies.name as Policy_Name , client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type , client_policy.policy_terms as Policy_Terms') - ->join('policies', 'client_policy.policy_id = policies.id', 'left') - ->where('client_policy.policy_type_id', 3 ) - ->where('client_policy.is_addon', 1 ) - ->where('client_policy.client_id', $this->request->getGet('client_id') ) - ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) - ->where('client_policy.is_active', 1 ) - ->get() - ->getResult(); - if($checkGmcParentsPolicyExist) - { - $GmcParrentsData = $this->getGmcParrentsPolicy($checkGmcParentsPolicyExist,$emp_code,$client_id,$client_branch_id); - return $this->respond(['status' => 'success','code' => 200,'data' => [$array,$GmcParrentsData]], 200); - - } - - if($this->request->getGet('policy') == 'GMC'){ - return $this->respond(['status' => 'success','code' => 200,'data' => [$array]], 200); - } - - } - - // $result[] = $array; - } - - return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); - - - }else{ - return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200); - } - // } catch (\Exception $e) { - // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); - // } -} - - -public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$client_branch_id) -{ - - $employeeData = $this->employeeModel->where('emp_code',$emp_code) - ->where('client_id',$client_id) - ->where('client_branch_id',$client_branch_id) - ->where('is_active', 1 ) - ->where('is_addon_value',0)->findAll(); - foreach ($GmcParrentsPolicy as $key => $array) { - - - - // Reset employee array - $empData = $employeeData; - - - $array->Policy_Terms = json_decode($array->Policy_Terms); - - - // Retrieve slab rate and grid master data by passing the ClientPolicyId and ClientId - $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId); - $array->SlabRates = $getSlabAndGridData['slab_rates']; - $array->GridMaster = $getSlabAndGridData['grid_master']; - - $tpaArray = $this->employeeModel->select('employees.name as name , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') - ->join('employee_polices', 'employee_polices.employee_id = employees.id') - ->where('employees.emp_code',$emp_code) - ->where('employees.is_active',1) - ->where('employee_polices.client_policy_id',$array->ClientPolicyId) - ->get() - ->getResult(); - - if(count($tpaArray)) - { - - if($tpaArray[0]->tpa_id != null) - $array->eCardDownload = base_url('download-e-card/') . $tpaArray[0]->rand_string; - else - $array->eCardDownload = null; - - }else{ - $array->eCardDownload = null; - } - - - $array->eCardDownload = null; - - // Map family floaters that already exist in the employee table - $familyFloates = $array->Policy_Terms->family_floaters; - - // Generate Notes string based on familyFloates terms - $array->notes = $this->FloterNotesConvertion($familyFloates); - - if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) - { - $array->floter_text_heading = 'Floater Sum Insured'; - $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.'; - }else{ - $array->floter_text_heading = 'Sum Insured'; - $array->floter_text_description = ''; - } - - - // remove parent and parent-in-law from familyFloaters - if($familyFloates->{'either-parents-pil'} != 0){ - unset($familyFloates->parents); - unset($familyFloates->parents_in_law); - } - - // Convert familyFloaters terms data to plain array - $floters = $this->FloterConvertion($familyFloates); - $data = []; - foreach ($floters as $familyFloatesValue) { - $dependent = preg_replace('/\d/', '', $familyFloatesValue); - - - if(count($empData)){ - foreach ($empData as $key => $value) { - if ($value['family_floater_key'] === $dependent) { - $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array->ClientPolicyId)->where('is_active', 1 )->get()->getRow(); - // dd( $employee_policy); - $temp['is_value_exist'] = true; - $temp['data']['family_floater_key'] = $familyFloatesValue; - $temp['data']['employee_id'] = $value['id']; - $temp['data']['relationship'] = $value['relationship']; - $temp['data']['name'] = $value['name']; - $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); - $temp['data']['client_policy_id'] = $array->ClientPolicyId; - $temp['data']['form_type'] = $dependent; - $temp['data']['basic_cover_si'] = $employee_policy->basic_cover_si; - $temp['data']['age_validation'] = $this->getAgeRange($array->Policy_Terms,$familyFloatesValue); - - - array_push($data,$temp); - unset($empData[$key]); - $floters = array_diff($floters, [$familyFloatesValue]); - break; - } - } - } - } - - // Remove Unwanted floter key from floters array based on either-parents-pil term value - if($familyFloates->{'either-parents-pil'} == 1 && count($floters)) - { - $count_parent = 0; - $count_parent_in_law = 0; - foreach ($floters as $value) { - if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } - if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;} - } - if($count_parent != 2) { - $floters = array_filter($floters, fn($value) => strpos($value, 'parent_in_law') === false); - } - if($count_parent_in_law != 2) { - $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false); - } - } - else if($familyFloates->{'either-parents-pil'} == 2 && count($floters)) - { - $count_parent = 0; - $count_parent_in_law = 0; - foreach ($floters as $value) { - if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } - if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;} - } - if(($count_parent + $count_parent_in_law) == 2) { - $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false); - } - - } - - // Add family floter buttons placement data for FE validation - if(count($floters)){ - foreach ($floters as $familyFloatesValue) { - - $temp2['is_value_exist'] = false; - $temp2['data']['family_floater_key'] = $familyFloatesValue; - $temp2['data']['client_policy_id'] = $array->ClientPolicyId; - $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); - $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue); - $temp2['data']['age_validation'] = $this->getAgeRange($array->Policy_Terms,$familyFloatesValue); - array_push($data,$temp2); - - } - } - - $array->mapped_family_floaters = $data; - $array->type = "Group Medical Coverage - Parents"; - - return $array; - - } - -} - -public function FloterConvertion($array){ - - $result = []; - - foreach ($array as $key => $value) { - if ($value > 0 && $key != 'elders_count') { - if ($value != 0 && $key === 'childrens') { - for ($i = 1; $i <= $value; $i++) { - $result[] = "child" . $i; - } - } else if($value != 0 && $key ==='parents') { - for ($i = 1; $i <= $value; $i++) { - $result[] = "parent" . $i; - } - }else if($value != 0 && $key ==='parents-in-law') { - for ($i = 1; $i <= $value; $i++) { - $result[] = "parent_in_law" . $i; - } - }else if($value != 0 && $key ==='either-parents-pil') { - for ($i = 1; $i <= 2; $i++) { - $result[] = "parent" . $i; - $result[] = "parent_in_law" . $i; - } - }else { - $result[] = $key; - } - } - } - - return $result; -} - -public function FloterNotesConvertion($array){ - - $result = ' '; - foreach ($array as $key => $value) { - if ($value > 0) { - if($value != 0 && $key ==='either-parents-pil') { - $result .= ' + Either 2 Parents or 2 Parents in law'; - }else if($value != 0 && $key ==='spouse') { - $string = str_replace('-', ' ', $key); - $string = ucwords($string); - $result .= ' + '.$string; - }else if($value != 0 && $key ==='self') { - $result = 'Can Add Self '; - }else if($value != 0 && $key ==='childrens') { - if($value > 1){ $result .= ' + '.$value.' Children'; }else{ $result .= ' + '.$value.' Child'; } - }else{ - $string = str_replace('-', ' ', $key); - $string = ucwords($string); - $result .= ' + '.$value.' '.$string; - } - } - } + //------------------------------------- + public function getAgeRange($terms,$familyFloatesValue) + { - return $result; -} - -public function getClientDetails() -{ - try { - - $client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first(); - if($client) { - $client['client_logo'] = base_url().'public/uploads/logo/'.$client['client_logo']; - $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id')) - ->where('client_branch_id',$this->request->getGet('client_branch_id'))->findAll(); - return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$clientPolicy]], 200); + $ageRangeArray = ['self' => ['min' => 18, 'max' => 60] , 'spouse' => ['min' => 18, 'max' => 60] , 'child' => ['min' => 0, 'max' => 25] , 'elders' => ['min' => 18, 'max' => 60] ]; + $ageKey = (preg_replace('/\d/', '', $familyFloatesValue) == 'parent' || preg_replace('/\d/', '', $familyFloatesValue) == 'parent_in_law') ? 'elders' : preg_replace('/\d/', '', $familyFloatesValue); + if(isset($terms->age_ratio)){ + return $terms->age_ratio->$ageKey; }else{ - return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404); + return $ageRangeArray[$ageKey]; } - } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + + } -} -public function getAddOnPolicy() -{ - try { + public function getEmployeePolicy() + { + // try { - $addOnEmployeeData = $this->employeeModel->where('is_active', 1 ) - ->where('emp_code',$this->request->getGet('emp_code')) - ->where('client_id',$this->request->getGet('client_id')) - ->where('client_branch_id',$this->request->getGet('client_branch_id')) - ->where('is_addon_value',1)->findAll(); + $id = $this->request->getGet('id'); + $emp_code = $this->request->getGet('emp_code'); + $client_id = $this->request->getGet('client_id'); + $client_branch_id = $this->request->getGet('client_branch_id'); - + // This is an array containing keys to be removed from the terms and conditions array + $keysToRemove = ["removable_keys"]; + // Retrieve employee policy data by passing the employee primary key + $empPolicy = $this->employeeModel->getEmployeePolicy($id); - $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id')) - ->where('client_branch_id',$this->request->getGet('client_branch_id')) - ->where('policy_status', 1) - ->findAll(); - - if(count($clientPolicy)) - { - $band = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('client_branch_id',$this->request->getGet('client_branch_id'))->where('family_floater_key','self')->get()->getRow()->band; + // Retrieve employee and dependents data by passing the employee code + $employeeData = $this->employeeModel->where('emp_code',$emp_code) + ->where('client_id',$client_id) + ->where('client_branch_id',$client_branch_id) + ->where('is_active', 1 ) + ->where('is_addon_value',0)->findAll(); - $PolicyData = []; - foreach ($clientPolicy as $key => $array) { - $responce = []; - - $decodedArray = json_decode($array['policy_terms']); - $policy_terms = $decodedArray; - $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array['id'],$array['client_id']); - $uniqueData = []; - $siValues = []; - foreach ($getSlabAndGridData['slab_rates'] as $item) { - if($getSlabAndGridData['grid_master']['emp_band'] == 1 ){ - if ($item['grade'] == $band) { - $uniqueData[] = $item; - } - }else{ - if (!in_array($item['si'], $siValues) ) { + + if ($empPolicy) { - if ($item['policy_grid_id'] == 11 && ($item['max_si'] != 0 || $item['max_si'] != null)) { - $uniqueData[] = $item; - $siValues[] = $item['si']; - }else if($item['policy_grid_id'] != 11){ - $uniqueData[] = $item; - $siValues[] = $item['si']; - } - - } - } - - } + $result = []; + foreach ($empPolicy as $array) { + // Reset employee array + $empData = $employeeData; - + + // Removes specific keys from the decoded array and assigns the result to $refusingData + $decodedArray = json_decode($array->Policy_Terms); + $refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove)); + $array->Policy_Terms = $refusingData; - $responce['policy_name'] = $this->policesModel->where('id',$array['policy_id'])->get()->getRow()->name; - $responce['SlabRates'] = $uniqueData; - $responce['GridMaster'] = $getSlabAndGridData['grid_master']; - $responce['client_id'] = $array['client_id']; - $responce['client_policy_id'] = $array['id']; - $responce['is_addon'] = $array['is_addon']; - $responce['OpenForEnrollment'] = $array['open_for_enrollment']; - $responce['policy_terms'] = $decodedArray; - $responce['policy_type_id'] = $array['policy_type_id']; + // Retrieve slab rate and grid master data by passing the ClientPolicyId and ClientId + $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId); + $array->SlabRates = $getSlabAndGridData['slab_rates']; + $array->GridMaster = $getSlabAndGridData['grid_master']; - $tpaArray = $this->employeeModel->select('employees.name as name , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') - ->join('employee_polices', 'employee_polices.employee_id = employees.id') - ->where('employees.emp_code',$this->request->getGet('emp_code')) - ->where('employees.is_active',1) - ->where('employee_polices.client_policy_id',$array['id']) - ->get() - ->getResult(); - - if(count($tpaArray)) - { - if($tpaArray[0]->tpa_id != null) - $responce['eCardDownload'] = base_url('download-e-card/') . $tpaArray[0]->rand_string; - else - $responce['eCardDownload'] = null; + if($array->tpa_id != null){ + $array->eCardDownload = base_url('download-e-card/') . $array->rand_string; + }else{ $array->eCardDownload = null; } - }else{ - $responce['eCardDownload'] = null; - } - - if(count($getSlabAndGridData['slab_rates'])){ - if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) - { - $responce['floter_text_heading'] = 'Floater Sum Insured'; - }else{ - $responce['floter_text_heading'] = 'Sum Insured'; - } - } - - if($array['is_addon'] == 3 && $array['policy_type_id'] == 3)//dependent add on policy - { + // Construct value for policy type GPA + if($getSlabAndGridData['grid_master']['policy_type'] == "GPA" && $this->request->getGet('policy') == 'GPA'){ + + // Filter employee data where the family_floater_key is 'self' + $selfData = array_filter($empData, fn($arr) => trim(strtolower($arr['family_floater_key'])) === 'self'); + $employee_policy = $this->employeePolicyModel->where('employee_id',$selfData[0]['id'])->where('client_policy_id',$array->ClientPolicyId)->where('is_active', 1 )->get()->getRow(); + + $self['is_value_exist'] = true; + $self['data']['family_floater_key'] = 'self'; + $self['data']['employee_id'] = $id; + $self['data']['relationship'] = 'Self'; + $self['data']['name'] = $selfData[0]['name']; + $self['data']['dob'] = $this->convertDateFormatDMY($selfData[0]['dob']); + $self['data']['mobile'] = $selfData[0]['mobile']; + $self['data']['client_policy_id'] = $array->ClientPolicyId; + $self['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + + $array->mapped_family_floaters = $self; + + // Return result + if($this->request->getGet('policy') == 'GPA') + { + return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200); + } + // Construct value for policy type GMC + }else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC" && $this->request->getGet('policy') == 'GMC' ){ - // Map family floaters that already exist in the employee table - $familyFloates = $policy_terms->family_floaters; - // remove parent and parent-in-law from familyFloaters - if($familyFloates->{'either-parents-pil'} != 0){ - unset($familyFloates->parents); - unset($familyFloates->parents_in_law); - } - // Convert familyFloaters terms data to plain array - $floters = $this->FloterConvertion($familyFloates); + + + // Map family floaters that already exist in the employee table + $familyFloates = $array->Policy_Terms->family_floaters; + + // Generate Notes string based on familyFloates terms + $array->notes = $this->FloterNotesConvertion($familyFloates); + + if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) + { + $array->floter_text_heading = 'Floater Sum Insured'; + $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.'; + }else{ + $array->floter_text_heading = 'Sum Insured'; + $array->floter_text_description = ''; + } + // remove parent and parent-in-law from familyFloaters + if($familyFloates->{'either-parents-pil'} != 0){ + unset($familyFloates->parents); + unset($familyFloates->parents_in_law); + } + $floters = $this->FloterConvertion($familyFloates); - $data = []; - $dependent_and_si_value = 0; - $dependent_and_si_premium_value = 0; - $dependent_and_si_gst_value = 0; - foreach ($floters as $familyFloatesValue) { - $dependent = preg_replace('/\d/', '', $familyFloatesValue); - if(count($addOnEmployeeData)){ - foreach ($addOnEmployeeData as $key => $value) { - if ($value['family_floater_key'] === $dependent) { - $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); - if(isset($employee_policy->basic_cover_si)){ $dependent_and_si_value = $employee_policy->basic_cover_si; } - if(isset($employee_policy->premium)){ $dependent_and_si_premium_value = $dependent_and_si_premium_value + $employee_policy->premium;} - if(isset($employee_policy->gst)){ $dependent_and_si_gst_value = $dependent_and_si_gst_value + $employee_policy->gst;} - - $temp['is_value_exist'] = true; - $temp['data']['family_floater_key'] = $familyFloatesValue; - $temp['data']['employee_id'] = $value['id']; - $temp['data']['relationship'] = $value['relationship']; - $temp['data']['name'] = $value['name']; - $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); - $temp['data']['client_policy_id'] = $array['id']; - $temp['data']['form_type'] = $dependent; - $temp['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; - $temp['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; - $temp['data']['age_validation'] = $this->getAgeRange($decodedArray,$familyFloatesValue); - - array_push($data,$temp); - unset($addOnEmployeeData[$key]); - $floters = array_diff($floters, [$familyFloatesValue]); - break; + $data = []; + foreach ($floters as $familyFloatesValue) { + $dependent = preg_replace('/\d/', '', $familyFloatesValue); + + if(count($empData)){ + foreach ($empData as $key => $value) { + if ($value['family_floater_key'] === $dependent) { + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array->ClientPolicyId)->where('is_active', 1 )->get()->getRow(); + $temp['is_value_exist'] = true; + $temp['data']['family_floater_key'] = $familyFloatesValue; + $temp['data']['employee_id'] = $value['id']; + $temp['data']['relationship'] = $value['relationship']; + $temp['data']['name'] = $value['name']; + $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp['data']['client_policy_id'] = $array->ClientPolicyId; + $temp['data']['form_type'] = $dependent; + $temp['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + + + $temp['data']['age_validation'] = $this->getAgeRange($decodedArray,$familyFloatesValue); + + array_push($data,$temp); + unset($empData[$key]); + $floters = array_diff($floters, [$familyFloatesValue]); + break; + } } } } - } - - //Remove Unwanted floter key from floters array based on either-parents-pil term value - if($familyFloates->{'either-parents-pil'} == 1 && count($floters)) - { - if(count($addOnEmployeeData) == 0) - { - $GMCEmpData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) - ->where('is_addon_value',0) - ->where('is_active', 1 ) - ->where('family_floater_key','parent') - ->findAll(); - - if(count($GMCEmpData) > 0){ - $floters = array_diff($floters, ["parent1","parent2"]); - }else{ - $floters = array_diff($floters, ["parent_in_law1","parent_in_law2"]); - } - }else{ + + // Remove Unwanted floter key from floters array based on either-parents-pil term value + if($familyFloates->{'either-parents-pil'} == 1 && count($floters)) + { $count_parent = 0; $count_parent_in_law = 0; foreach ($floters as $value) { @@ -1569,25 +1089,8 @@ public function getAddOnPolicy() $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false); } } - - - } - else if($familyFloates->{'either-parents-pil'} == 2 && count($floters)) - { - if(count($addOnEmployeeData) == 0) + else if($familyFloates->{'either-parents-pil'} == 2 && count($floters)) { - $GMCEmpData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) - ->where('is_addon_value',0) - ->where('is_active', 1 ) - ->where('family_floater_key','parent') - ->findAll(); - - if(count($GMCEmpData) > 0){ - $floters = array_diff($floters, ["parent1","parent2"]); - }else{ - $floters = array_diff($floters, ["parent_in_law1","parent_in_law2"]); - } - }else{ $count_parent = 0; $count_parent_in_law = 0; foreach ($floters as $value) { @@ -1597,726 +1100,1278 @@ public function getAddOnPolicy() if(($count_parent + $count_parent_in_law) == 2) { $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false); } + + } + + + // Add family floter buttons placement data for FE validation + if(count($floters)){ + foreach ($floters as $familyFloatesValue) { + + $temp2['is_value_exist'] = false; + $temp2['data']['family_floater_key'] = $familyFloatesValue; + $temp2['data']['client_policy_id'] = $array->ClientPolicyId; + $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); + $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue); + + + $temp2['data']['age_validation'] = $this->getAgeRange($decodedArray,$familyFloatesValue); + + array_push($data,$temp2); + } - } + $array->mapped_family_floaters = $data; + $array->type = "Group Medical Coverage"; + + $checkGmcParentsPolicyExist = $this->clientPolicyModel->select('client_policy.id as ClientPolicyId , client_policy.client_id as ClientId, policies.id as PolicyId , client_policy.policy_type_id as policy_type_id, policies.name as Policy_Name , client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type , client_policy.policy_terms as Policy_Terms') + ->join('policies', 'client_policy.policy_id = policies.id', 'left') + ->where('client_policy.policy_type_id', 3 ) + ->where('client_policy.is_addon', 1 ) + ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) + ->where('client_policy.is_active', 1 ) + ->get() + ->getResult(); + if($checkGmcParentsPolicyExist) + { + $GmcParrentsData = $this->getGmcParrentsPolicy($checkGmcParentsPolicyExist,$emp_code,$client_id,$client_branch_id); + return $this->respond(['status' => 'success','code' => 200,'data' => [$array,$GmcParrentsData]], 200); + + } + if($this->request->getGet('policy') == 'GMC'){ + return $this->respond(['status' => 'success','code' => 200,'data' => [$array]], 200); + } + + } + + // $result[] = $array; + } + + return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); - // Add family floter buttons placement data for FE validation - if(count($floters)){ - foreach ($floters as $familyFloatesValue) { - $temp2['is_value_exist'] = false; - $temp2['data']['family_floater_key'] = $familyFloatesValue; - $temp2['data']['client_policy_id'] = $array['id']; - $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); - $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue); - - $temp2['data']['age_validation'] = $this->getAgeRange($decodedArray,$familyFloatesValue); + }else{ + return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200); + } + // } catch (\Exception $e) { + // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + // } + } - array_push($data,$temp2); + public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$client_branch_id) + { + + $employeeData = $this->employeeModel->where('emp_code',$emp_code) + ->where('client_id',$client_id) + ->where('client_branch_id',$client_branch_id) + ->where('is_active', 1 ) + ->where('is_addon_value',0)->findAll(); + foreach ($GmcParrentsPolicy as $key => $array) { + + + + // Reset employee array + $empData = $employeeData; + + + $array->Policy_Terms = json_decode($array->Policy_Terms); + + + // Retrieve slab rate and grid master data by passing the ClientPolicyId and ClientId + $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId); + $array->SlabRates = $getSlabAndGridData['slab_rates']; + $array->GridMaster = $getSlabAndGridData['grid_master']; + + $tpaArray = $this->employeeModel->select('employees.name as name , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('employees.emp_code',$emp_code) + ->where('employees.is_active',1) + ->where('employee_polices.client_policy_id',$array->ClientPolicyId) + ->get() + ->getResult(); + + if(count($tpaArray)) + { + + if($tpaArray[0]->tpa_id != null) + $array->eCardDownload = base_url('download-e-card/') . $tpaArray[0]->rand_string; + else + $array->eCardDownload = null; + + }else{ + $array->eCardDownload = null; + } + + + $array->eCardDownload = null; + + // Map family floaters that already exist in the employee table + $familyFloates = $array->Policy_Terms->family_floaters; + + // Generate Notes string based on familyFloates terms + $array->notes = $this->FloterNotesConvertion($familyFloates); + + if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) + { + $array->floter_text_heading = 'Floater Sum Insured'; + $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.'; + }else{ + $array->floter_text_heading = 'Sum Insured'; + $array->floter_text_description = ''; + } + + + // remove parent and parent-in-law from familyFloaters + if($familyFloates->{'either-parents-pil'} != 0){ + unset($familyFloates->parents); + unset($familyFloates->parents_in_law); + } + + // Convert familyFloaters terms data to plain array + $floters = $this->FloterConvertion($familyFloates); + $data = []; + foreach ($floters as $familyFloatesValue) { + $dependent = preg_replace('/\d/', '', $familyFloatesValue); + + + if(count($empData)){ + foreach ($empData as $key => $value) { + if ($value['family_floater_key'] === $dependent) { + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array->ClientPolicyId)->where('is_active', 1 )->get()->getRow(); + // dd( $employee_policy); + $temp['is_value_exist'] = true; + $temp['data']['family_floater_key'] = $familyFloatesValue; + $temp['data']['employee_id'] = $value['id']; + $temp['data']['relationship'] = $value['relationship']; + $temp['data']['name'] = $value['name']; + $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp['data']['client_policy_id'] = $array->ClientPolicyId; + $temp['data']['form_type'] = $dependent; + $temp['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + $temp['data']['age_validation'] = $this->getAgeRange($array->Policy_Terms,$familyFloatesValue); + + + array_push($data,$temp); + unset($empData[$key]); + $floters = array_diff($floters, [$familyFloatesValue]); + break; + } } - } + } + } - $responce['family_floaters_of_dependent_and_si_array'] = $data; - $responce['family_floaters_of_dependent_and_si_value'] = $dependent_and_si_value; - $responce['family_floaters_of_dependent_and_si_premium_value'] = $dependent_and_si_premium_value; - $responce['family_floaters_of_dependent_and_gst_value'] = $dependent_and_si_gst_value; + // Remove Unwanted floter key from floters array based on either-parents-pil term value + if($familyFloates->{'either-parents-pil'} == 1 && count($floters)) + { + $count_parent = 0; + $count_parent_in_law = 0; + foreach ($floters as $value) { + if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } + if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;} + } + if($count_parent != 2) { + $floters = array_filter($floters, fn($value) => strpos($value, 'parent_in_law') === false); + } + if($count_parent_in_law != 2) { + $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false); + } + } + else if($familyFloates->{'either-parents-pil'} == 2 && count($floters)) + { + $count_parent = 0; + $count_parent_in_law = 0; + foreach ($floters as $value) { + if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } + if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;} + } + if(($count_parent + $count_parent_in_law) == 2) { + $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false); + } + + } + + // Add family floter buttons placement data for FE validation + if(count($floters)){ + foreach ($floters as $familyFloatesValue) { + + $temp2['is_value_exist'] = false; + $temp2['data']['family_floater_key'] = $familyFloatesValue; + $temp2['data']['client_policy_id'] = $array->ClientPolicyId; + $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); + $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue); + $temp2['data']['age_validation'] = $this->getAgeRange($array->Policy_Terms,$familyFloatesValue); + array_push($data,$temp2); + + } + } + + $array->mapped_family_floaters = $data; + $array->type = "Group Medical Coverage - Parents"; + + return $array; + + } + + } + + public function FloterConvertion($array){ + + $result = []; + + foreach ($array as $key => $value) { + if ($value > 0 && $key != 'elders_count') { + if ($value != 0 && $key === 'childrens') { + for ($i = 1; $i <= $value; $i++) { + $result[] = "child" . $i; + } + } else if($value != 0 && $key ==='parents') { + for ($i = 1; $i <= $value; $i++) { + $result[] = "parent" . $i; + } + }else if($value != 0 && $key ==='parents-in-law') { + for ($i = 1; $i <= $value; $i++) { + $result[] = "parent_in_law" . $i; + } + }else if($value != 0 && $key ==='either-parents-pil') { + for ($i = 1; $i <= 2; $i++) { + $result[] = "parent" . $i; + $result[] = "parent_in_law" . $i; + } + }else { + $result[] = $key; + } + } + } + + return $result; + } + + public function FloterNotesConvertion($array){ + + $result = ' '; + foreach ($array as $key => $value) { + if ($value > 0) { + if($value != 0 && $key ==='either-parents-pil') { + $result .= ' + Either 2 Parents or 2 Parents in law'; + }else if($value != 0 && $key ==='spouse') { + $string = str_replace('-', ' ', $key); + $string = ucwords($string); + $result .= ' + '.$string; + }else if($value != 0 && $key ==='self') { + $result = 'Can Add Self '; + }else if($value != 0 && $key ==='childrens') { + if($value > 1){ $result .= ' + '.$value.' Children'; }else{ $result .= ' + '.$value.' Child'; } + }else{ + $string = str_replace('-', ' ', $key); + $string = ucwords($string); + $result .= ' + '.$value.' '.$string; + } + } + } + + return $result; + } + + public function getClientDetails() + { + try { + + $client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first(); + if($client) { + $client['client_logo'] = base_url().'public/uploads/logo/'.$client['client_logo']; + $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id')) + ->where('client_branch_id',$this->request->getGet('client_branch_id'))->findAll(); + return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$clientPolicy]], 200); + + }else{ + return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404); + } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } + } + + public function getAddOnPolicy() + { + try { + + $addOnEmployeeData = $this->employeeModel->where('is_active', 1 ) + ->where('emp_code',$this->request->getGet('emp_code')) + ->where('client_id',$this->request->getGet('client_id')) + ->where('client_branch_id',$this->request->getGet('client_branch_id')) + ->where('is_addon_value',1)->findAll(); + + + + $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id')) + ->where('client_branch_id',$this->request->getGet('client_branch_id')) + ->where('policy_status', 1) + ->findAll(); + + if(count($clientPolicy)) + { + $band = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('client_branch_id',$this->request->getGet('client_branch_id'))->where('family_floater_key','self')->get()->getRow()->band; + + $PolicyData = []; + foreach ($clientPolicy as $key => $array) { + $responce = []; + + $decodedArray = json_decode($array['policy_terms']); + $policy_terms = $decodedArray; + $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array['id'],$array['client_id']); + $uniqueData = []; + $siValues = []; + foreach ($getSlabAndGridData['slab_rates'] as $item) { + if($getSlabAndGridData['grid_master']['emp_band'] == 1 ){ + if ($item['grade'] == $band) { + $uniqueData[] = $item; + } + }else{ + if (!in_array($item['si'], $siValues) ) { + + if ($item['policy_grid_id'] == 11 && ($item['max_si'] != 0 || $item['max_si'] != null)) { + $uniqueData[] = $item; + $siValues[] = $item['si']; + }else if($item['policy_grid_id'] != 11){ + $uniqueData[] = $item; + $siValues[] = $item['si']; + } + + } + } + + } + + + + $responce['policy_name'] = $this->policesModel->where('id',$array['policy_id'])->get()->getRow()->name; + $responce['SlabRates'] = $uniqueData; + $responce['GridMaster'] = $getSlabAndGridData['grid_master']; + $responce['client_id'] = $array['client_id']; + $responce['client_policy_id'] = $array['id']; + $responce['is_addon'] = $array['is_addon']; + $responce['OpenForEnrollment'] = $array['open_for_enrollment']; + $responce['policy_terms'] = $decodedArray; + $responce['policy_type_id'] = $array['policy_type_id']; + + $tpaArray = $this->employeeModel->select('employees.name as name , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('employees.emp_code',$this->request->getGet('emp_code')) + ->where('employees.is_active',1) + ->where('employee_polices.client_policy_id',$array['id']) + ->get() + ->getResult(); + + if(count($tpaArray)) + { + if($tpaArray[0]->tpa_id != null) + $responce['eCardDownload'] = base_url('download-e-card/') . $tpaArray[0]->rand_string; + else + $responce['eCardDownload'] = null; + + }else{ + $responce['eCardDownload'] = null; + } + + if(count($getSlabAndGridData['slab_rates'])){ + if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) + { + $responce['floter_text_heading'] = 'Floater Sum Insured'; + }else{ + $responce['floter_text_heading'] = 'Sum Insured'; + } + } + + + if($array['is_addon'] == 3 && $array['policy_type_id'] == 3)//dependent add on policy + { + + + // Map family floaters that already exist in the employee table + $familyFloates = $policy_terms->family_floaters; + // remove parent and parent-in-law from familyFloaters + if($familyFloates->{'either-parents-pil'} != 0){ + unset($familyFloates->parents); + unset($familyFloates->parents_in_law); + } + // Convert familyFloaters terms data to plain array + $floters = $this->FloterConvertion($familyFloates); + + + $data = []; + $dependent_and_si_value = 0; + $dependent_and_si_premium_value = 0; + $dependent_and_si_gst_value = 0; + foreach ($floters as $familyFloatesValue) { + $dependent = preg_replace('/\d/', '', $familyFloatesValue); + if(count($addOnEmployeeData)){ + foreach ($addOnEmployeeData as $key => $value) { + if ($value['family_floater_key'] === $dependent) { + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); + if(isset($employee_policy->basic_cover_si)){ $dependent_and_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->premium)){ $dependent_and_si_premium_value = $dependent_and_si_premium_value + $employee_policy->premium;} + if(isset($employee_policy->gst)){ $dependent_and_si_gst_value = $dependent_and_si_gst_value + $employee_policy->gst;} + + $temp['is_value_exist'] = true; + $temp['data']['family_floater_key'] = $familyFloatesValue; + $temp['data']['employee_id'] = $value['id']; + $temp['data']['relationship'] = $value['relationship']; + $temp['data']['name'] = $value['name']; + $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp['data']['client_policy_id'] = $array['id']; + $temp['data']['form_type'] = $dependent; + $temp['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; + $temp['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; + $temp['data']['age_validation'] = $this->getAgeRange($decodedArray,$familyFloatesValue); + + array_push($data,$temp); + unset($addOnEmployeeData[$key]); + $floters = array_diff($floters, [$familyFloatesValue]); + break; + } + } + } + } + + + //Remove Unwanted floter key from floters array based on either-parents-pil term value + if($familyFloates->{'either-parents-pil'} == 1 && count($floters)) + { + if(count($addOnEmployeeData) == 0) + { + $GMCEmpData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value',0) + ->where('is_active', 1 ) + ->where('family_floater_key','parent') + ->findAll(); + + if(count($GMCEmpData) > 0){ + $floters = array_diff($floters, ["parent1","parent2"]); + }else{ + $floters = array_diff($floters, ["parent_in_law1","parent_in_law2"]); + } + }else{ + + $count_parent = 0; + $count_parent_in_law = 0; + foreach ($floters as $value) { + if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } + if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;} + } + if($count_parent != 2) { + $floters = array_filter($floters, fn($value) => strpos($value, 'parent_in_law') === false); + } + if($count_parent_in_law != 2) { + $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false); + } + } + + + } + else if($familyFloates->{'either-parents-pil'} == 2 && count($floters)) + { + if(count($addOnEmployeeData) == 0) + { + $GMCEmpData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value',0) + ->where('is_active', 1 ) + ->where('family_floater_key','parent') + ->findAll(); + + if(count($GMCEmpData) > 0){ + $floters = array_diff($floters, ["parent1","parent2"]); + }else{ + $floters = array_diff($floters, ["parent_in_law1","parent_in_law2"]); + } + }else{ + $count_parent = 0; + $count_parent_in_law = 0; + foreach ($floters as $value) { + if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } + if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;} + } + if(($count_parent + $count_parent_in_law) == 2) { + $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false); + } + } + + } - + // Add family floter buttons placement data for FE validation + if(count($floters)){ + foreach ($floters as $familyFloatesValue) { - if($this->request->getGet('policy') == 'GMC-DEPENDENT-ADDON'){ - return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_dependent_addon'=>$responce]], 200); - } - - //array_push($PolicyData, $responce); + $temp2['is_value_exist'] = false; + $temp2['data']['family_floater_key'] = $familyFloatesValue; + $temp2['data']['client_policy_id'] = $array['id']; + $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); + $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue); + + $temp2['data']['age_validation'] = $this->getAgeRange($decodedArray,$familyFloatesValue); - }else if($array['is_addon'] == 2 && $array['policy_type_id'] == 4)//Topup policy - { - + array_push($data,$temp2); - $whereArray = []; - foreach ( $decodedArray->family_floaters as $key => $value) { - if($value != 0){ - if($key == 'parents'){ $text = 'parent'; }else if($key == 'childrens'){ $text = 'child'; }else if($key == 'parents-in-law'){$text = 'parent_in_law';}else{ $text = $key; } - array_push($whereArray,$text); - } - } - - - $getAddOnType = $this->clientPolicyModel->where('id',$array['base_policy'])->where('policy_status', 1)->get()->getRow(); - $basePolicyAddOnType = $getAddOnType->is_addon; - // if is_addon value is 1 it is GMC if not it is one of the Add On policy - if($basePolicyAddOnType == 1){ $is_addon_value = 0; }else{ $is_addon_value = 1; } - $only_si_array = []; - $only_si_value = 0; - $only_si_premium_value = 0; - $only_si_gst_value = 0; - $BasePolicyEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',$is_addon_value)->whereIn('family_floater_key',$whereArray)->findAll(); - foreach ($BasePolicyEmployeeData as $key => $value) { - - $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); - if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } - if(isset($employee_policy->premium)){ $only_si_premium_value = $only_si_premium_value + $employee_policy->rata_premimum;} - if(isset($employee_policy->gst)){ $only_si_gst_value = $only_si_gst_value + $employee_policy->gst;} - $temp3['is_value_exist'] = true; - $temp3['data']['employee_id'] = $value['id']; - $temp3['data']['relationship'] = $value['relationship']; - $temp3['data']['name'] = $value['name']; - $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']); - $temp3['data']['client_policy_id'] = $array['id']; - $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; - $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; - array_push($only_si_array,$temp3); - - } - - $responce['family_floaters_of_only_si_array'] = $only_si_array; - $responce['family_floaters_of_only_si_value'] = $only_si_value; - $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; - $responce['family_floaters_of_only_si_gst_value'] = $only_si_gst_value; - $responce['type'] = "Group Medical Coverage - Top Up"; - - if($this->request->getGet('policy') == 'GMC-SI-TOPUP'){ - return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_topup'=>$responce]], 200); - } - - - }else if($array['is_addon'] == 2 && $array['policy_type_id'] == 5)//Parents Topup policy - { - - $whereArray = []; - foreach ( $decodedArray->family_floaters as $key => $value) { - if($value != 0){ - if($key == 'parents'){ $text = 'parent'; }else if($key == 'childrens'){ $text = 'child'; }else if($key == 'parents-in-law'){$text = 'parent_in_law';}else{ $text = $key; } - array_push($whereArray,$text); - } - } - - $getAddOnType = $this->clientPolicyModel->where('id',$array['base_policy'])->where('policy_status', 1)->get()->getRow(); - $basePolicyAddOnType = $getAddOnType->is_addon; - // if is_addon value is 1 it is GMC if not it is one of the Add On policy - if($basePolicyAddOnType == 1){ $is_addon_value = 0; }else{ $is_addon_value = 1; } - $only_si_array = []; - $only_si_value = 0; - $only_si_premium_value = 0; - $only_si_gst_value = 0; - $BasePolicyEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',$is_addon_value)->whereIn('family_floater_key',$whereArray)->findAll(); - foreach ($BasePolicyEmployeeData as $key => $value) { - - $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); - if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } - if(isset($employee_policy->premium)){ $only_si_premium_value = $only_si_premium_value + $employee_policy->rata_premimum;} - if(isset($employee_policy->gst)){ $only_si_gst_value = $only_si_gst_value + $employee_policy->gst;} - $temp3['is_value_exist'] = true; - $temp3['data']['employee_id'] = $value['id']; - $temp3['data']['relationship'] = $value['relationship']; - $temp3['data']['name'] = $value['name']; - $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']); - $temp3['data']['client_policy_id'] = $array['id']; - $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; - $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; - array_push($only_si_array,$temp3); - - } - - $responce['family_floaters_of_only_si_array'] = $only_si_array; - $responce['family_floaters_of_only_si_value'] = $only_si_value; - $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; - $responce['family_floaters_of_only_si_gst_value'] = $only_si_gst_value; - $responce['type'] = "Group Medical Coverage - Parents Top Up"; - - if($this->request->getGet('policy') == 'GMC-SI-PARENT-TOPUP'){ - return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_parent_topup'=>$responce]], 200); - } - - - } - - } - - - return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); - - }else{ - return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200); - } - } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); - } -} - -public function iAgreeForAddOn() -{ - $postData = json_decode($this->request->getBody(), true); - $client_policy_id = $postData['client_policy_id']; - sort($client_policy_id); - // Alternatively, you can use echo to see the type - $emp_code = $postData['emp_code']; - $client_id = $postData['client_id']; - - $this->employeeModel->where('emp_code', $emp_code ) - ->where('client_id', $client_id ) - ->where('is_active', 1 ) - ->set(array('emp_status'=>'enrolled')) - ->update(); - - $empData = $this->employeeModel->where('emp_code', $emp_code )->where('client_id', $client_id ) ->where('is_active', 1 )->findAll(); - - if (!is_null($client_policy_id) && is_array($client_policy_id)) - { - $array_list = []; - foreach ($client_policy_id as $key => $value) - { - foreach ($empData as $empDataKey => $empDataValue) - { - $this->employeePolicyModel->where('client_policy_id', $value ) - ->where('is_active', 1 ) - ->where('employee_id', $empDataValue['id'] ) - ->set(array('status'=>'enrolled')) - ->update(); - } - - $find = $this->employeeModel->getEmpFamilybyEmpCode(client_policy_id: $value,emp_code: $emp_code,client_id: $client_id,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); - if(count($find) > 0){ - $array_list[] = $find; - } - } - - $notification = $this->notificationModel->where('client_id' ,$client_id)->where('template_name', 'member_review_and_summary_mail')->first(); - - - if (isset($notification) && $notification['enabled'] == 1) { - $params ['array_list'] = $array_list; - $params ['client_policy_id'] = $client_policy_id; - $params ['emp_code'] = $emp_code; - $params ['client_id'] = $client_id; - $params ['notification'] = $notification; - // print_r($params);die; - $wholeData =sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params); - $mail_send_return = MailHelper::send_email($wholeData[0]); - $this->myLogger->logme("info", $mail_send_return); - - if (isset($wholeData[0])) { - - $account_manager_wholeData =sendMailNotification::sendMailNotification('account_maneger_summary_mail', $params); - - foreach ($account_manager_wholeData as $key => $value) { - $mail_send_return1 = MailHelper::send_email($value); - $this->myLogger->logme("info", $mail_send_return1); - } - - $client_hr_wholeData =sendMailNotification::sendMailNotification('client_hr_summary_mail', $params); - - foreach ($client_hr_wholeData as $key => $value) { - $mail_send_return2 = MailHelper::send_email($value); - $this->myLogger->logme("info", $mail_send_return2); - } - } - } - - } - - return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200); -} - -//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 -{ - 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); - - - $client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id']; - // get policy and rack details - $policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id,$client_policy_id); - $policy_type = $policy_terms[0]->is_addon; - $base_policy = $policy_terms[0]->base_policy; - $policy_terms = (array) $policy_terms[0];// convert obj to array - - //get policy slab rates - $slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); - // print_r($slab_details);die(); - - $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); - - if(!count($existing_famility_details) && $policy_type == 2)//top up addon only - { - //get basepolicy id then pull emplist from base policy if only current policy is DA addon policy and emplist is zero - // echo 'inside'; - $client_policy_id = $base_policy; - $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); - } - - $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception']; - // 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(); - 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_premimum($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si); - // dd($data); - $employee_data_group_by_family[$emp_id] = $data; - - } - - if($clientPolicyId != null && $empCode != null) - { - return $employee_data_group_by_family; - }else{ - // dd ($employee_data_group_by_family); - return $this->respond(['status' => 'success','code' => (count($employee_data_group_by_family) ? 200 : 404),'data' => [$employee_data_group_by_family] ], 200); - - } - -} - - -public function getCashDepositData() -{ - - $ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name') - ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left') - ->where('client_policy.client_id', $this->request->getGet('client_id') ) - ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) - ->where('client_policy.is_active', 1 ) - ->where('client_policy.policy_status', 1) - ->groupBy('client_policy.insurer_id') - ->findAll(); - $result = []; - - if(count($ClientPolicyData)) - { - foreach ($ClientPolicyData as $key => $value) { - - $data['clientId'] = $value['clientId']; - $data['insurerId'] = $value['insurerId']; - $data['insurerName'] = $value['insurer_name']; - $data['depositData'] = $this->clientPolicyModel->getdepositData($value['clientId'],$value['insurerId']); - $data['balance'] = count($data['depositData']) ? $data['depositData'][0]->balance : 0; - - $data['policyDetails'] = []; - $ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id , client_policy.policy_type_id as policy_type_id, policies.name as policy_name , client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type ') - ->join('policies', 'client_policy.policy_id = policies.id', 'left') - ->where('client_policy.insurer_id', $value['insurerId'] ) - ->where('client_policy.client_id', $this->request->getGet('client_id') ) - ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) - ->where('client_policy.is_active', 1 ) - ->where('client_policy.policy_status', 1) - ->findAll(); - // dd( $ClientPolicyData); - foreach ($ClientPolicyData as $key => $value) - { - - $value['type'] = $this->policyTypeModel->where('id',$value['policy_type_id'])->get()->getRow()->policy_type; - $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0,branch_id:$this->request->getGet('client_branch_id')); - $enrolledCount = 0; - $draftCount = 0; - if(count($employeeDetails)) - { - foreach ($employeeDetails as $item) { - if ($item['emp_status'] === 'enrolled') { - $enrolledCount++; - } elseif ($item['emp_status'] === 'draft') { - $draftCount++; } + } + + $responce['family_floaters_of_dependent_and_si_array'] = $data; + $responce['family_floaters_of_dependent_and_si_value'] = $dependent_and_si_value; + $responce['family_floaters_of_dependent_and_si_premium_value'] = $dependent_and_si_premium_value; + $responce['family_floaters_of_dependent_and_gst_value'] = $dependent_and_si_gst_value; + + + + + + if($this->request->getGet('policy') == 'GMC-DEPENDENT-ADDON'){ + return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_dependent_addon'=>$responce]], 200); + } + + //array_push($PolicyData, $responce); + + }else if($array['is_addon'] == 2 && $array['policy_type_id'] == 4)//Topup policy + { + + + $whereArray = []; + foreach ( $decodedArray->family_floaters as $key => $value) { + if($value != 0){ + if($key == 'parents'){ $text = 'parent'; }else if($key == 'childrens'){ $text = 'child'; }else if($key == 'parents-in-law'){$text = 'parent_in_law';}else{ $text = $key; } + array_push($whereArray,$text); } } - - $value['totalMembersCount'] = count($employeeDetails); - $value['membersCountOfEnrolled'] = $enrolledCount; - $value['membersCountOfDraft'] = $draftCount; - - array_push($data['policyDetails'],$value); + + + $getAddOnType = $this->clientPolicyModel->where('id',$array['base_policy'])->where('policy_status', 1)->get()->getRow(); + $basePolicyAddOnType = $getAddOnType->is_addon; + // if is_addon value is 1 it is GMC if not it is one of the Add On policy + if($basePolicyAddOnType == 1){ $is_addon_value = 0; }else{ $is_addon_value = 1; } + $only_si_array = []; + $only_si_value = 0; + $only_si_premium_value = 0; + $only_si_gst_value = 0; + $BasePolicyEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',$is_addon_value)->whereIn('family_floater_key',$whereArray)->findAll(); + foreach ($BasePolicyEmployeeData as $key => $value) { + + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); + if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->premium)){ $only_si_premium_value = $only_si_premium_value + $employee_policy->rata_premimum;} + if(isset($employee_policy->gst)){ $only_si_gst_value = $only_si_gst_value + $employee_policy->gst;} + $temp3['is_value_exist'] = true; + $temp3['data']['employee_id'] = $value['id']; + $temp3['data']['relationship'] = $value['relationship']; + $temp3['data']['name'] = $value['name']; + $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp3['data']['client_policy_id'] = $array['id']; + $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; + $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; + array_push($only_si_array,$temp3); + + } + + $responce['family_floaters_of_only_si_array'] = $only_si_array; + $responce['family_floaters_of_only_si_value'] = $only_si_value; + $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; + $responce['family_floaters_of_only_si_gst_value'] = $only_si_gst_value; + $responce['type'] = "Group Medical Coverage - Top Up"; + + if($this->request->getGet('policy') == 'GMC-SI-TOPUP'){ + return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_topup'=>$responce]], 200); + } + + + }else if($array['is_addon'] == 2 && $array['policy_type_id'] == 5)//Parents Topup policy + { + + $whereArray = []; + foreach ( $decodedArray->family_floaters as $key => $value) { + if($value != 0){ + if($key == 'parents'){ $text = 'parent'; }else if($key == 'childrens'){ $text = 'child'; }else if($key == 'parents-in-law'){$text = 'parent_in_law';}else{ $text = $key; } + array_push($whereArray,$text); + } + } + + $getAddOnType = $this->clientPolicyModel->where('id',$array['base_policy'])->where('policy_status', 1)->get()->getRow(); + $basePolicyAddOnType = $getAddOnType->is_addon; + // if is_addon value is 1 it is GMC if not it is one of the Add On policy + if($basePolicyAddOnType == 1){ $is_addon_value = 0; }else{ $is_addon_value = 1; } + $only_si_array = []; + $only_si_value = 0; + $only_si_premium_value = 0; + $only_si_gst_value = 0; + $BasePolicyEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',$is_addon_value)->whereIn('family_floater_key',$whereArray)->findAll(); + foreach ($BasePolicyEmployeeData as $key => $value) { + + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); + if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->premium)){ $only_si_premium_value = $only_si_premium_value + $employee_policy->rata_premimum;} + if(isset($employee_policy->gst)){ $only_si_gst_value = $only_si_gst_value + $employee_policy->gst;} + $temp3['is_value_exist'] = true; + $temp3['data']['employee_id'] = $value['id']; + $temp3['data']['relationship'] = $value['relationship']; + $temp3['data']['name'] = $value['name']; + $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp3['data']['client_policy_id'] = $array['id']; + $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; + $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; + array_push($only_si_array,$temp3); + + } + + $responce['family_floaters_of_only_si_array'] = $only_si_array; + $responce['family_floaters_of_only_si_value'] = $only_si_value; + $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; + $responce['family_floaters_of_only_si_gst_value'] = $only_si_gst_value; + $responce['type'] = "Group Medical Coverage - Parents Top Up"; + + if($this->request->getGet('policy') == 'GMC-SI-PARENT-TOPUP'){ + return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_parent_topup'=>$responce]], 200); + } + + } - - - array_push($result,$data); - + + } + + + return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); + + }else{ + return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200); + } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); } } - + public function iAgreeForAddOn() + { + $postData = json_decode($this->request->getBody(), true); + $client_policy_id = $postData['client_policy_id']; + sort($client_policy_id); + // Alternatively, you can use echo to see the type + $emp_code = $postData['emp_code']; + $client_id = $postData['client_id']; - if($result) - { - return $this->respond(['status' => 'success','code' => (count($result) ? 200 : 404),'data' => $result ], 200); - }else{ - return $this->respond(['status' => 'failed','code' => (count($result) ? 200 : 404),'data' => [] ], 200); - } - -} + $this->employeeModel->where('emp_code', $emp_code ) + ->where('client_id', $client_id ) + ->where('is_active', 1 ) + ->set(array('emp_status'=>'enrolled')) + ->update(); + + $empData = $this->employeeModel->where('emp_code', $emp_code )->where('client_id', $client_id ) ->where('is_active', 1 )->findAll(); + + if (!is_null($client_policy_id) && is_array($client_policy_id)) + { + $array_list = []; + foreach ($client_policy_id as $key => $value) + { + foreach ($empData as $empDataKey => $empDataValue) + { + $this->employeePolicyModel->where('client_policy_id', $value ) + ->where('is_active', 1 ) + ->where('employee_id', $empDataValue['id'] ) + ->set(array('status'=>'enrolled')) + ->update(); + } + + $find = $this->employeeModel->getEmpFamilybyEmpCode(client_policy_id: $value,emp_code: $emp_code,client_id: $client_id,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); + if(count($find) > 0){ + $array_list[] = $find; + } + } + + $notification = $this->notificationModel->where('client_id' ,$client_id)->where('template_name', 'member_review_and_summary_mail')->first(); + if (isset($notification) && $notification['enabled'] == 1) { + $params ['array_list'] = $array_list; + $params ['client_policy_id'] = $client_policy_id; + $params ['emp_code'] = $emp_code; + $params ['client_id'] = $client_id; + $params ['notification'] = $notification; + // print_r($params);die; + $wholeData =sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params); + $mail_send_return = MailHelper::send_email($wholeData[0]); + $this->myLogger->logme("info", $mail_send_return); + + if (isset($wholeData[0])) { + + $account_manager_wholeData =sendMailNotification::sendMailNotification('account_maneger_summary_mail', $params); + + foreach ($account_manager_wholeData as $key => $value) { + $mail_send_return1 = MailHelper::send_email($value); + $this->myLogger->logme("info", $mail_send_return1); + } + + $client_hr_wholeData =sendMailNotification::sendMailNotification('client_hr_summary_mail', $params); + + foreach ($client_hr_wholeData as $key => $value) { + $mail_send_return2 = MailHelper::send_email($value); + $this->myLogger->logme("info", $mail_send_return2); + } + } + } + + } + + return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200); + } + + //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 + { + 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); -public function exportCashDepositData() -{ + $client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id']; + // get policy and rack details + $policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id,$client_policy_id); + $policy_type = $policy_terms[0]->is_addon; + $base_policy = $policy_terms[0]->base_policy; + $policy_terms = (array) $policy_terms[0];// convert obj to array - $CashDepositData = $this->clientPolicyModel->getdepositData($this->request->getGet('client_id'),$this->request->getGet('insurer_id')); + //get policy slab rates + $slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); + // print_r($slab_details);die(); - // echo '
';print_r($CashDepositData); echo '
';die; + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); - if(count($CashDepositData)) - { - // Define headers and map database fields to Excel fields - $headers = [ - 'Date' => 'created_at', - 'Type' => 'transaction_type', - 'Amount' => 'amount', - 'Balance' => 'balance', - 'Description' => 'description', - 'Insurer Name' => 'insurer_name', - 'Client Name' => 'clientname' - ]; - - // Create a new Spreadsheet object - $spreadsheet = new Spreadsheet(); - - // Get the active sheet - $sheet = $spreadsheet->getActiveSheet(); - - // Add headers - $column = 'A'; - foreach ($headers as $header => $dbField) { - $sheet->setCellValue($column . '1', $header); - $column++; + if(!count($existing_famility_details) && $policy_type == 2)//top up addon only + { + //get basepolicy id then pull emplist from base policy if only current policy is DA addon policy and emplist is zero + // echo 'inside'; + $client_policy_id = $base_policy; + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); } - // Add data - $row = 2; - foreach ($CashDepositData as $Cashvalue) { + $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception']; + // 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(); + 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_premimum($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si); + // dd($data); + $employee_data_group_by_family[$emp_id] = $data; + + } + + if($clientPolicyId != null && $empCode != null) + { + return $employee_data_group_by_family; + }else{ + // dd ($employee_data_group_by_family); + return $this->respond(['status' => 'success','code' => (count($employee_data_group_by_family) ? 200 : 404),'data' => [$employee_data_group_by_family] ], 200); + + } + + } + + + public function getCashDepositData() + { + + $ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name') + ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left') + ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) + ->where('client_policy.is_active', 1 ) + ->where('client_policy.policy_status', 1) + ->groupBy('client_policy.insurer_id') + ->findAll(); + $result = []; + + if(count($ClientPolicyData)) + { + foreach ($ClientPolicyData as $key => $value) { + + $data['clientId'] = $value['clientId']; + $data['insurerId'] = $value['insurerId']; + $data['insurerName'] = $value['insurer_name']; + $data['depositData'] = $this->clientPolicyModel->getdepositData($value['clientId'],$value['insurerId']); + $data['balance'] = count($data['depositData']) ? $data['depositData'][0]->balance : 0; + + $data['policyDetails'] = []; + $ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id , client_policy.policy_type_id as policy_type_id, policies.name as policy_name , client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type ') + ->join('policies', 'client_policy.policy_id = policies.id', 'left') + ->where('client_policy.insurer_id', $value['insurerId'] ) + ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) + ->where('client_policy.is_active', 1 ) + ->where('client_policy.policy_status', 1) + ->findAll(); + // dd( $ClientPolicyData); + foreach ($ClientPolicyData as $key => $value) + { + + $value['type'] = $this->policyTypeModel->where('id',$value['policy_type_id'])->get()->getRow()->policy_type; + $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0,branch_id:$this->request->getGet('client_branch_id')); + $enrolledCount = 0; + $draftCount = 0; + if(count($employeeDetails)) + { + foreach ($employeeDetails as $item) { + if ($item['emp_status'] === 'enrolled') { + $enrolledCount++; + } elseif ($item['emp_status'] === 'draft') { + $draftCount++; + } + } + } + + $value['totalMembersCount'] = count($employeeDetails); + $value['membersCountOfEnrolled'] = $enrolledCount; + $value['membersCountOfDraft'] = $draftCount; + + array_push($data['policyDetails'],$value); + } + + + array_push($result,$data); + + } + } + + + + if($result) + { + return $this->respond(['status' => 'success','code' => (count($result) ? 200 : 404),'data' => $result ], 200); + }else{ + return $this->respond(['status' => 'failed','code' => (count($result) ? 200 : 404),'data' => [] ], 200); + } + + } + + + + + public function exportCashDepositData() + { + + $CashDepositData = $this->clientPolicyModel->getdepositData($this->request->getGet('client_id'),$this->request->getGet('insurer_id')); + + // echo '
';print_r($CashDepositData); echo '
';die; + + if(count($CashDepositData)) + { + // Define headers and map database fields to Excel fields + $headers = [ + 'Date' => 'created_at', + 'Type' => 'transaction_type', + 'Amount' => 'amount', + 'Balance' => 'balance', + 'Description' => 'description', + 'Insurer Name' => 'insurer_name', + 'Client Name' => 'clientname' + ]; + + // Create a new Spreadsheet object + $spreadsheet = new Spreadsheet(); + + // Get the active sheet + $sheet = $spreadsheet->getActiveSheet(); + + // Add headers $column = 'A'; - foreach ($headers as $dbField) { - $sheet->setCellValue($column . $row, $Cashvalue->$dbField); + foreach ($headers as $header => $dbField) { + $sheet->setCellValue($column . '1', $header); $column++; } - $row++; + + // Add data + $row = 2; + foreach ($CashDepositData as $Cashvalue) { + $column = 'A'; + foreach ($headers as $dbField) { + $sheet->setCellValue($column . $row, $Cashvalue->$dbField); + $column++; + } + $row++; + } + + + // Set the header for download + $filename = $CashDepositData[0]->insurer_name.'-CashDeposit.xlsx'; + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $filename . '"'); + header('Cache-Control: max-age=0'); + + // Save the Excel file to output + $writer = new Xlsx($spreadsheet); + $writer->save('php://output'); + exit; + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200); + + }else{ + + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200); } - - - // Set the header for download - $filename = $CashDepositData[0]->insurer_name.'-CashDeposit.xlsx'; - header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - header('Content-Disposition: attachment;filename="' . $filename . '"'); - header('Cache-Control: max-age=0'); - - // Save the Excel file to output - $writer = new Xlsx($spreadsheet); - $writer->save('php://output'); - exit; - - return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200); - - }else{ - - return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200); - } - -} - - -public function removeEmpAndEmpPolicyData() -{ - try { - - $clientPolicy = $this->clientPolicyModel->where('id',$this->request->getGet('client_policy_id'))->findAll(); - if(count($clientPolicy)) - { + } - if($clientPolicy[0]['is_addon'] == 2)//Topup + public function removeEmpAndEmpPolicyData() + { + try { + + $clientPolicy = $this->clientPolicyModel->where('id',$this->request->getGet('client_policy_id'))->findAll(); + + if(count($clientPolicy)) { - $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) - ->where('is_addon_value', 0 )->findAll(); - if(count($empData)) + + + if($clientPolicy[0]['is_addon'] == 2)//Topup { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 0 )->findAll(); + if(count($empData)) + { + foreach ($empData as $key => $value) { + + $this->employeePolicyModel->where('client_policy_id',$this->request->getGet('client_policy_id') ) + ->where('employee_id', $value['id'] ) + ->set(array('is_active'=> 0 )) + ->update(); + + } + } + + } + else if($clientPolicy[0]['is_addon'] == 3)//Dependent addon + { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 1 )->findAll(); + if(count($empData)) + { foreach ($empData as $key => $value) { $this->employeePolicyModel->where('client_policy_id',$this->request->getGet('client_policy_id') ) - ->where('employee_id', $value['id'] ) - ->set(array('is_active'=> 0 )) - ->update(); - + ->where('employee_id', $value['id'] ) + ->set(array('is_active'=> 0 )) + ->update(); + } + + $this->employeeModel->where('emp_code', $this->request->getGet('emp_code') ) + ->where('is_active', 1 )->where('is_addon_value', 1 ) + ->set(array('is_active'=> 0 )) + ->update(); + } + + } + + + + return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 200); + + }else{ + return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 200); + } + + + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } + + } + + + function getEmployeeActiveOrInactivePolicy() + { + + if($this->request->getGet('type') == 'Active'){ $policy_status = 1; }else{ $policy_status = 0; } + $ClientPolicyData = $this->clientPolicyModel->select('client_policy.* , policies.name as policy_name , policy_type.policy_type as policy_type') + ->join('policies', 'client_policy.policy_id = policies.id', 'left') + ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left') + ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) + ->where('client_policy.is_active', 1 ) + ->where('client_policy.policy_status', $policy_status) + ->orderby('client_policy.id' , 'ASC') + ->findAll(); + + // Retrieve employee and dependents data by passing the employee code + $employeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('client_id',$this->request->getGet('client_id')) + ->where('client_branch_id',$this->request->getGet('client_branch_id')) + ->where('is_active', 1 )->findAll(); + $employeeName = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('client_id',$this->request->getGet('client_id')) + ->where('client_branch_id',$this->request->getGet('client_branch_id')) + ->where('family_floater_key','self')->where('is_active', 1 ) + ->get()->getRow()->name; + $whereArrayForId = []; + foreach ( $employeeData as $key => $value) { array_push($whereArrayForId, $value['id']); } + + if(count($ClientPolicyData) > 0 && count($employeeData) > 0) + { + $result = []; + foreach ($ClientPolicyData as $key => $ClientPolicyValue) { + + + + $terms = json_decode($ClientPolicyValue['policy_terms']); + + if($ClientPolicyValue['policy_type_id'] == 1){ $data['policy_terms'] = $this->policyTermsFiter($terms,'gpa'); } + else{ $data['policy_terms'] = $this->policyTermsFiter($terms,'gmc'); } + + $data['client_id'] = $ClientPolicyValue['client_id']; + $data['client_policy_id'] = $ClientPolicyValue['id']; + $data['policy_name'] = $ClientPolicyValue['policy_name']; + $data['policy_type'] = $ClientPolicyValue['policy_type']; + $data['policy_type'] = $ClientPolicyValue['policy_type']; + $data['policy_no'] = $ClientPolicyValue['policy_no']; + $data['policy_start_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_start_date']); + $data['policy_end_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_end_date']); + // $data['policy_terms'] = $terms; + + if($ClientPolicyValue['policy_type_id'] == 1){ $data['heading'] = 'Group Personal Accident Coverage'; }else + if($ClientPolicyValue['policy_type_id'] == 2){ $data['heading'] = 'Group Medical Coverage'; }else + if($ClientPolicyValue['policy_type_id'] == 3){ $data['heading'] = 'Group Medical Coverage - Parents'; }else + if($ClientPolicyValue['policy_type_id'] == 4){ $data['heading'] = 'Group Medical Coverage - Top Up'; }else + if($ClientPolicyValue['policy_type_id'] == 5){ $data['heading'] = 'Group Medical Coverage - Parents (Top Up)'; } + + if($ClientPolicyValue['policy_type_id'] == 1){ $data['floter_text_heading'] = 'Sum Insured'; } + else + { + if($terms->family_floater == 1){ $data['floter_text_heading'] = 'Floter Sum Insured'; }else{ $data['floter_text_heading'] = 'Sum Insured'; } + } + + $employee_policy = $this->employeePolicyModel->select('employees.*,employee_polices.employee_id , employee_polices.basic_cover_si , employee_polices.premium , employee_polices.gst , employee_polices.tpa_id , employee_polices.rand_string , employee_polices.uhid as uhid') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->whereIn('employee_polices.employee_id',$whereArrayForId) + ->where('employee_polices.client_policy_id',$ClientPolicyValue['id']) + ->where('employee_polices.is_active', 1 )->findAll(); + if(count($employee_policy) > 0) + { + $si_value = 0; + $si_premium_value = 0; + $si_gst_value = 0; + + foreach ($employee_policy as $key => $value) { + if(isset($value['basic_cover_si'])){ $si_value = $value['basic_cover_si']; } + if(isset($value['premium'])){ $si_premium_value = $si_premium_value + $value['premium'];} + if(isset($value['gst'])){ $si_gst_value = $si_gst_value + $value['gst'];} + } + + + if($employee_policy[0]['tpa_id'] != null) + $data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string']; + else + $data['eCardDownload'] = null; + + + + $data['si_value'] = $si_value; + $data['si_premium_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_premium_value; + $data['si_gst_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_gst_value; + + $data['EmployeePolicy'] = $employee_policy; + array_push($result, $data); } } - else if($clientPolicy[0]['is_addon'] == 3)//Dependent addon - { - $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) - ->where('is_addon_value', 1 )->findAll(); - if(count($empData)) - { - foreach ($empData as $key => $value) { - $this->employeePolicyModel->where('client_policy_id',$this->request->getGet('client_policy_id') ) - ->where('employee_id', $value['id'] ) - ->set(array('is_active'=> 0 )) - ->update(); + return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'emp_name' => $employeeName ], 200); - } - - $this->employeeModel->where('emp_code', $this->request->getGet('emp_code') ) - ->where('is_active', 1 )->where('is_addon_value', 1 ) - ->set(array('is_active'=> 0 )) - ->update(); - } - - } - - - - return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 200); - }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 200); } - - - } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } - -} -function getEmployeeActiveOrInactivePolicy() -{ - - if($this->request->getGet('type') == 'Active'){ $policy_status = 1; }else{ $policy_status = 0; } - $ClientPolicyData = $this->clientPolicyModel->select('client_policy.* , policies.name as policy_name , policy_type.policy_type as policy_type') - ->join('policies', 'client_policy.policy_id = policies.id', 'left') - ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left') - ->where('client_policy.client_id', $this->request->getGet('client_id') ) - ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) - ->where('client_policy.is_active', 1 ) - ->where('client_policy.policy_status', $policy_status) - ->orderby('client_policy.id' , 'ASC') - ->findAll(); - - // Retrieve employee and dependents data by passing the employee code - $employeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) - ->where('client_id',$this->request->getGet('client_id')) - ->where('client_branch_id',$this->request->getGet('client_branch_id')) - ->where('is_active', 1 )->findAll(); - $employeeName = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) - ->where('client_id',$this->request->getGet('client_id')) - ->where('client_branch_id',$this->request->getGet('client_branch_id')) - ->where('family_floater_key','self')->where('is_active', 1 ) - ->get()->getRow()->name; - $whereArrayForId = []; - foreach ( $employeeData as $key => $value) { array_push($whereArrayForId, $value['id']); } - - if(count($ClientPolicyData) > 0 && count($employeeData) > 0) + function policyTermsFiter($terms , $type) { - $result = []; - foreach ($ClientPolicyData as $key => $ClientPolicyValue) { + + $gpa = [ + "sumInsured2" => "Sum Insured", + "totalSumInsured" => "Total Sum Assured", + "self" => "Self", + "self_min_age" => "Min Age", + "self_max_age" => "Max Age", + "accidentalDeathBenefit" => "Accidental Death Benefit", + "permanentTotalDisablement" => "Permanent Total Disablement", + "permanentPartialDisablement" => "Permanent Partial Disablement", + "temporaryTotalDisablementBenefit" => "Temporary Total Disablement benefit", + "accidentalHospitalizationExpenses" => "Accidental Hospitalization Expenses", + "childrenEducationWelfareFund" => "Children Education Welfare Fund", + "compassionateVisitExpenses" => "Compassionate Visit Expenses", + "compassionateVisitExpensesData" => "Compassionate Visit Expenses Data", + "brokenBoneExpenses" => "Broken Bone Expenses", + "brokenBoneExpensesData" => "Broken Bone Expenses Data", + "ambulanceCharges" => "Ambulance charges", + "ambulanceChargesData" => "Ambulance charges Data", + "burnExpenses" => "Burn Expenses", + "burnExpensesData" => "Burn Expenses Data", + "carriageOfDeadBody" => "Carriage of Dead Body", + "carriageOfDeadBodyData" => "Carriage of Dead Body Data", + "animalSnakeInsectBite" => "Animal/Snake/Insect bite", + "terrorism" => "Terrorism", + "worldwideCover" => "Worldwide Cover" + ]; + + $gmc = [ + "sum_insured" => "Sum Insured", + "waiverofpreexistingdiseases" => "Waiver of Pre-existing Diseases", + "maternitycoverage" => "Maternity Coverage", + "babyday1cover" => "Baby Day 1 Cover", + "9monthwaitingperiodwaived" => "9-month waiting Period –waived", + "coverfromthedateofjoining" => "Cover from the date of Joining", + "waiverof1,2,3&4thyearexclusions" => "Waiver of 1, 2, 3 & 4th year Exclusions", + "waiverof30dayswaitingperiod" => "Waiver of 30 days waiting period", + "prehospitalizationcover" => "Pre Hospitalization Cover", + "copayzonewisecopay" => "Co-Pay/Zone wise Co Pay", + "roomrentlimit" => "Room Rent Limit", + "ailmentcapping" => "Ailment capping", + ]; - - $terms = json_decode($ClientPolicyValue['policy_terms']); - - if($ClientPolicyValue['policy_type_id'] == 1){ $data['policy_terms'] = $this->policyTermsFiter($terms,'gpa'); } - else{ $data['policy_terms'] = $this->policyTermsFiter($terms,'gmc'); } - - $data['client_id'] = $ClientPolicyValue['client_id']; - $data['client_policy_id'] = $ClientPolicyValue['id']; - $data['policy_name'] = $ClientPolicyValue['policy_name']; - $data['policy_type'] = $ClientPolicyValue['policy_type']; - $data['policy_type'] = $ClientPolicyValue['policy_type']; - $data['policy_no'] = $ClientPolicyValue['policy_no']; - $data['policy_start_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_start_date']); - $data['policy_end_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_end_date']); - // $data['policy_terms'] = $terms; - - if($ClientPolicyValue['policy_type_id'] == 1){ $data['heading'] = 'Group Personal Accident Coverage'; }else - if($ClientPolicyValue['policy_type_id'] == 2){ $data['heading'] = 'Group Medical Coverage'; }else - if($ClientPolicyValue['policy_type_id'] == 3){ $data['heading'] = 'Group Medical Coverage - Parents'; }else - if($ClientPolicyValue['policy_type_id'] == 4){ $data['heading'] = 'Group Medical Coverage - Top Up'; }else - if($ClientPolicyValue['policy_type_id'] == 5){ $data['heading'] = 'Group Medical Coverage - Parents (Top Up)'; } - - if($ClientPolicyValue['policy_type_id'] == 1){ $data['floter_text_heading'] = 'Sum Insured'; } - else - { - if($terms->family_floater == 1){ $data['floter_text_heading'] = 'Floter Sum Insured'; }else{ $data['floter_text_heading'] = 'Sum Insured'; } - } - - $employee_policy = $this->employeePolicyModel->select('employees.*,employee_polices.employee_id , employee_polices.basic_cover_si , employee_polices.premium , employee_polices.gst , employee_polices.tpa_id , employee_polices.rand_string , employee_polices.uhid as uhid') - ->join('employees', 'employee_polices.employee_id = employees.id', 'left') - ->whereIn('employee_polices.employee_id',$whereArrayForId) - ->where('employee_polices.client_policy_id',$ClientPolicyValue['id']) - ->where('employee_polices.is_active', 1 )->findAll(); - if(count($employee_policy) > 0) - { - $si_value = 0; - $si_premium_value = 0; - $si_gst_value = 0; - - foreach ($employee_policy as $key => $value) { - if(isset($value['basic_cover_si'])){ $si_value = $value['basic_cover_si']; } - if(isset($value['premium'])){ $si_premium_value = $si_premium_value + $value['premium'];} - if(isset($value['gst'])){ $si_gst_value = $si_gst_value + $value['gst'];} - } - - - if($employee_policy[0]['tpa_id'] != null) - $data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string']; - else - $data['eCardDownload'] = null; - - - $data['si_value'] = $si_value; - $data['si_premium_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_premium_value; - $data['si_gst_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_gst_value; - - $data['EmployeePolicy'] = $employee_policy; - array_push($result, $data); + $finalarray = []; + if($type == 'gpa'){ + foreach ($gpa as $key => $value) { + if(isset($terms->$key)) + $finalarray[$value] = $terms->$key; } + }else{ + foreach ($gmc as $key => $value) { + if(isset($terms->$key)) + $finalarray[$value] = $terms->$key; + } + } + + + return $finalarray; + + } + + + private function convertDateFormatDisplay($dateString) + { + // Attempt to create a DateTime object from the provided date string + $dateTime = \DateTime::createFromFormat('Y-m-d', $dateString); + + if ($dateTime instanceof \DateTime) { + return $dateTime->format('d-M-Y'); + } else { + return null; + } + } + + public function getFEContent() + { + try { + + $feContentData = $this->feContentModel->findAll(); + if (count($feContentData) > 0) { - } + return $this->respond(['status' => 'success','code' => 200,'data' => $feContentData ],200); - return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'emp_name' => $employeeName ], 200); - - }else{ - return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 200); - } - -} - - -function policyTermsFiter($terms , $type) -{ - - $gpa = [ - "sumInsured2" => "Sum Insured", - "totalSumInsured" => "Total Sum Assured", - "self" => "Self", - "self_min_age" => "Min Age", - "self_max_age" => "Max Age", - "accidentalDeathBenefit" => "Accidental Death Benefit", - "permanentTotalDisablement" => "Permanent Total Disablement", - "permanentPartialDisablement" => "Permanent Partial Disablement", - "temporaryTotalDisablementBenefit" => "Temporary Total Disablement benefit", - "accidentalHospitalizationExpenses" => "Accidental Hospitalization Expenses", - "childrenEducationWelfareFund" => "Children Education Welfare Fund", - "compassionateVisitExpenses" => "Compassionate Visit Expenses", - "compassionateVisitExpensesData" => "Compassionate Visit Expenses Data", - "brokenBoneExpenses" => "Broken Bone Expenses", - "brokenBoneExpensesData" => "Broken Bone Expenses Data", - "ambulanceCharges" => "Ambulance charges", - "ambulanceChargesData" => "Ambulance charges Data", - "burnExpenses" => "Burn Expenses", - "burnExpensesData" => "Burn Expenses Data", - "carriageOfDeadBody" => "Carriage of Dead Body", - "carriageOfDeadBodyData" => "Carriage of Dead Body Data", - "animalSnakeInsectBite" => "Animal/Snake/Insect bite", - "terrorism" => "Terrorism", - "worldwideCover" => "Worldwide Cover" - ]; - - $gmc = [ - "sum_insured" => "Sum Insured", - "waiverofpreexistingdiseases" => "Waiver of Pre-existing Diseases", - "maternitycoverage" => "Maternity Coverage", - "babyday1cover" => "Baby Day 1 Cover", - "9monthwaitingperiodwaived" => "9-month waiting Period –waived", - "coverfromthedateofjoining" => "Cover from the date of Joining", - "waiverof1,2,3&4thyearexclusions" => "Waiver of 1, 2, 3 & 4th year Exclusions", - "waiverof30dayswaitingperiod" => "Waiver of 30 days waiting period", - "prehospitalizationcover" => "Pre Hospitalization Cover", - "copayzonewisecopay" => "Co-Pay/Zone wise Co Pay", - "roomrentlimit" => "Room Rent Limit", - "ailmentcapping" => "Ailment capping", - ]; - - - - $finalarray = []; - if($type == 'gpa'){ - foreach ($gpa as $key => $value) { - if(isset($terms->$key)) - $finalarray[$value] = $terms->$key; - } - }else{ - foreach ($gmc as $key => $value) { - if(isset($terms->$key)) - $finalarray[$value] = $terms->$key; - } - } - - - return $finalarray; - -} - - -private function convertDateFormatDisplay($dateString) -{ - // Attempt to create a DateTime object from the provided date string - $dateTime = \DateTime::createFromFormat('Y-m-d', $dateString); - - if ($dateTime instanceof \DateTime) { - return $dateTime->format('d-M-Y'); - } else { - return null; - } -} - -public function getFEContent() -{ - try { - - $feContentData = $this->feContentModel->findAll(); - if (count($feContentData) > 0) { - - return $this->respond(['status' => 'success','code' => 200,'data' => $feContentData ],200); - - } else { - - return $this->respond(['status' => 'failed','code' => 404,'data' => 'No Data'],404); - } - } catch (\Throwable $th) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); - } -} - -public function getAdvertisementImage() -{ - try { - - $img = $this->addImgModel->where('is_active',1)->findAll(); - - if (count($img) > 0) { - $data=[]; - foreach ($img as $key => $value) { - $url = base_url('public/uploads/add_image_upload/').$value['name']; - array_push($data,$url); + } else { + + return $this->respond(['status' => 'failed','code' => 404,'data' => 'No Data'],404); } - - return $this->respond(['status' => 'success','code' => 200,'data' => $data ],200); + } catch (\Throwable $th) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); + } + } - } else { - - return $this->respond(['status' => 'failed','code' => 404,'data' => 'No Data'],404); + public function getAdvertisementImage() + { + try { + + $img = $this->addImgModel->where('is_active',1)->findAll(); + + if (count($img) > 0) { + $data=[]; + foreach ($img as $key => $value) { + $url = base_url('public/uploads/add_image_upload/').$value['name']; + array_push($data,$url); + } + + return $this->respond(['status' => 'success','code' => 200,'data' => $data ],200); + + } else { + + return $this->respond(['status' => 'failed','code' => 404,'data' => 'No Data'],404); + } + } catch (\Throwable $th) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } - } catch (\Throwable $th) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); - } -} + } + + + public function storeFireBase() + { + try { + $firebase_token = $this->request->getPost('firebase_token'); + $mobile = $this->request->getPost('mobile'); + + // Ensure the mobile number is provided + if (empty($mobile)) { + return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Mobile number is required'], 400); + } + + // Fetch employee by mobile number + $employee = $this->employeeModel->where('mobile', $mobile)->first(); + + if ($employee) { + // Check if firebase_token is provided + if (!empty($firebase_token)) { + + // Check if the current firebase_token is different from the new one + if ($employee['firebase_token'] !== $firebase_token) { + // Update the employee's firebase_token + $data['firebase_token'] = $firebase_token; + $id = $employee['id']; + // return json_encode($data); + // Direct database update query for testing + $db = \Config\Database::connect(); + $builder = $db->table('employees'); + $update_emp = $builder->update($data, ['id' => $id]); + + // Check if the update was successful + if ($db->affectedRows() > 0) { + // Fetch the updated employee data + $updated_employee = $this->employeeModel->find($id); + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $updated_employee], 200); + } else { + log_message('error', 'Update failed. No rows affected.'); + return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'Failed to update employee data'], 500); + } + } else { + return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'New Firebase Token is the same as the current one'], 400); + } + } else { + return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Firebase Token is required'], 400); + } + } else { + return $this->respond(['status' => 'failed', 'code' => 404, 'message' => 'Employee not found'], 404); + } + } catch (\Throwable $th) { + log_message('error', 'An error occurred: ' . $th->getMessage()); + return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'An error occurred', 'error' => $th->getMessage()], 500); + } + } + } \ No newline at end of file From 3d03a6f063f6b4fda5be9c2f8f5d91d9d755bf11 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Sat, 20 Jul 2024 14:20:41 +0530 Subject: [PATCH 25/29] CHANGE_EMP_REST_BASIC_PAY : AADHAVAN --- app/Controllers/EmployeeRestController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 40d6f8b5..92c36a0a 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -785,6 +785,7 @@ class EmployeeRestController extends AdminController 'client_id' => $client_id, 'emp_status'=>'draft', 'band'=> $extra['10'][$index], + 'basic_pay'=> $extra['11'][$index], 'client_branch_id' => $client_branch_id ]; From 816c49cc53ef20604d2c2f250b9400c57b69ea4d Mon Sep 17 00:00:00 2001 From: Venba Date: Sat, 20 Jul 2024 09:24:29 +0000 Subject: [PATCH 26/29] CHANGE_EMP_REST_UNTI_FILED_ADDED --- app/Controllers/EmployeeRestController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 92c36a0a..9b4db74a 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -786,6 +786,7 @@ class EmployeeRestController extends AdminController 'emp_status'=>'draft', 'band'=> $extra['10'][$index], 'basic_pay'=> $extra['11'][$index], + 'unit'=> $extra['12'][$index], 'client_branch_id' => $client_branch_id ]; @@ -2235,7 +2236,7 @@ class EmployeeRestController extends AdminController "waiverofpreexistingdiseases" => "Waiver of Pre-existing Diseases", "maternitycoverage" => "Maternity Coverage", "babyday1cover" => "Baby Day 1 Cover", - "9monthwaitingperiodwaived" => "9-month waiting Period –waived", + "9monthwaitingperiodwaived" => "9-month waiting Period –waived", "coverfromthedateofjoining" => "Cover from the date of Joining", "waiverof1,2,3&4thyearexclusions" => "Waiver of 1, 2, 3 & 4th year Exclusions", "waiverof30dayswaitingperiod" => "Waiver of 30 days waiting period", From 8d3f31413c5502cffd13d701052e6c61d6853a9d Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Sat, 20 Jul 2024 16:40:29 +0530 Subject: [PATCH 27/29] CHANGE_EMP_REST_EMP_UPLOAD_FIREBASE_JSON : AADHAVAN --- app/Controllers/EmployeeRestController.php | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 92c36a0a..f3f28503 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -632,6 +632,7 @@ class EmployeeRestController extends AdminController $policy_id = $this->request->getPost('policy_id'); $client_data = $this->clientModel->where('id', $client_id)->first(); + $notification = $this->notificationModel->where('client_id',$client_id)->where('template_name','member_welcome_mail')->first(); $jwt = $this->request->getHeader('Authorization'); @@ -742,13 +743,13 @@ class EmployeeRestController extends AdminController $basic_cover_si= []; foreach ($extra['0'] as $index => $id) { $relation =''; - if ($extra['5'][$index] === 'Mother' || $extra['5'][$index] === 'Father') { + if (strtolower(trim($extra['5'][$index])) === 'mother' || strtolower(trim($extra['5'][$index])) === 'father') { $relation = 'parent'; - } else if($extra['5'][$index] === 'Son' || $extra['5'][$index] === 'Daughter'){ + } else if(strtolower(trim($extra['5'][$index])) === 'son' || strtolower(trim($extra['5'][$index])) === 'daughter'){ $relation = 'child'; - }else if($extra['5'][$index] === 'Father in Law' || $extra['5'][$index] === 'Mother in Law'){ + }else if(strtolower(trim($extra['5'][$index])) === 'father in law' || strtolower(trim($extra['5'][$index])) === 'mother in law'){ $relation = 'parent_in_law'; - }else if($extra['5'][$index] === 'Spouse'){ + }else if(strtolower(trim($extra['5'][$index])) === 'spouse'){ $relation = 'spouse'; }else{ $relation = 'self'; @@ -777,7 +778,7 @@ class EmployeeRestController extends AdminController // Check if the 'doj' key exists before accessing it 'doj' => $doj_new_format, 'gender' => $extra['4'][$index], - 'relationship' => ucfirst($extra['5'][$index]), + 'relationship' => ucfirst(trim($extra['5'][$index])), 'family_floater_key' => $relation, 'dob' => $dob_new_format, 'email_corporate' => $extra['7'][$index], @@ -888,10 +889,10 @@ class EmployeeRestController extends AdminController $emp_policy = $this->employeePolicyModel->insert($emp_policy_data); } - $notification = $this->notificationModel->where('client_id',$client_id)->where('template_name','member_welcome_mail')->first(); + if (isset($notification) && $notification['enabled'] == 1 && !empty($notification['mail_content'])) { - if (isset($notification) && $notification['enabled'] == 1) { //trigger + $wholeData=[]; if ($dataToInsert[$a]['relationship'] == 'Self' && isset($dataToInsert[$a]['email_corporate']) && !empty($dataToInsert[$a]['email_corporate'])) { $params['dataToInsert'] = $dataToInsert[$a]; @@ -2323,9 +2324,10 @@ class EmployeeRestController extends AdminController public function storeFireBase() { - try { - $firebase_token = $this->request->getPost('firebase_token'); - $mobile = $this->request->getPost('mobile'); + // try { + $json = $this->request->getJSON(); + $firebase_token = $json->firebase_token; + $mobile = $json->mobile; // Ensure the mobile number is provided if (empty($mobile)) { @@ -2368,10 +2370,10 @@ class EmployeeRestController extends AdminController } else { return $this->respond(['status' => 'failed', 'code' => 404, 'message' => 'Employee not found'], 404); } - } catch (\Throwable $th) { - log_message('error', 'An error occurred: ' . $th->getMessage()); - return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'An error occurred', 'error' => $th->getMessage()], 500); - } + // } catch (\Throwable $th) { + // log_message('error', 'An error occurred: ' . $th->getMessage()); + // return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'An error occurred', 'error' => $th->getMessage()], 500); + // } } From 469d0d92fe002ef14bdaf221fbf47c64110b077d Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Sat, 20 Jul 2024 16:45:40 +0530 Subject: [PATCH 28/29] CHANGE_ROUTE_FILE : AADHAVAN --- app/Config/Routes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 06888fcb..14f1ef6a 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -136,7 +136,8 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { $routes->post("upload", "EmployeeController::employeesUplodWithEvents"); $routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1"); $routes->get("endorsement-list", "EmployeeController::endorsementList"); - $routes->get("enrollment-list", "EmployeeController::enrollmentList"); + $routes->get("enrollment-list", "EmployeeController::enrollmentClientList"); + $routes->get("empby_client_clientbranch/(:any)/(:any)", "EmployeeController::empby_client_clientbranch/$1/$2"); $routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1"); }); From a147cf313055a23c64e869baa97347ace62c41f3 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Mon, 22 Jul 2024 13:41:45 +0530 Subject: [PATCH 29/29] CHNAGE_ push notification : GWM --- app/Config/Routes.php | 2 ++ app/Config/google-services.json | 13 ++++++++ app/Controllers/EmployeeRestController.php | 38 +++++++++++++++++++++- composer.json | 4 ++- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 app/Config/google-services.json diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 14f1ef6a..aae95756 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -323,6 +323,8 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage"); }); +$routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); + diff --git a/app/Config/google-services.json b/app/Config/google-services.json new file mode 100644 index 00000000..f465fcd7 --- /dev/null +++ b/app/Config/google-services.json @@ -0,0 +1,13 @@ +{ + "type": "service_account", + "project_id": "push-notification-enrollment", + "private_key_id": "979d0fcd0ce95d31367f3150d34ee0044ca51b0d", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC4Xsan6ESIzM12\nG15gRU361Yy6PVmoMzTToWtZHPEcDRd9weFNlCXjmX+WAqdgD/hQ42GcZQVCndse\nEQGJHbRu/ifMKGo53zxOpshNZnCSxojAGWIGrIHFE5kFumiKz9drW9vPWsFLtgx0\nEAW0T7su1MejjH33GftHG8k/q3uyWoU0+OFRD6emhYkFdVsucwR27hE7GsFwE+CF\nnRdSWQ5mu2e8J7q9Qbpgot5d7uk7iJgpiyNdChPvqUZ7XeknVrw1F4REZlbAkVjb\nFuwKg5qtG97LZ1NkyYqFmssA1rNkqSi4+T+2/ERegdwyA6W4/HLT9fPbSl4v1MvB\ntJlGYkMpAgMBAAECggEABhspdCUmo+s4gMleQkz5TK3m58IhZocvoDSv4/cn6xhp\n50HVDucxrAyI47R5y54ryK4HLRFRb8ffmmrQxLRFpgln0wShpAIHMsmmR531a38E\nx2vvya3L7HV+M2jdjn9csJMNwBvO3A2O8wcW0UZ0uhPU+s8r2tOy9UNv0lqBEcKM\nUxCtk7UxcLEM3btDP5I4oEHVo2f5jzPeb99KHbYQV/vc0BtA1wtuYTzGT2EhBpTG\nN1rbQhlj6iJ6vMwHETWrctNMohCQNQEv/QIC/NWYPNRqmtrJfNe29XGWN9IIhv0e\n/ZmhdzoO+uhJW4VaWpI93nB5ZAa6LHqJSg+OyrPoawKBgQDd45Aiq7d+4Z+kDZYu\n72bgW5CGhyck2hrqHpBdHA960AYIftw/wHgI9xb9Z8hi+Lh+W18xDywOLoaz7TJV\nElj2Gh3oj2ZLzDpeyqV9UOgz11dbm6yYUK8jl7zyajBt7RhGcdj+4x+YjUTT6O61\nuxm2ZbKsb/0er/W6DlKDVvpWSwKBgQDUtqowATEaGTrd+eutanRwtv+rdptVcadj\nD4H3XdY4PAsVSp1mT9knGgh7c5elI0lBH/VD/IbM5uPXOc7judnIK4RgKScrJT2P\nekyEJnXyFAZGS3WTFG7fzeXn/cNNx5MCZE2Yay7LqqON8Kg08IvvesiTushrDlMJ\nX8cunSyz2wKBgDIOwZigxq/QNNSs4AHMrpfU8GD5IqKUtde1d3oZ94AMaCAIhqW3\nRR04qS4X+MQjOnP/JxWJR7YXVvpGe8FndzxmHfM2Tqyw8UYrT3RbCVeQsDuRfjmK\nkkhkVhMWU8Co6X4S9xJhqOIglLN97ESBZkaY4Ns4FJGUvsnvqzvIJofLAoGBAKJO\ny2eb0TK/46ozJEELxNOo30efVgGJmpa844e0A1yffDl/2MCT1ve+JpDEcAbi+OeH\nkieRTe6Vk27LvnEHhAT4J6cUX73NSb7sK+x+SGsyGmOS+qEC62M8gdxWRqtXyHX/\nwTG3P1rK1sfcxQy4K57NSrVmxbzijjvN6HdKGS0XAoGATtsid5pypcZ0BsYUp/27\neS6z++ewo7QCVCBPa4Ag4nX56/0kdrECvy/ISMDjggNv+mR8hpyCjfm9ztJ88njB\nUBu1jzLBZ+u5gEjmtu43qvuDJNobyb+evDSReEJmify943vFZqnkIhFlwg1PcS6S\nCd+pr559KWURPIgfxb7S/JU=\n-----END PRIVATE KEY-----\n", + "client_email": "firebase-adminsdk-gzzkw@push-notification-enrollment.iam.gserviceaccount.com", + "client_id": "109128197176743587316", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-gzzkw%40push-notification-enrollment.iam.gserviceaccount.com", + "universe_domain": "googleapis.com" +} diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 95e93d2e..3851457e 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -42,6 +42,11 @@ use Illuminate\Http\Request; use App\Controllers\EmployeeServiceController; +use Kreait\Firebase\Factory; +use Kreait\Firebase\Messaging\CloudMessage; +use Kreait\Firebase\Messaging\Notification; +use Kreait\Firebase\Exception\MessagingException; + class EmployeeRestController extends AdminController { @@ -2237,7 +2242,7 @@ class EmployeeRestController extends AdminController "waiverofpreexistingdiseases" => "Waiver of Pre-existing Diseases", "maternitycoverage" => "Maternity Coverage", "babyday1cover" => "Baby Day 1 Cover", - "9monthwaitingperiodwaived" => "9-month waiting Period –waived", + "9monthwaitingperiodwaived" => "9-month waiting Period �waived", "coverfromthedateofjoining" => "Cover from the date of Joining", "waiverof1,2,3&4thyearexclusions" => "Waiver of 1, 2, 3 & 4th year Exclusions", "waiverof30dayswaitingperiod" => "Waiver of 30 days waiting period", @@ -2376,6 +2381,37 @@ class EmployeeRestController extends AdminController // return $this->respond(['status' => 'failed', 'code' => 500, 'message' => 'An error occurred', 'error' => $th->getMessage()], 500); // } } + + + + + + public function sendPushNotification() + { + $deviceToken = 'ffvc39yhRk-J-vGE9luw6l:APA91bFgNv7lzvA3lGuJ_pMDHdZ_rey6SMg11P2DvJk-WWiBs0nXWCF0lo5nEka3dn3DeTCS5yx0WrHs1yKj5faitBQYKeKxLg2VpUkDcmk3FrTDGkZdHcnW1Go0G0K8dYAkajRIjSEJ'; + $title = 'Nhance'; + $body = 'All your policy enrolled successfully ..!'; + + // Initialize Firebase with the service account + $firebase = (new Factory) + ->withServiceAccount(APPPATH . 'Config/google-services.json') + ->createMessaging(); + + $notification = Notification::create($title, $body); + $message = CloudMessage::withTarget('token', $deviceToken) + ->withNotification($notification); + + try { + $firebase->send($message); + return $this->response->setJSON(['status' => 'success']); + } catch (MessagingException $e) { + return $this->response->setJSON(['status' => 'error', 'message' => $e->getMessage()]); + } + } + + + + } \ No newline at end of file diff --git a/composer.json b/composer.json index 9f2ec667..da1c83ff 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,9 @@ "phpoffice/phpspreadsheet": "^2.1", "psr/log": "^1.1", "slim/slim": "^4.13", - "zircote/swagger-php": "^4.8" + "zircote/swagger-php": "^4.8", + "psr/http-message": "^1.0", + "kreait/firebase-php":"^7.0" }, "require-dev": { "codeigniter/coding-standard": "^1.7",