diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 046a54a1..a9765430 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -28,6 +28,8 @@ class Home extends BaseController // $data['active_category'] = $model->schemes(); $data['active_schemes'] = $model->active_schemes(); $data['expiring_membership'] = $model->expiring_membership_list(); + $data['notifications'] = $model->expiring_membership_list(); + // print_r( $data['expiring_membership']);die; // $data['active_category'] = array_filter($model->schemes(), function ($element) { // return $element['count'] !== '0' ; // }); diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 37cb69e5..2f0b6b36 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -835,6 +835,14 @@ $encodedUrl = urlencode($url); } } + private function calculateTotalBookQuantity(&$reportData) +{ + // Calculate the total book quantity for each publisher + foreach ($reportData as &$row) { + $totalBookQuantity = array_sum(array_column($row->books, 'quantity')); + $row->total_book_quantity = $totalBookQuantity; + } +} public function book_publishwise_Report() { if($this->request->getmethod() == 'get') diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index e58e5f9e..b194dc34 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -452,7 +452,7 @@ class Notifications extends BaseController ################################################################ public function getExpCustomerDetail($window_time = null) { - echo "hi";die; + echo "hi"; # Step 1: add the days to retrive the data// $providedDate = date('Y-m-d'); $newDate = date('Y-m-d', strtotime($providedDate . ' + ' . $window_time . ' days')); diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php index affa89d1..2652e238 100644 --- a/app/Models/HomeModel.php +++ b/app/Models/HomeModel.php @@ -25,6 +25,27 @@ class HomeModel extends Model return $customer; } + // public function invoice_dtls() { + // if ((int)date('m') <= 3) { + // $invoice['financial_year'] = (date('Y')-1) . '-' . date('Y'); + // $start_date = (date('Y')-1).'-04-01'; + // $end_date = date('Y').'-03-31'; + // } else { + // $invoice['financial_year'] = date('Y') . '-' . (date('Y') + 1); + // $start_date = date('Y').'-04-01'; + // $end_date = (date('Y')+1).'-03-31'; + // } + // $date_where = ['DATE(created_on)' => date('Y-m-d'),'isactive'=>1]; + // $date_query = $this->db->table('invoice')->where($date_where)->countAllResults(); + // $month_where = ['MONTH(created_on)' => date('m'),'isactive'=>1]; + // $month_query = $this->db->table('invoice')->where($month_where)->countAllResults(); + // $fin_year_where = ['DATE(created_on) >= ' => $start_date , 'DATE(created_on) <= ' => $end_date,'isactive'=>1]; + // $fin_year_query = $this->db->table('invoice')->where($fin_year_where)->countAllResults(); + // $invoice['today'] = $date_query; + // $invoice['month'] = $month_query; + // $invoice['year'] = $fin_year_query; + // return $invoice; + // } public function invoice_dtls() { if ((int)date('m') <= 3) { $invoice['financial_year'] = (date('Y')-1) . '-' . date('Y'); @@ -35,17 +56,38 @@ class HomeModel extends Model $start_date = date('Y').'-04-01'; $end_date = (date('Y')+1).'-03-31'; } - $date_where = ['DATE(created_on)' => date('Y-m-d'),'isactive'=>1]; + + // Today + $date_where = ['DATE(created_on)' => date('Y-m-d'), 'invoice_type' => 1, 'isactive' => 1]; $date_query = $this->db->table('invoice')->where($date_where)->countAllResults(); - $month_where = ['MONTH(created_on)' => date('m'),'isactive'=>1]; + $date_amount_query = $this->db->table('invoice')->selectSum('total_amount')->where($date_where)->get()->getRowArray(); + $invoice['today'] = [ + 'count' => $date_query, + 'total_amount' => $date_amount_query['total_amount'] ?? 0, + ]; + + // Current Month + $month_where = ['MONTH(created_on)' => date('m'), 'invoice_type' => 1, 'isactive' => 1]; $month_query = $this->db->table('invoice')->where($month_where)->countAllResults(); - $fin_year_where = ['DATE(created_on) >= ' => $start_date , 'DATE(created_on) <= ' => $end_date,'isactive'=>1]; + $month_amount_query = $this->db->table('invoice')->selectSum('total_amount')->where($month_where)->get()->getRowArray(); + $invoice['month'] = [ + 'count' => $month_query, + 'total_amount' => $month_amount_query['total_amount'] ?? 0, + ]; + + // Current Financial Year + $fin_year_where = ['DATE(created_on) >=' => $start_date, 'DATE(created_on) <=' => $end_date, 'invoice_type' => 1, 'isactive' => 1]; $fin_year_query = $this->db->table('invoice')->where($fin_year_where)->countAllResults(); - $invoice['today'] = $date_query; - $invoice['month'] = $month_query; - $invoice['year'] = $fin_year_query; + $fin_year_amount_query = $this->db->table('invoice')->selectSum('total_amount')->where($fin_year_where)->get()->getRowArray(); + $invoice['year'] = [ + 'count' => $fin_year_query, + 'total_amount' => $fin_year_amount_query['total_amount'] ?? 0, + ]; + + // print_r($invoice);die; return $invoice; } + // public function schemes(){ // $query = $this->db->table('category AS C') @@ -60,41 +102,78 @@ class HomeModel extends Model public function active_schemes() { $query = $this->db->table('subscription AS S') - ->select('S.business_id,BK.title as name,BK.book_id as id,S.scheme_id,LEFT(BK.title, 1) AS first_letter,COUNT(S.customer_id) AS count,BI.wp_img_url') - //->select('COUNT(S.customer_id) AS overall,COUNT(IF(S.isactive = 0, S.customer_id, NULL)) AS nonrenewal,COUNT(IF(S.isactive = 1, S.customer_id, NULL)) AS renewal') - //->select('COUNT(IF(S.isactive = 1, S.customer_id, NULL)) AS overall,COUNT(IF(S.is_renew = 0 AND S.isactive = 1, S.customer_id, NULL)) AS nonrenewal,COUNT(IF(S.is_renew = 1 AND S.isactive = 1, S.customer_id, NULL)) AS renewal') - ->select('COUNT(S.customer_id) AS overall,COUNT(IF(S.isactive = 1, S.customer_id, NULL)) AS activeoverall,COUNT(IF(S.is_renew = 0 AND S.isactive = 1, S.customer_id, NULL)) AS nonrenewal,COUNT(IF(S.is_renew = 1 AND S.isactive = 1, S.customer_id, NULL)) AS renewal') + ->select('S.business_id, BK.title as name, BK.short_code, BK.book_id as id, S.scheme_id, LEFT(BK.title, 1) AS first_letter, COUNT(S.customer_id) AS count, BI.wp_img_url') + ->select('COUNT(S.customer_id) AS overall, COUNT(IF(S.isactive = 1, S.customer_id, NULL)) AS activeoverall, COUNT(IF(S.is_renew = 0 AND S.isactive = 1, S.customer_id, NULL)) AS nonrenewal, COUNT(IF(S.is_renew = 1 AND S.isactive = 1, S.customer_id, NULL)) AS renewal, SUM(CASE WHEN S.created_on >= NOW() - INTERVAL 30 DAY THEN 1 ELSE 0 END) AS new_subscribers') ->join('customers AS C', 'C.customer_id = S.customer_id AND C.isactive = 1', 'left') ->join('books AS BK', 'BK.book_id = S.scheme_id', 'left') ->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' => 2,'BK.isactive' => 1]) + ->where(['S.business_id' => 2, 'BK.isactive' => 1]) ->groupBy('S.scheme_id'); + // print_r($query);die; + // echo $this->db->getLastQuery(); die; $results = $query->get()->getResultArray(); + // print_r($results);die; return $results; } + + // public function expiring_membership_list(){ + // $now = date('Y-m-d'); + // $last30days = date('Y-m-d', strtotime('+30 days')); + // return $this->db->table('subscription as S') + // ->join('customers as C', 'C.customer_id = S.customer_id', 'left') + // ->join('books as BK', 'BK.book_id = S.scheme_id', 'left') + // ->join('book_categories as BC', 'BC.book_id = S.scheme_id', 'left') + // ->join('category as CM', 'CM.id = BC.category_id', 'left') + // ->select('CM.name, CONCAT(C.first_name, " ", C.last_name) as customer_name, C.email as customer_email, C.mobile_no as customer_mobile, S.sub_id, S.scheme_id, S.customer_id, S.business_id, S.to_subscription, S.from_subscription, BK.title,BK.short_code, BK.book_id,DATEDIFF(S.to_subscription, CURDATE()) as countdays,DATE_FORMAT(S.to_subscription, "%d/%m/%Y") as to_subscription_date_format') + // ->where('S.to_subscription >=', $now) + // ->where('S.to_subscription <=', $last30days) + // // ->where('BC.category_id', 5) + // ->where('LOWER(CM.name)', strtolower("Membership")) + // ->orderBy('S.to_subscription', 'ASC') + // ->groupBy('S.sub_id') + // ->get() + // ->getResultArray(); + // } public function expiring_membership_list(){ $now = date('Y-m-d'); $last30days = date('Y-m-d', strtotime('+30 days')); - return $this->db->table('subscription as S') + + $membershipList = $this->db->table('subscription as S') ->join('customers as C', 'C.customer_id = S.customer_id', 'left') ->join('books as BK', 'BK.book_id = S.scheme_id', 'left') ->join('book_categories as BC', 'BC.book_id = S.scheme_id', 'left') ->join('category as CM', 'CM.id = BC.category_id', 'left') - ->select('CM.name, CONCAT(C.first_name, " ", C.last_name) as customer_name, C.email as customer_email, C.mobile_no as customer_mobile, S.sub_id, S.scheme_id, S.customer_id, S.business_id, S.to_subscription, S.from_subscription, BK.title, BK.book_id,DATEDIFF(S.to_subscription, CURDATE()) as countdays,DATE_FORMAT(S.to_subscription, "%d/%m/%Y") as to_subscription_date_format') + ->select('CM.name, CONCAT(C.first_name, " ", C.last_name) as customer_name, C.email as customer_email, C.mobile_no as customer_mobile, S.sub_id, S.scheme_id, S.customer_id, S.business_id, S.to_subscription, S.from_subscription, BK.title, BK.short_code, BK.book_id, DATEDIFF(S.to_subscription, CURDATE()) as countdays, DATE_FORMAT(S.to_subscription, "%d/%m/%Y") as to_subscription_date_format') ->where('S.to_subscription >=', $now) ->where('S.to_subscription <=', $last30days) - // ->where('BC.category_id', 5) ->where('LOWER(CM.name)', strtolower("Membership")) ->orderBy('S.to_subscription', 'ASC') ->groupBy('S.sub_id') ->get() ->getResultArray(); + + foreach ($membershipList as &$membership) { + $notifications = $this->getNotifications($membership['customer_id']); + + $membership['notifications'] = $notifications; + } + + return $membershipList; } - + + private function getNotifications($customerId) { + return $this->db->table('notification_campaign as NC') + ->join('notification_history_parents as NH', 'NH.campaign_id = NC.campaign_id', 'left') + ->join('notification_history_children as NP', 'NP.fkid = NH.id', 'left') + ->select('NC.*, NH.*, NP.*') + ->where('NP.customer_id', $customerId) + ->get() + ->getResultArray(); + } + public function book_published_dtls(){ if ((int)date('m') <= 3) { @@ -143,5 +222,36 @@ class HomeModel extends Model return $book_published; } + public function bookSales() + { + $result = []; + + // Fetch book sales for YTD + $result['ytd'] = $this->getBookSalesCount('start_of_current_year'); + + // Fetch book sales for MTD + $result['mtd'] = $this->getBookSalesCount('start_of_current_month'); + + // Fetch book sales for Today + $result['today'] = $this->getBookSalesCount('today'); +// print_r($result);die; + return $result; + + } + + private function getBookSalesCount($dateFilter) + { + return $this->db->table('invoiceitems') + ->join('invoice', 'invoice.invoice_id = invoiceitems.invoice_id', 'left') + ->join('books', 'books.book_id = invoiceitems.product', 'left') + ->select('books.book_id, books.title, COUNT(invoiceitems.invoice_child_id) as sales_count') + ->where("DATE(invoice.invoice_date) >= '$dateFilter'") + ->groupBy('books.book_id, books.title') + ->get() + ->getResultArray(); + + } + + // Other existing methods... } diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 2aa8f949..f4f91763 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -377,29 +377,75 @@ public function get_mem_invoice_data($f_date = null, $t_date = null) } +// public function itemwise_report_data($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); + +// // 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(); + +// return $result; +// } public function itemwise_report_data($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') + ->select('books.publishers_code, COUNT(invoiceitems.product) as publisher_item_count, books.title as book_name, COUNT(invoiceitems.product) as item_count, SUM(invoiceitems.quantity * invoiceitems.unit_price) as total_cost') ->where('invoice.isactive', 1) ->where('books.isactive', 1); - // 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); - } + // 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') + $result = $query->join('invoiceitems', 'invoiceitems.invoice_id = invoice.invoice_id', 'left') ->join('books', 'books.book_id = invoiceitems.product', 'left') - ->groupBy('books.book_id') + ->groupBy('books.publishers_code, books.title') ->get() ->getResult(); - return $result; + // Group by publisher_code and include books + $groupedResult = []; + foreach ($result as $row) { + $publisherCode = $row->publishers_code; + if (!isset($groupedResult[$publisherCode])) { + $groupedResult[$publisherCode] = (object)[ + 'publisher_code' => $publisherCode, + 'publisher_item_count' => 0, + 'publisher_total_cost' => 0, + 'books' => [], + ]; + } + + // Add book information to the grouped result + $groupedResult[$publisherCode]->publisher_item_count += $row->item_count; + $groupedResult[$publisherCode]->publisher_total_cost += $row->total_cost; + $groupedResult[$publisherCode]->books[] = (object)[ + 'book_name' => $row->book_name, + 'item_count' => $row->item_count, + 'total_cost' => $row->total_cost, + ]; + } + + return array_values($groupedResult); } + public function getInvoiceIdByMd5($md5Hash) { $result = $this->db->table($this->table) diff --git a/app/Views/dashboard.php b/app/Views/dashboard.php index 98186810..5171f9d8 100644 --- a/app/Views/dashboard.php +++ b/app/Views/dashboard.php @@ -45,87 +45,268 @@ -->
-
-
-
-
-
- -
-
-

