diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 776abcd3..6ad4f058 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -26,6 +26,8 @@ $routes->get("updateRemainderDate", "ClientController::updateRemainderDate"); $routes->get("sendCroneRemainderMail", "DashboardController::sendCroneRemainderMail"); $routes->get("sendextraparam", "ClientController::sendextraparam"); // $routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); +// $routes->get("sendCroneRemainderMail", "DashboardController::sendCroneRemainderMail"); +// $routes->post("employeeUpload", "EmployeeRestController::employeeUpload"); $routes->post("add_advertise_image", "AppContentManagementController::add_advertise_image"); $routes->get("add_image_index", "AppContentManagementController::add_image_index"); @@ -134,6 +136,11 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->get("list/(:any)", "ClientController::listVehicleFiles/$1"); $routes->get("delete/(:any)", "ClientController::deleteVehicleFiles/$1"); }); + + + $routes->group("others", ["filter" => "authMVC"], function ($routes) { + $routes->post("create", "ClientController::createOtherTabContent"); + }); }); $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index efcd633e..40f52992 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -315,6 +315,8 @@ class ClientController extends AdminController // return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200); } + //-------------------------------------------------------------------------------------------------------- + public function index() { $this->myLogger->logme('error', 'Client list function called'); @@ -2079,6 +2081,11 @@ class ClientController extends AdminController $data['age_ratio']['elders']['min'] = $this->request->getPost("other_member_min_age") ? $this->request->getPost("other_member_min_age") : 0; $data['age_ratio']['elders']['max'] = $this->request->getPost("other_member_max_age") ? $this->request->getPost("other_member_max_age") : 0; + $data['is_payable_employee']['self'] = $this->request->getPost("is_payable_employee_for_self") ? 1 : 0; + $data['is_payable_employee']['spouse'] = $this->request->getPost("is_payable_employee_for_spouse") ? 1 : 0; + $data['is_payable_employee']['childern'] = $this->request->getPost("is_payable_employee_for_child") ? 1 : 0; + $data['is_payable_employee']['elders'] = $this->request->getPost("is_payable_employee_for_elders") ? 1 : 0; + // if (!in_array("self", $data['family_floaters'])) { @@ -2309,6 +2316,8 @@ class ClientController extends AdminController $data['totalSumInsured'] = str_replace(',', '', $this->request->getPost("totalSumInsured")); $data['age_ratio']['self']['min'] = $this->request->getPost("self_min_age"); $data['age_ratio']['self']['max'] = $this->request->getPost("self_max_age"); + $data['is_payable_employee']['self'] = 0; + $data['accidentalDeathBenefit'] = str_replace(',', '', $this->request->getPost("accidentalDeathBenefit")); $data['permanentTotalDisablement'] = str_replace(',', '', $this->request->getPost("permanentTotalDisablement")); $data['permanentPartialDisablement'] = $this->request->getPost("permanentPartialDisablement"); @@ -2442,11 +2451,11 @@ class ClientController extends AdminController $termsData = json_decode($termsData['policy_terms']); - if (isset($termsData->sum_insured) && empty($termsData->sum_insured)) { + if (isset($termsData->sum_insured) && $termsData->sum_insured == "" && $termsData->sum_insured == null) { return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty', 'data' => $record], 200); } - if (isset($termsData->SumInsured) && empty($termsData->sum_insured)) { + if (isset($termsData->sumInsured2) && $termsData->sumInsured2 == "" && $termsData->sumInsured2 == null) { return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty'], 200); } @@ -2892,6 +2901,13 @@ class ClientController extends AdminController $client_policy_id = $this->request->getPost("client_policy_id"); $policy_terms = $this->request->getPost("policy_terms"); + if (!empty($policy_terms)) { + $policy_terms = json_decode($policy_terms, true); + $policy_terms['is_payable_employee']['self'] = 0; + $policy_terms = json_encode($policy_terms); + } + + $record = $this->clientPolicyModel->where('id', $client_policy_id)->first(); if ($record) { @@ -3602,15 +3618,22 @@ class ClientController extends AdminController dd($result); } + // --------------------------------------------------------------------------------------------------------- + public function updatePolicyTermsKey() { + $client_id = $this->request->getGet('client_id'); - $data = $this->clientPolicyModel + $query = $this->clientPolicyModel ->where("policy_terms IS NOT NULL AND policy_terms <> ''") - ->where('policy_type_id', 2) - ->where('is_active', 1) - ->findAll(); - + ->where('is_active', 1); + + if (!empty($client_id)) { + $query->where('client_id', $client_id); + } + + $data = $query->findAll(); + for ($i = 0; $i < count($data); $i++) { if (isset($data[$i]['policy_terms']) && !empty($data[$i]['policy_terms'])) { @@ -3619,49 +3642,110 @@ class ClientController extends AdminController continue; } - // Set default value of copayzonewisecopay to "empty" - $ans = isset($policyTerms['copayzonewisecopay']) ? $policyTerms['copayzonewisecopay'] : 'empty'; + $is_addon = $data[$i]['is_addon']; + + $payable_arr = []; + if (in_array($data[$i]['policy_type_id'], [2,3]) && $is_addon == 1) { + + $payable_arr = [ "self" => 0, "spouse" => 0, "childern" => 0, "elders" => 0, ]; + + } else if ($data[$i]['policy_type_id'] == 3 && $is_addon == 3) { + + $payable_arr = ["self" => 1,"spouse" => 1,"childern" => 1,"elders" => 1,]; + + } else if (in_array($data[$i]['policy_type_id'], [4, 5])) { + + $payable_arr = ["self" => 1,"spouse" => 1,"childern" => 1,"elders" => 1,]; + } // Initialize an empty array for the ordered policy terms $orderedPolicyTerms = []; - // Add copayzonewisecopay and copayzonewisecopaydata if they exist_ - if (isset($policyTerms['copayzonewisecopay'])) { + if(in_array($data[$i]['policy_type_id'], [2,3,4,5])){ - if(!isset($policyTerms['co_pay_details'])){ + // Set default value of copayzonewisecopay to "empty" + $ans = isset($policyTerms['copayzonewisecopay']) ? $policyTerms['copayzonewisecopay'] : 'empty'; - $co_pay_details_value = ""; - if (strtolower($ans) == "nil" || $ans == 0) { - $policyTerms['copayzonewisecopay'] = 0; - $co_pay_details_value = ""; - } elseif ($ans != 'empty' && $ans !== 'Nil' && $ans !== null && $ans != '' && $ans != 0) { - $policyTerms['copayzonewisecopay'] = 1; - $co_pay_details_value = $ans; + // add is_payable_employee for the GMC Policy + if (isset($policyTerms['age_ratio'])) { + if(!isset($policyTerms['is_payable_employee'])){ + $aliment_index = array_search('age_ratio', array_keys($policyTerms)); + $orderedPolicyTerms[] = [ + "key" => "is_payable_employee", + "value" => $payable_arr, + "position" => $aliment_index + 1, + ]; } - - $co_pay_index = array_search('copayzonewisecopay', array_keys($policyTerms)); - $orderedPolicyTerms[] = [ - "key" => "co_pay_details", - "value" => $co_pay_details_value, - "position" => $co_pay_index + 1, - ]; - - unset($policyTerms['optionalparentalcopay']); - } + + // Add copayzonewisecopay and copayzonewisecopaydata if they exist_ + if (isset($policyTerms['copayzonewisecopay'])) { + + if(!isset($policyTerms['co_pay_details'])){ + + $co_pay_details_value = ""; + if (strtolower($ans) == "nil" || $ans == 0) { + $policyTerms['copayzonewisecopay'] = 0; + $co_pay_details_value = ""; + } elseif ($ans != 'empty' && $ans !== 'Nil' && $ans !== null && $ans != '' && $ans != 0) { + $policyTerms['copayzonewisecopay'] = 1; + $co_pay_details_value = $ans; + } + + $co_pay_index = array_search('copayzonewisecopay', array_keys($policyTerms)); + $orderedPolicyTerms[] = [ + "key" => "co_pay_details", + "value" => $co_pay_details_value, + "position" => $co_pay_index + 2, + ]; + + unset($policyTerms['optionalparentalcopay']); + + } + } + + // Add ailmentcapping and ailmentcappingdata if they exist + if (isset($policyTerms['ailmentcapping'])) { + if(!isset($policyTerms['ailment_capping_details'])){ + $aliment_index = array_search('ailmentcapping', array_keys($policyTerms)); + $orderedPolicyTerms[] = [ + "key" => "ailment_capping_details", + "value" => "", + "position" => $aliment_index + 3, + ]; + } + } + + }else { + + // add is_payable_employee for the GMC Policy + if (isset($policyTerms['age_ratio'])) { + if(!isset($policyTerms['is_payable_employee'])){ + $aliment_index = array_search('age_ratio', array_keys($policyTerms)); + $orderedPolicyTerms[] = [ + "key" => "is_payable_employee", + "value" => [ + "self" => 0, + ], + "position" => $aliment_index + 1, + ]; + } + }else{ + + if(!isset($policyTerms['is_payable_employee'])){ + $orderedPolicyTerms[] = [ + "key" => "is_payable_employee", + "value" => [ + "self" => 0, + ], + "position" => 2, + ]; + } + } + } - // Add ailmentcapping and ailmentcappingdata if they exist_ - if (isset($policyTerms['ailmentcapping'])) { - if(!isset($policyTerms['ailment_capping_details'])){ - $aliment_index = array_search('ailmentcapping', array_keys($policyTerms)); - $orderedPolicyTerms[] = [ - "key" => "ailment_capping_details", - "value" => "", - "position" => $aliment_index + 2, - ]; - } - } + foreach ($orderedPolicyTerms as $term) { $position = $term['position']; @@ -3706,10 +3790,15 @@ class ClientController extends AdminController dd($days); } - public function sendextraparam(){ + public function sendextraparam() + { + + // dd($this->request); + // $employeeRestController = new EmployeeServiceController(); + // $employeeRestController->employeesEnrollmentInsert(['file_id' => 721]); + + // $r = Jobs::addJob(['job_name' => 'employeesEnrollmentInsert','payload' => ['file_id' => 721]]); - $employeeRestController = new EmployeeServiceController(); - $employeeRestController->employeesEnrollmentInsert(['file_id' => 683]); // $dashBoardController = new DashboardController(); // $client_policy_data = $this->clientPolicyModel->getPolicyDetailsForRemainder($client_id=159, $client_branch_id=126); @@ -3719,6 +3808,28 @@ class ClientController extends AdminController // $emp_data = $this->employeePolicyModel->getEmployeePolicyForEcard(12); // $ids = array_column($emp_data, 'id'); // $EmpDataServiceController->sendMailForDownloadingECard($ids); + + // $empServiceController = new EmployeeServiceController(); + // $res = $empServiceController->employeesOnboardPreprocess(['file_id' => '741']); } + + // ------------------------------------------------------------------------------------------------------- + + public function createOtherTabContent() + { + $this->myLogger->logme('error', 'Client Others function called'); + $data = $this->request->getPost(); + $data['created_by'] = get_session_userid(); + $client_id = $data['client_id']; + unset($data['client_id']); + + $insert = $this->clientModel->where('id', $client_id)->set($data)->update(); + + if ($insert) { + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Client others data updated', 'data' => $data], 200); + } else { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'No data to update'], 200); + } + } } diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 1a8c8382..7c0ef32b 100755 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -365,41 +365,81 @@ class DashboardController extends AdminController foreach ($client_policy_data as $client_policy) { - if (empty($send_mail_for_manual_or_crone)) { + // Fetch client data + $client_data = $this->clientModel->find($client_policy['client_id']); - // Fetch client data - $client_data = $this->clientModel->find($client_policy['client_id']); + // Fetch notification settings + $notification_data = $this->notificationModel + ->where('client_id', $client_policy['client_id']) + ->where('template_name', 'member_reminder_mail') + ->first(); - // Fetch notification settings - $notification_data = $this->notificationModel - ->where('client_id', $client_policy['client_id']) - ->where('template_name', 'member_reminder_mail') - ->first(); + if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { - // $this->myLogger->logme('error', 'Notification data fetched: ' . json_encode($notification_data)); + //manaual + if (empty($send_mail_for_manual_or_crone)) { - // Check if notification should be sent - if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { + // Check if notification should be sent $this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']); - // Fetch all employees related to the client policy - $employees = $this->employeePolicyModel - ->select('employees.*, employee_polices.id as emp_policy_id') - ->join('employees', 'employee_polices.employee_id = employees.id', 'left') - ->where('employee_polices.client_policy_id', $client_policy['id']) - ->where('employees.emp_status', 'draft') - ->where('employees.is_active', 1) - ->where('employee_polices.status', 'draft') - ->where('employee_polices.is_active', 1) - ->where('employees.relationship', 'Self') - ->findAll(); + $employees = []; + if (in_array($client_policy['policy_type_id'], [2, 4]) || ($client_policy['policy_type_id'] == 3 && $client_policy['is_addon'] == 1)) { - // dd($employees); + // Fetch all employees related to the client policy + $employees = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.emp_status', 'draft') + ->where('employee_polices.status', 'draft') + ->where('employees.relationship', 'Self') + ->where("employees.email_corporate IS NOT NULL AND employees.email_corporate != ''") + ->findAll(); + + // dd($employees, 'first'); + + } else if (($client_policy['policy_type_id'] == 3 && $client_policy['is_addon'] == 3) || $client_policy['policy_type_id'] == 5) { + + $empDependentData = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.emp_status', 'draft') + ->where('employee_polices.status', 'draft') + ->where('employees.relationship !=', 'Self') + ->findAll(); + + $empCodes = array_column($empDependentData, 'emp_code'); + + // dd($empDependentData, $empCodes,'second'); + + if (!empty($empCodes)) { + + $empSelfData = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->whereIn('employees.emp_code', $empCodes) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.relationship', 'Self') + ->where("employees.email_corporate IS NOT NULL AND employees.email_corporate != ''") + ->findAll(); + + $employees = array_merge($employees, $empSelfData); + } + } + + // dd($employees); // Process each employee - foreach ($employees as $employee) { + if (!empty($employees) && count($employees) > 0) { + + foreach ($employees as $employee) { - if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') { $this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']); // Mail params @@ -407,8 +447,8 @@ class DashboardController extends AdminController $params['client_data'] = $client_data; $params['notification_data'] = $notification_data; $params['common'] = [ - 'client_id' => $client_policy['client_id'], - 'client_branch_id' => $client_policy['client_branch_id'], + 'client_id' => $client_policy['client_id'], + 'client_branch_id' => $client_policy['client_branch_id'], 'client_policy_id' => $client_policy['id'], 'employee_policy_id' => $employee['emp_policy_id'], 'employee_id' => $employee['id'], @@ -417,54 +457,81 @@ class DashboardController extends AdminController // Send the mail notification $mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params); + // dd($mail_result); // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); - $reminder_whole_mail[] = $mail_result; + $reminder_whole_mail[] = $mail_result[0]; } } - } else { - $this->myLogger->logme('error', 'Notification was not sent for Client Policy ID: ' . $client_policy['id']); - $this->myLogger->logme('error', 'Notification setup not found or not enabled'); - } - } else { - $currentDate = date('d'); - $remainder_dates = explode(",", $client_policy['reminder_date']); + } else { // crone - foreach ($remainder_dates as $date) { + if (!empty($client_policy['reminder_date'])) { - if ($currentDate == $date) { + $currentDate = date('d'); + $remainder_dates = explode(",", $client_policy['reminder_date']); - $client_data = $this->clientModel->find($client_policy['client_id']); + foreach ($remainder_dates as $date) { - // Fetch notification settings - $notification_data = $this->notificationModel - ->where('client_id', $client_policy['client_id']) - ->where('template_name', 'member_reminder_mail') - ->first(); + if ($currentDate == $date) { - // Check if notification should be sent - if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { + $this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']); - // echo '4'; + // Fetch all employees related to the client policy + $employees = []; + if (in_array($client_policy['policy_type_id'], [2, 4]) || ($client_policy['policy_type_id'] == 3 && $client_policy['is_addon'] == 1)) { - $this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']); + $employees = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.emp_status', 'draft') + ->where('employee_polices.status', 'draft') + ->where('employees.relationship', 'Self') + ->where("employees.email_corporate IS NOT NULL AND employees.email_corporate != ''") + ->findAll(); - // Fetch all employees related to the client policy - $employees = $this->employeePolicyModel - ->select('employees.*, employee_polices.id as emp_policy_id') - ->join('employees', 'employee_polices.employee_id = employees.id', 'left') - ->where('employee_polices.client_policy_id', $client_policy['id']) - ->where('employees.emp_status', 'draft') - ->where('employees.is_active', 1) - ->where('employee_polices.status', 'draft') - ->where('employee_polices.is_active', 1) - ->where('employees.relationship', 'Self') - ->findAll(); + // dd($employees, 'first'); - // Process each employee - foreach ($employees as $employee) { + } else if (($client_policy['policy_type_id'] == 3 && $client_policy['is_addon'] == 3) || $client_policy['policy_type_id'] == 5) { + + $empDependentData = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.emp_status', 'draft') + ->where('employee_polices.status', 'draft') + ->where('employees.relationship !=', 'Self') + ->findAll(); + + $empCodes = array_column($empDependentData, 'emp_code'); + + // dd($empDependentData, $empCodes,'second'); + + if (!empty($empCodes)) { + + $empSelfData = $this->employeePolicyModel + ->select('employees.*, employee_polices.id as emp_policy_id') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->whereIn('employees.emp_code', $empCodes) + ->where('employees.is_active', 1) + ->where('employee_polices.is_active', 1) + ->where('employees.relationship', 'Self') + ->where("employees.email_corporate IS NOT NULL AND employees.email_corporate != ''") + ->findAll(); + + $employees = array_merge($employees, $empSelfData); + } + } + + // dd($employees); + + // Process each employee + foreach ($employees as $employee) { - if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') { $this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']); // Mail params @@ -472,8 +539,8 @@ class DashboardController extends AdminController $params['client_data'] = $client_data; $params['notification_data'] = $notification_data; $params['common'] = [ - 'client_id' => $client_policy['client_id'], - 'client_branch_id' => $client_policy['client_branch_id'], + 'client_id' => $client_policy['client_id'], + 'client_branch_id' => $client_policy['client_branch_id'], 'client_policy_id' => $client_policy['id'], 'employee_policy_id' => $employee['emp_policy_id'], 'employee_id' => $employee['id'], @@ -483,27 +550,33 @@ class DashboardController extends AdminController // Send the mail notification $mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params); // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); - $reminder_whole_mail[] = $mail_result; + $reminder_whole_mail[] = $mail_result[0]; } + } - } else { - // echo '5'; - $this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']); } + + } else { + $this->myLogger->logme('error', "SEND REMAINDER CRONE --- Remainder date is empty()"); } } + + } else { + + $this->myLogger->logme('error', 'Notification setup not found or not enabled'); + $this->myLogger->logme('error', 'Notification was not sent for this Client ID: ' . $client_policy['client_id']); } } // dd($reminder_whole_mail); + // print_rr($reminder_whole_mail); die; // Process and queue bulk emails if (!empty($reminder_whole_mail) && count($reminder_whole_mail) > 0) { $reminder_whole_mail = array_chunk($reminder_whole_mail, 20); - foreach ($reminder_whole_mail as $key => $value) { - $job_details = new Jobs(); + // $job_details = new Jobs(); $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]); } } @@ -515,17 +588,21 @@ class DashboardController extends AdminController } } - public function sendManualReminder($client_id, $client_branch_id) + public function sendManualReminder($client_id, $client_branch_id, $client_policy_id = null) { + $this->myLogger->logme('error','Log Works'); + $this->myLogger->logme('error', "sendManualRemainder called with client_id: {$client_id}, client_branch_id: {$client_branch_id}"); - $client_policy_data = $this->clientPolicyModel->getPolicyDetailsForRemainder($client_id, $client_branch_id); + $client_policy_data = $this->clientPolicyModel->getPolicyDetailsForRemainder($client_id, $client_branch_id, $client_policy_id); // print_r($client_policy_data); die; // print_r($this->clientPolicyModel->getLastQuery()); die; // $this->myLogger->logme('error', "Policy details fetched: " . json_encode($client_policy_data)); if ($client_policy_data) { $result = $this->sendRemainderMail($client_policy_data); + log_message('error',json_encode($result)); + $this->myLogger->logme('error',$result); $this->myLogger->logme('error', "Manual Remainder Mail sending result: " . ($result ? 'success' : 'failure')); if ($result) { @@ -552,6 +629,7 @@ class DashboardController extends AdminController { return $this->respond(['status' => false, 'code' => 400, 'message' => 'No template found','message2' => 'Failed' ], 200); } + $emp_data = $this->employeePolicyModel->getEmployeePolicyForEcard($policy_id); if(count($emp_data) == 0) diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 02c01d34..5092c22e 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -108,7 +108,7 @@ class EmployeeController extends AdminController emp_name : $filterData['emp_name'] ?? null, status : $filterData['status'] ?? [], ); - + log_message('error',json_encode($data['employees'])); // Set getData in $data array with the processed $filterData $data['getData'] = $filterData; } @@ -711,16 +711,25 @@ class EmployeeController extends AdminController public function enrollmentClientList() { $data = []; - $client_list = $this->clientModel->findAll(); - $branch_list = $this->clientBranchModel->findAll(); + $client_list = $this->clientModel->where('clients.is_active', 1)->findAll(); + $branch_list = $this->clientBranchModel->where('client_branch.is_active', 1)->findAll(); + $policy_list = $this->clientPolicyModel + ->select('client_policy.*, policy_type.policy_type') + ->join('policy_type', 'client_policy.policy_type_id = policy_type.id') + ->where('client_policy.is_active', 1) + ->findAll(); + $data['client_list'] = $client_list; $data['branch_list'] = $branch_list; + $data['policy_list'] = $policy_list; // Get session data if available $data['selected_client_id'] = session()->get('client_id'); $data['selected_branch_id'] = session()->get('branch_id'); $data['selected_type'] = session()->get('type'); + // dd($data); + $this->myLogger->logme('error', 'list called'); return $this->loadLayout('enrollment_list', $data); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 5e625d88..2d196475 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -363,7 +363,7 @@ class EmployeeRestController extends AdminController ->where('client_policy_id',$value['policy_details']['client_policy_id'] ) ->where('employee_id' , $value['temp']['emp_id'] ) ->where('is_active', 1 ) - ->set(array('premium'=> $value['policy_details']['premium'] , 'rata_premimum'=> $value['policy_details']['rata_premimum'] , 'gst'=> $value['policy_details']['gst'] )) + ->set(array('basic_cover_si' => $value['policy_details']['basic_cover_si'],'premium'=> $value['policy_details']['premium'] , 'rata_premimum'=> $value['policy_details']['rata_premimum'] , 'gst'=> $value['policy_details']['gst'] )) ->update(); } @@ -950,11 +950,13 @@ class EmployeeRestController extends AdminController } } } + $emp_policy_data =[ 'employee_id'=>$emp_id, 'client_policy_id'=>$policy_id, 'status'=> 'draft', 'date_coverage' => $date_coverage, + 'payable_employee' => check_pay_by_employee_or_company($client_policy['policy_terms'], $dataToInsert[$a]['relationship']), 'basic_cover_si'=>isset($basic_cover_si[$a]) ? $basic_cover_si[$a] : null ]; @@ -2084,11 +2086,21 @@ class EmployeeRestController extends AdminController // retun array public function calculatePremium($clientPolicyId = null , $empCode = null, $default_si = null , $client_branch_id = null)//family level { + // dd($clientPolicyId, $empCode, $default_si, $client_branch_id); 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 - $client_branch_id = $this->request->getVar('client_branch_id') ?? $client_branch_id; + + if($this->request){ // + $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 + $client_branch_id = $this->request->getVar('client_branch_id') ?? $client_branch_id; + }else{ + //Cli and enrollment + $client_policy_id = $clientPolicyId; + $emp_code = $empCode; + $default_si = $default_si;// si amt which choosed in add on policy + $client_branch_id =$client_branch_id; + } // dd($client_policy_id); diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 7297c26c..e1f58ee2 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1580,9 +1580,15 @@ class EmployeeServiceController extends AdminController // insert or update in db for inception addition depent addition public function employeesOnboardProcess($params) - { + { + // dd($params); + $familiy_data = $params['familiy_data']; $file = $params['file']; + + $policy_details = $this->clientPolicyModel->where('id', $file['policy_id'])->first(); + // dd($policy_details); + foreach($familiy_data as $fkey => $value) { if(is_array($value)) @@ -1658,7 +1664,8 @@ class EmployeeServiceController extends AdminController $policy_data['updated_by'] = $file['created_by']; $policy_data['id'] = $employee_policy[0]['id']; $policy_data['status'] = 'active'; - + $policy_data['payable_employee'] = check_pay_by_employee_or_company($policy_details['policy_terms'], $value['relationship']); + $log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si']; // echo 'insert policy'; } @@ -1668,6 +1675,8 @@ class EmployeeServiceController extends AdminController $policy_data['client_policy_id'] = $file['policy_id']; $policy_data['created_by'] = $file['created_by']; $policy_data['status'] = 'active'; + $policy_data['payable_employee'] = check_pay_by_employee_or_company($policy_details['policy_terms'], $value['relationship']); + $log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si']; // echo 'update policy'; } @@ -1930,7 +1939,7 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ public function employeesEnrollmentInsert($params) { - + // dd($this->request); helper('excel_util_helper'); //get file name $file_id = $params['file_id']; @@ -1980,6 +1989,10 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ $policy_details = $this->clientPolicyModel->where('id', $file['policy_id'])->first(); // dd($policy_details); + + //get policy slab rates + // $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); + // dd($slab_details); foreach ($excel_data as $key => $row) { @@ -2027,7 +2040,7 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ $value['family_floater_key'] = $relation; $policy_data['basic_cover_si'] = $row[9]; - $policy_data['date_coverage'] = $row[13] != "" && $row[13] != null ? change_date_format($row[13],'d-M-Y','Y-m-d') : null; + $policy_data['date_coverage'] = $row[13] != "" && $row[13] != null ? change_date_format($row[13],null,'Y-m-d') : null; $policy_data['client_policy_id'] = $file['policy_id']; $employee = $this->employeeModel->checkExistingEmployee($value,$file['client_branch_id']); @@ -2069,6 +2082,7 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ $policy_data['updated_by'] = $file['created_by']; $policy_data['id'] = $employee_policy[0]['id']; $policy_data['status'] = 'draft'; + $policy_data['payable_employee'] = check_pay_by_employee_or_company($policy_details['policy_terms'], $value['relationship']); $log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si']; // echo 'insert policy'; @@ -2079,6 +2093,8 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ $policy_data['client_policy_id'] = $file['policy_id']; $policy_data['created_by'] = $file['created_by']; $policy_data['status'] = 'draft'; + $policy_data['payable_employee'] = check_pay_by_employee_or_company($policy_details['policy_terms'], $value['relationship']); + $log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si']; // echo 'update policy'; } @@ -2087,6 +2103,10 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ $emp_policy_id = $this->employeePolicyModel->getInsertID(); $this->myLogger->logme('error',$log_message); + $employeeRestController = new EmployeeRestController(); + $employeeRestController->updatePremiumAmount($file['policy_id'], $value['emp_code'], $file['client_branch_id']); + + //save email of self for send mail later if (isset($notification) && $notification['enabled'] == 1 && $notification['mail_content'] != '') { @@ -2095,7 +2115,14 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ $params['dataToInsert'] = $value; //holds employee master data $params['notification'] = $notification; $params['client_data'] = $client_details; - + $params['common'] = [ + 'client_id' => $file['client_id'], + 'client_branch_id' => $file['client_branch_id'], + 'client_policy_id' => $file['policy_id'], + 'employee_policy_id' => $emp_policy_id ?? null, + 'employee_id' => $emp_id, + 'mail_type' => 'member_welcome_mail', + ]; //store email and mail content via helper to send notification $emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params); } @@ -2103,6 +2130,7 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ }// endof if row is empty check } //end of for loop + // dd($emp_emails); // for bulk mail queue job push if (!empty($emp_emails) && count($emp_emails) > 0) { diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 1599bac2..a875e437 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -30,6 +30,8 @@ use App\Models\StateModel; use App\Models\PolicyTypeModel; use App\Models\CDMasterModel; use App\Models\ClientDepositModel; +use App\Models\EmployeePolicyModel; +use App\Models\FileModel; use App\Models\InsurerExcelExportTemplateModel; use App\Models\SettingsModel; use App\Models\VehicleModel; @@ -1574,7 +1576,7 @@ class MasterController extends AdminController $to = $this->request->getPost('to'); $subject = $this->request->getPost('subject'); $mail_content = $this->request->getPost('content'); - + $common = ['mail_type'=>'test_mail_ui']; /*****CHOOSE ANY ONE AT A TIME, COMMENT ANOTHER ONE******/ /*****CALLING DIRECLT USING LIB******/ @@ -1591,7 +1593,7 @@ class MasterController extends AdminController /*****CALLING DIRECLT USING LIB******/ /*****CALLING VIA MAIL HELPER******/ - $res = MailHelper::send_email(['mail' => $to, 'subject' => $subject, 'message' => $mail_content]); + $res = MailHelper::send_email(['mail' => $to, 'subject' => $subject,'common'=>$common ,'message' => $mail_content]); return $this->respond(['status' => 'success','code' => 200,'data' => $res],200); /*****CALLING VIA MAIL HELPER******/ @@ -1623,10 +1625,10 @@ class MasterController extends AdminController ["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"], ["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"] ]; - - + $common = ['mail_type'=>'test_mail_cli']; $email_id = CLI::getOption('to') ? CLI::getOption('to') : $email_id; - $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments]); + $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments,'common'=>$common]); + echo "Inside the master controller"; print_r($res); } diff --git a/app/Helpers/GmailResponseHandler.php b/app/Helpers/GmailResponseHandler.php new file mode 100644 index 00000000..f2cb07f7 --- /dev/null +++ b/app/Helpers/GmailResponseHandler.php @@ -0,0 +1,125 @@ +myLogger = \Config\Services::mylogger(); + + } + + + public function receive_and_distribute_param_to_functions($params) + { + try{ + + $this->store_gmail_response_data($params); + $this->gmail_response_logger($params); + $this->client_id_flag_setter($params); + + } + catch(Exception $e) + { + + $error = $e->getMessage(); + echo "An Error Occured" . $error; + log_message('error',$error); + + } + } + + + public function store_gmail_response_data($params){ + // foreach ($params as $key => $value){ + // $prepare_data = [ + // $key => $value + // ]; + // } + // $data = [ + // 'email' => isset($params['params']['mail']) ? $params['params']['mail'] : null, + // 'bcc' => isset($params['params']['bcc']) ? json_encode($params['params']['bcc']) : null, + // 'cc' => isset($params['params']['cc']) ? json_encode($params['params']['cc']) : null, + // 'message' => isset($params['params']['message']) ? $params['params']['message'] : null, + // 'attachments' => isset($params['params']['attachments']) ? json_encode($params['params']['attachments']) : null, + // 'client_id' => isset($params['params']['common']['client_id']) ? $params['params']['common']['client_id'] : null, + // 'client_branch_id' => isset($params['params']['common']['client_branch_id']) ? $params['params']['common']['client_branch_id'] : null, + // 'client_policy_id' => isset($params['params']['common']['client_policy_id']) ? $params['params']['common']['client_policy_id'] : null, + // 'employee_policy_id' => isset($params['params']['common']['employee_policy_id']) ? $params['params']['common']['employee_policy_id'] : null, + // 'employee_id' => isset($params['params']['common']['employee_id']) ? $params['params']['common']['employee_id'] : null, + // 'mail_type' => isset($params['params']['common']['mail_type']) ? $params['params']['common']['mail_type'] : null, + // 'gmail_api_status' => isset($params['gmail_api']['status']) ? $params['gmail_api']['status'] : null, + // 'gmail_api_id' => isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null + // ]; + // Initialize data array + $data = []; + // print_r($params['params']['common']);die(); + if (isset($params['params']['common'])) { + foreach ($params['params']['common'] as $key => $value) { + $data[$key] = isset($value) ? $value : null; + } + unset($params['params']['common']); + } + if (isset($params['params'])){ + foreach($params['params'] as $key => $value){ + $arr = ['bcc','cc','attachments']; + if(in_array($key,$arr)){ + $data[$key] = isset($value)?json_encode($value):null; + }else{ + $data[$key] = isset($value)?$value:null; + } + } + } + if(isset($params['gmail_api']['status']) && $params['gmail_api']['status'] == 1 ){ + $data['gmail_api_status'] = isset($params['gmail_api']['status']) ? $params['gmail_api']['status'] : null; + $data['gmail_api_id'] = isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null; + $data['received_message'] = isset($params['gmail_api']['data']['labelIds']) ? json_encode($params['gmail_api']['data']['labelIds']) : null; + + } + elseif(isset($params['gmail_api']['status']) && $params['gmail_api']['status'] == false ){ + $data['gmail_api_status'] = $params['gmail_api']['status']; + if(isset($params['gmail_api']['data'])){ + $data['received_message'] = json_encode($params['gmail_api']['data']); + } + } + + $gmailModel = new GmailSentHistoryModel(); + $save_status = $gmailModel->insert($data); + } + + public function gmail_response_logger($params) + { + $this->myLogger->logme('error',json_encode($params)); + } + + public function client_id_flag_setter($params) + { + try{ + if (isset($params['params']['common']['mail_type'])){ + if($params['params']['common']['mail_type'] == 'member_ecard_mail'){ + $employeePolicyModel = new EmployeePolicyModel(); + $update_status = $employeePolicyModel->where('id',$params['params']['common']['employee_policy_id'])->set('ecard_sent_status',1)->update(); + if($update_status){ + $this->myLogger->logme('error',"ecard_sent_status updated for ".$params['params']['common']['employee_policy_id']); + }else{ + $this->myLogger->logme('error','ecard_sent_status failed to update'); + } + } + + } + } + catch(Exception $e){ + $error = $e->getMessage(); + $this->myLogger->logme('error','An Error Occured - '.$error); + } + } + + +} \ No newline at end of file diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php index 196bdaca..41d76b5c 100755 --- a/app/Helpers/JWTToken.php +++ b/app/Helpers/JWTToken.php @@ -11,7 +11,7 @@ use Firebase\JWT\SignatureInvalidException; // use Psr\Http\Message\RequestInterface; use CodeIgniter\HTTP\RequestInterface; use ReflectionClass; - +use Exception; use App\Models\EmployeeModel; use App\Models\LevelContactModel; diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 0bc21c46..6116bc0c 100755 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -11,7 +11,6 @@ use PHPMailer\PHPMailer\Exception; use App\Models\JobModel; - class MailHelper { public static function send_email_smtp($params) @@ -94,7 +93,7 @@ class MailHelper $subject = $params['subject']; $message = $params['message']; $attachments = isset($params['attachments']) && count($params['attachments']) ? $params['attachments'] : []; - + $common = isset($params['common'])?$params['common']:''; //check BCC mail if (isset($params['bcc'])) { $bcc = $params['bcc']; @@ -118,32 +117,42 @@ class MailHelper if(isset($params['reply_to']) && !empty($params['reply_to'])){ $reply_to = $params['reply_to']; } + $MailDataHelper = new GmailResponseHandler(); + $res['params'] = $params; try { - $res = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc,$attachments); - - if($res['status']) + $res['gmail_api'] = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc,$attachments); + if($res['gmail_api']['status']) { + $response = $res; + $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'success','code' => 200, 'message'=>('Email Sent Successfully...'.$emaill),'data' => $res,],200); } else { $myLogger->logme('error', "mail sent failed - $emaill"); + $response = $res; + $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'failed','code' => 404,'message'=>( 'Email Sent Failed...' . $emaill ),'data' => $res ],404); } } catch (Exception $e) { - $msg = $e->getMessage(); + $msg['error'] = $e->getMessage(); + $msg['params'] = $params; $myLogger->logme('error', "mail sent failed - $msg"); + $response = $msg; + $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'failed','code' => 500,'data' => $msg],500); - } + } + + } public static function bulk_mail(array $mails = []) { - // print_r();die; + // print_r($mails);die; $model = new JobModel(); $start = microtime(true); $runtime= 0; @@ -156,7 +165,9 @@ class MailHelper return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...'],200); } catch (\Throwable $th) { - return json_encode(['status' => 'failed','code' => 500],500); + $error = $th->getMessage(); + log_message('error',$error); + return json_encode(['status' => 'failed','code' => 500,'error'=>$error],500); } } diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 9a27ab9b..76cf51a3 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -1209,7 +1209,7 @@ if (!function_exists('premium_calculation_manager')) $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3 ) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1232,7 +1232,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { // dd($slab_value); $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1253,7 +1253,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3 ) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1273,7 +1273,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { // echo $emp_data['name']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1295,7 +1295,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1317,7 +1317,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1339,7 +1339,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1366,7 +1366,7 @@ if (!function_exists('premium_calculation_manager')) if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) && (($slab_value['premium_type'] == 1 && - ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ) ) + ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) ) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; $emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']; @@ -1391,7 +1391,7 @@ if (!function_exists('premium_calculation_manager')) { if($slab_value['si'] == $employee_received_si && $slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && - ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { //calculate premium based on count // echo $emp_data['name']; @@ -1420,7 +1420,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['basic_cover_si'] = null; foreach ($temp_slab_rates as $skey => $slab_value) { - if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) + if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; @@ -1445,7 +1445,7 @@ if (!function_exists('premium_calculation_manager')) $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; foreach ($temp_slab_rates as $skey => $slab_value) { - if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) + if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; @@ -1466,6 +1466,13 @@ if (!function_exists('premium_calculation_manager')) default: $myLogger->logme('error',($emp_data['emp_code'].'-'.$emp_data['name'].' - grid type not found')); } + + //this if condition for premium calculated & premium type 3 (familiy floater but premium calculated every individual implemented later) then remove si amount only for dependents (not self) + if($is_match_found && strtolower($emp_data['relationship']) != 'self' && $temp_slab_rates[0]['premium_type'] == 3) + { + //set dependent si to 0 + $emp_data['policy_details']['basic_cover_si'] = 0; + } if(!$is_match_found) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index e6b6edf9..cb87e28f 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -81,76 +81,18 @@ class sendMailNotification $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); - if ($emp_data && (isset($notification_data) && $notification_data['enabled'] == 1)) { - if(isset($emp_data['relationship'])){ - if ($emp_data['relationship'] == 'Self') { - if(count($emp_data) > 0){ - $mail =''; - if ($emp_data['relationship'] == 'Self') { - $employee_name =$emp_data['name']; - $employee_mobile_no =$emp_data['mobile']; - $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail_content = str_replace("[[member_mobile]]", $employee_mobile_no, $mail_content); - $mail = $emp_data['email_corporate']; - } - } - }else{ - $mail =''; - } - - }else{ - $employee_name =$emp_data['name']; - $employee_mobile_no =$emp_data['mobile']; - $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail_content = str_replace("[[member_mobile]]", $employee_mobile_no, $mail_content); - $mail = $emp_data['email_corporate']; - } - - if (isset($mail) && !empty($mail)) { - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common]; - } + - }else{ - - foreach ($emp_data as $key => $value) { - if ($value['relationship'] != 'Self') { - $emp_data = $EmployeeModel->where('client_id', $client_data['id'])->where('emp_code', $value['emp_code'])->where('is_active',1)->findAll(); - if(count($emp_data) > 1){ - $mail =''; - foreach ($emp_data as $key => $values) { - if ($value['relationship'] == 'Self') { - $employee_name =$values['name']; - $employee_mobile_no =$values['mobile']; - $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail_content = str_replace("[[member_mobile]]", $employee_mobile_no, $mail_content); - $mail = $values['email_corporate']; - } - } - }else{ - $mail =''; - } - }else{ - $employee_name =$value['name']; - $employee_mobile_no =$value['mobile']; - $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail_content = str_replace("[[member_mobile]]", $employee_mobile_no, $mail_content); - $mail = $value['email_corporate']; - } - if (isset($mail) && !empty($mail)) { - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common]; - } - } - } + $employee_name =$emp_data['name']; + $employee_mobile_no =$emp_data['mobile']; + $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); + $mail_content = str_replace("[[member_mobile]]", $employee_mobile_no, $mail_content); + $mail = $emp_data['email_corporate']; - if (count($wholeData) < 1) { - $wholeData = []; - } + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common]; return $wholeData; - // }else{ - // return "false"; - // } } else if($action == 'member_ecard_mail'){ @@ -249,7 +191,11 @@ class sendMailNotification // echo '
';
                 // print_r($array_list); die;
 
