diff --git a/app/Config/Constants.php b/app/Config/Constants.php
index 20716889..d1441b41 100644
--- a/app/Config/Constants.php
+++ b/app/Config/Constants.php
@@ -118,5 +118,7 @@ define('order_child_column', ["invoice_id","wp_api_line_items_id","customer_id"]
define('WAAI_TOKEN', '65156a8cc4358');
define('WAAI_INSTANCE', '65156ADE3E24F');
define('SEND_WAAI_URL', 'https://waai.in/api/send');
+define('SEND_WAAI_GROUP_URL', 'https://waai.in/api/send_group');
+
diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php
index 1be5b058..eed4f9f9 100644
--- a/app/Controllers/Invoice.php
+++ b/app/Controllers/Invoice.php
@@ -342,7 +342,7 @@ class Invoice extends BaseController
$model = new InvoiceModel();
$where = ['I.business_id' => (int)get_business_id(), 'I.invoice_id' => $invoice_id, 'I.isactive' => 1];
$details = $model->getDetailForApproveNotifications($where);
-
+ $records = [];
$reference_number = "";
$invoice_serial_number = "";
$recipient_name = "";
@@ -385,9 +385,10 @@ class Invoice extends BaseController
$records['page_name'] = 'Approve Template';
// view('approve_template',$records);
// $this->logger->info("Approve : Request data = ".json_encode($records));
- view('approve_template',$records);
+ // view('approve_template',$records);
$records['template_name'] = 'approve_template';
+ $records['item'] = $details['item'];
$records['subject'] = $invoice_serial_number . " - Approval Notification";
$records['description'] = "
VBP Approve Information
@@ -414,7 +415,7 @@ class Invoice extends BaseController
$params->instance_id = WAAI_INSTANCE;
$params->access_token = WAAI_TOKEN;
$this->logger->info("Invoice: approve notification Email Request data = ".json_encode($records));
- $email_result = $notification->sendEmail($details);
+ $email_result = $notification->sendEmail($records);
$this->logger->info("Invoice: approve notification Email Response = " . json_encode($email_result));
$this->logger->info("Invoice: approve notification Whatsapp Request data = ".json_encode($params));
$whatsapp_result = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params);
diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php
index 6991685c..ca741efc 100755
--- a/app/Controllers/Notifications.php
+++ b/app/Controllers/Notifications.php
@@ -10,8 +10,6 @@ class Notifications extends BaseController
## Email Section :
public function mail_custom_notifications()
{
- $successMessage = session()->getFlashdata('success');
- $validationErrors = session()->getFlashdata('error');
$request = \Config\Services::request();
if ($request->is('post')) {
$records = $request->getVar();
@@ -39,24 +37,34 @@ class Notifications extends BaseController
$this->logger->info("Whatsapp : sending message instance id = " . WAAI_INSTANCE);
try {
$this->logger->info("Whatsapp : sending message instance id = " . WAAI_INSTANCE);
- $params->number = (int)'91' . $records['mobile'];
+ 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{
+ 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.."); }
+ }
+
+ $url = constant($records['categories']);
$params->type = $records['type'] == "" ? "text" : $records['type'];
$params->instance_id = WAAI_INSTANCE;
$params->access_token = WAAI_TOKEN;
$params->message = $records['description'];
- if ($records['type'] == 'media') {
- $params->media_url = $records['media_url'];
- }
$this->logger->info("Whatsapp : sending message request type b4 = " . gettype($params));
helper('notification');
$notification = new NotificationHelper();
- $success = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params);
+ $success = $notification->sendWhatsAppMessage($url, "POST", $params);
session()->setFlashdata('success', 'Message : ' . $success);
$this->logger->info("Whatsapp : Reponse = " . $success);
} catch (\Exception $e) {
$this->logger->error("Whatsapp : Exception Message = " . $e->getMessage() . " File: " . $e->getFile() . " Line: " . $e->getLine() . " ");
- $error = "An error occurred: " . $e->getMessage();
- session()->setFlashdata('error', 'Message: ' . $error);
+ session()->setFlashdata('error', 'Message: ' . $e->getMessage());
}
}
$data['page_name'] = 'Custom Notifications';
diff --git a/app/Helpers/NotificationHelper.php b/app/Helpers/NotificationHelper.php
index 69032de7..d995e9a2 100644
--- a/app/Helpers/NotificationHelper.php
+++ b/app/Helpers/NotificationHelper.php
@@ -17,10 +17,15 @@ class NotificationHelper
public function sendEmail($records)
{
- $this->logger->info('Helper : Email');
+ $this->logger->info('Helper : Email Request Data type = '.gettype($records));
+
$cc = isset($records['carboncopy']) ? $records['carboncopy'] : '';
$bcc = isset($records['blindcarboncopy']) ? $records['blindcarboncopy'] : '';
+
try {
+ if($records['recipient_email'] == "" && $records['subject'] == ""){
+ 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->email->setFrom('no-reply@tripapprovaltool.com', isset($records['company'])?$records['company']:"VBP");
@@ -28,6 +33,7 @@ class NotificationHelper
$this->logger->info('Helper : Email subject = '.$records['subject']);
if($records['template_name'] != ""){
$this->logger->info('Helper : Email Template = '.$records['template_name']);
+ $this->logger->info("Helper : Email Request data = ".json_encode($records));
$emailContent = view($records['template_name'],$records);
$this->email->setMessage($emailContent);
}else{
@@ -38,7 +44,7 @@ class NotificationHelper
if (!empty($cc)) {
$ccRecipients = explode(',', $cc);
- $this->logger->info('Helper : Email CC recipient = '.$ccRecipients);
+ $this->logger->info('Helper : Email carboncopy CC recipient = '.$ccRecipients);
foreach ($ccRecipients as $ccRecipient) {
$this->email->setCC(trim($ccRecipient));
}
@@ -46,7 +52,7 @@ class NotificationHelper
if (!empty($bcc)) {
$bccRecipients = explode(',', $bcc);
- $this->logger->info('Helper : Email BCC recipient = '.$bccRecipients);
+ $this->logger->info('Helper : Email blindcarboncopy BCC recipient = '.$bccRecipients);
foreach ($bccRecipients as $bccRecipient) {
$this->email->setBCC(trim($bccRecipient));
}
@@ -59,8 +65,8 @@ class NotificationHelper
throw new \Exception('Email sending failed.');
}
} catch (\Exception $e) {
- $this->logger->error('Email Error: ' . $e->getMessage());
- $message['error'] = 'Helper : Email Exception Occur : ' . $e->getMessage();
+ $this->logger->error('Helper : Email Error: ' . $e->getMessage());
+ $message['error'] = 'Email Exception Occur : ' . $e->getMessage();
}
return $message;
}
@@ -111,7 +117,7 @@ class NotificationHelper
curl_close($curl);
}catch (\Exception $e) {
$this->logger->error('Helper : Whatsapp Exception Occur = ' . $e->getMessage());
- $final_result = "Exception Errno returned".$e->getMessage()." ";
+ $final_result = "Exception Errno returned ".$e->getMessage()." ";
}
return $final_result;
}
diff --git a/app/Views/approve_template.php b/app/Views/approve_template.php
index 56360da1..3d991351 100644
--- a/app/Views/approve_template.php
+++ b/app/Views/approve_template.php
@@ -1,108 +1,9 @@
-
-
-
-
- = $browser_title ?>
-
-
-
-
-
-
-
-
-
-
+
+
-