Today : -

-
-
- MTD : - YTD : -
-
-
-
-
- -
-
-
-

Schemes

-
- $a) : ?> -
- - table-user - -
-
- +
+
+
+ - -
-
-

- Subscribers - -

-
-
-
- - - +
+
+

+

Today sale

+
+ +
+
+
+ MTD : -₹ + YTD : -₹ +
+
+
-
-
Samarth Scheme (1years)
-

- 32 Subscribers -

+
+ + + + + +
+
+
+ + + +

+ +
+
+
+ + +
+
+

+

Total Subscriber

+
+ +
+
+
+ New :
+ Renewed:
+
+ +
+
+
+
+ + + + + --> + +
+
+
+ + + +

+ +
+
+
+ +
+
+

+

Total Subscriber

+
+ +
+
+
+ New :
+ Renewed:
+
+
+
+
+
+ +
+
+
+
+ +
+
+ + table-user + +
+ +
+
-
-
-
+
+
+
+

+ +

+
+
+
+
+
+
+
+

Total Subscribers

+
+
+
+
+
+

New Subscribers

+
+
+
+
+
+

Renewed

+
+
+
+
+
+
+
+ +
+ -
-
+ +

Expiring Membership List

@@ -136,8 +317,11 @@ # Name + Mobile No + Email Scheme Name Expiring In + Notification On @@ -155,10 +339,23 @@
- + - + + +
+ + + + + + + +
-
-
-
-

Books Published Report

-
-
-
-

Overall

-

-
-
-

YTD

-

-
-
-

MTD

-

-
-
-
-
-
-

Last One Month

-
-
- - - - - - - - - 0) : foreach ($book_published['book_published'] as $b) : ?> - - - - - - - -
Book DetailsCategory
- -

- -

- - -

- -

- - -

- -

- -
- - - -
-
-
-
-
-
-
-
+ \ No newline at end of file diff --git a/app/Views/report_book_publish.php b/app/Views/report_book_publish.php index d01bbf5a..e2125077 100644 --- a/app/Views/report_book_publish.php +++ b/app/Views/report_book_publish.php @@ -6,7 +6,7 @@
-
+
@@ -43,7 +43,7 @@ Book Name Author Cost - Published On + Published By Inv Date @@ -78,42 +78,21 @@