From 0cd0be63c92c9ebae1b88867f3e7f376cadf9552 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Mon, 5 Jan 2026 10:04:31 +0530 Subject: [PATCH] GWM : vehicle type(product) CRUD --- app/Config/Routes.php | 6 +- app/Controllers/EnquiryController.php | 31 +++++++ app/Controllers/MasterController.php | 120 ++++++++++++++++++++++++-- 3 files changed, 147 insertions(+), 10 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 24b1441..230b321 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -35,7 +35,6 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { //Master $routes->get('master/getRoleMaster', 'MasterController::getRoleMaster'); - $routes->get('master/getVehicleTypeMaster', 'MasterController::getVehicleTypeMaster'); $routes->get('master/getInsurancePlanTypeMaster', 'MasterController::getInsurancePlanTypeMaster'); $routes->get('master/getClaimMaster', 'MasterController::getClaimMaster'); $routes->get('master/getEndorsementMaster', 'MasterController::getEndorsementMaster'); @@ -54,6 +53,10 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { $routes->post('master/createEndorsement', 'MasterController::createEndorsement'); $routes->post('master/updateEndorsement/(:num)', 'MasterController::updateEndorsement/$1'); $routes->post('master/updateEndorsementStatus/(:num)', 'MasterController::updateEndorsementStatus/$1'); + $routes->get('master/getVehicleTypeMaster', 'MasterController::getVehicleTypeMaster'); + $routes->post('master/createVehicleType', 'MasterController::createVehicleType'); + $routes->post('master/updateVehicleType/(:num)', 'MasterController::updateVehicleType/$1'); + $routes->post('master/updateVehicleTypeStatus/(:num)', 'MasterController::updateVehicleTypeStatus/$1'); @@ -101,6 +104,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { $routes->get('enquiry/updateEnquiryInProgress', 'EnquiryController::updateEnquiryInProgress'); $routes->get('enquiry/updateEnquiryStatus', 'EnquiryController::updateEnquiryStatus'); $routes->get('enquiry/checkVehicleDuplicate', 'EnquiryController::checkVehicleDuplicate'); // VALIDATION + $routes->post('enquiry/setVehicleTypeToEnquiry', 'EnquiryController::setVehicleTypeToEnquiry'); //Proposal diff --git a/app/Controllers/EnquiryController.php b/app/Controllers/EnquiryController.php index 1a5be4f..49d34ca 100644 --- a/app/Controllers/EnquiryController.php +++ b/app/Controllers/EnquiryController.php @@ -790,4 +790,35 @@ class EnquiryController extends ResourceController ]); } + + public function setVehicleTypeToEnquiry() + { + try { + $data = $this->request->getPost(); + + if (!isset($data['id'])) { + return $this->respond(['status' => 'failed', 'code' => 200, 'error' => 'ID Required'], 200); + } + + $id = $data['id']; + $enquiry = $this->enquiryModel->find($id); + + if (!$enquiry) { + return $this->respond(['status' => 'failed', 'code' => 200, 'error' => 'Data Not Found'], 200); + } + + $updateData = [ + 'vehicle_type_id' => $data['vehicle_type_id'] ?? $enquiry['vehicle_type_id'], + 'updated_by' => $data['updated_by'] ?? null, + ]; + + $this->enquiryModel->update($id, $updateData); + + return $this->respond(['status' => 'success', 'code' => 200, 'message' => 'Enquiry updated successfully'], 200); + + } catch (\Exception $e) { + return $this->respond(['status' => 'failed', 'code' => 500, 'error' => $e->getMessage()], 500); + } + } + } diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 1568e16..242de8f 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -66,16 +66,7 @@ class MasterController extends ResourceController return $this->respond(['status' => 200,'message' => 'success','data' => $data]); } - public function getVehicleTypeMaster() - { - $data = $this->VehicleTypeMasterModel->findAll(); - if (!$data) { - return $this->failNotFound('No data found'); - } - - return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - } public function getInsurancePlanTypeMaster() { @@ -132,6 +123,117 @@ class MasterController extends ResourceController return $this->respond(['status' => 200,'message' => 'success','data' => $data]); } + //Vehicle type CRUD--------------------------------------------------------------------- + public function getVehicleTypeMaster() + { + $data = $this->VehicleTypeMasterModel->findAll(); + + if (!$data) { + return $this->failNotFound('No data found'); + } + + return $this->respond(['status' => 200,'message' => 'success','data' => $data]); + } + + public function createVehicleType() + { + $input = $this->request->getJSON(true); + + if (empty($input['vehicle_type'])) { + return $this->response->setJSON(['status' => 404, 'message' => 'Value is required']); + } + + // Duplicate check (case-insensitive) + $exists = $this->VehicleTypeMasterModel + ->where('LOWER(vehicle_type)', strtolower($input['vehicle_type'])) + ->where('is_active', 1) + ->first(); + + if ($exists) { + return $this->response->setJSON([ + 'status' => 404, + 'message' => 'Vehicle Type already exists' + ]); + } + + $data = [ + 'vehicle_type' => $input['vehicle_type'], + 'is_active' => 1, + 'created_by' => $input['created_by'] ?? null, + ]; + + $this->VehicleTypeMasterModel->insert($data); + + return $this->response->setJSON([ + 'status' => 200, + 'message' => 'Vehicle Type created successfully' + ]); + } + + public function updateVehicleType($id) + { + $input = $this->request->getJSON(true); + + if (!$this->VehicleTypeMasterModel->find($id)) { + return $this->response->setJSON(['status' => 404, 'message' => 'Record not found']); + } + + // Duplicate name check (excluding current record) + $checkDuplicate = $this->VehicleTypeMasterModel + ->where('LOWER(vehicle_type)', strtolower($input['vehicle_type'])) + ->where('id !=', $id) + ->where('is_active', 1) + ->first(); + + if ($checkDuplicate) { + return $this->response->setJSON([ + 'status' => 404, + 'message' => 'Vehicle Type already exists' + ]); + } + + $data = [ + 'vehicle_type' => $input['vehicle_type'] , + 'updated_by' => $input['updated_by'] ?? null, + ]; + + $this->VehicleTypeMasterModel->update($id, $data); + + return $this->response->setJSON([ + 'status' => 200, + 'message' => 'Vehicle Type updated successfully' + ]); + } + + public function updateVehicleTypeStatus($id) + { + $input = $this->request->getJSON(true); + + if (!isset($input['is_active'])) { + return $this->response->setJSON([ + 'status' => 404, + 'message' => 'is_active field is required' + ]); + } + + $record = $this->VehicleTypeMasterModel->find($id); + if (!$record) { + return $this->response->setJSON(['status' => 404, 'message' => 'Record not found']); + } + + $status = ($input['is_active'] == 1) ? 0 : 1; + + $this->VehicleTypeMasterModel->update($id, [ + 'is_active' => $status, + 'updated_by' => $input['updated_by'] ?? null, + ]); + + return $this->response->setJSON([ + 'status' => 200, + 'message' => 'Status updated successfully' + ]); + } + //Broker CRUD--------------------------------------------------------------------------- public function getAllBrokers()