From 048d9ba61bd59c9a7060e85a5b5a181934fbdaed Mon Sep 17 00:00:00 2001 From: heama Date: Thu, 28 Sep 2023 17:04:11 +0530 Subject: [PATCH 1/2] subscription module --- app/Config/Routes.php | 3 +- app/Controllers/Subscription.php | 64 ++++++++++++++++++++------- app/Models/SchemeModel.php | 22 ++++++++- app/Models/SubscriptionModel.php | 63 +++++++++++++++++++++++++- app/Views/address_pdf_template.php | 28 ++++++------ app/Views/print_addresses_form.php | 47 ++++++++++++-------- app/Views/subscribers_list.php | 71 ++++++++++++------------------ 7 files changed, 201 insertions(+), 97 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index e59b1127..4a9da76a 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -86,7 +86,8 @@ $routes->get("delete_scheme/(:any)", "Scheme::delete_scheme/$1"); $routes->get("subscribers_list/", "Subscription::index"); $routes->get("new_subscription/", "Subscription::new_subscription/"); $routes->post("add_subscription/", "Subscription::add_subscription/"); -$routes->get('subscription/generate_pdf', 'Subscription::generate_pdf'); +$routes->post('subscription/download_details', 'Subscription::download_details'); + #adres priknt diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php index 4fec4727..499dd110 100644 --- a/app/Controllers/Subscription.php +++ b/app/Controllers/Subscription.php @@ -75,34 +75,64 @@ public function add_subscription() { // Subscription.php (Controller) -public function generate_pdf() +// 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() { - $schemeName = $this->request->getGet('scheme_name'); + $selectedScheme = $this->request->getPost('selected_scheme'); - // Call the model method to get customer addresses + // Call the model method to get all customer details for the selected scheme $subscriptionModel = new SubscriptionModel(); - $addresses = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName); - $billingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 1); - $shippingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 2); - $customerName = $subscriptionModel->getCustomerNameBySchemeName($schemeName); + $customerDetails = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme); + + // Create an HTML content string using the view file (similar to print_addresses.php) + if (!empty($customerDetails)) { + $html = view('print_addresses_form', ['customerDetails' => $customerDetails]); - // Create an HTML content string using the view file - if ($customerName !== 'Customer not found') { - // Create an HTML content string using the view file - $html = view('print_addresses_form', ['customerName' => $customerName, 'billingInfo' => $billingInfo, 'shippingInfo' => $shippingInfo]); - // Generate a PDF from the HTML content $pdf = new Mpdf(); - + $pdf->WriteHTML($html); - // Output the PDF to the browser in a new tab - $pdf->Output('CustomerAddress.pdf', 'D'); + // 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'; + // Handle the case where no customer details are found for the selected scheme + echo 'No customer details found for the selected scheme.'; } } + } // public function generate_pdf() // { diff --git a/app/Models/SchemeModel.php b/app/Models/SchemeModel.php index a93e7ac9..11d64fad 100644 --- a/app/Models/SchemeModel.php +++ b/app/Models/SchemeModel.php @@ -81,10 +81,28 @@ public function getSchemeNames() print_r($schemes);die(); } +public function getSchemeNameById($schemeId) +{ + // Query the database to retrieve the scheme name by ID + $builder = $this->db->table('schemes'); + $builder->select('scheme_name'); + $builder->where('scheme_id', $schemeId); + $query = $builder->get(); + // Check if a record was found + if ($query->getNumRows() > 0) { + $row = $query->getRow(); + return $row->scheme_name; + } else { + return null; // Return null if no scheme with the given ID is found + } +} +public function getAllSchemes() + { + return $this->findAll(); + } } - - \ No newline at end of file + diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index 9ce1a9ac..4ab630fe 100644 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -86,8 +86,69 @@ public function getCustomerAddressesBySchemeName($schemeName) return $addresses; } +public function getAllCustomerDetailsBySchemeName($schemeName) +{ + $builder = $this->db->table('subscription'); + $builder->select('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,business.address,business.city,business.state,business.postal_code,schemes.scheme_name,from_subscription,to_subscription'); + $builder->join('customers', 'customers.customer_id = subscription.customer_id'); + $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id'); + $builder->join('business', 'business.business_id = subscription.business_id'); + $builder->join('schemes', 'schemes.scheme_id = subscription.scheme_id'); + $builder->where('schemes.scheme_name', $schemeName); + $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2 + $builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers + + // Fetch the query result + $query = $builder->get(); + + $customerDetails = []; + + if ($query->getNumRows() > 0) { + $currentCustomerID = null; + $shippingAddress = []; + + foreach ($query->getResultArray() as $row) { + $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'], + 'postal_code' => $row['postal_code'], + 'address' => $row['address'], + 'city' => $row['city'], + 'state' => $row['state'], + 'postal_code' => $row['postal_code'], + 'title' => $row['title'], + 'to_subscription'=>$row['to_subscription'], + 'scheme_name'=>$row['scheme_name'], + ]; + + $currentCustomerID = $customerID; + } + } + + // Add the last customer's details (if any) + if (!empty($shippingAddress)) { + $customerDetails[] = $shippingAddress; + } + } + + return $customerDetails; +} + } - diff --git a/app/Views/address_pdf_template.php b/app/Views/address_pdf_template.php index 0b299746..632d118e 100644 --- a/app/Views/address_pdf_template.php +++ b/app/Views/address_pdf_template.php @@ -12,21 +12,22 @@ } .shipping-label { - width: 250px; /* Reduced width for courier cover */ - margin: 20px auto; + width: 400px; /* Set the width */ + height: 140px; /* Set the height to match the width for a square shape */ + margin: 10px; border: 1px solid #000; background-color: #fff; padding: 10px; } .label-title { - font-size: 14px; /* Reduced font size for title */ + font-size: 12px; font-weight: bold; margin-bottom: 10px; } .address { - font-size: 12px; /* Reduced font size for address */ + font-size: 16px; margin-top: 10px; } @@ -40,29 +41,26 @@ } .footer { - font-size: 10px; + font-size: 14px; text-align: center; margin-top: 10px; } .business-logo { - max-width: 150px; /* Adjust the logo size */ + max-width: 150px; } - +
- -
- -
-