+               
+
                 foreach ($array_list as $item) {
+
+                    $payable_employee_array = [];
                     
                     if (count($item) != 0) {
 
@@ -269,6 +215,12 @@ class sendMailNotification
                             }
                             //end of getting policy premium data
 
+                            if($inner_item['payable_employee'] == 1 && $client_policy_data['policy_type_id'] == 2){
+                                $payable_employee_array[] = $inner_item;
+                            }
+
+                            // dd($policy_premium_data);
+
                             $policy_name = $inner_item['policy_name'];
                             
                             if ($inner_item['relationship'] == 'Self') {
@@ -282,11 +234,11 @@ class sendMailNotification
                             $premium = '';
                             $gst_forself = '';
                             
-                            if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){
+                            // if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){
                                 $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']);
-                                $premium = '₹ ' .format_indian_number(round($inner_item['premium']));
+                                $premium = '₹ ' .format_indian_number(round($inner_item['rata_premimum']));
                                 $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst']));
-                            }
+                            // }
                     
                             $temp_data .= '';
                             $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . '';
@@ -352,6 +304,89 @@ class sendMailNotification
                         $addtional_premium = 0;
                         $gst = 0;
                     }
+
+                    if(count($payable_employee_array) > 0){
+
+                        $table_content .= '

Policy Type :'; + $temp_data = ''; + $is_addon = ''; + + foreach ($payable_employee_array as $inner_item) { + + + //getting policy premium data + $client_policy_data = $clientPolicyModel->where('id', $inner_item['client_policy_id'])->first(); + if($client_policy_data['policy_type_id'] == 1 || $client_policy_data['policy_type_id'] == 6 || $client_policy_data['policy_type_id'] == 7 ){ + $policy_premium_data = $PolicyPremium1Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + }else{ + $policy_premium_data = $PolicyPremium2Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } + //end of getting policy premium data + + + $si = ''; + $premium = ''; + $gst_forself = ''; + + $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']); + $premium = '₹ ' .format_indian_number(round($inner_item['rata_premimum'])); + $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst'])); + + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; + $temp_data .= '' . $inner_item['relationship'] . ''; + $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + $temp_data .= '' . $si . ''; + $temp_data .= '' . $premium . ''; + $temp_data .= '' . $gst_forself . ''; + + $temp_data .= ''; + + $is_addon = $inner_item['is_addon']; + + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + $gst = $inner_item['gst'] + $gst; + } + + $policy_name_for_policy_type = $inner_item['policy_name']; + if($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3){ + $policy_name_for_policy_type = 'Add-On Group Medical Coverage for Parents'; + } + + $table_content .= $policy_name_for_policy_type . ' ( Payable By Employee )

