FIX_Notification
This commit is contained in:
parent
c73b186e71
commit
c0010f229b
24
.env
24
.env
@ -147,18 +147,32 @@ APP_TIMEZONE = 'Asia/Kolkata'
|
||||
# Whatsapp Access Token And Instance ID
|
||||
#--------------------------------------------------------------------
|
||||
# for Live Don't delete it
|
||||
WAAI_TOKEN = '6582950cb468b'
|
||||
WAAI_INSTANCE = '6582F04394D59'
|
||||
# 1st Account
|
||||
# WAAI_TOKEN = '6582950cb468b'
|
||||
# WAAI_INSTANCE = '6582F04394D59'
|
||||
# 2nd Account
|
||||
# WAAI_TOKEN = '6568739969f28'
|
||||
# WAAI_INSTANCE = '656876690A9FD'
|
||||
|
||||
# Dummy Account by sanjeev created on 14th dec Testing purpose office mail ID (user name - Venba V1 - Krish12345)
|
||||
|
||||
# for Testing Purpose
|
||||
# 4th Account - Dummy Account by sanjeev created on 10th april 24 Testing purpose
|
||||
# Dummy Office Mail ID - venba.it.chennai@venbainfotech.com
|
||||
# (UN - venba.it.chennai PWD - venba.it.chennai)
|
||||
WAAI_INSTANCE = '661621B29BDEE'
|
||||
WAAI_TOKEN = '66162101e2f1d'
|
||||
|
||||
# 3rd Account - Dummy Account by sanjeev created on 14th dec Testing purpose
|
||||
# Office Mail ID - sanjeev.p@venbainfotech.com
|
||||
# (UN - Venba V1 PWD - Krish12345)
|
||||
# WAAI_TOKEN = '657af9bf8cad1'
|
||||
# WAAI_INSTANCE = '657AFA5A01B21'
|
||||
|
||||
# for Test by sanjeev already created
|
||||
# 2nd Account - Dummy Account by sanjeev
|
||||
# WAAI_TOKEN = '65685e954bcf6'
|
||||
# WAAI_INSTANCE = '656863C54F90C'
|
||||
|
||||
# for Old Test by krishanan sir
|
||||
# 1st Account - Dummy Account by krishanan sir
|
||||
# WAAI_TOKEN = '652548474f4e4'
|
||||
# WAAI_INSTANCE = '65254894E4A88'
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ class Notifications extends BaseController
|
||||
# Custom Notification
|
||||
################################################################
|
||||
public function custom_notifications(){
|
||||
$data['page_name'] = 'Custom Notifications';
|
||||
if ($this->request->is('post')) {
|
||||
session()->setFlashdata('reset', true);
|
||||
$records = $this->request->getVar();
|
||||
@ -42,7 +43,7 @@ class Notifications extends BaseController
|
||||
'message' => $records['description'],
|
||||
'result'=>strtolower(gettype($history_msg)) == "string" ? $history_msg : json_encode($history_msg)];
|
||||
$history_child_id = $NotificationModel->save_notification_history_child($history_child_data);
|
||||
$this->logger->info('Custom Notifications Email : historychildid = '.$history_child_id);
|
||||
$this->logger->error('Custom Notifications Email : historychildid = '.$history_child_id);
|
||||
|
||||
}else{
|
||||
$records = $this->request->getVar();
|
||||
@ -52,133 +53,173 @@ class Notifications extends BaseController
|
||||
$receiving_status = 0;
|
||||
$doc_path = APPPATH . '../public/uploads/';
|
||||
$doc_name = '';
|
||||
$this->logger->info("Whatsapp : sending message instance id = " . $_ENV['WAAI_INSTANCE'] . " - " . $_ENV['WAAI_TOKEN']);
|
||||
$errorMessages = [];
|
||||
$this->logger->error("Whatsapp : sending message instance id = " . $_ENV['WAAI_INSTANCE'] . " - " . $_ENV['WAAI_TOKEN']);
|
||||
if($records['mobile'] != ""){
|
||||
$string = $records['mobile'];
|
||||
$mobile_no_arr = explode(',', $string);
|
||||
$total_number_count = count($mobile_no_arr);
|
||||
$sended_number_count = 0;
|
||||
$not_sended_number_count = 0;
|
||||
if ($records['type'] == 'document') {
|
||||
$doc_name = $doc_details->getName();
|
||||
if($doc_name !== '' && $doc_details->isValid()) {
|
||||
$doc_details->move($doc_path, $doc_name);
|
||||
$this->logger->info("Name After Upload".$doc_name);
|
||||
// Step 1 Categories Check
|
||||
if ($records['categories'] == 'SEND_WAAI_GROUP_URL') {
|
||||
if ($records['group_id'] != "") {
|
||||
$params->group_id = $records['group_id'];
|
||||
} else {
|
||||
session()->setFlashdata('error', 'Group Id Missing Please Try again..');
|
||||
$this->render_page('notifications_form', $data);
|
||||
return;
|
||||
}
|
||||
}else if ($records['categories'] == 'SEND_WAAI_URL') {
|
||||
if ($records['mobile'] == "") {
|
||||
session()->setFlashdata('error', 'Mobile Number Missing Please Try again..');
|
||||
$this->render_page('notifications_form', $data);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('error', 'Please Choose your Category..');
|
||||
$this->render_page('notifications_form', $data);
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 2 Media Check, Document Also Convert into Media Here.
|
||||
if ($records['type'] == 'media') {
|
||||
if ($records['media_url'] != "") {
|
||||
$params->media_url = $records['media_url'];
|
||||
$params->type = "media";
|
||||
} else {
|
||||
session()->setFlashdata('error', 'Media Url Missing Please Try again..');
|
||||
$this->render_page('notifications_form', $data);
|
||||
return;
|
||||
}
|
||||
}else if ($records['type'] == 'document') {
|
||||
if (isset($records['media_doc'])) {
|
||||
if ($doc_details->isValid() && $doc_details->getClientMimeType() === 'image/jpeg') {
|
||||
$doc_name = $doc_details->getName();
|
||||
if ($doc_name !== '') {
|
||||
$doc_details->move($doc_path, $doc_name);
|
||||
$params->media_url = base_url().'public/uploads/'.$doc_name;
|
||||
$params->type = "media";
|
||||
$this->logger->error("Name After Upload: " . $doc_name);
|
||||
}
|
||||
else{
|
||||
$this->logger->error("Err on upload name not Founded ".$records['media_doc']);
|
||||
session()->setFlashdata('error', 'Media Document Missing Please Try again..');
|
||||
$this->render_page('notifications_form', $data);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('error', 'Please upload a JPEG image.');
|
||||
$this->render_page('notifications_form', $data);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
session()->setFlashdata('error', 'Please upload a JPEG image.');
|
||||
$this->render_page('notifications_form', $data);
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
$params->type = "text" ;
|
||||
}
|
||||
|
||||
$NotificationModel = new NotificationModel();
|
||||
$history_parents_data = ['campaign_id' => 0,'status' => 0];
|
||||
$history_parents_data = ['campaign_id' => 0,'status' => 0,'field_value' =>$records['mobile']];
|
||||
$history_parent_id = $NotificationModel->save_notification_history_parents($history_parents_data);
|
||||
// print_r($mobile_no_arr);
|
||||
if(!empty($mobile_no_arr)){
|
||||
try {
|
||||
foreach ($mobile_no_arr as $mobile) {
|
||||
foreach ($mobile_no_arr as $mobile) {
|
||||
// try {
|
||||
$exceptionOccurred = false;
|
||||
// echo "----$mobile";
|
||||
if (trim(strlen($mobile)) == 10) {
|
||||
if (ctype_digit($mobile)) {
|
||||
// ------------ Step 1
|
||||
if ($records['categories'] == 'SEND_WAAI_GROUP_URL') {
|
||||
if ($records['group_id'] != "") {
|
||||
$params->group_id = $records['group_id'];
|
||||
} else {
|
||||
throw new \Exception("Group Id Missing Please Try again..");
|
||||
}
|
||||
} else if ($records['categories'] == 'SEND_WAAI_URL') {
|
||||
if ($records['mobile'] != "") {
|
||||
if ($mobile != "") {
|
||||
$params->number = (int)'91' . $mobile;
|
||||
|
||||
} else {
|
||||
throw new \Exception("Mobile Number Missing Please Try again..");
|
||||
}
|
||||
$url = constant($records['categories']);
|
||||
$params->instance_id = $_ENV['WAAI_INSTANCE'];
|
||||
$params->access_token = $_ENV['WAAI_TOKEN'];
|
||||
$params->message = strip_tags(ltrim($records['description']));
|
||||
$this->logger->error("Whatsapp : Request Type ==> Mobile Number = ".$mobile." - " . gettype($params));
|
||||
helper('notification');
|
||||
$notification = new NotificationHelper();
|
||||
$success = $notification->sendWhatsAppMessage($url, "POST", $params);
|
||||
// echo "<pre>";print_r($success);echo "</pre>";
|
||||
$receiving_status = $success['receiving_status'];
|
||||
$parents_status = $success['receiving_status'];
|
||||
$this->logger->error("Whatsapp : Reponse ==> Mobile Number = ".$mobile." Waai Reponse = ". json_encode($success['reponse']));
|
||||
$history_msg = strtolower(gettype($success)) == "string" ? $success : json_encode($success['reponse']);
|
||||
// $tag = (int)$receiving_status === 1 ? 'success' : 'error' ;
|
||||
// session()->setFlashdata($tag, 'Message : ' . $success['message']);
|
||||
(int)$receiving_status === 1 ? $sended_number_count++ : $not_sended_number_count++;
|
||||
} else {
|
||||
throw new \Exception("Please Choose your Category");
|
||||
$receiving_status = 0;
|
||||
$parents_status = 0;
|
||||
$history_msg = "Mobile Number = ".$mobile." is invalid.";
|
||||
$this->logger->error("Whatsapp : Reponse ==> ".$history_msg);
|
||||
$not_sended_number_count++;
|
||||
$errorMessages[] = $history_msg;
|
||||
}
|
||||
// echo "***".$params->number;
|
||||
//---------Step 2
|
||||
if ($records['type'] == 'media') {
|
||||
if ($records['media_url'] != "") {
|
||||
$params->media_url = $records['media_url'];
|
||||
$params->type = "media";
|
||||
} else {
|
||||
throw new \Exception("Media Url Missing Please Try again..");
|
||||
}
|
||||
}else if ($records['type'] == 'document') {
|
||||
$doc_name = $doc_details->getName();
|
||||
if($doc_name == ''){
|
||||
$this->logger->error("Err on upload name not Founded ".$records['media_doc']);
|
||||
throw new \Exception("Media Document Missing Please Try again..");
|
||||
}else{
|
||||
$params->media_url = base_url().'public/uploads/'.$doc_name;
|
||||
$params->type = "media";
|
||||
}
|
||||
}else{
|
||||
$params->type = "text" ;
|
||||
}
|
||||
$url = constant($records['categories']);
|
||||
$params->instance_id = $_ENV['WAAI_INSTANCE'];
|
||||
$params->access_token = $_ENV['WAAI_TOKEN'];
|
||||
$params->message = strip_tags(ltrim($records['description']));
|
||||
$this->logger->info("Whatsapp : sending message request = " . json_encode($params));
|
||||
$this->logger->info("Whatsapp : sending message request type b4 = " . gettype($params));
|
||||
|
||||
helper('notification');
|
||||
$notification = new NotificationHelper();
|
||||
$success = $notification->sendWhatsAppMessage($url, "POST", $params);
|
||||
// echo "<pre>";print_r($success);echo "</pre>";
|
||||
$receiving_status = $success['receiving_status'];
|
||||
$parents_status = $success['receiving_status'];
|
||||
$this->logger->info("Whatsapp : Reponse ==> Mobile Number = ".$mobile." Message = ". json_encode($success['reponse']));
|
||||
$history_msg = strtolower(gettype($success)) == "string" ? $success : json_encode($success['reponse']);
|
||||
// $tag = (int)$receiving_status === 1 ? 'success' : 'error' ;
|
||||
// session()->setFlashdata($tag, 'Message : ' . $success['message']);
|
||||
$this->logger->info("Whatsapp : Reponse = " . $success['message']);
|
||||
(int)$receiving_status === 1 ? $sended_number_count++ : $not_sended_number_count++;
|
||||
}elseif (ctype_alpha($mobile)) {
|
||||
$receiving_status = 0;
|
||||
$parents_status = 0;
|
||||
$history_msg = "Mobile Number = ".$mobile." is a character.";
|
||||
$this->logger->info("Whatsapp : Reponse ==> ".$history_msg);
|
||||
$this->logger->error("Whatsapp : Reponse ==> ".$history_msg);
|
||||
$not_sended_number_count++;
|
||||
throw new \Exception($history_msg);
|
||||
$errorMessages[] = $history_msg;
|
||||
|
||||
}else {
|
||||
$receiving_status = 0;
|
||||
$parents_status = 0;
|
||||
$history_msg = "Mobile Number = ".$mobile." is a combination of characters and numbers.";
|
||||
$this->logger->info("Whatsapp : Reponse ==> ".$history_msg);
|
||||
$this->logger->error("Whatsapp : Reponse ==> ".$history_msg);
|
||||
$not_sended_number_count++;
|
||||
throw new \Exception($history_msg);
|
||||
$errorMessages[] = $history_msg;
|
||||
|
||||
}
|
||||
}else {
|
||||
$history_msg = "Mobile Number = ".$mobile." does not have 10 digits.";
|
||||
$this->logger->info("Whatsapp : Reponse ==> ".$history_msg);
|
||||
$this->logger->error("Whatsapp : Reponse ==> ".$history_msg);
|
||||
$not_sended_number_count++;
|
||||
throw new \Exception($history_msg);
|
||||
$errorMessages[] = $history_msg;
|
||||
}
|
||||
$NotificationModel = new NotificationModel();
|
||||
$history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,0);
|
||||
$this->logger->info($history_parent_statement);
|
||||
$history_child_data = [ 'fkid' => $history_parent_id,
|
||||
'customer_id' => 0,
|
||||
'receiving_entity' => $mobile." (original : ".$records['mobile'].")",
|
||||
'receiving_entity' => $mobile,
|
||||
'receiving_status' => $receiving_status,
|
||||
'message' => $records['description'],
|
||||
'result'=>$history_msg];
|
||||
$history_child_id = $NotificationModel->save_notification_history_child($history_child_data);
|
||||
$this->logger->info('Custom Notifications Whatsapp : historychildid = '.$history_child_id);
|
||||
}
|
||||
session()->setFlashdata("success","Message : Sent Success (". $sended_number_count." / ".$total_number_count." )");
|
||||
$this->logger->info("Whatsapp : Final ==> ".$sended_number_count." Sended out of ".$total_number_count." ( Not sended numbers count ".$not_sended_number_count." ) ");
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Whatsapp : Exception Message = " . $e->getMessage() . "<br> File: " . $e->getFile() . "<br> Line: " . $e->getLine() . "<br>");
|
||||
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
|
||||
$NotificationModel = new NotificationModel();
|
||||
$history_child_id = $NotificationModel->save_custom_notification_history_child($history_child_data);
|
||||
$this->logger->error('Custom Notifications Whatsapp : historychildid = '.$history_child_id);
|
||||
}
|
||||
if (!empty($errorMessages)) {
|
||||
$this->logger->error(implode("\n", $errorMessages));
|
||||
session()->setFlashdata('error', implode('<br>', $errorMessages));
|
||||
$errorMessages = [];
|
||||
}
|
||||
if($sended_number_count > 0){
|
||||
$NotificationModel = new NotificationModel();
|
||||
$history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,0);
|
||||
$this->logger->error($history_parent_statement);
|
||||
session()->setFlashdata("success","Message : Sent Success (". $sended_number_count." / ".$total_number_count." )");
|
||||
$this->logger->error("Whatsapp : Final ==> ".$sended_number_count." Sended out of ".$total_number_count." ( Not sended numbers count ".$not_sended_number_count." ) ");
|
||||
}
|
||||
$this->render_page('notifications_form', $data);
|
||||
return;
|
||||
}else{
|
||||
session()->setFlashdata('error', 'Message : Mobile Not Founded');
|
||||
$this->logger->error('Message : Mobile Not Founded');
|
||||
$this->render_page('notifications_form', $data);
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
session()->setFlashdata('error', 'Message : Mobile Field Empty');
|
||||
$this->logger->error('Message : Mobile Field Empty');
|
||||
$this->render_page('notifications_form', $data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$records = [];
|
||||
$data['page_name'] = 'Custom Notifications';
|
||||
$this->render_page('notifications_form', $data);
|
||||
}
|
||||
|
||||
@ -200,7 +241,7 @@ class Notifications extends BaseController
|
||||
$business_name = "";
|
||||
$to_subscription = "";
|
||||
if (isset($details)) {
|
||||
$this->logger->info("Notification : Duedate notification Request data type = " . gettype($details));
|
||||
$this->logger->error("Notification : Duedate notification Request data type = " . gettype($details));
|
||||
}
|
||||
helper('notification');
|
||||
$notification = new NotificationHelper();
|
||||
@ -239,13 +280,13 @@ class Notifications extends BaseController
|
||||
$params->message = $template;
|
||||
$params->instance_id = $_ENV['WAAI_INSTANCE'];
|
||||
$params->access_token = $_ENV['WAAI_TOKEN'];
|
||||
$this->logger->info("Notification : Duedate notification Email Request data = " . json_encode($records));
|
||||
$this->logger->error("Notification : Duedate notification Email Request data = " . json_encode($records));
|
||||
|
||||
$email_result = $notification->sendEmail($records);
|
||||
$this->logger->info("Notification : Duedate notification Email Response = " . json_encode($email_result));
|
||||
$this->logger->info("Notification : Duedate notification Whatsapp Request data = " . json_encode($params));
|
||||
$this->logger->error("Notification : Duedate notification Email Response = " . json_encode($email_result));
|
||||
$this->logger->error("Notification : Duedate notification Whatsapp Request data = " . json_encode($params));
|
||||
$whatsapp_result = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params);
|
||||
$this->logger->info("Notification : Duedate notification Whatsapp Response = " . json_encode($whatsapp_result));
|
||||
$this->logger->error("Notification : Duedate notification Whatsapp Response = " . json_encode($whatsapp_result));
|
||||
}
|
||||
|
||||
public function template_creation()
|
||||
@ -266,11 +307,11 @@ class Notifications extends BaseController
|
||||
$data['group_details'] = $this->get_group_details();
|
||||
$model = new NotificationModel();
|
||||
if ($id === '0') {
|
||||
$this->logger->info("Template Creation: In Add Page");
|
||||
$this->logger->error("Template Creation: In Add Page");
|
||||
$data['page_name'] = 'Add Template';
|
||||
$data['template_details'] = [];
|
||||
} elseif ($id !== '0') {
|
||||
$this->logger->info("Template Creation: In Edit Page ID =" . $id);
|
||||
$this->logger->error("Template Creation: In Edit Page ID =" . $id);
|
||||
$data['page_name'] = 'Edit Template';
|
||||
$model->setTable('templates');
|
||||
$where = ['template_id' => (int)$id];
|
||||
@ -294,12 +335,12 @@ class Notifications extends BaseController
|
||||
$where = ['template_id' => (int)$id];
|
||||
$result = $model->where($where)->findAll();
|
||||
if ($result) {
|
||||
$this->logger->Info("Template: Going to Inactive ID = " . $id);
|
||||
$this->logger->error("Template: Going to Inactive ID = " . $id);
|
||||
$data = ['isactive' => 0, 'updated_by' => $session_uid, 'template_id' => (int)$id];
|
||||
$statement = $model->saveDetails($data, 'template_id', 'templates'); // just updating Inactive status only.
|
||||
if ($statement['success']) {
|
||||
session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : "");
|
||||
$this->logger->info($statement['log']);
|
||||
$this->logger->error($statement['log']);
|
||||
} else if ($statement['error']) {
|
||||
session()->setFlashdata('error', $statement['error']);
|
||||
$this->logger->error($statement['log']);
|
||||
@ -338,7 +379,7 @@ class Notifications extends BaseController
|
||||
|
||||
public function template_creation_insert()
|
||||
{
|
||||
$this->logger->info("Template: Inserting/Updating Details");
|
||||
$this->logger->error("Template: Inserting/Updating Details");
|
||||
try {
|
||||
## Declarions
|
||||
helper('session');
|
||||
@ -367,7 +408,7 @@ class Notifications extends BaseController
|
||||
$statement = $model->saveDetails($data, 'template_id', 'templates');
|
||||
if ($statement['success']) {
|
||||
session()->setFlashdata('success', $statement['success']);
|
||||
$this->logger->info($statement['log']);
|
||||
$this->logger->error($statement['log']);
|
||||
} else if ($statement['error']) {
|
||||
session()->setFlashdata('error', $statement['error']);
|
||||
$this->logger->error($statement['log']);
|
||||
@ -397,11 +438,11 @@ class Notifications extends BaseController
|
||||
$data['template_details'] = $this->get_template_details();
|
||||
$model = new NotificationModel();
|
||||
if ($id === '0') {
|
||||
$this->logger->info("Campaign Creation: In Add Page");
|
||||
$this->logger->error("Campaign Creation: In Add Page");
|
||||
$data['page_name'] = 'Add Campaign';
|
||||
$data['campaign_details'] = [];
|
||||
} elseif ($id !== '0') {
|
||||
$this->logger->info("Campaign Creation: In Edit Page ID =" . $id);
|
||||
$this->logger->error("Campaign Creation: In Edit Page ID =" . $id);
|
||||
$data['page_name'] = 'Edit Campaign';
|
||||
$model->setTable('notification_campaign');
|
||||
$where = ['campaign_id' => (int)$id];
|
||||
@ -426,12 +467,12 @@ class Notifications extends BaseController
|
||||
$where = ['campaign_id' => (int)$id];
|
||||
$result = $model->where($where)->findAll();
|
||||
if ($result) {
|
||||
$this->logger->Info("Campaign: Going to Inactive ID = " . $id);
|
||||
$this->logger->error("Campaign: Going to Inactive ID = " . $id);
|
||||
$data = ['isactive' => 0, 'updated_by' => $session_uid, 'campaign_id' => (int)$id];
|
||||
$statement = $model->saveDetails($data, 'campaign_id', 'notification_campaign'); // just updating Inactive status only.
|
||||
if ($statement['success']) {
|
||||
session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : "");
|
||||
$this->logger->info($statement['log']);
|
||||
$this->logger->error($statement['log']);
|
||||
} else if ($statement['error']) {
|
||||
session()->setFlashdata('error', $statement['error']);
|
||||
$this->logger->error($statement['log']);
|
||||
@ -448,7 +489,7 @@ class Notifications extends BaseController
|
||||
|
||||
public function campaign_creation_insert()
|
||||
{
|
||||
$this->logger->info("Campaign: Inserting/Updating Details");
|
||||
$this->logger->error("Campaign: Inserting/Updating Details");
|
||||
try {
|
||||
## Declarions
|
||||
helper('session');
|
||||
@ -487,7 +528,7 @@ class Notifications extends BaseController
|
||||
}
|
||||
if ($statement['success']) {
|
||||
session()->setFlashdata('success', $statement['success']);
|
||||
$this->logger->info($statement['log']);
|
||||
$this->logger->error($statement['log']);
|
||||
} else if ($statement['error']) {
|
||||
session()->setFlashdata('error', $statement['error']);
|
||||
$this->logger->error($statement['log']);
|
||||
@ -510,14 +551,14 @@ class Notifications extends BaseController
|
||||
# Step 1: add the days to retrive the data//
|
||||
$providedDate = date('Y-m-d');
|
||||
$newDate = date('Y-m-d', strtotime($providedDate . ' + ' . $window_time . ' days'));
|
||||
$this->logger->info('EXPIRYDATE T-Date = '.$providedDate.', Given ' .$window_time.' Day, Calacuated Date based on Given day count = '.$newDate);
|
||||
$this->logger->error('EXPIRYDATE T-Date = '.$providedDate.', Given ' .$window_time.' Day, Calacuated Date based on Given day count = '.$newDate);
|
||||
|
||||
# Step 2 :Get the customer detail//
|
||||
$NotificationModel = new NotificationModel();
|
||||
$ExpCustomerDetail = $NotificationModel->getExpDate(); // Retrieve the stored query
|
||||
|
||||
if (empty($ExpCustomerDetail)) {
|
||||
$this->logger->info('No customer group found by the name of EXPIRYDATE');
|
||||
$this->logger->error('No customer group found by the name of EXPIRYDATE');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -525,7 +566,7 @@ class Notifications extends BaseController
|
||||
$modifiedQuery = str_replace('WINDOW_TIME', $window_time, $ExpCustomerDetail);
|
||||
// print_r($modifiedQuery);die;
|
||||
if (empty($modifiedQuery)) {
|
||||
$this->logger->info('There is no sub query');
|
||||
$this->logger->error('There is no sub query');
|
||||
return;
|
||||
}
|
||||
$db = \Config\Database::connect();
|
||||
@ -533,7 +574,7 @@ class Notifications extends BaseController
|
||||
|
||||
$notification = new NotificationHelper();
|
||||
if (empty($queryResult)) {
|
||||
$this->logger->info("There is no customer expiring on date:{$newDate}");
|
||||
$this->logger->error("There is no customer expiring on date:{$newDate}");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -549,7 +590,7 @@ class Notifications extends BaseController
|
||||
$expirydate = $row['to_subscription'];
|
||||
$customerId = $row['customer_id'];
|
||||
if (empty($fullName)) {
|
||||
$this->logger->info('There is no subcription Name');
|
||||
$this->logger->error('There is no subcription Name');
|
||||
continue;
|
||||
}
|
||||
if ($status === 'Approved') {
|
||||
@ -584,40 +625,40 @@ class Notifications extends BaseController
|
||||
# Step 6:Send email using NotificationHelper
|
||||
$emailResult = $notification->sendEmail($emailData);
|
||||
|
||||
$this->logger->info("EXPIRAY NOTIFY TEMPLATE EMAIL Email CID = ".$customerId." ".json_encode($emailResult));
|
||||
$this->logger->error("EXPIRAY NOTIFY TEMPLATE EMAIL Email CID = ".$customerId." ".json_encode($emailResult));
|
||||
|
||||
if (isset($emailResult['success'])) {
|
||||
$history_msg = 'Email sent successfully';
|
||||
$history_child_updatedata = ['receiving_status'=>1,'result'=>$history_msg];
|
||||
$history_child_where = ['fkid' => $history_parent_id,'id' => (int)$history_child_id];
|
||||
$history_child_statement = $NotificationModel->update_notification_history_child($history_child_updatedata,$history_child_where);
|
||||
$this->logger->info($history_child_statement);
|
||||
$this->logger->error($history_child_statement);
|
||||
|
||||
$history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,$campaign_id);
|
||||
$this->logger->info($history_parent_statement);
|
||||
$this->logger->error($history_parent_statement);
|
||||
echo ($inx+1).") ".$history_msg."<br>";
|
||||
} else {
|
||||
$history_msg = (strtolower(gettype($emailResult)) == "string" ? $emailResult : json_encode($emailResult)) ;
|
||||
$history_child_updatedata = ['receiving_status'=>0,'result'=>$history_msg];
|
||||
$history_child_where = ['fkid' => $history_parent_id,'id' => (int)$history_child_id];
|
||||
$history_child_statement = $NotificationModel->update_notification_history_child($history_child_updatedata,$history_child_where);
|
||||
$this->logger->info($history_child_statement);
|
||||
$this->logger->error($history_child_statement);
|
||||
|
||||
$history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,$campaign_id);
|
||||
$this->logger->info($history_parent_statement);
|
||||
$this->logger->error($history_parent_statement);
|
||||
echo ($inx+1).") Failed to send email <br>";
|
||||
}
|
||||
} else {
|
||||
$history_msg = 'There is no email template found by the name of EXPIRAY_NOTIFY_TEMPLATE_EMAIL';
|
||||
// $receiving_status = 0 ;
|
||||
$this->logger->info($history_msg);
|
||||
$this->logger->error($history_msg);
|
||||
echo $history_msg."<br>";
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
$this->logger->info("status is Draft");
|
||||
$this->logger->error("status is Draft");
|
||||
}
|
||||
# EXPIRAY_NOTIFY_TEMPLATE_EMAIL Closed
|
||||
if ($status === 'Approved') {
|
||||
@ -633,11 +674,11 @@ class Notifications extends BaseController
|
||||
$history_child_updatedata = ['receiving_status'=>0,'result'=>$history_msg];
|
||||
$history_child_where = ['fkid' => $history_parent_id,'id' => (int)$history_child_id];
|
||||
$history_child_statement = $NotificationModel->update_notification_history_child($history_child_updatedata,$history_child_where);
|
||||
$this->logger->info($history_child_statement);
|
||||
$this->logger->error($history_child_statement);
|
||||
|
||||
$history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,$campaign_id);
|
||||
$this->logger->info($history_parent_statement);
|
||||
$this->logger->info($history_msg);
|
||||
$this->logger->error($history_parent_statement);
|
||||
$this->logger->error($history_msg);
|
||||
echo ($inx+1).") ".$history_msg."<br>";
|
||||
continue;
|
||||
}
|
||||
@ -668,19 +709,19 @@ class Notifications extends BaseController
|
||||
$params->message = strip_tags(ltrim($whatsappContent));
|
||||
$params->instance_id = $_ENV['WAAI_INSTANCE'];
|
||||
$params->access_token = $_ENV['WAAI_TOKEN'];
|
||||
$this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Request = " . json_encode($params));
|
||||
$this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Request type b4 = " . gettype($params));
|
||||
$this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Request = " . json_encode($params));
|
||||
$this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Request type b4 = " . gettype($params));
|
||||
$whatsapp_result = $notification->sendWhatsAppMessage($url, "POST", $params);
|
||||
$receiving_status = $whatsapp_result['receiving_status'];
|
||||
$history_msg = strtolower(gettype($whatsapp_result)) == "string" ? $whatsapp_result : json_encode($whatsapp_result['reponse']);
|
||||
$history_child_updatedata = ['receiving_status'=>$receiving_status,'result'=>$history_msg];
|
||||
$history_child_where = ['fkid' => $history_parent_id,'id' => (int)$history_child_id];
|
||||
$history_child_statement = $NotificationModel->update_notification_history_child($history_child_updatedata,$history_child_where);
|
||||
$this->logger->info($history_child_statement);
|
||||
$this->logger->error($history_child_statement);
|
||||
|
||||
$history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,$campaign_id);
|
||||
$this->logger->info($history_parent_statement);
|
||||
$this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Reponse = " . $history_msg);
|
||||
$this->logger->error($history_parent_statement);
|
||||
$this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Reponse = " . $history_msg);
|
||||
|
||||
if(strtolower(gettype($whatsapp_result)) == "string"){
|
||||
echo ($inx+1).") ".$whatsapp_result."<br>";
|
||||
@ -690,18 +731,18 @@ class Notifications extends BaseController
|
||||
$decodedResult = json_decode($result, true);
|
||||
if ($decodedResult && isset($decodedResult['message']['key']['remoteJid'])) {
|
||||
$remoteJid = $decodedResult['message']['key']['remoteJid'];
|
||||
$this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Remote Jid = " . $remoteJid);
|
||||
$this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Remote Jid = " . $remoteJid);
|
||||
echo ($inx+1).") Whatsapp sent successfully <br>";
|
||||
} else {
|
||||
// echo "Failed to extract remoteJid";
|
||||
$this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Failed to extract remoteJid ");
|
||||
$this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Failed to extract remoteJid ");
|
||||
echo ($inx+1).") Failed to send Whatsapp <br>";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// $receiving_status = 0;
|
||||
$history_msg = 'There is no Whatsapp template found by the name of EXPIRAY NOTIFY TEMPLATE WHATSAPP ';
|
||||
$this->logger->info($history_msg);
|
||||
$this->logger->error($history_msg);
|
||||
echo "There is no Whatsapp template <br>";
|
||||
continue;
|
||||
}
|
||||
@ -709,7 +750,7 @@ class Notifications extends BaseController
|
||||
# EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP Closed
|
||||
}
|
||||
else{
|
||||
$this->logger->info("statsu is draft");
|
||||
$this->logger->error("statsu is draft");
|
||||
}
|
||||
|
||||
# Loop Closed
|
||||
@ -723,15 +764,15 @@ class Notifications extends BaseController
|
||||
################################################################
|
||||
## notification campaign details
|
||||
public function processScheduledNotifications(){
|
||||
$this->logger->info("Auto Scheduled Notification Started");
|
||||
$this->logger->error("Auto Scheduled Notification Started");
|
||||
$model = new NotificationModel();
|
||||
#step 1 get scheduled notification details
|
||||
$notification_campaign_result = $this->getScheduledNotificationDetails();
|
||||
$this->logger->info("Auto Scheduled Campaign Details Count = ".count($notification_campaign_result));
|
||||
$this->logger->error("Auto Scheduled Campaign Details Count = ".count($notification_campaign_result));
|
||||
if(!count($notification_campaign_result))
|
||||
{
|
||||
$this->logger->info("No Auto Scheduled Notification in DB,exiting...!");
|
||||
$this->logger->info("Auto Scheduled Notification Ends");
|
||||
$this->logger->error("No Auto Scheduled Notification in DB,exiting...!");
|
||||
$this->logger->error("Auto Scheduled Notification Ends");
|
||||
echo "No Scheduled Data Founded"."<br>";
|
||||
exit();
|
||||
}
|
||||
@ -744,7 +785,7 @@ class Notifications extends BaseController
|
||||
echo "Notification Campaign Name = ".$single_campaign['campaign_name']."<br>";
|
||||
#step 2 get template details
|
||||
$template = $this->getTemplateDetails($single_campaign['template_id']);
|
||||
$this->logger->info("Auto Scheduled Template Details TID = ".$single_campaign['template_id']);
|
||||
$this->logger->error("Auto Scheduled Template Details TID = ".$single_campaign['template_id']);
|
||||
if(count($template))
|
||||
{
|
||||
#step 2.1
|
||||
@ -772,7 +813,7 @@ class Notifications extends BaseController
|
||||
//check wheather if notification send to the current customer already
|
||||
if(!in_array($customer['customer_id'],$sent_customer_details))
|
||||
{
|
||||
$this->logger->info("Auto Scheduled Customer CID = ".$customer['customer_id'].", CN = ".$customer['customer_name']);
|
||||
$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')
|
||||
@ -780,12 +821,12 @@ class Notifications extends BaseController
|
||||
$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->info("Auto Scheduled Email CID = ".$customer['customer_id']." ".$mail_log);
|
||||
$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->info($history_child_statement);
|
||||
$this->logger->error($history_child_statement);
|
||||
|
||||
}
|
||||
else
|
||||
@ -800,12 +841,12 @@ class Notifications extends BaseController
|
||||
$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."<br>";
|
||||
$this->logger->info("Auto Scheduled Whatsapp CID = ".$customer['customer_id']." ".$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->info($history_child_statement);
|
||||
$this->logger->error($history_child_statement);
|
||||
|
||||
}
|
||||
|
||||
@ -818,12 +859,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."<br>";
|
||||
$this->logger->info($statement);
|
||||
$this->logger->error($statement);
|
||||
|
||||
#step 7 update history parent status to 1
|
||||
$history_parent_statement = $model->update_notification_history_parent_status(['status' => 1],$single_campaign['history_parent_id'],$single_campaign['campaign_id']);
|
||||
echo "Final Acknowlegdement = ".$history_parent_statement."<br>";
|
||||
$this->logger->info($history_parent_statement);
|
||||
$this->logger->error($history_parent_statement);
|
||||
|
||||
}
|
||||
|
||||
@ -862,7 +903,7 @@ class Notifications extends BaseController
|
||||
function getCustomerDetails($group_ids)
|
||||
{
|
||||
$group_id_arr = unserialize($group_ids);
|
||||
$this->logger->info("Auto Scheduled Customer Group CGID = ".implode(", ", $group_id_arr));
|
||||
$this->logger->error("Auto Scheduled Customer Group CGID = ".implode(", ", $group_id_arr));
|
||||
$customer_details = [];
|
||||
if(count($group_id_arr))
|
||||
{
|
||||
|
||||
@ -17,7 +17,7 @@ class NotificationHelper
|
||||
|
||||
public function sendEmail($records)
|
||||
{
|
||||
$this->logger->info('Helper : Email Request Data type = '.gettype($records));
|
||||
$this->logger->error('Helper : Email Request Data type = '.gettype($records));
|
||||
|
||||
$cc = isset($records['carboncopy']) ? $records['carboncopy'] : '';
|
||||
$bcc = isset($records['blindcarboncopy']) ? $records['blindcarboncopy'] : '';
|
||||
@ -28,26 +28,26 @@ class NotificationHelper
|
||||
throw new \Exception("Email and Subject are Must Please Try again..");
|
||||
}
|
||||
$this->email->setTo($records['recipient_email']);
|
||||
$this->logger->info('Helper : Email recipient = '.$records['recipient_email']);
|
||||
$this->logger->error('Helper : Email recipient = '.$records['recipient_email']);
|
||||
$this->email->setFrom('web@vijayabharathambooks.com', isset($records['company'])?$records['company']:"VB");
|
||||
$this->email->setSubject($records['subject']);
|
||||
$this->logger->info('Helper : Email subject = '.$records['subject']);
|
||||
$this->logger->error('Helper : Email subject = '.$records['subject']);
|
||||
$this->email->setMessage($records['description']);
|
||||
|
||||
// if($records['template_name'] != ""){
|
||||
// $this->logger->info('Helper : Email Template = '.$records['template_name']);
|
||||
// $this->logger->info("Helper : Email Request data = ".json_encode($records));
|
||||
// $this->logger->error('Helper : Email Template = '.$records['template_name']);
|
||||
// $this->logger->error("Helper : Email Request data = ".json_encode($records));
|
||||
// $emailContent = view($records['template_name'],$records);
|
||||
// $this->email->setMessage($emailContent);
|
||||
// }else{
|
||||
// $this->logger->info('Helper : Email Dynamic Template');
|
||||
// $this->logger->error('Helper : Email Dynamic Template');
|
||||
// $this->email->setMessage($records['description']);
|
||||
// }
|
||||
|
||||
|
||||
if ($cc !== '') {
|
||||
$ccRecipients = explode(',', trim($cc));
|
||||
$this->logger->info('Helper : Email carbon copy CC recipient = ' . implode(',', $ccRecipients));
|
||||
$this->logger->error('Helper : Email carbon copy CC recipient = ' . implode(',', $ccRecipients));
|
||||
if (!empty($ccRecipients)) {
|
||||
if (getenv('CI_ENVIRONMENT') === "production") {
|
||||
$this->email->setCC('contact@vijayabharathambooks.com');
|
||||
@ -62,7 +62,7 @@ class NotificationHelper
|
||||
|
||||
if ($bcc !== '') {
|
||||
$bccRecipients = explode(',', trim($bcc));
|
||||
$this->logger->info('Helper : Email blindcarboncopy BCC recipient = ' . implode(',', $bccRecipients));
|
||||
$this->logger->error('Helper : Email blindcarboncopy BCC recipient = ' . implode(',', $bccRecipients));
|
||||
if(!empty($bccRecipients)) {
|
||||
$this->email->setBCC($bccRecipients);
|
||||
}
|
||||
@ -70,7 +70,7 @@ class NotificationHelper
|
||||
|
||||
if ($this->email->send()) {
|
||||
$message['success'] = 'Email sent successfully';
|
||||
$this->logger->info('Helper : Email Status = sent successfully');
|
||||
$this->logger->error('Helper : Email Status = sent successfully');
|
||||
} else {
|
||||
throw new \Exception('Email sending failed.');
|
||||
}
|
||||
@ -86,18 +86,18 @@ class NotificationHelper
|
||||
$final_result = []; // Initialize outside try-catch block
|
||||
|
||||
try {
|
||||
$this->logger->info('Helper : Whatsapp');
|
||||
$this->logger->error('Helper : Whatsapp called');
|
||||
$curl = curl_init();
|
||||
$headers = array('Content-Type:application/json');
|
||||
$jsonencoded = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
$this->logger->info('Helper : Whatsapp url = ' . $url);
|
||||
$this->logger->error('Helper : Whatsapp url = ' . $url);
|
||||
|
||||
switch ($method) {
|
||||
case "POST":
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
if ($data) {
|
||||
$this->logger->info('Helper : Whatsapp jsonencoded = ' . $jsonencoded);
|
||||
$this->logger->error('Helper : Whatsapp Request in jsonencoded Type = ' . $jsonencoded);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonencoded);
|
||||
}
|
||||
break;
|
||||
@ -114,7 +114,7 @@ class NotificationHelper
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
|
||||
$curl_exec = curl_exec($curl);
|
||||
$this->logger->info('Helper : Whatsapp Reponse = ' . $curl_exec);
|
||||
$this->logger->error('Helper : Whatsapp Reponse = ' . $curl_exec);
|
||||
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($http_status === 200) {
|
||||
|
||||
@ -246,6 +246,12 @@ public function customerGroupQueryExecution($queries){
|
||||
return $insertID;
|
||||
}
|
||||
|
||||
public function save_custom_notification_history_child($data){
|
||||
$this->db->table('notification_history_children')->insert($data);
|
||||
$insertID = $this->db->insertID();
|
||||
return $insertID;
|
||||
}
|
||||
|
||||
public function update_notification_history_child($data, $where){
|
||||
|
||||
$id = isset($where['id']) ? $where['id'] : "";
|
||||
|
||||
@ -159,8 +159,12 @@
|
||||
<div class="form-group row">
|
||||
<label for="media_doc" class="col-3 col-form-label">Document</label>
|
||||
<div class="col-9">
|
||||
<input type="file" id="media_doc" name="media_doc" accept="image/*"/>
|
||||
<div>
|
||||
<input type="file" id="media_doc" name="media_doc" accept="image/jpeg"/>
|
||||
</div>
|
||||
<span class="help-block"><small>Upload JPEG Images Only.</small></span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user