From 5d9b4ca3920302d89c7d30c4bb4f304a4a9c591b Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Mon, 9 Dec 2024 12:27:33 +0530 Subject: [PATCH] FIX_REQUESTED_CLIENT_CHANGES --- app/Config/Routes.php | 2 + app/Controllers/Event.php | 58 +++++++++++++++++- app/Controllers/Invoice.php | 51 +++++++++++----- app/Controllers/Payment.php | 5 +- app/Models/EventModel.php | 12 ++++ app/Models/InvoiceModel.php | 16 +++++ app/Views/address_pdf_landscape_template.php | 14 +++-- app/Views/customer_form.php | 18 +++--- app/Views/event_list.php | 5 +- app/Views/invoice_form.php | 11 +++- app/Views/invoice_pdf_template.php | 3 + .../itemwise_report_with_payment_method.php | 4 +- app/Views/received_payments_report.php | 4 +- app/Views/report_book_publish.php | 4 +- app/Views/report_expired_customers.php | 59 +++++++++++++++++-- app/Views/report_general_invoice.php | 4 +- app/Views/report_itemwise.php | 4 +- app/Views/report_userwise_and_eventwise.php | 4 +- app/Views/scheme_list.php | 2 +- 19 files changed, 230 insertions(+), 50 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4e3c4a76..0c10a667 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -108,6 +108,7 @@ $routes->post('address/generatePdf', 'Address::generatePdf'); #evnts $routes->get("event_list/", "Event::index"); $routes->get("new_event/(:any)", "Event::new_event/$1"); +$routes->get("delete_event/(:any)","Event::delete_event/$1"); $routes->post("insert_event/", "Event::insert_event"); $routes->post("change_default_event/", "Event::change_default_event"); @@ -148,6 +149,7 @@ $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'],'/report_userwise_and_eventwise','Invoice::userwise_eventwise_report'); $routes->match(['get','post'],'/expired_customer_report','Invoice::expired_customer_report'); +$routes->post('getActiveMembers','Invoice::getActiveMembers'); $routes->match(['get','post'],'/received_payments_report','Invoice::received_payments_report'); $routes->match(['get','post'],'/book_publishwise_Report','Invoice::book_publishwise_Report'); $routes->match(['get','post'],'/itemwise_report_with_payment_method','Invoice::itemwise_report_with_payment_method'); diff --git a/app/Controllers/Event.php b/app/Controllers/Event.php index 578f896a..88596401 100755 --- a/app/Controllers/Event.php +++ b/app/Controllers/Event.php @@ -23,7 +23,7 @@ class Event extends BaseController $EventModel = new EventModel(); $data['page_name'] = 'Event Details'; - $events = $EventModel->where($where)->orderBy('event_id', 'DESC')->findAll(); // Retrieve the events + $events = $EventModel->where('isactive',1)->where($where)->orderBy('event_id', 'DESC')->findAll(); // Retrieve the events // Sort the events by ID in descending order (newest first) // usort($events, function ($a, $b) { @@ -209,4 +209,60 @@ class Event extends BaseController return $this->response->setJSON(['response' => $response]); } + + public function delete_event($id) + { + try { + helper('session'); + $session_uid = get_logged_user_id(); + $event_model = new EventModel(); + + // Define the common where condition + $where = ['event_id' => (int)$id, 'isactive' => 1]; + + // Check if the event exists based on the where condition + $existingEvent = $event_model->where($where)->first(); + + if ($existingEvent) { + // Log info about deactivating the event + $this->logger->Info("Event: Going to Inactive ID = " . $id); + + // Data to update the event (mark as inactive) + $data = ['isactive' => 0, 'updated_by' => $session_uid]; + + // Update the event as inactive + $result = $event_model->where('event_id', $id)->where('isactive', 1)->set($data)->update(); + $last_query = $event_model->getLastQuery(); + // dd($last_query); + // Check if the event was updated + if ($result) { + // Log success info + $this->logger->Info("Event: has been Inactived successfully. Inactived ID = " . $id); + + // Set success flashdata + session()->setFlashdata('success', 'Event deactivated successfully.'); + } else { + // Log error if update fails + $this->logger->error("Event: Not able to Inactive ID = " . $id); + throw new \Exception("Failed to deactivate the event."); + } + + } else { + // Log error if no matching event is found + $this->logger->error("Event: No event found to deactivate with ID = " . $id); + session()->setFlashdata('error', 'Event not found or already inactive.'); + } + + } catch (\Exception $e) { + // Log error details + $this->logger->error("Event: Error Occurred = " . $e->getMessage() . " File = " . $e->getFile() . " Line = " . $e->getLine()); + + // Set error flashdata + session()->setFlashdata('error', 'Error: ' . $e->getMessage()); + } + + // Redirect to the event list page + return redirect()->route('event_list'); + } + } diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 415c133f..e7c634ba 100755 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -112,7 +112,7 @@ class Invoice extends BaseController // Get customer names for the dropdown, events details, and subscription books details $data['customers'] = $model->getData('customers', $where); - $data['events'] = $model->getData('events', $where); + $data['events'] = $model->getData('events', array_merge($where, ['isactive' => 1])); $data['books'] = $model->getCategoryBooks(2); // Invocie type = 2 (subscription) $data['invoice_number_formatting'] = $model->getData('invoice_number_formatting', $where); if ($id === '0') { @@ -411,8 +411,15 @@ class Invoice extends BaseController // Send notification if invoice is approved $this->logger->info($msg_flag_name . ": ID = " . $invoice_id . ", Status =" . $invoice_status); if ($invoice_status == 'Approved' && $invoice_id != "") { + + if(null!=($this->request->getPost('contact_method_mail'))){ + $contact_method['msg_mail'] = 1; + } + if(null!=($this->request->getPost('contact_method_whatsapp'))){ + $contact_method['msg_whatsapp'] = 1; + } $this->logger->info($msg_flag_name . ": in " . $invoice_status . ". ID = " . $invoice_id); - $this->approve_notifications((int)$invoice_id); + $this->approve_notifications((int)$invoice_id,isset($contact_method)?$contact_method:null); } // Redirect to the appropriate route based on the invoice type @@ -467,6 +474,7 @@ public function create_or_update_invoice($invoice_id, $msg_flag_name) public function prepare_invoice_data($invoice_id, $msg_flag_name) { + $invdate = $this->request->getVar('invoice_date'); $duedate = $this->request->getVar('due_date'); $invoice_status = $this->request->getPost('status'); @@ -774,9 +782,9 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ return $now . " " . $result; } - public function approve_notifications($invoice_id) + public function approve_notifications($invoice_id,$contact_method = null) { - $this->logger->info("Approve Notifications : ID " . $invoice_id); + log_message('info',"Approve Notifications : ID " . $invoice_id); $model = new InvoiceModel(); $where = ['I.business_id' => (int)get_business_id(), 'I.invoice_id' => $invoice_id, 'I.isactive' => 1]; $details = $model->getDetailForApproveNotifications($where); @@ -800,7 +808,7 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ $business_email = ""; $business_mobile_no = ""; if (isset($details)) { - $this->logger->info("Invoice: approve notification Request data type = " . gettype($details)); + log_message('info',"Invoice: approve notification Request data type = " . gettype($details)); } helper('notification'); $notification = new NotificationHelper(); @@ -883,17 +891,23 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ // 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: " . $url; + if(isset($contact_method['msg_whatsapp'])){ + $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: " . $url; - $params = (object) Null; - $params->number = (int)'91' . $recipient_mobile; - $params->type = "text"; - $params->message = $template; - $params->instance_id = $_ENV['WAAI_INSTANCE']; - $params->access_token = $_ENV['WAAI_TOKEN']; - $this->logger->info("Approve notification Email Request data = " . json_encode($records)); - $email_result = $notification->sendEmail($records); - $this->logger->info("Approve notification Email Response = " . json_encode($email_result)); + $params = (object) Null; + $params->number = (int)'91' . $recipient_mobile; + $params->type = "text"; + $params->message = $template; + $params->instance_id = $_ENV['WAAI_INSTANCE']; + $params->access_token = $_ENV['WAAI_TOKEN']; + } + if(isset($contact_method['msg_mail'])){ + log_message('info',"Approve notification Email Request data = " . json_encode($records)); + + $email_result = $notification->sendEmail($records); + log_message('info',"Approve notification Email Response = " . json_encode($email_result)); + + } // $this->logger->info("Approve notification Whatsapp Request data = " . json_encode($params)); // $whatsapp_result = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params); // $this->logger->info("Approve notification Whatsapp Response = " . json_encode($whatsapp_result)); @@ -1629,5 +1643,10 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ return $this->response->setJSON($response); } - + public function getActiveMembers(){ + $Invoice_Model = new InvoiceModel(); + $response['data'] = $Invoice_Model->getActiveMembers(); + // log_message('error',json_encode($response));die(); + return $this->response->setJSON($response); + } } diff --git a/app/Controllers/Payment.php b/app/Controllers/Payment.php index 70b9026d..398120e2 100644 --- a/app/Controllers/Payment.php +++ b/app/Controllers/Payment.php @@ -246,7 +246,10 @@ public function payment_success() { 'to_subscription' =>$tsubscription, ]; - $db->table('invoiceitems')->insert($requestData); + $db->table('invoiceitems')->insert($requestData); + $invoice = new Invoice(); + $contact_method['msg_mail'] = 1; + $invoice->approve_notifications((int)$invoice_id['invoice_id'],$contact_method); $model3 = new SubscriptionModel(); $invoiceController = new Invoice(); $membership_id = $invoiceController->generate_membership_id(6); diff --git a/app/Models/EventModel.php b/app/Models/EventModel.php index 354536a1..a6fe41ab 100755 --- a/app/Models/EventModel.php +++ b/app/Models/EventModel.php @@ -49,6 +49,18 @@ class EventModel extends Model return ["info"=>"","err"=>'Database operation failed: ' . $e->getMessage()]; } } + public function getData($table, $where = null, $whereIn = null) + { + $query = $this->db->table($table); + if ($where) { + $query->where($where); + } + if ($whereIn) { + // $query->whereIn($column_name,$missingValues) + $query->whereIn($whereIn[0], $whereIn[1]); + } + return $query->get()->getResult(); + } } diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index e7053418..e68ac8d4 100755 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -597,6 +597,21 @@ $result = $query // Fetch results as an associative array return $result->getResultArray(); } +public function getActiveMembers(){ + $result = + $this->db->table('subscription as S') + ->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, B.short_code, S.membership_id') + ->join('customers as C', 'C.customer_id = S.customer_id', 'left') + ->join('books as B', 'B.book_id = S.scheme_id', 'left') + ->where('S.isactive', 1) + ->where('S.status',1) + ->orderBy('S.to_subscription', 'ASC') + ->get(); + return $result->getResultArray(); + +} public function itemwise_report_data_with_publish_code($f_date = null, $t_date = null) { @@ -811,5 +826,6 @@ public function getActiveSchemes(){ + } diff --git a/app/Views/address_pdf_landscape_template.php b/app/Views/address_pdf_landscape_template.php index 68479364..4872db84 100755 --- a/app/Views/address_pdf_landscape_template.php +++ b/app/Views/address_pdf_landscape_template.php @@ -43,12 +43,18 @@
+ - - + + + + + + +
From: - invoice_number == $value->wp_api_order_id ? "Order Number :" : "Invoice Number :"; ?> + + invoice_number == $value->wp_api_order_id ? "Order Number :" : "Invoice Number :"; ?> invoice_number; ?> -
From:
diff --git a/app/Views/customer_form.php b/app/Views/customer_form.php index 667fd916..0e75d561 100755 --- a/app/Views/customer_form.php +++ b/app/Views/customer_form.php @@ -137,8 +137,8 @@
+
+ diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index d4d8d943..bfa4a0a9 100755 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -552,7 +552,16 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d - +
+
+
+ + +
+
+ + +
- +Sri Kasi, 12, M.V. Naidu Street, Chetpet,Chennai -