'; + $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + $table_content .= ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + + $addon_list_array = [ + 'policy_name' => $policy_name_for_policy_type . '( Payable By Employee )', + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + $Addon_list[] = $addon_list_array; + + + $temp_data = ''; + $addtional_premium = 0; + $gst = 0; + + } } if (count($Addon_list) > 0) { @@ -393,6 +428,7 @@ class sendMailNotification // $table_content .= '
' . $sum_total_words . '
'; } + // dd($payable_employee_array, $Addon_list); // print_r($table_content); die; $mail_content = str_replace("[[member_name]]", $name . ' (' . $emp_code . ')' , $mail_content); @@ -462,6 +498,9 @@ class sendMailNotification $Addon_list = []; foreach ($array_list as $item) { + + $payable_employee_array = []; + if (count($item) != 0) { $table_content .= '

Policy Type :'; $temp_data = ''; @@ -479,6 +518,10 @@ class sendMailNotification } //end of getting policy premium data + if($inner_item['payable_employee'] == 1 && $client_policy_data['policy_type_id'] == 2){ + $payable_employee_array[] = $inner_item; + } + $policy_name = $inner_item['policy_name']; if ($inner_item['relationship'] == 'Self') { @@ -490,11 +533,11 @@ class sendMailNotification $si = ''; $premium = ''; $gst_forself = ''; - if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ + // if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']); $premium = '₹ ' .format_indian_number(round($inner_item['premium'])); $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst'])); - } + // } $temp_data .= ''; $temp_data .= '' . $inner_item['name'] . $emp_code . ''; @@ -560,6 +603,90 @@ class sendMailNotification $addtional_premium = 0; $gst = 0; } + + if(count($payable_employee_array) > 0){ + + $table_content .= '

