diff --git a/app/Config/Email.php b/app/Config/Email.php
index 5cb4e15a..9e4e3801 100644
--- a/app/Config/Email.php
+++ b/app/Config/Email.php
@@ -28,17 +28,17 @@ class Email extends BaseConfig
/**
* SMTP Server Address
*/
- public string $SMTPHost = 'smtp.sendgrid.net';
+ public string $SMTPHost = 'smtp.zoho.in';
/**
* SMTP Username
*/
- public string $SMTPUser = 'apikey';
+ public string $SMTPUser = 'web@vijayabharathambooks.com';
/**
* SMTP Password
*/
- public string $SMTPPass = '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';
+ public string $SMTPPass = 'Sz9VueQ2iLgH';
/**
* SMTP Port
@@ -59,7 +59,7 @@ class Email extends BaseConfig
* SMTP Encryption. Either tls or ssl
*/
public string $SMTPCrypto = 'tls';
-
+
/**
* Enable word-wrap
*/
diff --git a/app/Controllers/ApiIntegration.php b/app/Controllers/ApiIntegration.php
index d59fa157..5205c035 100644
--- a/app/Controllers/ApiIntegration.php
+++ b/app/Controllers/ApiIntegration.php
@@ -18,7 +18,7 @@ class ApiIntegration extends ResourceController
public function __construct()
{
- $this->global_variable_business_id = 1;
+ $this->global_variable_business_id = 2;
$this->global_variable_role = "Online";
$api_model = new ApiIntegrationModel();
$table = 'users';
diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php
index 3cbdd2e8..43f4f5f2 100644
--- a/app/Controllers/Customer.php
+++ b/app/Controllers/Customer.php
@@ -46,7 +46,7 @@ class Customer extends BaseController
$data['customer'] = [];
$data['customer_billing'] = [];
$data['customer_shipping'] = [];
- $data['subscriptionData'] = [];
+ $data['subscriptions'] = [];
$data['invoices'] = [];
} else if ($id !== '0') {
// Edit Customer
@@ -63,7 +63,7 @@ class Customer extends BaseController
// Retrieve subscriber data based on the customer ID
$subscriberData = $customerModel->getSubscriberDataByCustomerId($id);
- $data['subscriptionData'] = $subscriberData;
+ $data['subscriptions'] = $subscriberData;
// Fetch invoice data for the customer
$CustomerModel = new CustomerModel();
$invoices = $CustomerModel->getInvoicesByCustomerId($id);
diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php
index 00621612..1a98a2ab 100644
--- a/app/Controllers/Invoice.php
+++ b/app/Controllers/Invoice.php
@@ -48,7 +48,7 @@ class Invoice extends BaseController
$data['customers'] = $model->getData('customers', $where);
$data['events'] = $model->getData('events', $where);
$data['invoice_number_formatting'] = $model->getData('invoice_number_formatting', $where);
- $data['books'] = $model->getNonMembershipCategoryBooks('books', $where);
+ $data['books'] = $model->getCategoryBooks(1); // Invocie type = 2 (invoice)
if ($id === '0') {
$this->logger->info("Book Invoice: In Add Details");
@@ -79,7 +79,7 @@ class Invoice extends BaseController
// Get customer names for the dropdown, events details, and subscription books details
$data['customers'] = $model->getData('customers', $where);
$data['events'] = $model->getData('events', $where);
- $data['books'] = $model->getCategoryBooks('books', $where);
+ $data['books'] = $model->getCategoryBooks(2); // Invocie type = 2 (subscription)
$data['invoice_number_formatting'] = $model->getData('invoice_number_formatting', $where);
if ($id === '0') {
$this->logger->info("Subscription Invoice: In Add Page");
@@ -159,15 +159,13 @@ class Invoice extends BaseController
## Declarions
helper('session');
$model = new InvoiceModel();
- // Array ( [customer_name] => 1 [shipping_address] => 2 [event_next_id] => 134 [event_id] => 1 [invoice_number] => NBF2023-INV-00133 [order_number] => 12 [invoice_date] => 2023-09-07 [due_date] => 2023-09-07 [item_details] => Array ( [0] => 1 ) [quantity] => Array ( [0] => 2 [1] => 2 ) [rate] => Array ( [0] => 3 [1] => 3 ) [tax] => [amount] => Array ( [0] => 5 [1] => 5 ) [itemDetails] => Array ( [0] => 1 ) [subtotal] => [discount] => 9 [total] => [terms] => i don't like... )
$duedate = $this->request->getVar('due_date');
$invdate = $this->request->getVar('invoice_date');
$invoice_status = $this->request->getPost('status');
- // echo 'Hi';
- // echo($this->request->getPost('invoice_number'));die();
$invoice_id = (!empty($this->request->getPost('invoice_id'))) ? $this->request->getPost('invoice_id') : "";
$customer_id = (int)$this->request->getPost('customer_name');
$invoiceType = $this->request->getPost('invoice_type');
+
## Array Formation For Invoice Details..
$data = [
'invoice_number' => $this->request->getPost('invoice_number'),
@@ -194,6 +192,7 @@ class Invoice extends BaseController
'status' => $invoice_status,
'isactive' => 1
];
+
## Based on the invoice ID, we designated Insert or Update on Details...
if (empty($invoice_id)) {
$data['created_by'] = (int)get_logged_user_id();
@@ -223,51 +222,55 @@ class Invoice extends BaseController
$requestData = $this->request->getPost();
if($this->request->getPost('next_id')){
- ## Array Formation For Events Details And Updating Events also Here..
- $update_events = [
+ ## Array Formation For Invoice Numbering Format Details..
+ $update_invoice_numbering = [
'id' => 1,
'next_id' => (int)$this->request->getPost('next_id'),
'business_id' => (int)get_business_id(),
'updated_by' => get_logged_user_id()
];
- $this->update_number_formatting($update_events);}
-
+ $this->update_number_formatting($update_invoice_numbering);}
## For Invoice Item Details Insert/Update..
$this->save_invoice_item($invoice_id, $requestData, (int)$this->request->getVar('product'));
- $invoiceItems = $this->get_invoice_item($invoice_id);
-
-
- if ($invoiceType === '2') {
- // Extract necessary data
- $customerId = (int)$this->request->getPost('customer_name');
- $invoiceId = $invoice_id; // You have this value already
-
+
+ ## Subscription..
+ if ((int)$invoiceType === 2) {
+
// Loop through invoice items and store them in the 'subscription' table
$subscriptionModel = new InvoiceModel(); // Replace with your actual model
+ $invoiceItems = $this->get_invoice_item($invoice_id);
+
foreach ($invoiceItems as $item) {
- $productId = $item['product'];
- $fromsub=$item['from_subscription'];
- $tosub=$item['to_subscription'];
+
+ $product_id = $item['product'];
+ $from_sub_date = $item['from_subscription'];
+ $to_sub_date = $item['to_subscription'];
- // Assuming 'product' is the field name in the invoice item table
-
- // Create an array for subscription data
- $subscriptionData = [
- 'customer_id' => $customerId,
- 'invoice_id' => $invoiceId,
- 'scheme_id' => $productId,
- 'from_subscription'=>$fromsub,
- 'to_subscription'=> $tosub,
+ $subscription_data = [
+ 'customer_id' => (int)$customer_id,
+ 'invoice_id' => $invoice_id,
+ 'scheme_id' => $product_id,
+ 'from_subscription'=>$from_sub_date,
+ 'to_subscription'=> $to_sub_date,
'business_id' => get_business_id(),
'created_by' =>get_logged_user_id(),
- // Add other subscription-specific data here
];
-
- // Insert the subscription data into the 'subscription' table
- $subscriptionModel->insertSubscriptionData($subscriptionData);
+
+ $subscription_where = ['scheme_id' => $product_id,'customer_id' => $customer_id,'invoice_id' => $invoice_id];
+ $subscription_details = $model->getData('subscription', $subscription_where);
+
+ if(count($subscription_details)==0){
+ $subscriptionModel->insertSubscriptionData($subscription_data);
+ }else{
+ unset($subscription_data['created_by']);
+ $subscription_data['updated_by'] =get_logged_user_id();
+ $subscription_where = ['sub_id' => (int)$subscription_details[0]->sub_id];
+ $subscriptionModel->updateData('subscription', $subscription_data, $subscription_where);
+ }
}
}
+
## Notification For Approve..
if ($invoice_status == 'Approved' && !$invoice_id) {
$this->approve_notifications((int)$invoice_id);
diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php
index 8983a333..71d2b7d1 100755
--- a/app/Controllers/Users.php
+++ b/app/Controllers/Users.php
@@ -17,22 +17,42 @@ class Users extends BaseController
$session_bid = get_business_id();
if (!empty($session_role) && $session_role !== "sadmin") {
- $this->logger->info("Users: Listing In admin role . BID = ".$session_bid);
- $where = ['users.business_id' => (int)$session_bid, 'users.isactive' => 1];
+
+
} else {
- $this->logger->info("Users: Listing In Super-admin role .");
- $where = ['users.isactive !=' => NULL];
+
+ }
+
+ switch ($session_role) {
+ case "sadmin":
+ $this->logger->info("Users: Listing In Super-admin role .");
+ $where = ['users.isactive !=' => NULL];
+ break;
+ case "admin":
+ $this->logger->info("Users: Listing In ".$session_role." role . BID = ".$session_bid);
+ $where = ['users.business_id' => (int)$session_bid, 'users.isactive !=' => NULL,'LOWER(users.role) !='=>strtolower("online")];
+ break;
+ case "manager":
+ $this->logger->info("Users: Listing In ".$session_role." role . BID = ".$session_bid);
+ $where = ['users.business_id' => $session_bid, 'users.isactive' => 1,'LOWER(users.role) !='=>strtolower("online") ];
+ break;
+ default:
+ $data['page_name'] = 'Page Not Found';
+ $where = [];
+ $render_page_name = 'pages_404';
+ }
+
+ if(!empty($where)){
+ $model = new UsersModel();
+ $model->setTable('users');
+ $user_details = $model->select('users.*,business.title as company_name')->where($where)->join('business', 'business.business_id = users.business_id','left')->orderBy('user_id', 'DESC')->findAll();
+ $this->logger->info("Users: Listing Count .".count($user_details));
+ $data['page_name'] = 'User Details';
+ $data['details'] = $user_details;
+ $render_page_name = 'user_list';
}
- $model = new UsersModel();
- $model->setTable('users');
-
- $user_details = $model->select('users.*,business.title as company_name')->where($where)->join('business', 'business.business_id = users.business_id','left')->orderBy('user_id', 'DESC')->findAll();
-
- $this->logger->info("Users: Listing Count .".count($user_details));
- $data['page_name'] = 'User Details';
- $data['details'] = $user_details;
$data['session_role'] = $session_role;
- $this->render_page('user_list', $data);
+ $this->render_page($render_page_name, $data);
}
## To Load User Add/Update page
@@ -62,14 +82,14 @@ class Users extends BaseController
$data['page_name'] = 'Edit User';
break;
case "admin":
- $where = ['users.user_id' => $id, 'users.isactive =' => 1];
+ $where = ['users.user_id' => $id, 'users.isactive !=' => NULL,'users.business_id' => $session_bid];
$edit_user_details = $model->where($where)->first();
$business_details = [];
$render_page_name = 'user_form';
$data['page_name'] = 'Edit User';
break;
case "manager":
- $where = ['users.user_id' => $id, 'users.isactive =' => 1];
+ $where = ['users.user_id' => $id, 'users.isactive' => 1 ,'users.business_id' => $session_bid];
$edit_user_details = $model->where($where)->first();
$business_details = [];
if($session_uid === $id && $session_role === "manager"){
@@ -87,6 +107,7 @@ class Users extends BaseController
}
$data['details'] = $edit_user_details;
}
+ echo count($data['details']);die;
$data['business_details'] = $business_details;
$data['session_bid'] = $session_bid;
$data['session_role'] = $session_role;
diff --git a/app/Helpers/NotificationHelper.php b/app/Helpers/NotificationHelper.php
index eafd2983..21d9cda7 100644
--- a/app/Helpers/NotificationHelper.php
+++ b/app/Helpers/NotificationHelper.php
@@ -18,17 +18,18 @@ class NotificationHelper
public function sendEmail($records)
{
$this->logger->info('Helper : Email Request Data type = '.gettype($records));
-
- $cc = isset($records['carboncopy']) ? $records['carboncopy'] : '';
+
+ $cc = isset($records['carboncopy']) ? $records['carboncopy'] : 'contact@vijayabharathambooks.com';
$bcc = isset($records['blindcarboncopy']) ? $records['blindcarboncopy'] : '';
try {
+ $this->email->clear();
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");
+ $this->email->setFrom('web@vijayabharathambooks.com', isset($records['company'])?$records['company']:"VB");
$this->email->setSubject($records['subject']);
$this->logger->info('Helper : Email subject = '.$records['subject']);
$this->email->setMessage($records['description']);
@@ -44,50 +45,53 @@ class NotificationHelper
// }
- if (!empty($cc)) {
- $ccRecipients = explode(',', $cc);
- $this->logger->info('Helper : Email carboncopy CC recipient = '.$ccRecipients);
- foreach ($ccRecipients as $ccRecipient) {
- $this->email->setCC(trim($ccRecipient));
+ if ($cc !== '') {
+ $ccRecipients = explode(',', trim($cc));
+ $this->logger->info('Helper : Email carboncopy CC recipient = ' . implode(',', $ccRecipients));
+ if(!empty($ccRecipients)) {
+ $this->email->setCC($ccRecipients);
}
}
-
- if (!empty($bcc)) {
- $bccRecipients = explode(',', $bcc);
- $this->logger->info('Helper : Email blindcarboncopy BCC recipient = '.$bccRecipients);
- foreach ($bccRecipients as $bccRecipient) {
- $this->email->setBCC(trim($bccRecipient));
+
+ if ($bcc !== '') {
+ $bccRecipients = explode(',', trim($bcc));
+ $this->logger->info('Helper : Email blindcarboncopy BCC recipient = ' . implode(',', $bccRecipients));
+ if(!empty($bccRecipients)) {
+ $this->email->setBCC($bccRecipients);
}
}
-
+
if ($this->email->send()) {
$message['success'] = 'Email sent successfully';
- $this->logger->info('Helper : Email = sent successfully');
+ $this->logger->info('Helper : Email Status = sent successfully');
} else {
throw new \Exception('Email sending failed.');
}
} catch (\Exception $e) {
- $this->logger->error('Helper : Email Error: ' . $e->getMessage());
+ $this->logger->error('Helper : Email Error = ' . $e->getMessage());
$message['error'] = 'Email Exception Occur : ' . $e->getMessage();
}
return $message;
}
- public function sendWhatsAppMessage($url,$method,$data)
+ public function sendWhatsAppMessage($url, $method, $data)
{
- try{
- $this->logger->info('Helper : Whatsapp');
- $curl = curl_init();
+ $final_result = ""; // Initialize outside try-catch block
+
+ try {
+ $this->logger->info('Helper : Whatsapp');
+ $curl = curl_init();
$headers = array('Content-Type:application/json');
$jsonencoded = json_encode($data);
- curl_setopt( $curl,CURLOPT_URL, $url);
- $this->logger->info('Helper : Whatsapp url = '.$url);
+ curl_setopt($curl, CURLOPT_URL, $url);
+ $this->logger->info('Helper : Whatsapp url = ' . $url);
+
switch ($method) {
case "POST":
- curl_setopt( $curl,CURLOPT_POST, true );
+ curl_setopt($curl, CURLOPT_POST, true);
if ($data) {
- $this->logger->info('Helper : Whatsapp jsonencoded = '.$jsonencoded);
- curl_setopt( $curl,CURLOPT_POSTFIELDS, $jsonencoded);
+ $this->logger->info('Helper : Whatsapp jsonencoded = ' . $jsonencoded);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonencoded);
}
break;
case "PUT":
@@ -95,37 +99,46 @@ class NotificationHelper
break;
default:
if ($data) {
- // print_r($data);die();
$url = sprintf("%s?%s", $url, http_build_query((array)$data));
}
}
- curl_setopt( $curl,CURLOPT_HTTPHEADER, $headers );
- curl_setopt( $curl,CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $curl,CURLOPT_SSL_VERIFYPEER, true );
- $curl_exec = curl_exec($curl);
- $this->logger->info('Helper : Whatsapp Reponse = '.$curl_exec);
+
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
+ $curl_exec = curl_exec($curl);
+ $this->logger->info('Helper : Whatsapp Reponse = ' . $curl_exec);
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+
if ($http_status === 200) {
$result = json_decode($curl_exec);
+
if ($result->status === "error") {
- $this->logger->error('Helper : Whatsapp Err occur = '.$result->message);
+ $this->logger->error('Helper : Whatsapp Err occur = ' . $result->message);
throw new \Exception($result->message);
}
+
if ($result->status === "success") {
- $final_result = isset($result->message) ? ((strtolower(gettype($result->message)) === 'string') ? $result->message : "Sended Success") : " Message Not Sent. ";
+ $final_result = isset($result->message) ? (
+ (strtolower(gettype($result->message)) === 'string') ?
+ $result->message : "Sended Success"
+ ) : " Message Not Sent. ";
}
- }else{
- $curl_errno= curl_errno($curl);
- $this->logger->error('Helper : Whatsapp curl error occur = '.$curl_errno);
- throw new \Exception(" Errno returned ".$curl_errno);
+ } else {
+ $curl_errno = curl_errno($curl);
+ $this->logger->error('Helper : Whatsapp curl error occur = ' . $curl_errno);
+ throw new \Exception(" Errno returned " . $curl_errno);
}
- curl_close($curl);
- }catch (\Exception $e) {
+
+ 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/Models/CustomerModel.php b/app/Models/CustomerModel.php
index e81ce68c..042aea41 100644
--- a/app/Models/CustomerModel.php
+++ b/app/Models/CustomerModel.php
@@ -111,6 +111,7 @@ public function getSubscriberDataByCustomerId($customerId)
// Add a where condition to filter results based on customer ID.
$builder->where('subscription.customer_id', $customerId);
$builder->where('invoice.invoice_type = "2"'); // Default type is 2 (subscription).
+ $builder->groupBy('subscription.sub_id');
// Execute the query and return the result as an array of objects.
return $builder->get()->getResult();
}
diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php
index 0b54a3fd..1e620828 100644
--- a/app/Models/HomeModel.php
+++ b/app/Models/HomeModel.php
@@ -51,7 +51,7 @@ class HomeModel extends Model
// $query = $this->db->table('category AS C')
// ->select('C.id,C.name,LEFT(C.name, 1) AS first_letter, COUNT(BC.category_id) AS count')
// ->join('book_categories AS BC', 'C.id = BC.category_id', 'left')
- // ->where(['C.isactive'=>1,'C.business_id'=>1])
+ // ->where(['C.isactive'=>1,'C.business_id'=>2])
// ->groupBy('C.id');
// $results = $query->get()->getResultArray();
// return $results;
@@ -66,8 +66,8 @@ class HomeModel extends Model
->join('book_categories AS BC', 'BC.book_id = S.scheme_id AND BC.isactive = 1', 'left')
->join('category AS CM', 'CM.id = BC.category_id AND C.isactive = 1', 'left')
->join('book_images AS BI', 'BI.book_id = S.scheme_id AND BI.isactive = 1', 'left')
- ->where('LOWER(CM.name)', strtolower("Membership"))
- ->where(['S.business_id' => 1,'BK.isactive' => 1])
+ // ->where('LOWER(CM.name)', strtolower("Membership"))
+ ->where(['S.business_id' => 2,'BK.isactive' => 1])
->groupBy('S.scheme_id');
$results = $query->get()->getResultArray();
return $results;
diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php
index 6dc48391..3e8aba8d 100644
--- a/app/Models/InvoiceModel.php
+++ b/app/Models/InvoiceModel.php
@@ -199,29 +199,25 @@ public function updateData($table, $data, $where)
return $data;
}
- public function getCategoryBooks()
-{
- return $this->db->table('books')
- ->join('book_categories', 'book_categories.book_id= books.book_id', 'left')
- ->join('category','category.id=book_categories.category_id')
- ->where('category.name', 'membership')
- ->get()
- ->getResult();
-
-}
-public function getNonMembershipCategoryBooks()
-{
- $data = $this->db->table('books')
- ->select('books.*')
- ->join('book_categories', 'book_categories.book_id= books.book_id', 'left')
- ->join('category','category.id=book_categories.category_id')
- ->where('category.name !=', 'membership')
- ->groupBy('books.book_id')
- ->get()
- ->getResult();
- return $data;
+
+ public function getCategoryBooks($type)
+ {
+
+ $where = ($type == 1) ? ['LOWER(category.name) !=' => strtolower('Membership')] : ['LOWER(category.name)' => strtolower('Membership')];
+
+ $data = $this->db->table('books')
+ ->select('books.book_id,books.business_id,books.wp_api_product_id,books.title,books.publication_date,books.publisher,books.author,books.genre,books.language,books.description,books.short_description,books.page_count,books.price,books.isbn_code,books.tax,books.sku,books.category,books.isactive')
+ ->join('book_categories', 'book_categories.book_id= books.book_id', 'left')
+ ->join('category','category.id=book_categories.category_id')
+ ->where($where)
+ ->groupBy('books.book_id')
+ ->get()
+ ->getResult();
+// print_r($this->db->getLastQuery());die;
+
+ return $data;
+ }
-}
public function insertSubscriptionData($data)
{
return $this->db->table('subscription')->insert($data);
diff --git a/app/Views/customer_form.php b/app/Views/customer_form.php
index 15b629ab..4e1726ba 100644
--- a/app/Views/customer_form.php
+++ b/app/Views/customer_form.php
@@ -21,7 +21,7 @@