From 21594469bc8462283f6007f5587810d66f1d61cc Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Sat, 16 May 2026 10:20:36 +0530 Subject: [PATCH] FIX_ISSUE --- app/Controllers/LeadsController.php | 126 ++++++++++++++-------------- 1 file changed, 64 insertions(+), 62 deletions(-) diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 06876db1..7f347d6f 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -571,69 +571,71 @@ class LeadsController extends BaseController } - // $leadFormType = (int) ($postData['lead_form_type'] ?? 1); - // $postedPolicyTypeIds = array_map('intval', (array) ($postData['policy_type_id'] ?? [])); - // $isEbRenewalGpaClaimHistory = $leadFormType === 1 - // && (int) ($postData['lead_type'] ?? 0) === 2 - // && in_array(1, $postedPolicyTypeIds, true) - // && (int) ($postData['claim_history'] ?? 0) === 1; + $leadFormType = (int) ($postData['lead_form_type'] ?? 1); + $postedPolicyTypeIds = array_map('intval', (array) ($postData['policy_type_id'] ?? [])); + $claimHistoryPolicyTypes = [1, 6, 7]; + $hasClaimHistoryPolicy = count(array_intersect($postedPolicyTypeIds, $claimHistoryPolicyTypes)) > 0; + $isEbClaimHistory = $leadFormType === 1 + && in_array((int) ($postData['lead_type'] ?? 0), [2, 3], true) + && $hasClaimHistoryPolicy + && (int) ($postData['claim_history'] ?? 0) === 1; - // if ($isEbRenewalGpaClaimHistory) { - // $rules['first_year.*'] = [ - // 'rules' => 'required|regex_match[/^\d{4}-\d{4}$/]', - // 'errors' => [ - // 'required' => 'Claim Year is required for all entries.', - // 'regex_match' => 'Year must be in format YYYY-YYYY.', - // ], - // ]; - // $rules['emp_id.*'] = [ - // 'rules' => 'required', - // 'errors' => ['required' => 'Employee ID is required in Claim History.'], - // ]; - // $rules['emp_name.*'] = [ - // 'rules' => 'required', - // 'errors' => ['required' => 'Employee Name is required in Claim History.'], - // ]; - // $rules['gender.*'] = [ - // 'rules' => 'required|in_list[Female,Male]', - // 'errors' => [ - // 'required' => 'Gender is required in Claim History.', - // 'in_list' => 'Gender must be Female or Male.', - // ], - // ]; - // $rules['designation.*'] = [ - // 'rules' => 'required', - // 'errors' => ['required' => 'Designation is required in Claim History.'], - // ]; - // $rules['sum_insured.*'] = [ - // 'rules' => 'required|numeric', - // 'errors' => [ - // 'required' => 'Sum Insured is required in Claim History.', - // 'numeric' => 'Sum Insured must be a number.', - // ], - // ]; - // $rules['first_death_date.*'] = [ - // 'rules' => 'required|regex_match[/^[0-9]{2}-([0-9]{2}|[A-Za-z]{3})-[0-9]{4}$/]', - // 'errors' => [ - // 'required' => 'Date of Death is required.', - // 'regex_match' => 'Date of Death must be in DD-MM-YYYY or DD-MMM-YYYY format.', - // ], - // ]; - // $rules['first_cause_of_death.*'] = [ - // 'rules' => 'required|in_list[natural_death,suicide,accident,cardiac_arrest,septic_shock,heart_attack]', - // 'errors' => [ - // 'required' => 'Nature/Cause Of Death is required.', - // 'in_list' => 'Nature/Cause Of Death is invalid.', - // ], - // ]; - // $rules['first_claim_amount.*'] = [ - // 'rules' => 'required|numeric', - // 'errors' => [ - // 'required' => 'Claim/Settled Amount is required.', - // 'numeric' => 'Claim/Settled Amount must be a number.', - // ], - // ]; - // } + if ($isEbClaimHistory) { + $rules['first_year.*'] = [ + 'rules' => 'required|regex_match[/^\d{4}-\d{4}$/]', + 'errors' => [ + 'required' => 'Claim Year is required for all entries.', + 'regex_match' => 'Year must be in format YYYY-YYYY.', + ], + ]; + $rules['emp_id.*'] = [ + 'rules' => 'required', + 'errors' => ['required' => 'Employee ID is required in Claim History.'], + ]; + $rules['emp_name.*'] = [ + 'rules' => 'required', + 'errors' => ['required' => 'Employee Name is required in Claim History.'], + ]; + $rules['gender.*'] = [ + 'rules' => 'required|in_list[Female,Male]', + 'errors' => [ + 'required' => 'Gender is required in Claim History.', + 'in_list' => 'Gender must be Female or Male.', + ], + ]; + $rules['designation.*'] = [ + 'rules' => 'required', + 'errors' => ['required' => 'Designation is required in Claim History.'], + ]; + $rules['sum_insured.*'] = [ + 'rules' => 'required|numeric', + 'errors' => [ + 'required' => 'Sum Insured is required in Claim History.', + 'numeric' => 'Sum Insured must be a number.', + ], + ]; + $rules['first_death_date.*'] = [ + 'rules' => 'required|regex_match[/^[0-9]{2}-([0-9]{2}|[A-Za-z]{3})-[0-9]{4}$/]', + 'errors' => [ + 'required' => 'Date of Death is required.', + 'regex_match' => 'Date of Death must be in DD-MM-YYYY or DD-MMM-YYYY format.', + ], + ]; + $rules['first_cause_of_death.*'] = [ + 'rules' => 'required|in_list[natural_death,suicide,accident,cardiac_arrest,septic_shock,heart_attack]', + 'errors' => [ + 'required' => 'Nature/Cause Of Death is required.', + 'in_list' => 'Nature/Cause Of Death is invalid.', + ], + ]; + $rules['first_claim_amount.*'] = [ + 'rules' => 'required|numeric', + 'errors' => [ + 'required' => 'Claim/Settled Amount is required.', + 'numeric' => 'Claim/Settled Amount must be a number.', + ], + ]; + } // 1. MANUALLY VALIDATE FILES BEFORE PROCESSING // $allFiles = $this->request->getFiles();