diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index b3960e33..1565cef8 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -71,6 +71,9 @@ abstract class BaseController extends Controller $details = $auth_model->getheringDetailsForHeader($session_uid); $data['company_name'] = $details[0]['site_name']; $data['company_short_name'] = $details[0]['site_title']; + $data['company_address'] = $details[0]['company_address']; + $data['company_mobile_no'] = $details[0]['company_mobile_no']; + $data['company_email'] = $details[0]['company_email']; $data['loggedin_person'] = $session_uname; $data['loggedin_person_id'] = $session_uid; $data['loggedin_person_role'] = $details[0]['role']; @@ -79,7 +82,9 @@ abstract class BaseController extends Controller $data['company_logo_small'] = !empty($details[0]['company_logo_small']) && file_exists(FCPATH."public/uploads/".$details[0]['company_logo_small']) ? base_url("public/uploads/" . $details[0]['company_logo_small']) : base_url("public/uploads/default_logo.png"); $data['company_logo_large'] = !empty($details[0]['company_logo_large']) && file_exists(FCPATH."public/uploads/".$details[0]['company_logo_large']) ? base_url("public/uploads/" . $details[0]['company_logo_large']) : base_url("public/uploads/default.png"); $data['browser_title'] = $data['company_name'] . ' | ' . $data['company_short_name'] . ' ' . $data['page_name']; - $data['heading'] = $data['page_name'] == "Dashboard" ? 'Welcome to ' . $data['company_name'] : ""; + $data['heading'] = $data['page_name'] === "Dashboard" ? 'Welcome to ' . $data['company_name'] : ""; + $data['loggedin_person'] = $session_uname; + echo view('template/header.php', $data); echo view('template/topbar.php', $data); echo view($viewpage, $data); diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index bb60f0e8..4f3a7237 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -29,7 +29,7 @@ class Invoice extends BaseController $model = new InvoiceModel(); $data['page_name'] = 'Invoice Details'; - $data['invoice'] = $model->getJoinedData($where, ['status']); + $data['invoice'] = $model->getJoinedData($where); $this->logger->info("Invoice: Listing Count ." . count($data['invoice'])); $this->render_page('invoice_list', $data); } else { @@ -315,7 +315,6 @@ class Invoice extends BaseController $where = ['isactive' => 1, 'status' => 'Approved', 'invoice_id' => (int)$id]; $details = $model->where($where)->findAll(); if (!empty($details)) { // change - // print_r($details);die; $data = ['status' => 'Approved', 'updated_by' => get_logged_user_id()]; if ($model->update($id, $data)) { $this->approve_notifications((int)$id); @@ -341,7 +340,8 @@ 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->getJoinedData($where); + $details = $model->getDetailForApproveNotifications($where); + $reference_number = ""; $invoice_serial_number = ""; $recipient_name = ""; @@ -349,26 +349,46 @@ class Invoice extends BaseController $approved_by = ""; $recipient_email = ""; $recipient_mobile = ""; - if (isset($details) && gettype($details) === 'object') { - $details = [$details]; - $this->logger->info("Approve : Request data type = " . gettype($details)); + $subtotal = ""; + $tax = ""; + $total_amount = ""; + $payment_method = ""; + if (isset($details)) { + $this->logger->info("Invoice: approve notification Request data type = ".gettype($details)); } helper('notification'); $notification = new NotificationHelper(); - - foreach ($details as $rec) { - $reference_number = $rec->order_number; - $invoice_serial_number = $rec->invoice_number; - $recipient_name = $rec->customer_name; - $approval_date = $rec->updated_on; - $approved_by = $rec->updated_by_name; - $recipient_email = $rec->customer_email; - $recipient_mobile = $rec->customer_mobile; - $records['recipient'] = $rec->customer_email; - $records['mobile'] = $rec->customer_mobile; + foreach ($details['invoice'] as $rec) { + $reference_number = $rec['order_number']; + $invoice_serial_number = $rec['invoice_number']; + $recipient_name = $rec['customer_name']; + $approval_date = $rec['updated_on']; + $approved_by = $rec['updated_by_name']; + $recipient_email = $rec['customer_email']; + $recipient_mobile = $rec['customer_mobile']; + $subtotal = $rec['subtotal']; + $tax = $rec['tax']; + $total_amount = $rec['total_amount']; + $payment_method = $rec['payment_method']; } - + $records['invoice_order_number'] = $reference_number; + $records['invoice_serial_number'] = $invoice_serial_number; + $records['recipient_name'] = $recipient_name; + $records['recipient_email'] = $recipient_email ? $recipient_email : "sanjeev.p@venbainfotech.com"; + $records['subtotal'] = $subtotal; + $records['tax'] = $tax; + $records['total_amount'] = $total_amount; + $records['payment_method'] = $payment_method; + $records['favicon'] = base_url("public/uploads/default.ico"); + $records['browser_title'] = "bbb-bp | Approve Template"; + $records['page_name'] = 'Approve Template'; + // view('approve_template',$records); + // $this->logger->info("Approve : Request data = ".json_encode($records)); + view('approve_template',$records); + + $records['template_name'] = 'approve_template'; $records['subject'] = $invoice_serial_number . " - Approval Notification"; + $records['description'] = "
Dear $recipient_name,
We are pleased to inform you that your Invoice has been approved.
@@ -392,17 +412,14 @@ class Invoice extends BaseController $params->message = $template; $params->instance_id = WAAI_INSTANCE; $params->access_token = WAAI_TOKEN; - - $email_result = $notification->sendEmail($records); - $this->logger->info("Invoice: approve notification = " . json_encode($email_result)); + $this->logger->info("Invoice: approve notification Email Request data = ".json_encode($records)); + $email_result = $notification->sendEmail($details); + $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); - $this->logger->info("Invoice: approve notification = " . json_encode($whatsapp_result)); + $this->logger->info("Invoice: approve notification Whatsapp Response = " . json_encode($whatsapp_result)); } - - - - ## To Generate Invoice PDF based on invoice ID public function generate_invoice_pdf($id) { diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index 37778854..6991685c 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -15,6 +15,7 @@ class Notifications extends BaseController $request = \Config\Services::request(); if ($request->is('post')) { $records = $request->getVar(); + $records['template_name'] = ""; helper('notification'); $notification = new NotificationHelper(); $data = $notification->sendEmail($records); diff --git a/app/Helpers/NotificationHelper.php b/app/Helpers/NotificationHelper.php index 835772b6..69032de7 100644 --- a/app/Helpers/NotificationHelper.php +++ b/app/Helpers/NotificationHelper.php @@ -21,14 +21,24 @@ class NotificationHelper $cc = isset($records['carboncopy']) ? $records['carboncopy'] : ''; $bcc = isset($records['blindcarboncopy']) ? $records['blindcarboncopy'] : ''; try { - $this->email->setTo($records['recipient']); + $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"); $this->email->setSubject($records['subject']); - $this->email->setMessage($records['description']); + $this->logger->info('Helper : Email subject = '.$records['subject']); + if($records['template_name'] != ""){ + $this->logger->info('Helper : Email Template = '.$records['template_name']); + $emailContent = view($records['template_name'],$records); + $this->email->setMessage($emailContent); + }else{ + $this->logger->info('Helper : Email Dynamic Template'); + $this->email->setMessage($records['description']); + } if (!empty($cc)) { $ccRecipients = explode(',', $cc); + $this->logger->info('Helper : Email CC recipient = '.$ccRecipients); foreach ($ccRecipients as $ccRecipient) { $this->email->setCC(trim($ccRecipient)); } @@ -36,6 +46,7 @@ class NotificationHelper if (!empty($bcc)) { $bccRecipients = explode(',', $bcc); + $this->logger->info('Helper : Email BCC recipient = '.$bccRecipients); foreach ($bccRecipients as $bccRecipient) { $this->email->setBCC(trim($bccRecipient)); } @@ -43,13 +54,13 @@ class NotificationHelper if ($this->email->send()) { $message['success'] = 'Email sent successfully'; - $this->logger->info('Email sent successfully'); + $this->logger->info('Helper : Email = sent successfully'); } else { throw new \Exception('Email sending failed.'); } } catch (\Exception $e) { $this->logger->error('Email Error: ' . $e->getMessage()); - $message['error'] = 'Email Error : ' . $e->getMessage(); + $message['error'] = 'Helper : Email Exception Occur : ' . $e->getMessage(); } return $message; } diff --git a/app/Models/AuthenticationModel.php b/app/Models/AuthenticationModel.php index 04acf241..046977e5 100644 --- a/app/Models/AuthenticationModel.php +++ b/app/Models/AuthenticationModel.php @@ -10,7 +10,7 @@ class AuthenticationModel extends Model public function getheringDetailsForHeader($user_id) { $builder = $this->db->table('users'); - $builder->select('user_id,user_name,users.email,users.first_name,users.last_name,users.password,users.mobile_no,date_of_birth,users.address,gender,profile_picture,users.city,users.state,users.postal_code,users.country,role,setting_id,site_name,site_title,favicon,logo,terms_service,footer_about,admin_email,mobile,copyright,pagination_limit,site_info,about_info,mail_protocol,mail_title,mail_host,mail_port,mail_encryption,mail_username,mail_password,currency,settings.country,settings.logo as company_logo_large,business.business_logo as company_logo_small'); + $builder->select('users.user_id,users.user_name,users.business_id,users.profile_picture,users.role,settings.site_name,settings.site_title,settings.favicon,settings.logo as company_logo_large,business.business_logo as company_logo_small,business.email as company_email,business.address as company_address,business.mobile_no as company_mobile_no,business.title'); $builder->join('settings', 'settings.business_id = users.business_id', 'left'); $builder->join('business', 'business.business_id = users.business_id', 'left'); $builder->where('user_id', $user_id); diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index eed5dc03..908dd3ba 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -53,14 +53,32 @@ public function updateData($table, $data, $where) ->join('business as B', 'B.business_id = I.business_id', 'left') ->join('users as U1', 'U1.user_id = I.created_by', 'left') ->join('users as U2', 'U2.user_id = I.updated_by', 'left') - ->select('I.invoice_id, I.invoice_number, I.customer_id,concat(C.first_name," ",C.last_name) as customer_name , I.invoice_date, I.due_date, I.subtotal, I.tax, I.discount, I.total_amount,I.status, I.payment_status, I.order_number, I.payment_method, I.event_id,E.event_name, I.business_id,B.title as business_name, I.created_on, I.created_by,concat(U1.first_name," ",U1.last_name) as created_by_name, I.updated_on, I.updated_by,concat(U2.first_name," ",U2.last_name) as updated_by_name, I.isactive,C.email as customer_email,C.mobile_no as customer_mobile') + ->select('I.invoice_id, I.invoice_number, I.customer_id,concat(C.first_name," ",C.last_name) as customer_name , I.invoice_date, I.due_date, I.subtotal, I.tax, I.discount, I.total_amount,I.status, I.payment_status, I.order_number, I.payment_method, I.event_id,E.event_name, I.business_id,B.title as business_name, I.created_on, I.created_by,concat(U1.first_name," ",U1.last_name) as created_by_name, I.updated_on, I.updated_by,concat(U2.first_name," ",U2.last_name) as updated_by_name, I.isactive,C.email as customer_email,C.mobile_no as customer_mobile,I.shipping_address_id,I.shipping_address,I.billing_address_id,I.billing_address') ->where($where) ->get() - ->getResult(); + ->getResultArray(); + // I.shipping_address_id, I.billing_address_id, } + + public function getDetailForApproveNotifications($where) + { + $result = $this->getJoinedData($where); + if(!empty($result)){ + foreach ($result as $object) { + $invoiceId = $object['invoice_id']; + $items = $this->getInvoiceItems($invoiceId); + } + }else{ + $items = []; + } + $data['invoice'] = $result; + $data['item'] = $items; + return $data; + } + public function getData($table, $where = null) { $query = $this->db->table($table); @@ -106,11 +124,11 @@ public function updateData($table, $data, $where) ->getResult(); } + // this function Also Used For Approve Notification. public function getInvoiceItems($id) { return $this->db->table('invoiceitems') - - ->where('invoice_id', $id) + ->where(['invoice_id'=>$id,'invoiceitems.isactive'=>1]) ->join('books as B','B.book_id=invoiceitems.product','left') ->select('invoiceitems.*,B.title') ->get() diff --git a/app/Views/approve_template.php b/app/Views/approve_template.php new file mode 100644 index 00000000..56360da1 --- /dev/null +++ b/app/Views/approve_template.php @@ -0,0 +1,310 @@ + + + + + +Payment Method
+
Paytm Payment Gateway
Shipment Method
+
Flexible Shipping
A publisher manages the design, editing, and production process with the help of proofreaders, printers, and editors. Publishers make schedules for every stage of the process and work backward from the planned date for publication. They distribute promotional catalogs to libraries and booksellers.
+ ARAVIND S
+ 22/2, SriKrishna Apartments
+ 1st Street, Subramania Nagar, Kodambakkam
+ CHENNAI 600024
+ Tamil Nadu
+ +919445062922
+ arasubu@gmail.com
+
+
+ ARAVIND S
+ 22/2, SriKrishna Apartments
+ 1st Street, Subramania Nagar, Kodambakkam
+ CHENNAI 600024
+ Tamil Nadu
+ +919445062922
+ arasubu@gmail.com
+