EVOLUTION-NINJA
Edit File: CustomerController.php
<?php namespace App\Controllers; use App\Models\ProductModel; use App\Models\ProductTypeModel; class CustomerController extends BaseController { // ========================================= // FETCH PRODUCT TYPES // ========================================= public function getProductTypes() { $productTypeModel = new ProductTypeModel(); $types = $productTypeModel ->where('status', 'active') ->findAll(); return $this->response->setJSON($types); } // ========================================= // FETCH PRODUCTS BASED ON TYPE // ========================================= public function getProductsByType() { $product_type = $this->request->getPost('product_type'); $productModel = new ProductModel(); $products = $productModel ->where('product_category', $product_type) ->where('status', 'active') ->findAll(); return $this->response->setJSON($products); } // ========================================= // FETCH PRODUCT DETAILS // ========================================= public function getProductDetails() { $product_id = $this->request->getPost('product_id'); $productModel = new ProductModel(); $product = $productModel ->where('product_id', $product_id) ->first(); return $this->response->setJSON($product); } // public function viewInvoice($id) // { // $model = new \App\Models\CreateCustomerModel(); // $data['customer'] = $model // ->where('id', $id) // ->first(); // return view('invoice/view_invoice', $data); // } // public function viewInvoice($id) // { // $model = new \App\Models\CreateCustomerModel(); // $data['customer'] = $model->where('id', $id)->first(); // $yearMonth = date('Ym'); // // use actual database ID (this gives 453, 231 style naturally) // $data['invoice_no'] = "INV-{$yearMonth}-{$id}"; // return view('invoice/view_invoice', $data); // } // public function viewInvoice($id) // { // $customerModel = new \App\Models\CreateCustomerModel(); // $productModel = new \App\Models\ProductModel(); // // customer data // $customer = $customerModel // ->where('id', $id) // ->first(); // // product details using product_id // $product = $productModel // ->where('product_id', $customer['product_id']) // ->first(); // // attach model name into customer array // $customer['product_model'] = // $product['model_name'] ?? ''; // $data['customer'] = $customer; // $yearMonth = date('Ym'); // $data['invoice_no'] = // "INV-{$yearMonth}-{$id}"; // return view('invoice/view_invoice', $data); // } public function viewInvoice($id) { $customerModel = new \App\Models\CreateCustomerModel(); $productModel = new \App\Models\ProductModel(); $aeModel = new \App\Models\AETransactionModel(); // CUSTOMER $customer = $customerModel ->where('id', $id) ->first(); // PRODUCT $product = $productModel ->where('product_id', $customer['product_id']) ->first(); // MODEL NAME $customer['product_model'] = $product['model_name'] ?? ''; // AE REPORT DATA $aeData = $aeModel ->where('customer_id', $id) ->first(); // FARMER SHARE $customer['farmer_share'] = $aeData['farmer_share'] ?? 0; $data['customer'] = $customer; $yearMonth = date('Ym'); $data['invoice_no'] = "INV-{$yearMonth}-{$id}"; return view('invoice/view_invoice', $data); } }