FEAT_PT_FILE_DOWNLOAD
This commit is contained in:
parent
b4cd7aa063
commit
701a702a0c
@ -688,6 +688,8 @@ $routes->group("employeeRest", ["filter" => ['GlobalPostFileUploadGuard', 'appSi
|
||||
// get insurer and policy type
|
||||
$routes->get("getPolicyTypeAndInsurer", "EmployeeRestController::getPolicyTypeAndInsurer");
|
||||
$routes->get("getExcelFileErrors/(:any)", "EmployeeController::getExcelFileErrors/$1");
|
||||
$routes->get("getPolicyAndEndorsementFiles", "EmployeeRestController::getPolicyAndEndorsementFiles");
|
||||
$routes->get("downloadPolicyFiles", "EmployeeRestController::downloadPolicyFiles");
|
||||
});
|
||||
|
||||
$routes->get("hrFileDownload", "EmployeeRestController::hrFileDownload");
|
||||
|
||||
@ -41,6 +41,8 @@ use App\Models\InsurerModel;
|
||||
use App\Models\HrFileUploadModel;
|
||||
use App\Models\EmployeeRetailPolicy;
|
||||
use App\Models\BatchFileModel;
|
||||
use App\Models\ClientDepositModel;
|
||||
use App\Models\PTFileModel;
|
||||
|
||||
|
||||
|
||||
@ -5417,6 +5419,99 @@ class EmployeeRestController extends AdminController
|
||||
return view('errors/404', $data);
|
||||
}
|
||||
}
|
||||
|
||||
// get policy files
|
||||
public function getPolicyAndEndorsementFiles()
|
||||
{
|
||||
$cd_ac_pk = $this->request->getGet('cd_ac_pk') ?? null;
|
||||
|
||||
$cdModel = new ClientDepositModel();
|
||||
$cd_data = $cdModel->where('id', $cd_ac_pk)
|
||||
->where('is_active', 1)
|
||||
->where('client_policy_id IS NOT NULL')
|
||||
->first();
|
||||
|
||||
if(empty($cd_data)){
|
||||
$this->myLogger->logme('error', 'getPolicyAndEndorsementFiles: No Client Deposit data found for cd_ac_pk=' . $cd_ac_pk);
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'No file found'], 200);
|
||||
}
|
||||
|
||||
$client_policy_data = $this->clientPolicyModel
|
||||
->where('id', $cd_data['client_policy_id'])
|
||||
->where('is_active', 1)
|
||||
->first();
|
||||
|
||||
if(empty($client_policy_data)){
|
||||
$this->myLogger->logme('error', 'getPolicyAndEndorsementFiles: No Client Policy data found for client_policy_id=' . $cd_data['client_policy_id']);
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'No file found'], 200);
|
||||
}
|
||||
|
||||
$policyTransactionModel = new PolicyTransactionModel();
|
||||
$policy_transaction_data = $policyTransactionModel->where('is_active', 1)->where('policy_no', $client_policy_data['policy_no'])->findAll();
|
||||
|
||||
if(empty($policy_transaction_data)){
|
||||
$this->myLogger->logme('error', 'getPolicyAndEndorsementFiles: No Policy Transaction data found for policy_no=' . $client_policy_data['policy_no']);
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'No file found'], 200);
|
||||
}
|
||||
|
||||
$policy_transaction_ids = array_column($policy_transaction_data, 'id');
|
||||
|
||||
|
||||
$ptFilesModel = new PTFileModel();
|
||||
$pt_files_data = $ptFilesModel->where('is_active', 1)->whereIn('policy_transaction_id', $policy_transaction_ids)->findAll();
|
||||
|
||||
if(empty($pt_files_data)){
|
||||
$this->myLogger->logme('error', 'getPolicyAndEndorsementFiles: No PT Files data found for pt_ids=' . implode(',', $policy_transaction_ids));
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'No file found'], 200);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// construct the policy file list
|
||||
private function constructPtFileToDownloadableLinks($data)
|
||||
{
|
||||
$file_list = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$file_list[] = [
|
||||
'id' => $value['id'],
|
||||
'pt_id' => $value['pt_id'],
|
||||
'file_name' => $value['file_name'],
|
||||
'doc_name' => $value['doc_name'],
|
||||
];
|
||||
}
|
||||
|
||||
return $file_list;
|
||||
}
|
||||
|
||||
// download policy file
|
||||
public function downloadPolicyFiles()
|
||||
{
|
||||
$pt_file_id = $this->request->getGet('file_id') ?? null;
|
||||
|
||||
if(empty($pt_file_id)){
|
||||
return $this->respond(['status' => false, 'code' => 404, 'message' => 'File ID is required'], 200);
|
||||
}
|
||||
|
||||
$uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents';
|
||||
|
||||
$ptFilesModel = new PTFileModel();
|
||||
$pt_files_data = $ptFilesModel->where('is_active', 1)->where('id', $pt_file_id)->first();
|
||||
|
||||
if(empty($pt_files_data)){
|
||||
$data['message'] = 'The Physical File Not Found in server';
|
||||
return view('errors/404', $data); }
|
||||
|
||||
$filePath = $uploadFilePath . '/' . $pt_files_data['file_name'];
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
$data['message'] = 'The Physical File Not Found in server';
|
||||
return view('errors/404', $data);
|
||||
}
|
||||
|
||||
// Force file download
|
||||
return $this->response->download($filePath, null)->setFileName($pt_files_data['file_name']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user