From 18f449ecce04ba2b8d31a4e0161d328325c6f00f Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 14 Oct 2024 11:17:12 +0530 Subject: [PATCH] FEAT_TESTING_CLIENT_NOTIFICATION_MAIL_FUNCTION_AND_OTHERS : RV --- app/Config/Routes.php | 5 +- app/Controllers/NotificationController.php | 41 +- app/Helpers/sendMailNotification.php | 551 +++++++++++++++++++++ app/Models/ClientModel.php | 1 + app/Views/notification.php | 231 ++++++++- 5 files changed, 803 insertions(+), 26 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6269cfd1..58ba30e4 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -12,9 +12,9 @@ $routes->get('/swagger', 'SwaggerController::index', ['filter' => 'authMVC']); // Reminder Mail Notification $routes->get("reminder_mail", "NotificationController::reminder_mail"); -// $routes->get("testing", "ClientController::Testing"); +$routes->get("testing", "ClientController::Testing"); // $routes->get("testing", "DashboardController::updatePolicyEnrollmentStatus"); -$routes->get("testing", "DashboardController::sendCroneRemainderMail"); +// $routes->get("testing", "DashboardController::sendCroneRemainderMail"); $routes->get("update-policy-terms-for-corrections", "ClientController::updatePolicyTermsForCorrections"); $routes->get("update_rack_rate_json", "ClientController::updateRackRateJson"); $routes->get("updatajson", "EmpDataServiceController::updatajson"); @@ -315,6 +315,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("get_client_policy_data_using_policy_no_and_endo_no/(:any)", "ClientController::get_client_policy_data_using_policy_no_and_endo_no/$1"); $routes->get("checkInvoiceStatus/(:any)", "PolicyTransactionController::checkInvoiceStatus/$1"); $routes->get("base_policy_for_policy_inception/(:any)", "PolicyTransactionController::getBasePolicy/$1"); + $routes->get("sentTestMail/(:any)", "NotificationController::sentTestMail/$1"); }); diff --git a/app/Controllers/NotificationController.php b/app/Controllers/NotificationController.php index 2c050523..ff666cef 100755 --- a/app/Controllers/NotificationController.php +++ b/app/Controllers/NotificationController.php @@ -18,18 +18,20 @@ use App\Models\EmployeeModel; use App\Models\UserModel; use App\Helpers\sendMailNotification; - +use App\Helpers\MailHelper; class NotificationController extends AdminController { use ResponseTrait; protected $myLogger; protected $notificationModel; + protected $clientModel; public function __construct() { $this->myLogger = \Config\Services::mylogger(); $this->notificationModel = new NotificationModel(); + $this->clientModel = new ClientModel(); } // This is for Template Name Camel Case to Snake Case for store in DB @@ -88,6 +90,8 @@ class NotificationController extends AdminController $id =$this->request->getPost('client_id'); $clientData['common_mails'] = $this->request->getPost('nhance_team_mail_ids'); $clientData['hr_mails'] = $this->request->getPost('hr_mail_id'); + $clientData['reply_to'] = $this->request->getPost('reply_to'); + $clientData['mail_domain'] = $this->request->getPost('mail_domain'); $clientModel->update($id,$clientData); foreach ($data as $key => $value) @@ -159,4 +163,39 @@ class NotificationController extends AdminController } } } + + // This function for sent a mail for testing + public function sentTestMail($template_id, $test_mail) + { + $notification_data = $this->notificationModel->where('id', $template_id)->where('enabled', 1)->first(); + $client_data = $this->clientModel->where('id', $notification_data['client_id'])->where('is_active', 1)->first(); + + if(!empty($notification_data)){ + + $params = [ + 'client_data' => $client_data, + 'notification_data' => $notification_data, + 'test_mail' => $test_mail + ]; + + $testMailData = sendMailNotification::sendMailNotificationForTesting($notification_data['template_name'], $params); + // print_r($testMailData); die; + if (!empty($testMailData)) { + + $mail_send_return1 = MailHelper::send_email($testMailData); + $this->myLogger->logme("info", $mail_send_return1); + $this->myLogger->logme("info", $mail_send_return1); + + return $this->respond(['status' => true,'code' => 200, 'respond' => json_decode($mail_send_return1)]); + + }else{ + + return $this->respond(['status' => false,'code' => 200, 'message' => 'Test Mail Data Does Not Exist']); + } + }else{ + + return $this->respond(['status' => false,'code' => 200, 'message' => 'Notification Template not enabled']); + + } + } } \ No newline at end of file diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index b0ae954c..91907824 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -689,4 +689,555 @@ class sendMailNotification } } + + public static function sendMailNotificationForTesting($action, $params) + { + $wholeData =[]; + + if ($action == 'member_welcome_mail') { + + $clientModel = new ClientModel(); + + $notification = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + $mail_content = $notification['mail_content']; + $subject = $notification['subject']; + + $employee_name = 'John Doe'; + + $app_link = $_ENV['App_Url']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); + $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); + $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + + $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); + + if ($mail != null || $mail != '') { + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; + } + + return $wholeData; + + } else if($action == 'member_reminder_mail'){ + + $notification_data = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + $mail_content = $notification_data['mail_content']; + $subject = $notification_data['subject']; + + $nhance_logo = $_ENV['NHANCE_LOGO']; + $app_link = $_ENV['App_Url']; + + $employee_name = 'John Doe'; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + $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 ((isset($notification_data) && $notification_data['enabled'] == 1)) { + + if (isset($mail) && !empty($mail)) { + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; + } + + } + + return $wholeData; + + + } else if($action == 'member_ecard_mail'){ + + $notification = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + $mail_content = $notification['mail_content']; + $subject = $notification['subject']; + + $rand_string = 'HX3kUh'; + $link = generate_download_link($rand_string); + + $name = 'John Doe'; + + $nhance_logo = $_ENV['NHANCE_LOGO']; + $app_link = $_ENV['App_Url']; + $post_enrollment_app_link = $_ENV['POST_ENROLLMENT_APP_LINK']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); + $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); + + $mail_content = str_replace("[[member_name]]", $name, $mail_content); + $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); + $mail_content = str_replace("[[post_enrollment_app_link]]", "Review Details", $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'], 'reply_to' => $client_data['reply_to']]; + + return $wholeData; + + } else if($action == 'member_review_and_summary_mail'){ + + $array_list = [ + 'policy_name' => 'Health Insurance Plan', + 'emp_code' => 'E12345', + 'name' => 'John Doe', + 'relationship' => 'Self', + 'dob' => '1985-05-15', + 'basic_cover_si' => 500000, + 'premium' => 12000, + 'gst' => 2160, + 'rata_premimum' => 12000, + 'is_addon' => 2 + ]; + + + $notification_data = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + if (isset($notification_data) && $notification_data['enabled'] == 1) { + + $mail_content = $notification_data['mail_content']; + $subject = $notification_data['subject']; + + $app_link = $_ENV['App_Url']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + $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); + + // Step 1: Replace the placeholder with an HTML table structure + $table_content = ''; + $addtional_premium = 0; + $gst = 0; + $Addon_list = []; + $name = $array_list['name']; + $emp_code = ''; + + if (!empty($array_list)) { + + $table_content .= '

