From eae368228ae0617afcfa0a0c221b3ad2ce1f65c5 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 10 Dec 2025 17:25:13 +0530 Subject: [PATCH] Insurer issue : GWM --- app/Controllers/PolicyController.php | 114 ++++++++++++++------------- app/Models/PolicyModel.php | 3 +- 2 files changed, 63 insertions(+), 54 deletions(-) diff --git a/app/Controllers/PolicyController.php b/app/Controllers/PolicyController.php index 05f1211..c31896f 100644 --- a/app/Controllers/PolicyController.php +++ b/app/Controllers/PolicyController.php @@ -180,35 +180,32 @@ 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 + '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, + 'updated_by' => $data['updated_by'] ?? null ]; $uploadPath = WRITEPATH . 'uploads/policy/'; @@ -240,7 +237,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 +311,6 @@ class PolicyController extends ResourceController return $this->respond(['status' => 'success', 'code' => 200, 'data' => $policyId ], 200); } - - - - if (!isset($data['id'])) { @@ -418,6 +423,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; @@ -437,6 +443,8 @@ class PolicyController extends ResourceController $policyData['model'] = $data['vehicle']['model'] ?? null; $policyData['cubic_capacity'] = $data['vehicle']['cubic_capacity'] ?? null; $policyData['vehicle_type'] = $data['vehicle']['vehicle_type'] ?? null; + + log_message('debug', 'Policy Update Payload: ' . json_encode($policyData)); @@ -448,24 +456,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 +483,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) @@ -517,7 +525,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; diff --git a/app/Models/PolicyModel.php b/app/Models/PolicyModel.php index bdbffd6..ba6b2be 100644 --- a/app/Models/PolicyModel.php +++ b/app/Models/PolicyModel.php @@ -48,7 +48,8 @@ class PolicyModel extends Model 'make', 'model', 'cubic_capacity', - 'vehicle_type' + 'vehicle_type', + 'broker_name' ]; protected $useTimestamps = false;