From 38894bc929ef5a138e2596c44d98eb7ca7e5e3a5 Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Mon, 1 Jun 2026 10:06:45 +0530 Subject: [PATCH 1/7] FIX_CLAIM_LIST_VEH_NO_NOT_LIST_AND_CLAIM_DISCRIPTION_REMOVE_REQUIRED_BY_VENKATESH --- app/Controllers/ClaimController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Controllers/ClaimController.php b/app/Controllers/ClaimController.php index 0981f4a..6940d90 100644 --- a/app/Controllers/ClaimController.php +++ b/app/Controllers/ClaimController.php @@ -73,7 +73,7 @@ class ClaimController extends ResourceController tcs.claim_status as claim_status_value, pp.start_date as policy_start_date, pp.end_date as policy_end_date, - v.vehicle_no as reg_no') + pp.rc_no as reg_no') ->join('insurers i', 'i.id = pc.insurer_id', 'left') ->join('partner_claim_type_master pct', 'pct.id = pc.claim_type', 'left') ->join('partner_agent pa', 'pa.id = pc.agent_id', 'left') @@ -145,11 +145,11 @@ class ClaimController extends ResourceController try { $reqData = $this->request->getPost(); - if (empty($reqData['policy_number']) || empty($reqData['claim_description']) || empty($reqData['claim_type'])) { + if (empty($reqData['policy_number']) || empty($reqData['claim_type'])) { return $this->respond([ 'status' => 'failed', 'code' => 400, - 'data' => 'policy_number, claim_description and claim_type are required', + 'data' => 'policy_number and claim_type are required', ], 400); } @@ -188,7 +188,7 @@ class ClaimController extends ResourceController 'claim_type' => $reqData['claim_type'], 'date_of_incident' => format_date_for_database($reqData['date_of_incident'] ?? null), 'place_of_incident' => $reqData['place_of_incident'] ?? null, - 'claim_description' => $reqData['claim_description'], + 'claim_description' => $reqData['claim_description'] ?? null, 'spot_surveyor_name' => $reqData['spot_surveyor_name'] ?? null, 'spot_surveyor_contact' => $reqData['spot_surveyor_contact'] ?? null, 'workshop_surveyor_name' => $reqData['workshop_surveyor_name'] ?? null, From b7d52e74d0162138b30737931304f63f6e33197f Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Mon, 1 Jun 2026 10:57:45 +0530 Subject: [PATCH 2/7] FIX_CLAIM_FILES_UPLOAD --- app/Controllers/ClaimController.php | 71 +++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/app/Controllers/ClaimController.php b/app/Controllers/ClaimController.php index 6940d90..6e8b551 100644 --- a/app/Controllers/ClaimController.php +++ b/app/Controllers/ClaimController.php @@ -503,23 +503,59 @@ class ClaimController extends ResourceController private function collectClaimUploadFiles(): array { $filesToProcess = []; + $candidates = []; $multiple = $this->request->getFileMultiple('claim_files'); if (!empty($multiple)) { - foreach ($multiple as $uploadedFile) { - if ($this->isValidUploadFile($uploadedFile)) { - $filesToProcess[] = $uploadedFile; - } - } - return $filesToProcess; + $candidates[] = $multiple; } $single = $this->request->getFile('claim_files'); - if ($this->isValidUploadFile($single)) { - $filesToProcess[] = $single; + if ($single !== null) { + $candidates[] = $single; } - return $filesToProcess; + $allFiles = $this->request->getFiles(); + if (!empty($allFiles['claim_files'])) { + $candidates[] = $allFiles['claim_files']; + } + + foreach ($candidates as $candidate) { + foreach ($this->flattenUploadedFiles($candidate) as $uploadedFile) { + if (!$this->isValidUploadFile($uploadedFile)) { + continue; + } + + // Deduplicate by temp path (same file reference can appear in multiple sources). + $filesToProcess[$uploadedFile->getTempName()] = $uploadedFile; + } + } + + return array_values($filesToProcess); + } + + /** + * Recursively extract UploadedFile instances from nested upload arrays. + * + * @param mixed $files + * @return list<\CodeIgniter\HTTP\Files\UploadedFile> + */ + private function flattenUploadedFiles($files): array + { + if ($files instanceof \CodeIgniter\HTTP\Files\UploadedFile) { + return [$files]; + } + + if (!is_array($files)) { + return []; + } + + $result = []; + foreach ($files as $file) { + $result = array_merge($result, $this->flattenUploadedFiles($file)); + } + + return $result; } private function isValidUploadFile($uploadedFile): bool @@ -548,22 +584,27 @@ class ClaimController extends ResourceController foreach ($filesToProcess as $file) { try { - $storedName = time() . '_' . $file->getRandomName(); + $clientName = $file->getClientName(); + $clientExt = $file->getClientExtension(); + $clientMime = $file->getClientMimeType(); + $storedName = $file->getRandomName(); if (!$file->move($uploadPath, $storedName)) { $result['errors'][] = $file->getErrorString() ?: 'Unable to move uploaded file'; continue; } - if (!$this->ClaimFilesModel->insert([ + $inserted = $this->ClaimFilesModel->insert([ 'claim_id' => $claimId, - 'file_name' => $file->getClientName() ?: $storedName, + 'file_name' => $clientName ?: $storedName, 'file_path' => self::CLAIM_UPLOAD_DIR . $storedName, - 'file_extension' => $file->getClientExtension(), - 'file_mime_type' => $file->getClientMimeType(), + 'file_extension' => $clientExt, + 'file_mime_type' => $clientMime, 'is_active' => 1, 'created_by' => $createdBy, - ])) { + ]); + + if ($inserted === false) { if (is_file($uploadPath . $storedName)) { unlink($uploadPath . $storedName); } From bea9f03013b56f4a377a734dbb0990de05686861 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Mon, 1 Jun 2026 11:26:16 +0530 Subject: [PATCH 3/7] FIX_CLAIM_FILE_UPLOAD_2 --- app/Controllers/ClaimController.php | 87 ++++++++++------------------- 1 file changed, 28 insertions(+), 59 deletions(-) diff --git a/app/Controllers/ClaimController.php b/app/Controllers/ClaimController.php index 6e8b551..084cec2 100644 --- a/app/Controllers/ClaimController.php +++ b/app/Controllers/ClaimController.php @@ -503,59 +503,33 @@ class ClaimController extends ResourceController private function collectClaimUploadFiles(): array { $filesToProcess = []; - $candidates = []; - + + // getFileMultiple() works when input name is claim_files[] $multiple = $this->request->getFileMultiple('claim_files'); - if (!empty($multiple)) { - $candidates[] = $multiple; - } - - $single = $this->request->getFile('claim_files'); - if ($single !== null) { - $candidates[] = $single; - } - - $allFiles = $this->request->getFiles(); - if (!empty($allFiles['claim_files'])) { - $candidates[] = $allFiles['claim_files']; - } - - foreach ($candidates as $candidate) { - foreach ($this->flattenUploadedFiles($candidate) as $uploadedFile) { - if (!$this->isValidUploadFile($uploadedFile)) { - continue; + + if (!empty($multiple) && is_array($multiple)) { + foreach ($multiple as $uploadedFile) { + if ($this->isValidUploadFile($uploadedFile)) { + $filesToProcess[] = $uploadedFile; } - - // Deduplicate by temp path (same file reference can appear in multiple sources). - $filesToProcess[$uploadedFile->getTempName()] = $uploadedFile; } + return $filesToProcess; } - - return array_values($filesToProcess); - } - - /** - * Recursively extract UploadedFile instances from nested upload arrays. - * - * @param mixed $files - * @return list<\CodeIgniter\HTTP\Files\UploadedFile> - */ - private function flattenUploadedFiles($files): array - { - if ($files instanceof \CodeIgniter\HTTP\Files\UploadedFile) { - return [$files]; + + // Fallback: getFile() may return an array of files in some CI4 versions + $single = $this->request->getFile('claim_files'); + + if (is_array($single)) { + foreach ($single as $uploadedFile) { + if ($this->isValidUploadFile($uploadedFile)) { + $filesToProcess[] = $uploadedFile; + } + } + } elseif ($this->isValidUploadFile($single)) { + $filesToProcess[] = $single; } - - if (!is_array($files)) { - return []; - } - - $result = []; - foreach ($files as $file) { - $result = array_merge($result, $this->flattenUploadedFiles($file)); - } - - return $result; + + return $filesToProcess; } private function isValidUploadFile($uploadedFile): bool @@ -584,27 +558,22 @@ class ClaimController extends ResourceController foreach ($filesToProcess as $file) { try { - $clientName = $file->getClientName(); - $clientExt = $file->getClientExtension(); - $clientMime = $file->getClientMimeType(); - $storedName = $file->getRandomName(); + $storedName = time() . '_' . $file->getRandomName(); if (!$file->move($uploadPath, $storedName)) { $result['errors'][] = $file->getErrorString() ?: 'Unable to move uploaded file'; continue; } - $inserted = $this->ClaimFilesModel->insert([ + if (!$this->ClaimFilesModel->insert([ 'claim_id' => $claimId, - 'file_name' => $clientName ?: $storedName, + 'file_name' => $file->getClientName() ?: $storedName, 'file_path' => self::CLAIM_UPLOAD_DIR . $storedName, - 'file_extension' => $clientExt, - 'file_mime_type' => $clientMime, + 'file_extension' => $file->getClientExtension(), + 'file_mime_type' => $file->getClientMimeType(), 'is_active' => 1, 'created_by' => $createdBy, - ]); - - if ($inserted === false) { + ])) { if (is_file($uploadPath . $storedName)) { unlink($uploadPath . $storedName); } From 28f6f4b9f80f7f3532688d72619f2eec83b765e9 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Mon, 1 Jun 2026 12:34:52 +0530 Subject: [PATCH 4/7] FEAT_POLICY_FROM_AND_CLAIM_NUMBER_HANDLE --- app/Controllers/ClaimController.php | 28 ++++++++++++++++------------ app/Models/ClaimModel.php | 2 ++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/Controllers/ClaimController.php b/app/Controllers/ClaimController.php index 084cec2..b9428f0 100644 --- a/app/Controllers/ClaimController.php +++ b/app/Controllers/ClaimController.php @@ -145,23 +145,25 @@ class ClaimController extends ResourceController try { $reqData = $this->request->getPost(); - if (empty($reqData['policy_number']) || empty($reqData['claim_type'])) { + if (empty($reqData['policy_number']) || empty($reqData['claim_type']) || empty($reqData['policy_from'])) { return $this->respond([ 'status' => 'failed', 'code' => 400, - 'data' => 'policy_number and claim_type are required', + 'data' => 'policy_number, claim_type and policy_from are required', ], 400); } - $policy = $this->PolicyModel - ->select('partner_policy.*, Q.insurer_id, E.mobile as client_mobile, E.email as client_email, E.broker_id') - ->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') - ->where('partner_policy.policy_number', $reqData['policy_number']) - ->first(); + if($reqData['policy_from'] === 'Internal') { + $policy = $this->PolicyModel + ->select('partner_policy.*, Q.insurer_id, E.mobile as client_mobile, E.email as client_email, E.broker_id') + ->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') + ->where('partner_policy.policy_number', $reqData['policy_number']) + ->first(); - if (empty($policy)) { - return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'Policy not found'], 404); + if (empty($policy)) { + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'Policy not found'], 404); + } } $status = $this->ClaimStatusModel @@ -176,8 +178,10 @@ class ClaimController extends ResourceController $claimData = [ 'claim_status_id' => $reqData['claim_status_id'] ?? $status['id'], - 'policy_id' => $policy['id'], - 'policy_no' => $policy['policy_number'], + 'policy_id' => $policy['id'] ?? null, + 'policy_no' => $policy['policy_number'] ?? null, + 'claim_number' => $reqData['claim_number'] ?? null, + 'policy_from' => $reqData['policy_from'], 'insurer_id' => $policy['insurer_id'] ?? null, 'broker_id' => $reqData['broker_id'] ?? $policy['broker_id'] ?? null, 'insured_name' => $reqData['insured_name'] ?? $policy['insured_name'] ?? null, diff --git a/app/Models/ClaimModel.php b/app/Models/ClaimModel.php index 862030e..2e27d42 100644 --- a/app/Models/ClaimModel.php +++ b/app/Models/ClaimModel.php @@ -36,6 +36,8 @@ class ClaimModel extends Model 'is_active', 'created_by', 'updated_by', + 'claim_number', + 'policy_from', ]; // Auto timestamps From 2eb2c589151b908c2eb6a561d2bf40c3e964bb5f Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Mon, 1 Jun 2026 12:43:22 +0530 Subject: [PATCH 5/7] FIX_POLICY_NO_AND_INSURER_NOT_SAVE_ISSUE --- app/Controllers/ClaimController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controllers/ClaimController.php b/app/Controllers/ClaimController.php index b9428f0..7dc6d2c 100644 --- a/app/Controllers/ClaimController.php +++ b/app/Controllers/ClaimController.php @@ -179,10 +179,10 @@ class ClaimController extends ResourceController $claimData = [ 'claim_status_id' => $reqData['claim_status_id'] ?? $status['id'], 'policy_id' => $policy['id'] ?? null, - 'policy_no' => $policy['policy_number'] ?? null, + 'policy_no' => $policy['policy_number'] ?? $reqData['policy_number'] ?? null, 'claim_number' => $reqData['claim_number'] ?? null, 'policy_from' => $reqData['policy_from'], - 'insurer_id' => $policy['insurer_id'] ?? null, + 'insurer_id' => $policy['insurer_id'] ?? $reqData['insurer_id'] ?? null, 'broker_id' => $reqData['broker_id'] ?? $policy['broker_id'] ?? null, 'insured_name' => $reqData['insured_name'] ?? $policy['insured_name'] ?? null, 'mobile' => $reqData['mobile'] ?? $policy['client_mobile'] ?? null, From cc579a9a77f3bacaf77c0014865b74e09119ca1f Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Mon, 1 Jun 2026 15:07:12 +0530 Subject: [PATCH 6/7] FEAT_REG_NO --- app/Controllers/ClaimController.php | 19 +++++++++++++++---- app/Models/ClaimModel.php | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/Controllers/ClaimController.php b/app/Controllers/ClaimController.php index 7dc6d2c..7e8722d 100644 --- a/app/Controllers/ClaimController.php +++ b/app/Controllers/ClaimController.php @@ -64,7 +64,7 @@ class ClaimController extends ResourceController $to_date = $this->request->getGet('to_date'); $builder = $this->db->table('partner_claims pc') - ->select('pc.*, + ->select("pc.*, i.name as insurer_name, i.short_name as insurer_short_name, pct.claim_type as claim_type_value, @@ -73,7 +73,12 @@ class ClaimController extends ResourceController tcs.claim_status as claim_status_value, pp.start_date as policy_start_date, pp.end_date as policy_end_date, - pp.rc_no as reg_no') + pp.rc_no as reg_no, + CASE + WHEN pc.reg_no IS NULL OR pc.reg_no = '' THEN pp.rc_no + ELSE pc.reg_no + END AS reg_no + ") ->join('insurers i', 'i.id = pc.insurer_id', 'left') ->join('partner_claim_type_master pct', 'pct.id = pc.claim_type', 'left') ->join('partner_agent pa', 'pa.id = pc.agent_id', 'left') @@ -200,6 +205,7 @@ class ClaimController extends ResourceController 'remark' => $reqData['remark'] ?? null, 'is_active' => 1, 'created_by' => $reqData['created_by'] ?? null, + 'reg_no' => $reqData['reg_no'] ?? null, ]; $this->db->transStart(); @@ -352,7 +358,7 @@ class ClaimController extends ResourceController } $claim = $this->db->table('partner_claims pc') - ->select('pc.*, + ->select("pc.*, i.name as insurer_name, i.short_name as insurer_short_name, pct.claim_type as claim_type_value, @@ -361,7 +367,12 @@ class ClaimController extends ResourceController tcs.claim_status as claim_status_value, pp.start_date as policy_start_date, pp.end_date as policy_end_date, - v.vehicle_no as reg_no') + + CASE + WHEN pc.reg_no IS NULL OR pc.reg_no = '' THEN v.vehicle_no + ELSE pc.reg_no + END AS reg_no + ") ->join('insurers i', 'i.id = pc.insurer_id', 'left') ->join('partner_claim_type_master pct', 'pct.id = pc.claim_type', 'left') ->join('partner_agent pa', 'pa.id = pc.agent_id', 'left') diff --git a/app/Models/ClaimModel.php b/app/Models/ClaimModel.php index 2e27d42..b779be0 100644 --- a/app/Models/ClaimModel.php +++ b/app/Models/ClaimModel.php @@ -38,6 +38,7 @@ class ClaimModel extends Model 'updated_by', 'claim_number', 'policy_from', + 'reg_no', ]; // Auto timestamps From b5512ee2ada3ad8ec6e42e3739840655af3e2c96 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Tue, 2 Jun 2026 10:51:26 +0530 Subject: [PATCH 7/7] FIX_UPDATE_API --- app/Controllers/ClaimController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Controllers/ClaimController.php b/app/Controllers/ClaimController.php index 7e8722d..77b260f 100644 --- a/app/Controllers/ClaimController.php +++ b/app/Controllers/ClaimController.php @@ -284,6 +284,7 @@ class ClaimController extends ResourceController 'workshop_surveyor_contact', 'remark', 'is_active', + 'policy_from', ]; foreach ($allowedUpdateFields as $field) { @@ -316,6 +317,12 @@ class ClaimController extends ResourceController $updateData['updated_by'] = $reqData['updated_by']; } + if($reqData['policy_from'] === 'External') { + $updateData['reg_no'] = $reqData['reg_no'] ?? null; + $updateData['claim_number'] = $reqData['claim_number'] ?? null; + $updateData['policy_no'] = $reqData['policy_number'] ?? null; + } + if (!empty($updateData) && !$this->ClaimModel->update((int) $claimId, $updateData)) { return $this->respond(['status' => 'failed', 'code' => 422, 'data' => $this->ClaimModel->errors()], 422); }