From 9895cb618186d378f339239dcc6d29b82ea644a0 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Mon, 13 Jul 2026 16:00:34 +0530 Subject: [PATCH] FIX_GPA_TPA_ISSUE --- app/Controllers/ClientController.php | 16 ++++++++-------- app/Views/client_policy.php | 8 +++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index b56714a0..d64146ee 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -2994,20 +2994,20 @@ class ClientController extends AdminController $base_policy = $sanitized_post_data['base_policy'] ?? null; - $insurerValue = (string) $sanitized_post_data['insurer'] ?? null; + $insurerValue = (string) ($sanitized_post_data['insurer'] ?? ''); list($insurerBranchId, $insurerId) = explode('-', $insurerValue); $sanitized_post_data['insurer_branch_id'] = $insurerBranchId; $sanitized_post_data['insurer_id'] = $insurerId; - $tpaValue = (string) $sanitized_post_data['tpa'] ?? null; + $tpaValue = (string) ($sanitized_post_data['tpa'] ?? ''); - if ($tpaValue === null || $tpaValue === '') { + if ($tpaValue === '') { $tpaBranchId = null; $tpaId = null; } else { - list($tpaBranchId, $tpaId) = explode('-', $tpaValue); + list($tpaBranchId, $tpaId) = array_pad(explode('-', $tpaValue, 2), 2, null); } @@ -3197,15 +3197,15 @@ class ClientController extends AdminController $base_policy = $sanitized_post_data['base_policy'] ?? null; - $insurerValue = (string) $sanitized_post_data['insurer']; + $insurerValue = (string) ($sanitized_post_data['insurer'] ?? ''); list($insurerBranchId, $insurerId) = explode('-', $insurerValue); $sanitized_post_data['insurer_branch_id'] = $insurerBranchId ?? null; $sanitized_post_data['insurer_id'] = $insurerId ?? null; - $tpaValue = (string) $sanitized_post_data['tpa'] ?? null; - if (!empty($tpaValue) || $tpaValue !== '') { - list($tpaBranchId, $tpaId) = explode('-', $tpaValue); + $tpaValue = (string) ($sanitized_post_data['tpa'] ?? ''); + if ($tpaValue !== '') { + list($tpaBranchId, $tpaId) = array_pad(explode('-', $tpaValue, 2), 2, null); } else { $tpaBranchId = null; $tpaId = null; diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 5b54fbe1..dd898b7a 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -751,6 +751,8 @@ input:checked + .slider_blue::before { $('.loader-mask').fadeIn(); var formData = new FormData($('#policy_form')[0]); + // TPA is optional for GPA and some other policy types; ensure the key is always posted + formData.set('tpa', $('#tpa').val() || ''); ['policy_start_date', 'policy_end_date', 'open_date', 'close_date'].forEach(function(fieldName) { var val = formData.get(fieldName); if (val) { @@ -2056,7 +2058,11 @@ input:checked + .slider_blue::before { if(res.status == true){ $('#insurer').val(res.data.insurer_branch_id + '-' + res.data.insurer_id).change(); - $('#tpa').val(res.data.tpa_branch_id + '-' + res.data.tpa_id).change(); + var baseTpaValue = ''; + if (res.data.tpa_branch_id && res.data.tpa_id) { + baseTpaValue = res.data.tpa_branch_id + '-' + res.data.tpa_id; + } + $('#tpa').val(baseTpaValue).change(); $('#policy_no').val(res.data.policy_no).change(); // $('#open_date').val(rearrangeDateFormat(res.data.open_date)).change(); // $('#close_date').val(rearrangeDateFormat(res.data.close_date)).change();