Policy Type :'; + $temp_data = ''; + $is_addon = ''; + + foreach ($payable_employee_array as $inner_item) { + + + //getting policy premium data + $client_policy_data = $clientPolicyModel->where('id', $inner_item['client_policy_id'])->first(); + if($client_policy_data['policy_type_id'] == 1 || $client_policy_data['policy_type_id'] == 6 || $client_policy_data['policy_type_id'] == 7 ){ + $policy_premium_data = $PolicyPremium1Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + }else{ + $policy_premium_data = $PolicyPremium2Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } + //end of getting policy premium data + + + $si = ''; + $premium = ''; + $gst_forself = ''; + + $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']); + $premium = '₹ ' .format_indian_number(round($inner_item['rata_premimum'])); + $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst'])); + + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; + $temp_data .= '' . $inner_item['relationship'] . ''; + $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + $temp_data .= '' . $si . ''; + $temp_data .= '' . $premium . ''; + $temp_data .= '' . $gst_forself . ''; + + $temp_data .= ''; + + $is_addon = $inner_item['is_addon']; + + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + $gst = $inner_item['gst'] + $gst; + } + + $policy_name_for_policy_type = $inner_item['policy_name']; + if($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3){ + $policy_name_for_policy_type = 'Add-On Group Medical Coverage for Parents'; + } + + $table_content .= $policy_name_for_policy_type . ' ( Payable By Employee )