Policy Name : '; + + $policy_name = $array_list['policy_name']; + + if ($array_list['relationship'] == 'Self') { + $emp_code = ' (' . $array_list['emp_code'] . ')'; + } else { + $emp_code = ''; + } + + // Start table row + $table_content .= $policy_name . '

'; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Table body with details + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
' . $array_list['name'] . $emp_code . '' . $array_list['relationship'] . '' . \DateTime::createFromFormat('Y-m-d', $array_list['dob'])->format('d-m-Y') . '₹' . format_indian_number($array_list['basic_cover_si']) . '₹' . format_indian_number(round($array_list['premium'])) . '₹' . format_indian_number(round($array_list['gst'])) . '
'; + + // Calculate additional premium and GST if applicable + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $addtional_premium = $array_list['rata_premimum']; + $gst = $array_list['gst']; + + // Prepare addon summary + $addon_list_array = [ + 'policy_name' => $policy_name, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + + $Addon_list[] = $addon_list_array; + } + + // Generate summary table for addon if applicable + if (count($Addon_list) > 0) { + $table_content .= '
'; + $table_content .= ''; + + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $total_addon = $Addon_list[0]['gst'] + $Addon_list[0]['addtional_premium']; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $sum_total_words = numberToWords($total_addon); + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= '
Policy NameAdditional PremiumGSTTotal
' . $Addon_list[0]['policy_name'] . '₹' . format_indian_number($Addon_list[0]['addtional_premium']) . '₹' . format_indian_number($Addon_list[0]['gst']) . '₹' . format_indian_number($total_addon) . '
Total₹' . format_indian_number($total_addon) . '
'; + } + } + + $mail_content = str_replace("[[member_name]]", $name . ' (' . $emp_code . ')' , $mail_content); + $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); + + + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; + + return $wholeData; + + } + + } else if($action == 'account_maneger_summary_mail'){ + + $array_list = [ + 'policy_name' => 'Health Insurance Plan', + 'emp_code' => 'E12345', + 'name' => 'John Doe', + 'relationship' => 'Self', + 'dob' => '1985-05-15', + 'basic_cover_si' => 500000, + 'premium' => 12000, + 'gst' => 2160, + 'rata_premimum' => 12000, + 'is_addon' => 2 + ]; + + $notification_data = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + if (isset($notification_data) && $notification_data['enabled'] == 1) { + + $mail_content = $notification_data['mail_content']; + $subject = $notification_data['subject']; + + $app_link = $_ENV['App_Url']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + $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); + + // Step 1: Replace the placeholder with an HTML table structure + $table_content = ''; + $addtional_premium = 0; + $gst = 0; + $Addon_list = []; + $name = $array_list['name']; + $emp_code = ''; + + if (!empty($array_list)) { + $table_content .= '

