diff --git a/.env b/.env index e5bfe125..08b34b1b 100644 --- a/.env +++ b/.env @@ -146,8 +146,15 @@ APP_TIMEZONE = 'Asia/Kolkata' #-------------------------------------------------------------------- # Whatsapp Access Token And Instance ID #-------------------------------------------------------------------- +# for Live WAAI_TOKEN = '6568739969f28' 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 diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 153861d9..61b24f71 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -115,17 +115,6 @@ define('order_column', ["invoice_id","wp_api_order_id","invoice_child_id"]); define('order_child','invoiceitems'); 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... define('WAAI_TOKEN', getenv('WAAI_TOKEN')); define('WAAI_INSTANCE', getenv('WAAI_INSTANCE')); diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index ef4fca89..8810d317 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -36,20 +36,29 @@ class Notifications extends BaseController $records = $request->getVar(); $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 { 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'] != ""){ $params->number = (int)'91' . $records['mobile']; } - else{ throw new \Exception("Mobile Number Missing Please Try again.."); } - }else{ + 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'] != "") { + $params->number = (int)'91' . $records['mobile']; + } else { + throw new \Exception("Mobile Number Missing Please Try again.."); + } + } else { throw new \Exception("Please Choose your Category"); } if ($records['type'] == 'media') { - if($records['media_url'] != ""){ $params->media_url = $records['media_url']; } - else{ throw new \Exception("Media Url Missing Please Try again.."); } + if ($records['media_url'] != "") { + $params->media_url = $records['media_url']; + } else { + throw new \Exception("Media Url Missing Please Try again.."); + } } $url = constant($records['categories']); @@ -76,22 +85,22 @@ class Notifications extends BaseController public function due_date_notifications() { $date = $this->request->getGet('date'); - + $model = new NotificationModel(); $details = $model->getSubscriptionDueDetail($date); // echo "
";
         // print_r($details);
         // echo "
"; // die; - $records = []; + $records = []; $recipient_name = ""; $recipient_email = ""; $recipient_mobile = ""; $subscription_name = ""; - $business_name= ""; - $to_subscription= ""; + $business_name = ""; + $to_subscription = ""; 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'); $notification = new NotificationHelper(); @@ -101,23 +110,22 @@ class Notifications extends BaseController $recipient_mobile = $rec['customer_mobile']; // $recipient_email = "sanjeev.p@venbainfotech.com"; // $recipient_mobile = 6369084112; - $business_name= $rec['business_name']; + $business_name = $rec['business_name']; $subscription_name = $rec['title']; - $to_subscription= $rec['to_subscription']; - + $to_subscription = $rec['to_subscription']; } $records['template_name'] = ''; $records['recipient_name'] = $recipient_name; $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'] = " Due Date Reminder -

Hello ".$recipient_name.",

+

Hello " . $recipient_name . ",

This is a reminder that the following subscription is due soon:

-

Subscription Name:".$subscription_name."

-

Due Date: ".$to_subscription."

+

Subscription Name:" . $subscription_name . "

+

Due Date: " . $to_subscription . "

Please make sure to complete this subscription on time.

Thank you.

