From 93d642b270dd54d6b7e3cdbe12b6e5103db2848d Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Thu, 11 Dec 2025 12:19:28 +0530 Subject: [PATCH] GWM : api test --- app/Config/Routes.php | 8 ++ app/Controllers/EnquiryController.php | 7 ++ app/Controllers/PolicyController.php | 101 ++++++++++++++++++++++---- 3 files changed, 101 insertions(+), 15 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 99689e0..6fdba95 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -156,6 +156,14 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { $routes->get("api/policy/PolicyFilePath", "PolicyController::PolicyFilePath"); + $routes->group('test', [ ], function ($routes) { + + $routes->get("policyCommissionCalculationAndGeminiPolicyRead", "PolicyController::policyCommissionCalculationAndGeminiPolicyRead"); + + }); + + + // $routes->get("policy/searchThePolicies", "PolicyController::searchThePolicies"); // $routes->get("dashboard/businessDashboard", "DashboardController::businessDashboard"); // $routes->get("dashboard/partnerDashboard", "DashboardController::partnerDashboard"); diff --git a/app/Controllers/EnquiryController.php b/app/Controllers/EnquiryController.php index ab71629..f7420fd 100644 --- a/app/Controllers/EnquiryController.php +++ b/app/Controllers/EnquiryController.php @@ -700,6 +700,13 @@ class EnquiryController extends ResourceController ])->setStatusCode(400); } + if ($reg_no == 'New' || $reg_no == 'new' || $reg_no == 'NEW') { + return $this->response->setJSON([ + "status" => "not exists", + "message" => "No active record found for this vehicle number in enquiries." + ]); + } + // --- 2. Step 1: Check in partner_enquiry (Active/Latest Record) --- // Get the LATEST ACTIVE enquiry record for the registration number $enquiry = $this->db->table("partner_enquiry") diff --git a/app/Controllers/PolicyController.php b/app/Controllers/PolicyController.php index b2017f9..779ae96 100644 --- a/app/Controllers/PolicyController.php +++ b/app/Controllers/PolicyController.php @@ -568,7 +568,12 @@ class PolicyController extends ResourceController // Check if the file exists if (!file_exists($filePath)) { log_message('info',"Error: File not found at {$filePath}"); - return ['status'=>"failed", 'message'=> "File not found at {$filePath}"]; + if($return == true) + { + return $this->respond(['status'=>"failed", 'message'=> "File not found at {$filePath}"], 200); + }else{ + return ['status'=>"failed", 'message'=> "File not found at {$filePath}"]; + } } // Get the file's MIME type using the finfo extension @@ -665,7 +670,12 @@ class PolicyController extends ResourceController if (curl_errno($ch)) { $curl_error = curl_error($ch); log_message('info',"cURL Error: " . $curl_error); - return ['status'=>"failed", 'message'=> "cURL Error: " . $curl_error]; + if($return == true) + { + return $this->respond(['status'=>"failed", 'message'=> "cURL Error: " . $curl_error], 200); + }else{ + return ['status'=>"failed", 'message'=> "cURL Error: " . $curl_error]; + } } $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); @@ -675,7 +685,12 @@ class PolicyController extends ResourceController // Check for non-successful HTTP status codes if ($http_code < 200 || $http_code >= 300) { log_message('info',"API returned non-successful HTTP status code: $http_code. Response: " . substr($response, 0, 200)); - return ['status'=>"failed", 'message'=> "API returned non-successful HTTP status code: $http_code. Response: " . substr($response, 0, 200)]; + if($return == true) + { + return $this->respond(['status'=>"failed", 'message'=> "API returned non-successful HTTP status code: $http_code. Response: " . substr($response, 0, 200)], 200); + }else{ + return ['status'=>"failed", 'message'=> "API returned non-successful HTTP status code: $http_code. Response: " . substr($response, 0, 200)]; + } } // Decode the JSON response @@ -704,7 +719,12 @@ class PolicyController extends ResourceController if (empty($json_string)) { log_message('info',"Could not extract a valid JSON string from the generated text."); - return ['status'=>"failed", 'message'=> "Could not extract a valid JSON string from the generated text."]; + if($return == true) + { + return $this->respond(['status'=>"failed", 'message'=> "Could not extract a valid JSON string from the generated text."], 200); + }else{ + return ['status'=>"failed", 'message'=> "Could not extract a valid JSON string from the generated text."]; + } } // Decode the extracted JSON string @@ -712,11 +732,24 @@ class PolicyController extends ResourceController log_message('info', "Extracted and decoded final JSON data successfully."); - return ['status'=>"success", 'message'=> "Doc read sucess" , 'data'=>$final_data]; + if($return == true) + { + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $final_data ], 200); + }else + { + return ['status'=>"success", 'message'=> "Doc read sucess" , 'data'=>$final_data]; + } + + } else { log_message('info',"Response structure invalid or no generated text candidate found."); - return ['status'=>"failed", 'message'=> "Response structure invalid or no generated text candidate found"]; + if($return == true) + { + return $this->respond(['status'=>"failed", 'message'=> "Response structure invalid or no generated text candidate found"], 200); + }else{ + return ['status'=>"failed", 'message'=> "Response structure invalid or no generated text candidate found"]; + } } } catch (\Exception $e) { @@ -725,12 +758,17 @@ class PolicyController extends ResourceController // curl_close($ch); // } log_message('error', "Fatal Error: " . $e->getMessage()); - return ['status'=>"failed", 'message'=> "Error: " . $e->getMessage()]; + if($return == true) + { + return $this->respond(['status'=>"failed", 'message'=> "Error: " . $e->getMessage()], 200); + }else{ + return ['status'=>"failed", 'message'=> "Error: " . $e->getMessage()]; + } } } - public function calculateCommission($policyId = null) + public function calculateCommission($policyId = null , $return = null) { log_message('debug', 'calculateCommission() started with policyId: ' . $policyId); @@ -799,7 +837,13 @@ class PolicyController extends ResourceController if ($error) { log_message('error', 'cURL Error: ' . $error); - return ['status'=>"failed", 'message'=> 'cURL Error: ' . $error]; + if($return == true) + { + return $this->respond( ['status'=>"failed", 'message'=> 'cURL Error: ' . $error], 200); + }else{ + return ['status'=>"failed", 'message'=> 'cURL Error: ' . $error]; + } + } else { log_message('debug', 'API Response: ' . $response); @@ -819,21 +863,48 @@ class PolicyController extends ResourceController log_message('debug', 'Updating Policy (ID=75) With: ' . json_encode($policyData)); - // Update record - $this->PolicyModel->update($policyId, $policyData); + if($return == true) + { + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $policyData ], 200); + }else{ + // Update record + $this->PolicyModel->update($policyId, $policyData); + log_message('debug', 'Policy update successful!'); + return ['status'=>"success", 'message'=> "Commission Updated!"]; + } - log_message('debug', 'Policy update successful!'); - - return ['status'=>"success", 'message'=> "Commission Updated!"]; + } else { log_message('debug', 'calculateCommission() - Invalid API Response'); - return ['status'=>"failed", 'message'=> "Invalid API Response!"]; + if($return == true) + { + return $this->respond( ['status'=>"failed", 'message'=> "Invalid API Response!"], 200); + }else{ + return ['status'=>"failed", 'message'=> "Invalid API Response!"]; + } } } } + public function policyCommissionCalculationAndGeminiPolicyRead() + { + + $type = $this->request->getGet('type'); + $policyId = $this->request->getGet('policy_id'); + + if($type == 'commission') + { + return $this->calculateCommission($policyId , true); + + }else if($type == 'read') + { + return $this->checkPolicyDoc($policyId , true); + } + + } + public function searchThePolicies() {