Policy Name : '; + + $policy_name = $array_list['policy_name']; + + if ($array_list['relationship'] == 'Self') { + $emp_code = ' (' . $array_list['emp_code'] . ')'; + } else { + $emp_code = ''; + } + + // Start table row + $table_content .= $policy_name . '

'; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Table body with details + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
' . $array_list['name'] . $emp_code . '' . $array_list['relationship'] . '' . \DateTime::createFromFormat('Y-m-d', $array_list['dob'])->format('d-m-Y') . '₹' . format_indian_number($array_list['basic_cover_si']) . '₹' . format_indian_number(round($array_list['premium'])) . '₹' . format_indian_number(round($array_list['gst'])) . '
'; + + // Calculate additional premium and GST if applicable + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $addtional_premium = $array_list['rata_premimum']; + $gst = $array_list['gst']; + + // Prepare addon summary + $addon_list_array = [ + 'policy_name' => $policy_name, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + + $Addon_list[] = $addon_list_array; + } + + // Generate summary table for addon if applicable + if (count($Addon_list) > 0) { + $table_content .= '
'; + $table_content .= ''; + + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $total_addon = $Addon_list[0]['gst'] + $Addon_list[0]['addtional_premium']; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $sum_total_words = numberToWords($total_addon); + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= '
Policy NameAdditional PremiumGSTTotal
' . $Addon_list[0]['policy_name'] . '₹' . format_indian_number($Addon_list[0]['addtional_premium']) . '₹' . format_indian_number($Addon_list[0]['gst']) . '₹' . format_indian_number($total_addon) . '
Total₹' . format_indian_number($total_addon) . '
'; + } + } + + $mail_content = str_replace("[[member_name]]", $name . ' (' . $emp_code . ')' , $mail_content); + $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); + + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'reply_to' => $client_data['reply_to']]; + + return $wholeData; + } + + } else if($action == 'client_hr_summary_mail'){ + + $array_list = [ + 'policy_name' => 'Health Insurance Plan', + 'emp_code' => 'E12345', + 'name' => 'John Doe', + 'relationship' => 'Self', + 'dob' => '1985-05-15', + 'basic_cover_si' => 500000, + 'premium' => 12000, + 'gst' => 2160, + 'rata_premimum' => 12000, + 'is_addon' => 2 + ]; + + $notification_data = $params['notification_data']; + $client_data = $params['client_data']; + $mail = $params['test_mail']; + + if (isset($notification_data['enabled']) && $notification_data['enabled'] == 1) { + + $mail_content = $notification_data['mail_content']; + $subject = $notification_data['subject']; + + $app_link = $_ENV['App_Url']; + $nhance_logo = $_ENV['NHANCE_LOGO']; + + $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo']; + + $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); + $mail_content = str_replace("[[client_logo]]", "Client Logo", $mail_content); + $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); + + $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); + + // Step 1: Replace the placeholder with an HTML table structure + $table_content = ''; + $addtional_premium = 0; + $gst = 0; + $Addon_list = []; + $name = $array_list['name']; + $emp_code = ''; + + if (!empty($array_list)) { + + $table_content .= '

