From 51648ee9f380c22b1ef00920bac180e6cf8b6dbb Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 10 Dec 2025 18:19:00 +0530 Subject: [PATCH] validation : GWM --- app/Config/Routes.php | 1 + app/Controllers/PolicyController.php | 45 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index becdca8..08de21a 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -116,6 +116,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { $routes->get('policy/downloadPolicyFile', 'PolicyController::downloadPolicyFile'); $routes->post('policy/uploadPolicyFile', 'PolicyController::uploadPolicyFile'); $routes->get("policy/searchThePolicies", "PolicyController::searchThePolicies"); + $routes->get("policy/PolicyFilePath", "PolicyController::PolicyFilePath"); //claims $routes->get('claim/ClaimList', 'ClaimController::ClaimList'); diff --git a/app/Controllers/PolicyController.php b/app/Controllers/PolicyController.php index fe56d18..2119298 100644 --- a/app/Controllers/PolicyController.php +++ b/app/Controllers/PolicyController.php @@ -406,6 +406,51 @@ class PolicyController extends ResourceController } } + public function PolicyFilePath() + { + try { + $policyId = $this->request->getGet('policy_id'); + $fileType = $this->request->getGet('file_type'); // policy_pdf , policy_payment_receipt + + if (!$policyId || !$fileType) { + return $this->respond(['status' => 'failed','code' => 400,'data' => 'policy_id and file_type are required'], 200); + } + + // Map file_type to DB column and folder + $fileMap = [ + 'policy_pdf' => ['column' => 'policy_pdf_file_name', 'folder' => 'policy_pdf'], + 'policy_payment_receipt'=> ['column' => 'policy_payment_receipt_file_name', 'folder' => 'policy_payment_receipt'], + ]; + + 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->PolicyModel->where('is_active', 1)->find($policyId); + + if (!$fileRecord || empty($fileRecord[$fileColumn])) { + return $this->respond([ 'status' => 'failed','code' => 404,'data' => 'File not found in database'], 200); + } + + $filePath = WRITEPATH . "uploads/policy/{$folder}/" . $fileRecord[$fileColumn]; + + if (!file_exists($filePath)) { + return $this->respond(['status' => 'failed','code' => 404,'data' => 'File missing on server'], 200); + } + + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $filePath ], 200); + + + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'message' => $e->getMessage() ], 500); + } + } + public function readFileAndCalculateCommission(array $data) { $policyId = $data['policy_id'];