'; + $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + $table_content .= ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + + $addon_list_array = [ + 'policy_name' => $policy_name_for_policy_type . '( Payable By Employee )', + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + $Addon_list[] = $addon_list_array; + + + $temp_data = ''; + $addtional_premium = 0; + $gst = 0; + + } + } if (count($Addon_list) > 0) { @@ -667,8 +794,11 @@ class sendMailNotification $gst = 0; $array_list = $params['array_list']; $Addon_list = []; - + foreach ($array_list as $item) { + + $payable_employee_array = []; + if (count($item) != 0) { $table_content .= '

Policy Type :'; $temp_data = ''; @@ -686,6 +816,10 @@ class sendMailNotification } //end of getting policy premium data + if($inner_item['payable_employee'] == 1 && $client_policy_data['policy_type_id'] == 2){ + $payable_employee_array[] = $inner_item; + } + $policy_name = $inner_item['policy_name']; if ($inner_item['relationship'] == 'Self') { @@ -700,11 +834,11 @@ class sendMailNotification // dd($policy_premium_data, $client_policy_data, $inner_item); - if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ + // if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']); $premium = '₹ ' .format_indian_number(round($inner_item['premium'])); $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst'])); - } + // } $temp_data .= ''; $temp_data .= '' . $inner_item['name'] . $emp_code . ''; @@ -770,6 +904,89 @@ class sendMailNotification $addtional_premium = 0; $gst = 0; } + + if(count($payable_employee_array) > 0){ + + $table_content .= '