@@ -131,17 +139,17 @@ 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->info("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->info("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)); - } - public function template_creation(){ + public function template_creation() + { $data['page_name'] = 'Template Details'; $model = new NotificationModel(); $data['template'] = $model->getTemplateDetails(); @@ -149,8 +157,9 @@ class Notifications extends BaseController // echo "templates";die; } - public function template_creation_form($id){ - + public function template_creation_form($id) + { + $data['group_details'] = $this->get_group_details(); $model = new NotificationModel(); if ($id === '0') { @@ -161,7 +170,7 @@ class Notifications extends BaseController $this->logger->info("Template Creation: In Edit Page ID =" . $id); $data['page_name'] = 'Edit Template'; $model->setTable('templates'); - $where = ['template_id'=>(int)$id]; + $where = ['template_id' => (int)$id]; $result = $model->where($where)->findAll(); $data['template_details'] = !empty($result[0]) ? $result[0] : []; } @@ -169,34 +178,34 @@ class Notifications extends BaseController $this->render_page('template_creation_form', $data); } - public function template_creation_delete($id){ + public function template_creation_delete($id) + { try { helper('session'); $session_uid = get_logged_user_id(); $model = new NotificationModel(); $model->setTable('templates'); - $where = ['template_id'=>(int)$id]; + $where = ['template_id' => (int)$id]; $result = $model->where($where)->findAll(); if ($result) { - $this->logger->Info("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. + $this->logger->Info("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']); - } else if ($statement['error']) { + session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : ""); + $this->logger->info($statement['log']); + } else if ($statement['error']) { session()->setFlashdata('error', $statement['error']); $this->logger->error($statement['log']); - }else{ - throw new \Exception("Template: Err Occur on data the Template Inactive"); + } else { + throw new \Exception("Template: Err Occur on data the Template Inactive"); } } } 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()); } return redirect()->route('template_creation'); - } public function get_group_details() @@ -208,51 +217,55 @@ class Notifications extends BaseController $details = $model->where($where)->orderBy('group_id', 'ASC')->findAll(); return $details; } - public function get_template_details(){ + + public function get_template_details() + { $model = new NotificationModel(); $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; } - public function template_creation_insert(){ + public function template_creation_insert() + { $this->logger->info("Template: Inserting/Updating Details"); - try { - ## Declarions - helper('session'); - $model = new NotificationModel(); - $session_uid = get_logged_user_id(); - $id = $this->request->getPost('template_id'); - $subject = $this->request->getPost('subject') ? $this->request->getPost('subject') : NULL; - $isactive = $id != "" ? $this->request->getPost('isactive') : 'on'; - $data = [ - 'template_id' => $id, - 'template_name' => $this->request->getPost('templatename'), - 'subject' => $subject, - 'message' => $this->request->getPost('templatemessage'), - 'mode' => $this->request->getPost('mode'), - 'isactive' => (($isactive == 'on') ? 1 : 0), - 'created_by' => $session_uid, - 'updated_by' => $session_uid - ]; - $statement = $model->saveDetails($data,'template_id','templates'); - 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("Template: Err Occur"); - } - }catch(\Exception $e) { - $this->logger->error("Template: Err Occur =".$e->getMessage()); - session()->setFlashdata('error', 'Message: ' .$e->getMessage()); - } - return redirect()->route('template_creation'); - } + try { + ## Declarions + helper('session'); + $model = new NotificationModel(); + $session_uid = get_logged_user_id(); + $id = $this->request->getPost('template_id'); + $subject = $this->request->getPost('subject') ? $this->request->getPost('subject') : NULL; + $isactive = $id != "" ? $this->request->getPost('isactive') : 'on'; + $data = [ + 'template_id' => $id, + 'template_name' => $this->request->getPost('templatename'), + 'subject' => $subject, + 'message' => $this->request->getPost('templatemessage'), + 'mode' => $this->request->getPost('mode'), + 'isactive' => (($isactive == 'on') ? 1 : 0), + 'created_by' => $session_uid, + 'updated_by' => $session_uid + ]; + $statement = $model->saveDetails($data, 'template_id', 'templates'); + 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("Template: Err Occur"); + } + } catch (\Exception $e) { + $this->logger->error("Template: Err Occur =" . $e->getMessage()); + session()->setFlashdata('error', 'Message: ' . $e->getMessage()); + } + return redirect()->route('template_creation'); + } - public function campaign_creation(){ + public function campaign_creation() + { $data['page_name'] = 'Campaign Details'; $model = new NotificationModel(); $data['campaign'] = $model->getCampaignDetails(); @@ -260,8 +273,9 @@ class Notifications extends BaseController // echo "templates";die; } - public function campaign_creation_form($id){ - + public function campaign_creation_form($id) + { + $data['group_details'] = $this->get_group_details(); $data['template_details'] = $this->get_template_details(); $model = new NotificationModel(); @@ -273,104 +287,102 @@ class Notifications extends BaseController $this->logger->info("Campaign Creation: In Edit Page ID =" . $id); $data['page_name'] = 'Edit Campaign'; $model->setTable('notification_campaign'); - $where = ['campaign_id'=>(int)$id]; + $where = ['campaign_id' => (int)$id]; $result = $model->where($where)->findAll(); if (!empty($result)) { foreach ($result as $i => $item) { $result[$i]['group_id'] = unserialize($item['group_id']); - } + } } $data['campaign_details'] = !empty($result[0]) ? $result[0] : []; - } $this->render_page('campaign_creation_form', $data); } - public function campaign_creation_delete($id){ + public function campaign_creation_delete($id) + { try { helper('session'); $session_uid = get_logged_user_id(); $model = new NotificationModel(); $model->setTable('notification_campaign'); - $where = ['campaign_id'=>(int)$id]; + $where = ['campaign_id' => (int)$id]; $result = $model->where($where)->findAll(); if ($result) { - $this->logger->Info("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. + $this->logger->Info("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']); - } else if ($statement['error']) { + session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : ""); + $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 on data the Template Inactive"); + } else { + throw new \Exception("Campaign: Err Occur on data the Template Inactive"); } } } 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()); } return redirect()->route('campaign_creation'); - } - public function campaign_creation_insert(){ + public function campaign_creation_insert() + { $this->logger->info("Campaign: Inserting/Updating Details"); - try { - ## Declarions - helper('session'); - $model = new NotificationModel(); - $session_uid = get_logged_user_id(); - $id = $this->request->getPost('campaign_id'); - $request_data = $this->request->getPost(); - $isactive = $id == "" ? 1 : (isset($request_data['isactive']) && $request_data['isactive'] == 'on' ? 1 : 0); - - $data = [ - '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'), - 'mode' => $this->request->getPost('mode'), - 'group_id' => serialize($this->request->getPost('group_id')), - 'isactive' => $isactive, - 'created_by' => $session_uid, - 'updated_by' => $session_uid - ]; - if($id != ""){ + try { + ## Declarions + helper('session'); + $model = new NotificationModel(); + $session_uid = get_logged_user_id(); + $id = $this->request->getPost('campaign_id'); + $request_data = $this->request->getPost(); + $isactive = $id == "" ? 1 : (isset($request_data['isactive']) && $request_data['isactive'] == 'on' ? 1 : 0); + + $data = [ + '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'), + 'mode' => $this->request->getPost('mode'), + 'group_id' => serialize($this->request->getPost('group_id')), + 'isactive' => $isactive, + 'created_by' => $session_uid, + 'updated_by' => $session_uid + ]; + if ($id != "") { $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.'; + $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['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{ - $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"); + $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'); } - - - }catch(\Exception $e) { - $this->logger->error("Campaign: Err Occur =".$e->getMessage()); - session()->setFlashdata('error', 'Message: ' .$e->getMessage()); - } - return redirect()->route('campaign_creation'); - } + } 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"); + } + } 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) { @@ -388,13 +400,14 @@ class Notifications extends BaseController //Step 3: Replace the placeholder WINDOW_TIME with the user-provided value $modifiedQuery = str_replace('WINDOW_TIME', $window_time, $ExpCustomerDetail); - + if (empty($modifiedQuery)) { $this->logger->info('There is no sub query'); return; } $db = \Config\Database::connect(); $queryResult = $db->query($modifiedQuery)->getResultArray(); + $notification = new NotificationHelper(); if (empty($queryResult)) { $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); - if(!empty($emailTemplateName)){ + if (!empty($emailTemplateName)) { //Step 4: Prepare email content based on the template $emailContent = $emailTemplateName[0]['message']; $emailContent = str_replace("{USER_NAME}", $fullName, $emailContent); @@ -435,315 +448,39 @@ class Notifications extends BaseController } else { echo 'Failed to send email'; } - }else{ + } else { $this->logger->info('There is no email template found by the name of EXPIRAY_NOTIFY_TEMPLATE_EMAIL'); continue; - }// $emailTemplateName + } // $emailTemplateName $whatsappTemplateName = $NotificationModel->getTempName(EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP); - if(!empty($whatsappTemplateName)){ + if (!empty($whatsappTemplateName)) { if (empty($userMobileNumber)) { $this->logger->info('There is no subscriber mobile number'); continue; - } + } //Step 6: 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); - // Step 7: Send email using NotificationHelper - $params = (object) Null; - $url = SEND_WAAI_URL; - $params->number = (int)'91' . $userMobileNumber; - $params->type = "text"; - $params->message = $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)); - $whatsapp_result = $notification->sendWhatsAppMessage($url, "POST", $params); - $this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Reponse = " .$whatsapp_result); - }else{ + // Step 7: Send email using NotificationHelper + $params = (object) Null; + $url = SEND_WAAI_URL; + $params->number = (int)'91' . $userMobileNumber; + $params->type = "text"; + $params->message = $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)); + $whatsapp_result = $notification->sendWhatsAppMessage($url, "POST", $params); + $this->logger->info("EXPIRAY NOTIFY TEMPLATE WHATSAPP Reponse = " . $whatsapp_result); + } else { $this->logger->info('There is no Whatsapp template found by the name of EXPIRAY NOTIFY TEMPLATE WHATSAPP '); continue; - }// $Whatsapp Template Name - }// for loop + } // $Whatsapp Template Name + } // 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 "
";print_r($ncr);echo "
";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 "
";print_r($customer_details_template);echo "
";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 "
";print_r($template_result);echo "
";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 "
";print_r($details);echo "
";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 "
";print_r($flattened_array);echo "
";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 "
";print_r($flattened_array);echo "
";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 "
";print_r($cd);echo "
";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 "
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!"; - } - } - } - - \ No newline at end of file +} diff --git a/app/Views/customer_group_form.php b/app/Views/customer_group_form.php index d7971f1d..2c703f69 100644 --- a/app/Views/customer_group_form.php +++ b/app/Views/customer_group_form.php @@ -580,37 +580,14 @@ function restriction(event,temporary_flag) {