From 3a2456b629561c88d933f249d54f58c89b8726b1 Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Thu, 13 Nov 2025 17:54:23 +0530 Subject: [PATCH] FIX_minor Bugs --- app/Controllers/Products.php | 3 +- app/Controllers/Service.php | 24 ++++++++++++---- app/Controllers/Users.php | 51 +++++++++++++++------------------ app/Views/edit_account_form.php | 2 +- app/Views/sales_order_form.php | 23 ++++++++------- app/Views/service_form.php | 4 +-- 6 files changed, 59 insertions(+), 48 deletions(-) diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index dcb3d15..370d9eb 100755 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -682,9 +682,10 @@ class Products extends BaseController $purchase_order_level = floor($qty_in_stock / 2); // Calculate purchase reorder level (half of qty in stock) $purchase_order_level = is_nan($purchase_order_level) ? '' : $purchase_order_level; // Safely assign values (handle invalid numbers) $reorder_level = is_nan($qty_in_stock) ? '' : $qty_in_stock; + $ccIds = $this->request->getPost('cubic_centimeter_id'); $data = [ - 'cubic_centimeter_id' => json_encode($this->request->getPost('cubic_centimeter_id')), + 'cubic_centimeter_id' => !empty($ccIds) ? json_encode($ccIds) : null, 'product_name' => $this->request->getPost('product_name'), 'product_category' => $this->request->getPost('product_category'), 'total_amount' => $this->request->getPost('product_total_amount'), diff --git a/app/Controllers/Service.php b/app/Controllers/Service.php index 75a68f7..10bd3db 100755 --- a/app/Controllers/Service.php +++ b/app/Controllers/Service.php @@ -99,6 +99,7 @@ class Service extends BaseController $data['tax'] = $this->ServicesModel->getTax(); $data['cubiccapacity']= $this->ComplaintModel->getCubicCapacityName(); + $data['product'] = []; if ($service_id === '0') { @@ -107,7 +108,7 @@ class Service extends BaseController $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll(); $data['models'] = []; $data['service'] = $this->ServicesModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); - $data['product'] = []; + } else if ($service_id !== '0') { @@ -129,8 +130,17 @@ class Service extends BaseController $data['service'] = $this->ServicesModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); $ccid = json_decode($services['cubic_capacity_id'], true); - $data['product'] = $this->get_product_by_cc($ccid); - // dd($data['service']); + if ($services['category'] == 0) { + $data['product'] = $this->ProductModel + ->select('products.*, manufacturer.manufacturer_name') + ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id', 'left') + ->where('products.isactive', 1) + ->findAll(); + } elseif ($services['category'] == 1) { + $data['product'] = $this->get_product_by_cc($ccid); + } + + // dd($data); } $data['service_id'] = $service_id; echo view('service_form',$data); @@ -153,11 +163,15 @@ class Service extends BaseController // $model_json = json_encode($model_ids); // $make_json = json_encode($make_ids); + + $productIds = $this->request->getPost('product_id'); + $subServiceIds = $this->request->getPost('sub_service_id'); + $data = [ 'service_name' => $this->request->getPost('servicename'), 'category' => $this->request->getPost('category'), - 'product_id' => json_encode($this->request->getPost('product_id')), - 'sub_service_id' => json_encode($this->request->getPost('sub_service_id')), + 'product_id' => !empty($productIds) ? json_encode($productIds) : null, + 'sub_service_id' => !empty($subServiceIds) ? json_encode($subServiceIds) : null, 'cgst' => $tax, 'sgst' => $tax, 'tax' => $this->request->getPost('tax'), diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php index a97c7ab..d133604 100755 --- a/app/Controllers/Users.php +++ b/app/Controllers/Users.php @@ -281,46 +281,41 @@ class Users extends BaseController return view('user_form',$data); } - public function edit_account($user_id) { + + $roleModel = new RoleModel(); + $businessModel = new BusinessModel(); + $usersModel = new UsersModel(); + $uri = $this->request->getUri(); // Get the query parameters $queryParams = $uri->getQuery(); - if ($user_id === '0') { + + $data = []; + + // Fetch roles once (used in both cases) + $data['roles'] = $roleModel->getRoles(); + $data['business'] = $businessModel->findAll(); + + if ($user_id === '0') { // New user $data['users'] = []; - $BusinessModel=new BusinessModel(); - $business=$BusinessModel->findAll(); - // print_r($business);die; - $rolemodel = new RoleModel(); - - $roles =$rolemodel->getRoles(); - - $data['business'] = $business; - $data['roles'] = $roles; - } else if ($user_id !== '0') { + $data['role_name'] = ''; + } else { // Existing user - $UsersModel = new UsersModel(); - $users=$UsersModel->getUserById($user_id); - $BusinessModel=new BusinessModel(); - $business=$BusinessModel->findAll(); - $BranchModel=new BranchModel(); - $branch=$BranchModel->where("business_id",$users['business_id'])->findAll(); - $data['users']=$users; - $data['business'] = $business; - $data['branches'] = $branch; - $rolemodel = new RoleModel(); + $users = $usersModel->getUserById($user_id); + + $data['users'] = $users; - $role = $rolemodel->where('role_id',$users['role'])->first(); - $roles =$rolemodel->getRoles(); + $branchModel = new BranchModel(); + $data['branches'] = $branchModel->where('business_id', $users['business_id'])->findAll(); - $data['roles'] = $roles; - $data['role'] = $role; - + $role = $roleModel->where('role_id', $users['role'])->first(); + $data['role_name'] = $role['roles'] ?? ''; } + $data['user_id'] = $user_id; - return view('edit_account_form',$data); } diff --git a/app/Views/edit_account_form.php b/app/Views/edit_account_form.php index c097f49..db3b233 100755 --- a/app/Views/edit_account_form.php +++ b/app/Views/edit_account_form.php @@ -15,7 +15,7 @@

-

@

+

@

diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php index 93e5536..0f2fcf7 100755 --- a/app/Views/sales_order_form.php +++ b/app/Views/sales_order_form.php @@ -205,7 +205,7 @@ } else { $value_ml = ''; } - ?> + ?> '; - + ''; } } newRow += '' + @@ -1170,6 +1169,8 @@ $(document).on('click', '#selectClient', function() { }); function fetchMakeAndModel(makeId, modelId) { + + console.log("*************************"); // Make sure makeId and modelId are valid if (makeId !== '' && modelId !== '') { // Perform AJAX request to fetch product information diff --git a/app/Views/service_form.php b/app/Views/service_form.php index 1b05f78..49ba30f 100755 --- a/app/Views/service_form.php +++ b/app/Views/service_form.php @@ -53,7 +53,7 @@ @@ -381,7 +381,7 @@ document.getElementById('category').addEventListener('change', function() { // Append new options $('#productSelect').append(''); $.each(response, function(index, product) { - $('#productSelect').append(''); + $('#productSelect').append(''); }); } else { // Handle case when no vendors are found for the selected model