diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 71015045..079e4d35 100755 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -202,59 +202,71 @@ class DashboardController extends AdminController public function updatePolicyEnrollmentStatus() { - $clientModel = new ClientModel(); $clientPolicyModel = new ClientPolicyModel(); - $notificationModel = new NotificationModel(); - $employeePolicyModel = new EmployeePolicyModel(); $myLogger = \Config\Services::mylogger(); - - // $myLogger->logme('error', 'enrollment_status function called'); - - $client_policy_data = $clientPolicyModel->getPolicyDetailsForRemainder(); - $myLogger->logme('error', 'Fetched client policy data'); + + $client_policy_data = $clientPolicyModel->getPolicyDetailsForEnrollment(); + $myLogger->logme('error', 'Fetched client policy data for Enrollment Status update'); // dd($client_policy_data); - $currentDate = date('d'); - // $myLogger->logme('error', 'Current date: ' . $currentDate); + $currentDate = date('d-m-Y'); + $openEnrollment = []; + $closeEnrollment = []; // Update policy status based on start and end dates foreach ($client_policy_data as $client_policy) { $id = $client_policy['id']; - $openDate = date('d', strtotime($client_policy['open_date'])); - $closeDate = date('d', strtotime($client_policy['close_date'])); - - // $myLogger->logme('error', 'Processing client policy ID: ' . $id); - // $myLogger->logme('error', 'Open date: ' . $openDate . ', Close date: ' . $closeDate); - + $openDate = date('d-m-Y', strtotime($client_policy['open_date'])); + $closeDate = date('d-m-Y', strtotime($client_policy['close_date'])); + if ($currentDate == $openDate) { $clientPolicyModel->update($id, ['open_for_enrollment' => 1]); + $openEnrollment[] = $id; $myLogger->logme('error', 'Updated policy ID ' . $id . ' to open for enrollment.'); } if ($closeDate < $currentDate) { $clientPolicyModel->update($id, ['open_for_enrollment' => 0]); + $closeEnrollment[] = $id; $myLogger->logme('error', 'Updated policy ID ' . $id . ' to close for enrollment.'); } } + + $myLogger->logme('error', 'enrollment_status function completed'); + return $this->respond([ + 'status' => true, + 'message' => 'updated Policy Enrollment Status', + 'open_policy_count' => count($openEnrollment), + 'close_policy_count' => count($closeEnrollment), + 'open_policy_ids' => $openEnrollment, + 'close_policy_ids' => $closeEnrollment, + ]); + + } + + public function sendCroneRemainderMail() + { + $clientPolicyModel = new ClientPolicyModel(); + $myLogger = \Config\Services::mylogger(); + + + $client_policy_data = $clientPolicyModel->getPolicyDetailsForRemainder(); + $myLogger->logme('error', 'Fetched client policy data'); + // dd($client_policy_data); // Mail send function - // $myLogger->logme('error', 'Calling sendRemainderMail function'); - if( $currentDate == date('d', strtotime($client_policy['reminder_date']))){ - $result = $this->sendRemainderMail($client_policy_data); - }else{ - $result = false; - } - - // $myLogger->logme('error', 'enrollment_status function completed'); + $result = $this->sendRemainderMail($client_policy_data, 'crone'); + + $myLogger->logme('error', 'sendCroneRemainderMail function completed'); + if($result){ return json_encode(['status' => true, 'message' => 'Mail send successfully']); }else{ return json_encode(['status' => false, 'message' => 'There is no data to send']); } } - public function featch_dashboard_data($type) { @@ -292,65 +304,133 @@ class DashboardController extends AdminController return $this->respond(['status' => true, 'data' => $data], 200); } - - public function sendRemainderMail($client_policy_data) + public function sendRemainderMail($client_policy_data, $send_mail_for_manual_or_crone = null) { // $this->myLogger->logme('error', 'sendRemainderMail function called'); + // dd($client_policy_data, $send_mail_for_manual_or_crone); + $reminder_whole_mail = []; foreach ($client_policy_data as $client_policy) { - - // 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(); - // $this->myLogger->logme('error', 'Notification data fetched: ' . json_encode($notification_data)); - - // 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']); - - // Fetch all employees related to the client policy - $employees = $this->employeePolicyModel - ->select('employees.*') - ->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(); - - // 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 - $params['emp_data'] = $employee; - $params['client_data'] = $client_data; - $params['notification_data'] = $notification_data; - - // 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; + if(empty($send_mail_for_manual_or_crone)){ + + // echo '1'; + + // 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(); + + // $this->myLogger->logme('error', 'Notification data fetched: ' . json_encode($notification_data)); + + // 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']); + + // Fetch all employees related to the client policy + $employees = $this->employeePolicyModel + ->select('employees.*') + ->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(); + + // 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 + $params['emp_data'] = $employee; + $params['client_data'] = $client_data; + $params['notification_data'] = $notification_data; + + // 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; + } + } + } else { + $this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']); + } + + } else { + + // echo '2'; + + $currentDate = date('d-m-Y'); + + if($currentDate == date('d-m-Y', strtotime($client_policy['reminder_date']))){ + + // echo '3'; + + $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(); + + // Check if notification should be sent + if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { + + // echo '4'; + + $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.*') + ->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(); + + // 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 + $params['emp_data'] = $employee; + $params['client_data'] = $client_data; + $params['notification_data'] = $notification_data; + + // 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; + } + } + } else { + // echo '5'; + $this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']); } } - } else { - $this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']); } } - $this->myLogger->logme('error', 'Whole email, count: ' . $reminder_whole_mail); + // dd($reminder_whole_mail); + + // $this->myLogger->logme('error', 'Whole email, count: ' . $reminder_whole_mail); // Process and queue bulk emails $temp_whole_data = []; @@ -387,7 +467,6 @@ class DashboardController extends AdminController } - public function sendManualRemainder($client_id, $client_branch_id) { $this->myLogger->logme('error', "sendManualRemainder called with client_id: {$client_id}, client_branch_id: {$client_branch_id}"); @@ -414,7 +493,6 @@ class DashboardController extends AdminController return $this->respond(['status' => false, 'code' => 200, 'message' => 'There is no data to send', 'message2' => 'No policy data found to send'], 200); } } - - + } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 9c0ce3c0..8d6ace5c 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -439,6 +439,29 @@ class EmployeeRestController extends AdminController try { $requestData = $this->request->getJSON(); + foreach ($requestData as $key => $value) + { + + $checkIfExist = $this->employeePolicyModel->where('employee_id', $value->employee_id) + ->where('client_policy_id', $value->client_policy_id) + ->where('is_active', 1 ) + ->findAll(); + + + if ($checkIfExist) { + + $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id, $value->employee_id, $value->basic_cover_si); + + }else{ + + $data['employee_id']= $value->employee_id; + $data['client_policy_id']= $value->client_policy_id; + $data['basic_cover_si']= $value->basic_cover_si; + $data['status'] = 'draft'; + + $this->employeePolicyModel->insert($data); + } + } if(count($requestData)) { $this->updatePremiumAmount($requestData[0]->client_policy_id , $requestData[0]->emp_code , $requestData[0]->client_branch_id); @@ -999,7 +1022,7 @@ class EmployeeRestController extends AdminController $self['data']['dob'] = $this->convertDateFormatDMY($selfData[0]['dob']); $self['data']['mobile'] = $selfData[0]['mobile']; $self['data']['client_policy_id'] = $array->ClientPolicyId; - $self['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + $self['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : 0; $array->mapped_family_floaters = $self; $array->type = 'GPA'; @@ -1056,6 +1079,7 @@ class EmployeeRestController extends AdminController foreach ($empData as $key => $value) { if ($value['family_floater_key'] === $dependent) { $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array->ClientPolicyId)->where('is_active', 1 )->get()->getRow(); + $temp['is_value_exist'] = true; $temp['data']['family_floater_key'] = $familyFloatesValue; $temp['data']['employee_id'] = $value['id']; @@ -1064,7 +1088,7 @@ class EmployeeRestController extends AdminController $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); $temp['data']['client_policy_id'] = $array->ClientPolicyId; $temp['data']['form_type'] = $dependent; - $temp['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + $temp['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : 0; $temp['data']['age_validation'] = $this->getAgeRange($decodedArray,$familyFloatesValue); @@ -1164,7 +1188,7 @@ class EmployeeRestController extends AdminController return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200); } } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getLine()], 500); } } @@ -1260,7 +1284,7 @@ class EmployeeRestController extends AdminController $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); $temp['data']['client_policy_id'] = $array->ClientPolicyId; $temp['data']['form_type'] = $dependent; - $temp['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + $temp['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : 0; $temp['data']['age_validation'] = $this->getAgeRange($array->Policy_Terms,$familyFloatesValue); @@ -1367,7 +1391,7 @@ class EmployeeRestController extends AdminController $self['data']['dob'] = $this->convertDateFormatDMY($selfData[0]['dob']); $self['data']['mobile'] = $selfData[0]['mobile']; $self['data']['client_policy_id'] = $array->ClientPolicyId; - $self['data']['basic_cover_si'] = $employee_policy->basic_cover_si; + $self['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : 0; $array->mapped_family_floaters = $self; if($array->enrolment_visibility == 1) @@ -1500,9 +1524,7 @@ class EmployeeRestController extends AdminController if(count($clientPolicy)) { - $self = $this->employeeModel - ->join('employee_polices', 'employees.id = employee_polices.employee_id') - ->where('employees.is_active', 1) + $self = $this->employeeModel->where('employees.is_active', 1) ->where('employees.emp_code', $this->request->getGet('emp_code')) ->where('employees.client_id', $this->request->getGet('client_id')) ->where('employees.client_branch_id', $this->request->getGet('client_branch_id')) @@ -1553,6 +1575,7 @@ class EmployeeRestController extends AdminController $responce['OpenForEnrollment'] = $array['open_for_enrollment']; $responce['policy_terms'] = $decodedArray; $responce['policy_type_id'] = $array['policy_type_id']; + $responce['disclaimer'] = $array['disclaimer']; $tpaArray = $this->employeeModel->select('employees.name as name , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') ->join('employee_polices', 'employee_polices.employee_id = employees.id') @@ -1586,8 +1609,18 @@ class EmployeeRestController extends AdminController if($array['is_addon'] == 3 && $array['policy_type_id'] == 3)//dependent add on policy { - - $selfSi = $self->basic_cover_si; + $selfGMC = $this->employeeModel->select('employees.name , employee_polices.basic_cover_si') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id AND client_policy.policy_type_id = 2') + ->where('employees.is_active', 1) + ->where('employees.emp_code', $this->request->getGet('emp_code')) + ->where('employees.client_id', $this->request->getGet('client_id')) + ->where('employees.client_branch_id', $this->request->getGet('client_branch_id')) + ->where('employees.family_floater_key', 'self') + ->get() + ->getRow(); + + $selfSi = $selfGMC->basic_cover_si; $filteredSlabRates = array_filter($responce['SlabRates'], function ($rate) use ($selfSi) { return $rate['si'] === $selfSi; }); 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/Filters/CloseDbConnection.php b/app/Filters/CloseDbConnection.php index ad49eb86..0ce482c9 100755 --- a/app/Filters/CloseDbConnection.php +++ b/app/Filters/CloseDbConnection.php @@ -19,7 +19,7 @@ class CloseDbConnection implements FilterInterface // Get all database configurations $db = \Config\Database::connect(); $log = \Config\Services::mylogger(); - $log->logme('error','CloseDbConnections....!'); + // $log->logme('error','CloseDbConnections....!'); $db->close(); } } diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 9ff6a624..f94d6419 100755 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -93,6 +93,8 @@ class MailHelper $emaill = $params['mail']; $subject = $params['subject']; $message = $params['message']; + + //check BCC mail if (isset($params['bcc'])) { $bcc = $params['bcc']; $bcc = explode(',', $bcc); @@ -100,16 +102,23 @@ class MailHelper $bcc = []; } + //check CC mail if (isset($params['cc'])) { $cc = $params['cc']; $cc = explode(',', $cc); }else{ $cc = []; } + + //check REPLY TO mail + $reply_to = ""; + if(isset($params['reply_to']) && !empty($params['reply_to'])){ + $reply_to = $params['reply_to']; + } + try { - - $res = $gmailapi->sendMessage($emaill, $subject, $message, 'info@nhanceindia.in', 'info@nhanceindia.in', $cc, $bcc); + $res = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc); if($res['status']) { diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 0865865a..91907824 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -14,6 +14,7 @@ class sendMailNotification { $wholeData =[]; if ($action == 'member_welcome_mail') { + $dataToInsert = $params['dataToInsert']; $notification = $params['notification']; $client_data = $params['client_data']; @@ -33,10 +34,13 @@ class sendMailNotification $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); if ($dataToInsert['relationship'] == 'Self' && $mail != null || $mail != '') { - $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails']]; + $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'){ + $EmployeeModel = new EmployeeModel(); $emp_data = $params['emp_data']; $notification_data = $params['notification_data']; @@ -46,9 +50,12 @@ class sendMailNotification $app_link = $_ENV['App_Url']; $mail_content = $notification_data['mail_content']; $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); if ($emp_data && (isset($notification_data) && $notification_data['enabled'] == 1)) { if(isset($emp_data['relationship'])){ @@ -72,9 +79,11 @@ class sendMailNotification } if (isset($mail) && !empty($mail)) { - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; } + }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(); @@ -96,7 +105,7 @@ class sendMailNotification $mail = $value['email_corporate']; } if (isset($mail) && !empty($mail)) { - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; } } } @@ -104,10 +113,13 @@ class sendMailNotification if (count($wholeData) < 1) { $wholeData = []; } + return $wholeData; + // }else{ // return "false"; // } + } else if($action == 'member_ecard_mail'){ $notification = $params['notification']; @@ -144,9 +156,10 @@ class sendMailNotification // $mail_content = str_replace("[[tpa_id]]", $tpa_id, $mail_content); $mail_content = str_replace("[[ecard_download_link]]", "Download Insurance Card", $mail_content); $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); - $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails']]; + $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 = $params['array_list'];//employeee lst @@ -189,64 +202,66 @@ class sendMailNotification foreach ($array_list as $item) { if (count($item) != 0) { - $table_content .= '
'; - $table_content .= '

Policy Name : '; + $table_content .= '

Policy Name : '; $temp_data = ''; $policy_name = ''; $is_addon = ''; - + foreach ($item as $inner_item) { $policy_name = $inner_item['policy_name']; - $temp_data .= ''; - $temp_data .= '' . $inner_item['name'] . ''; + + if ($inner_item['relationship'] == 'Self') { + $emp_code = ' (' . $inner_item['emp_code'] . ')'; + } else { + $emp_code = ''; + } + + $temp_data .= ''; + $temp_data .= '' . $inner_item['name'] . $emp_code . ''; $temp_data .= '' . $inner_item['relationship'] . ''; $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; $temp_data .= '₹' . format_indian_number($inner_item['basic_cover_si']) . ''; - - //Only Display SI Topup and Dependent Addon + + // Only Display SI Topup and Dependent Addon if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { $temp_data .= '₹' . format_indian_number(round($inner_item['premium'])) . ''; $temp_data .= '₹' . format_indian_number(round($inner_item['gst'])) . ''; } - + $temp_data .= ''; - - - - if ($inner_item['relationship'] == 'Self' || $inner_item['relationship'] == 'self') { - $mail = $inner_item['email_corporate']; - $name = $inner_item['name']; - $emp_code = $inner_item['emp_code']; - } - + $is_addon = $inner_item['is_addon']; - + if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { $addtional_premium = $inner_item['rata_premimum'] + $addtional_premium; $gst = $inner_item['gst'] + $gst; } } - + $table_content .= $policy_name . '

'; $table_content .= ''; - $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; - - //Only Display SI Topup and Dependent Addon + + // Only Display SI Topup and Dependent Addon if ($is_addon == 2 || $is_addon == 3) { $table_content .= ''; $table_content .= ''; } - + $table_content .= ''; $table_content .= ''; - $table_content .= '' . $temp_data . ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; - + if ($is_addon == 2 || $is_addon == 3) { $addon_list_array = [ 'policy_name' => $policy_name, @@ -255,36 +270,52 @@ class sendMailNotification ]; $Addon_list[] = $addon_list_array; } - + $temp_data = ''; $addtional_premium = 0; $gst = 0; } } - - if (count($Addon_list) != 0 && count($Addon_list) > 0) { - - $table_content .= '
'; - $table_content .= '
'; - $table_content .= ''; - $table_content .= ''; - $table_content .= ''; - $table_content .= ''; - $sum_tolal = 0; - + + if (count($Addon_list) > 0) { + $table_content .= '
'; + $table_content .= '
Policy NameAdditional PremiumGSTTotal
'; + + // Center align for table header and body + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= ''; + + $table_content .= ''; + + $sum_total = 0; foreach ($Addon_list as $key => $value) { - $sum_tolal = $value['gst'] + $value['addtional_premium'] + $sum_tolal; - $table_content .= ''; + $total_addon = $value['gst'] + $value['addtional_premium']; + $sum_total += $total_addon; + + $table_content .= ''; + $table_content .= ''; $table_content .= ''; $table_content .= ''; - $table_content .= ''; + $table_content .= ''; + $table_content .= ''; } - - $sum_total_words = numberToWords($sum_tolal); - $table_content .= ''; - $table_content .= '
Policy NameAdditional PremiumGSTTotal
' . $value['policy_name'] . '
' . $value['policy_name'] . '₹' . format_indian_number($value['addtional_premium']) . '₹' . format_indian_number($value['gst']) . '₹' . format_indian_number(($value['gst'] + $value['addtional_premium'])) . '
₹' . format_indian_number($total_addon) . '
Total₹' . format_indian_number($sum_tolal) . '
'; - // $table_content .= '
' . $sum_total_words . '
'; + + $sum_total_words = numberToWords($sum_total); + $table_content .= ''; + $table_content .= 'Total'; + $table_content .= '₹' . format_indian_number($sum_total) . ''; + $table_content .= ''; + $table_content .= ''; + $table_content .= '

'; + // $table_content .= '
' . $sum_total_words . '
'; } + // print_r($table_content); die; @@ -296,7 +327,7 @@ class sendMailNotification // $mail = "aadhavanvalli@gmail.com"; // if (isset($mail) && !empty($mail)) { - $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']]; // } return $wholeData; @@ -349,7 +380,6 @@ class sendMailNotification $Addon_list = []; foreach ($array_list as $item) { - if (count($item) != 0) { $table_content .= '

