Merge code
This commit is contained in:
commit
56362a4e98
@ -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");
|
||||
|
||||
|
||||
//claims
|
||||
$routes->get('claim/ClaimList', 'ClaimController::ClaimList');
|
||||
@ -158,27 +159,15 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
|
||||
|
||||
});
|
||||
|
||||
$routes->get("policy/searchThePolicies", "PolicyController::searchThePolicies");
|
||||
$routes->get("dashboard/businessDashboard", "DashboardController::businessDashboard");
|
||||
$routes->get("dashboard/partnerDashboard", "DashboardController::partnerDashboard");
|
||||
$routes->get("dashboard/productivityDashboard", "DashboardController::productivityDashboard");
|
||||
|
||||
$routes->get("dashboard/downloadBrokerPoliciesExcel", "DashboardController::downloadBrokerPoliciesExcel");
|
||||
$routes->get("dashboard/downloadInsurerPoliciesExcel", "DashboardController::downloadInsurerPoliciesExcel");
|
||||
$routes->get("dashboard/downloadProductPoliciesExcel", "DashboardController::downloadProductPoliciesExcel");
|
||||
$routes->get("dashboard/partnerDashboard", "DashboardController::partnerDashboard");
|
||||
$routes->get("dashboard/partnerDashboard", "DashboardController::partnerDashboard");
|
||||
$routes->get("dashboard/partnerDashboard", "DashboardController::partnerDashboard");
|
||||
$routes->get("dashboard/productivityDashboard", "DashboardController::productivityDashboard");
|
||||
|
||||
|
||||
// $routes->get('agent/agentList', 'AgentController::agentList');
|
||||
// $routes->get('salesExecutive/executiveList', 'SalesExecutive::salesExecutiveList');
|
||||
// $routes->get('salesExecutive/findExecutive', 'SalesExecutive::findSalesExecutive');
|
||||
// $routes->post('salesExecutive/createExecutive', 'SalesExecutive::createSalesExecutive');
|
||||
// $routes->post('salesExecutive/updateExecutive', 'SalesExecutive::updateSalesExecutivedetails');
|
||||
// $routes->post('salesExecutive/changeExecutiveStatus', 'SalesExecutive::changeSalesExecutiveStatus');
|
||||
$routes->get("api/policy/PolicyFilePath", "PolicyController::PolicyFilePath");
|
||||
|
||||
$routes->group('test', [ ], function ($routes) {
|
||||
|
||||
$routes->get("policyCommissionCalculationAndGeminiPolicyRead", "PolicyController::policyCommissionCalculationAndGeminiPolicyRead");
|
||||
|
||||
});
|
||||
|
||||
$routes->cli('cli/processjob', 'JobWorker::processJob');
|
||||
$routes->cli('cli/processjobs', 'JobWorker::processJobs');
|
||||
$routes->get("processjob", "JobWorker::processJob");
|
||||
|
||||
@ -415,6 +415,7 @@ class EnquiryController extends ResourceController
|
||||
|
||||
];
|
||||
|
||||
|
||||
// File updates
|
||||
$idProofFile = $this->request->getFile('id_proof_file_name');
|
||||
$rcFile = $this->request->getFile('rc_file_name');
|
||||
@ -451,6 +452,11 @@ class EnquiryController extends ResourceController
|
||||
$this->enquiryModel->update($id, ['enquiry_status' => 'Assigned']);
|
||||
}
|
||||
|
||||
//update insurer data to quotation ( accepted quotation )
|
||||
$this->QuotationModel->set([ 'insurer_id' => $data['insurer_id'] ?? $enquiry['insurer_id'],'insurer_branch_id' => $insurerBranchresult['id'] ?? $enquiry['insurer_branch_id']])
|
||||
->where('enquiry_id',$id)->where('status','Accepted')
|
||||
->update();
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'message' => 'Enquiry updated successfully'], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@ -694,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")
|
||||
|
||||
@ -168,7 +168,7 @@ class PolicyController extends ResourceController
|
||||
public function updatePolicy()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getPost();
|
||||
$data = $this->request->getJSON(true);
|
||||
if (!isset($data['id'])) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'ID Required'], 200);
|
||||
}
|
||||
@ -180,35 +180,36 @@ class PolicyController extends ResourceController
|
||||
}
|
||||
|
||||
$updateData = [
|
||||
'quotation_id' => $data['quotation_id'] ?? $policy['quotation_id'],
|
||||
'insured_name' => $data['insured_name'] ?? $policy['insured_name'],
|
||||
'issued_date' => format_date_for_database($data['issued_date']),
|
||||
'start_date' => format_date_for_database($data['start_date']),
|
||||
'end_date' => format_date_for_database($data['end_date']),
|
||||
'premium_amount' => $data['premium_amount'] ?? $policy['premium_amount'],
|
||||
'policy_number' => $data['policy_number'] ?? $policy['policy_number'],
|
||||
'payment_mode' => $data['payment_mode'] ?? $policy['payment_mode'],
|
||||
|
||||
// newly added fields
|
||||
'tp' => $data['tp'] ?? null,
|
||||
'od' => $data['od'] ?? null,
|
||||
'pa' => $data['pa'] ?? null,
|
||||
'cgst' => $data['cgst'] ?? null,
|
||||
'sgst' => $data['sgst'] ?? null,
|
||||
'igst' => $data['igst'] ?? null,
|
||||
'rto_state_code' => $data['rto_state_code'] ?? null,
|
||||
'rto_city_code' => $data['rto_city_code'] ?? null,
|
||||
'weight' => $data['weight'] ?? null,
|
||||
'fuel_type' => $data['fuel_type'] ?? null,
|
||||
'date_of_registration' => !empty($data['date_of_registration']) ? format_date_for_database($data['date_of_registration']) : null,
|
||||
'year_of_manufacture' => $data['year_of_manufacture'] ?? null,
|
||||
'engine_no' => $data['engine_no'] ?? null,
|
||||
'chassis_no' => $data['chassis_no'] ?? null,
|
||||
'make' => $data['make'] ?? null,
|
||||
'model' => $data['model'] ?? null,
|
||||
'cubic_capacity' => $data['cubic_capacity'] ?? null,
|
||||
'vehicle_type' => $data['vehicle_type'] ?? null,
|
||||
'updated_by' => $data['updated_by'] ?? null
|
||||
'rc_no' => $data['rc_no'] ?? $policy['rc_no'],
|
||||
'insured_name' => $data['insured_name'] ?? $policy['insured_name'],
|
||||
'issued_date' => format_date_for_database($data['issued_date']),
|
||||
'start_date' => format_date_for_database($data['start_date']),
|
||||
'end_date' => format_date_for_database($data['end_date']),
|
||||
'premium_amount' => $data['premium_amount'] ?? $policy['premium_amount'],
|
||||
'policy_number' => $data['policy_number'] ?? $policy['policy_number'],
|
||||
'payment_mode' => $data['payment_mode'] ?? $policy['payment_mode'],
|
||||
'tp' => $data['tp'] ?? null,
|
||||
'od' => $data['od'] ?? null,
|
||||
'pa' => $data['pa'] ?? null,
|
||||
'cgst' => $data['cgst'] ?? null,
|
||||
'sgst' => $data['sgst'] ?? null,
|
||||
'igst' => $data['igst'] ?? null,
|
||||
'rto_state_code' => $data['rto_state_code'] ?? null,
|
||||
'rto_city_code' => $data['rto_city_code'] ?? null,
|
||||
'weight' => $data['weight'] ?? null,
|
||||
'fuel_type' => $data['fuel_type'] ?? null,
|
||||
'date_of_registration' => !empty($data['date_of_registration']) ? format_date_for_database($data['date_of_registration']) : null,
|
||||
'year_of_manufacture' => $data['year_of_manufacture'] ?? null,
|
||||
'engine_no' => $data['engine_no'] ?? null,
|
||||
'chassis_no' => $data['chassis_no'] ?? null,
|
||||
'make' => $data['make'] ?? null,
|
||||
'model' => $data['model'] ?? null,
|
||||
'cubic_capacity' => $data['cubic_capacity'] ?? null,
|
||||
'vehicle_type' => $data['vehicle_type'] ?? null,
|
||||
'broker_name' => $data['broker_name'] ?? null,
|
||||
'commission_amount' => $data['commission_amount'] ?? null,
|
||||
'updated_by' => $data['updated_by'] ?? null,
|
||||
'is_data_accuracy_checked'=> 1
|
||||
];
|
||||
|
||||
$uploadPath = WRITEPATH . 'uploads/policy/';
|
||||
@ -240,7 +241,19 @@ class PolicyController extends ResourceController
|
||||
$this->PolicyModel->update($id, $updateData);
|
||||
|
||||
|
||||
// trigger_email('policy_created', ['policy_id' => $id]);
|
||||
// Call helper to create BDS record after creating client,clientPolicy,vehicle records
|
||||
$policyData = $this->PolicyModel->select('partner_policy.*,Q.insurer_id,Q.insurer_branch_id,E.name as client_name,E.mobile as client_mobile,E.email as client_email,E.reg_no,E.vehicle_type_id,A.id as agent_id,A.agent_code')
|
||||
->join('partner_quotation Q', 'Q.id = partner_policy.quotation_id AND Q.status = "Accepted"', 'left')
|
||||
->join('partner_enquiry E', 'E.id = partner_policy.enquiry_id', 'left')
|
||||
->join('partner_agent A', 'A.id = partner_policy.agent_id', 'left')
|
||||
->where('partner_policy.id',$id)
|
||||
->first();
|
||||
$bdsLogs = createBDS($policyData, $id);
|
||||
if (!empty($bdsLogs)) {
|
||||
foreach ($bdsLogs as $msg) {
|
||||
log_message('info', '[BDS Entry] ' . $msg);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
|
||||
|
||||
@ -302,10 +315,6 @@ class PolicyController extends ResourceController
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $policyId ], 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!isset($data['id'])) {
|
||||
|
||||
@ -324,7 +333,7 @@ class PolicyController extends ResourceController
|
||||
//update enquiry status
|
||||
$quotationData = $this->QuotationModel->where('id',$data['quotation_id'])->first();
|
||||
if (!empty($quotationData)){
|
||||
$enquiryArray = ['vehicle_type_id' => $data['vehicle_type_id'] ?? 0 , 'broker_id' => $data['broker_id'] ?? 0 , 'status'=> 'Policy Created' , 'enquiry_status' => 'Completed' ];
|
||||
$enquiryArray = ['status'=> 'Policy Created' , 'enquiry_status' => 'Completed' ];
|
||||
$this->EnquiryModel->update($quotationData['enquiry_id'], $enquiryArray );
|
||||
}
|
||||
|
||||
@ -400,6 +409,61 @@ 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];
|
||||
$publicUrl = base_url("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' => $publicUrl ], 200);
|
||||
|
||||
// Detect the file mime type
|
||||
$mime = mime_content_type($filePath);
|
||||
|
||||
// Stream file to browser / Flutter
|
||||
return $this->response
|
||||
->setHeader('Content-Type', $mime)
|
||||
->setHeader('Content-Disposition', 'inline; filename="' . $fileRecord[$fileColumn] . '"')
|
||||
->setBody(file_get_contents($filePath));
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'message' => $e->getMessage() ], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function readFileAndCalculateCommission(array $data)
|
||||
{
|
||||
$policyId = $data['policy_id'];
|
||||
@ -418,6 +482,7 @@ class PolicyController extends ResourceController
|
||||
$policyData['issued_date'] = $data['policy']['issue_date'] ?? null;
|
||||
$policyData['start_date'] = $data['policy']['period']['start'] ?? null;
|
||||
$policyData['end_date'] = $data['policy']['period']['end'] ?? null;
|
||||
$policyData['broker_name'] = $data['policy']['intermediary_name'] ?? null;
|
||||
$policyData['tp'] = $data['premium']['tp'] ?? null;
|
||||
$policyData['od'] = $data['premium']['od'] ?? null;
|
||||
$policyData['pa'] = $data['premium']['pa'] ?? null;
|
||||
@ -436,7 +501,10 @@ class PolicyController extends ResourceController
|
||||
$policyData['make'] = $data['vehicle']['make'] ?? null;
|
||||
$policyData['model'] = $data['vehicle']['model'] ?? null;
|
||||
$policyData['cubic_capacity'] = $data['vehicle']['cubic_capacity'] ?? null;
|
||||
$policyData['vehicle_type'] = $data['vehicle']['vehicle_type'] ?? null;
|
||||
$policyData['vehicle_type'] = $data['vehicle']['vehicle_type'] ?? null;
|
||||
$policyData['rc_no'] = $data['vehicle']['reg_no'] ?? null;
|
||||
|
||||
|
||||
|
||||
log_message('debug', 'Policy Update Payload: ' . json_encode($policyData));
|
||||
|
||||
@ -448,24 +516,24 @@ class PolicyController extends ResourceController
|
||||
|
||||
$calculateCommission = $this->calculateCommission($policyId);
|
||||
|
||||
if($calculateCommission['status'] == 'success')
|
||||
{
|
||||
log_message('debug', 'BDS record creating started for ID: '.$policyId);
|
||||
// if($calculateCommission['status'] == 'success')
|
||||
// {
|
||||
// log_message('debug', 'BDS record creating started for ID: '.$policyId);
|
||||
|
||||
// Call helper to create BDS record after creating client,clientPolicy,vehicle records
|
||||
$policyData = $this->PolicyModel->select('partner_policy.*,Q.insurer_id,Q.insurer_branch_id,E.name as client_name,E.mobile as client_mobile,E.email as client_email,E.reg_no,E.vehicle_type_id,A.id as agent_id,A.agent_code')
|
||||
->join('partner_quotation Q', 'Q.id = partner_policy.quotation_id AND Q.status = "Accepted"', 'left')
|
||||
->join('partner_enquiry E', 'E.id = partner_policy.enquiry_id', 'left')
|
||||
->join('partner_agent A', 'A.id = partner_policy.agent_id', 'left')
|
||||
->where('partner_policy.id',$policyId)
|
||||
->first();
|
||||
$bdsLogs = createBDS($policyData, $policyId);
|
||||
if (!empty($bdsLogs)) {
|
||||
foreach ($bdsLogs as $msg) {
|
||||
log_message('info', '[BDS Entry] ' . $msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
// // Call helper to create BDS record after creating client,clientPolicy,vehicle records
|
||||
// $policyData = $this->PolicyModel->select('partner_policy.*,Q.insurer_id,Q.insurer_branch_id,E.name as client_name,E.mobile as client_mobile,E.email as client_email,E.reg_no,E.vehicle_type_id,A.id as agent_id,A.agent_code')
|
||||
// ->join('partner_quotation Q', 'Q.id = partner_policy.quotation_id AND Q.status = "Accepted"', 'left')
|
||||
// ->join('partner_enquiry E', 'E.id = partner_policy.enquiry_id', 'left')
|
||||
// ->join('partner_agent A', 'A.id = partner_policy.agent_id', 'left')
|
||||
// ->where('partner_policy.id',$policyId)
|
||||
// ->first();
|
||||
// $bdsLogs = createBDS($policyData, $policyId);
|
||||
// if (!empty($bdsLogs)) {
|
||||
// foreach ($bdsLogs as $msg) {
|
||||
// log_message('info', '[BDS Entry] ' . $msg);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
} else {
|
||||
log_message('error', 'Failed to update policy for ID: '.$policyId);
|
||||
@ -475,7 +543,7 @@ class PolicyController extends ResourceController
|
||||
}
|
||||
|
||||
|
||||
return ['checkPolicyDoc' => $readDoc['status'] , 'calculateCommission' => $calculateCommission['status'] ?? 'failed' , 'createBDS' => 'Started , check log for more details.' ];
|
||||
return ['checkPolicyDoc' => $readDoc['status'] , 'calculateCommission' => $calculateCommission['status'] ?? 'failed' ];
|
||||
}
|
||||
|
||||
public function checkPolicyDoc($policyId = null , $return = null)
|
||||
@ -500,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
|
||||
@ -517,7 +590,7 @@ class PolicyController extends ResourceController
|
||||
// The prompt you want to send to the model
|
||||
// $prompt = "give me a json with emp data like name,age,dob,mobile and email. only json not any explanations";
|
||||
$prompt = "Read the following motor policy pdf document and convert into JSON format as sample specified. Give me only JSON,not any explanations.while pick up premium break up give own damage, third party ,personal accident and taxes as mentioned in JSON format.Notes:vehicle_type should be like Two Wheeler,Four Feeler,Good Vehicle,Bus, Tractor,Commercial Vehicle.rto_state_code is first two char of reg_no and rto_city_code 3rd & 4th char of reg_no and it should be two digit numeric code. Any date should be in mysql date format";
|
||||
$prompt .= '"{\"policy\":{\"policy_number\":\"\",\"issue_date\":\"\",\"period\":{\"start\":\"\",\"end\":\"\"},\"insurer\":\"\",\"previous_policy_number\":\"\"},\"insured\":{\"name\":\"\",\"father_name\":\"\",\"address\":[\"\"],\"mobile\":\"\",\"id_proofs\":{\"aadhaar\":\"\",\"pan\":\"\"}},\"vehicle\":{\"reg_no\":\"\",\"rto_state_code\":\"\",\"rto_city_code\":\"\",\"weight\":\"\",\"fuel_type\":\"\",\"date_of_registration\":\"\",\"year_of_manufacture\":\"\",\"engine_no\":\"\",\"chassis_no\":\"\",\"make\":\"\",\"model\":\"\",\"year\":\"\",\"cubic_capacity\":\"\",\"vehicle_type\":\"\"},\"rto\":\"\",\"premium\":{\"tp\":0,\"od\":0,\"pa\":0,\"taxes\":{},\"total\":0,\"in_words\":\"\"},\"endorsements\":[{\"code\":\"\",\"desc\":\"\"}]}"';
|
||||
$prompt .= '"{\"policy\":{\"intermediary_name\":\"\",\"policy_number\":\"\",\"issue_date\":\"\",\"period\":{\"start\":\"\",\"end\":\"\"},\"insurer\":\"\",\"previous_policy_number\":\"\"},\"insured\":{\"name\":\"\",\"father_name\":\"\",\"address\":[\"\"],\"mobile\":\"\",\"id_proofs\":{\"aadhaar\":\"\",\"pan\":\"\"}},\"vehicle\":{\"reg_no\":\"\",\"rto_state_code\":\"\",\"rto_city_code\":\"\",\"weight\":\"\",\"fuel_type\":\"\",\"date_of_registration\":\"\",\"year_of_manufacture\":\"\",\"engine_no\":\"\",\"chassis_no\":\"\",\"make\":\"\",\"model\":\"\",\"year\":\"\",\"cubic_capacity\":\"\",\"vehicle_type\":\"\"},\"rto\":\"\",\"premium\":{\"tp\":0,\"od\":0,\"pa\":0,\"taxes\":{},\"total\":0,\"in_words\":\"\"},\"endorsements\":[{\"code\":\"\",\"desc\":\"\"}]}"';
|
||||
|
||||
$payloadPart = null;
|
||||
|
||||
@ -597,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);
|
||||
|
||||
@ -607,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
|
||||
@ -636,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
|
||||
@ -644,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) {
|
||||
@ -657,26 +758,33 @@ 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);
|
||||
|
||||
$record = $this->PolicyModel->select('partner_policy.* , pe.insurer_id , VT.vehicle_type , ipti.insurance_plan_type,')
|
||||
$record = $this->PolicyModel->select('partner_policy.* , rto_state.rto_state_name as rto_state_code , ,pe.insurer_id , VT.vehicle_type as vehicle_type_master , ipti.insurance_plan_type,')
|
||||
->join('partner_enquiry pe', 'pe.id = partner_policy.enquiry_id', 'left')
|
||||
->join('vehicle_type VT', 'VT.id = pe.vehicle_type_id', 'left')
|
||||
->join('partner_quotation pq', 'pq.id = partner_policy.quotation_id', 'left')
|
||||
->join('partner_insurance_plan_type_master ipti', 'ipti.id = pq.insurance_plan_type_id', 'left')
|
||||
->join('rto_master rto_state', 'rto_state.rto_state = partner_policy.rto_state_code', 'left')
|
||||
// ->join('rto_master rto_city', 'rto_city.rto_code = partner_policy.rto_city_code', 'left')
|
||||
->where('partner_policy.id', $policyId)
|
||||
->first();
|
||||
|
||||
$apiUrl = "https://venbait.in/nhance/dev/getCommission";
|
||||
$apiUrl = getenv('COMMISSION_CALCULATION_URL');
|
||||
|
||||
$token = "A7fP3xQ9mD2vT6sR1bW8kJ4yC0gN5zH3uL9pE2rF7cV1tX6hB0qM4dG8nS5aU3jK7";
|
||||
$token = getenv('COMMISSION_CALCULATION_TOKEN');
|
||||
|
||||
$manufactureYear = (int) $record['year_of_manufacture'];
|
||||
$currentYear = (int) date("Y");
|
||||
@ -693,7 +801,7 @@ class PolicyController extends ResourceController
|
||||
"premium" => $record['premium_amount'],
|
||||
"od_premium" => $record['od'],
|
||||
"tp_premium" => $record['tp'],
|
||||
"cubic_capcity" => $record['cubic_capacity'],
|
||||
"cubic_capacity" => $record['cubic_capacity'],
|
||||
"weight" => $record['weight'],
|
||||
"make" => $record['make'],
|
||||
"model" => $record['model'],
|
||||
@ -731,7 +839,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);
|
||||
@ -741,6 +855,11 @@ class PolicyController extends ResourceController
|
||||
// Optional: Debug API result
|
||||
// print_r($result);
|
||||
|
||||
if($return == true)
|
||||
{
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result , 'payload' => $postData ], 200);
|
||||
}
|
||||
|
||||
if (!empty($result) && isset($result['success']) && $result['success'] === true) {
|
||||
|
||||
// Safely extract values
|
||||
@ -751,21 +870,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() {
|
||||
|
||||
|
||||
@ -53,11 +53,13 @@ class EnquiryModel extends Model
|
||||
P.policy_number,
|
||||
P.id as policy_id,
|
||||
P.policy_pdf_file_name,
|
||||
P.is_data_accuracy_checked,
|
||||
PB.name as broker_name,
|
||||
pm.id as payment_mode_id ,
|
||||
pm.value as payment_mode_value,
|
||||
ipti.insurance_plan_type
|
||||
')
|
||||
->select('CASE WHEN P.client_id IS NOT NULL THEN 1 ELSE 0 END AS is_bds_pushed', false)
|
||||
->join('vehicle_type VT', 'VT.id = partner_enquiry.vehicle_type_id', 'left')
|
||||
->join('partner_agent A', 'A.id = partner_enquiry.agent_id', 'left')
|
||||
->join('partner_staff S', 'S.id = partner_enquiry.assigned_to', 'left')
|
||||
|
||||
@ -48,7 +48,10 @@ class PolicyModel extends Model
|
||||
'make',
|
||||
'model',
|
||||
'cubic_capacity',
|
||||
'vehicle_type'
|
||||
'vehicle_type',
|
||||
'broker_name',
|
||||
'commission_amount',
|
||||
'is_data_accuracy_checked',
|
||||
];
|
||||
|
||||
protected $useTimestamps = false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user