GWM : Enquiry
This commit is contained in:
parent
4541afe9cc
commit
8ba82c4d4b
@ -27,7 +27,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
||||
|
||||
|
||||
//api's with token
|
||||
// $routes->group('api', ['filter' => ["jwtAuth","appSignature"] ], function ($routes) {
|
||||
$routes->group('api', ['filter' => ["jwtAuth","appSignature"] ], function ($routes) {
|
||||
|
||||
|
||||
//Master
|
||||
@ -35,6 +35,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
||||
$routes->get('master/getVehicleTypeMaster', 'MasterController::getVehicleTypeMaster');
|
||||
$routes->get('master/getInsurancePlanTypeMaster', 'MasterController::getInsurancePlanTypeMaster');
|
||||
$routes->get('master/getInsurersMaster', 'MasterController::getInsurersMaster');
|
||||
$routes->get('master/getStaffMaster', 'MasterController::getStaffMaster');
|
||||
|
||||
//Agent
|
||||
$routes->get('agent/agentList', 'AgentController::agentList');
|
||||
@ -59,8 +60,12 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
||||
|
||||
//Enquiry
|
||||
$routes->get('enquiry/enquiryList', 'EnquiryController::enquiryList');
|
||||
$routes->post('enquiry/enquiryAssignUpdate', 'EnquiryController::enquiryAssignUpdate');
|
||||
$routes->post('enquiry/createEnquiry', 'EnquiryController::createEnquiry');
|
||||
$routes->post('enquiry/updateEnquiry', 'EnquiryController::updateEnquiry');
|
||||
$routes->get('enquiry/downloadEnquiryFile', 'EnquiryController::downloadEnquiryFile');
|
||||
|
||||
// });
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@ -4,14 +4,17 @@ namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
use App\Models\EnquiryModel;
|
||||
use App\Models\AgentModel;
|
||||
|
||||
class EnquiryController extends ResourceController
|
||||
{
|
||||
protected $enquiryModel;
|
||||
protected $AgentModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->enquiryModel = new EnquiryModel();
|
||||
$this->AgentModel = new AgentModel();
|
||||
}
|
||||
|
||||
// List all enquiries
|
||||
@ -22,6 +25,7 @@ class EnquiryController extends ResourceController
|
||||
$agent_id = $this->request->getGet('agent_id');
|
||||
$staff_id = $this->request->getGet('staff_id');
|
||||
$enquiry_id = $this->request->getGet('enquiry_id');
|
||||
$manager_id = $this->request->getGet('manager_id');
|
||||
|
||||
if (!empty($agent_id)) {
|
||||
$data = $this->enquiryModel->getEnquiry('AGENT', $agent_id);
|
||||
@ -29,6 +33,8 @@ class EnquiryController extends ResourceController
|
||||
$data = $this->enquiryModel->getEnquiry('STAFF', $staff_id);
|
||||
} elseif (!empty($enquiry_id)) {
|
||||
$data = $this->enquiryModel->getEnquiry('ENQUIRY',$enquiry_id);
|
||||
} elseif (!empty($manager_id)) {
|
||||
$data = $this->enquiryModel->getEnquiry('MANAGER',$manager_id);
|
||||
} else {
|
||||
$data = $this->enquiryModel->getEnquiry('ALL');
|
||||
}
|
||||
@ -40,23 +46,6 @@ class EnquiryController extends ResourceController
|
||||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
@ -99,14 +88,14 @@ class EnquiryController extends ResourceController
|
||||
$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,
|
||||
'vehicle_type_id' => $data['vehicle_type_id'],
|
||||
'insurer_id' => $data['insurer_id'],
|
||||
'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
|
||||
'remarks' => $data['remarks'],
|
||||
'manager_id' => $data['manager_id'] ,
|
||||
'created_by' => $data['created_by']
|
||||
];
|
||||
|
||||
$this->enquiryModel->insert($insertData);
|
||||
@ -141,7 +130,6 @@ class EnquiryController extends ResourceController
|
||||
'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,
|
||||
];
|
||||
|
||||
@ -183,22 +171,92 @@ class EnquiryController extends ResourceController
|
||||
}
|
||||
}
|
||||
|
||||
// Activate/Deactivate enquiry
|
||||
public function toggleEnquiryStatus()
|
||||
//Assign to staff
|
||||
public function enquiryAssignUpdate()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->getPost('id');
|
||||
$isActive = $this->request->getPost('is_active');
|
||||
|
||||
if (!$id) {
|
||||
$data = $this->request->getPost();
|
||||
|
||||
if (!isset($data['id'])) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'error' => 'ID Required'], 200);
|
||||
}
|
||||
|
||||
$this->enquiryModel->update($id, ['is_active' => $isActive]);
|
||||
$id = $data['id'];
|
||||
$enquiry = $this->enquiryModel->find($id);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'message' => 'Status updated'], 200);
|
||||
if (!$enquiry) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'error' => 'Data Not Found'], 200);
|
||||
}
|
||||
|
||||
$updateData = [
|
||||
'assigned_to' => $data['assigned_to']
|
||||
];
|
||||
|
||||
$this->enquiryModel->update($id, $updateData);
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'message' => 'Enquiry updated successfully'], 200);
|
||||
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Download enquiry file
|
||||
public function downloadEnquiryFile()
|
||||
{
|
||||
try {
|
||||
$enquiryId = $this->request->getGet('enquiry_id');
|
||||
$fileType = $this->request->getGet('file_type'); // rc | id_proof | previous_policy
|
||||
|
||||
if (!$enquiryId || !$fileType) {
|
||||
return $this->respond(['status' => 'failed','code' => 400,'data' => 'enquiry_id and file_type are required'], 200);
|
||||
}
|
||||
|
||||
// Map file_type to DB column and folder
|
||||
$fileMap = [
|
||||
'rc' => ['column' => 'rc_file_name', 'folder' => 'rc'],
|
||||
'id_proof' => ['column' => 'id_proof_file_name', 'folder' => 'id_proof'],
|
||||
'previous_policy' => ['column' => 'previous_policy_file_name', 'folder' => 'previous_policy'],
|
||||
];
|
||||
|
||||
if (!array_key_exists($fileType, $fileMap)) {
|
||||
return $this->respond(['status' => 'failed','code' => 400,'data' => 'Invalid file_type'], 200);
|
||||
}
|
||||
|
||||
$fileColumn = $fileMap[$fileType]['column'];
|
||||
$folder = $fileMap[$fileType]['folder'];
|
||||
|
||||
// Fetch record from DB
|
||||
$fileRecord = $this->enquiryModel->where('is_active', 1)->find($enquiryId);
|
||||
|
||||
if (!$fileRecord || empty($fileRecord[$fileColumn])) {
|
||||
return $this->respond([ 'status' => 'failed','code' => 404,'data' => 'File not found in database'], 200);
|
||||
}
|
||||
|
||||
$filePath = WRITEPATH . "uploads/enquiry/{$folder}/" . $fileRecord[$fileColumn];
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => 'File missing on server'], 200);
|
||||
}
|
||||
|
||||
// Force file download
|
||||
return $this->response->download($filePath, null);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'message' => $e->getMessage() ], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ use App\Models\RoleMasterModel;
|
||||
use App\Models\VehicleTypeMasterModel;
|
||||
use App\Models\InsurancePlanTypeMasterModel;
|
||||
use App\Models\InsurersModel;
|
||||
use App\Models\StaffModel;
|
||||
|
||||
|
||||
class MasterController extends ResourceController
|
||||
@ -17,6 +18,7 @@ class MasterController extends ResourceController
|
||||
protected $VehicleTypeMasterModel;
|
||||
protected $InsurancePlanTypeMasterModel;
|
||||
protected $InsurersModel;
|
||||
protected $StaffModel;
|
||||
|
||||
|
||||
public function __construct()
|
||||
@ -26,6 +28,7 @@ class MasterController extends ResourceController
|
||||
$this->VehicleTypeMasterModel = new VehicleTypeMasterModel();
|
||||
$this->InsurancePlanTypeMasterModel = new InsurancePlanTypeMasterModel();
|
||||
$this->InsurersModel = new InsurersModel();
|
||||
$this->StaffModel = new StaffModel();
|
||||
|
||||
}
|
||||
|
||||
@ -80,6 +83,17 @@ class MasterController extends ResourceController
|
||||
return $this->respond(['status' => 200,'message' => 'success','data' => $data]);
|
||||
}
|
||||
|
||||
public function getStaffMaster()
|
||||
{
|
||||
$data = $this->StaffModel->select('id,name')->where('is_active',1)->where('riole_id',2)->findAll();
|
||||
|
||||
if (!$data) {
|
||||
return $this->failNotFound('No data found');
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 200,'message' => 'success','data' => $data]);
|
||||
}
|
||||
|
||||
|
||||
// public function getTravelStatusMaster()
|
||||
// {
|
||||
|
||||
@ -20,6 +20,7 @@ class EnquiryModel extends Model
|
||||
'remarks',
|
||||
'status',
|
||||
'is_active',
|
||||
'manager_id',
|
||||
'assigned_to',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
@ -69,6 +70,10 @@ class EnquiryModel extends Model
|
||||
{
|
||||
return $data->where('partner_enquiry.id', $Id)->first();
|
||||
}
|
||||
else if($getBy == 'MANAGER')
|
||||
{
|
||||
return $data->where('partner_enquiry.manager_id', $Id)->first();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ class PolicyModel extends Model
|
||||
'policy_pdf_file_name',
|
||||
'policy_payment_receipt_file_name',
|
||||
'is_active',
|
||||
'manager_id',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
@ -16,6 +16,7 @@ class QuotationModel extends Model
|
||||
'status',
|
||||
'reject_reason',
|
||||
'is_active',
|
||||
'manager_id',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user