Fixes : ps

This commit is contained in:
VE10-Sanjeev 2023-12-12 19:33:58 +05:30
parent 66f057b1b4
commit a2522630ed
4 changed files with 189 additions and 479 deletions

7
.env
View File

@ -146,8 +146,15 @@ APP_TIMEZONE = 'Asia/Kolkata'
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Whatsapp Access Token And Instance ID # Whatsapp Access Token And Instance ID
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# for Live
WAAI_TOKEN = '6568739969f28' WAAI_TOKEN = '6568739969f28'
WAAI_INSTANCE = '656876690A9FD' WAAI_INSTANCE = '656876690A9FD'
# for Test
# WAAI_TOKEN = '65685e954bcf6'
# WAAI_INSTANCE = '656863C54F90C'
# for Old Test
# WAAI_TOKEN = '652548474f4e4'
# WAAI_INSTANCE = '65254894E4A88'
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Email Host Name,User,Passcode And Port # Email Host Name,User,Passcode And Port

View File

@ -115,17 +115,6 @@ define('order_column', ["invoice_id","wp_api_order_id","invoice_child_id"]);
define('order_child','invoiceitems'); define('order_child','invoiceitems');
define('order_child_column', ["invoice_id","wp_api_line_items_id","customer_id"]); define('order_child_column', ["invoice_id","wp_api_line_items_id","customer_id"]);
// define('WAAI_TOKEN', '652548474f4e4');
// define('WAAI_INSTANCE', '65254894E4A88');
// UAT - for testing Purpose..
// define('WAAI_TOKEN', '65685e954bcf6');
// define('WAAI_INSTANCE', '656863C54F90C');
// LIVE - Vel given.30th Nov.
// define('WAAI_TOKEN', '6568739969f28');
// define('WAAI_INSTANCE', '656876690A9FD');
## GET Constant Based on ENV file Starts... ## GET Constant Based on ENV file Starts...
define('WAAI_TOKEN', getenv('WAAI_TOKEN')); define('WAAI_TOKEN', getenv('WAAI_TOKEN'));
define('WAAI_INSTANCE', getenv('WAAI_INSTANCE')); define('WAAI_INSTANCE', getenv('WAAI_INSTANCE'));

View File

