diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index 0b76818c..bae69804 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -38,9 +38,10 @@ class Customer extends BaseController { helper('session'); $session_bid = get_business_id(); + if ($id === '0') { // Add Customer - $data['page_name'] = 'Add Customer'; + $data['page_name'] = 'Add Customer'; $data['customer'] = []; $data['customer_billing'] = []; $data['customer_shipping'] = []; @@ -48,22 +49,27 @@ class Customer extends BaseController $data['invoices'] = []; } else if ($id !== '0') { // Edit Customer - $data['page_name'] = 'Edit Customer'; - $subscriptionModel = new SubscriptionModel(); - $subscriptionData = $subscriptionModel->getSubscriptionsByCustomerId($id); - $model = new CustomerModel(); - $model->setTable('customers'); - $edit_user_details = $model->where(['customer_id' => $id])->first(); + $data['page_name'] = 'Edit Customer'; + + // Load your Customer Model + $customerModel = new CustomerModel(); + + // Retrieve customer details by customer ID + $edit_user_details = $customerModel->where(['customer_id' => $id])->first(); $data['customer'] = $edit_user_details; $data['customer_billing'] = $this->get_customer_address($id, 1); $data['customer_shipping'] = $this->get_customer_address($id, 2); - $data['subscriptionData'] = $subscriptionData; + + // Retrieve subscriber data based on the customer ID + $subscriberData = $customerModel->getSubscriberDataByCustomerId($id); + $data['subscriptionData'] = $subscriberData; // Fetch invoice data for the customer $CustomerModel = new CustomerModel(); $invoices = $CustomerModel->getInvoicesByCustomerId($id); $data['invoices'] = $invoices; } + $data['session_bid'] = $session_bid; $this->render_page('customer_form', $data); } diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php index b3ee3a4a..1c10c68e 100644 --- a/app/Models/CustomerModel.php +++ b/app/Models/CustomerModel.php @@ -98,5 +98,22 @@ class CustomerModel extends Model ->get() ->getResult(); } +public function getSubscriberDataByCustomerId($customerId) +{ + // Assuming 'subscription' is the table name where subscriber data is stored. + $builder = $this->db->table('subscription'); + $builder->join('schemes', 'schemes.scheme_id = subscription.scheme_id'); + + + // Define the columns you want to select from the subscription table. + $builder->select('sub_id, to_subscription, from_subscription,schemes.scheme_name'); + + // Add a where condition to filter results based on customer ID. + $builder->where('customer_id', $customerId); + + // Execute the query and return the result as an array of objects. + return $builder->get()->getResult(); +} + } ?> \ No newline at end of file diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index 5992885e..dfbfbab6 100644 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -147,14 +147,7 @@ public function getAllCustomerDetailsBySchemeName($schemeName) return $customerDetails; } - public function getSubscriptionsByCustomerId($customerId) - { - $builder = $this->db->table('subscription'); - $builder->select('schemes.scheme_name,from_subscription,to_subscription'); - $builder->join('schemes', 'schemes.scheme_id = subscription.scheme_id'); - // Query to retrieve subscription records for a specific customer - return $builder->get()->getResultArray(); - } + } diff --git a/app/Views/customer_form.php b/app/Views/customer_form.php index 3508f406..fef4fb65 100644 --- a/app/Views/customer_form.php +++ b/app/Views/customer_form.php @@ -328,9 +328,9 @@ - - - + scheme_name ?> + from_subscription ?> + to_subscription ?> diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index e19b7465..b32d6bb2 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -740,5 +740,22 @@ invoiceDateInput.setAttribute("min", minDate); // Optional: Set the default value to today's date + + diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index 7c9066f8..092c92d9 100644 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -272,7 +272,7 @@ if (count($invoiceDateParts) === 3) {
- +
diff --git a/app/Views/template/header.php b/app/Views/template/header.php index 468503f1..79140cde 100644 --- a/app/Views/template/header.php +++ b/app/Views/template/header.php @@ -142,7 +142,7 @@
  • "> - + Products