diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ad81baf..5b65b69 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -83,19 +83,21 @@ $routes->get('dashboard', 'Users::dashboard'); -//---------------------- Make And Model +//---------------------- Make And Model // Service // Make $routes->get('make_index', 'Make::index'); $routes->post('create_make', 'Make::create_make'); - - // Model $routes->get('bike_model_index/(:any)', 'Model::index/$1'); - $routes->post('create_model', 'Model::create_model'); - $routes->post('status_model', 'Model::status_model'); +// Service +$routes->get('service_index', 'Service::service_index'); +$routes->get("new_service/(:any)", "Service::new_service/$1"); +$routes->post("add_service", "Service::add_service"); +$routes->post("get_models_service", "Service::get_models"); +$routes->get("delete_service/(:any)", "Service::delete_service/$1"); diff --git a/app/Controllers/Service.php b/app/Controllers/Service.php new file mode 100644 index 0000000..abf8b1d --- /dev/null +++ b/app/Controllers/Service.php @@ -0,0 +1,242 @@ +session = session(); + } + + public function service_index() + { + + $ServiceModel = new ServiceModel(); + $services = $ServiceModel->findAll(); + + foreach ($services as &$service) { + // Convert JSON strings to arrays + $makes_ids = json_decode($service['makes_id'], true) ?? []; + $models_ids = json_decode($service['models_id'], true) ?? []; + + // Fetch make names + $makeNames = []; + $BikemakeModel = new BikemakeModel(); + + foreach ($makes_ids as $make_id) { + if (!empty($make_id)) { // Check if $make_id is not null or empty + $make = $BikemakeModel->find($make_id); + if ($make) { + $makeNames[] = $make['make']; + } + } + } + + // Fetch model names + $modelNames = []; + $BikemodelsModel = new BikemodelsModel(); + + foreach ($models_ids as $model_id) { + if (!empty($model_id)) { // Check if $model_id is not null or empty + $model = $BikemodelsModel->find($model_id); + if ($model) { + $modelNames[] = $model['model_name']; + } + } + } + + // Replace IDs with names + $service['makes_names'] = implode(', ', $makeNames); + $service['models_names'] = implode(', ', $modelNames); + } + + $data['services']=$services; + return view('service_list',$data); + } + + + public function new_service($service_id) + { + + + if ($service_id === '0') { + + $data['services'] = []; + $ServiceModel = new ServiceModel(); + $tax=$ServiceModel->getTax(); + $data['tax']=$tax; + $BikemakeModel = new BikemakeModel(); + $data['make'] = $BikemakeModel->findAll(); + $data['models'] = []; + $data['page_name']="Add Service"; + } else if ($service_id !== '0') { + + $ServiceModel = new ServiceModel(); + $services=$ServiceModel->where('service_id', $service_id)->get()->getRowArray(); + + $services['models_id'] = json_decode($services['models_id'], true); + $services['makes_id'] = json_decode($services['makes_id'], true); + + $data['page_name']="Edit Service"; + + + $models = []; + $BikemodelsModel = new BikemodelsModel(); + + foreach ($services['makes_id'] as $make_id) { + $models[] = $BikemodelsModel->where('make_id', $make_id)->findAll(); + } + $data['models'] = $models; + + // Load make data + $BikemakeModel = new BikemakeModel(); + $data['make'] = $BikemakeModel->findAll(); + + $tax=$ServiceModel->getTax(); + $data['tax']=$tax; + + $data['services']=$services; + + } + $data['service_id'] = $service_id; + // echo"
";
+ // print_r($data);die;
+ echo view('service_form',$data);
+ }
+
+
+ public function add_service()
+ {
+
+ $ServiceModel = new ServiceModel();
+
+ $tax= $this->request->getPost('tax')/2;
+
+ $make_ids = $this->request->getPost('make');
+ $model_ids = $this->request->getPost('model');
+
+
+ $model_json = json_encode($model_ids);
+ $make_json = json_encode($make_ids);
+ $data = [
+ 'service_name' => $this->request->getPost('servicename'),
+ 'price' => $this->request->getPost('price'),
+ 'cgst' => $tax,
+ 'igst' => $tax,
+ 'makes_id' => $make_json,
+ 'models_id' => $model_json,
+ 'description' => $this->request->getPost('description'),
+ 'isactive' => 1 ,
+ ];
+
+ $service_id = $this->request->getPost('service_id');
+
+
+ if (!empty($service_id)) {
+
+ $ServiceModel->update($service_id, $data);
+ } else {
+
+ $ServiceModel->insert($data);
+ }
+
+
+ return redirect()->to('service_index');
+ }
+
+ public function delete_service($service_id)
+ {
+ $ServiceModel = new ServiceModel();
+ $where = ['service_id' => $service_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database
+ $existingService = $ServiceModel->where($where)->first();
+
+ if ($existingService) {
+ $data['isactive'] = 0;
+
+ if ($ServiceModel->update($service_id, $data)) {
+ session()->setFlashdata('success', 'Deleted successfully.');
+ $this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$service_id);
+ }
+ }
+
+
+ return redirect()->to('service_index');
+ }
+
+ // Retrieve the make_id from the AJAX request
+ public function get_vendors_by_model()
+ {
+ $make_id = $this->request->getPost('make_id');
+ $model_ids = $this->request->getPost('model_ids');
+ // print_r( $model_ids);die;
+
+ // If make_id or model_ids is not provided, return an empty response
+
+
+ // Create an instance of VendorModel
+ $vendorModel = new VendorModel();
+
+ // Call the get_vendors_by_model method from the model
+ $vendors = $vendorModel->get_vendors_by_model($make_id, $model_ids);
+ // Return the response as JSON
+ // return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.']);
+ if ($vendors) {
+ // Return the retrieved vendors as JSON response
+ return $this->response->setJSON($vendors);
+ } else {
+ // If no vendors were found, return an empty response or handle the error accordingly
+ return $this->response->setJSON([]);
+ }
+ }
+
+
+
+
+
+ public function get_models()
+ {
+ $selected_makes = $this->request->getPost('selected_makes');
+
+ // Load the BikemakeModel to fetch models
+ $BikemodelModel = new BikemodelsModel();
+
+ // Initialize an empty array to store formatted model data
+ $formatted_models = [];
+
+ // Iterate over each selected make ID
+ if ($selected_makes) {
+ foreach ($selected_makes as $make_id) {
+ // Fetch models based on the selected make ID
+ $models = $BikemodelModel->where('make_id', $make_id)->findAll();
+
+ // Iterate over each fetched model and format it as needed
+ foreach ($models as $model) {
+ // Create an associative array with 'model_id' and 'model_name' properties
+ $formatted_model = [
+ 'make_id' => $model['make_id'],
+ 'model_id' => $model['model_id'],
+ 'model_name' => $model['model_name']
+ // Add other properties if needed
+ ];
+
+ // Push the formatted model into the array
+ $formatted_models[] = $formatted_model;
+ }
+ }
+ }
+
+ // Send the formatted models as JSON response back to the client
+ return $this->response->setJSON($formatted_models);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Controllers/Vendor.php b/app/Controllers/Vendor.php
index 27c917d..b3d490e 100644
--- a/app/Controllers/Vendor.php
+++ b/app/Controllers/Vendor.php
@@ -77,7 +77,7 @@ class Vendor extends BaseController
// Convert model IDs to JSON format
$model_json = json_encode($model_ids);
- $make_json=json_encode($make_ids);
+ $make_json=json_encode($make_ids);
$data = [
'vendor_name' => $this->request->getPost('vendor_name'),
'contact_name' => $this->request->getPost('contact_name'),
diff --git a/app/Models/ServiceModel.php b/app/Models/ServiceModel.php
new file mode 100644
index 0000000..28f65f2
--- /dev/null
+++ b/app/Models/ServiceModel.php
@@ -0,0 +1,28 @@
+table('tax')->get();
+
+ // Check if query returned results
+ if ($query->resultID->num_rows > 0) {
+ return $query->getResultArray();
+ } else {
+ return []; // Return an empty array if no tax data found
+ }
+ }
+
+}
+?>
\ No newline at end of file
diff --git a/app/Views/bike_model_list.php b/app/Views/bike_model_list.php
index 8b981d9..a6cd70f 100644
--- a/app/Views/bike_model_list.php
+++ b/app/Views/bike_model_list.php
@@ -1,9 +1,9 @@
-
+
- Bike Model List -
+ Bike Model List -