GWM : user management and auth apis
This commit is contained in:
parent
be541de46f
commit
24424c5be3
@ -11,158 +11,40 @@ $routes->get('swagger/json', 'SwaggerController::generate');
|
||||
//Auth
|
||||
$routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
||||
|
||||
// Agent Login api
|
||||
$routes->post('auth/verifyAgentWithMobileNumber', 'AgentAuthController::verifyAgentWithMobileNumber');
|
||||
$routes->post('auth/verifyAgentWithEmailId', 'AgentAuthController::verifyAgentWithEmailId');
|
||||
$routes->post('auth/getVerifiedAgentData', 'AgentAuthController::getVerifiedAgentData');
|
||||
// Agent Login api
|
||||
$routes->post('auth/verifyAgentWithMobileNumber', 'AgentAuthController::verifyAgentWithMobileNumber');
|
||||
$routes->post('auth/verifyAgentWithEmailId', 'AgentAuthController::verifyAgentWithEmailId');
|
||||
$routes->post('auth/getVerifiedAgentData', 'AgentAuthController::getVerifiedAgentData');
|
||||
|
||||
// Staff Login api
|
||||
$routes->post('auth/verifyStaffWithMobileNumber', 'StaffAuthController::verifyStaffWithMobileNumber');
|
||||
$routes->post('auth/verifyStaffWithEmailId', 'StaffAuthController::verifyStaffWithEmailId');
|
||||
$routes->post('auth/getVerifiedStaffData', 'StaffAuthController::getVerifiedStaffData');
|
||||
// Staff Login api
|
||||
$routes->post('auth/verifyStaffWithMobileNumber', 'StaffAuthController::verifyStaffWithMobileNumber');
|
||||
$routes->post('auth/verifyStaffWithEmailId', 'StaffAuthController::verifyStaffWithEmailId');
|
||||
$routes->post('auth/getVerifiedStaffData', 'StaffAuthController::getVerifiedStaffData');
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//api's with token
|
||||
$routes->group('api', ['filter' => ["jwtAuth","appSignature"] ], function ($routes) {
|
||||
|
||||
$routes->get('user/refreshUserToken', 'AuthController::refreshUserToken');
|
||||
//Agent
|
||||
$routes->get('agentList', 'AgentController::agentList');
|
||||
$routes->get('findAgent', 'AgentController::findAgent');
|
||||
$routes->post('createAgent', 'AgentController::createAgent');
|
||||
$routes->post('updateAgent', 'AgentController::updateAgent');
|
||||
$routes->post('updateAgent', 'AgentController::updateAgent');
|
||||
|
||||
|
||||
//Organization
|
||||
$routes->get('organizations', 'OrganizationController::index');
|
||||
$routes->get('organizations/find/(:num)', 'OrganizationController::find/$1');
|
||||
$routes->post('organizations/create', 'OrganizationController::create');
|
||||
$routes->put('organizations/update/(:num)', 'OrganizationController::update/$1');
|
||||
$routes->put('organizations/org-status/(:num)', 'OrganizationController::updateOrganizationStatus/$1');
|
||||
$routes->post('organizations/testMail', 'OrganizationController::testMail');
|
||||
|
||||
//Service
|
||||
$routes->get('service', 'OrganizationController::getServices');
|
||||
|
||||
//Group
|
||||
$routes->get('groups', 'OrganizationController::getGroups');
|
||||
$routes->get('groups/find/(:num)', 'OrganizationController::findGroup/$1');
|
||||
$routes->post('groups/create', 'OrganizationController::createGroup');
|
||||
$routes->put('groups/update/(:num)', 'OrganizationController::updateGroup/$1');
|
||||
$routes->put('groups/group-status/(:num)', 'OrganizationController::updateGroupStatus/$1');
|
||||
|
||||
//Policy
|
||||
$routes->get('policy', 'OrganizationController::getPolicy');
|
||||
$routes->get('policy/find/(:num)', 'OrganizationController::findPolicy/$1');
|
||||
$routes->post('policy/createOrUpdate', 'OrganizationController::createOrUpdatePolicy');
|
||||
$routes->put('policy/policy-status/(:num)', 'OrganizationController::updatePolicyStatus/$1');
|
||||
|
||||
//User
|
||||
$routes->get('users', 'UserController::index');
|
||||
$routes->get('agentList', 'UserController::agentList');
|
||||
$routes->get('users/find/(:num)', 'UserController::find/$1');
|
||||
$routes->post('users/create', 'UserController::create');
|
||||
$routes->put('users/update/(:num)', 'UserController::update/$1');
|
||||
$routes->put('user/user-status/(:num)', 'UserController::updateUserStatus/$1');
|
||||
$routes->put('user/user-password/(:num)', 'UserController::changePassword/$1');
|
||||
$routes->get('checkDuplicate', 'UserController::checkDuplicate');
|
||||
$routes->post('user/userUpload','UserController::userUpload');
|
||||
$routes->get('user/userUploadTemplate','UserController::userUploadTemplate');
|
||||
|
||||
|
||||
//Traveller
|
||||
$routes->get('travellers', 'TravellerController::index');
|
||||
$routes->post('travellers/create', 'TravellerController::create');
|
||||
$routes->get('travellers/find', 'TravellerController::find');
|
||||
$routes->put('travellers/update/(:num)', 'TravellerController::update/$1');
|
||||
$routes->get('travellers/find/name/(:any)', 'TravellerController::findByName/$1');
|
||||
$routes->get('travellers/find/email/(:any)', 'TravellerController::findByEmail/$1');
|
||||
$routes->get('travellers/find/mobile/(:any)', 'TravellerController::findByMobile/$1');
|
||||
|
||||
|
||||
//Plan
|
||||
$routes->get('plans', 'PlanController::index');
|
||||
$routes->put('plans/find/(:num)', 'PlanController::find/$1');
|
||||
$routes->post('plans/createOrEditPlan', 'PlanController::createOrEditPlan');
|
||||
$routes->post('plans/getForexPerdiem', 'PlanController::getForexPerdiem');
|
||||
$routes->post('plans/approvePlan', 'PlanController::approvePlan');
|
||||
$routes->post('plans/rejectPlan', 'PlanController::rejectPlan');
|
||||
$routes->get('plans/statusDashboard', 'PlanController::statusDashboard');
|
||||
$routes->get('plans/download', 'PlanController::downloadPlan');
|
||||
$routes->get('plans/view', 'PlanController::viewPlan');
|
||||
$routes->get('plans/findApprovalList', 'PlanController::findApprovalList');
|
||||
$routes->get('plans/findTravelAgentPlanList', 'PlanController::findTravelAgentPlanList');
|
||||
$routes->post('plans/addOrEditPlanRemark', 'PlanController::addOrEditPlanRemark');
|
||||
$routes->get('plans/getRemarksByPlanId', 'PlanController::getRemarksByPlanId');
|
||||
$routes->get('plans/forexDownload', 'PlanController::forexDownload');
|
||||
$routes->get('plans/cancle_plan', 'PlanController::canclePlan');
|
||||
$routes->get('plans/get_plan_approval_status', 'PlanController::get_plan_approval_status');
|
||||
$routes->get('plans/plan_pdf', 'PlanController::plan_pdf');
|
||||
$routes->get('plans/plan_policy_action_status', 'PlanController::plan_policy_action_status');
|
||||
|
||||
//Master
|
||||
$routes->get('getDropdownMaster', 'MasterController::getDropdownMaster');
|
||||
$routes->get('getTravelStatusMaster', 'MasterController::getTravelStatusMaster');
|
||||
$routes->get('getcountryMaster', 'MasterController::getcountryMaster');
|
||||
$routes->get('getAirportCodeMaster', 'MasterController::getAirportCodeMaster');
|
||||
$routes->get('getAirlineMaster', 'MasterController::getAirlineMaster');
|
||||
$routes->get('getTrainCodeMaster', 'MasterController::getTrainCodeMaster');
|
||||
$routes->get('getFlightAndTrainClass', 'MasterController::getFlightAndTrainClass');
|
||||
// Costcenter
|
||||
$routes->get('getCostCenterMaster', 'MasterController::getCostCenterMaster');
|
||||
$routes->post('createCostCenter', 'MasterController::createCostCenter');
|
||||
$routes->get('findCostCenter', 'MasterController::findCostCenter');
|
||||
$routes->put('updateCostCenter/(:num)', 'MasterController::updateCostCenter/$1');
|
||||
// Department Master
|
||||
$routes->get('getDepartmentList', 'MasterController::getDepartmentList');
|
||||
$routes->post('createDepartment', 'MasterController::createDepartment');
|
||||
$routes->get('findDepartment', 'MasterController::findDepartment');
|
||||
$routes->put('updateDepartment/(:num)', 'MasterController::updateDepartment/$1');
|
||||
// Purpose of travel Master
|
||||
$routes->get('getPurposeOfTravelList', 'MasterController::getPurposeOfTravelList');
|
||||
$routes->post('createPurposeOfTravel', 'MasterController::createPurposeOfTravel');
|
||||
$routes->get('findPurposeOfTravel', 'MasterController::findPurposeOfTravel');
|
||||
$routes->put('updatePurposeOfTravel/(:num)', 'MasterController::updatePurposeOfTravel/$1');
|
||||
// Forex Master
|
||||
$routes->get('getForexPerdiemList', 'MasterController::getForexPerdiemList');
|
||||
$routes->post('createForexPerdiem', 'MasterController::createForexPerdiem');
|
||||
$routes->get('findForexPerdiem', 'MasterController::findForexPerdiem');
|
||||
$routes->put('updateForexPerdiem/(:num)', 'MasterController::updateForexPerdiem/$1');
|
||||
$routes->post('forex_signature_upload', 'MasterController::forex_signature_upload');
|
||||
$routes->get('getForexSignaturePath', 'MasterController::getForexSignaturePath');
|
||||
// Hotels Master
|
||||
$routes->get('getHotels', 'MasterController::getHotels');
|
||||
$routes->post('createHotels', 'MasterController::createHotels');
|
||||
$routes->get('findHotels', 'MasterController::findHotels');
|
||||
$routes->put('updateHotels/(:num)', 'MasterController::updateHotels/$1');
|
||||
|
||||
|
||||
//mail template
|
||||
$routes->get('template', 'EmailTemplateController::index');
|
||||
$routes->put('template/find/(:num)', 'EmailTemplateController::find/$1');
|
||||
$routes->post('template/create', 'EmailTemplateController::create');
|
||||
$routes->put('template/update/(:num)', 'EmailTemplateController::update/$1');
|
||||
$routes->get('getForexTemplate', 'EmailTemplateController::getForexTemplate');
|
||||
|
||||
$routes->get('getRoles', 'UserController::roleList');
|
||||
|
||||
|
||||
$routes->post('advancePurchaseReport', 'ReportsController::advancePurchaseReport');
|
||||
$routes->post('misServicesAnalysis', 'ReportsController::misServicesAnalysis');
|
||||
$routes->post('misAirReport', 'ReportsController::misAirReport');
|
||||
$routes->post('misHotelReport', 'ReportsController::misHotelReport');
|
||||
$routes->post('misForexReport', 'ReportsController::misForexReport');
|
||||
$routes->post('guestHouseReport', 'ReportsController::guestHouseReport');
|
||||
|
||||
//Agent
|
||||
$routes->get('staffList', 'StaffController::staffList');
|
||||
$routes->get('findStaff', 'StaffController::findStaff');
|
||||
$routes->post('createStaff', 'StaffController::createStaff');
|
||||
$routes->post('updateStaff', 'StaffController::updateStaff');
|
||||
$routes->post('changeStaffStatus', 'StaffController::changeStaffStatus');
|
||||
|
||||
});
|
||||
|
||||
|
||||
// plan review related signed url
|
||||
$routes->post('approvePlan', 'PlanController::approvePlan');
|
||||
$routes->post('rejectPlan', 'PlanController::rejectPlan');
|
||||
$routes->get('review', 'PlanController::protectedPage', ['filter' => 'signedUrl']);
|
||||
$routes->get('url', 'PlanController::url');
|
||||
|
||||
|
||||
|
||||
|
||||
@ -112,7 +112,7 @@ class AgentAuthController extends ResourceController
|
||||
if ($agentData && $otp_verification == true || $agentData && isset($this->request->getJSON()->otp) ) {
|
||||
|
||||
if(isset($this->request->getJSON()->otp)){
|
||||
$this->AgentModel->where('id', $agentData['id'])->where('otp', $otp)->where('is_active', 1)->set(['otp'=>null])->update();
|
||||
$this->AgentModel->where('id', $agentData['id'])->where('email_otp', $otp)->where('is_active', 1)->set(['email_otp'=>null])->update();
|
||||
}
|
||||
|
||||
$result = generateJWT($agentData);
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\AgentModel;
|
||||
|
||||
class PartnerAgentController extends BaseController
|
||||
class AgentController extends ResourceController
|
||||
{
|
||||
protected $AgentModel;
|
||||
|
||||
@ -14,72 +14,186 @@ class PartnerAgentController extends BaseController
|
||||
$this->AgentModel = new AgentModel();
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 1. List all records
|
||||
// =========================
|
||||
public function list()
|
||||
// List of all agents
|
||||
public function agentList()
|
||||
{
|
||||
$data = $this->AgentModel->findAll();
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
try{
|
||||
|
||||
// =========================
|
||||
// 2. Find single record by ID
|
||||
// =========================
|
||||
public function find($id = null)
|
||||
{
|
||||
$record = $this->AgentModel->find($id);
|
||||
$data = $this->AgentModel->findAll();
|
||||
|
||||
if (!$record) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'Record not found'
|
||||
])->setStatusCode(404);
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return $this->response->setJSON($record);
|
||||
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 3. Create new record
|
||||
// =========================
|
||||
public function create()
|
||||
// Find a agent
|
||||
public function findAgent()
|
||||
{
|
||||
$data = $this->request->getJSON(true); // get JSON body as array
|
||||
try{
|
||||
|
||||
if (!$this->AgentModel->insert($data)) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to insert',
|
||||
'errors' => $this->AgentModel->errors()
|
||||
])->setStatusCode(400);
|
||||
$id = $this->request->getGet('id');
|
||||
|
||||
$record = $this->AgentModel->find($id);
|
||||
|
||||
if (!$record) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $record], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => 'success',
|
||||
'message' => 'Record created successfully',
|
||||
'id' => $this->AgentModel->getInsertID()
|
||||
]);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 4. Update record by ID
|
||||
// =========================
|
||||
public function update($id = null)
|
||||
// CREATE agent
|
||||
public function createAgent()
|
||||
{
|
||||
$data = $this->request->getJSON(true);
|
||||
try{
|
||||
$data = $this->request->getPost();
|
||||
|
||||
if (!$this->AgentModel->update($id, $data)) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to update',
|
||||
'errors' => $this->AgentModel->errors()
|
||||
])->setStatusCode(400);
|
||||
// handle file uploads
|
||||
$certificateFile = $this->request->getFile('certificate_file_name');
|
||||
$incentiveFile = $this->request->getFile('incentive_file_name');
|
||||
|
||||
$certificateFileName = null;
|
||||
$incentiveFileName = null;
|
||||
|
||||
// certificate upload
|
||||
if ($certificateFile && $certificateFile->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/agent/certificate_file/';
|
||||
if (!is_dir($uploadPath)) {
|
||||
mkdir($uploadPath, 0777, true);
|
||||
}
|
||||
$certificateFileName = time() . '_' . $certificateFile->getRandomName();
|
||||
$certificateFile->move($uploadPath, $certificateFileName);
|
||||
}
|
||||
|
||||
// incentive upload
|
||||
if ($incentiveFile && $incentiveFile->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/agent/incentive_file/';
|
||||
if (!is_dir($uploadPath)) {
|
||||
mkdir($uploadPath, 0777, true);
|
||||
}
|
||||
$incentiveFileName = time() . '_' . $incentiveFile->getRandomName();
|
||||
$incentiveFile->move($uploadPath, $incentiveFileName);
|
||||
}
|
||||
|
||||
$insertData = [
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'mobile' => $data['mobile'],
|
||||
'address' => $data['address'] ?? null,
|
||||
'certificate_file_name' => $certificateFileName,
|
||||
'incentive_file_name' => $incentiveFileName,
|
||||
'created_by' => $data['created_by'] ?? null
|
||||
];
|
||||
|
||||
$this->AgentModel->insert($insertData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => 'success',
|
||||
'message' => 'Record updated successfully'
|
||||
]);
|
||||
}
|
||||
|
||||
// UPDATE agent
|
||||
public function updateAgent()
|
||||
{
|
||||
try{
|
||||
|
||||
$data = $this->request->getPost();
|
||||
if (!isset($data['id'])) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'ID Required'], 200);
|
||||
}
|
||||
|
||||
$id = $data['id'];
|
||||
|
||||
// check if agent exists
|
||||
$agent = $this->AgentModel->find($id);
|
||||
if (!$agent) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'Date Not Found'], 200);
|
||||
}
|
||||
|
||||
// handle file uploads
|
||||
$certificateFile = $this->request->getFile('certificate_file_name');
|
||||
$incentiveFile = $this->request->getFile('incentive_file_name');
|
||||
|
||||
$updateData = [
|
||||
'name' => $data['name'] ?? null,
|
||||
'email' => $data['email'] ?? null,
|
||||
'mobile' => $data['mobile'] ?? null,
|
||||
'address' => $data['address'] ?? null,
|
||||
'updated_by' => $data['updated_by'] ?? null,
|
||||
];
|
||||
|
||||
if ($certificateFile && $certificateFile->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/agent/certificate_file/';
|
||||
if (!is_dir($uploadPath)) {
|
||||
mkdir($uploadPath, 0777, true);
|
||||
}
|
||||
$certificateFileName = time() . '_' . $certificateFile->getRandomName();
|
||||
$certificateFile->move($uploadPath, $certificateFileName);
|
||||
$updateData['certificate_file_name'] = $certificateFileName;
|
||||
}
|
||||
|
||||
if ($incentiveFile && $incentiveFile->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/agent/incentive_file/';
|
||||
if (!is_dir($uploadPath)) {
|
||||
mkdir($uploadPath, 0777, true);
|
||||
}
|
||||
$incentiveFileName = time() . '_' . $incentiveFile->getRandomName();
|
||||
$incentiveFile->move($uploadPath, $incentiveFileName);
|
||||
$updateData['incentive_file_name'] = $incentiveFileName;
|
||||
}
|
||||
|
||||
$this->AgentModel->update($id, $updateData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// ACTIVATE / DEACTIVATE agent
|
||||
public function changeAgentStatus()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
|
||||
// validate inputs
|
||||
if (!isset($data['id']) || !isset($data['is_active'])) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200,'data' => 'ID and Status are required'], 200);
|
||||
}
|
||||
|
||||
$id = $data['id'];
|
||||
$is_active = (int) $data['is_active']; // 0 or 1
|
||||
|
||||
$status = ($is_active == 1) ? 0 : 1;
|
||||
|
||||
// check if agent exists
|
||||
$agent = $this->AgentModel->find($id);
|
||||
if (!$agent) {
|
||||
return $this->respond(['status' => 'failed','code' => 200, 'data' => 'Agent not found'], 200);
|
||||
}
|
||||
|
||||
// update status
|
||||
$this->AgentModel->update($id, ['is_active' => $status]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success', 'code' => 200,'data' => "Agent status updated"], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
189
app/Controllers/EnquiryController.php
Normal file
189
app/Controllers/EnquiryController.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
use App\Models\EnquiryModel;
|
||||
|
||||
class EnquiryController extends ResourceController
|
||||
{
|
||||
protected $enquiryModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->enquiryModel = new EnquiryModel();
|
||||
}
|
||||
|
||||
// List all enquiries
|
||||
public function enquiryList()
|
||||
{
|
||||
try {
|
||||
$data = $this->enquiryModel->findAll();
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Find a single enquiry
|
||||
public function findEnquiry()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->getGet('id');
|
||||
$record = $this->enquiryModel->find($id);
|
||||
|
||||
if (!$record) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $record], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// CREATE enquiry
|
||||
public function createEnquiry()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
|
||||
// handle file uploads
|
||||
$idProofFile = $this->request->getFile('id_proof_file_name');
|
||||
$rcFile = $this->request->getFile('rc_file_name');
|
||||
$previousPolicy = $this->request->getFile('previous_policy_file_name');
|
||||
|
||||
$idProofFileName = null;
|
||||
$rcFileName = null;
|
||||
$previousPolicyFileName = null;
|
||||
|
||||
// ID proof upload
|
||||
if ($idProofFile && $idProofFile->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/enquiry/id_proof/';
|
||||
if (!is_dir($uploadPath)) mkdir($uploadPath, 0777, true);
|
||||
$idProofFileName = time() . '_' . $idProofFile->getRandomName();
|
||||
$idProofFile->move($uploadPath, $idProofFileName);
|
||||
}
|
||||
|
||||
// RC upload
|
||||
if ($rcFile && $rcFile->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/enquiry/rc/';
|
||||
if (!is_dir($uploadPath)) mkdir($uploadPath, 0777, true);
|
||||
$rcFileName = time() . '_' . $rcFile->getRandomName();
|
||||
$rcFile->move($uploadPath, $rcFileName);
|
||||
}
|
||||
|
||||
// Previous policy upload
|
||||
if ($previousPolicy && $previousPolicy->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/enquiry/previous_policy/';
|
||||
if (!is_dir($uploadPath)) mkdir($uploadPath, 0777, true);
|
||||
$previousPolicyFileName = time() . '_' . $previousPolicy->getRandomName();
|
||||
$previousPolicy->move($uploadPath, $previousPolicyFileName);
|
||||
}
|
||||
|
||||
$insertData = [
|
||||
'agent_id' => $data['agent_id'],
|
||||
'reg_no' => $data['reg_no'],
|
||||
'vehicle_type_id' => $data['vehicle_type_id'] ?? null,
|
||||
'insurer_id' => $data['insurer_id'] ?? null,
|
||||
'rc_file_name' => $rcFileName,
|
||||
'id_proof_file_name' => $idProofFileName,
|
||||
'previous_policy_file_name' => $previousPolicyFileName,
|
||||
'remarks' => $data['remarks'] ?? null,
|
||||
'status' => $data['status'] ?? 'Pending',
|
||||
'created_by' => $data['created_by'] ?? null
|
||||
];
|
||||
|
||||
$this->enquiryModel->insert($insertData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'message' => 'Enquiry created successfully'], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// UPDATE enquiry
|
||||
public function updateEnquiry()
|
||||
{
|
||||
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 = [
|
||||
'agent_id' => $data['agent_id'] ?? $enquiry['agent_id'],
|
||||
'reg_no' => $data['reg_no'] ?? $enquiry['reg_no'],
|
||||
'vehicle_type_id' => $data['vehicle_type_id'] ?? $enquiry['vehicle_type_id'],
|
||||
'insurer_id' => $data['insurer_id'] ?? $enquiry['insurer_id'],
|
||||
'remarks' => $data['remarks'] ?? $enquiry['remarks'],
|
||||
'status' => $data['status'] ?? $enquiry['status'],
|
||||
'updated_by' => $data['updated_by'] ?? null,
|
||||
];
|
||||
|
||||
// File updates
|
||||
$idProofFile = $this->request->getFile('id_proof_file_name');
|
||||
$rcFile = $this->request->getFile('rc_file_name');
|
||||
$previousPolicy = $this->request->getFile('previous_policy_file_name');
|
||||
|
||||
if ($idProofFile && $idProofFile->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/enquiry/id_proof/';
|
||||
if (!is_dir($uploadPath)) mkdir($uploadPath, 0777, true);
|
||||
$idProofFileName = time() . '_' . $idProofFile->getRandomName();
|
||||
$idProofFile->move($uploadPath, $idProofFileName);
|
||||
$updateData['id_proof_file_name'] = $idProofFileName;
|
||||
}
|
||||
|
||||
if ($rcFile && $rcFile->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/enquiry/rc/';
|
||||
if (!is_dir($uploadPath)) mkdir($uploadPath, 0777, true);
|
||||
$rcFileName = time() . '_' . $rcFile->getRandomName();
|
||||
$rcFile->move($uploadPath, $rcFileName);
|
||||
$updateData['rc_file_name'] = $rcFileName;
|
||||
}
|
||||
|
||||
if ($previousPolicy && $previousPolicy->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/enquiry/previous_policy/';
|
||||
if (!is_dir($uploadPath)) mkdir($uploadPath, 0777, true);
|
||||
$previousPolicyFileName = time() . '_' . $previousPolicy->getRandomName();
|
||||
$previousPolicy->move($uploadPath, $previousPolicyFileName);
|
||||
$updateData['previous_policy_file_name'] = $previousPolicyFileName;
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
// Activate/Deactivate enquiry
|
||||
public function toggleEnquiryStatus()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->getPost('id');
|
||||
$isActive = $this->request->getPost('is_active');
|
||||
|
||||
if (!$id) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'error' => 'ID Required'], 200);
|
||||
}
|
||||
|
||||
$this->enquiryModel->update($id, ['is_active' => $isActive]);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'message' => 'Status updated'], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
177
app/Controllers/PolicyController.php
Normal file
177
app/Controllers/PolicyController.php
Normal file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
use App\Models\PolicyModel;
|
||||
|
||||
class PolicyController extends ResourceController
|
||||
{
|
||||
protected $PolicyModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->PolicyModel = new PolicyModel();
|
||||
}
|
||||
|
||||
// List policies
|
||||
public function policyList()
|
||||
{
|
||||
try {
|
||||
$data = $this->PolicyModel->findAll();
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Find single policy
|
||||
public function findPolicy()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->getGet('id');
|
||||
$record = $this->PolicyModel->find($id);
|
||||
|
||||
if (!$record) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
}
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $record], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Create policy
|
||||
public function createPolicy()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
$uploadPath = WRITEPATH . 'uploads/policy/';
|
||||
|
||||
$policyPdf = $this->request->getFile('policy_pdf_file_name');
|
||||
$policyReceipt = $this->request->getFile('policy_payment_receipt_file_name');
|
||||
|
||||
$pdfFileName = null;
|
||||
$receiptFileName = null;
|
||||
|
||||
// PDF Upload
|
||||
if ($policyPdf && $policyPdf->isValid()) {
|
||||
$pdfPath = $uploadPath . 'policy_pdf/';
|
||||
if (!is_dir($pdfPath)) {
|
||||
mkdir($pdfPath, 0777, true);
|
||||
}
|
||||
$pdfFileName = time() . '_' . $policyPdf->getRandomName();
|
||||
$policyPdf->move($pdfPath, $pdfFileName);
|
||||
}
|
||||
|
||||
// Receipt Upload
|
||||
if ($policyReceipt && $policyReceipt->isValid()) {
|
||||
$receiptPath = $uploadPath . 'policy_payment_receipt/';
|
||||
if (!is_dir($receiptPath)) {
|
||||
mkdir($receiptPath, 0777, true);
|
||||
}
|
||||
$receiptFileName = time() . '_' . $policyReceipt->getRandomName();
|
||||
$policyReceipt->move($receiptPath, $receiptFileName);
|
||||
}
|
||||
|
||||
$insertData = [
|
||||
'quotation_id' => $data['quotation_id'],
|
||||
'insurer_name' => $data['insurer_name'],
|
||||
'premium_amount' => $data['premium_amount'],
|
||||
'policy_number' => $data['policy_number'],
|
||||
'policy_pdf_file_name' => $pdfFileName,
|
||||
'policy_payment_receipt_file_name' => $receiptFileName,
|
||||
'created_by' => $data['created_by'] ?? null
|
||||
];
|
||||
|
||||
$this->PolicyModel->insert($insertData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Update policy
|
||||
public function updatePolicy()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
if (!isset($data['id'])) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'ID Required'], 200);
|
||||
}
|
||||
|
||||
$id = $data['id'];
|
||||
$policy = $this->PolicyModel->find($id);
|
||||
if (!$policy) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'Data Not Found'], 200);
|
||||
}
|
||||
|
||||
$updateData = [
|
||||
'quotation_id' => $data['quotation_id'] ?? $policy['quotation_id'],
|
||||
'insurer_name' => $data['insurer_name'] ?? $policy['insurer_name'],
|
||||
'premium_amount' => $data['premium_amount'] ?? $policy['premium_amount'],
|
||||
'policy_number' => $data['policy_number'] ?? $policy['policy_number'],
|
||||
'updated_by' => $data['updated_by'] ?? null
|
||||
];
|
||||
|
||||
$uploadPath = WRITEPATH . 'uploads/policy/';
|
||||
|
||||
// PDF Update
|
||||
$policyPdf = $this->request->getFile('policy_pdf_file_name');
|
||||
if ($policyPdf && $policyPdf->isValid()) {
|
||||
$pdfPath = $uploadPath . 'policy_pdf/';
|
||||
if (!is_dir($pdfPath)) {
|
||||
mkdir($pdfPath, 0777, true);
|
||||
}
|
||||
$pdfFileName = time() . '_' . $policyPdf->getRandomName();
|
||||
$policyPdf->move($pdfPath, $pdfFileName);
|
||||
$updateData['policy_pdf_file_name'] = $pdfFileName;
|
||||
}
|
||||
|
||||
// Receipt Update
|
||||
$policyReceipt = $this->request->getFile('policy_payment_receipt_file_name');
|
||||
if ($policyReceipt && $policyReceipt->isValid()) {
|
||||
$receiptPath = $uploadPath . 'policy_payment_receipt/';
|
||||
if (!is_dir($receiptPath)) {
|
||||
mkdir($receiptPath, 0777, true);
|
||||
}
|
||||
$receiptFileName = time() . '_' . $policyReceipt->getRandomName();
|
||||
$policyReceipt->move($receiptPath, $receiptFileName);
|
||||
$updateData['policy_payment_receipt_file_name'] = $receiptFileName;
|
||||
}
|
||||
|
||||
$this->PolicyModel->update($id, $updateData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Active / Deactive policy
|
||||
public function toggleActiveStatus()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->getPost('id');
|
||||
if (!$id) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'ID Required'], 200);
|
||||
}
|
||||
|
||||
$policy = $this->PolicyModel->find($id);
|
||||
if (!$policy) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'Data Not Found'], 200);
|
||||
}
|
||||
|
||||
$newStatus = ($policy['is_active'] == 1) ? 0 : 1;
|
||||
$this->PolicyModel->update($id, ['is_active' => $newStatus]);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => ['is_active' => $newStatus]], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
149
app/Controllers/QuotationController.php
Normal file
149
app/Controllers/QuotationController.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
use App\Models\QuotationModel;
|
||||
|
||||
class QuotationController extends ResourceController
|
||||
{
|
||||
protected $QuotationModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->QuotationModel = new QuotationModel();
|
||||
}
|
||||
|
||||
// List quotations
|
||||
public function quotationList()
|
||||
{
|
||||
try {
|
||||
$data = $this->QuotationModel->findAll();
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Find single quotation
|
||||
public function findQuotation()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->getGet('id');
|
||||
$record = $this->QuotationModel->find($id);
|
||||
|
||||
if (!$record) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
}
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $record], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Create quotation
|
||||
public function createQuotation()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
|
||||
$uploadFile = $this->request->getFile('additional_uploaded_file_name');
|
||||
$uploadedFileName = null;
|
||||
|
||||
if ($uploadFile && $uploadFile->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/quotation/';
|
||||
if (!is_dir($uploadPath)) {
|
||||
mkdir($uploadPath, 0777, true);
|
||||
}
|
||||
$uploadedFileName = time() . '_' . $uploadFile->getRandomName();
|
||||
$uploadFile->move($uploadPath, $uploadedFileName);
|
||||
}
|
||||
|
||||
$insertData = [
|
||||
'enquiry_id' => $data['enquiry_id'],
|
||||
'insured_declared_value' => $data['insured_declared_value'],
|
||||
'premium_amount' => $data['premium_amount'],
|
||||
'insurance_plan_type_id' => $data['insurance_plan_type_id'],
|
||||
'additional_uploaded_file_name' => $uploadedFileName,
|
||||
'created_by' => $data['created_by'] ?? null
|
||||
];
|
||||
|
||||
$this->QuotationModel->insert($insertData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Update quotation
|
||||
public function updateQuotation()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
if (!isset($data['id'])) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'ID Required'], 200);
|
||||
}
|
||||
|
||||
$id = $data['id'];
|
||||
$quotation = $this->QuotationModel->find($id);
|
||||
if (!$quotation) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'Data Not Found'], 200);
|
||||
}
|
||||
|
||||
$updateData = [
|
||||
'enquiry_id' => $data['enquiry_id'] ?? $quotation['enquiry_id'],
|
||||
'insured_declared_value' => $data['insured_declared_value'] ?? $quotation['insured_declared_value'],
|
||||
'premium_amount' => $data['premium_amount'] ?? $quotation['premium_amount'],
|
||||
'insurance_plan_type_id' => $data['insurance_plan_type_id'] ?? $quotation['insurance_plan_type_id'],
|
||||
'status' => $data['status'] ?? $quotation['status'],
|
||||
'reject_reason' => $data['reject_reason'] ?? $quotation['reject_reason'],
|
||||
'updated_by' => $data['updated_by'] ?? null
|
||||
];
|
||||
|
||||
// File upload
|
||||
$uploadFile = $this->request->getFile('additional_uploaded_file_name');
|
||||
if ($uploadFile && $uploadFile->isValid()) {
|
||||
$uploadPath = WRITEPATH . 'uploads/quotation/';
|
||||
if (!is_dir($uploadPath)) {
|
||||
mkdir($uploadPath, 0777, true);
|
||||
}
|
||||
$uploadedFileName = time() . '_' . $uploadFile->getRandomName();
|
||||
$uploadFile->move($uploadPath, $uploadedFileName);
|
||||
$updateData['additional_uploaded_file_name'] = $uploadedFileName;
|
||||
}
|
||||
|
||||
$this->QuotationModel->update($id, $updateData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Active / Deactive quotation
|
||||
public function toggleActiveStatus()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->getPost('id');
|
||||
if (!$id) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'ID Required'], 200);
|
||||
}
|
||||
|
||||
$quotation = $this->QuotationModel->find($id);
|
||||
if (!$quotation) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'Data Not Found'], 200);
|
||||
}
|
||||
|
||||
$newStatus = ($quotation['is_active'] == 1) ? 0 : 1;
|
||||
$this->QuotationModel->update($id, ['is_active' => $newStatus]);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => ['is_active' => $newStatus]], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,7 +112,7 @@ class StaffAuthController extends ResourceController
|
||||
if ($StaffData && $otp_verification == true || $StaffData && isset($this->request->getJSON()->otp) ) {
|
||||
|
||||
if(isset($this->request->getJSON()->otp)){
|
||||
$this->StaffModel->where('id', $StaffData['id'])->where('otp', $otp)->where('is_active', 1)->set(['otp'=>null])->update();
|
||||
$this->StaffModel->where('id', $StaffData['id'])->where('email_otp', $otp)->where('is_active', 1)->set(['email_otp'=>null])->update();
|
||||
}
|
||||
|
||||
$result = generateJWT($StaffData);
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\StaffModel;
|
||||
|
||||
class StaffController extends BaseController
|
||||
class StaffController extends ResourceController
|
||||
{
|
||||
protected $StaffModel;
|
||||
|
||||
@ -14,72 +14,139 @@ class StaffController extends BaseController
|
||||
$this->StaffModel = new StaffModel();
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 1. List all staff
|
||||
// =========================
|
||||
public function list()
|
||||
// List of all Staffs
|
||||
public function staffList()
|
||||
{
|
||||
$data = $this->StaffModel->findAll();
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
try{
|
||||
$data = $this->StaffModel->select('partner_staff.* , R.role')
|
||||
->join('partner_role_master R', 'R.id = partner_staff.role_id', 'left')
|
||||
->findAll();
|
||||
|
||||
// =========================
|
||||
// 2. Find single staff by ID
|
||||
// =========================
|
||||
public function find($id = null)
|
||||
{
|
||||
$record = $this->StaffModel->find($id);
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200);
|
||||
|
||||
if (!$record) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'Record not found'
|
||||
])->setStatusCode(404);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return $this->response->setJSON($record);
|
||||
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 3. Create new staff
|
||||
// =========================
|
||||
public function create()
|
||||
// Find a Staff
|
||||
public function findStaff()
|
||||
{
|
||||
$data = $this->request->getJSON(true); // JSON body to array
|
||||
try{
|
||||
|
||||
if (!$this->StaffModel->insert($data)) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to insert',
|
||||
'errors' => $this->StaffModel->errors()
|
||||
])->setStatusCode(400);
|
||||
$id = $this->request->getGet('id');
|
||||
|
||||
$record = $this->StaffModel->find($id);
|
||||
|
||||
if (!$record) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $record], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => 'success',
|
||||
'message' => 'Staff created successfully',
|
||||
'id' => $this->StaffModel->getInsertID()
|
||||
]);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 4. Update staff by ID
|
||||
// =========================
|
||||
public function update($id = null)
|
||||
// CREATE Staff
|
||||
public function createStaff()
|
||||
{
|
||||
$data = $this->request->getJSON(true);
|
||||
try{
|
||||
$data = $this->request->getPost();
|
||||
|
||||
if (!$this->StaffModel->update($id, $data)) {
|
||||
return $this->response->setJSON([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to update',
|
||||
'errors' => $this->StaffModel->errors()
|
||||
])->setStatusCode(400);
|
||||
$insertData = [
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'mobile' => $data['mobile'],
|
||||
'role_id' => $data['role_id'] ?? null,
|
||||
'emp_id' => $data['emp_id'] ?? null,
|
||||
'created_by' => $data['created_by'] ?? null
|
||||
];
|
||||
|
||||
$this->StaffModel->insert($insertData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => 'success',
|
||||
'message' => 'Staff updated successfully'
|
||||
]);
|
||||
}
|
||||
|
||||
// UPDATE Staff
|
||||
public function updateStaff()
|
||||
{
|
||||
try{
|
||||
|
||||
$data = $this->request->getPost();
|
||||
if (!isset($data['id'])) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'ID Required'], 200);
|
||||
}
|
||||
|
||||
$id = $data['id'];
|
||||
|
||||
// check if Staff exists
|
||||
$Staff = $this->StaffModel->find($id);
|
||||
if (!$Staff) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'Date Not Found'], 200);
|
||||
}
|
||||
|
||||
|
||||
$updateData = [
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'mobile' => $data['mobile'],
|
||||
'role_id' => $data['role_id'] ?? null,
|
||||
'emp_id' => $data['emp_id'] ?? null,
|
||||
'updated_by' => $data['updated_by'] ?? null,
|
||||
];
|
||||
|
||||
|
||||
|
||||
$this->StaffModel->update($id, $updateData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
// ACTIVATE / DEACTIVATE Staff
|
||||
public function changeStaffStatus()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
|
||||
// validate inputs
|
||||
if (!isset($data['id']) || !isset($data['is_active'])) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200,'data' => 'ID and Status are required'], 200);
|
||||
}
|
||||
|
||||
$id = $data['id'];
|
||||
$is_active = (int) $data['is_active']; // 0 or 1
|
||||
|
||||
$status = ($is_active == 1) ? 0 : 1;
|
||||
|
||||
// check if Staff exists
|
||||
$Staff = $this->StaffModel->find($id);
|
||||
if (!$Staff) {
|
||||
return $this->respond(['status' => 'failed','code' => 200, 'data' => 'Staff not found'], 200);
|
||||
}
|
||||
|
||||
// update status
|
||||
$this->StaffModel->update($id, ['is_active' => $status]);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success', 'code' => 200,'data' => "Staff status updated"], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\Filters\FilterInterface;
|
||||
use Config\Services;
|
||||
class SignedUrlFilter implements FilterInterface
|
||||
{
|
||||
public function before(RequestInterface $request, $arguments = null)
|
||||
{
|
||||
$secretKey = 'your-secret-key'; // Change this to your secret key
|
||||
$expires = $request->getGet('expires');
|
||||
$signature = $request->getGet('signature');
|
||||
|
||||
if (!$expires || !$signature) {
|
||||
return Services::response()->setStatusCode(403)->setBody('Forbidden');
|
||||
}
|
||||
|
||||
if (time() > $expires) {
|
||||
$body = view('expired_link');
|
||||
return Services::response()->setStatusCode(403)->setBody($body);
|
||||
}
|
||||
|
||||
$queryParams = $request->getGet();
|
||||
unset($queryParams['signature']);
|
||||
$route = $request->getPath();
|
||||
$expectedSignature = hash_hmac('sha256', $route . '?' . http_build_query($queryParams), $secretKey);
|
||||
|
||||
if (!hash_equals($expectedSignature, $signature)) {
|
||||
return Services::response()->setStatusCode(403)->setBody('Invalid signature');
|
||||
}
|
||||
|
||||
return true; // Allow the request
|
||||
}
|
||||
|
||||
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||
{
|
||||
// Do nothing here
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ if (!function_exists('generateJWT')) {
|
||||
'iss' => base_url(), // Issuer
|
||||
'iat' => $issuedAt, // Issued at
|
||||
'exp' => $expire, // Expiration time
|
||||
'sub' => $userData['user_id'], // Subject (User ID)
|
||||
'sub' => $userData['id'], // Subject (User ID)
|
||||
'data' => $userData // Additional user data
|
||||
];
|
||||
|
||||
|
||||
31
app/Models/EnquiryModel.php
Normal file
31
app/Models/EnquiryModel.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class EnquiryModel extends Model
|
||||
{
|
||||
protected $table = 'partner_enquiry';
|
||||
protected $primaryKey = 'id';
|
||||
protected $returnType = 'array';
|
||||
protected $allowedFields = [
|
||||
'agent_id',
|
||||
'reg_no',
|
||||
'vehicle_type_id',
|
||||
'insurer_id',
|
||||
'rc_file_name',
|
||||
'id_proof_file_name',
|
||||
'previous_policy_file_name',
|
||||
'remarks',
|
||||
'status',
|
||||
'is_active',
|
||||
'assigned_to',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $createdField = 'created_on';
|
||||
protected $updatedField = 'updated_on';
|
||||
}
|
||||
22
app/Models/PolicyModel.php
Normal file
22
app/Models/PolicyModel.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class PolicyModel extends Model
|
||||
{
|
||||
protected $table = 'partner_policy';
|
||||
protected $primaryKey = 'id';
|
||||
protected $allowedFields = [
|
||||
'quotation_id',
|
||||
'insurer_name',
|
||||
'premium_amount',
|
||||
'policy_number',
|
||||
'policy_pdf_file_name',
|
||||
'policy_payment_receipt_file_name',
|
||||
'is_active',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
protected $useTimestamps = false;
|
||||
}
|
||||
23
app/Models/QuotationModel.php
Normal file
23
app/Models/QuotationModel.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class QuotationModel extends Model
|
||||
{
|
||||
protected $table = 'partner_quotation';
|
||||
protected $primaryKey = 'id';
|
||||
protected $allowedFields = [
|
||||
'enquiry_id',
|
||||
'insured_declared_value',
|
||||
'premium_amount',
|
||||
'insurance_plan_type_id',
|
||||
'additional_uploaded_file_name',
|
||||
'status',
|
||||
'reject_reason',
|
||||
'is_active',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
protected $useTimestamps = false;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user