Policy Type :'; + $temp_data = ''; + $is_addon = ''; + + foreach ($payable_employee_array as $inner_item) { + + + //getting policy premium data + $client_policy_data = $clientPolicyModel->where('id', $inner_item['client_policy_id'])->first(); + if($client_policy_data['policy_type_id'] == 1 || $client_policy_data['policy_type_id'] == 6 || $client_policy_data['policy_type_id'] == 7 ){ + $policy_premium_data = $PolicyPremium1Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + }else{ + $policy_premium_data = $PolicyPremium2Model->where('client_policy_id', $inner_item['client_policy_id'])->where('is_active', '1')->first(); + } + //end of getting policy premium data + + + $si = ''; + $premium = ''; + $gst_forself = ''; + + $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']); + $premium = '₹ ' .format_indian_number(round($inner_item['rata_premimum'])); + $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst'])); + + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; + $temp_data .= '' . $inner_item['relationship'] . ''; + $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; + $temp_data .= '' . $si . ''; + $temp_data .= '' . $premium . ''; + $temp_data .= '' . $gst_forself . ''; + + $temp_data .= ''; + + $is_addon = $inner_item['is_addon']; + + $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; + $gst = $inner_item['gst'] + $gst; + } + + $policy_name_for_policy_type = $inner_item['policy_name']; + if($client_policy_data['policy_type_id'] == 3 && $client_policy_data['is_addon'] == 3){ + $policy_name_for_policy_type = 'Add-On Group Medical Coverage for Parents'; + } + + $table_content .= $policy_name_for_policy_type . ' ( Payable By Employee )

