diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 04000705..75a760cf 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -51,6 +51,8 @@ $routes->get('dashboard/', 'Home::index');
$routes->get("user_list/", "Users::index");
$routes->get("user_page/(:any)", "Users::user_page/$1");
$routes->post("insert_users", "Users::insert_users");
+$routes->get('users/fetch_event_names', 'Users::fetch_event_names');
+
$routes->get("delete_user/(:any)", "Users::delete_user/$1");
# Books Routes
@@ -114,6 +116,9 @@ $routes->post("insert_invoice_number_format", "Event::insert_invoice_number_form
$routes->get("invoice_list/", "Invoice::index");
$routes->get("new_book_invoice/(:any)", "Invoice::new_book_invoice/$1");
$routes->get("new_subscription_invoice/(:any)", "Invoice::new_subscription_invoice/$1");
+// $routes->get("download_invoice_pdf/(:num)",'Invoice::download_invoice_pdf/$1');
+$routes->get("download_invoice_pdf/(:any)", 'Invoice::download_invoice_pdf/$1');
+
$routes->post("get_customer_billing_details", "Invoice::get_customer_billing_details");
@@ -128,6 +133,9 @@ $routes->get('print_address/(:num)', 'Invoice::print_address/$1');
$routes->match(['get','post'],'/general_inv_rp','Invoice::general_inv_rp');
$routes->match(['get','post'],'/mem_inv_rp','Invoice::general_membership_inv_rp');
$routes->match(['get','post'],'/itemwise_report','Invoice::itemwise_report');
+$routes->match(['get','post'],'/expired_customer_report','Invoice::expired_customer_report');
+$routes->match(['get','post'],'/book_publishwise_Report','Invoice::book_publishwise_Report');
+
# Notifications Routes
diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php
index 83cddded..1806c7d4 100644
--- a/app/Controllers/BaseController.php
+++ b/app/Controllers/BaseController.php
@@ -65,7 +65,8 @@ abstract class BaseController extends Controller
echo "This is a command-line request.";
// echo $requestedRoute;
} else {
- if ($requestedRoute !== '/login' && $requestedRoute !== '/authenticate' && $uri->getSegment(1) != 'getExpCustomerDetail') {
+
+ if ($requestedRoute !== '/login' && $requestedRoute !== '/authenticate' && $uri->getSegment(1) != 'getExpCustomerDetail'&& $uri->getSegment(1) != 'download_invoice_pdf') {
$this->authData = $this->session_log();
}
}
diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php
index 68df5ee3..37cb69e5 100644
--- a/app/Controllers/Invoice.php
+++ b/app/Controllers/Invoice.php
@@ -541,6 +541,8 @@ class Invoice extends BaseController
$recipient_mobile = $rec['customer_mobile'];
$subtotal = $rec['subtotal'];
$tax = $rec['tax'];
+ $invoiceDate=$rec['invoice_date'];
+
$total_amount = $rec['total_amount'];
$payment_method = $rec['payment_method'];
$business_name= $rec['business_name'];
@@ -549,7 +551,8 @@ class Invoice extends BaseController
$business_state= $rec['business_state'];
$business_postal_code= $rec['business_postal_code'];
$business_email= $rec['business_email'];
- $business_mobile_no= $rec['business_mobile_no'];
+ $business_mobile_no= $rec['business_mobile_no'];
+
}
$records['invoice_order_number'] = $reference_number;
$records['invoice_serial_number'] = $invoice_serial_number;
@@ -568,24 +571,49 @@ class Invoice extends BaseController
$records['template_name'] = 'approve_template';
$records['item'] = $details['item'];
+ // print_r($records['item']);die;
+ $lineitem_html="";
+ foreach ($records['item'] as $inv) {
+ // print_r($item->title);die;
+ $lineitem_html.='
'.$inv->title. ' x ' .$inv->quantity .' => ' .$inv->subtotal.'
';
+
+
+ }
+ // print_r($title);die;
$records['subject'] = $invoice_serial_number . " - Approval Notification";
- $records['description'] = "VBP Approve Information
- Dear $recipient_name,
- We are pleased to inform you that your Invoice has been approved.
- Details:
- - Approval Date:" . $approval_date . "
- - Approved By:" . $approved_by . "
- - Reference ID:" . $reference_number . "
-
- Best regards,
-
- - ".$business_name.",
- - ".$business_address." ".$business_city." ".$business_state." - ".$business_postal_code."
- - Call Us: +91 ".$business_mobile_no."
- - Email Us: ".$business_email."
";
-
- $template = "Dear " . $recipient_name . ",\r\r\n\nYour Invoice has been approved.\n\nDetails:\r\n- Approval Date: " . $approval_date . "\r\n- Approved By: " . $approved_by . "\r\n- Reference ID: " . $reference_number . "\r\n\nBest regards,\n".$business_name.",\n".$business_address." ".$business_city." ".$business_state." - ".$business_postal_code.".\nCall Us: +91 ".$business_mobile_no."\nEmail Us:".$business_email;
+ $records['description'] = "
+
+
+
+

