logger->info("Invoice: Listing In Admin BID = " . $session_bid); $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'S.invoice_id !='=>"",'S.sub_id !='=>""]; } else { $this->logger->info("Invoice: Listing In the Super-Admin "); $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'S.invoice_id !='=>"",'S.sub_id !='=>""]; } $model = new InvoiceModel(); $data['page_name'] = 'Subscription Invoice Details'; $data['invoice'] = $model->getSubscriptionInvoiceDetail($where); $this->logger->info("Invoice: Listing Count ." . count($data['invoice'])); $data['active_schemes'] = $model->getActiveSchemes(); // $data['subscriber'] = $SubscriptionModel->where($where)->findAll();; //dd($data); $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'); } } public function new_subscription() { helper('session'); helper('session'); $session_bid = get_business_id(); $data['page_name'] = 'Subscription Details'; $customerModel = new CustomerModel(); $schemeModel = new SchemeModel(); $business_id = get_business_id(); // Get scheme names and durations from the SchemeModel $data['customers'] = $customerModel->getCustomerNamesByBusiness($business_id); $data['scheme_names'] = $schemeModel->getSchemeNamesAndDurationsByBusiness($business_id); //print_r($data);die(); $this->render_page('subscription_form', $data); } // Subscription Controller (Subscription.php) public function add_subscription() { helper('session'); $session_bid = get_business_id(); $session_uid = get_logged_user_id(); $validationRules = [ 'customer_name' => 'required', 'from_subscription' => 'required', 'to_subscription' => 'required', 'shipping_address_id' => 'required', 'invoice_date' => 'required|valid_date', 'scheme' => 'required' ]; if (!$this->validate($validationRules)) { $validation = \Config\Services::validation(); $errorMessage = $validation->getErrors(); $firstError = reset($errorMessage); return redirect()->back()->with('error', $firstError)->withInput(); } $SubscriptionModel = new SubscriptionModel(); $data = [ 'scheme_id' =>$this->request->getPost('scheme'), 'customer_id' =>$this->request->getPost('customer'), 'from_subscription' => $this->request->getPost('from_date'), 'to_subscription' => $this->request->getPost('to_date'), // 'type' => "subscribed customer", 'type' => "customer", 'mode' => $this->request->getPost('mode'), 'business_id'=>$session_bid ]; $SubscriptionModel->insert($data); // $data['subscriber'] = $subscriberModel->getAllSubscribersWithNames(); // print_r($data);die(); return redirect()->to('subscribers_list')->with('data', $data); } // Subscription.php (Controller) // public function download_details() // { // $selectedScheme = $this->request->getPost('selected_scheme'); // // Call the model method to get customer details for the selected scheme // $subscriptionModel = new SubscriptionModel(); // $business = $subscriptionModel->getCustomerAddressesBySchemeName($selectedScheme); // $shippingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($selectedScheme, 2); // $customerName = $subscriptionModel->getCustomerNameBySchemeName($selectedScheme); // // Create an HTML content string using the view file (similar to print_addresses.php) // if ($customerName !== 'Customer not found') { // $html = view('print_addresses_form', ['customerName' => $customerName, 'shippingInfo' => $shippingInfo, 'business' => $business]); // // Generate a PDF from the HTML content // $pdf = new Mpdf(); // $pdf->WriteHTML($html); // // Set the PDF filename // $filename = 'CustomerDetails_' . date('YmdHis') . '.pdf'; // // Output the PDF for download // $pdf->Output($filename, 'D'); // } else { // // Handle the case where the customer is not found // echo 'Customer not found'; // } // } public function download_details_by_hema() { $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 = []; // Iterate through selected schemes if (!empty($selectedSchemes)) { foreach ($selectedSchemes as $selectedScheme) { // Call the model method to get customer details for each selected scheme and download type $subscriptionModel = new SubscriptionModel(); if ($downloadType === 'active') { $details = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme); } elseif ($downloadType === 'expired') { $details = $subscriptionModel->getAllExpiredCustomerDetailsByScheme($selectedScheme); } elseif ($downloadType === 'both') { $details =$subscriptionModel->getBothDetailsSchemeName($selectedScheme); } $customerDetails = array_merge($customerDetails, $details); } if (!empty($customerDetails)) { // Pass customer details, action, and pdf to the view $html = view('print_addresses_form', ['customerDetails' => $customerDetails, 'action' => $action, 'pdf' => $pdf]); // 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 ""; } } 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); // dd($customerDetails); if (!empty($customerDetails)) { $html = view('print_addresses_form', ['customerDetails' => $customerDetails, 'action' => $action, 'pdf' => $pdf]); // echo $html;die; // Add the details to the PDF ini_set('pcre.backtrack_limit', 10000000); $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 ""; } } public function notify_the_expiry_subscribers(){ if ($this->request->is('post')){ $dateParts = explode(' - ', $this->request->getPost('date')); $fromDate = $dateParts[0]; $toDate = $dateParts[1]; $from_date = \DateTime::createFromFormat('d/m/Y', $fromDate); $to_date = \DateTime::createFromFormat('d/m/Y', $toDate); $model = new NotificationModel(); $response['data'] = $model->get_email_data($from_date->format('Y-m-d'), $to_date->format('Y-m-d')); // log_message('info','Selected from date is '.$from_date); $response['selected_data'] = $this->request->getPost('date'); return $this->response->setJson($response); } $data['page_name'] = 'Notify the Expiry Subscribers'; $data['selected_data'] = ''; $this->render_page('notify_the_expiry_subscribers',$data); } } // public function generate_pdf() // { // $schemeName = $this->request->getGet('scheme_name'); // // Call the model method to get the customer's name and address (billing or shipping) // $subscriptionModel = new SubscriptionModel(); // // For billing address // $billingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 1); // // For shipping address // $shippingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 2); // print_r($billingInfo); // print_r($shippingInfo); // // Handle the PDF generation using $billingInfo['customer_name'], $billingInfo['address'] (for billing address) // // and $shippingInfo['customer_name'], $shippingInfo['address'] (for shipping address) // }