From 069f30ebc6b97b4fe3253a1ed8c03054b53309d3 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Fri, 7 Nov 2025 10:50:50 +0530 Subject: [PATCH] GWM : broker added --- app/Config/Routes.php | 1 + app/Controllers/EnquiryController.php | 10 +- app/Controllers/MasterController.php | 638 +------------------------- app/Models/EnquiryModel.php | 7 +- app/Models/PartnerBrokerModel.php | 25 + 5 files changed, 49 insertions(+), 632 deletions(-) create mode 100644 app/Models/PartnerBrokerModel.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 8311fca..818fa7a 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -40,6 +40,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { $routes->get('master/getEndorsementMaster', 'MasterController::getEndorsementMaster'); $routes->get('master/getInsurersMaster', 'MasterController::getInsurersMaster'); $routes->get('master/getStaffMaster', 'MasterController::getStaffMaster'); + $routes->get('master/getAllBrokers', 'MasterController::getAllBrokers'); //Agent $routes->get('agent/agentList', 'AgentController::agentList'); diff --git a/app/Controllers/EnquiryController.php b/app/Controllers/EnquiryController.php index 427f0f9..aa5eaa2 100644 --- a/app/Controllers/EnquiryController.php +++ b/app/Controllers/EnquiryController.php @@ -102,9 +102,10 @@ class EnquiryController extends ResourceController } //Get enquiry details - $enquiry = $this->enquiryModel->select('partner_enquiry.* , I.name as insurer_name , VT.vehicle_type as vehicle_type') + $enquiry = $this->enquiryModel->select('partner_enquiry.* , I.name as insurer_name , VT.vehicle_type as vehicle_type,PB.name as broker_name') ->join('insurers I', 'I.id = partner_enquiry.insurer_id', 'left') ->join('vehicle_type VT', 'VT.id = partner_enquiry.vehicle_type_id', 'left') + ->join('partner_brokers PB', 'PB.id = partner_enquiry.broker_id', 'left') ->where('partner_enquiry.id', $enquiry_id) ->where('partner_enquiry.is_active', 1) ->first(); @@ -114,10 +115,11 @@ class EnquiryController extends ResourceController } //Get related quotations - $quotations = $this->QuotationModel->select('partner_quotation.*, pe.reg_no , I.name as insurer_name, ipti.insurance_plan_type' ) + $quotations = $this->QuotationModel->select('partner_quotation.*, pe.reg_no , I.name as insurer_name, ipti.insurance_plan_type,PB.name as broker_name' ) ->join('partner_enquiry pe', 'pe.id = partner_quotation.enquiry_id', 'left') ->join('insurers I', 'I.id = partner_quotation.insurer_id', 'left') ->join('partner_insurance_plan_type_master ipti', 'ipti.id = partner_quotation.insurance_plan_type_id', 'left') + ->join('partner_brokers PB', 'PB.id = pe.broker_id', 'left') ->where('partner_quotation.enquiry_id', $enquiry_id) ->where('partner_quotation.is_active', 1) ->orderBy('partner_quotation.id', 'DESC') @@ -131,11 +133,12 @@ class EnquiryController extends ResourceController if($value['status'] == 'Accepted') { $quotationId = $value['id']; } } - $policies = $this->PolicyModel->select('partner_policy.*, pe.reg_no, I.name as insurer_name, pq.insured_declared_value, ipti.insurance_plan_type') + $policies = $this->PolicyModel->select('partner_policy.*, pe.reg_no, I.name as insurer_name, pq.insured_declared_value, ipti.insurance_plan_type, PB.name as broker_name') ->join('partner_enquiry pe', 'pe.id = partner_policy.enquiry_id', 'left') ->join('partner_quotation pq', 'pq.id = partner_policy.quotation_id', 'left') ->join('insurers I', 'I.id = pq.insurer_id', 'left') ->join('partner_insurance_plan_type_master ipti', 'ipti.id = pq.insurance_plan_type_id', 'left') + ->join('partner_brokers PB', 'PB.id = pe.broker_id', 'left') ->where('partner_policy.quotation_id', $quotationId) ->where('partner_policy.is_active', 1) ->first(); @@ -322,6 +325,7 @@ class EnquiryController extends ResourceController 'assigned_to' => $data['assigned_to'], 'insurer_id' => $data['insurer_id'], 'insurer_branch_id'=> $insurerBranchresult['id'] ?? 0, + 'broker_id' => $data['broker_id'] ?? 1, ]; $this->enquiryModel->update($id, $updateData); diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 9c46513..d0a7352 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -10,6 +10,8 @@ use App\Models\ClaimTypeModel; use App\Models\EndorsementTypeModel; use App\Models\InsurersModel; use App\Models\StaffModel; +use App\Models\PartnerBrokerModel; + class MasterController extends ResourceController @@ -23,6 +25,7 @@ class MasterController extends ResourceController protected $EndorsementTypeModel; protected $InsurersModel; protected $StaffModel; + protected $PartnerBrokerModel; public function __construct() @@ -35,6 +38,7 @@ class MasterController extends ResourceController $this->EndorsementTypeModel = new EndorsementTypeModel(); $this->InsurersModel = new InsurersModel(); $this->StaffModel = new StaffModel(); + $this->PartnerBrokerModel = new PartnerBrokerModel(); } @@ -122,636 +126,16 @@ class MasterController extends ResourceController return $this->respond(['status' => 200,'message' => 'success','data' => $data]); } + public function getAllBrokers() + { + + $data = $this->PartnerBrokerModel->where('is_active', 1)->findAll(); - // public function getTravelStatusMaster() - // { - // $data = $this->travelStatusModel->where('is_active',1)->findAll(); + return $this->respond(['status' => 200,'message' => 'success','data' => $data]); + } - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function getcountryMaster() - // { - // $data = $this->countryModel->where('is_active',1)->findAll(); - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function getAirlineMaster() - // { - // $data = $this->airlineModel->findAll(); - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - - // public function getAirportCodeMaster() - // { - // $type = $this->request->getGet('trip_type'); - - // // Build the query - // $query = $this->airportCodeModel->where('is_active', 1); - // if ($type == 1) { - // $query->where('Country_Code', 'IN'); - // } - - // // Execute the query and get the result - // $data = $query->findAll(); - - // // Check if data exists - // if (empty($data)) { - // return $this->failNotFound('No data found'); - // } - - // // Return success response - // return $this->respond([ - // 'status' => 200, - // 'message' => 'success', - // 'data' => $data - // ]); - // } - - // public function getTrainCodeMaster() - // { - // $data = $this->trainStationsModel->where('is_active',1)->findAll(); - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function getFlightAndTrainClass() - // { - - - // $trip_type = $this->request->getGet('trip_type'); - // $user_id = $this->request->getVar('user_id'); - - // $user = $this->userModel->where('user_id', $user_id)->first(); - - // $groupData = $this->groupModel->find($user['group_id']); - - // if($groupData) - // { - // if($trip_type == 1) { $policyId = $groupData['domestic_policy_id'];}else{ $policyId = $groupData['international_policy_id'];} - // dd($policyId); - // if($policyId != null) - // { - // $minFlightRow = $this->policyDetailsModel->where('policy_id', $policyId)->where('service_id', 1)->get()->getRow(); - - // $minTrainRow = $this->policyDetailsModel->where('policy_id', $policyId)->where('service_id', 2)->get()->getRow(); - - // $minHotelRow = $this->policyDetailsModel->where('policy_id', $policyId)->where('service_id', 5)->get()->getRow(); - - // $minFlightClassKey = $minFlightRow ? $minFlightRow->class : null; - // $minTrainClassKey = $minTrainRow ? $minTrainRow->class : null; - // $minHotelClassKey = $minHotelRow ? $minHotelRow->class : null; - - // } - - - // //flight - // $allFlightClass = $this->dropdownModel->where('dropdown', 'flight_class')->orderBy('dropdown_key','ASC')->findAll(); - // $minFlightClassKey = $minFlightClassKey ?? 0; - // $data['flight_class'] = []; - // foreach ($allFlightClass as $key => $value) { - - // if((int)$value['dropdown_key'] >= (int)$minFlightClassKey){ - // $value['is_allowed'] = 'yes'; - // array_push($data['flight_class'] , $value); - // }else{ - // $value['is_allowed'] = 'No'; - // array_push($data['flight_class'] , $value); - // } - - // } - - - // //train - // $allTrainClass = $this->dropdownModel->where('dropdown', 'train_class')->orderBy('dropdown_key','ASC')->findAll(); - // $minTrainClassKey = $minTrainClassKey ?? 0; - // $data['train_class'] = []; - - // foreach ($allTrainClass as $key => $value) { - - // if((int)$value['dropdown_key'] >= (int)$minTrainClassKey){ - // $value['is_allowed'] = 'yes'; - // array_push($data['train_class'] , $value); - // }else{ - // $value['is_allowed'] = 'No'; - // array_push($data['train_class'] , $value); - // } - - // } - - // //hotel - // $allHotelClass = $this->dropdownModel->where('dropdown', 'hotel_class')->orderBy('dropdown_key','ASC')->findAll(); - // $minHotelClassKey = $minHotelClassKey ?? 0; - // $data['hotel_class'] = []; - - // foreach ($allHotelClass as $key => $value) { - - // if((int)$value['dropdown_key'] >= (int)$minHotelClassKey){ - // $value['is_allowed'] = 'yes'; - // array_push($data['hotel_class'] , $value); - // }else{ - // $value['is_allowed'] = 'No'; - // array_push($data['hotel_class'] , $value); - // } - - // } - - // } - - - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - - // // Department crud - // public function getDepartmentList() - // { - // $for = $this->request->getVar('for'); - - // if (isset($for) && $for === 'table_view') - // { - // $data = $this->dropdownModel->where('dropdown','plan_functional_department')->findAll(); - // } else { - // $data = $this->dropdownModel->where('dropdown','plan_functional_department')->where('is_active', 1)->findAll(); - // } - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function createDepartment() - // { - // $data = $this->request->getJSON(true); - - // $data['dropdown'] = 'plan_functional_department'; - // $data['is_active'] = 1; - // $existData = $this->dropdownModel->where('dropdown','plan_functional_department')->findAll(); - // $data['dropdown_key'] = count($existData) + 1; - - // if (!$this->dropdownModel->insert($data)) { - // return $this->failValidationErrors($this->dropdownModel->errors()); - // } - - // return $this->respondCreated([ - // 'status' => 201, - // 'message' => 'Department created successfully' - // ]); - - // } - - // public function findDepartment() - // { - - // $id = $this->request->getGet('id'); - - // $data = $this->dropdownModel->where('id',$id)->find(); - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function updateDepartment($id = null) - // { - // $data = $this->request->getJSON(true); - - // if (!$this->dropdownModel->find($id)) { - // return $this->failNotFound('Department not found'); - // } - - // if (!$this->dropdownModel->update($id, $data)) { - // return $this->failValidationErrors($this->dropdownModel->errors()); - // } - - // return $this->respond([ - // 'status' => 200, - // 'message' => 'Department updated successfully' - // ]); - // } - - - // // Purpose of travel crud - // public function getPurposeOfTravelList() - // { - // $for = $this->request->getVar('for'); - - // if (isset($for) && $for === 'table_view') - // { - // $data = $this->dropdownModel->where('dropdown','plan_purpose_of_travel')->findAll(); - // } else { - // $data = $this->dropdownModel->where('dropdown','plan_purpose_of_travel')->where('is_active', 1)->findAll(); - // } - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function createPurposeOfTravel() - // { - // $data = $this->request->getJSON(true); - - // $data['dropdown'] = 'plan_purpose_of_travel'; - // $data['is_active'] = 1; - // $existData = $this->dropdownModel->where('dropdown','plan_purpose_of_travel')->findAll(); - // $data['dropdown_key'] = count($existData) + 1; - - // if (!$this->dropdownModel->insert($data)) { - // return $this->failValidationErrors($this->dropdownModel->errors()); - // } - - // return $this->respondCreated([ - // 'status' => 201, - // 'message' => 'Department created successfully' - // ]); - - // } - - // public function findPurposeOfTravel() - // { - - // $id = $this->request->getGet('id'); - - // $data = $this->dropdownModel->where('id',$id)->find(); - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function updatePurposeOfTravel($id = null) - // { - // $data = $this->request->getJSON(true); - - // if (!$this->dropdownModel->find($id)) { - // return $this->failNotFound('Department not found'); - // } - - // if (!$this->dropdownModel->update($id, $data)) { - // return $this->failValidationErrors($this->dropdownModel->errors()); - // } - - // return $this->respond([ - // 'status' => 200, - // 'message' => 'Department updated successfully' - // ]); - // } - - // // Cost center crud - // public function getCostCenterMaster() - // { - // $for = $this->request->getVar('for'); - - // if (isset($for) && $for === 'table_view') - // { - // $data = $this->costCenterModel->findAll(); - // } else { - // $data = $this->costCenterModel->where('is_active', 1)->findAll(); - // } - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function createCostCenter() - // { - // $data = $this->request->getJSON(true); - - // if (!$this->costCenterModel->insert($data)) { - // return $this->failValidationErrors($this->costCenterModel->errors()); - // } - - // return $this->respondCreated([ - // 'status' => 201, - // 'message' => 'Cost Center created successfully' - // ]); - - // } - - // public function findCostCenter() - // { - - // $id = $this->request->getGet('cost_center_id'); - - // $data = $this->costCenterModel->where('cost_center_id',$id)->find(); - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function updateCostCenter($id = null) - // { - // $data = $this->request->getJSON(true); - - // if (!$this->costCenterModel->find($id)) { - // return $this->failNotFound('Cost Center not found'); - // } - - // if (!$this->costCenterModel->update($id, $data)) { - // return $this->failValidationErrors($this->costCenterModel->errors()); - // } - - // return $this->respond([ - // 'status' => 200, - // 'message' => 'Cost Center updated successfully' - // ]); - // } - - - // // Forex crud - // public function getForexPerdiemList() - // { - - // $for = $this->request->getVar('for'); - - // if (isset($for) && $for === 'table_view') - // { - // $data = $this->forexPerdiemModel->findAll(); - // } else { - // $data = $this->forexPerdiemModel->where('is_active', 1)->findAll(); - // } - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function createForexPerdiem() - // { - - - // try { - - // $data = $this->request->getJSON(true); - - // if (!$this->forexPerdiemModel->insert($data)) { - // return $this->failValidationErrors($this->forexPerdiemModel->errors()); - // } - - // return $this->respondCreated([ - // 'status' => 201, - // 'message' => 'Forex Perdiem created successfully' - // ]); - // } catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) { - - // if (strpos($e->getMessage(), 'Duplicate entry') !== false) { - // return $this->respond([ - // 'status' => 404, - // 'message' => 'Duplicate entry' - // ],404); - // } - - // // For other DB-related exceptions - // return $this->failServerError($e->getMessage()); - // } - - - // } - - // public function findForexPerdiem() - // { - - // $id = $this->request->getGet('forex_perdiem_id'); - - // $data = $this->forexPerdiemModel->where('forex_perdiem_id',$id)->find(); - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function updateForexPerdiem($id = null) - // { - // try{ - - // $data = $this->request->getJSON(true); - - // if (!$this->forexPerdiemModel->find($id)) { - // return $this->failNotFound('Forex Perdiem not found'); - // } - - - // if (!$this->forexPerdiemModel->update($id, $data)) { - // return $this->failValidationErrors($this->forexPerdiemModel->errors()); - // } - - // return $this->respond([ - // 'status' => 200, - // 'message' => 'Forex Perdiem updated successfully' - // ]); - - // } catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) { - - // if (strpos($e->getMessage(), 'Duplicate entry') !== false) { - // return $this->respond([ - // 'status' => 404, - // 'message' => 'Duplicate entry' - // ]); - // } - - // // For other DB-related exceptions - // return $this->failServerError($e->getMessage()); - // } - // } - - // // Hotels crud - // public function getHotels() - // { - - // $for = $this->request->getVar('for'); - - // if (isset($for) && $for === 'table_view') - // { - // $hotels = $this->hotelModel->select('m_hotels.* , C.country_name') - // ->join('m_country C', 'C.country_code = m_hotels.country_code', 'left') - // ->findAll(); - // } else { - // $hotels = $this->hotelModel->select('m_hotels.* , C.country_name') - // ->join('m_country C', 'C.country_code = m_hotels.country_code', 'left') - // ->where('m_hotels.is_active', 1) - // ->findAll(); - // } - - - // return $this->response->setJSON([ - // 'status' => 200, - // 'message' => 'Hotel list fetched successfully', - // 'data' => $hotels - // ]); - // } - - // public function createHotels() - // { - // $data = $this->request->getJSON(true); - - // if (!$this->hotelModel->insert($data)) { - // return $this->failValidationErrors($this->hotelModel->errors()); - // } - - // return $this->respondCreated([ - // 'status' => 201, - // 'message' => 'Hotels created successfully' - // ]); - - // } - - // public function findHotels() - // { - - // $id = $this->request->getGet('hotel_id'); - - // $data = $this->hotelModel->where('hotel_id',$id)->find(); - - // if (!$data) { - // return $this->failNotFound('No data found'); - // } - - // return $this->respond(['status' => 200,'message' => 'success','data' => $data]); - // } - - // public function updateHotels($id = null) - // { - // $data = $this->request->getJSON(true); - - // if (!$this->hotelModel->find($id)) { - // return $this->failNotFound('Hotels not found'); - // } - - // if (!$this->hotelModel->update($id, $data)) { - // return $this->failValidationErrors($this->hotelModel->errors()); - // } - - // return $this->respond([ - // 'status' => 200, - // 'message' => 'Hotels updated successfully' - // ]); - // } - - - // public function forex_signature_upload() - // { - - // $data = $this->request->getPost(); - - // // Handle file upload - // $file = $this->request->getFile('signature'); - // if ($file && $file->isValid() && !$file->hasMoved()) { - // $newName = $file->getRandomName(); // Generate a unique name - // // $uploadPath = WRITEPATH.'uploads/signature'; - // $uploadPath = FCPATH.'public/assets/images/signature'; - - // // print_r( $uploadPath); die; - - // // Move file to the specified directory - // $file->move($uploadPath, $newName); - - // // Save file path in database - // $path = $uploadPath . '/' . $newName; - // } else { - // return $this->failValidationErrors(['passport_document' => 'Invalid file upload']); - // } - - // try { - - // $this->mailTemplateModel->set(['image_location' => $newName])->where('template_name','forex')->update(); - - - // return $this->respondCreated([ - // 'status' => 201, - // 'message' => 'organization created successfully', - // 'data' => $data - // ]); - // } catch (\Exception $e) { - // return $this->failServerError('Failed to create organization: ' . $e->getMessage()); - // } - // } - - // // public function getForexSignaturePath() - // // { - - // // $data = $this->mailTemplateModel->where('template_name','forex')->first(); - - // // return $this->respond([ - // // 'status' => 200, - // // 'message' => 'success', - // // 'data' => $data - - // // ]); - - // // } - - // public function getForexSignaturePath() - // { - // $data = $this->mailTemplateModel->where('template_name', 'forex')->first(); - - // if (!$data || empty($data['image_location'])) { - // return $this->respond([ - // 'status' => 404, - // 'message' => 'Image not found', - // 'url' => null - // ]); - // } - - // // If the DB stores only the filename, adjust accordingly - // $fileName = basename($data['image_location']); - - - // $imageUrl = base_url('public/assets/images/signature/' . $fileName); - - // // Add both the URL and ready-made HTML tag - // $data['image_url'] = $imageUrl; - // $data['image_tag'] = 'Signature'; - - // return $this->respond([ - // 'status' => 200, - // 'message' => 'success', - // 'url' => $imageUrl - // ]); - // } - + diff --git a/app/Models/EnquiryModel.php b/app/Models/EnquiryModel.php index b9bd603..e7d66b7 100644 --- a/app/Models/EnquiryModel.php +++ b/app/Models/EnquiryModel.php @@ -29,7 +29,8 @@ class EnquiryModel extends Model 'created_by', 'updated_by', 'is_data_created_by_handler', - 'is_data_created_by_manager' + 'is_data_created_by_manager', + 'broker_id', ]; protected $useTimestamps = true; @@ -47,7 +48,8 @@ class EnquiryModel extends Model Q.id as quotation_id, P.payment_mode, P.premium_amount, - P.policy_number' + P.policy_number, + PB.name as broker_name', ) ->join('vehicle_type VT', 'VT.id = partner_enquiry.vehicle_type_id', 'left') ->join('partner_agent A', 'A.id = partner_enquiry.agent_id', 'left') @@ -55,6 +57,7 @@ class EnquiryModel extends Model ->join('partner_quotation Q', 'Q.enquiry_id = partner_enquiry.id AND Q.status = "Accepted"', 'left') ->join('insurers I', 'I.id = partner_enquiry.insurer_id', 'left') ->join('partner_policy P', 'P.quotation_id = Q.id', 'left') + ->join('partner_brokers PB', 'PB.id = partner_enquiry.broker_id', 'left') ->where('partner_enquiry.is_active', 1) ->orderBy('partner_enquiry.created_on', 'ASC'); diff --git a/app/Models/PartnerBrokerModel.php b/app/Models/PartnerBrokerModel.php new file mode 100644 index 0000000..e573abb --- /dev/null +++ b/app/Models/PartnerBrokerModel.php @@ -0,0 +1,25 @@ +