427 lines
23 KiB
PHP
427 lines
23 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use App\Models\ClientModel;
|
|
use App\Models\ClientRMModel;
|
|
use App\Models\NotificationModel;
|
|
use App\Models\UserModel;
|
|
use App\Models\EmployeeModel;
|
|
|
|
class sendMailNotification
|
|
{
|
|
public static function sendMailNotification($action, $params)
|
|
{
|
|
if ($action == 'member_welcome_mail') {
|
|
$dataToInsert = $params['dataToInsert'];
|
|
$notification = $params['notification'];
|
|
$client_data = $params['client_data'];
|
|
|
|
$mail = $dataToInsert['email_corporate'];
|
|
$subject = $notification['subject'];
|
|
$app_link = $_ENV['App_Url'];
|
|
$employee_name =$dataToInsert['name'];
|
|
$mail_content = $notification['mail_content'];
|
|
$nhance_logo = $_ENV['NHANCE_LOGO'];
|
|
$client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo'];
|
|
|
|
$mail_content = str_replace("[[client_logo]]", "<img src='$client_logo' alt='Client Logo' width='20'>", $mail_content);
|
|
$mail_content = str_replace("[[nhance_logo]]", "<img src='$nhance_logo' alt='Nhance Logo' width='20'>", $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]]", "<a href='$app_link'>Review Details</a>", $mail_content);
|
|
if ($dataToInsert['relationship'] == 'Self' && $mail != null || $mail != '') {
|
|
$wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails']];
|
|
}
|
|
return $wholeData;
|
|
} else if($action == 'member_reminder_mail'){
|
|
|
|
// print_r($params);die;
|
|
$EmployeeModel = new EmployeeModel();
|
|
$emp_data = $params['emp_data'];
|
|
$notification_data = $params['notification_data'];
|
|
$client_data = $params['client_data'];
|
|
|
|
$subject = $notification_data['subject'];
|
|
$app_link = $_ENV['App_Url'];
|
|
$mail_content = $notification_data['mail_content'];
|
|
$nhance_logo = $_ENV['NHANCE_LOGO'];
|
|
|
|
$mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content);
|
|
$mail_content = str_replace("[[nhance_logo]]", "<img src='$nhance_logo' alt='Nhance Logo' width='20'>", $mail_content);
|
|
$mail_content = str_replace("[[app_link]]", "<a href='$app_link'>Review Details</a>", $mail_content);
|
|
|
|
if ($emp_data && (isset($notification_data) && $notification_data['enabled'] == 1)) {
|
|
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'];
|
|
$mail_content = str_replace("[[member_name]]", $employee_name, $mail_content);
|
|
|
|
$mail = $values['email_corporate'];
|
|
}
|
|
}
|
|
}else{
|
|
$mail ='';
|
|
}
|
|
|
|
}else{
|
|
$employee_name =$value['name'];
|
|
$mail_content = str_replace("[[member_name]]", $employee_name, $mail_content);
|
|
$mail = $value['email_corporate'];
|
|
}
|
|
if (isset($mail) && !empty($mail)) {
|
|
$wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']];
|
|
}
|
|
}
|
|
if (count($wholeData) < 1) {
|
|
$wholeData = [];
|
|
}
|
|
return $wholeData;
|
|
}else{
|
|
return "false";
|
|
}
|
|
} else if($action == 'member_ecard_mail'){
|
|
|
|
$notification = $params['notification'];
|
|
$get_emp_email_and_other_details = $params['get_emp_email_and_other_details'];
|
|
$rand_string = $params['rand_string'];
|
|
$client_data = $params['client_data'];
|
|
$tpa_id = $params['tpa_id'];
|
|
|
|
|
|
$mail_content = $notification['mail_content'];
|
|
$mail = $get_emp_email_and_other_details['email_corporate'];
|
|
$subject = $notification['subject'];
|
|
$link = generate_download_link($rand_string);
|
|
$app_link = $_ENV['App_Url'];
|
|
$name = $get_emp_email_and_other_details['name'];
|
|
$mail_content = $notification['mail_content'];
|
|
$nhance_logo = $_ENV['NHANCE_LOGO'];
|
|
$post_enrollment_app_link = $_ENV['POST_ENROLLMENT_APP_LINK'];
|
|
|
|
$client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo'];
|
|
// $client_logo = $nhance_logo;
|
|
|
|
$mail_content = str_replace("[[nhance_logo]]", "<img src='$nhance_logo' alt='Nhance Logo' width='20'>", $mail_content);
|
|
$mail_content = str_replace("[[client_logo]]", "<img src='$client_logo' alt='Client Logo' width='20'>", $mail_content);
|
|
|
|
$mail_content = str_replace("[[member_name]]", $name, $mail_content);
|
|
$mail_content = str_replace("[[app_link]]", "<a href='$app_link'>Review Details</a>", $mail_content);
|
|
$mail_content = str_replace("[[post_enrollment_app_link]]", "<a href='$post_enrollment_app_link'>Review Details</a>", $mail_content);
|
|
// $mail_content = str_replace("[[tpa_id]]", $tpa_id, $mail_content);
|
|
$mail_content = str_replace("[[ecard_download_link]]", "<a href='$link/1'>Download Insurance Card</a>", $mail_content);
|
|
$mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content);
|
|
|
|
$wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails']];
|
|
|
|
return $wholeData;
|
|
} else if($action == 'member_review_and_summary_mail'){
|
|
|
|
$array_list = $params['array_list'];
|
|
$client_policy_id = $params['client_policy_id'];
|
|
$emp_code = $params['emp_code'];
|
|
$client_id = $params['client_id'];
|
|
|
|
$clientModel = new ClientModel();
|
|
$notificationModel = new NotificationModel();
|
|
|
|
$client_data =$clientModel->where('id', $client_id)->first();
|
|
$notification_data = $notificationModel->where('client_id' ,$client_id)->where('template_name', $action)->first();
|
|
|
|
if ($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'];
|
|
// $client_logo = $nhance_logo;
|
|
|
|
$mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content);
|
|
$mail_content = str_replace("[[nhance_logo]]", "<img src='$nhance_logo' alt='Nhance Logo' width='20'>", $mail_content);
|
|
$mail_content = str_replace("[[client_logo]]", "<img src='$client_logo' alt='Client Logo' width='20'>", $mail_content);
|
|
|
|
$mail_content = str_replace("[[app_link]]", "<a href='$app_link'>Review Details</a>", $mail_content);
|
|
|
|
// Step 1: Replace the placeholder with an HTML table structure
|
|
$mail = '';
|
|
// print_r($array_list);die;
|
|
$table_content = '';
|
|
$addtional_premium = 0;
|
|
$gst = 0;
|
|
foreach ($array_list as $item) {
|
|
$table_content .= '<div style="text-align: left;"><div style="text-align:left;"><h4>Policy Name : ';
|
|
$temp_data ='';
|
|
foreach ($item as $inner_item) {
|
|
$policy_name = $inner_item['policy_name'];
|
|
$temp_data .= '<tr ><td style="width:20%">' . $inner_item['name'] . '</td><td style="width:20%">'.$inner_item['mobile'].'</td><td style="width:20%">₹'.number_format($inner_item['basic_cover_si'], 2, '.', ',').'</td><td style="width:20%">'.\DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y').'</tr>';
|
|
if($inner_item['relationship'] == 'Self' || $inner_item['relationship'] == 'self'){
|
|
$mail = $inner_item['email_corporate'];
|
|
$name = $inner_item['name'];
|
|
}
|
|
// print_r($inner_item);die;
|
|
$is_addon = $inner_item['is_addon'];
|
|
|
|
if($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3){
|
|
$addtional_premium = $inner_item['rata_premimum'] + $addtional_premium;
|
|
$gst = $inner_item['gst'] + $gst;
|
|
}
|
|
}
|
|
$table_content .= $policy_name.'</h4></div><table style="width:60%"><thead style="background-color: #02a8b5;"><tr><th style="width:20%">Name</th><th>Mobile Number</th><th>Sum Insure</th><th style="width:15%">Date Of Birth</th></tr></thead><tbody>';
|
|
$table_content .= $temp_data;
|
|
$table_content .= '</tbody></table></div>';
|
|
|
|
if ($is_addon == 2 || $is_addon == 3) {
|
|
$addon_list_array = [
|
|
'policy_name'=>$policy_name,
|
|
'addtional_premium'=>$addtional_premium,
|
|
'gst'=>$gst
|
|
];
|
|
$Addon_list[]= $addon_list_array;
|
|
|
|
}
|
|
|
|
|
|
$temp_data = '';
|
|
$addtional_premium = 0;
|
|
$gst = 0;
|
|
}
|
|
|
|
$table_content .='<br><table style="width:60%"><thead style="background-color: #e26828;"><tr><th>Policy Name</th><th> Additional Premium</th><th>GST</th><th>Total</th></tr></thead><tbody>';
|
|
$sum_tolal = 0;
|
|
foreach ($Addon_list as $key => $value) {
|
|
$sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal;
|
|
$table_content .= '<tr><td>'.$value['policy_name'].'</td><td>₹'.$value['addtional_premium'].'</td><td>'.$value['gst'].'</td><td>'.$value['gst'] + $value['addtional_premium'] .'</td></tr>';
|
|
}
|
|
$table_content .= '<tr><td></td><td></td><td><h4>Total</h4></td><td>'.$sum_tolal.'</td></tr>';
|
|
$table_content .= '</tbody></table>';
|
|
$mail_content = str_replace("[[member_name]]", $name, $mail_content);
|
|
|
|
$mail_content = str_replace("[[member_summary]]", $table_content , $mail_content);
|
|
// $mail = "aadhavanvalli@gmail.com";
|
|
// if (isset($mail) && !empty($mail)) {
|
|
$wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']];
|
|
// }
|
|
|
|
return $wholeData;
|
|
|
|
}
|
|
// print_r($wholeData);die;
|
|
} else if($action == 'account_maneger_summary_mail'){
|
|
|
|
$client_id = $params['client_id'];
|
|
|
|
$clientModel = new ClientModel();
|
|
|
|
$client_data =$clientModel->where('id', $client_id)->first();
|
|
$notificationModel = new NotificationModel();
|
|
$notification_data = $notificationModel->where('client_id' ,$client_id)->where('template_name', $action)->first();
|
|
$clientRMModel =new ClientRMModel();
|
|
|
|
if ($notification_data['enabled'] == 1) {
|
|
$client_rm_data= $clientRMModel->where('client_id', $client_id)->where('is_active',1)->findAll();
|
|
$user_list= [];
|
|
foreach ($client_rm_data as $key => $value) {
|
|
if($value['level'] == 3){
|
|
$userModel = new UserModel();
|
|
$user_data = $userModel->where('id', $value['user_id'])->first();
|
|
$user_list[]=$user_data;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$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'];
|
|
// $client_logo = $nhance_logo;
|
|
|
|
$mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content);
|
|
$mail_content = str_replace("[[nhance_logo]]", "<img src='$nhance_logo' alt='Nhance Logo' width='20'>", $mail_content);
|
|
$mail_content = str_replace("[[client_logo]]", "<img src='$client_logo' alt='Client Logo' width='20'>", $mail_content);
|
|
|
|
$mail_content = str_replace("[[app_link]]", "<a href='$app_link'>Review Details</a>", $mail_content);
|
|
|
|
// Step 1: Replace the placeholder with an HTML table structure
|
|
$mail = '';
|
|
// print_r($array_list);die;
|
|
$table_content = '';
|
|
$addtional_premium = 0;
|
|
$gst = 0;
|
|
$array_list = $params['array_list'];
|
|
|
|
foreach ($array_list as $item) {
|
|
$table_content .= '<div style="text-align: left;"><div style="text-align:left;"><h4>Policy Name : ';
|
|
$temp_data ='';
|
|
foreach ($item as $inner_item) {
|
|
$policy_name = $inner_item['policy_name'];
|
|
$temp_data .= '<tr ><td style="width:20%">' . $inner_item['name'] . '</td><td style="width:20%">'.$inner_item['mobile'].'</td><td style="width:20%">₹'.number_format($inner_item['basic_cover_si'], 2, '.', ',').'</td><td style="width:20%">'.\DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y').'</tr>';
|
|
// print_r($inner_item);die;
|
|
$is_addon = $inner_item['is_addon'];
|
|
|
|
if($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3){
|
|
$addtional_premium = $inner_item['rata_premimum'] + $addtional_premium;
|
|
$gst = $inner_item['gst'] + $gst;
|
|
}
|
|
}
|
|
$table_content .= $policy_name.'</h4></div><table style="width:60%"><thead style="background-color: #02a8b5;"><tr><th style="width:20%">Name</th><th>Mobile Number</th><th>Sum Insure</th><th style="width:15%">Date Of Birth</th></tr></thead><tbody>';
|
|
$table_content .= $temp_data;
|
|
$table_content .= '</tbody></table></div>';
|
|
|
|
if ($is_addon == 2 || $is_addon == 3) {
|
|
$addon_list_array = [
|
|
'policy_name'=>$policy_name,
|
|
'addtional_premium'=>$addtional_premium,
|
|
'gst'=>$gst
|
|
];
|
|
$Addon_list[]= $addon_list_array;
|
|
|
|
}
|
|
|
|
|
|
$temp_data = '';
|
|
$addtional_premium = 0;
|
|
$gst = 0;
|
|
|
|
}
|
|
|
|
$table_content .='<br><table style="width:60%"><thead style="background-color: #e26828;"><tr><th>Policy Name</th><th> Additional Premium</th><th>GST</th><th>Total</th></tr></thead><tbody>';
|
|
$sum_tolal = 0;
|
|
foreach ($Addon_list as $key => $value) {
|
|
$sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal;
|
|
$table_content .= '<tr><td>'.$value['policy_name'].'</td><td>₹'.$value['addtional_premium'].'</td><td>'.$value['gst'].'</td><td>'.$value['gst'] + $value['addtional_premium'] .'</td></tr>';
|
|
}
|
|
$table_content .= '<tr><td></td><td></td><td><h4>Total</h4></td><td>'.$sum_tolal.'</td></tr>';
|
|
$table_content .= '</tbody></table>';
|
|
|
|
$mail_content = str_replace("[[member_summary]]", $table_content , $mail_content);
|
|
|
|
$account_manager_mail_list = [];
|
|
foreach ($user_list as $key => $value) {
|
|
$full_name = $value['first_name'] .' ' .$value['last_name'];
|
|
$mail_content = str_replace("[[member_name]]", $full_name , $mail_content);
|
|
|
|
$wholeData[] = ['mail' => $value['email'], 'subject' => $subject,'message'=> $mail_content];
|
|
// $wholeData[] = ['mail' => $value['email'], 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']];
|
|
}
|
|
return $wholeData;
|
|
}
|
|
} else if($action == 'client_hr_summary_mail'){
|
|
|
|
$client_id = $params['client_id'];
|
|
|
|
$clientModel = new ClientModel();
|
|
|
|
$client_data =$clientModel->where('id', $client_id)->first();
|
|
$notificationModel = new NotificationModel();
|
|
$notification_data = $notificationModel->where('client_id' ,$client_id)->where('template_name', $action)->first();
|
|
$clientRMModel =new ClientRMModel();
|
|
|
|
if ($notification_data['enabled'] == 1) {
|
|
$client_rm_data= $clientRMModel->where('client_id', $client_id)->where('is_active',1)->findAll();
|
|
$user_list= [];
|
|
foreach ($client_rm_data as $key => $value) {
|
|
if($value['level'] == 3){
|
|
$userModel = new UserModel();
|
|
$user_data = $userModel->where('id', $value['user_id'])->first();
|
|
$user_list[]=$user_data;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$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'];
|
|
// $client_logo = $nhance_logo;
|
|
|
|
$mail_content = str_replace("[[nhance_logo]]", "<img src='$nhance_logo' alt='Nhance Logo' width='20'>", $mail_content);
|
|
$mail_content = str_replace("[[client_logo]]", "<img src='$client_logo' alt='Client Logo' width='20'>", $mail_content);
|
|
$mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content);
|
|
|
|
$mail_content = str_replace("[[app_link]]", "<a href='$app_link'>Review Details</a>", $mail_content);
|
|
|
|
// Step 1: Replace the placeholder with an HTML table structure
|
|
$mail = '';
|
|
// print_r($array_list);die;
|
|
$table_content = '';
|
|
$addtional_premium = 0;
|
|
$gst = 0;
|
|
$array_list = $params['array_list'];
|
|
|
|
foreach ($array_list as $item) {
|
|
$table_content .= '<div style="text-align: left;"><div style="text-align:left;"><h4>Policy Name : ';
|
|
$temp_data ='';
|
|
foreach ($item as $inner_item) {
|
|
$policy_name = $inner_item['policy_name'];
|
|
$temp_data .= '<tr ><td style="width:20%">' . $inner_item['name'] . '</td><td style="width:20%">'.$inner_item['mobile'].'</td><td style="width:20%">₹'.number_format($inner_item['basic_cover_si'], 2, '.', ',').'</td><td style="width:20%">'.\DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y').'</tr>';
|
|
// print_r($inner_item);die;
|
|
$is_addon = $inner_item['is_addon'];
|
|
|
|
if($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3){
|
|
$addtional_premium = $inner_item['rata_premimum'] + $addtional_premium;
|
|
$gst = $inner_item['gst'] + $gst;
|
|
}
|
|
}
|
|
$table_content .= $policy_name.'</h4></div><table style="width:60%"><thead style="background-color: #02a8b5;"><tr><th style="width:20%">Name</th><th>Mobile Number</th><th>Sum Insure</th><th style="width:15%">Date Of Birth</th></tr></thead><tbody>';
|
|
$table_content .= $temp_data;
|
|
$table_content .= '</tbody></table></div>';
|
|
|
|
if ($is_addon == 2 || $is_addon == 3) {
|
|
$addon_list_array = [
|
|
'policy_name'=>$policy_name,
|
|
'addtional_premium'=>$addtional_premium,
|
|
'gst'=>$gst
|
|
];
|
|
$Addon_list[]= $addon_list_array;
|
|
|
|
}
|
|
|
|
|
|
$temp_data = '';
|
|
$addtional_premium = 0;
|
|
$gst = 0;
|
|
|
|
}
|
|
|
|
$table_content .='<br><table style="width:60%"><thead style="background-color: #e26828;"><tr><th>Policy Name</th><th> Additional Premium</th><th>GST</th><th>Total</th></tr></thead><tbody>';
|
|
$sum_tolal = 0;
|
|
foreach ($Addon_list as $key => $value) {
|
|
$sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal;
|
|
$table_content .= '<tr><td>'.$value['policy_name'].'</td><td>₹'.$value['addtional_premium'].'</td><td>'.$value['gst'].'</td><td>'.$value['gst'] + $value['addtional_premium'] .'</td></tr>';
|
|
}
|
|
$table_content .= '<tr><td></td><td></td><td><h4>Total</h4></td><td>'.$sum_tolal.'</td></tr>';
|
|
$table_content .= '</tbody></table>';
|
|
|
|
$mail_content = str_replace("[[member_summary]]", $table_content , $mail_content);
|
|
|
|
|
|
$hr_mails = $client_data['hr_mails'];
|
|
$mail_array = explode(',', $hr_mails);
|
|
$mail_array = array_map('trim', $mail_array);
|
|
|
|
foreach ($mail_array as $key => $value) {
|
|
$wholeData[] = ['mail' => $value, 'subject' => $subject,'message'=> $mail_content];
|
|
// $wholeData[] = ['mail' => $value, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']];
|
|
}
|
|
|
|
return $wholeData;
|
|
}
|
|
|
|
}
|
|
}
|
|
} |