diff --git a/app/Config/Email.php b/app/Config/Email.php
index 9e4e3801..21911614 100755
--- a/app/Config/Email.php
+++ b/app/Config/Email.php
@@ -28,17 +28,21 @@ class Email extends BaseConfig
/**
* SMTP Server Address
*/
- public string $SMTPHost = 'smtp.zoho.in';
+ // public string $SMTPHost = 'smtp.zoho.in';
+ public string $SMTPHost = 'smtp.gmail.com';
/**
* SMTP Username
*/
- public string $SMTPUser = 'web@vijayabharathambooks.com';
+ // public string $SMTPUser = 'web@vijayabharathambooks.com';
+ public string $SMTPUser = 'venbalap08@gmail.com';
+
/**
* SMTP Password
*/
- public string $SMTPPass = 'Sz9VueQ2iLgH';
+ //public string $SMTPPass = 'Sz9VueQ2iLgH';
+ public string $SMTPPass = 'bqhvujeauokgcdxt';
/**
* SMTP Port
diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index dc58b69b..ab3447ce 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -175,7 +175,7 @@ $routes->post("campaign_creation_insert", "Notifications::campaign_creation_inse
# Auto run process routes
$routes->get('process_scheduled_notifications/', 'Notifications::processScheduledNotifications');
-$routes->get('process_customergroup_notifications/(:any)/(:any)', 'Notifications::customer_group_notification/$1/$2');
+// $routes->get('process_customergroup_notifications/(:any)/(:any)', 'Notifications::customer_group_notification/$1/$2');
$routes->get('acknowlegdement', 'Notifications::noifications_acknowlegdement');
$routes->get('subscription_inactive', 'Invoice::subscription_inactive');
diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php
index b8d7a138..b1860ebe 100755
--- a/app/Controllers/Notifications.php
+++ b/app/Controllers/Notifications.php
@@ -324,6 +324,7 @@ class Notifications extends BaseController
if ($id === '0') {
$this->logger->error("Template Creation: In Add Page");
$data['page_name'] = 'Add Template';
+ $data['template_id'] = (int)$id;
$data['template_details'] = [];
} elseif ($id !== '0') {
$this->logger->error("Template Creation: In Edit Page ID =" . $id);
@@ -331,6 +332,7 @@ class Notifications extends BaseController
$model->setTable('templates');
$where = ['template_id' => (int)$id];
$result = $model->where($where)->findAll();
+ $data['template_id'] = (int)$id;
$data['template_details'] = !empty($result[0]) ? $result[0] : [];
}
// print_r($data['template_details']);die();
@@ -518,8 +520,8 @@ class Notifications extends BaseController
'campaign_id' => $id,
'campaign_name' => $this->request->getPost('campaign_name'),
'template_id' => $this->request->getPost('template_id'),
- 'scheduled_date' => $this->request->getPost('scheduled_date'),
- 'scheduled_time' => $this->request->getPost('scheduled_time') != "" ? $this->request->getPost('scheduled_time') : NULL,
+ // 'scheduled_date' => $this->request->getPost('scheduled_date'),
+ // 'scheduled_time' => $this->request->getPost('scheduled_time') != "" ? $this->request->getPost('scheduled_time') : NULL,
'mode' => $this->request->getPost('mode'),
'group_id' => serialize($this->request->getPost('group_id')),
'isactive' => $isactive,
@@ -527,21 +529,27 @@ class Notifications extends BaseController
'updated_by' => $session_uid
];
if ($id != "") {
+ // id has value means updation process.
$notify_mod = new NotificationModel();
$notify_mod->setTable('notification_campaign');
$where = ['campaign_id' => (int)$id];
$isactive_check = $notify_mod->where($where)->select('isactive')->first();
if ((int)$isactive_check['isactive'] === 0 && $isactive === 0) {
- $statement['success'] = 'Notification Campaign already In-Active. can`t able to update.';
- $statement['error'] = "";
+ $statement['success'] = '';
+ $statement['error'] = 'Notification Campaign already In-Active. can`t able to update.';
$statement['log'] = "Notification Campaign: already inactive status.Can`t able to update, Notification Campaign Group ID = " . $id;
} else {
$statement = $model->saveDetails($data, 'campaign_id', 'notification_campaign');
}
} else {
+ // id has no value means insertion process.
$statement = $model->saveDetails($data, 'campaign_id', 'notification_campaign');
}
+
if ($statement['success']) {
+ $tid = $data['template_id'];
+ $cid = $data['campaign_id'] ? $data['campaign_id'] : $statement['insert_id'];
+ $this->scheduledNotifications($tid,$cid,1);
session()->setFlashdata('success', $statement['success']);
$this->logger->error($statement['log']);
} else if ($statement['error']) {
@@ -562,7 +570,7 @@ class Notifications extends BaseController
################################################################
public function getExpCustomerDetail($window_time = null)
{
- echo "hi";
+ echo "Hi, ";
# Step 1: add the days to retrive the data//
$providedDate = date('Y-m-d');
$newDate = date('Y-m-d', strtotime($providedDate . ' + ' . $window_time . ' days'));
@@ -579,7 +587,7 @@ class Notifications extends BaseController
# Step 3: Replace the placeholder WINDOW_TIME with the user-provided value
$modifiedQuery = str_replace('WINDOW_TIME', $window_time, $ExpCustomerDetail);
-// print_r($modifiedQuery);die;
+ // print_r($modifiedQuery);die;
if (empty($modifiedQuery)) {
$this->logger->error('There is no sub query');
return;
@@ -611,6 +619,7 @@ class Notifications extends BaseController
if ($status === 'Approved') {
# EXPIRAY_NOTIFY_TEMPLATE_EMAIL
$emailTemplateName = $NotificationModel->getTempName(EXPIRAY_NOTIFY_TEMPLATE_EMAIL);
+ echo "Person Name :".$fullName."
";
if (count($emailTemplateName) && !empty($emailTemplateName)) {
$campaign_id = 1;
# Insertion on History Email Means Campaign ID 1 Hardcoded
@@ -619,16 +628,29 @@ class Notifications extends BaseController
# Step 4: Prepare email content based on the template
$emailContent = $emailTemplateName[0]['message'];
- $emailContent = str_replace("{USER_NAME}", $fullName, $emailContent);
- $emailContent = str_replace("{SCHEME_NAME}", $schemename, $emailContent);
- $emailContent = str_replace("{EXPIRY_DATE}", $expirydate, $emailContent);
+ if (isset($fullName)) {
+ $emailContent = str_replace("{USER_NAME}", $fullName, $emailContent);
+ }
+ if (isset($schemename)) {
+ $emailContent = str_replace("{SCHEME_NAME}", $schemename, $emailContent);
+ }
+ if (isset($expirydate)) {
+ $emailContent = str_replace("{EXPIRY_DATE}", $expirydate, $emailContent);
+ }
+ if (isset($customerId)) {
+ $emailContent = str_replace("{RENEWAL_LINK}", base_url() . 'subscription_renewal/' . $customerId, $emailContent);
+ }
+
+
$emailData = [
'template_name' => 'EXPIRAY_NOTIFY_TEMPLATE_EMAIL',
'recipient_email' => $row['email'],
'subject' => 'Your Subscription Expiry Notification',
'description' => $emailContent,
];
+
+
$history_child_data = [ 'fkid' => $history_parent_id,
'customer_id' => $customerId,
'receiving_entity' => $row['email'],
@@ -703,10 +725,18 @@ class Notifications extends BaseController
# Step 7: Prepare whatsapp content based on the template
$whatsappContent = $whatsappTemplateName[0]['message'];
- $whatsappContent = str_replace("{USER_NAME}", $fullName, $emailContent);
- $whatsappContent = str_replace("{SCHEME_NAME}", $schemename, $emailContent);
- $whatsappContent = str_replace("{EXPIRY_DATE}", $expirydate, $emailContent);
-
+ if (isset($fullName)) {
+ $whatsappContent = str_replace("{USER_NAME}", $fullName, $whatsappContent);
+ }
+ if (isset($schemename)) {
+ $whatsappContent = str_replace("{SCHEME_NAME}", $schemename, $whatsappContent);
+ }
+ if (isset($expirydate)) {
+ $whatsappContent = str_replace("{EXPIRY_DATE}", $expirydate, $whatsappContent);
+ }
+ if (isset($customerId)) {
+ $whatsappContent = str_replace("{RENEWAL_LINK}", base_url() . 'subscription_renewal/' . $customerId, $whatsappContent);
+ }
# Step 8: Insertion on History Child for whatsapp
$history_child_data = [ 'fkid' => $history_parent_id,
'customer_id' => $customerId,
@@ -779,17 +809,24 @@ class Notifications extends BaseController
################################################################
## notification campaign details
public function processScheduledNotifications(){
+ $this->scheduledNotifications(0,0,0);
+ // parameter are template_id is zero , campaign_id is zero , dummy is zero
+ }
+
+ public function scheduledNotifications($tid,$cid,$dummyvariable){
$this->logger->error("Auto Scheduled Notification Started");
$model = new NotificationModel();
#step 1 get scheduled notification details
- $notification_campaign_result = $this->getScheduledNotificationDetails(0,0);
+ $notification_campaign_result = $this->getScheduledNotificationDetails($tid,$cid);
$this->logger->error("Auto Scheduled Campaign Details Count = ".count($notification_campaign_result));
if(!count($notification_campaign_result))
{
$this->logger->error("No Auto Scheduled Notification in DB,exiting...!");
$this->logger->error("Auto Scheduled Notification Ends");
- echo "No Scheduled Data Founded"."
";
- exit();
+ if($dummyvariable == 0){
+ echo "No Scheduled Data Founded"."
";
+ exit();
+ }
}
// echo "Notification campaign Result Array in count = ".count($notification_campaign_result)."
";
//looping multiple notification campaign
@@ -797,7 +834,9 @@ class Notifications extends BaseController
{
foreach($notification_campaign_result as $index => $single_campaign)
{
- echo "Notification Campaign Name = ".$single_campaign['campaign_name']."
";
+ if($dummyvariable == 0){
+ echo "Notification Campaign Name = ".$single_campaign['campaign_name']."
";
+ }
#step 2 get template details
$template = $this->getTemplateDetails($single_campaign['template_id']);
$customer_details = $this->getCustomerDetails($single_campaign['group_id']);
@@ -850,7 +889,7 @@ class Notifications extends BaseController
$notification = new NotificationHelper();
if($single_campaign['mode'] == 'Email')
{
- $email_response = $notification->sendEmail(array('recipient_email' => $customer['email'],'subject' => $template['subject'],'template_name' => $template['template_name'],'description' => $notificationContent));
+ $email_response = $notification->sendEmail(array('recipient_email' => $customer['email'],'subject' => $template['subject'],'template_name' => $template['template_name'],'description' => $notificationContent));
$mail_log = isset($email_response['success']) ? 'Email sent successfully' : 'Failed to send email';
$receiving_status = isset($email_response['success']) ? 1 : 0;
$this->logger->error("Auto Scheduled Email CID = ".$customer['customer_id']." ".$mail_log);
@@ -888,12 +927,12 @@ class Notifications extends BaseController
}
// #step 6 update campaign status to 1
$statement = $model->update_notification_campaign_status(['status' => 1],$single_campaign['campaign_id']);
- echo "Final Campaign Status = ".$statement."
";
+ if($dummyvariable == 0){ echo "Final Campaign Status = ".$statement."
"; }
$this->logger->error($statement);
#step 7 update history parent status to 1
$history_parent_statement = $model->update_notification_history_parent_status(['status' => 1],$history_parent_id,$single_campaign['campaign_id']);
- echo "Final Acknowlegdement = ".$history_parent_statement."
";
+ if($dummyvariable == 0){ echo "Final Acknowlegdement = ".$history_parent_statement."
"; }
$this->logger->error($history_parent_statement);
}
@@ -974,10 +1013,18 @@ class Notifications extends BaseController
// print_r($dataPointsArray['customer_name']);
// echo $originalTemplate;
$notificationContent = $originalTemplate;
- $notificationContent = str_replace("{USER_NAME}", $dataPointsArray["customer_name"], $notificationContent);
- $notificationContent = str_replace("{SCHEME_NAME}", $dataPointsArray["scheme_name"], $notificationContent);
- $notificationContent = str_replace("{EXPIRY_DATE}", $dataPointsArray["formatted_due_date"], $notificationContent);
- $notificationContent = str_replace("{RENEWAL_LINK}", base_url() . 'subscription_renewal/' . $dataPointsArray["customer_id"], $notificationContent);
+ if (isset($dataPointsArray["customer_name"])) {
+ $notificationContent = str_replace("{USER_NAME}", $dataPointsArray["customer_name"], $notificationContent);
+ }
+ if (isset($dataPointsArray["scheme_name"])) {
+ $notificationContent = str_replace("{SCHEME_NAME}", $dataPointsArray["scheme_name"], $notificationContent);
+ }
+ if (isset($dataPointsArray["formatted_due_date"])) {
+ $notificationContent = str_replace("{EXPIRY_DATE}", $dataPointsArray["formatted_due_date"], $notificationContent);
+ }
+ if (isset($dataPointsArray["customer_id"])) {
+ $notificationContent = str_replace("{RENEWAL_LINK}", base_url() . 'subscription_renewal/' . $dataPointsArray["customer_id"], $notificationContent);
+ }
return $notificationContent;
}
############## Auto Scheduled Notification Ends ################
@@ -993,119 +1040,4 @@ class Notifications extends BaseController
$this->render_page('noifications_acknowlegdement', $data);
}
############## Notification Acknowlegdement Ends ################
- public function customer_group_notification($tid,$cid){
- $this->logger->error("Customer Group Notification Started");
-
- $this->logger->error("Customer Group Notification Ended");
- $model = new NotificationModel();
- #step 1 get scheduled notification details
- $notification_campaign_result = $this->getScheduledNotificationDetails($tid,$cid);
- // print_r($notification_campaign_result);
- //looping multiple notification campaign
- if(count($notification_campaign_result))
- {
- foreach($notification_campaign_result as $index => $single_campaign)
- {
- echo "Notification Campaign Name = ".$single_campaign['campaign_name']."
";
- #step 2 get template details
- $template = $this->getTemplateDetails($single_campaign['template_id']);
- $customer_details = $this->getCustomerDetails($single_campaign['group_id']);
- if(count($template) && count($customer_details))
- {
- #step 3 execute the customer group query and return customer details
- $sent_customer_details = [];
- if(count($customer_details))
- {
- #step 2.1
- $history_parents_data = ['campaign_id' => $single_campaign['campaign_id'],'status' => 0];
- $history_parent_id = $model->save_notification_history_parents($history_parents_data);
- $single_campaign['history_parent_id'] = $history_parent_id;
-
- foreach($customer_details as $customer)
- {
- $customer['customer_name'] = isset($customer['customer_name'])
- ? $customer['customer_name']
- : (isset($customer['first_name']) && isset($customer['last_name'])
- ? $customer['first_name'] . ' ' . $customer['last_name']
- : '');
- $customer['scheme_name'] = isset($customer['scheme_name']) ? $customer['scheme_name'] : (isset($customer['title']) ? $customer['title'] : "");
- $formatted_due_date = "";
-
- if(isset($customer['to_subscription'])){
- $dateObj = date_create($customer['to_subscription']);
- $formatted_due_date = date_format($dateObj, 'd-m-Y');
- }else{
- $formatted_due_date = $customer['formatted_due_date'];
- }
- $customer['formatted_due_date'] = $formatted_due_date;
-
-
- #step 4 replace templates palceholders with data points
- $notificationContent = $this->replaceTemplateWithDataPoints($template['message'],$customer);
- $history_child_data = [
- 'fkid' => $single_campaign['history_parent_id'],
- 'customer_id' => $customer['customer_id'],
- 'receiving_entity' => $single_campaign['mode'] == 'Email' ? $customer['email'] : $customer['mobile_no'],
- 'receiving_status' => 0,
- 'message' => $notificationContent];
- $history_child_id = $model->save_notification_history_child($history_child_data);
- if(!in_array($customer['customer_id'],$sent_customer_details))
- {
- $this->logger->error("Auto Scheduled Customer CID = ".$customer['customer_id'].", CN = ".$customer['customer_name']);
- #step 5 send notification
- $notification = new NotificationHelper();
- if($single_campaign['mode'] == 'Email')
- {
- $email_response = $notification->sendEmail(array('recipient_email' => $customer['email'],'subject' => $template['subject'],'template_name' => $template['template_name'],'description' => $notificationContent));
- $mail_log = isset($email_response['success']) ? 'Email sent successfully' : 'Failed to send email';
- $receiving_status = isset($email_response['success']) ? 1 : 0;
- $this->logger->error("Auto Scheduled Email CID = ".$customer['customer_id']." ".$mail_log);
-
- $history_child_where = ['fkid' => $single_campaign['history_parent_id'],'id' => (int)$history_child_id];
- $history_child_updatedata = ['receiving_status'=>$receiving_status, 'result'=>isset($email_response['success']) ? $mail_log : (strtolower(gettype($email_response)) == "string" ? $email_response : json_encode($email_response)) ];
- $history_child_statement = $model->update_notification_history_child($history_child_updatedata,$history_child_where);
- $this->logger->error($history_child_statement);
-
- }
- if($single_campaign['mode'] == 'Whatsapp')
- {
- $params = (object) Null;
- $url = SEND_WAAI_URL;
- $params->type = "text";
- $params->instance_id = $_ENV['WAAI_INSTANCE'];
- $params->access_token = $_ENV['WAAI_TOKEN'];
- $params->message = strip_tags(ltrim($notificationContent));
- $params->number = (int)'91' . $customer['mobile_no'];
- $whatsapp_reponse = $notification->sendWhatsAppMessage($url, "POST", $params);
- $whatsapp_reponse_msg = strtolower(gettype($whatsapp_reponse)) == "string" ? $whatsapp_reponse : json_encode($whatsapp_reponse['reponse']);
- // echo "Whatsapp Response = ".$whatsapp_reponse_msg."
";
- $this->logger->error("Auto Scheduled Whatsapp CID = ".$customer['customer_id']." ".$whatsapp_reponse_msg);
- $history_child_where = ['fkid' => $single_campaign['history_parent_id'],'id' => (int)$history_child_id];
-
- $history_child_updatedata = ['receiving_status'=>$whatsapp_reponse['receiving_status'],'result'=>$whatsapp_reponse_msg];
- $history_child_statement = $model->update_notification_history_child($history_child_updatedata,$history_child_where);
- $this->logger->error($history_child_statement);
-
- }
-
- array_push($sent_customer_details,$customer['customer_id']);
- }
-
- }
-
- }
- #step 6 update campaign status to 1
- $statement = $model->update_notification_campaign_status(['status' => 0],$single_campaign['campaign_id']);
- echo "Final Campaign Status = ".$statement."
";
- $this->logger->error($statement);
-
- #step 7 update history parent status to 1
- $history_parent_statement = $model->update_notification_history_parent_status(['status' => 1],$history_parent_id,$single_campaign['campaign_id']);
- echo "Final Acknowlegdement = ".$history_parent_statement."
";
- $this->logger->error($history_parent_statement);
- }
- }
- }
- }
-
}
diff --git a/app/Helpers/NotificationHelper.php b/app/Helpers/NotificationHelper.php
index 2b4b90c5..cbc3afc4 100755
--- a/app/Helpers/NotificationHelper.php
+++ b/app/Helpers/NotificationHelper.php
@@ -148,6 +148,66 @@ class NotificationHelper
return $final_result;
}
+ // public function send_whatsapp_message($to , $doc_url)
+ // {
+ // $url = 'https://graph.facebook.com/v20.0/355752820961010/messages';
+ // $headers = [
+ // 'Authorization: Bearer '.$_ENV['whatsAppToken'],
+ // 'Content-Type: application/json'
+ // ];
+
+ // $templateName = 'bbsigndoc';
+ // $languageCode = 'en';
+ // $parsedUrl = parse_url($doc_url, PHP_URL_QUERY);
+
+ // $data = [
+ // 'messaging_product' => 'whatsapp',
+ // 'to' => $to,
+ // 'type' => 'template',
+ // 'template' => [
+ // 'name' => $templateName,
+ // 'language' => [
+ // 'code' => $languageCode
+ // ],
+ // 'components' => [
+ // [
+ // 'type' => 'body',
+ // ],
+ // [
+ // 'type' => 'button',
+ // 'sub_type' => 'url',
+ // 'index' => 0,
+ // 'parameters' => [
+
+ // [
+ // 'type' => 'text',
+ // 'text' => $parsedUrl
+ // ]
+ // ]
+ // ]
+ // ]
+ // ]
+ // ];
+
+
+ // $ch = curl_init();
+ // curl_setopt($ch, CURLOPT_URL, $url);
+ // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+ // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ // curl_setopt($ch, CURLOPT_POST, true);
+ // curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
+
+ // $response = curl_exec($ch);
+ // $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ // curl_close($ch);
+
+ // return [
+ // 'status_code' => $statusCode,
+ // 'response' => json_decode($response, true)
+ // ];
+ // }
+
+
}
?>
diff --git a/app/Models/NotificationModel.php b/app/Models/NotificationModel.php
index 2a8569d9..359307ec 100755
--- a/app/Models/NotificationModel.php
+++ b/app/Models/NotificationModel.php
@@ -43,7 +43,7 @@ class NotificationModel extends Model
->join('users as U1', 'U1.user_id = T.created_by', 'left')
->join('users as U2', 'U2.user_id = T.updated_by', 'left')
->select('T.template_id,T.template_name,T.mode,T.created_on,T.created_by,T.updated_on,T.updated_by,DATE_FORMAT(T.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,CONCAT_WS(" ", U1.first_name, U1.last_name) as created_by_name,CONCAT_WS(" ", U2.first_name, U2.last_name) as updated_by_name,T.isactive')
- ->whereNotIn('T.template_name',array('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP'))
+ // ->whereNotIn('T.template_name',array('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP'))
->get()->getResultArray();
}
@@ -58,10 +58,13 @@ class NotificationModel extends Model
$statement['success'] = $statement_string.' has been updated successfully.';
$statement['error'] = "";
$statement['log'] = $statement_string.": has been updated successfully. Updated ".$pk_name." = " .$id." Affected Rows = ".$affectedRows;
+ $statement['insert_id'] = $id;
+
} else {
$statement['success'] = "";
$statement['error'] = $statement_string.' update failed. Please try again.';
$statement['log'] = $statement_string.": Err Failed to update ID = " .$id ;
+ $statement['insert_id'] = $id;
}
}else{
unset($data['updated_by']);
@@ -70,10 +73,12 @@ class NotificationModel extends Model
$statement['success'] = $statement_string.' has been Inserted successfully.';
$statement['error'] = "";
$statement['log'] = $statement_string.": has been added successfully. Inserted ID = " .$insertID ;
+ $statement['insert_id'] = $insertID;
} else {
$statement['success'] = "";
$statement['error'] = $statement_string." could not be added. Please try again..";
$statement['log'] = $statement_string.": Err could not be added. Please try again.";
+ $statement['insert_id'] = "";
}
}
return $statement;
@@ -157,7 +162,7 @@ public function customerGroupQueryExecution($queries){
{
$db = \Config\Database::connect();
- $query = "SELECT * FROM customer_groups WHERE group_name = 'EXPIRYDATE'";
+ $query = "SELECT * FROM customer_groups WHERE group_name = 'EXPIRYDATE' AND isactive = 1";
$result = $db->query($query)->getResultArray();
diff --git a/app/Views/campaign_creation.php b/app/Views/campaign_creation.php
index ed2f1937..af8b6a8b 100755
--- a/app/Views/campaign_creation.php
+++ b/app/Views/campaign_creation.php
@@ -34,7 +34,7 @@