diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 54b05f32..0bc4cbf5 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -719,7 +719,8 @@ $routes->group('test', function($routes) {
$routes->get('membervalidation', 'TestingController::membervalidation');
$routes->get('generateExcel', 'TestingController::generateExcel');
$routes->get('logo_renaming','TestingController::logo_renaming');
- // $routes->get('createDefaultMailTempalteInDB','TestingController::createDefaultMailTempalteInDB');
+ // $routes->get('createDefaultMailTempalteInDB','TestingController::createDefaultMailTempalteInCrossDB');
+ // $routes->get('createDefaultMailTempalteInSameDB','TestingController::createDefaultMailTempalteInSameDB');
});
$routes->cli('cli/testcli', 'TestingController::testcli');
diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php
index 5b091387..908a1ede 100755
--- a/app/Controllers/ClientController.php
+++ b/app/Controllers/ClientController.php
@@ -7745,6 +7745,10 @@ class ClientController extends AdminController
$member_review_and_summary_mail_template = $this->notificationModel->where('client_id',NULL)->where('template_name','member_review_and_summary_mail')->get()->getResultArray()[0]??[];
+ $member_ecard_mail_template = $this->notificationModel->where('client_id',NULL)->where('template_name','member_ecard_mail')->get()->getResultArray()[0]??[];
+
+ $member_common_mail_template = $this->notificationModel->where('client_id',NULL)->where('template_name','member_common_mail')->get()->getResultArray()[0]??[];
+
$default_member_welcome_mail_template = [
'client_id' => $client_id,
'template_name' => 'member_welcome_mail',
@@ -7787,6 +7791,34 @@ class ClientController extends AdminController
'mail_content_copy'=> null
];
+ $default_member_ecard_mail_template = [
+ 'client_id' => $client_id,
+ 'template_name' => 'member_ecard_mail',
+ 'subject' => $member_ecard_mail_template['subject']??'',
+ 'mail_content' => $member_ecard_mail_template['mail_content']??'',
+ 'mail_content_json'=> $member_ecard_mail_template['mail_content_json']??'',
+
+ 'created_by' => get_session_userid(),
+ 'created_at' => date('Y-m-d H:i:s'),
+ 'updated_by' => null,
+ 'updated_at' => date('Y-m-d H:i:s'),
+ 'mail_content_copy'=> null
+ ];
+
+ $default_member_common_mail_template = [
+ 'client_id' => $client_id,
+ 'template_name' => 'member_common_mail',
+ 'subject' => $member_common_mail_template['subject']??'',
+ 'mail_content' => $member_common_mail_template['mail_content']??'',
+ 'mail_content_json'=> $member_common_mail_template['mail_content_json']??'',
+
+ 'created_by' => get_session_userid(),
+ 'created_at' => date('Y-m-d H:i:s'),
+ 'updated_by' => null,
+ 'updated_at' => date('Y-m-d H:i:s'),
+ 'mail_content_copy'=> null
+ ];
+
$this->myLogger->logme('error', 'Default Mail Template Data ' . json_encode([
$default_member_welcome_mail_template,
$default_member_remainder_mail_template,
@@ -7798,7 +7830,9 @@ class ClientController extends AdminController
$default_templates_inserted = $this->notificationModel->insertBatch([
$default_member_welcome_mail_template,
$default_member_remainder_mail_template,
- $default_member_review_and_summary_mail_template
+ $default_member_review_and_summary_mail_template,
+ $default_member_ecard_mail_template,
+ $default_member_common_mail_template
]);
diff --git a/app/Controllers/NotificationController.php b/app/Controllers/NotificationController.php
index b497e958..64988466 100755
--- a/app/Controllers/NotificationController.php
+++ b/app/Controllers/NotificationController.php
@@ -3,6 +3,7 @@
// declare(strict_types=1);
namespace App\Controllers;
+use App\Models\CommonEMailModel;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
@@ -28,13 +29,16 @@ class NotificationController extends AdminController
protected $notificationModel;
protected $clientModel;
protected $MailAttachmentModel;
+
+ protected $CommonEMailModel;
public function __construct()
{
$this->myLogger = \Config\Services::mylogger();
$this->notificationModel = new NotificationModel();
$this->clientModel = new ClientModel();
- $this->MailAttachmentModel = new MailAttachmentModel();
+ $this->MailAttachmentModel = new MailAttachmentModel();
+ $this->CommonEMailModel = new CommonEMailModel();
}
// This is for Template Name Camel Case to Snake Case for store in DB
@@ -53,33 +57,80 @@ class NotificationController extends AdminController
$form_data['mail_content'] = $this->request->getPost('mailContent');
$form_data['client_id'] = $this->request->getPost('client_id');
$form_data['mail_content_json'] = $this->request->getPost('mailJson');
+ $form_data['email_list'] = $this->request->getPost('email_list');
$notificationModel = new NotificationModel();
$find_notification = $notificationModel->where('client_id',$form_data['client_id'])->where('template_name',$form_data['template_name'])->first();
if ($find_notification) {
- $id = $find_notification['id'];
+ $id = $find_notification['id'] ?? '';
$form_data['updated_by'] = get_session_userid();
$notificationModel->update($id,$form_data);
+ $this->save_common_mail($id , $form_data);
$complete = "Update";
}else{
$form_data['created_by'] = get_session_userid();
- $notificationModel->insert($form_data);
+ $id = $notificationModel->insert($form_data);
+ $this->save_common_mail($id , $form_data);
$complete = "Inserted";
}
return json_encode($complete);
-
+
}
+ private function save_common_mail($id, $form_data)
+ {
+
+ $this->logger->debug("step 1 - inside save common mail");
+
+ if (empty($form_data['email_list'])) {
+ return;
+ }
+
+
+ $this->logger->debug("step 2 - id and form_data are present");
+
+ $emails = array_map('trim', explode(',', $form_data['email_list']));
+
+
+ $this->logger->debug("step 3 common emails were present");
+
+ $common_mail_data = [];
+
+ foreach ($emails as $email) {
+ $common_mail_data[] = ['notification_id' => $id , 'email' => $email , 'is_active' => 1];
+ }
+
+ $this->logger->debug("step 4 common email data \n" . json_encode($common_mail_data));
+
+
+ // Deactivate existing emails
+ $this->CommonEMailModel
+ ->where('notification_id', $id)
+ ->set(['is_active' => 0])
+ ->update();
+
+ $this->logger->debug("step 5 deleted old common email data");
+
+
+
+ // Insert all at once
+ $this->CommonEMailModel->insertBatch($common_mail_data);
+
+ $this->logger->debug("step 6 common mail data insertion done ..!!");
+
+ }
+
// This is for the Enabls in Notification area and Update the Recipient and HR Mail Id in( Enables -> Notification table and Mail id's -> Client table)
public function update_enable()
{
$checkboxNames = [
'member_welcome_mail_btn',
+ 'common_mail_btn',
'member_reminder_mail_btn',
'member_ecard_mail_btn',
'member_review_and_summary_mail_btn',
diff --git a/app/Controllers/TestingController.php b/app/Controllers/TestingController.php
index 98257f4e..75d4d578 100644
--- a/app/Controllers/TestingController.php
+++ b/app/Controllers/TestingController.php
@@ -869,7 +869,7 @@ class TestingController extends BaseController
}
- public function createDefaultMailTempalteInDB()
+ public function createDefaultMailTempalteInCrossDB()
{
$postDB = \Config\Database::connect(); // target DB
$preDB = \Config\Database::connect('preDB'); // source DB
@@ -920,7 +920,66 @@ class TestingController extends BaseController
}
- return $this->response->setJSON(['message'=>"Created Default Mail Tempalte In DB "])->setStatusCode(200);
+ return $this->response->setJSON(['message'=>"Created Default Mail Tempalte In Cross DB "])->setStatusCode(200);
+ }
+
+ public function createDefaultMailTempalteInSameDB()
+ {
+ $postDB = \Config\Database::connect();
+
+ // Templates to copy
+ $templateNames = [
+ 'member_welcome_mail',
+ 'member_reminder_mail',
+ 'member_review_and_summary_mail',
+ 'member_common_mail',
+ 'member_ecard_mail'
+ ];
+
+
+
+
+ foreach ($templateNames as $template) {
+
+ $exists = $postDB->table('notifications')
+ ->where('client_id', NULL)
+ ->where('template_name', $template)
+ ->countAllResults();
+
+ if ($exists > 0 ) {
+ continue; // Skip if already inserted
+ }
+
+ // Fetch template from preDB
+ $templateData = $postDB->table('notifications')
+
+ // this is where we want to replace 0 with the client id we want to replace
+ ->where('client_id', 0)
+
+ // template_name from which you want to create a common template from templateNames array.
+ ->where('template_name', $template)
+ ->get()
+ ->getRowArray();
+
+ if (!empty($templateData)) {
+
+ // Remove ID to avoid duplicate primary key issues
+ unset($templateData['id']);
+
+ // Set created_by and timestamps if needed
+ $templateData['client_id'] = NULL;
+ $templateData['created_by'] = 1;
+ $templateData['cretaed_at'] = date('Y-m-d H:i:s');
+ $templateData['updated_by'] = NULL;
+ $templateData['updated_at'] = NULL;
+
+ // Insert into postDB
+ $postDB->table('notifications')->insert($templateData);
+ }
+ }
+
+
+ return $this->response->setJSON(['message'=>"Created Default Mail Tempalte In Same DB "])->setStatusCode(200);
}
diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php
index a726fe16..4ac2580e 100755
--- a/app/Helpers/sendMailNotification.php
+++ b/app/Helpers/sendMailNotification.php
@@ -163,7 +163,62 @@ class sendMailNotification
return $wholeData;
- } else if($action == 'member_review_and_summary_mail'){
+ } else if($action == 'member_common_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'];
+ $common = $params['common'];
+
+
+ $mail_content = $notification['mail_content'];
+ $mail = $get_emp_email_and_other_details['email_corporate'];
+ $subject = $notification['subject'];
+
+ $cleanedText = mb_convert_encoding($subject, 'UTF-8', 'UTF-8'); // Normalize encoding
+ $cleanedText = preg_replace('/[^\x20-\x7E]/', '', $cleanedText);
+
+ $subject = $cleanedText;
+
+ $link = generate_download_link($rand_string).'/1';
+
+ $app_link = $_ENV['App_Url'];
+ $name = $get_emp_email_and_other_details['name'];
+ $employee_mobile_no = $get_emp_email_and_other_details['mobile'];
+ $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]]", "{{nhance_logo}}"], "", $mail_content);
+ $mail_content = str_replace(["[[client_logo]]", "{{client_logo}}"], "
", $mail_content);
+
+ $mail_content = str_replace(["[[member_name]]", "{{member_name}}"], $name, $mail_content);
+ $mail_content = str_replace(["[[member_mobile]]", "{{member_mobile}}"], $employee_mobile_no, $mail_content);
+ $mail_content = str_replace(["[[app_link]]", "{{app_link}}"], "Review Details", $mail_content);
+ $mail_content = str_replace(["[[post_enrollment_app_link]]", "{{post_enrollment_app_link}}"], "Review Details", $mail_content);
+ // $mail_content = str_replace("[[tpa_id]]", $tpa_id, $mail_content);
+ $mail_content = str_replace(["[[ecard_download_link]]", "{{ecard_download_link}}"], "Download Insurance Card", $mail_content);
+ $mail_content = str_replace(["[[client_name]]", "{{client_name}}"], $client_data['client_name'], $mail_content);
+
+ $mail_content = preg_replace('/
]*>( |\s)*<\/p>/i', '', $mail_content);
+
+ $data['params'] = $params;$data['client_logo'] = $client_logo;
+ $data['mail_content'] = $mail_content;
+ $mail_content = view('mail_template', $data);
+
+
+ $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common];
+
+ return $wholeData;
+
+ }else if($action == 'member_review_and_summary_mail'){
$array_list = $params['array_list'];//employeee lst
$client_policy_id = $params['client_policy_id'];
@@ -1331,6 +1386,61 @@ class sendMailNotification
return $wholeData;
+ }else if($action == 'member_common_mail'){
+
+ $notification = $params['notification_data'];
+ $client_data = $params['client_data'];
+ $mail = $params['test_mail'];
+ $mailAttachmentModel = new MailAttachmentModel();
+ $attachment_data = $mailAttachmentModel
+ ->select('file_path, file_name')
+ ->where('notification_id', $notification['id'])
+ ->where('is_active', 1)
+ ->findAll();
+
+ $attachments = [];
+ foreach ($attachment_data as $data) {
+ $attachments[] = [
+ "filePath" => WRITEPATH . $data['file_path'],
+ "fileName" => $data['file_name']
+ ];
+ }
+
+ $mail_content = $notification['mail_content'];
+ $subject = $notification['subject'];
+
+ $rand_string = 'HX3kUh';
+ $link = generate_download_link($rand_string).'/1';
+
+ $name = 'John Doe';
+ $mobile = 9080706050;
+
+ $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]]", "{{member_name}}"], $name, $mail_content);
+ $mail_content = str_replace(["[[member_mobile]]", "{{member_mobile}}"], $mobile, $mail_content);
+ $mail_content = str_replace(["[[app_link]]", "{{app_link}}"], "Review Details", $mail_content);
+ $mail_content = str_replace(["[[post_enrollment_app_link]]", "{{post_enrollment_app_link}}"], "Review Details", $mail_content);
+ $mail_content = str_replace(["[[ecard_download_link]]", "{{ecard_download_link}}"], "Download Insurance Card", $mail_content);
+ $mail_content = str_replace(["[[client_name]]", "{{client_name}}"], $client_data['client_name'], $mail_content);
+
+ $mail_content = preg_replace('/
]*>( |\s)*<\/p>/i', '', $mail_content); + + $data['params'] = $params;$data['client_logo'] = $client_logo; + $data['mail_content'] = $mail_content; + $mail_content = view('mail_template', $data); + + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'],'attachments' => $attachments, 'reply_to' => $client_data['reply_to']]; + + return $wholeData; + } else if($action == 'member_review_and_summary_mail'){ $array_list = [ diff --git a/app/Models/CommonEMailModel.php b/app/Models/CommonEMailModel.php new file mode 100644 index 00000000..4b96f7ee --- /dev/null +++ b/app/Models/CommonEMailModel.php @@ -0,0 +1,42 @@ + -