diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f098faf4..bbddfdec 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -352,7 +352,8 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("get_client_policy_data_using_policy_no_and_endo_no", "ClientController::get_client_policy_data_using_policy_no_and_endo_no"); $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"); + $routes->get("sentTestMail/(:any)","NotificationController::sentTestMail/$1"); + $routes->post("sendCommonTestMail","NotificationController::sendCommonTestMail"); $routes->get("send_manual_reminder/(:any)", "DashboardController::sendManualReminder/$1"); $routes->get("send_manual_ecard/(:any)", "DashboardController::sendManualEcard/$1"); $routes->get("get_client_policy_list_for_remainder/(:any)", "EmployeeController::get_client_policy_list_for_remainder/$1"); diff --git a/app/Controllers/NotificationController.php b/app/Controllers/NotificationController.php index 82771ba4..ee50a0fd 100755 --- a/app/Controllers/NotificationController.php +++ b/app/Controllers/NotificationController.php @@ -57,72 +57,30 @@ 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')??''; + $form_data['common_mail'] = $this->request->getPost('common_mail')??''; $notificationModel = new NotificationModel(); $find_notification = $notificationModel->where('client_id',$form_data['client_id'])->where('template_name',$form_data['template_name'])->first(); if ($find_notification) { + $this->logger->debug("inside notification update"); $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{ + $this->logger->debug("inside notification insert"); $form_data['created_by'] = get_session_userid(); $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) @@ -201,14 +159,8 @@ class NotificationController extends AdminController } if( isset($value['template_name']) && !empty($value['template_name']) && $value['template_name'] == "member_common_mail"){ - $common_mails = $this->CommonEMailModel - ->where('notification_id',$value['id']) - ->where('is_active',1) - ->findAll()??[]; - $value['comman_mails'] = !empty($common_mails) - ? trim(implode("," , array_column( $common_mails,'email') )) - : []; - + $common_mails = $value['common_mail']??[]; + $value['comman_mails'] = !empty($common_mails) ? $common_mails : ""; } @@ -299,6 +251,51 @@ class NotificationController extends AdminController } } + + + public function sendCommonTestMail() + { + + $template_id = $this->request->getPost('template_id'); + + $test_mail = $this->request->getPost('test_mail'); + + $test_mail_list = $this->request->getPost('test_mail_list'); + + + $notification_data = $this->notificationModel->where('id', $template_id)->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, + 'test_mail_list' => $test_mail_list + ]; + + $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']); + + } + } + public function insertAttachmentsForMailTemplates() { $form_data = $this->request->getPost(); diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 9b1a8d4a..fae31ef5 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -215,7 +215,7 @@ class sendMailNotification $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]; + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'cc' => $params['test_mail_list'],'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common]; return $wholeData; @@ -1438,7 +1438,7 @@ class sendMailNotification $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']]; + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'cc' => $params['test_mail_list'], 'bcc'=> $client_data['common_mails'],'attachments' => $attachments, 'reply_to' => $client_data['reply_to']]; return $wholeData; diff --git a/app/Models/NotificationModel.php b/app/Models/NotificationModel.php index edc3069d..a39df3b3 100755 --- a/app/Models/NotificationModel.php +++ b/app/Models/NotificationModel.php @@ -8,5 +8,5 @@ class NotificationModel extends Model { protected $table = 'notifications'; protected $primaryKey = 'id'; - protected $allowedFields = ["id","client_id","template_name","subject","mail_content","enabled","created_by","updated_by","is_active",'mail_content_json']; + protected $allowedFields = ["id","client_id","template_name","subject","mail_content","enabled","created_by","updated_by","is_active",'mail_content_json','common_mail']; } \ No newline at end of file diff --git a/app/Views/mail_template.php b/app/Views/mail_template.php index 29e8569c..e4f6f20f 100644 --- a/app/Views/mail_template.php +++ b/app/Views/mail_template.php @@ -1,6 +1,18 @@ diff --git a/app/Views/notification.php b/app/Views/notification.php index c6d84602..b36d3845 100755 --- a/app/Views/notification.php +++ b/app/Views/notification.php @@ -378,7 +378,7 @@
- +

(* Multiple Emails Should Be Comma Seperated)

@@ -1364,35 +1364,45 @@ function sendCommonMails(){ - let test_mail_list = $('#email_list').val(); + // test mail list + let test_mail_list = $('#common_mail').val(); - test_mail_list = test_mail_list.split(','); - - console.log("test_mail_list"); - - console.log(test_mail_list); - - test_mail_list.forEach((element)=>{ - - test_mail = element; + + let test_mail = test_mail_list.split(',')[0] ?? ''; if (test_mail !== null || test_mail !== "") { + console.log("valid email or not"); + console.log(test_mail); + + test_mail = test_mail.replace(/\s+/g, '').trim(); + + console.log("is valid email check"); + console.log(isValidEmail((test_mail))); + if (isValidEmail(test_mail)) { var template_id = $('#notification_temp_id').val(); + console.log("template_id"); + console.log(template_id); + if (template_id) { console.log("testmail ..!!"); console.log(test_mail); - let url = '' + template_id + '/' + test_mail; + let url = ''; console.log('testing mail url:', url); $.ajax({ url: url, - type: "GET", + type: "POST", + data:{ + template_id, + test_mail, + test_mail_list + }, dataType: 'json', success: function(res) { @@ -1427,8 +1437,6 @@ } } - - }) } @@ -1865,10 +1873,10 @@ } - if(res.comman_mails != []){ + if(res.comman_mails != ""){ console.log("common mails recieved here ........!!!!!!!!!!!"); console.log(res); - $('#email_list').val(res.comman_mails); + $('#common_mail').val(res.comman_mails); } $('.loader').fadeOut();