diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php
index 5fb89fe..9f2895e 100644
--- a/app/Controllers/Sales.php
+++ b/app/Controllers/Sales.php
@@ -306,9 +306,12 @@ public function delete_sales_product()
];
// Attempt to insert the client data
- if ($ClientModel->insert($data)) {
+ $id = $ClientModel->insert($data);
+ if ($id) {
+ $clientData = $ClientModel->where('client_id',$id)->first();
+
// If insertion succeeds, return success response
- return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.']);
+ return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','clientData'=>$clientData]);
} else {
// If insertion fails, return error response
return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']);
diff --git a/app/Controllers/Vehicle.php b/app/Controllers/Vehicle.php
index 56fdebb..7613135 100644
--- a/app/Controllers/Vehicle.php
+++ b/app/Controllers/Vehicle.php
@@ -24,11 +24,13 @@ class Vehicle extends BaseController
{
$VehicleModel = new VehicleModel();
- $vehicle=$VehicleModel->getCustomerandVehicle();
- $data['vehicle']=$vehicle;
+ $vehicle = $VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id'));
+ $data['vehicle'] = $vehicle;
+
$ClientModel = new ClientModel();
- $client=$ClientModel->findAll();
+ $client = $ClientModel->where('branch_id', $this->session->get('logged_user_branch_id'))->findAll();
$data['client']=$client;
+
return view('vehicle_list',$data);
}
@@ -41,16 +43,21 @@ class Vehicle extends BaseController
$ClientModel = new ClientModel();
$data['vehicle'] = [];
$data['page_name']="Add vehicle";
- $client=$ClientModel->findAll();
+ $client = $ClientModel->where('branch_id', $this->session->get('logged_user_branch_id'))->findAll();
$data['client']=$client;
} else if ($vehicle_id !== '0') {
+
$data['page_name']="Edit vehicle";
$VehicleModel = new VehicleModel();
- $vehicle=$VehicleModel->where('vehicle_id', $vehicle_id)->get()->getRowArray();
+ $vehicle= $VehicleModel->select('vehicle.*, model.model_name as model_name')
+ ->join('model', 'model.model_id = vehicle.model')
+ ->where('vehicle.vehicle_id', $vehicle_id)
+ ->where('vehicle.branch_id', $this->session->get('logged_user_branch_id'))
+ ->get()->getRowArray();
$data['vehicle']=$vehicle;
$ClientModel = new ClientModel();
- $client=$ClientModel->findAll();
+ $client=$ClientModel->where('branch_id', $this->session->get('logged_user_branch_id'))->findAll();
$data['client']=$client;
}
$data['vehicle_id'] = $vehicle_id;
@@ -74,12 +81,12 @@ class Vehicle extends BaseController
'city' => $this->request->getPost('city'),
'state' => $this->request->getPost('state'),
'postal_code' => $this->request->getPost('postalcode'),
- 'country' => $this->request->getPost('country'),
'make' => $this->request->getPost('make'),
'model' => $this->request->getPost('model'),
'reg_no' => $this->request->getPost('regno'),
'colour' => $this->request->getPost('colour'),
-
+ 'year_of_manufacturing' => $this->request->getPost('year_of_manufacturing'),
+ 'branch_id' => $this->session->get('logged_user_branch_id'),
'isactive' => 1 // Assuming this is a default value or handled separately
];
// print_r($data);die;
diff --git a/app/Models/VehicleModel.php b/app/Models/VehicleModel.php
index 67874b9..23d716b 100644
--- a/app/Models/VehicleModel.php
+++ b/app/Models/VehicleModel.php
@@ -3,16 +3,20 @@ namespace App\Models;
use CodeIgniter\Model;
class VehicleModel extends Model
{
+
+
protected $table = 'vehicle';
protected $primaryKey = 'vehicle_id';
- protected $allowedFields = ['vehicle_id','make','model','reg_no','colour','client_id','address','country','state','city','email','postal_code','mobile_no','isactive'];
+ protected $allowedFields = ['branch_id','vehicle_id','make','model','reg_no','year_of_manufacturing','colour','client_id','address','country','state','city','email','postal_code','mobile_no','isactive'];
- public function getCustomerandVehicle()
+ public function getCustomerandVehicle($branch_id)
{
// Select required fields from both tables
- $this->select('vehicle.*, client.client_name');
+ $this->select('vehicle.*, client.client_name , make.make as make_name , model.model_name as model_name');
$this->join('client', 'client.client_id = vehicle.client_id');
- // Add condition to fetch only active sales orders
+ $this->join('make', 'make.make_id = vehicle.make');
+ $this->join('model', 'model.model_id = vehicle.model');
+ $this->where('vehicle.branch_id', $branch_id);
$this->where('vehicle.isactive', 1);
// Get the results
diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php
index 38adb3c..7b1ef4c 100644
--- a/app/Views/sales_order_form.php
+++ b/app/Views/sales_order_form.php
@@ -487,10 +487,6 @@ function initializeSelect2() {