+
THANKS FOR YOUR ORDER!!
+
Order Number:#$invoice_serial_number
+
Total Amount:$total_amount
+
+
+
Download Invoice
+
+
Thank you for choosing us!
+
+ - $business_name
+ - $business_address $business_city $business_state - $business_postal_code
+ - Call Us: +91 $business_mobile_no
+ - Email Us: $business_email
+
+
+
+ ";
+
+ // print_r($records['description']);die;
+ $url = base_url("download_invoice_pdf/" . md5($invoice_id));
+$encodedUrl = urlencode($url);
+ $template = "Dear " . $recipient_name . ",\r\r\n\nYour Invoice has been generated.\n\nDetails:\r\n- Invoice Date: " . $invoiceDate . "\r\n- Invoice Number: " . $invoice_serial_number . "\r\n- Click here to download the Invoice: " . base_url("download_invoice_pdf/" .$encodedUrl);
$params = (object) Null;
$params->number = (int)'91' . $recipient_mobile;
@@ -604,6 +632,7 @@ class Invoice extends BaseController
## To Generate Invoice PDF based on invoice ID
public function generate_invoice_pdf($id)
{
+ // echo "hello"; die;
// Fetch the invoice data based on $invoice_id
$model = new InvoiceModel();
$data = $model->getInvoiceData($id);
@@ -629,6 +658,9 @@ class Invoice extends BaseController
$mpdf->SetTitle('Invoice');
$mpdf->SetAuthor($data[0]->company_name);
$mpdf->SetCreator('');
+ $htmlFooter='
+
';
+ $mpdf->setHTMLFooter($htmlFooter);
// Generate the PDF content (HTML)
if ($data[0]->status === 'Draft') {
@@ -691,24 +723,35 @@ class Invoice extends BaseController
}
public function general_inv_rp()
- {
+ {
$model = new InvoiceModel();
- if($this->request->is('get'))
- {
+
+ if ($this->request->is('get')) {
$data['report_data'] = $model->get_general_invoice_data();
$data['selected_data'] = "";
- }
- else
- {
- $dateParts = explode(' - ', $this->request->getVar('date') );
+ } else {
+ $dateParts = explode(' - ', $this->request->getVar('date'));
$fromDate = $dateParts[0];
$toDate = $dateParts[1];
- $data['report_data'] = $model->get_general_invoice_data( date("Y-m-d", strtotime($fromDate)) , date("Y-m-d", strtotime($toDate)) );
+
+ // Update date conversion format using the global namespace
+ $fromDate = \DateTime::createFromFormat('d/m/Y', $fromDate)->format('Y-m-d');
+ $toDate = \DateTime::createFromFormat('d/m/Y', $toDate)->format('Y-m-d');
+
+ // Debugging statements for date range
+ var_dump($fromDate, $toDate);
+
+ $data['report_data'] = $model->get_general_invoice_data($fromDate, $toDate);
$data['selected_data'] = $this->request->getVar('date');
}
- $data['page_name'] = 'General Invoice Report';
+
+ // Debugging statement for report data
+ // var_dump($data['report_data']);
+
+ $data['page_name'] = 'Sales Report';
$this->render_page('report_general_invoice', $data);
}
+
public function general_membership_inv_rp()
{
@@ -736,6 +779,34 @@ class Invoice extends BaseController
$this->render_page('report_mem_invoice', $data);
}
}
+ public function expired_customer_report()
+ {
+
+ if($this->request->getmethod() == 'get')
+ {
+ $model = new InvoiceModel();
+ $data['expired_customers'] = $model->getExpiredCustomers();
+
+ $this->logger->info("'Membership Renewals Report'");
+ $data['page_name'] = 'Membership Renewals Report';
+ $this->render_page('report_expired_customers', $data);
+ }
+ else
+ {
+ $dateParts = explode(' - ', $this->request->getVar('date') );
+ $fromDate = $dateParts[0];
+ $toDate = $dateParts[1];
+
+ $dateTime = \DateTime::createFromFormat('m/d/Y', $fromDate);
+ $dateTime1 = \DateTime::createFromFormat('m/d/Y', $toDate);
+ $model = new InvoiceModel();
+ $data['expired_customers'] = $model->getExpiredCustomers( $dateTime->format('Y-m-d') , $dateTime1->format('Y-m-d') );
+ $this->logger->info("Itemwise Report ");
+ $this->logger->info("'Membership Renewals Report'");
+ $data['page_name'] = 'Membership Renewals Report';
+ $this->render_page('report_expired_customers', $data);
+ }
+}
public function itemwise_report()
{
@@ -744,7 +815,7 @@ class Invoice extends BaseController
$model = new InvoiceModel();
$data['report_data'] = $model->itemwise_report_data();
$this->logger->info("Itemwise Report ");
- $data['page_name'] = 'Itemwise Report';
+ $data['page_name'] = 'Bookswise Report';
$this->render_page('report_itemwise', $data);
}
else
@@ -758,13 +829,42 @@ class Invoice extends BaseController
$model = new InvoiceModel();
$data['report_data'] = $model->itemwise_report_data( $dateTime->format('Y-m-d') , $dateTime1->format('Y-m-d') );
$this->logger->info("Itemwise Report ");
- $data['page_name'] = 'Itemwise Report';
+ $data['page_name'] = 'Bookswise Report';
$data['selected_data'] = $this->request->getVar('date');
$this->render_page('report_itemwise', $data);
}
}
-}
+ public function book_publishwise_Report()
+ {
+ if($this->request->getmethod() == 'get')
+ {
+ $model = new InvoiceModel();
+ $data['report_data'] = $model->itemwise_report_data_with_publish_code();
+ $this->logger->info("Itemwise Report ");
+ $data['page_name'] = 'Bookswise Report';
+ // print_r($data);die;
+ $this->render_page('report_book_publish', $data);
+ }
+ else
+ {
+ $dateParts = explode(' - ', $this->request->getVar('date') );
+ $fromDate = $dateParts[0];
+ $toDate = $dateParts[1];
+
+ $dateTime = \DateTime::createFromFormat('m/d/Y', $fromDate);
+ $dateTime1 = \DateTime::createFromFormat('m/d/Y', $toDate);
+ $model = new InvoiceModel();
+ $data['report_data'] = $model->itemwise_report_data_with_publish_code( $dateTime->format('Y-m-d') , $dateTime1->format('Y-m-d') );
+ $this->logger->info("Itemwise Report ");
+ $data['page_name'] = 'Bookswise Report';
+ $data['selected_data'] = $this->request->getVar('date');
+ $this->render_page('report_book_publish', $data);
+ }
+
+ }
+
+
// public function generate_invoice_pdf($id)
// {
@@ -799,4 +899,60 @@ class Invoice extends BaseController
// }
+ // Fetch the invoice data based on $invoice_id
+ public function download_invoice_pdf($md5Hash)
+ {
+ $model = new InvoiceModel();
+ // Retrieve the invoice ID from the MD5 hash
+ $invoice_id = $model->getInvoiceIdByMd5($md5Hash);
+ // Check if the MD5 hash is valid and the invoice ID exists
+ if ($invoice_id) {
+ // Fetch the invoice data based on $invoice_id
+
+ $data = $model->getInvoiceData($invoice_id);
+ $invoiceItems = $model->getInvoiceItems($invoice_id, 'groupby');
+ foreach ($invoiceItems as $index => $singleItem) {
+ $productImgs = $model->getProductImgs($singleItem->product);
+ $invoiceItems[$index]->imgs = $productImgs;
+ }
+
+ $invoice_type = $data[0]->invoice_type;
+
+ // Create an mPDF object
+ $mpdf = new Mpdf();
+ $mpdf->autoLangToFont = true;
+ $mpdf->autoScriptToLang = true;
+
+ // Set PDF properties
+ $mpdf->SetTitle('Invoice');
+ $mpdf->SetAuthor($data[0]->company_name);
+ $mpdf->SetCreator('');
+ $htmlFooter = '
+
';
+ $mpdf->setHTMLFooter($htmlFooter);
+
+ // Generate the PDF content (HTML) with data
+ $html = view('invoice_pdf_template', ['data' => $data, 'invoiceItems' => $invoiceItems, 'invoice_type' => $invoice_type, 'invoiceTerms' => $data]);
+
+ // Load HTML into the mPDF instance
+ $mpdf->WriteHTML($html);
+
+ // Output the PDF to the browser for download
+ $mpdf->Output("invoice_" . date('Y-m-d H-i-s') . '.pdf', 'D');
+}else{
+ echo "no code works";
+}
+
+
+}
+private function getInvoiceIdByMd5($md5Hash)
+{
+
+ // Assuming you have a table named 'invoices' with columns 'invoice_id' and 'md5_hash'
+ $result = $this->db->table('invoices')->select('invoice_id')->where('md5_hash', $md5Hash)->get()->getRow();
+
+ return $result ? $result->invoice_id : null;
+}
+
+}
diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php
index 9fb3a419..e58e5f9e 100755
--- a/app/Controllers/Notifications.php
+++ b/app/Controllers/Notifications.php
@@ -452,6 +452,7 @@ class Notifications extends BaseController
################################################################
public function getExpCustomerDetail($window_time = null)
{
+ echo "hi";die;
# Step 1: add the days to retrive the data//
$providedDate = date('Y-m-d');
$newDate = date('Y-m-d', strtotime($providedDate . ' + ' . $window_time . ' days'));
@@ -839,7 +840,7 @@ class Notifications extends BaseController
public function noifications_acknowlegdement(){
$model = new NotificationModel();
$data['noifications_acknowlegdement'] = $model->get_noifications_acknowlegdement_data();
- $data['page_name'] = 'Notifications Acknowlegdement';
+ $data['page_name'] = 'Notifications Status';
$this->render_page('noifications_acknowlegdement', $data);
}
############## Notification Acknowlegdement Ends ################
diff --git a/app/Controllers/Scheme.php b/app/Controllers/Scheme.php
index 5ce095e5..0aea6854 100644
--- a/app/Controllers/Scheme.php
+++ b/app/Controllers/Scheme.php
@@ -68,6 +68,7 @@ class Scheme extends BaseController
'price' => $this->request->getPost('sprice'),
'duration' => $this->request->getPost('sduration'),
'sku' => $this->request->getPost('sku'),
+ 'short_code'=>$this->request->getpost('short_code'),
'business_id' => $this->request->getPost('business_id')
];
diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php
index 96c18c5f..dde3724e 100644
--- a/app/Controllers/Subscription.php
+++ b/app/Controllers/Subscription.php
@@ -124,7 +124,10 @@ public function add_subscription() {
public function download_details()
{
$selectedSchemes = $this->request->getPost('selected_schemes');
+ $downloadType = $this->request->getPost('download_type');
+
$action = $this->request->getPost('action');
+
// Initialize an empty PDF with custom paper size (4x6 inches)
$config = [
'mode' => 'utf-8',
@@ -151,47 +154,59 @@ public function download_details()
'margin_footer' => 0,
];
-
- if($action == 1) $pdf = new Mpdf($config);
+ if ($action == 1) $pdf = new Mpdf($config);
else $pdf = new Mpdf($configa4);
+
$customerDetails = [];
+
// Iterate through selected schemes
if (!empty($selectedSchemes)) {
- foreach ($selectedSchemes as $selectedScheme) {
- // Call the model method to get customer details for each selected scheme
- $subscriptionModel = new SubscriptionModel();
- $details = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme);
- $customerDetails = array_merge($customerDetails, $details);
- }
-
+ foreach ($selectedSchemes as $selectedScheme) {
+ // Call the model method to get customer details for each selected scheme and download type
+ $subscriptionModel = new SubscriptionModel();
+
+ if ($downloadType === 'active') {
+ $details = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme);
+ } elseif ($downloadType === 'expired') {
+ $details = $subscriptionModel->getAllExpiredCustomerDetailsByScheme($selectedScheme);
+ } elseif ($downloadType === 'both') {
+
+ $details =$subscriptionModel->getBothDetailsSchemeName($selectedScheme);
+ }
+
+ $customerDetails = array_merge($customerDetails, $details);
+ }
+
if (!empty($customerDetails)) {
- $html = view('print_addresses_form', ['customerDetails' => $customerDetails , 'action' => $action , 'pdf' => $pdf]);
- // Add the current scheme's details to the PDF
- // echo $html;die;
- // $pdf->AddPage();
+ // Pass customer details, action, and pdf to the view
+ $html = view('print_addresses_form', ['customerDetails' => $customerDetails, 'action' => $action, 'pdf' => $pdf]);
+ // Add the details to the PDF
$pdf->WriteHTML($html);
+
// Set the PDF filename
$filename = 'CustomerDetails_' . date('YmdHis') . '.pdf';
// Output the PDF for download
$pdf->Output($filename, 'D');
- $this->logger->info("Print Addresses (Scheme) : Downloaded = ".$filename);
+ $this->logger->info("Print Addresses (Scheme): Downloaded = " . $filename);
} else {
- $this->logger->info("Print Addresses (Scheme) : Details Not Available ");
+ // Handle case when customer details are not available
+ $this->logger->info("Print Addresses (Scheme): Details Not Available");
echo "";
echo "";
}
} else {
- $this->logger->info("Print Addresses (Scheme) : Schemes Not Choosen ");
- echo "";
+ // Handle case when no schemes are chosen
+ $this->logger->info("Print Addresses (Scheme): Schemes Not Chosen");
+ echo "";
echo "";
}
-
}
+
}
// public function generate_pdf()
// {
diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php
index 24850a4d..b9f502d0 100755
--- a/app/Controllers/Users.php
+++ b/app/Controllers/Users.php
@@ -202,6 +202,7 @@ class Users extends BaseController
'last_name' => $this->request->getPost('last_name'),
'mobile_no' => $this->request->getPost('mobile_no'),
'date_of_birth' => NULL,
+ 'event_id' => $this->request->getPost('event_id'),
'address' => $this->request->getPost('address'),
'gender' => $this->request->getPost('gender'),
'business_id' => $business_id
@@ -290,4 +291,13 @@ class Users extends BaseController
}
return redirect()->route('user_list');
}
+ public function fetch_event_names()
+ {
+ $usersModel = new UsersModel();
+ $eventNames = $usersModel->getEventName();
+
+ return $this->response->setJSON(['eventNames' => $eventNames]);
+ }
+
+
}
diff --git a/app/Controllers/email_temp.php b/app/Controllers/email_temp.php
new file mode 100644
index 00000000..dafc6968
--- /dev/null
+++ b/app/Controllers/email_temp.php
@@ -0,0 +1,33 @@
+
+
+
+
+ Order Confirmed
+
+
+
+
Order Confirmed
+
Thank you for your order! Your invoice has been successfully approved.
+
Order Details:
+ $lineitem_html
+
+
+ - Order Date:
+ - Confirmed By:
+ - Order Reference ID:
+
+
+
+
+
Download Invoice
+
+
Thank you for choosing us!
+
+ - ,
+ - $business_address $business_city $business_state - $business_postal_code
+ - Call Us: +91 $business_mobile_no
+ - Email Us: $business_email
+
+
+
+
diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php
index ad56128e..2aa8f949 100644
--- a/app/Models/InvoiceModel.php
+++ b/app/Models/InvoiceModel.php
@@ -95,25 +95,31 @@ public function existsSubscriptionDetails($where){
}
}
- public function getSubscriptionInvoiceDetail($where)
- {
- $result = $this->getJoinedData($where);
- if(!empty($result)){
- foreach ($result as $i => $item) {
- $invoiceId = $item['invoice_id'];
- $scheme_name = [];
- $invoiceItems = $this->getInvoiceItems($invoiceId,'');
- foreach ($invoiceItems as $j => $child) {
- if ($child->category_name == 'Membership') {
- $scheme_name[] = $child->title;
- }
+public function getSubscriptionInvoiceDetail($where)
+{
+ $result = $this->getJoinedData($where);
+ if (!empty($result)) {
+ foreach ($result as $i => $item) {
+ $invoiceId = $item['invoice_id'];
+ $schemes = [];
+ $invoiceItems = $this->getInvoiceItems($invoiceId, '');
+ foreach ($invoiceItems as $j => $child) {
+ if ($child->category_name == 'Membership') {
+ $schemes[] = [
+ 'scheme_name' => $child->title,
+ 'scheme_code' => $child->short_code, // Update this line to use the correct property
+ ];
}
- $result[$i]['scheme_name'] = !empty($scheme_name) ? implode(", ", $scheme_name) : '';
- $result[$i]['invoice_items_details'] = $invoiceItems;
}
+ $result[$i]['scheme_name'] = !empty($schemes) ? implode(", ", array_column($schemes, 'scheme_name')) : '';
+ $result[$i]['scheme_code'] = !empty($schemes) ? implode(", ", array_column($schemes, 'scheme_code')) : '';
+
+ $result[$i]['invoice_items_details'] = $invoiceItems;
}
- return $result;
}
+ return $result;
+}
+
public function getJoinedData($where)
{
@@ -324,7 +330,7 @@ public function get_general_invoice_data($f_date = null, $t_date = null)
$query = $this->db->table('invoice')
->select('invoice.*,DATE_FORMAT(invoice.invoice_date, "%d/%m/%Y") AS formatted_invoice_date, customers.*, COUNT(invoiceitems.product) as item_count')
->where('invoice.isactive', 1)
- ->where('invoice.invoice_type', 1)
+
->where('invoiceitems.isactive', 1);
// Add date range filter if provided
@@ -394,6 +400,67 @@ public function itemwise_report_data($f_date = null, $t_date = null)
return $result;
}
+public function getInvoiceIdByMd5($md5Hash)
+{
+ $result = $this->db->table($this->table)
+ ->select('invoice_id')
+ ->get()
+ ->getResult();
+
+ foreach ($result as $row) {
+ if (md5($row->invoice_id) === $md5Hash) {
+ return $row->invoice_id;
+ }
+ }
+
+ return null;
+}
+public function getExpiredCustomers($f_date = null, $t_date = null)
+{
+ $now = date('Y-m-d');
+ $query = $this->db->table('subscription as S'); // Define $query here
+
+ if ($f_date !== null && $t_date !== null) {
+ $query->where('S.to_subscription >=', $f_date)
+ ->where('S.to_subscription <=', $t_date);
+ }
+
+ $result = $query
+ ->select('S.customer_id,S.sub_id, S.from_subscription, S.to_subscription, C.first_name, C.last_name, C.email, C.mobile_no, S.scheme_id,books.short_code')
+ ->join('customers as C', 'C.customer_id = S.customer_id', 'left')
+ ->join('books', 'books.book_id = S.scheme_id', 'left')
+ ->where('S.isactive', 1)
+ ->where('S.to_subscription <=', $now)
+ ->get()
+ ->getResultArray();
+
+ return $result;
+
+}
+public function itemwise_report_data_with_publish_code($f_date = null, $t_date = null)
+{
+ // Fetch invoice data
+ $query = $this->db->table('invoice')
+ ->select('invoice.*, books.* , COUNT(invoiceitems.product) as item_count , sum(invoiceitems.product * invoiceitems.unit_price) as item_cost')
+ ->where('invoice.isactive', 1)
+ ->where('books.isactive', 1)
+ ->where('books.publishers_code', 'VJB'); // Additional condition for publish_code
+
+ // Add date range filter if provided
+ if ($f_date !== null && $t_date !== null) {
+ $query->where('invoice.invoice_date >=', $f_date)
+ ->where('invoice.invoice_date <=', $t_date);
+ }
+
+ $result = $query->join('invoiceitems', 'invoiceitems.invoice_id = invoice.invoice_id', 'left')
+ ->join('books', 'books.book_id = invoiceitems.product', 'left')
+ ->groupBy('books.book_id')
+ ->get()
+ ->getResult();
+ // print_r($result);die;
+
+ return $result;
}
+}
diff --git a/app/Models/SchemeModel.php b/app/Models/SchemeModel.php
index eef0182c..4a9fa130 100644
--- a/app/Models/SchemeModel.php
+++ b/app/Models/SchemeModel.php
@@ -9,7 +9,7 @@ class SchemeModel extends Model
{
protected $table = 'books';
protected $primaryKey = 'book_id';
- protected $allowedFields = ['book_id ','title','sku','description','price','features','duration','business_id','updated_by','category','isactive','created_by'];
+ protected $allowedFields = ['book_id ','title','sku','description','price','features','short_code','duration','business_id','updated_by','category','isactive','created_by'];
public function insertScheme($data)
{
@@ -20,7 +20,7 @@ class SchemeModel extends Model
public function getSchemeNamesAndDurationsByBusiness($business_id)
{
$builder = $this->builder();
- $builder->select('books.book_id, books.title, books.price, books.duration, category.name as category_name');
+ $builder->select('books.book_id, books.title,books.short_code, books.price, books.duration, category.name as category_name');
$builder->join('book_categories', 'book_categories.book_id = books.book_id', 'left');
$builder->join('category', 'category.id = book_categories.category_id', 'left');
$builder->where('books.business_id', $business_id);
@@ -37,7 +37,8 @@ class SchemeModel extends Model
'price' => $row->price,
'duration' => $row->duration,
'category_name' => $row->category_name,
- 'book_id'=>$row->book_id
+ 'book_id'=>$row->book_id,
+ 'short_code'=>$row->short_code,
];
}
diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php
index 451d8b3c..6408a3c2 100644
--- a/app/Models/SubscriptionModel.php
+++ b/app/Models/SubscriptionModel.php
@@ -88,6 +88,7 @@ public function getCustomerAddressesBySchemeName($schemeName)
}
public function getAllCustomerDetailsBySchemeName($schemeName)
{
+ $currentDate = date('Y-m-d');
$builder = $this->db->table('subscription');
$builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name,customer_addresses.mobile_no, customer_addresses.address_1,customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code,business.title as business_name,business.address as business_address,business.city as business_city,business.state as business_state,business.postal_code as business_postal_code,books.title,from_subscription,to_subscription,business.title as business_name,business.mobile_no as business_mobile_no,states.state_name');
$builder->join('customers', 'customers.customer_id = subscription.customer_id');
@@ -96,12 +97,13 @@ public function getAllCustomerDetailsBySchemeName($schemeName)
$builder->join('books', 'books.book_id = subscription.scheme_id');
$builder->join('states', 'states.state_short_name = customer_addresses.state');
$builder->where('books.title', $schemeName);
+ $builder->where('subscription.to_subscription >=', $currentDate);
$builder->where('customer_addresses.address_type', 2); // Filter by address_type 2
$builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers
// Fetch the query result
$query = $builder->get();
-
+// print_r($query);die;
$customerDetails = [];
if ($query->getNumRows() > 0) {
@@ -150,6 +152,197 @@ public function getAllCustomerDetailsBySchemeName($schemeName)
return $customerDetails;
}
+public function getAllActiveCustomerDetails($selectedScheme)
+{
+ // $currentDate = date('Y-m-d');
+
+ $builder = $this->db->table('subscription');
+ $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.mobile_no, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code, business.title as business_name, books.title, from_subscription, to_subscription, business.mobile_no as business_mobile_no, business.address as business_address,business.city as business_city,business.state as business_state,business.postal_code as business_postal_code,books.title,from_subscription,to_subscription,business.title as business_name,business.mobile_no as business_mobile_no,states.state_name');
+ $builder->join('customers', 'customers.customer_id = subscription.customer_id');
+ $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id');
+ $builder->join('business', 'business.business_id = subscription.business_id');
+ $builder->join('books', 'books.book_id = subscription.scheme_id');
+ $builder->join('states', 'states.state_short_name = customer_addresses.state');
+ // Active subscriptions only
+ $builder->where('books.title', $schemeName);
+ $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2
+ $builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers
+
+ $query = $builder->get();
+
+ $activeCustomerDetails = [];
+
+ if ($query->getNumRows() > 0) {
+ $currentCustomerID = null;
+ $shippingAddress = [];
+
+ foreach ($query->getResultArray() as $row) {
+ $customerID = $row['customer_id'];
+
+ if ($currentCustomerID !== $customerID) {
+ // New customer, add the previous customer's details (if any)
+ if (!empty($shippingAddress)) {
+ $activeCustomerDetails[] = $shippingAddress;
+ }
+
+ // Start a new customer's details
+ $shippingAddress = [
+ 'customer_name' => $row['customer_name'],
+ 'address_1' => $row['address_1'],
+ 'address_2' => $row['address_2'],
+ 'mobile_no' => $row['mobile_no'],
+ 'city' => $row['city'],
+ 'state' => $row['state'],
+ 'state_name' => $row['state_name'] != "" ? $row['state_name'] : $row['state'],
+ 'postal_code' => $row['postal_code'],
+ 'title' => $row['title'],
+ 'to_subscription' => $row['to_subscription'],
+ 'company_name' => $row['business_name'],
+ 'company_mobile_no' => $row['business_mobile_no'],
+ 'company_city'=>$row['business_city'],
+
+ ];
+
+ $currentCustomerID = $customerID;
+ }
+ }
+
+ // Add the last customer's details (if any)
+ if (!empty($shippingAddress)) {
+ $activeCustomerDetails[] = $shippingAddress;
+ }
+ }
+
+ return $activeCustomerDetails;
+}
+
+public function getAllExpiredCustomerDetailsByScheme($schemeName)
+{
+ $currentDate = date('Y-m-d');
+
+ $builder = $this->db->table('subscription');
+ $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.mobile_no, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code, business.title as business_name, books.title, from_subscription, to_subscription, business.mobile_no as business_mobile_no, states.state_name');
+ $builder->join('customers', 'customers.customer_id = subscription.customer_id');
+ $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id');
+ $builder->join('business', 'business.business_id = subscription.business_id');
+ $builder->join('books', 'books.book_id = subscription.scheme_id');
+ $builder->join('states', 'states.state_short_name = customer_addresses.state');
+ $builder->where('books.title', $schemeName);
+ $builder->where('subscription.to_subscription <', $currentDate); // Expired subscriptions only
+ $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2
+ $builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers
+
+ // Fetch the query result
+ $query = $builder->get();
+
+ $customerDetails = [];
+
+ if ($query->getNumRows() > 0) {
+ $currentCustomerID = null;
+ $shippingAddress = [];
+
+ foreach ($query->getResultArray() as $row) {
+ $customerID = $row['customer_id'];
+
+ if ($currentCustomerID !== $customerID) {
+ // New customer, add the previous customer's details (if any)
+ if (!empty($shippingAddress)) {
+ $customerDetails[] = $shippingAddress;
+ }
+
+ // Start a new customer's details
+ $shippingAddress = [
+ 'customer_name' => $row['customer_name'],
+ 'address_1' => $row['address_1'],
+ 'address_2' => $row['address_2'],
+ 'mobile_no' => $row['mobile_no'],
+ 'city' => $row['city'],
+ 'state' => $row['state'],
+ 'state_name' => $row['state_name'] != "" ? $row['state_name'] : $row['state'],
+ 'postal_code' => $row['postal_code'],
+ 'title' => $row['title'],
+ 'to_subscription' => $row['to_subscription'],
+ 'company_name' => $row['business_name'],
+ 'company_mobile_no' => $row['business_mobile_no'],
+ ];
+
+ $currentCustomerID = $customerID;
+ }
+ }
+
+ // Add the last customer's details (if any)
+ if (!empty($shippingAddress)) {
+ $customerDetails[] = $shippingAddress;
+ }
+ }
+
+ return $customerDetails;
+}
+public function getBothDetailsSchemeName($schemeName)
+{
+ $builder = $this->db->table('subscription');
+ $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.mobile_no, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code, business.title as business_name, books.title, from_subscription, to_subscription, business.mobile_no as business_mobile_no, business.address as business_address, business.city as business_city, business.state as business_state, business.postal_code as business_postal_code, books.title, states.state_name');
+ $builder->join('customers', 'customers.customer_id = subscription.customer_id');
+ $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id');
+ $builder->join('business', 'business.business_id = subscription.business_id');
+ $builder->join('books', 'books.book_id = subscription.scheme_id');
+ $builder->join('states', 'states.state_short_name = customer_addresses.state');
+ $builder->where('books.title', $schemeName);
+ $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2
+ $builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers
+
+ $query = $builder->get();
+
+ $customerDetails = [];
+
+ if ($query->getNumRows() > 0) {
+ $currentCustomerID = null;
+ $shippingAddress = [];
+
+ foreach ($query->getResultArray() as $row) {
+ // print_r($row);die;
+ $customerID = $row['customer_id'];
+
+ if ($currentCustomerID !== $customerID) {
+ // New customer, add the previous customer's details (if any)
+ if (!empty($shippingAddress)) {
+ $customerDetails[]= $shippingAddress;
+ }
+
+ // Start a new customer's details
+ $shippingAddress = [
+ 'customer_name' => $row['customer_name'],
+ 'address_1' => $row['address_1'],
+ 'address_2' => $row['address_2'],
+ 'mobile_no' => $row['mobile_no'],
+ 'city' => $row['city'],
+ 'state' => $row['state'],
+ 'state_name' => $row['state_name'] != "" ? $row['state_name'] : $row['state'],
+ 'postal_code' => $row['postal_code'],
+ 'title' => $row['title'],
+ 'to_subscription' => $row['to_subscription'],
+ 'company_name' => $row['business_name'],
+ 'company_mobile_no' => $row['business_mobile_no'],
+ 'company_city' => $row['business_city'],
+ 'company_state' => $row['business_state'],
+ 'company_postal_code' => $row['business_postal_code'],
+ ];
+
+ $currentCustomerID = $customerID;
+ }
+ }
+
+ // Add the last customer's details (if any)
+ if (!empty($shippingAddress)) {
+ $customerDetails[] = $shippingAddress;
+ }
+ }
+
+ return $customerDetails;
+}
+
+
+
}
diff --git a/app/Models/UsersModel.php b/app/Models/UsersModel.php
index 6c467271..3d485978 100644
--- a/app/Models/UsersModel.php
+++ b/app/Models/UsersModel.php
@@ -5,7 +5,7 @@ class UsersModel extends Model
{
protected $table = 'users';
protected $primaryKey = 'user_id';
- protected $allowedFields = ['user_id','user_name','email','first_name','last_name','password','mobile_no','date_of_birth','address','gender','profile_picture','city','state','postal_code','country','role','isactive','business_id','created_by','updated_by'];
+ protected $allowedFields = ['user_id','user_name','email','event_id','first_name','last_name','password','mobile_no','date_of_birth','address','gender','profile_picture','city','state','postal_code','country','role','isactive','business_id','created_by','updated_by'];
public function saveData($data, $id = null)
{
@@ -17,6 +17,17 @@ class UsersModel extends Model
return $this->update($id, $data);
}
}
+ public function getEventName()
+ {
+
+ return $this->db->table('events')
+ ->select('events.*')
+
+ ->get()
+ ->getResult();
+ print_r($this->db->getLastQuery());die;
+
+ }
}
diff --git a/app/Views/business_form.php b/app/Views/business_form.php
index fb9ca211..09085d5d 100644
--- a/app/Views/business_form.php
+++ b/app/Views/business_form.php
@@ -119,6 +119,10 @@
+ ">
+
+ Invoice Number Format
+