From 77b0fc2beb314da2ec3c0b4d7e13ba603ad09dff Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Tue, 4 Jun 2024 06:37:14 +0000 Subject: [PATCH] Changes_alteration on subscribers list - Prnt pdf : ps --- app/Controllers/Subscription.php | 80 ++++++++++++- app/Models/CustomerModel.php | 4 +- app/Models/HomeModel.php | 2 +- app/Models/InvoiceModel.php | 6 +- app/Models/NotificationModel.php | 8 +- app/Models/SubscriptionModel.php | 179 ++++++++++++++++++----------- app/Views/print_addresses_form.php | 14 ++- app/Views/subscribers_list.php | 41 ++++--- 8 files changed, 241 insertions(+), 93 deletions(-) diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php index 6bcbcf8e..5430400b 100644 --- a/app/Controllers/Subscription.php +++ b/app/Controllers/Subscription.php @@ -39,6 +39,7 @@ class Subscription extends BaseController $SubscriptionModel = new SubscriptionModel(); $swhere = ['subscription.business_id' => (int)$session_bid]; $data['subscriber'] = $SubscriptionModel->getAllSubscribersWithNames($swhere); + $data['membershipbooks'] = $SubscriptionModel->getBooksByCategory('Membership'); $this->render_page('subscribers_list', $data); }else { return redirect()->to('login'); @@ -121,7 +122,7 @@ public function add_subscription() { // } // } -public function download_details() +public function download_details_by_hema() { $selectedSchemes = $this->request->getPost('selected_schemes'); $downloadType = $this->request->getPost('download_type'); @@ -203,6 +204,83 @@ public function download_details() } } +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', + 'format' => [101.6, 152.4], + 'default_font_size' => 12, + 'default_font' => 'Arial', + 'margin_left' => 0, + 'margin_right' => 0, + 'margin_top' => 0, + 'margin_bottom' => 0, + 'margin_header' => 0, + 'margin_footer' => 0, + 'orientation' => 'P', // Portrait + ]; + + $configa4 = [ + 'mode' => 'utf-8', + 'format' => 'A4', + 'margin_left' => 1, + 'margin_right' => 1, + 'margin_top' => 1, + 'margin_bottom' => 1, + 'margin_header' => 0, + 'margin_footer' => 0, + ]; + + if ($action == 1) $pdf = new Mpdf($config); + else $pdf = new Mpdf($configa4); + + $customerDetails = []; + $mergedBookids = []; + + if (!empty($selectedSchemes)) { + foreach ($selectedSchemes as $b) { + $ids = explode(',', $b); + $mergedBookids = array_merge($mergedBookids, $ids); + } + } + + if (!empty($mergedBookids)) { + + $subscriptionModel = new SubscriptionModel(); + $customerDetails = $subscriptionModel->getSubscriptionDetailsBySchemeName($mergedBookids, $downloadType); + if (!empty($customerDetails)) { + + $html = view('print_addresses_form', ['customerDetails' => $customerDetails, 'action' => $action, 'pdf' => $pdf]); + // echo $html;die; + // 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); + } else { + // Handle case when customer details are not available + $this->logger->info("Print Addresses (Scheme): Details Not Available"); + echo ""; + echo ""; + } + } else { + // Handle case when no schemes are chosen + $this->logger->info("Print Addresses (Scheme): Schemes Not Chosen"); + echo ""; + echo ""; + } +} + diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php index ad491b43..699ee866 100644 --- a/app/Models/CustomerModel.php +++ b/app/Models/CustomerModel.php @@ -18,7 +18,7 @@ class CustomerModel extends Model } public function getCustomerNamesByBusiness($business_id) { - $this->builder()->select('customer_id,CONCAT(first_name, " ", last_name) as full_name', false); + $this->builder()->select('customer_id,CONCAT_WS(" ", first_name, last_name) as full_name', false); $this->builder()->where('business_id ', $business_id); // Filter by business_id $query = $this->builder()->get(); // Use findAll() instead of get() return ($query->getResult()); @@ -206,7 +206,7 @@ public function getGroupDetails() return $this->db->table('customer_groups as CG' ) ->join('users as U1', 'U1.user_id = CG.created_by', 'left') ->join('users as U2', 'U2.user_id = CG.updated_by', 'left') -->select('CG.group_id,CG.group_name,CG.created_on,CG.created_by,CG.updated_on,CG.updated_by,DATE_FORMAT(CG.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,concat(U1.first_name," ",U1.last_name) as created_by_name,concat(U2.first_name," ",U2.last_name) as updated_by_name,CG.isactive') +->select('CG.group_id,CG.group_name,CG.created_on,CG.created_by,CG.updated_on,CG.updated_by,DATE_FORMAT(CG.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,CONCAT_WS(" ", U1.first_name, U1.last_name) as created_by_name,CONCAT_WS(" ", U2.first_name, U2.last_name) as updated_by_name,CG.isactive') ->where(['CG.group_name != ' => 'EXPIRYDATE']) // ->where(['CG.isactive' => 1]) ->get() diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php index 6c71c42e..966f7379 100644 --- a/app/Models/HomeModel.php +++ b/app/Models/HomeModel.php @@ -146,7 +146,7 @@ class HomeModel extends Model ->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') + ->select('CM.name,CONCAT_WS(" ", 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('LOWER(CM.name)', strtolower("Membership")) diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 35579b0d..fec99f13 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -130,7 +130,7 @@ public function getJoinedData($where, $orderby = []) ->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.wp_api_order_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.invoice_type, I.event_id,E.event_name, I.business_id,B.title as business_name,DATE_FORMAT(I.created_on, "%d/%m/%Y") as created_on_format,I.created_on, I.created_by,concat(U1.first_name," ",U1.last_name) as created_by_name,DATE_FORMAT(I.updated_on, "%d/%m/%Y") as updated_on_format, 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,B.address as business_address,B.city as business_city,B.state as business_state,B.postal_code as business_postal_code,B.email as business_email,B.mobile_no as business_mobile_no,S.from_subscription,S.to_subscription,DATEDIFF(S.to_subscription, S.from_subscription) as subscription_in_days,S.scheme_id') + ->select('I.invoice_id,I.wp_api_order_id,I.invoice_number, I.customer_id,CONCAT_WS(" ", 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.invoice_type, I.event_id,E.event_name, I.business_id,B.title as business_name,DATE_FORMAT(I.created_on, "%d/%m/%Y") as created_on_format,I.created_on, I.created_by,CONCAT_WS(" ", U1.first_name, U1.last_name) as created_by_name,DATE_FORMAT(I.updated_on, "%d/%m/%Y") as updated_on_format, I.updated_by,CONCAT_WS(" ", 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,B.address as business_address,B.city as business_city,B.state as business_state,B.postal_code as business_postal_code,B.email as business_email,B.mobile_no as business_mobile_no,S.from_subscription,S.to_subscription,DATEDIFF(S.to_subscription, S.from_subscription) as subscription_in_days,S.scheme_id') ->where($where); // if (!empty($orderby)) { // $query->orderBy($orderby[0], $orderby[1]); @@ -240,7 +240,7 @@ public function getJoinedData($where, $orderby = []) ->join('customer_addresses as S','S.customer_address_id=invoice.shipping_address_id AND S.address_type = 2','left') ->join('states', 'states.state_short_name = A.state AND A.country = "IN"', 'left') ->join('countries', 'countries.country_short_name = A.country', 'left') - ->select('invoice.*,DATE_FORMAT(invoice.invoice_date, "%d/%m/%Y") AS formatted_invoice_date,DATE_FORMAT(invoice.due_date, "%d/%m/%Y") AS formatted_due_date ,concat(C.first_name," ",C.last_name) as customer_name,C.mobile_no,A.address_1, A.address_2,A.postal_code,A.city, A.state,C.mobile_no as customer_mobile') + ->select('invoice.*,DATE_FORMAT(invoice.invoice_date, "%d/%m/%Y") AS formatted_invoice_date,DATE_FORMAT(invoice.due_date, "%d/%m/%Y") AS formatted_due_date ,CONCAT_WS(" ", C.first_name, C.last_name) as customer_name,C.mobile_no,A.address_1, A.address_2,A.postal_code,A.city, A.state,C.mobile_no as customer_mobile') ->select('B.title as company_name,B.business_logo,B.terms as company_terms,B.address as company_address,B.city as company_city,B.state as company_state,B.postal_code as company_postal_code,B.email as company_email,B.mobile_no as company_mobile_no') ->select('COALESCE(NULLIF(states.state_name, ""), A.state) AS customer_bill_state') ->select('COALESCE(NULLIF(states.state_name, ""), S.state) AS customer_ship_state') @@ -288,7 +288,7 @@ public function getJoinedData($where, $orderby = []) ->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('S.customer_id, CONCAT(C.first_name, " ", C.last_name) as customer_name, S.sub_id, S.scheme_id, DATE_FORMAT(S.from_subscription, "%d/%m/%Y") AS formatted_from_subscription, DATE_FORMAT(S.to_subscription, "%d/%m/%Y") AS formatted_to_subscription, S.from_subscription, S.to_subscription,S.isactive,S.is_renew, S.created_on, CM.name, BK.title, BK.book_id') + ->select('S.customer_id, CONCAT_WS(" ", C.first_name, C.last_name) as customer_name, S.sub_id, S.scheme_id, DATE_FORMAT(S.from_subscription, "%d/%m/%Y") AS formatted_from_subscription, DATE_FORMAT(S.to_subscription, "%d/%m/%Y") AS formatted_to_subscription, S.from_subscription, S.to_subscription,S.isactive,S.is_renew, S.created_on, CM.name, BK.title, BK.book_id') ->where('LOWER(CM.name)', strtolower($category)) ->where('S.customer_id', $id) ->orderBy('S.to_subscription', 'ASC') diff --git a/app/Models/NotificationModel.php b/app/Models/NotificationModel.php index 1be59cc9..ffccbe8b 100644 --- a/app/Models/NotificationModel.php +++ b/app/Models/NotificationModel.php @@ -30,7 +30,7 @@ class NotificationModel extends Model ->join('business as B', 'B.business_id = S.business_id', 'left') ->join('book_categories as BC', 'BC.category_id = S.scheme_id', 'left') ->join('books as BK', 'BC.book_id = BK.book_id', 'left') - ->select('concat("Your subscription going to expried in ",DATEDIFF(S.to_subscription, CURDATE())," days") as statement,DATEDIFF(S.to_subscription, CURDATE()) as countdays,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.from_subscription,S.to_subscription,S.business_id,B.title as business_name,B.address as business_address,B.city as business_city,B.state as business_state,B.postal_code as business_postal_code,B.email as business_email,B.mobile_no as business_mobile_no,S.to_subscription,S.from_subscription,BK.title,BK.book_id') + ->select('concat("Your subscription going to expried in ",DATEDIFF(S.to_subscription, CURDATE())," days") as statement,DATEDIFF(S.to_subscription, CURDATE()) as countdays,CM.name,CONCAT_WS(" ", 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.from_subscription,S.to_subscription,S.business_id,B.title as business_name,B.address as business_address,B.city as business_city,B.state as business_state,B.postal_code as business_postal_code,B.email as business_email,B.mobile_no as business_mobile_no,S.to_subscription,S.from_subscription,BK.title,BK.book_id') // ->where('S.to_subscription >=', $now)->where('S.to_subscription <=',$lastWeek) ->where('S.to_subscription =',date('Y-m-d', strtotime($date))) ->groupBy('S.sub_id') @@ -41,7 +41,7 @@ class NotificationModel extends Model return $this->db->table('templates as T' ) ->join('users as U1', 'U1.user_id = T.created_by', 'left') ->join('users as U2', 'U2.user_id = T.updated_by', 'left') - ->select('T.template_id,T.template_name,T.mode,T.created_on,T.created_by,T.updated_on,T.updated_by,DATE_FORMAT(T.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,concat(U1.first_name," ",U1.last_name) as created_by_name,concat(U2.first_name," ",U2.last_name) as updated_by_name,T.isactive') + ->select('T.template_id,T.template_name,T.mode,T.created_on,T.created_by,T.updated_on,T.updated_by,DATE_FORMAT(T.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,CONCAT_WS(" ", U1.first_name, U1.last_name) as created_by_name,CONCAT_WS(" ", U2.first_name, U2.last_name) as updated_by_name,T.isactive') ->whereNotIn('T.template_name',array('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP')) ->get()->getResultArray(); } @@ -83,7 +83,7 @@ public function getCampaignDetails(){ ->join('users as U1', 'U1.user_id = NC.created_by', 'left') ->join('users as U2', 'U2.user_id = NC.updated_by', 'left') ->join('templates as T', 'T.template_id = NC.template_id', 'left') - ->select('NC.campaign_id,NC.campaign_name,T.template_id,T.template_name,NC.mode,NC.created_on,NC.created_by,NC.updated_on,NC.updated_by,DATE_FORMAT(NC.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,concat(U1.first_name," ",U1.last_name) as created_by_name,concat(U2.first_name," ",U2.last_name) as updated_by_name,NC.isactive,NC.group_id,NC.scheduled_date,if(NC.scheduled_time IS NULL ,"",NC.scheduled_time) as scheduled_time') + ->select('NC.campaign_id,NC.campaign_name,T.template_id,T.template_name,NC.mode,NC.created_on,NC.created_by,NC.updated_on,NC.updated_by,DATE_FORMAT(NC.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,CONCAT_WS(" ", U1.first_name, U1.last_name) as created_by_name,CONCAT_WS(" ", U2.first_name, U2.last_name) as updated_by_name,NC.isactive,NC.group_id,NC.scheduled_date,if(NC.scheduled_time IS NULL ,"",NC.scheduled_time) as scheduled_time') ->whereNotIn('T.template_name',array('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_WHATSAPP')) ->get()->getResultArray(); @@ -279,7 +279,7 @@ public function customerGroupQueryExecution($queries){ notification_history_children.id AS child_id, notification_history_children.fkid AS parent_id, notification_history_children.customer_id, - CONCAT(customers.first_name, " ", customers.last_name) AS customers_name, + CONCAT_WS(" ", customers.first_name, customers.last_name) AS customers_name, notification_history_children.receiving_entity, notification_history_children.receiving_status, notification_history_children.result, diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index 5dd8c362..76a6bde1 100644 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -15,7 +15,7 @@ public function getAllSubscribersWithNames($where) { $builder = $this->db->table('subscription'); - $builder->select('subscription.*, books.title,books.short_code, books.isactive, CONCAT(customers.first_name, " ", customers.last_name) as customer_name'); + $builder->select('subscription.*, books.title,books.short_code, books.isactive, CONCAT_WS(" ", customers.first_name, customers.last_name) as customer_name'); $builder->join('books', 'books.book_id = subscription.scheme_id'); $builder->join('customers', 'customers.customer_id = subscription.customer_id'); $builder->where($where); @@ -44,7 +44,7 @@ public function getCustomerNameBySchemeName($schemeName) public function getCustomerAddressesBySchemeName($schemeName) { $builder = $this->db->table('subscription'); - $builder->select('CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state,customer_addresses.postal_code, customer_addresses.address_type,business.address,business.city,business.state,business.postal_code,business.country'); + $builder->select('CONCAT_WS(" ", customers.first_name, customers.last_name) as customer_name, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state,customer_addresses.postal_code, customer_addresses.address_type,business.address,business.city,business.state,business.postal_code,business.country'); $builder->join('customers', 'customers.customer_id = subscription.customer_id'); $builder->join('customer_addresses', 'customer_addresses.customer_id = subscription.customer_id'); $builder->join('business', 'business.business_id = subscription.business_id'); @@ -276,72 +276,121 @@ public function getAllExpiredCustomerDetailsByScheme($schemeName) } } - return $customerDetails; -} -public function getBothDetailsSchemeName($schemeName) -{ - $builder = $this->db->table('subscription'); - $builder->select('subscription.sub_id,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','left'); - $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','left'); - $builder->where('books.title', $schemeName); - $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2 - $builder->groupBy('subscription.sub_id'); - $builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers - - $query = $builder->get(); - // print_r($this->db->getLastQuery());die; - $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; } +public function getSubscriptionDetailsBySchemeName($selectedScheme, $downloadType){ + + // print_r($selectedScheme); + $customerDetails = []; + $currentDate = date('Y-m-d'); + + $builder = $this->db->table('subscription as s'); + + $builder->select(" + CONCAT_WS(' ', c.first_name, c.last_name) as customer_name, + c.customer_id, c.mobile_no, c.email, + s.from_subscription, s.to_subscription, s.scheme_id, bs.title, + i.invoice_id, i.invoice_date, i.shipping_address_id, + ca.customer_address_id, ca.address_1, ca.address_2, ca.city, ca.state, ca.postal_code, ca.address_type, st.state_name, + b.title as business_name, b.address as business_address, b.city as business_city, + b.state as business_state, b.postal_code as business_postal_code, b.mobile_no as business_mobile_no + "); + + $builder->join('customers as c', 's.customer_id = c.customer_id', 'left'); + $builder->join('invoice as i', 's.invoice_id = i.invoice_id', 'left'); + // $builder->join('customer_addresses as ca', 'ca.customer_id = s.customer_id AND i.shipping_address_id = ca.customer_address_id AND ca.address_type = 2', 'left'); + $builder->join('customer_addresses as ca', 'ca.customer_id = c.customer_id and ca.address_type = 2','left'); + $builder->join('books as bs', 'bs.book_id = s.scheme_id', 'left'); + $builder->join('states as st', 'st.state_short_name = ca.state', 'left'); + $builder->join('business as b', 'b.business_id = s.business_id', 'left'); + + $builder->whereIn('bs.book_id', $selectedScheme); + + if ($downloadType === 'active') { + $builder->where('s.isactive', 1); + // $builder->where('s.to_subscription >=', $currentDate); + } elseif ($downloadType === 'expired') { + $builder->where('s.isactive', 0); + // $builder->where('s.to_subscription <', $currentDate); + } + + $builder->orderBy('s.from_subscription', 'asc'); + + $query = $builder->get(); + $result = $query->getResultArray(); + //print_r($result);die; + // Initialize the customerDetails array and a set to track processed customer IDs + $customerDetails = []; + $processedCustomerIDs = []; + + // Process the results if not empty + if (!empty($result)) { + foreach ($result as $row) { + // Check if the customer ID has already been processed + if (!in_array($row['customer_id'], $processedCustomerIDs)) { + $customerDetails[] = [ + 'customer_id' => $row['customer_id'], + 'invoice_id' => $row['invoice_id'], + 'invoice_date' => $row['invoice_date'], + 'customer_name' => $row['customer_name'], + 'from_subscription' => $row['from_subscription'], + 'address_1' => $row['address_1'], + 'address_2' => $row['address_2'], + 'mobile_no' => $row['mobile_no'], + 'email' => $row['email'], + '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_address' => $row['business_address'], + 'company_city' => $row['business_city'], + 'company_state' => $row['business_state'], + 'company_postal_code' => $row['business_postal_code'], + ]; + + // Add the customer ID to the set of processed IDs + $processedCustomerIDs[] = $row['customer_id']; + } + } + + // Sorting the customerDetails array by from_subscription date + usort($customerDetails, function($a, $b) { + return strtotime($a['invoice_date']) - strtotime($b['invoice_date']); + }); + } +// $lastQuery = $this->db->getLastQuery(); +// $finalQueryString = $lastQuery->getQuery(); +// echo $finalQueryString; +// echo count($customerDetails); + return $customerDetails; + } + + + public function getBooksByCategory($categoryName) + { + // $builder = $this->db->table('books'); + // $builder->select('books.book_id, books.title'); + // $builder->join('book_categories', 'books.book_id = book_categories.book_id', 'left'); + // $builder->join('category', 'category.id = book_categories.category_id', 'left'); + // $builder->where('LOWER(category.name)', strtolower($categoryName)); + + $builder = $this->db->table('books'); + $builder->select('GROUP_CONCAT(books.book_id ORDER BY books.book_id) AS book_ids'); + $builder->select('books.short_code, books.title'); + $builder->join('book_categories', 'books.book_id = book_categories.book_id', 'left'); + $builder->join('category', 'category.id = book_categories.category_id', 'left'); + $builder->where('LOWER(category.name)', strtolower($categoryName)); + $builder->groupBy('books.short_code'); + + $query = $builder->get(); + return $query->getResult(); + } + diff --git a/app/Views/print_addresses_form.php b/app/Views/print_addresses_form.php index bf76a46e..d0865f8b 100644 --- a/app/Views/print_addresses_form.php +++ b/app/Views/print_addresses_form.php @@ -69,10 +69,15 @@
,
- ,
+ + ,
+ , +
+ +
@@ -170,10 +175,15 @@
, - ,
+ + , +
, +
+ +
diff --git a/app/Views/subscribers_list.php b/app/Views/subscribers_list.php index ba09ec8d..f4633389 100644 --- a/app/Views/subscribers_list.php +++ b/app/Views/subscribers_list.php @@ -109,22 +109,32 @@