diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 5349988e..60a6305a 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -258,7 +258,14 @@ class Invoice extends BaseController } - return redirect()->route('invoice_list'); + + if ($invoiceType === '1') { + // If the invoice_type is 1 (subscription invoice), redirect to the subscription list. + return redirect()->route('subscribers_list'); // Adjust the route name as needed. + } else { + // For other invoice types, redirect to the invoice list. + return redirect()->route('invoice_list'); // Adjust the route name as needed. + } } ## For Updating Events Details .. diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php index f901f3ba..d67fa18b 100644 --- a/app/Controllers/Subscription.php +++ b/app/Controllers/Subscription.php @@ -6,6 +6,7 @@ namespace App\Controllers; use App\Models\CustomerModel; use App\Models\SubscriptionModel; use App\Models\SchemeModel; +use App\Models\InvoiceModel; use Mpdf\Mpdf; class Subscription extends BaseController @@ -17,15 +18,26 @@ class Subscription extends BaseController $session_bid = get_business_id(); if (!empty($session_role) && $session_role !== "sadmin") { - $where = ['subscription.business_id'=>(int)$session_bid]; - }else{ $where = ['subscription.business_id != '=>NULL];} + $this->logger->info("Invoice: Listing In Admin BID = " . $session_bid); + $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1]; + } else { + $this->logger->info("Invoice: Listing In the Super-Admin "); + $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL]; + } + + $model = new InvoiceModel(); + $data['page_name'] = 'Subscription Invoice Details'; + $data['invoice'] = $model->getJoinedData($where); + + $this->logger->info("Invoice: Listing Count ." . count($data['invoice'])); - $SubscriptionModel = new SubscriptionModel(); - $data['page_name'] = 'Subscription Details'; - // $data['subscriber'] = $SubscriptionModel->where($where)->findAll();; - $data['subscriber'] = $SubscriptionModel->getAllSubscribersWithNames($where); - + // $data['subscriber'] = $SubscriptionModel->where($where)->findAll();; + + + $SubscriptionModel = new SubscriptionModel(); + $swhere = ['subscription.business_id' => (int)$session_bid]; + $data['subscriber'] = $SubscriptionModel->getAllSubscribersWithNames($swhere); $this->render_page('subscribers_list', $data); }else { return redirect()->to('login'); @@ -109,32 +121,34 @@ public function add_subscription() { // } public function download_details() { - $selectedScheme = $this->request->getPost('selected_scheme'); + $selectedSchemes = $this->request->getPost('selected_schemes'); - // Call the model method to get all customer details for the selected scheme - $subscriptionModel = new SubscriptionModel(); - $customerDetails = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme); + // Initialize an empty PDF + $pdf = new Mpdf(); - // Create an HTML content string using the view file (similar to print_addresses.php) - if (!empty($customerDetails)) { - $html = view('print_addresses_form', ['customerDetails' => $customerDetails]); + // Iterate through selected schemes + foreach ($selectedSchemes as $selectedScheme) { + // Call the model method to get customer details for each selected scheme + $subscriptionModel = new SubscriptionModel(); + $customerDetails = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme); - // Generate a PDF from the HTML content - $pdf = new Mpdf(); + // Create an HTML content string for the current scheme + if (!empty($customerDetails)) { + $html = view('print_addresses_form', ['customerDetails' => $customerDetails]); - $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 no customer details are found for the selected scheme - echo 'No customer details found for the selected scheme.'; + // Add the current scheme's 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'); } + } // public function generate_pdf() // { diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index f9e820d6..6a64bb94 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -48,6 +48,7 @@ public function updateData($table, $data, $where) { return $this->db->table($this->table.' as I' ) + ->join('customers as C', 'C.customer_id = I.customer_id', 'left') ->join('events as E', 'E.id = I.event_id', 'left') ->join('business as B', 'B.business_id = I.business_id', 'left') @@ -55,6 +56,7 @@ public function updateData($table, $data, $where) ->join('users as U2', 'U2.user_id = I.updated_by', 'left') ->select('I.invoice_id, I.invoice_number, I.customer_id,concat(C.first_name," ",C.last_name) as customer_name , I.invoice_date, I.due_date, I.subtotal, I.tax, I.discount, I.total_amount,I.status, I.payment_status, I.order_number, I.payment_method,I.invoice_type, I.event_id,E.event_name, I.business_id,B.title as business_name, I.created_on, I.created_by,concat(U1.first_name," ",U1.last_name) as created_by_name, I.updated_on, I.updated_by,concat(U2.first_name," ",U2.last_name) as updated_by_name, I.isactive,C.email as customer_email,C.mobile_no as customer_mobile,I.shipping_address_id,I.shipping_address,I.billing_address_id,I.billing_address,B.address as business_address,B.city as business_city,B.state as business_state,B.postal_code as business_postal_code,B.email as business_email,B.mobile_no as business_mobile_no') ->where($where) + ->orderBy('invoice_id', 'DESC') ->get() ->getResultArray(); diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index bf3d1805..d6f3d0ef 100644 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -48,8 +48,8 @@ public function getCustomerAddressesBySchemeName($schemeName) $builder->join('customers', 'customers.customer_id = subscription.customer_id'); $builder->join('customer_addresses', 'customer_addresses.customer_id = subscription.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->join('books', 'books.book_id = subscription.scheme_id'); + $builder->where('books.title', $schemeName); $query = $builder->get(); @@ -89,12 +89,12 @@ public function getCustomerAddressesBySchemeName($schemeName) 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->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,books.title,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->join('books', 'books.book_id = subscription.scheme_id'); + $builder->where('books.title', $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 @@ -132,7 +132,7 @@ public function getAllCustomerDetailsBySchemeName($schemeName) 'postal_code' => $row['postal_code'], 'title' => $row['title'], 'to_subscription'=>$row['to_subscription'], - 'scheme_name'=>$row['scheme_name'], + 'title'=>$row['title'], ]; $currentCustomerID = $customerID; diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index 7926660c..d8055940 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -217,7 +217,7 @@ name="discount_amount[]" oninput="calculateInvoice(this)" /> - + > + oninput="calculateOverallTotals()" >
- + > + oninput="calculateOverallTotals()" >
@@ -438,7 +436,7 @@ $shippingChargesStyle = $isSubscriptionInvoice ? 'display: none;' : ''; cell6.innerHTML = ''; cell7.innerHTML = - ''; + ''; cell8.innerHTML = '
'; diff --git a/app/Views/invoice_list.php b/app/Views/invoice_list.php index 629e05a7..ed64e377 100644 --- a/app/Views/invoice_list.php +++ b/app/Views/invoice_list.php @@ -56,6 +56,7 @@ + @@ -74,6 +75,7 @@ + @@ -91,7 +93,7 @@ " class="download-pdf-button" title="Download the Invoice">  " class="print-address-button" title="Print Address">  - +
Invoice Number Invoice Date
diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index aa552b9e..4bd1529c 100644 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -253,8 +253,10 @@ if (count($invoiceDateParts) === 3) { imgs[0]->wp_img_url)) : ?> Product Image + imgs[0]) && !empty($item->imgs[0]->img_name)) : ?> Fallback Image - + + title ?> @@ -288,8 +290,19 @@ if (count($invoiceDateParts) === 3) { shipping_label?> :   ₹shipping_charge, 2, '.', ',') ?> - Total :   ₹subtotal, 2, '.', ',') ?> + Total :   ₹total_amount, 2, '.', ',') ?> + status === 'Draft'): ?> + + + Balance :   ₹total_amount, 2, '.', ',') ?> + + +status === 'Approved'): ?> + + Paid :   ₹total_amount, 2, '.', ',') ?> + + diff --git a/app/Views/print_addresses_form.php b/app/Views/print_addresses_form.php index 6c9ae392..6bf343f8 100644 --- a/app/Views/print_addresses_form.php +++ b/app/Views/print_addresses_form.php @@ -82,7 +82,7 @@ Barcode - + diff --git a/app/Views/subscribers_list.php b/app/Views/subscribers_list.php index 9ae4b347..530cb1e9 100644 --- a/app/Views/subscribers_list.php +++ b/app/Views/subscribers_list.php @@ -16,34 +16,49 @@ - +
- - + + + - - - - - + + + + + + - + - - - - - - - - + + + + + + + +   + + +
Scheme NameInvoice NumberInvoice Date Customer NameSubscription FromSubscription ToMode
StatusTotalAction
" class="approve-button" title="Approve the Invoice">  + + + " class="edit-button" title="Edit the Invoice">  + + " class="edit-button" title="Edit the Invoice">  + + + " class="download-pdf-button" title="Download the Invoice">  + " class="print-address-button" title="Print Address">
- - - @@ -62,21 +77,23 @@
- -
- - -
- +
+ +
+ + +
+ +
+
@@ -90,14 +107,15 @@ + + + + + - - - -