Policy Name : '; $temp_data = ''; @@ -364,19 +394,19 @@ class sendMailNotification } else { $emp_code = ''; } - + $temp_data .= ''; $temp_data .= '' . $inner_item['name'] . $emp_code . ''; $temp_data .= '' . $inner_item['relationship'] . ''; $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; $temp_data .= '₹' . format_indian_number($inner_item['basic_cover_si']) . ''; - - //Only Display SI Topup and Dependent Addon + + // Only Display SI Topup and Dependent Addon if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { $temp_data .= '₹' . format_indian_number(round($inner_item['premium'])) . ''; $temp_data .= '₹' . format_indian_number(round($inner_item['gst'])) . ''; } - + $temp_data .= ''; $is_addon = $inner_item['is_addon']; @@ -389,22 +419,26 @@ class sendMailNotification $table_content .= $policy_name . '

'; $table_content .= ''; - $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; - - //Only Display SI Topup and Dependent Addon + + // Only Display SI Topup and Dependent Addon if ($is_addon == 2 || $is_addon == 3) { $table_content .= ''; $table_content .= ''; } - + $table_content .= ''; $table_content .= ''; - $table_content .= '' . $temp_data . ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; if ($is_addon == 2 || $is_addon == 3) { @@ -425,7 +459,9 @@ class sendMailNotification if (count($Addon_list) > 0) { $table_content .= '
'; $table_content .= ''; - $table_content .= ''; + + // Center align for table header and body + $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; @@ -433,8 +469,9 @@ class sendMailNotification $table_content .= ''; $table_content .= ''; $table_content .= ''; - $table_content .= ''; - + + $table_content .= ''; + $sum_total = 0; foreach ($Addon_list as $key => $value) { $total_addon = $value['gst'] + $value['addtional_premium']; @@ -457,6 +494,7 @@ class sendMailNotification $table_content .= '
Policy NameAdditional PremiumTotal
'; // $table_content .= '
' . $sum_total_words . '
'; } + $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); @@ -466,7 +504,7 @@ class sendMailNotification $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, 'reply_to' => $client_data['reply_to']]; // $wholeData[] = ['mail' => $value['email'], 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; } return $wholeData; @@ -519,7 +557,6 @@ class sendMailNotification $Addon_list = []; foreach ($array_list as $item) { - if (count($item) != 0) { $table_content .= '

