GWM : multiple file upload
This commit is contained in:
parent
fabae5dca6
commit
e64bbd7fa2
@ -87,6 +87,10 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
|||||||
$routes->post('enquiry/createEnquiry', 'EnquiryController::createEnquiry');
|
$routes->post('enquiry/createEnquiry', 'EnquiryController::createEnquiry');
|
||||||
$routes->post('enquiry/updateEnquiry', 'EnquiryController::updateEnquiry');
|
$routes->post('enquiry/updateEnquiry', 'EnquiryController::updateEnquiry');
|
||||||
$routes->get('enquiry/downloadEnquiryFile', 'EnquiryController::downloadEnquiryFile');
|
$routes->get('enquiry/downloadEnquiryFile', 'EnquiryController::downloadEnquiryFile');
|
||||||
|
$routes->post('enquiry/uploadEnquiryFiles', 'EnquiryController::uploadEnquiryFiles');
|
||||||
|
$routes->get('enquiry/downloadEnquiryFiles', 'EnquiryController::downloadEnquiryFiles');
|
||||||
|
$routes->get('enquiry/enquiryFiles', 'EnquiryController::enquiryFiles');
|
||||||
|
|
||||||
|
|
||||||
//Proposal
|
//Proposal
|
||||||
$routes->get('quotation/quotationList', 'QuotationController::quotationList');
|
$routes->get('quotation/quotationList', 'QuotationController::quotationList');
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use App\Models\AgentModel;
|
|||||||
use App\Models\EnquiryModel;
|
use App\Models\EnquiryModel;
|
||||||
use App\Models\QuotationModel;
|
use App\Models\QuotationModel;
|
||||||
use App\Models\PolicyModel;
|
use App\Models\PolicyModel;
|
||||||
|
use App\Models\FilesModel;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
class EnquiryController extends ResourceController
|
class EnquiryController extends ResourceController
|
||||||
{
|
{
|
||||||
@ -16,6 +17,7 @@ class EnquiryController extends ResourceController
|
|||||||
protected $AgentModel;
|
protected $AgentModel;
|
||||||
protected $QuotationModel;
|
protected $QuotationModel;
|
||||||
protected $PolicyModel;
|
protected $PolicyModel;
|
||||||
|
protected $FilesModel;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -25,6 +27,7 @@ class EnquiryController extends ResourceController
|
|||||||
$this->AgentModel = new AgentModel();
|
$this->AgentModel = new AgentModel();
|
||||||
$this->QuotationModel = new QuotationModel();
|
$this->QuotationModel = new QuotationModel();
|
||||||
$this->PolicyModel = new PolicyModel();
|
$this->PolicyModel = new PolicyModel();
|
||||||
|
$this->FilesModel = new FilesModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
// List all enquiries
|
// List all enquiries
|
||||||
@ -240,12 +243,28 @@ class EnquiryController extends ResourceController
|
|||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$enquiryId = $this->enquiryModel->insert($insertData , true);
|
$enquiryId = $this->enquiryModel->insert($insertData , true);
|
||||||
|
|
||||||
// trigger_email('enquiry_created', ['enquiry_id' => $enquiryId]);
|
// trigger_email('enquiry_created', ['enquiry_id' => $enquiryId]);
|
||||||
|
|
||||||
|
//create Quotation ana mark as accepted
|
||||||
|
$quotationData = [
|
||||||
|
'enquiry_id' => $enquiryId,
|
||||||
|
'insured_declared_value' => $data['insured_declared_value'] ?? 0,
|
||||||
|
'premium_amount' => $data['premium_amount'] ?? 0,
|
||||||
|
'insurance_plan_type_id' => $data['insurance_plan_type_id'] ?? 0,
|
||||||
|
'insurer_id' => $data['insurer_id'] ?? 0,
|
||||||
|
'insurer_branch_id' => $insurerBranchresult['id'] ?? 0,
|
||||||
|
'manager_id' => $data['manager_id'],
|
||||||
|
'payment_mode_id' => $data['payment_mode_id'] ?? 0,
|
||||||
|
'created_by' => $data['created_by'],
|
||||||
|
'status' => 'Accepted'
|
||||||
|
];
|
||||||
|
$QuotationId = $this->QuotationModel->insert($quotationData, true);
|
||||||
|
$this->enquiryModel->update($data['enquiry_id'], [ 'status' => 'Proposal Accepted' ]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->respond(['status' => 'success', 'code' => 200, 'message' => 'Enquiry created successfully'], 200);
|
return $this->respond(['status' => 'success', 'code' => 200, 'message' => 'Enquiry created successfully'], 200);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -422,6 +441,101 @@ class EnquiryController extends ResourceController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function uploadEnquiryFiles()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$enquiryId = $this->request->getPost('enquiry_id');
|
||||||
|
|
||||||
|
if (!$enquiryId) {
|
||||||
|
return $this->respond(['status' => 'failed', 'message' => 'enquiry_id required'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$files = $this->request->getFiles();
|
||||||
|
|
||||||
|
if (!$files) {
|
||||||
|
return $this->respond(['status' => 'failed', 'message' => 'No files uploaded'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$savedFiles = [];
|
||||||
|
|
||||||
|
foreach ($files['files'] as $file) {
|
||||||
|
if ($file->isValid()) {
|
||||||
|
$uploadPath = WRITEPATH . "uploads/enquiry/";
|
||||||
|
if (!is_dir($uploadPath)) {
|
||||||
|
mkdir($uploadPath, 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate file name
|
||||||
|
$newName = time() . '_' . $file->getRandomName();
|
||||||
|
$file->move($uploadPath, $newName);
|
||||||
|
|
||||||
|
// Save DB record
|
||||||
|
$this->FilesModel->insert([
|
||||||
|
'enquiry_id' => $enquiryId,
|
||||||
|
'file_name' => $newName,
|
||||||
|
'is_active' => 1,
|
||||||
|
'created_by' => $this->request->getPost('created_by') ?? 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$savedFiles[] = $newName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => 'success','uploaded_files' => $savedFiles ], 200);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 'failed', 'message' => $e->getMessage()], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function downloadEnquiryFiles()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$fileId = $this->request->getGet('file_id');
|
||||||
|
|
||||||
|
$file = $this->FilesModel->find($fileId);
|
||||||
|
|
||||||
|
if (!$file) {
|
||||||
|
return $this->respond(['status' => 'failed','message' => 'Invalid file id'], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$filePath = WRITEPATH . "uploads/enquiry/{$file['file_name']}";
|
||||||
|
|
||||||
|
if (!file_exists($filePath)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'failed',
|
||||||
|
'message' => 'File missing on server'
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force file download
|
||||||
|
return $this->response->download($filePath, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enquiryFiles()
|
||||||
|
{
|
||||||
|
$enquiryId = $this->request->getGet('enquiry_id');
|
||||||
|
|
||||||
|
if (!$enquiryId) {
|
||||||
|
return $this->respond(['status' => 'failed', 'message' => 'enquiry_id required'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$files = $this->FilesModel
|
||||||
|
->where('enquiry_id', $enquiryId)
|
||||||
|
->where('is_active', 1)
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => $files
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
36
app/Models/FilesModel.php
Normal file
36
app/Models/FilesModel.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class FilesModel extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'partner_files';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
protected $useAutoIncrement = true;
|
||||||
|
|
||||||
|
protected $returnType = 'array';
|
||||||
|
protected $useSoftDeletes = false;
|
||||||
|
|
||||||
|
protected $allowedFields = [
|
||||||
|
'enquiry_id',
|
||||||
|
'file_name',
|
||||||
|
'is_active',
|
||||||
|
'created_at',
|
||||||
|
'created_by',
|
||||||
|
'updated_at',
|
||||||
|
'updated_by'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Automatically handle created_at / updated_at (if you prefer CI4 timestamps)
|
||||||
|
protected $useTimestamps = false; // using manual timestamps in DB
|
||||||
|
|
||||||
|
// Validation Rules (optional)
|
||||||
|
protected $validationRules = [
|
||||||
|
'enquiry_id' => 'required|integer',
|
||||||
|
'file_name' => 'required|min_length[1]|max_length[255]',
|
||||||
|
'is_active' => 'permit_empty|in_list[0,1]'
|
||||||
|
];
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user