diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index 2a0d5184..f1a24640 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -609,10 +609,11 @@ class Notifications extends BaseController $response .= "Started.
Customer expiring. till dated = ".date('d/m/Y', strtotime($newDate))."
There are ".count($queryResult)." persons
"; if(!empty($queryResult)){ usort($queryResult, function ($a, $b) { - return $b['to_subscription'] <=> $a['to_subscription']; // Descending order + return $a['to_subscription'] <=> $b['to_subscription']; //Asc order }); } foreach ($queryResult as $inx => $row) { + $subscription_id = $row['sub_id']; $status = $row['status']; $userFirstName = $row['first_name']; $userLastName = $row['last_name']; @@ -703,6 +704,7 @@ class Notifications extends BaseController 'customer_id' => $customerId, 'receiving_entity' => $row['email'], 'receiving_status' => 0, + 'subscription_id' => $subscription_id, 'message' => $emailContent]; # Step 5: Insertion on History Child $history_child_id = $NotificationModel->save_notification_history_child($history_child_data); @@ -816,6 +818,7 @@ class Notifications extends BaseController 'customer_id' => $customerId, 'receiving_entity' => $userMobileNumber, 'receiving_status' => 0, + 'subscription_id' => $subscription_id, 'message' => strip_tags(ltrim($whatsappContent))]; $history_child_id = $NotificationModel->save_notification_history_child($history_child_data); diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index b5f64dd1..8966b6b1 100755 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -227,7 +227,7 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va $builder->select(" CONCAT_WS(' ', c.first_name, c.last_name) as customer_name, c.customer_id, c.mobile_no, c.email, DATEDIFF(s.to_subscription, CURDATE()) AS remaining_days, - s.from_subscription, s.to_subscription, s.scheme_id, bs.title, + s.from_subscription, s.to_subscription, s.scheme_id, bs.title, s.membership_id,s.sub_id, 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, @@ -248,6 +248,10 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va $builder->orderBy('s.to_subscription', 'asc'); $query = $builder->get(); $result = $query->getResultArray(); + $lastQuery = $this->db->getLastQuery(); + $finalQueryString = $lastQuery->getQuery(); + echo $finalQueryString; + die; return $result; } public function getSubscriptionDetailsBySchemeName($selectedScheme, $downloadType){ @@ -275,12 +279,16 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va $customerDetails = []; $processedCustomerIDs = []; + $subscriptionIDs = []; + // 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)) { + // if (!in_array($row['customer_id'], $processedCustomerIDs)) { } // previous if condition + + if (!in_array($row['sub_id'], $subscriptionIDs)) { $customerDetails[] = [ 'customer_id' => $row['customer_id'], 'invoice_id' => $row['invoice_id'], @@ -303,6 +311,7 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va 'company_city' => $row['business_city'], 'company_state' => $row['business_state'], 'company_postal_code' => $row['business_postal_code'], + 'membership_id' => $row['membership_id'] ]; // Add the customer ID to the set of processed IDs @@ -328,11 +337,14 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va // $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('GROUP_CONCAT(books.book_id ORDER BY books.book_id) AS book_ids'); + $builder->select('GROUP_CONCAT(DISTINCT 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->join('invoiceitems', 'books.book_id = invoiceitems.product', 'left'); $builder->where('LOWER(category.name)', strtolower($categoryName)); + $builder->where('invoiceitems.product IS NOT NULL', null, false); $builder->groupBy('books.short_code'); $query = $builder->get(); diff --git a/app/Views/notify_the_expiry_subscribers.php b/app/Views/notify_the_expiry_subscribers.php index babcd8f2..257da56b 100755 --- a/app/Views/notify_the_expiry_subscribers.php +++ b/app/Views/notify_the_expiry_subscribers.php @@ -36,6 +36,8 @@ }, error: function(xhr, status, error) { console.error("AJAX Error:", error); + $('#target-div').html(""); + $("#params").val(''); } }); diff --git a/app/Views/print_addresses_form.php b/app/Views/print_addresses_form.php index d0865f8b..6879853b 100755 --- a/app/Views/print_addresses_form.php +++ b/app/Views/print_addresses_form.php @@ -67,7 +67,9 @@
-
+ + +
,
,