From 3038e19ca627c5925d61616775c592b11c69707b Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Tue, 3 Dec 2024 17:18:43 +0530 Subject: [PATCH] FEATURE DATE RANGE FILTER ADDED IN EMAIL --- app/Config/Routes.php | 3 +- app/Controllers/Event.php | 2 +- app/Controllers/Invoice.php | 2 +- app/Controllers/Notifications.php | 45 +++++++++++---- app/Models/NotificationModel.php | 18 ++++++ app/Views/invoice_form.php | 2 +- app/Views/notify_the_expiry_subscribers.php | 64 ++++++++++++++++++--- app/Views/received_payments_report.php | 9 ++- app/Views/report_general_invoice.php | 2 +- app/Views/report_userwise_and_eventwise.php | 2 +- 10 files changed, 122 insertions(+), 27 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 02fc154a..30d0c5b2 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -157,8 +157,9 @@ $routes->match(['get','post'],'/itemwise_report_with_payment_method','Invoice::i # Notifications Routes // $routes->get('controller/SubExpdetail/(:num)', 'YourController::SubExpdetail/$1'); - +$routes->get("getExpCustomerDetail",'Notifications::getExpCustomerDetail/'); $routes->get("getExpCustomerDetail/(:any)",'Notifications::getExpCustomerDetail/$1'); +$routes->get("getExpCustomerDetail/(:any)/(:any)",'Notifications::getExpCustomerDetail/$1/$2'); $routes->get('send_whatsapp_message/', 'Notifications::send_whatsapp_message'); // $routes->post('whatsapp_custom_notifications/', 'Notifications::whatsapp_custom_notifications'); // $routes->match(['post', 'get'], 'mail_custom_notifications', 'Notifications::mail_custom_notifications'); diff --git a/app/Controllers/Event.php b/app/Controllers/Event.php index 2c610ee0..578f896a 100755 --- a/app/Controllers/Event.php +++ b/app/Controllers/Event.php @@ -200,7 +200,7 @@ class Event extends BaseController $update_result = $EventModel->updateData('events', $data, $where); if ($update_result['info']) { - $response = "Event set as Default"; + $response = "You have set this event as the Default"; $this->logger->info($update_result['info']); } else { $response = $update_result['err']; diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index f4cf3126..415c133f 100755 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -1435,7 +1435,7 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ $response = array(); if ($bookId) { $response['success'] = true; - $response['message'] = 'Book saved successfully.'; + $response['message'] = 'Book Added Successfully'; $response['book_id'] = $bookId; // Include the book ID in the response $response['title'] = $bookName; // $response['tax'] = $bookId; diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index 94304d06..8f4387aa 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -5,6 +5,7 @@ namespace App\Controllers; use App\Helpers\NotificationHelper; use App\Models\NotificationModel; use App\Models\SubscriptionModel; +use DateTime; class Notifications extends BaseController { @@ -569,37 +570,59 @@ class Notifications extends BaseController ################################################################ # Expiry Notification ReferWith : Hema ################################################################ - public function getExpCustomerDetail($window_time = null) + public function getExpCustomerDetail($window_time = null,$to_time = null) { + $NotificationModel = new NotificationModel(); $this->update_expired_members(); $response ="
";// $response = "
 Hi, Started. 
"; # Step 1: add the days to retrive the data// $providedDate = date('Y-m-d'); - if($window_time >= 0){ - $newDate = date('Y-m-d', strtotime("$providedDate + $window_time days")); + $window_time = $this->request->getGet('params'); + if ($window_time!= ''){ + if($window_time >= 0){ + $newDate = date('Y-m-d', strtotime("$providedDate + $window_time days")); + }else{ + $newDate = date('Y-m-d', strtotime("$providedDate $window_time days")); + } + $ExpCustomerDetail = $NotificationModel->getExpDate(); // Retrieve the stored query + }else{ - $newDate = date('Y-m-d', strtotime("$providedDate $window_time days")); + $dateData = $this->request->getGet('to_date'); + $newDate = date('Y-m-d',strtotime($dateData)); + $ExpCustomerDetail = $NotificationModel->getExpDate2(); } + # Step 2 :Get the customer detail// - $NotificationModel = new NotificationModel(); - $ExpCustomerDetail = $NotificationModel->getExpDate(); // Retrieve the stored query + if (empty($ExpCustomerDetail)) { $this->logger->error('No customer group found by the name of EXPIRYDATE'); return; } + if($window_time != ''){ + $modifiedQuery = str_replace('WINDOW_TIME', $window_time, $ExpCustomerDetail); + //print_r($modifiedQuery);die; + - # Step 3: Replace the placeholder WINDOW_TIME with the user-provided value - $modifiedQuery = str_replace('WINDOW_TIME', $window_time, $ExpCustomerDetail); - // print_r($modifiedQuery);die; + } + else{ + $from_date2 = $this->request->getGet('from_date'); + $to_date2 = $this->request->getGet('to_date'); + $from_date = DateTime::createFromFormat('d/m/Y', $from_date2)->format('Y-m-d'); + $to_date = DateTime::createFromFormat('d/m/Y', $to_date2)->format('Y-m-d'); + // Add single quotes around the date values during the replacement + $modifiedQuery = str_replace('FROM_DATE', "'$from_date'", $ExpCustomerDetail); + $modifiedQuery = str_replace('TO_DATE', "'$to_date'", $modifiedQuery); + + } if (empty($modifiedQuery)) { $this->logger->error('There is no sub query'); return; } + # Step 3: Replace the placeholder WINDOW_TIME with the user-provided value $db = \Config\Database::connect(); $queryResult = $db->query($modifiedQuery)->getResultArray(); - $notification = new NotificationHelper(); if (empty($queryResult)) { $this->logger->error("There is no customer expiring on date:{$newDate}"); @@ -615,7 +638,6 @@ class Notifications extends BaseController return $a['to_subscription'] <=> $b['to_subscription']; //Asc order }); } - foreach ($queryResult as $inx => $row) { $subscription_id = $row['sub_id']; $status = $row['status']; @@ -822,6 +844,7 @@ class Notifications extends BaseController ->update(); log_message('error','inside the update function'); } + # getExpCustomerDetail fns Closed ################################################################ diff --git a/app/Models/NotificationModel.php b/app/Models/NotificationModel.php index c52edd78..4bad4109 100755 --- a/app/Models/NotificationModel.php +++ b/app/Models/NotificationModel.php @@ -177,6 +177,24 @@ public function customerGroupQueryExecution($queries){ } } +public function getExpDate2(){ + $db = \Config\Database::connect(); + + $query = "SELECT * FROM customer_groups WHERE group_name = 'EXPIRYDATE_2' AND isactive = 1"; + + $result = $db->query($query)->getResultArray(); + + if (isset($result[0]["group_query"])) { + return $result[0]["group_query"]; + } else { + + error_log('group_query is not available in getExpDate()'); + + return ; + + } +} + public function getTempName($name) { $db = \Config\Database::connect(); diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index d9a7725b..4ec21c91 100755 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -2122,7 +2122,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d isValid = false; } if (Quickadd_publishersCode === '') { - errorMessage += 'Book Publishers Code\n'; + errorMessage += 'Publisher Code\n'; isValid = false; } diff --git a/app/Views/notify_the_expiry_subscribers.php b/app/Views/notify_the_expiry_subscribers.php index 039e52d3..a18e815c 100755 --- a/app/Views/notify_the_expiry_subscribers.php +++ b/app/Views/notify_the_expiry_subscribers.php @@ -8,6 +8,9 @@ +
+ +
@@ -21,15 +24,62 @@ + + \ No newline at end of file + + diff --git a/app/Views/received_payments_report.php b/app/Views/received_payments_report.php index a8b3c3e4..214796d0 100644 --- a/app/Views/received_payments_report.php +++ b/app/Views/received_payments_report.php @@ -25,7 +25,7 @@ text-align: center; /* Center-align content */ border: none; /* No border for container */ background-color: transparent; /* Transparent container */ - width: 190px; /* Card width */ + width: 160px; /* Card width */ height: 50px; /* Card height */ padding-left: 20px; @@ -72,7 +72,8 @@