address ?>,
city ?>, state ?>,

-

postal_code ?>

-

email ?>

-

mobile_no ?>

+
+ address ?>,
city ?>, state ?>, + postal_code ?>
+ +

To:

customer_name ?>

diff --git a/app/Views/print_addresses_form.php b/app/Views/print_addresses_form.php index be574358..c5c83f83 100644 --- a/app/Views/print_addresses_form.php +++ b/app/Views/print_addresses_form.php @@ -12,21 +12,22 @@ } .shipping-label { - width: 250px; /* Reduced width for courier cover */ - margin: 20px auto; + width: 600px; /* Set the width */ + height: 140px; /* Set the height to match the width for a square shape */ + margin: 10px; border: 1px solid #000; background-color: #fff; padding: 10px; } .label-title { - font-size: 14px; /* Reduced font size for title */ + font-size: 10px; font-weight: bold; margin-bottom: 10px; } .address { - font-size: 12px; /* Reduced font size for address */ + font-size: 16px; margin-top: 10px; } @@ -40,40 +41,48 @@ } .footer { - font-size: 10px; + font-size: 14px; text-align: center; margin-top: 10px; } .business-logo { - max-width: 150px; /* Adjust the logo size */ + max-width: 150px; } - +
- +
+   + + - + +
-
- -

-
- + +

To:

-

- -

-

 

-

+
+ +
+
+
+    
+

+ +
+
Barcode
- + +
diff --git a/app/Views/subscribers_list.php b/app/Views/subscribers_list.php index f8757b63..3a17e281 100644 --- a/app/Views/subscribers_list.php +++ b/app/Views/subscribers_list.php @@ -3,8 +3,8 @@
- - Print Address + + Add New @@ -44,34 +44,41 @@ -