@ -36,20 +36,29 @@ class Notifications extends BaseController
$records = $request->getVar(); $records = $request->getVar();
$params = (object) Null; $params = (object) Null;
$this->logger->info("Whatsapp : sending message instance id = " . $_ENV['WAAI_INSTANCE'] ." - ". $_ENV['WAAI_TOKEN']); $this->logger->info("Whatsapp : sending message instance id = " . $_ENV['WAAI_INSTANCE'] . " - " . $_ENV['WAAI_TOKEN']);
try { try {
if ($records['categories'] == 'SEND_WAAI_GROUP_URL') { if ($records['categories'] == 'SEND_WAAI_GROUP_URL') {
if($records['group_id'] != ""){ $params->group_id = $records['group_id']; } if ($records['group_id'] != "") {
else{ throw new \Exception("Group Id Missing Please Try again.."); } $params->group_id = $records['group_id'];
}else if ($records['categories'] == 'SEND_WAAI_URL') { } else {
if($records['mobile'] != ""){ $params->number = (int)'91' . $records['mobile']; } throw new \Exception("Group Id Missing Please Try again..");
else{ throw new \Exception("Mobile Number Missing Please Try again.."); } }
}else{ } else if ($records['categories'] == 'SEND_WAAI_URL') {
if ($records['mobile'] != "") {
$params->number = (int)'91' . $records['mobile'];
} else {
throw new \Exception("Mobile Number Missing Please Try again..");
}
} else {
throw new \Exception("Please Choose your Category"); throw new \Exception("Please Choose your Category");
} }
if ($records['type'] == 'media') { if ($records['type'] == 'media') {
if($records['media_url'] != ""){ $params->media_url = $records['media_url']; } if ($records['media_url'] != "") {
else{ throw new \Exception("Media Url Missing Please Try again.."); } $params->media_url = $records['media_url'];
} else {
throw new \Exception("Media Url Missing Please Try again..");
}
} }
$url = constant($records['categories']); $url = constant($records['categories']);
@ -76,22 +85,22 @@ class Notifications extends BaseController
public function due_date_notifications() public function due_date_notifications()
{ {
$date = $this->request->getGet('date'); $date = $this->request->getGet('date');
$model = new NotificationModel(); $model = new NotificationModel();
$details = $model->getSubscriptionDueDetail($date); $details = $model->getSubscriptionDueDetail($date);
// echo "<pre>"; // echo "<pre>";
// print_r($details); // print_r($details);
// echo "</pre>"; // echo "</pre>";
// die; // die;
$records = []; $records = [];
$recipient_name = ""; $recipient_name = "";
$recipient_email = ""; $recipient_email = "";
$recipient_mobile = ""; $recipient_mobile = "";
$subscription_name = ""; $subscription_name = "";
$business_name= ""; $business_name = "";
$to_subscription= ""; $to_subscription = "";
if (isset($details)) { if (isset($details)) {
$this->logger->info("Notification : Duedate notification Request data type = ".gettype($details)); $this->logger->info("Notification : Duedate notification Request data type = " . gettype($details));
} }
helper('notification'); helper('notification');
$notification = new NotificationHelper(); $notification = new NotificationHelper();
@ -101,23 +110,22 @@ class Notifications extends BaseController
$recipient_mobile = $rec['customer_mobile']; $recipient_mobile = $rec['customer_mobile'];
// $recipient_email = "sanjeev.p@venbainfotech.com"; // $recipient_email = "sanjeev.p@venbainfotech.com";
// $recipient_mobile = 6369084112; // $recipient_mobile = 6369084112;
$business_name= $rec['business_name']; $business_name = $rec['business_name'];
$subscription_name = $rec['title']; $subscription_name = $rec['title'];
$to_subscription= $rec['to_subscription']; $to_subscription = $rec['to_subscription'];
} }
$records['template_name'] = ''; $records['template_name'] = '';
$records['recipient_name'] = $recipient_name; $records['recipient_name'] = $recipient_name;
$records['recipient_email'] = $recipient_email ? $recipient_email : "sanjeev.p@venbainfotech.com"; $records['recipient_email'] = $recipient_email ? $recipient_email : "sanjeev.p@venbainfotech.com";
$records['subject'] = $business_name ." - Due Date Reminder"; $records['subject'] = $business_name . " - Due Date Reminder";
$records['description'] = "<!DOCTYPE html> $records['description'] = "<!DOCTYPE html>
<html> <html>
<head><title>Due Date Reminder</title></head> <head><title>Due Date Reminder</title></head>
<body> <body>
<p>Hello ".$recipient_name.",</p> <p>Hello " . $recipient_name . ",</p>
<p>This is a reminder that the following subscription is due soon:</p> <p>This is a reminder that the following subscription is due soon:</p>
<p><strong>Subscription Name:</strong>".$subscription_name." </p> <p><strong>Subscription Name:</strong>" . $subscription_name . " </p>
<p><strong>Due Date:</strong> ".$to_subscription."</p> <p><strong>Due Date:</strong> " . $to_subscription . "</p>
<p>Please make sure to complete this subscription on time.</p> <p>Please make sure to complete this subscription on time.</p>
<p>Thank you.</p> <p>Thank you.</p>
</body> </body>
@ -131,17 +139,17 @@ class Notifications extends BaseController
$params->message = $template; $params->message = $template;
$params->instance_id = $_ENV['WAAI_INSTANCE']; $params->instance_id = $_ENV['WAAI_INSTANCE'];
$params->access_token = $_ENV['WAAI_TOKEN']; $params->access_token = $_ENV['WAAI_TOKEN'];
$this->logger->info("Notification : Duedate notification Email Request data = ".json_encode($records)); $this->logger->info("Notification : Duedate notification Email Request data = " . json_encode($records));
$email_result = $notification->sendEmail($records); $email_result = $notification->sendEmail($records);
$this->logger->info("Notification : Duedate notification Email Response = " . json_encode($email_result)); $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->info("Notification : Duedate notification Whatsapp Request data = " . json_encode($params));
$whatsapp_result = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params); $whatsapp_result = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params);
$this->logger->info("Notification : Duedate notification Whatsapp Response = " . json_encode($whatsapp_result)); $this->logger->info("Notification : Duedate notification Whatsapp Response = " . json_encode($whatsapp_result));
} }
public function template_creation(){ public function template_creation()
{
$data['page_name'] = 'Template Details'; $data['page_name'] = 'Template Details';
$model = new NotificationModel(); $model = new NotificationModel();
$data['template'] = $model->getTemplateDetails(); $data['template'] = $model->getTemplateDetails();
@ -149,8 +157,9 @@ class Notifications extends BaseController
// echo "templates";die; // echo "templates";die;
} }
public function template_creation_form($id){ public function template_creation_form($id)
{
$data['group_details'] = $this->get_group_details(); $data['group_details'] = $this->get_group_details();
$model = new NotificationModel(); $model = new NotificationModel();
if ($id === '0') { if ($id === '0') {
@ -161,7 +170,7 @@ class Notifications extends BaseController
$this->logger->info("Template Creation: In Edit Page ID =" . $id); $this->logger->info("Template Creation: In Edit Page ID =" . $id);
$data['page_name'] = 'Edit Template'; $data['page_name'] = 'Edit Template';
$model->setTable('templates'); $model->setTable('templates');
$where = ['template_id'=>(int)$id]; $where = ['template_id' => (int)$id];
$result = $model->where($where)->findAll(); $result = $model->where($where)->findAll();
$data['template_details'] = !empty($result[0]) ? $result[0] : []; $data['template_details'] = !empty($result[0]) ? $result[0] : [];
} }
@ -169,34 +178,34 @@ class Notifications extends BaseController
$this->render_page('template_creation_form', $data); $this->render_page('template_creation_form', $data);
} }
public function template_creation_delete($id){ public function template_creation_delete($id)
{
try { try {
helper('session'); helper('session');
$session_uid = get_logged_user_id(); $session_uid = get_logged_user_id();
$model = new NotificationModel(); $model = new NotificationModel();
$model->setTable('templates'); $model->setTable('templates');
$where = ['template_id'=>(int)$id]; $where = ['template_id' => (int)$id];
$result = $model->where($where)->findAll(); $result = $model->where($where)->findAll();
if ($result) { if ($result) {
$this->logger->Info("Template: Going to Inactive ID = ".$id); $this->logger->Info("Template: Going to Inactive ID = " . $id);
$data = ['isactive' => 0 , 'updated_by' => $session_uid,'template_id'=>(int)$id]; $data = ['isactive' => 0, 'updated_by' => $session_uid, 'template_id' => (int)$id];
$statement = $model->saveDetails($data,'template_id','templates');// just updating Inactive status only. $statement = $model->saveDetails($data, 'template_id', 'templates'); // just updating Inactive status only.
if ($statement['success']) { if ($statement['success']) {
session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : "" ); session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : "");
$this->logger->info($statement['log']); $this->logger->info($statement['log']);
} else if ($statement['error']) { } else if ($statement['error']) {
session()->setFlashdata('error', $statement['error']); session()->setFlashdata('error', $statement['error']);
$this->logger->error($statement['log']); $this->logger->error($statement['log']);
}else{ } else {
throw new \Exception("Template: Err Occur on data the Template Inactive"); throw new \Exception("Template: Err Occur on data the Template Inactive");
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error("Template: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); $this->logger->error("Template: Err Occur = " . $e->getMessage() . " File = " . $e->getFile() . " Line = " . $e->getLine());
session()->setFlashdata('error', 'Message: ' . $e->getMessage()); session()->setFlashdata('error', 'Message: ' . $e->getMessage());
} }
return redirect()->route('template_creation'); return redirect()->route('template_creation');
} }
public function get_group_details() public function get_group_details()
@ -208,51 +217,55 @@ class Notifications extends BaseController
$details = $model->where($where)->orderBy('group_id', 'ASC')->findAll(); $details = $model->where($where)->orderBy('group_id', 'ASC')->findAll();
return $details; return $details;
} }
public function get_template_details(){
public function get_template_details()
{
$model = new NotificationModel(); $model = new NotificationModel();
$model->setTable('templates'); $model->setTable('templates');
$details = $model->where('isactive',1)->orderBy('template_id', 'ASC')->findAll(); $details = $model->where('isactive', 1)->orderBy('template_id', 'ASC')->findAll();
return $details; return $details;
} }
public function template_creation_insert(){ public function template_creation_insert()
{
$this->logger->info("Template: Inserting/Updating Details"); $this->logger->info("Template: Inserting/Updating Details");
try { try {
## Declarions ## Declarions
helper('session'); helper('session');
$model = new NotificationModel(); $model = new NotificationModel();
$session_uid = get_logged_user_id(); $session_uid = get_logged_user_id();
$id = $this->request->getPost('template_id'); $id = $this->request->getPost('template_id');
$subject = $this->request->getPost('subject') ? $this->request->getPost('subject') : NULL; $subject = $this->request->getPost('subject') ? $this->request->getPost('subject') : NULL;
$isactive = $id != "" ? $this->request->getPost('isactive') : 'on'; $isactive = $id != "" ? $this->request->getPost('isactive') : 'on';
$data = [ $data = [
'template_id' => $id, 'template_id' => $id,
'template_name' => $this->request->getPost('templatename'), 'template_name' => $this->request->getPost('templatename'),
'subject' => $subject, 'subject' => $subject,
'message' => $this->request->getPost('templatemessage'), 'message' => $this->request->getPost('templatemessage'),
'mode' => $this->request->getPost('mode'), 'mode' => $this->request->getPost('mode'),
'isactive' => (($isactive == 'on') ? 1 : 0), 'isactive' => (($isactive == 'on') ? 1 : 0),
'created_by' => $session_uid, 'created_by' => $session_uid,
'updated_by' => $session_uid 'updated_by' => $session_uid
]; ];
$statement = $model->saveDetails($data,'template_id','templates'); $statement = $model->saveDetails($data, 'template_id', 'templates');
if ($statement['success']) { if ($statement['success']) {
session()->setFlashdata('success', $statement['success']); session()->setFlashdata('success', $statement['success']);
$this->logger->info($statement['log']); $this->logger->info($statement['log']);
} else if ($statement['error']) { } else if ($statement['error']) {
session()->setFlashdata('error', $statement['error']); session()->setFlashdata('error', $statement['error']);
$this->logger->error($statement['log']); $this->logger->error($statement['log']);
}else{ } else {
throw new \Exception("Template: Err Occur"); throw new \Exception("Template: Err Occur");
} }
}catch(\Exception $e) { } catch (\Exception $e) {
$this->logger->error("Template: Err Occur =".$e->getMessage()); $this->logger->error("Template: Err Occur =" . $e->getMessage());
session()->setFlashdata('error', 'Message: ' .$e->getMessage()); session()->setFlashdata('error', 'Message: ' . $e->getMessage());
} }
return redirect()->route('template_creation'); return redirect()->route('template_creation');
} }
public function campaign_creation(){ public function campaign_creation()
{
$data['page_name'] = 'Campaign Details'; $data['page_name'] = 'Campaign Details';
$model = new NotificationModel(); $model = new NotificationModel();
$data['campaign'] = $model->getCampaignDetails(); $data['campaign'] = $model->getCampaignDetails();
@ -260,8 +273,9 @@ class Notifications extends BaseController
// echo "templates";die; // echo "templates";die;
} }
public function campaign_creation_form($id){ public function campaign_creation_form($id)
{
$data['group_details'] = $this->get_group_details(); $data['group_details'] = $this->get_group_details();
$data['template_details'] = $this->get_template_details(); $data['template_details'] = $this->get_template_details();
$model = new NotificationModel(); $model = new NotificationModel();
@ -273,104 +287,102 @@ class Notifications extends BaseController
$this->logger->info("Campaign Creation: In Edit Page ID =" . $id); $this->logger->info("Campaign Creation: In Edit Page ID =" . $id);
$data['page_name'] = 'Edit Campaign'; $data['page_name'] = 'Edit Campaign';
$model->setTable('notification_campaign'); $model->setTable('notification_campaign');
$where = ['campaign_id'=>(int)$id]; $where = ['campaign_id' => (int)$id];
$result = $model->where($where)->findAll(); $result = $model->where($where)->findAll();
if (!empty($result)) { if (!empty($result)) {
foreach ($result as $i => $item) { foreach ($result as $i => $item) {
$result[$i]['group_id'] = unserialize($item['group_id']); $result[$i]['group_id'] = unserialize($item['group_id']);
} }
} }
$data['campaign_details'] = !empty($result[0]) ? $result[0] : []; $data['campaign_details'] = !empty($result[0]) ? $result[0] : [];
} }
$this->render_page('campaign_creation_form', $data); $this->render_page('campaign_creation_form', $data);
} }
public function campaign_creation_delete($id){ public function campaign_creation_delete($id)
{
try { try {
helper('session'); helper('session');
$session_uid = get_logged_user_id(); $session_uid = get_logged_user_id();
$model = new NotificationModel(); $model = new NotificationModel();
$model->setTable('notification_campaign'); $model->setTable('notification_campaign');
$where = ['campaign_id'=>(int)$id]; $where = ['campaign_id' => (int)$id];
$result = $model->where($where)->findAll(); $result = $model->where($where)->findAll();
if ($result) { if ($result) {
$this->logger->Info("Campaign: Going to Inactive ID = ".$id); $this->logger->Info("Campaign: Going to Inactive ID = " . $id);
$data = ['isactive' => 0 , 'updated_by' => $session_uid,'campaign_id'=>(int)$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. $statement = $model->saveDetails($data, 'campaign_id', 'notification_campaign'); // just updating Inactive status only.
if ($statement['success']) { if ($statement['success']) {
session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : "" ); session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : "");
$this->logger->info($statement['log']); $this->logger->info($statement['log']);
} else if ($statement['error']) { } else if ($statement['error']) {
session()->setFlashdata('error', $statement['error']); session()->setFlashdata('error', $statement['error']);
$this->logger->error($statement['log']); $this->logger->error($statement['log']);
}else{ } else {
throw new \Exception("Campaign: Err Occur on data the Template Inactive"); throw new \Exception("Campaign: Err Occur on data the Template Inactive");
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error("Campaign: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); $this->logger->error("Campaign: Err Occur = " . $e->getMessage() . " File = " . $e->getFile() . " Line = " . $e->getLine());
session()->setFlashdata('error', 'Message: ' . $e->getMessage()); session()->setFlashdata('error', 'Message: ' . $e->getMessage());
} }
return redirect()->route('campaign_creation'); return redirect()->route('campaign_creation');
} }
public function campaign_creation_insert(){ public function campaign_creation_insert()
{
$this->logger->info("Campaign: Inserting/Updating Details"); $this->logger->info("Campaign: Inserting/Updating Details");
try { try {
## Declarions ## Declarions
helper('session'); helper('session');
$model = new NotificationModel(); $model = new NotificationModel();
$session_uid = get_logged_user_id(); $session_uid = get_logged_user_id();
$id = $this->request->getPost('campaign_id'); $id = $this->request->getPost('campaign_id');
$request_data = $this->request->getPost(); $request_data = $this->request->getPost();
$isactive = $id == "" ? 1 : (isset($request_data['isactive']) && $request_data['isactive'] == 'on' ? 1 : 0); $isactive = $id == "" ? 1 : (isset($request_data['isactive']) && $request_data['isactive'] == 'on' ? 1 : 0);
$data = [ $data = [
'campaign_id' => $id, 'campaign_id' => $id,
'campaign_name' => $this->request->getPost('campaign_name'), 'campaign_name' => $this->request->getPost('campaign_name'),
'template_id' => $this->request->getPost('template_id'), 'template_id' => $this->request->getPost('template_id'),
'scheduled_date' => $this->request->getPost('scheduled_date'), 'scheduled_date' => $this->request->getPost('scheduled_date'),
'scheduled_time' => $this->request->getPost('scheduled_time'), 'scheduled_time' => $this->request->getPost('scheduled_time'),
'mode' => $this->request->getPost('mode'), 'mode' => $this->request->getPost('mode'),
'group_id' => serialize($this->request->getPost('group_id')), 'group_id' => serialize($this->request->getPost('group_id')),
'isactive' => $isactive, 'isactive' => $isactive,
'created_by' => $session_uid, 'created_by' => $session_uid,
'updated_by' => $session_uid 'updated_by' => $session_uid
]; ];
if($id != ""){ if ($id != "") {
$notify_mod = new NotificationModel(); $notify_mod = new NotificationModel();
$notify_mod->setTable('notification_campaign'); $notify_mod->setTable('notification_campaign');
$where = ['campaign_id'=>(int)$id]; $where = ['campaign_id' => (int)$id];
$isactive_check = $notify_mod->where($where)->select('isactive')->first(); $isactive_check = $notify_mod->where($where)->select('isactive')->first();
if((int)$isactive_check['isactive'] === 0 && $isactive === 0){ if ((int)$isactive_check['isactive'] === 0 && $isactive === 0) {
$statement['success'] = 'Notification Campaign already In-Active. can`t able to update.'; $statement['success'] = 'Notification Campaign already In-Active. can`t able to update.';
$statement['error'] = ""; $statement['error'] = "";
$statement['log'] = "Notification Campaign: already inactive status.Can`t able to update, Notification Campaign Group ID = " .$id ; $statement['log'] = "Notification Campaign: already inactive status.Can`t able to update, Notification Campaign Group ID = " . $id;
}else{ } else {
$statement = $model->saveDetails($data,'campaign_id','notification_campaign'); $statement = $model->saveDetails($data, 'campaign_id', 'notification_campaign');
}
}else{
$statement = $model->saveDetails($data,'campaign_id','notification_campaign');
}
if ($statement['success']) {
session()->setFlashdata('success', $statement['success']);
$this->logger->info($statement['log']);
} else if ($statement['error']) {
session()->setFlashdata('error', $statement['error']);
$this->logger->error($statement['log']);
}else{
throw new \Exception("Campaign: Err Occur");
} }
} else {
$statement = $model->saveDetails($data, 'campaign_id', 'notification_campaign');
}catch(\Exception $e) { }
$this->logger->error("Campaign: Err Occur =".$e->getMessage()); if ($statement['success']) {
session()->setFlashdata('error', 'Message: ' .$e->getMessage()); session()->setFlashdata('success', $statement['success']);
} $this->logger->info($statement['log']);
return redirect()->route('campaign_creation'); } else if ($statement['error']) {
} session()->setFlashdata('error', $statement['error']);
$this->logger->error($statement['log']);
} else {
throw new \Exception("Campaign: Err Occur");
}
} catch (\Exception $e) {
$this->logger->error("Campaign: Err Occur =" . $e->getMessage());
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
}
return redirect()->route('campaign_creation');
}
public function getExpCustomerDetail($window_time = null) public function getExpCustomerDetail($window_time = null)
{ {
@ -388,13 +400,14 @@ class Notifications extends BaseController
//Step 3: Replace the placeholder WINDOW_TIME with the user-provided value //Step 3: Replace the placeholder WINDOW_TIME with the user-provided value
$modifiedQuery = str_replace('WINDOW_TIME', $window_time, $ExpCustomerDetail); $modifiedQuery = str_replace('WINDOW_TIME', $window_time, $ExpCustomerDetail);
if (empty($modifiedQuery)) { if (empty($modifiedQuery)) {
$this->logger->info('There is no sub query'); $this->logger->info('There is no sub query');
return; return;
} }
$db = \Config\Database::connect(); $db = \Config\Database::connect();
$queryResult = $db->query($modifiedQuery)->getResultArray(); $queryResult = $db->query($modifiedQuery)->getResultArray();
$notification = new NotificationHelper(); $notification = new NotificationHelper();
if (empty($queryResult)) { if (empty($queryResult)) {
$this->logger->info("There is no customer expiring on date:{$newDate}"); $this->logger->info("There is no customer expiring on date:{$newDate}");
@ -413,7 +426,7 @@ class Notifications extends BaseController
} }
$emailTemplateName = $NotificationModel->getTempName(EXPIRAY_NOTIFY_TEMPLATE_EMAIL); $emailTemplateName = $NotificationModel->getTempName(EXPIRAY_NOTIFY_TEMPLATE_EMAIL);
if(!empty($emailTemplateName)){ if (!empty($emailTemplateName)) {
//Step 4: Prepare email content based on the template //Step 4: Prepare email content based on the template
$emailContent = $emailTemplateName[0]['message']; $emailContent = $emailTemplateName[0]['message'];
$emailContent = str_replace("{USER_NAME}", $fullName, $emailContent); $emailContent = str_replace("{USER_NAME}", $fullName, $emailContent);
@ -435,315 +448,39 @@ class Notifications extends BaseController
} else { } else {
echo 'Failed to send email'; echo 'Failed to send email';
} }
}else{ } else {
$this->logger->info('There is no email template found by the name of EXPIRAY_NOTIFY_TEMPLATE_EMAIL'); $this->logger->info('There is no email template found by the name of EXPIRAY_NOTIFY_TEMPLATE_EMAIL');
continue; continue;
}// $emailTemplateName } // $emailTemplateName
$whatsappTemplateName = $NotificationModel->getTempName(EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP); $whatsappTemplateName = $NotificationModel->getTempName(EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP);
if(!empty($whatsappTemplateName)){ if (!empty($whatsappTemplateName)) {
if (empty($userMobileNumber)) { if (empty($userMobileNumber)) {
$this->logger->info('There is no subscriber mobile number'); $this->logger->info('There is no subscriber mobile number');
continue; continue;
} }
//Step 6: Prepare whatsapp content based on the template //Step 6: Prepare whatsapp content based on the template
$whatsappContent = $whatsappTemplateName[0]['message']; $whatsappContent = $whatsappTemplateName[0]['message'];
$whatsappContent = str_replace("{USER_NAME}", $fullName, $emailContent); $whatsappContent = str_replace("{USER_NAME}", $fullName, $emailContent);
$whatsappContent = str_replace("{SCHEME_NAME}", $schemename, $emailContent); $whatsappContent = str_replace("{SCHEME_NAME}", $schemename, $emailContent);
$whatsappContent = str_replace("{EXPIRY_DATE}", $expirydate, $emailContent); $whatsappContent = str_replace("{EXPIRY_DATE}", $expirydate, $emailContent);
// Step 7: Send email using NotificationHelper // Step 7: Send email using NotificationHelper
$params = (object) Null; $params = (object) Null;
$url = SEND_WAAI_URL; $url = SEND_WAAI_URL;
$params->number = (int)'91' . $userMobileNumber; $params->number = (int)'91' . $userMobileNumber;
$params->type = "text"; $params->type = "text";
$params->message = $whatsappContent; $params->message = $whatsappContent;
$params->instance_id = $_ENV['WAAI_INSTANCE']; $params->instance_id = $_ENV['WAAI_INSTANCE'];
$params->access_token = $_ENV['WAAI_TOKEN']; $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 = " . json_encode($params));
$this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Request type b4 = " . gettype($params)); $this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Request type b4 = " . gettype($params));
$whatsapp_result = $notification->sendWhatsAppMessage($url, "POST", $params); $whatsapp_result = $notification->sendWhatsAppMessage($url, "POST", $params);
$this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Reponse = " .$whatsapp_result); $this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Reponse = " . $whatsapp_result);
}else{ } else {
$this->logger->info('There is no Whatsapp template found by the name of EXPIRAY NOTIFY TEMPLATE WHATSAPP '); $this->logger->info('There is no Whatsapp template found by the name of EXPIRAY NOTIFY TEMPLATE WHATSAPP ');
continue; continue;
}// $Whatsapp Template Name } // $Whatsapp Template Name
}// for loop } // for loop
} }
}
public function auto_scheduled_notification()
{
$this->logger->info("Auto Scheduled Notification Started");
$nc_id = "";
$model = new NotificationModel();
$model->setTable('notification_campaign');
$where = ['status'=>0];
$notification_campaign_result = $model->where($where)->findAll();
$today = date('Y-m-d');
$customer_details = array();
$customer_details_template = array();
if (!empty($notification_campaign_result)) {
foreach ($notification_campaign_result as $n => $ncr) {
if($today == $ncr['scheduled_date']){
// echo "<pre>";print_r($ncr);echo "</pre>";die; //working fine.
$nc_id = $ncr['campaign_id'];
$this->logger->info("Step 1 : (Campaign) Scheduled Date = " .$ncr['scheduled_date']."/".$ncr['scheduled_time'].", Today = ".$today );
$customer_details_template = $this->auto_scheduled_template_details($ncr);
}else{
$this->logger->info("Step 1 : (Campaign) Scheduled Date = " .$ncr['scheduled_date'].", Today = ".$today );
}
}
if(!empty($customer_details_template)){
// echo "<pre>";print_r($customer_details_template);echo "</pre>";die;
$customer_details = $this->auto_scheduled_send_message($customer_details_template);
if(!empty($customer_details)){
$this->auto_scheduled_notification_campaign_status($nc_id);
$nc_id = "";
}
}
}else{
$this->logger->info("Step 1 : Campaign details not found ");
$this->logger->info("Auto Scheduled Notification End");
}
}
public function auto_scheduled_template_details($ncr){
$this->logger->info("To Retrieved Template for Auto Scheduled");
$template_id = $ncr['template_id'];
$group_id = $ncr['group_id'];
$nc_mode = $ncr['mode'];
$model = new NotificationModel();
$model->setTable('templates');
$where = ['template_id'=>$template_id];
$template_result = $model->where($where)->findAll();
// echo "<pre>";print_r($template_result);echo "</pre>";die;
$flattened_array = array(); // its have customer Details...
if (!empty($template_result)) {
$group_details = array();
foreach ($template_result as $t => $tr) {
$this->logger->info("Step 2 : (Template) id = ".$tr['template_id']."/".$tr['template_name']." , Template Mode = ".$tr['mode']." NotifyCampian Mode = ".$nc_mode);
$details = $this->auto_scheduled_customer_group_details($tr,$ncr);
// echo "<pre>";print_r($details);echo "</pre>";die;
if(!empty($details)){
foreach ($details as $d => $dr) {
$group_details[] = $dr['group_query_results'];
}
}
if(!empty($group_details)){
foreach ($group_details as $sub_array) {
foreach ($sub_array as $inner_array) {
$flattened_array[] = $inner_array;
}
}
}
// echo "<pre>";print_r($flattened_array);echo "</pre>";die;
// Don't Delete It Duplication Check 07-12-2023
// // Extract customer IDs using array_column
// $customer_ids = array_column($flattened_array, 'customer_id');
// // Find unique customer IDs
// $unique_customer_ids = array_unique($customer_ids);
// // Initialize a new array for unique data
// $unique_data = [];
// // Iterate through the original data and keep only unique entries
// foreach ($flattened_array as $entry) {
// if (in_array($entry['customer_id'], $unique_customer_ids)) {
// $unique_data[] = $entry;
// // Remove the customer ID from the unique array to avoid duplicates
// unset($unique_customer_ids[array_search($entry['customer_id'], $unique_customer_ids)]);
// }
// }
// // Now $uniqueData contains entries with unique customer IDs
// print_r($unique_data);
// echo "<pre>";print_r($flattened_array);echo "</pre>";die;
}
}else{
$this->logger->info("Step 2 : Template Details details not found");
$this->logger->info("Auto Scheduled Notification End");
}
return $flattened_array;
}
public function auto_scheduled_customer_group_details($tr_object,$ncr_object){
$this->logger->info("To Retrieved Customer Group Details for Auto Scheduled");
$group_id = $ncr_object['group_id'];
$nc_mode = $ncr_object['mode'];
$group_arr = unserialize($group_id);
$t_mode = $tr_object['mode'];
$group_details = [];
if (!empty($group_arr)) {
$this->logger->info("Step 3 : (Customer Group) id = ".implode(", ", $group_arr));
$model = new NotificationModel();
$model->setTable('customer_groups');
$group_arr_result = $model->whereIn('group_id', $group_arr)->findAll();
if (!empty($group_arr_result)) {
foreach ($group_arr_result as $g => $gar) {
$group_details[$g]['group_query'] = $gar['group_query'];
$group_details[$g]['group_id'] = $gar['group_id'];
$db = \Config\Database::connect();
$sql = (string)$gar['group_query'];
if($sql){
$query = $db->query($sql);
$results = $query->getResultArray();
foreach ($results as &$row) {
$row['group_id'] = $gar['group_id'];
$row['nc_mode'] = $nc_mode; // mode from notification_campaign Table Cross Check purpose
$row['t_mode'] = $t_mode; // mode from template Table Cross Check purpose
$row['template_message'] = $tr_object['message'];
$row['template_subject'] = $tr_object['subject'];
$row['campaign_id'] = $ncr_object['campaign_id'];
}
$group_details[$g]['group_query_results'] = $results;
$group_details[$g]['group_query_customer_count'] = count($results);
$this->logger->info("Step 3 : Customer Group SQL customer count = ".count($results)." group id = ".$gar['group_id']);
}else{
$this->logger->info("Step 3 : Customer Group SQL not found");
}
}
}else{
$this->logger->info("Step 3 : Customer Group details not found");
}
}else{
$this->logger->info("Step 3 : Customer Group ID not found");
}
return $group_details;
}
public function auto_scheduled_send_message($customer_details){
$this->logger->info("To Send Message on Customer for Auto Scheduled");
$return_statement = array();
if (!empty($customer_details)) {
foreach($customer_details as $c => $cd) {
switch($cd['nc_mode']) {
case "Whatsapp":
$whatsapp = $this->auto_scheduled_whatsapp($cd);
array_push($return_statement, $whatsapp);
break;
case "Email":
$email = $this->auto_scheduled_email($cd);
array_push($return_statement, $email);
break;
default:
$this->logger->error($cd["customer_name"]." Can't able to identity the mode for Auto Scheduled");
array_push($return_statement, $cd["customer_name"]." Can't able to identity the mode for Auto Scheduled");
}
}
}
return $return_statement;
}
public function auto_scheduled_email($cd){
// // $cd["city"]
// // $cd["state"]
// // $cd["invoice_date"]
// // $cd["customer_id"]
// echo $cd["customer_name"];
// // $cd["email"]
// // $cd["mobile_no"]
// // $cd["due_date"]
// // $cd["isactive"]
// // $cd["invoice_count_raised_by_customer"]
// // $cd["scheme_id"]
// // $cd["name"]
// // $cd["group_id"]
// // $cd["nc_mode"]
// // $cd["t_mode"]
// // $cd["template_message"]
// // $cd["campaign_id"]
$this->logger->info("Auto Notification : Email Customer Details = " . json_encode($cd));
if(!empty($cd["template_message"] )){
$emailContent = $cd["template_message"] ;
$emailContent = str_replace("{USER_NAME}", $cd["customer_name"], $emailContent);
$emailContent = str_replace("{SCHEME_NAME}", $cd["name"], $emailContent);
$emailContent = str_replace("{EXPIRY_DATE}", $cd["formatted_due_date"], $emailContent);
$emailData = [
'template_name' => '',
'recipient_email' => $cd["email"],
'subject' => $cd["template_subject"] != "" ? $cd["template_subject"] : ucfirst(str_replace('_', ' ', (string)$cd["name"]))." Notification" ,
'description' => $emailContent,
];
$notification = new NotificationHelper();
// $emailResult = $notification->sendEmail($emailData);
$emailResult = array();
$this->logger->info("Auto Notification : Email Content = " . $emailContent);
$this->logger->info("Auto Notification : Email Response = " . json_encode($emailResult));
if (isset($emailResult['success'])) {
$this->logger->info("Auto Notification : ".$cd["customer_name"]."`s mail sended Mail ID = ".$cd["email"]);
return $cd["customer_name"]." mail sended";
} else {
$this->logger->info("Auto Notification : ".$cd["customer_name"]."`s mail not sended Mail ID = ".$cd["email"]);
return $cd["customer_name"]." mail not sended";
}
}else{
$this->logger->info('There is no email template found');
return $cd["customer_name"]." mail template not found";
}
}
public function auto_scheduled_whatsapp($cd){
if(!empty($cd["template_message"])){
if (empty($cd["mobile_no"])) {
$this->logger->info('There is no mobile number Founded');
return $cd["customer_name"]." mobile number not found";
}
echo "<pre>";print_r($cd);echo "</pre>";die;
$this->logger->info('testing purpose ==> '.$cd["customer_name"]." -- ".$cd["name"]." -- ".$cd["due_date"]);
$whatsappContent = $cd["template_message"];
$whatsappContent = str_replace("{USER_NAME}", $cd["customer_name"], $whatsappContent);
$whatsappContent = str_replace("{SCHEME_NAME}", $cd["name"], $whatsappContent);
$whatsappContent = str_replace("{EXPIRY_DATE}", $cd["formatted_due_date"], $whatsappContent);
$params = (object) Null;
$url = SEND_WAAI_URL;
$params->number = (int)'91' . $cd["mobile_no"];
$params->type = "text";
$params->message = $whatsappContent;
$params->instance_id = $_ENV['WAAI_INSTANCE'];
$params->access_token = $_ENV['WAAI_TOKEN'];
$this->logger->info("Auto Notification : Whatsapp Content = " . $whatsappContent);
$this->logger->info($cd["name"]." Whatsapp Request = " . json_encode($params));
$this->logger->info($cd["name"]." Whatsapp Request type b4 = " . gettype($params));
$notification = new NotificationHelper();
// $whatsapp_result = $notification->sendWhatsAppMessage($url, "POST", $params);
$whatsapp_result = array();
// $this->logger->info($cd["name"]." Whatsapp Reponse = " .$whatsapp_result);
return $cd["customer_name"]."/".$cd["name"]." whatsapp template found not found";
}else{
$this->logger->info('There is no Whatsapp template found by the name of '.$cd["name"]);
return $cd["customer_name"]."/".$cd["name"]." whatsapp template found not found";
}// $Whatsapp Template Name
}
public function auto_scheduled_notification_campaign_status($campaign_id){
// echo "<br> have to update...................";
$model = new NotificationModel();
$model->setTable('notification_campaign');
$where = ['isactive' => 1, 'status' => 0, 'campaign_id' => (int) $campaign_id];
$data = ['status' => 1];
if ($model->where($where)->update($data)) {
// Update successful
echo "Update successful!";
} else {
// Update failed
echo "Update failed!";
}
}
}