Policy Name : '; $temp_data = ''; @@ -534,19 +571,19 @@ class sendMailNotification } else { $emp_code = ''; } - + $temp_data .= ''; $temp_data .= '' . $inner_item['name'] . $emp_code . ''; $temp_data .= '' . $inner_item['relationship'] . ''; $temp_data .= '' . \DateTime::createFromFormat('Y-m-d', $inner_item['dob'])->format('d-m-Y') . ''; $temp_data .= '₹' . format_indian_number($inner_item['basic_cover_si']) . ''; - - //Only Display SI Topup and Dependent Addon + + // Only Display SI Topup and Dependent Addon if ($inner_item['is_addon'] == 2 || $inner_item['is_addon'] == 3) { $temp_data .= '₹' . format_indian_number(round($inner_item['premium'])) . ''; $temp_data .= '₹' . format_indian_number(round($inner_item['gst'])) . ''; } - + $temp_data .= ''; $is_addon = $inner_item['is_addon']; @@ -559,22 +596,26 @@ class sendMailNotification $table_content .= $policy_name . '

'; $table_content .= ''; - $table_content .= ''; + + // Add text-align: center to the table head + $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; - - //Only Display SI Topup and Dependent Addon + + // Only Display SI Topup and Dependent Addon if ($is_addon == 2 || $is_addon == 3) { $table_content .= ''; $table_content .= ''; } - + $table_content .= ''; $table_content .= ''; - $table_content .= '' . $temp_data . ''; + + // Add text-align: center to the table body + $table_content .= '' . $temp_data . ''; $table_content .= '
NameRelationDate Of BirthSum InsuredPremiumGST
'; if ($is_addon == 2 || $is_addon == 3) { @@ -595,7 +636,9 @@ class sendMailNotification if (count($Addon_list) > 0) { $table_content .= '
'; $table_content .= ''; - $table_content .= ''; + + // Center align for table header and body + $table_content .= ''; $table_content .= ''; $table_content .= ''; $table_content .= ''; @@ -603,8 +646,9 @@ class sendMailNotification $table_content .= ''; $table_content .= ''; $table_content .= ''; - $table_content .= ''; - + + $table_content .= ''; + $sum_total = 0; foreach ($Addon_list as $key => $value) { $total_addon = $value['gst'] + $value['addtional_premium']; @@ -627,7 +671,7 @@ class sendMailNotification $table_content .= '
Policy NameAdditional PremiumTotal
'; // $table_content .= '
' . $sum_total_words . '
'; } - + $mail_content = str_replace("[[member_summary]]", $table_content , $mail_content); @@ -636,7 +680,7 @@ class sendMailNotification $mail_array = array_map('trim', $mail_array); $wholeData = []; foreach ($mail_array as $key => $value) { - $wholeData[] = ['mail' => $value, 'subject' => $subject,'message'=> $mail_content]; + $wholeData[] = ['mail' => $value, 'subject' => $subject,'message'=> $mail_content, 'reply_to' => $client_data['reply_to']]; // $wholeData[] = ['mail' => $value, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; } @@ -645,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 ce5481d3..e188b5bd 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -37,6 +37,8 @@ class ClientModel extends Model "reference", "phone", "email", + "reply_to", + "mail_domain", ]; diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 470bbb0a..1aa5bf2d 100755 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -49,6 +49,7 @@ class ClientPolicyModel extends Model "cd_ac_no", "gst", "enrolment_visibility", + "disclaimer", "is_active", ]; @@ -404,9 +405,24 @@ public function getPolicyDetailsForRemainder($client_id = null, $branch_id = nul } return $builder->get()->getResultArray(); +} +//for this using in CRONE JOB +public function getPolicyDetailsForEnrollment($client_id = null, $branch_id = null) +{ + $builder = $this->table('client_policy') + ->where('client_policy.is_active', 1) + ->where('client_policy.policy_status', 1) + ->where('client_policy.open_date IS NOT NULL') + ->where('client_policy.close_date IS NOT NULL'); + if ($client_id && $branch_id) { + $builder->where('client_policy.client_id', $client_id) + ->where('client_policy.client_branch_id', $branch_id); } + return $builder->get()->getResultArray(); +} + } diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 086dbd88..b84b96a9 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -161,7 +161,7 @@ class EmployeeModel extends Model // for EMP rest API process do not change public function checkExistingEmployee($arr,$client_branch_id) { - return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->where('client_id', $arr['client_id'])->where('client_branch_id', $client_branch_id)->first(); + return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->where('client_id', $arr['client_id'])->where('client_branch_id', $client_branch_id)->where('emp_status !=', 'truncated')->first(); } diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 40e682f2..6ced70eb 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -128,7 +128,6 @@ -
@@ -143,18 +142,27 @@
+
+
+
+ +
+ + +
+