Policy Name : '; + + $policy_name = $array_list['policy_name']; + + if ($array_list['relationship'] == 'Self') { + $emp_code = ' (' . $array_list['emp_code'] . ')'; + } else { + $emp_code = ''; + } + + // Start table row + $table_content .= $policy_name . '

'; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + // Only Display SI Topup and Dependent Addon + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + + // Table body with details + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $table_content .= ''; + $table_content .= ''; + } + + $table_content .= ''; + $table_content .= ''; + $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
' . $array_list['name'] . $emp_code . '' . $array_list['relationship'] . '' . \DateTime::createFromFormat('Y-m-d', $array_list['dob'])->format('d-m-Y') . '₹' . format_indian_number($array_list['basic_cover_si']) . '₹' . format_indian_number(round($array_list['premium'])) . '₹' . format_indian_number(round($array_list['gst'])) . '
'; + + // Calculate additional premium and GST if applicable + if ($array_list['is_addon'] == 2 || $array_list['is_addon'] == 3) { + $addtional_premium = $array_list['rata_premimum']; + $gst = $array_list['gst']; + + // Prepare addon summary + $addon_list_array = [ + 'policy_name' => $policy_name, + 'addtional_premium' => round($addtional_premium), + 'gst' => round($gst) + ]; + + $Addon_list[] = $addon_list_array; + } + + // Generate summary table for addon if applicable + if (count($Addon_list) > 0) { + + $table_content .= '
'; + $table_content .= ''; + + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $total_addon = $Addon_list[0]['gst'] + $Addon_list[0]['addtional_premium']; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $sum_total_words = numberToWords($total_addon); + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= '
Policy NameAdditional PremiumGSTTotal
' . $Addon_list[0]['policy_name'] . '₹' . format_indian_number($Addon_list[0]['addtional_premium']) . '₹' . format_indian_number($Addon_list[0]['gst']) . '₹' . format_indian_number($total_addon) . '
Total₹' . format_indian_number($total_addon) . '
'; + } + } + + $mail_content = str_replace("[[member_name]]", $name . ' (' . $emp_code . ')' , $mail_content); + $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); + + + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'reply_to' => $client_data['reply_to']]; + + return $wholeData; + } + + } + } } \ No newline at end of file diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index 4e05f84a..e188b5bd 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -38,6 +38,7 @@ class ClientModel extends Model "phone", "email", "reply_to", + "mail_domain", ]; diff --git a/app/Views/notification.php b/app/Views/notification.php index 09c95038..6b15116a 100755 --- a/app/Views/notification.php +++ b/app/Views/notification.php @@ -5,6 +5,10 @@ .preview_button{ display:none; } + + .scrollb { + overflow-y: auto !important; + }
@@ -56,16 +60,29 @@ ?>

+
- +
- +
+ +
+
+ + +
+
+ + +
+
+
@@ -156,6 +173,7 @@
+
@@ -176,7 +194,7 @@