View File

@ -580,37 +580,14 @@ function restriction(event,temporary_flag) {
</script> </script>
<script> <script>
document.getElementById('myForm').addEventListener('submit', function(event) { document.getElementById('myForm').addEventListener('submit', function(event) {
var table = document.getElementById("itemTable").getElementsByTagName("tbody")[0];
var rows = table.getElementsByTagName("tr");
var hasValue = false;
var rowCounter = rows.length; // Get the current number of rows
// Check if any existing fields are empty
for (var i = 0; i < rows.length; i++) {
var cells = rows[i].getElementsByTagName("td");
for (var j = 0; j < cells.length; j++) {
var input = cells[j].querySelector('input, select');
if (input && input.value.trim() === "") {
alert("Field in row " + (i + 1) + " is empty.");
$('#scrollable-modal').modal('hide');
return; // Exit the loop after the first empty field is found.
} else {
hasValue = true;
}
}
}
if (hasValue) {
var form = event.target; var form = event.target;
if (form.checkValidity() === false) { if (form.checkValidity() === false) {
form.reportValidity(); // Display validation error messages form.reportValidity(); // Display validation error messages
event.preventDefault(); // Prevent form submission if it's not valid event.preventDefault(); // Prevent form submission if it's not valid
$('#save').prop('disabled', false); $('#save').prop('disabled', false);
} else { } else {
$('#save').prop('disabled', true); $('#save').prop('disabled', true);
}} }
}); });
</script> </script>