'; + $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + $table_content .= ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; + + + $addon_list_array = [ + 'policy_name' => $policy_name_for_policy_type . '( Payable By Employee )', + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + $Addon_list[] = $addon_list_array; + + + $temp_data = ''; + $addtional_premium = 0; + $gst = 0; + + } } if (count($Addon_list) > 0) { diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index fe345717..79523f60 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -24,9 +24,9 @@ if (!function_exists('generate_uuid')) { } } -if (!function_exists('change_date_format')) { +if (!function_exists('change_date_format2')) { - function change_date_format($data, $source_format, $output_format) + function change_date_format2($data, $source_format, $output_format) { $data = trim($data); // echo $data, $source_format, $output_format;return true; @@ -404,67 +404,68 @@ if(!function_exists('checkFamilyFloaters')){ } } +if (!function_exists('numberToWords')) { + 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' + ); -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) : ''); + if ($number < 21) { + return $words[$number]; } - } - return $number; // Fallback for numbers beyond the supported range + 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 + } } if (!function_exists('print_rr')) { @@ -493,6 +494,7 @@ if (!function_exists('get_server_details')) { ]; } } + if (!function_exists('isJsonString')) { function isJsonString($input) @@ -501,3 +503,161 @@ if (!function_exists('isJsonString')) { return (json_last_error() === JSON_ERROR_NONE); // Check if the last JSON error is "no error" } } + +if (!function_exists('isValidDate')) { + function isValidDate($date, $format) { + $parsed_date = DateTime::createFromFormat($format, $date); + return $parsed_date && $parsed_date->format($format) === $date; + } +} + +if (!function_exists('change_date_format')) { + + function change_date_format($date_str, $source_format = null, $output_format = 'Y-m-d') { + + $date_str = trim($date_str); + // Allowed date formats + $allowed_formats = [ + // Day Month Year (clear unambiguous formats) + 'd M Y', // 01 Dec 2024 + 'd-M-Y', // 01-Dec-2024 + 'd/M/Y', // 01/Dec/2024 + 'd.M.Y', // 01.Dec.2024 + 'd,M,Y', // 01,Dec,2024 + + // Month Day Year (clear unambiguous formats) + 'M d Y', // Dec 01 2024 + 'M-d-Y', // Dec-01-2024 + 'M/d/Y', // Dec/01/2024 + 'M.d.Y', // Dec.01.2024 + 'M,d,Y', // Dec,01,2024 + + // Year Month Day (clear unambiguous formats) + 'Y M d', // 2024 Dec 01 + 'Y-M-d', // 2024-Dec-01 + 'Y/M/d', // 2024/Dec/01 + 'Y.M.d', // 2024.Dec.01 + 'Y,M,d', // 2024,Dec,01 + + // Year Numeric Month Numeric Day + 'Y-m-d', // 2024-12-01 + 'Y/m/d', // 2024/12/01 + 'Y.m.d', // 2024.12.01 + 'Y,m,d', // 2024,12,01 + ]; + + try { + // Case 1: Source and Output formats are provided + if ($source_format !== null && $output_format !== null) { + $date = DateTime::createFromFormat($source_format, $date_str); + if (!$date) { + throw new Exception("Invalid date string for source format: $source_format"); + } + return $date->format($output_format); + } + + // Case 2: Source format is provided, Output format is null + if ($source_format !== null && $output_format === null) { + $date = DateTime::createFromFormat($source_format, $date_str); + if (!$date) { + throw new Exception("Invalid date string for source format: $source_format"); + } + return $date->format('Y-m-d'); // MySQL default format + } + + // Case 3: Source format is null, auto-detect format + if ($source_format === null) { + foreach ($allowed_formats as $format) { + if (isValidDate($date_str, $format)) { + $date = DateTime::createFromFormat($format, $date_str); + return $date->format($output_format); // Default is MySQL format + } + } + // If no format matches, throw an exception + $allowed_placeholders = implode(', ', $allowed_formats); + throw new Exception("Invalid date string format. Allowed formats: $allowed_placeholders"); + } + } catch (Exception $e) { + return "Error: " . $e->getMessage(); + } + + return null; + } +} + +// if (!function_exists('check_pay_by_employee_or_company')) +// { + +// function check_pay_by_employee_or_company($is_payable_employee = null, $relationship = null) { + +// $relationship = strtolower(str_replace(" ", "_", $relationship)); + +// $result = 0; + +// if($relationship == 'self'){ + +// $result = $is_payable_employee['self'] == 1 ? 1 : 0; + +// }else if($relationship == 'spouse'){ + +// $result = $is_payable_employee['spouse'] == 1 ? 1 : 0; + +// }else if(in_array($relationship, ['son', 'daughter'])){ + +// $result = $is_payable_employee['childern'] == 1 ? 1 : 0; + +// }else if(in_array($relationship, ['father', 'mother', 'father_in_law', 'mother_in_law'])){ + +// $result = $is_payable_employee['elders'] == 1 ? 1 : 0; + +// } + +// return $result; +// } +// } + +if (!function_exists('check_pay_by_employee_or_company')) { + + function check_pay_by_employee_or_company($policy_terms = null, $relationship = null) + { + + // dd($policy_terms, $relationship); + + if (!$policy_terms || !($policy_terms = json_decode($policy_terms, true))) { + return 0; + } + + // dd($policy_terms, $relationship); + + if (!isset($policy_terms['is_payable_employee'])) { + return 0; + } + + $is_payable_employee = $policy_terms['is_payable_employee']; + + $relationship = strtolower(str_replace(" ", "_", $relationship)); + + // dd($is_payable_employee, $relationship); + + $relationshipMap = [ + 'self' => 'self', + 'spouse' => 'spouse', + 'son' => 'childern', + 'daughter' => 'childern', + 'father' => 'elders', + 'mother' => 'elders', + 'father_in_law' => 'elders', + 'mother_in_law' => 'elders' + ]; + + if (array_key_exists($relationship, $relationshipMap)) { + $key = $relationshipMap[$relationship]; + + return isset($is_payable_employee[$key]) && $is_payable_employee[$key] == 1 ? 1 : 0; + } + + return 0; + } + +} + diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index 2151ec97..1013d0d0 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -39,6 +39,7 @@ class ClientModel extends Model "email", "reply_to", "mail_domain", + "addon_subheading", ]; diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index aac8cd01..7ed17d10 100755 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -390,21 +390,26 @@ public function getCliendDataForExcelFileName($client_policy_id){ } //for this using in CRONE JOB -public function getPolicyDetailsForRemainder($client_id = null, $branch_id = null) +public function getPolicyDetailsForRemainder($client_id = null, $branch_id = null, $policy_id = null) { $builder = $this->table('client_policy') - ->where('client_policy.is_addon', 1) - ->where('client_policy.open_for_enrollment', 1) - ->where('client_policy.inception_type', 2) ->where('client_policy.is_active', 1) ->where('client_policy.policy_status', 1) - ->whereIn('client_policy.policy_type_id', [2, 3]); - + // ->where('client_policy.is_addon', 1) + // ->where('client_policy.inception_type', 2) + ->where('client_policy.open_for_enrollment', 1); + if ($client_id && $branch_id) { $builder->where('client_policy.client_id', $client_id) ->where('client_policy.client_branch_id', $branch_id); } + if(empty($policy_id)){ + $builder->whereIn('client_policy.policy_type_id', [2, 3, 4, 5]); + }else{ + $builder->where('client_policy.id', $policy_id); + } + return $builder->get()->getResultArray(); } diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index edffa781..06c39c7f 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -106,7 +106,7 @@ class EmployeeModel extends Model public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,array $emp_status = [],array $policy_status = [],array $relationship = [],array $client_branch_id = []) { - $result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employees.unit','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policy_type.long_name as policy_name','client_policy.is_addon']) + $result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employees.unit','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policy_type.long_name as policy_name','client_policy.is_addon', 'employee_polices.payable_employee']) ->join('employee_polices', 'employee_polices.employee_id = employees.id') ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') ->join('policy_type', 'policy_type.id = client_policy.policy_type_id','left') @@ -149,7 +149,7 @@ class EmployeeModel extends Model { return $this->db->table('employee_polices') - ->select(' policy_type.long_name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment, client_policy.is_member_modify_allowed, client_policy.disclaimer,client_policy.policy_type_id , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') // Select all columns from both tables + ->select(' policy_type.long_name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment,client_policy.disclaimer,client_policy.policy_type_id , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') // Select all columns from both tables ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') ->where('client_policy.policy_status', 1) diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 2d285bb6..2eda9d79 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -33,6 +33,8 @@ class EmployeePolicyModel extends Model "rand_string", "is_active", "claim_status", + 'ecard_sent_status', + 'payable_employee', ]; // Callbacks @@ -125,7 +127,6 @@ class EmployeePolicyModel extends Model ->join('client_branch', 'emp.client_branch_id = client_branch.id') //cm - client master ->orderBy('emp.emp_code', 'ASC') ->orderBy('employee_polices.employee_id', 'ASC'); - // Conditionally add where clauses if ($client_id != 0 && !empty($client_id)) { $result->where('emp.client_id', $client_id); @@ -194,6 +195,7 @@ class EmployeePolicyModel extends Model $result->where('employee_polices.is_active', 1) ->where('employee_polices.status', 'active') ->where('employee_polices.tpa_id is not null') + ->where('employee_polices.ecard_sent_status',0) ->where('emp.relationship','Self'); return $result->findAll(); diff --git a/app/Models/GmailSentHistoryModel.php b/app/Models/GmailSentHistoryModel.php new file mode 100644 index 00000000..9a0ae8ea --- /dev/null +++ b/app/Models/GmailSentHistoryModel.php @@ -0,0 +1,11 @@ +Policies +
+ - diff --git a/app/Views/client_others_tab.php b/app/Views/client_others_tab.php new file mode 100644 index 00000000..e7f0979c --- /dev/null +++ b/app/Views/client_others_tab.php @@ -0,0 +1,81 @@ +
+
+
+
+
+ + +
+
+
+ + +
+
+
+
+ +
+
+
+
+
+ +
+ + + + \ No newline at end of file diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index fd4a01a5..7a3b3911 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -175,14 +175,14 @@
-
+
@@ -827,11 +827,11 @@ } // Member Modify Data Enable or Disable - if (res.data.is_member_modify_allowed == 1) { - $('#is_member_modify_allowed').prop('checked', true); - } else { - $('#is_member_modify_allowed').prop('checked', false); - } + // if (res.data.is_member_modify_allowed == 1) { + // $('#is_member_modify_allowed').prop('checked', true); + // } else { + // $('#is_member_modify_allowed').prop('checked', false); + // } // if (res.data.is_addon != '1' && res.data.is_addon != '0') { @@ -1199,7 +1199,9 @@ } else if (input) { // console.log( 'input type step 2', typeof input); // Handle the case where input is a string - number = parseFloat(input.replace(/,/g, ''), 10); + // number = parseFloat(input.replace(/,/g, ''), 10); + number = parseFloat(String(input).replace(/,/g, ''), 10); + } else { // Handle the case where input is undefined or null number = NaN; // or handle as needed diff --git a/app/Views/enrollment_list.php b/app/Views/enrollment_list.php index edbdd473..d88a4619 100755 --- a/app/Views/enrollment_list.php +++ b/app/Views/enrollment_list.php @@ -17,7 +17,7 @@ /* background-color: #eb7a76; */ background-color: darkgrey; /* padding-bottom: 1px; */ - padding-top: 10px; + /* padding-top: 10px; */ } #tickets-table_filter { @@ -59,24 +59,31 @@

-
+
+
+ +
+
- +
-
+ -
+
- +
@@ -84,7 +91,7 @@
-
@@ -234,6 +241,7 @@