From 707d4710d9278741c86ccdb2684cbaaf3ba5531d Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 4 Aug 2025 14:22:16 +0530 Subject: [PATCH] CHANGE_ENROLLMENT_FILE_UPLOAD_CR : RV --- app/Controllers/ClientController.php | 9 + app/Controllers/EmpDataServiceController.php | 96 +- app/Controllers/EmployeeController.php | 3 +- app/Models/PolicyTransactionModel.php | 55 +- app/Views/batch_list.php | 4 +- app/Views/client_policy.php | 158 +- app/Views/insurer_basic_info.php | 2 +- app/Views/insurer_export_templete.php | 4 +- app/Views/insurer_onboarding.php | 2 +- app/Views/insurer_or_tpa_data.php | 85 +- app/Views/other_policy_terms.php | 1440 +++++++++-------- app/Views/policy_gmc_terms.php | 95 +- app/Views/policy_gpa_terms.php | 1236 +++++++------- app/Views/policy_grid.php | 3 +- .../policy_transaction_inception_form.php | 8 +- 15 files changed, 1787 insertions(+), 1413 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 39a0285e..bff1d34f 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -2557,6 +2557,7 @@ class ClientController extends AdminController // $data['special_condition_label'] = str_replace(',', '', $this->request->getPost("special_condition_label")) ?? []; // $data['special_condition_input'] = str_replace(',', '', $this->request->getPost("special_condition_input")) ?? []; // $data['multiple_sum_insured'] = str_replace(',', '', $this->request->getPost("multiple_sum_insured")) ?? []; + $fields = [ 'waiverofpreexistingdiseases' => false, 'waiverof1,2,3&4thyearexclusions' => false, @@ -2611,6 +2612,8 @@ class ClientController extends AdminController if ($value !== null && $value !== '') { $data[$field] = $needsCleanup ? str_replace(',', '', $value) : $value; + }else{ + $data[$field] = $value; } } @@ -2877,6 +2880,8 @@ class ClientController extends AdminController try { $this->myLogger->logme('error', 'Policy GPA Terms CREATE function called'); + // print_r($this->request->getPost()); die; + /*** Client Policy Table Primary Key(ID) ***/ $client_policy_id = $this->request->getPost("client_policy_id"); @@ -2948,6 +2953,8 @@ class ClientController extends AdminController $value = $this->request->getPost($field); if ($value !== null) { $data[$field] = str_replace(',', '', $value); + }else{ + $data[$field] = $value; } } @@ -2956,6 +2963,8 @@ class ClientController extends AdminController $value = $this->request->getPost($field); if ($value !== null) { $data[$field] = $value; + }else{ + $data[$field] = $value; } } diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 9d3eeecf..6da138fd 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -199,13 +199,21 @@ class EmpDataServiceController extends BaseController $totals = round($totals, 2); - if($export_data['insurer_or_tpa'] == 'insurer') //check CD amt related issue for only insurer, not tpa + //check CD amt insufficient only insurer, not tpa // DO NOT REMOVE THIS + if($export_data['insurer_or_tpa'] == 'insurer') { if (!empty($cash_balance)) { if ((int) $cash_balance['balance'] < (int) $totals) { $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.'); $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount. CASH BALANCE : {balance} and TOTAL AMOUNT : {total}', ['balance' => $cash_balance['balance'], 'total' => $totals]); - return 0; + session()->set('cd_balance', false); + session()->set('cd_amount', $cash_balance['balance']); + session()->set('excel_file_amt', $totals); + }else{ + session()->set('cd_balance', true); + session()->set('cd_amount', $cash_balance['balance']); + session()->set('excel_file_amt', $totals); + } } } @@ -700,13 +708,21 @@ class EmpDataServiceController extends BaseController // echo '
';
         // print_r($ids); die;
 
-        if($export_data['insurer_or_tpa'] == 'insurer') //check CD amt related issue for only insurer, not tpa
+        //check CD amt insufficiend for only insurer, not tpa // DO NOT REMOVE THIS
+        if($export_data['insurer_or_tpa'] == 'insurer')
         {
             if (!empty($cash_balance)) {
                 if ((int) $cash_balance['balance']  < (int) $rounded_totals) {
                     $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.');
                     $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.  CASH BALANCE : {balance}  and  TOTAL AMOUNT : {total}', ['balance' => $cash_balance['balance'], 'total' => $totals]);
-                    return 0;
+                    session()->set('cd_balance', false);
+                    session()->set('cd_amount', $cash_balance['balance']);
+                    session()->set('excel_file_amt', $rounded_totals);
+                }else{
+                    session()->set('cd_balance', true);
+                    session()->set('cd_amount', $cash_balance['balance']);
+                    session()->set('excel_file_amt', $rounded_totals);
+
                 }
             }
         }
@@ -1003,22 +1019,29 @@ class EmpDataServiceController extends BaseController
                 $cash_balance['balance'] = $balance['opening_bal'];
             }
 
+            // Calculate the total amount from the objects
+            $totals = 0;
+            foreach ($inceptionData as $item) {
+                $totals =  $totals + $item->total;
+            }
 
-            
-                // Calculate the total amount from the objects
-                $totals = 0;
-                foreach ($inceptionData as $item) {
-                    $totals =  $totals + $item->total;
-                }
              $totals = round($totals, 2);
             
-            if($export_data['insurer_or_tpa'] != 'tpa')// check overal emp premium amt with cd balance only for insurer export, not tpa export
+            
+             if($export_data['insurer_or_tpa'] != 'tpa')// check overal emp premium amt with cd balance only for insurer export, not tpa export
             { 
                 if (!empty($cash_balance)) {
                     if ((int) $cash_balance['balance']  < (int) $totals) {
                         $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.');
                         $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.  CASH BALANCE : {balance}  and  TOTAL AMOUNT : {total}', ['balance' => $cash_balance['balance'], 'total' => $totals]);
-                        return 0;
+                        session()->set('cd_balance', false);
+                        session()->set('cd_amount', $cash_balance['balance']);
+                        session()->set('excel_file_amt', $totals);
+                    }else{
+                        session()->set('cd_balance', true);
+                        session()->set('cd_amount', $cash_balance['balance']);
+                        session()->set('excel_file_amt', $totals);
+
                     }
                 }
             }
@@ -1359,6 +1382,8 @@ class EmpDataServiceController extends BaseController
         $batch_code = $file['batch_code'];
         $user_id = $file['created_by'];
 
+        $client_policy_data = $this->clientPolicyModel->where('id', $client_policy_id)->first();
+
         $insurer_or_tpa = $file['insurer_or_tpa'];
         if ($insurer_or_tpa == 'tpa') {
             $id = 'tpa_id';
@@ -1516,37 +1541,40 @@ class EmpDataServiceController extends BaseController
 
             //--- TPA ID Duplicate check start ---
 
-            $current_tpa_id = $excel_data[$key][13];
+            // Duplicate checking for only GMC's and GPA
+            if(in_array($client_policy_data['policy_type_id'], [1,2,3,4,5])){
+                $current_tpa_id = $excel_data[$key][13];
 
-            if (isset($tpa_id_all[$current_tpa_id])) {
+                if (isset($tpa_id_all[$current_tpa_id])) {
 
-                // Add the current row to errors
-                $errors[$key][] = [
-                    'row' => $key,
-                    'column' => 13,
-                    'db_data' => "Duplicate TPA ID Found",
-                    'excel_data' => $current_tpa_id
-                ];
-            
-                // Add all existing rows with the same TPA ID to errors
-                foreach ($tpa_id_all[$current_tpa_id] as $existing_row) {
-                    $errors[$existing_row][] = [
-                        'row' => $existing_row,
+                    // Add the current row to errors
+                    $errors[$key][] = [
+                        'row' => $key,
                         'column' => 13,
                         'db_data' => "Duplicate TPA ID Found",
                         'excel_data' => $current_tpa_id
                     ];
-                }
+                
+                    // Add all existing rows with the same TPA ID to errors
+                    foreach ($tpa_id_all[$current_tpa_id] as $existing_row) {
+                        $errors[$existing_row][] = [
+                            'row' => $existing_row,
+                            'column' => 13,
+                            'db_data' => "Duplicate TPA ID Found",
+                            'excel_data' => $current_tpa_id
+                        ];
+                    }
 
-            } else {
-                if($current_tpa_id != "" && $current_tpa_id != null){
-                    $tpa_id_all[$current_tpa_id][] = $key;
-                }            
+                } else {
+                    if($current_tpa_id != "" && $current_tpa_id != null){
+                        $tpa_id_all[$current_tpa_id][] = $key;
+                    }            
+                }
             }
             
             //--- TPA ID Duplicate check end ---
 
-            if ($insurer_or_tpa == 'tpa') {
+            if ($insurer_or_tpa == 'tpa' && in_array($client_policy_data['policy_type_id'], [1,2,3,4,5])) {
 
                 if ($excel_data[$key][13] === null) {
                     $missing_id[$key][] = [
@@ -1688,7 +1716,7 @@ class EmpDataServiceController extends BaseController
                 ];
             }
 
-            if ($insurer_or_tpa == 'tpa') {
+            if ($insurer_or_tpa == 'tpa' && in_array($client_policy_data['policy_type_id'], [1,2,3,4,5])) {
 
                 if ($emp_value['uhid'] != $excel_data[$key][14]) {
                     $errors[$key][] = [
@@ -1699,7 +1727,7 @@ class EmpDataServiceController extends BaseController
                     ];
                 }
 
-            } else if ($insurer_or_tpa == 'insurer') {
+            } else if ($insurer_or_tpa == 'insurer' && in_array($client_policy_data['policy_type_id'], [1,2,3,4,5])) {
 
                  if ($emp_value['tpa_id'] != $excel_data[$key][13]) {
                     $errors[$key][] = [
diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php
index 97a71e4c..dd80cd05 100755
--- a/app/Controllers/EmployeeController.php
+++ b/app/Controllers/EmployeeController.php
@@ -305,7 +305,8 @@ class EmployeeController extends AdminController
         $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement'];
         // $data['actions'] = ['inception' => 'Inception (Employee + Dependents)',  'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement','enrollment' => 'Enrolment'];
         
-        $data['import_or_export'] = ['import' => 'Import', 'export' => 'Export'];
+        // $data['import_or_export'] = ['import' => 'Import', 'export' => 'Export'];
+        $data['import_or_export'] = ['import' => 'Upload', 'export' => 'Download'];
         $data['insurer_or_tpa'] = ['insurer' => 'Insurer', 'tpa' => 'TPA'];
 
         // $data['fileList'] = $this->fileModel
diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php
index 5eabf684..ba9b2fcd 100644
--- a/app/Models/PolicyTransactionModel.php
+++ b/app/Models/PolicyTransactionModel.php
@@ -765,7 +765,12 @@ class PolicyTransactionModel extends Model
                 ), 
                 2
                 ) AS unbilled_amt,
-                 created_user.first_name as user_name
+                 created_user.first_name as user_name,
+                CASE 
+                    WHEN `pt_co_share_details`.`co_share_type` IN (0, 1) THEN `policy_transaction`.`policy_no`
+                    WHEN `pt_co_share_details`.`co_share_type` > 1 THEN `pt_co_share_details`.`follower_policy_no`
+                    ELSE `policy_transaction`.`policy_no` -- Default fallback
+                END AS `policy_no`
 
             ")
             ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left')
@@ -986,7 +991,12 @@ class PolicyTransactionModel extends Model
                 pt_co_share_details.tp_amt AS tp,
                 clients.pan,
                 DATE_FORMAT(policy_transaction.created_at, '%d %b %Y %h:%i %p') AS created_at,
-                user_profiles.first_name as user_name
+                user_profiles.first_name as user_name,
+                CASE 
+                    WHEN `pt_co_share_details`.`co_share_type` IN (0, 1) THEN `policy_transaction`.`policy_no`
+                    WHEN `pt_co_share_details`.`co_share_type` > 1 THEN `pt_co_share_details`.`follower_policy_no`
+                    ELSE `policy_transaction`.`policy_no` -- Default fallback
+                END AS `policy_no`
             ")
             ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left')
             ->join('clients', 'clients.id = policy_transaction.client_id', 'left')
@@ -1049,8 +1059,8 @@ class PolicyTransactionModel extends Model
 
         // Optimize Query Execution
         $builder->orderBy('policy_transaction.id', 'desc');
-
-        return $builder->get()->getResultArray();
+        $data = $builder->get()->getResultArray();
+        return $data;
     }
 
 
@@ -1065,7 +1075,12 @@ class PolicyTransactionModel extends Model
                     client_branch.branch_name as client_branch_name,
                     insurers.name AS insurer_name,
                     insurers.short_name AS insurer_short_name,
-                    policy_type.policy_type 
+                    policy_type.policy_type ,
+                    CASE 
+                        WHEN `pt_co_share_details`.`co_share_type` IN (0, 1) THEN `policy_transaction`.`policy_no`
+                        WHEN `pt_co_share_details`.`co_share_type` > 1 THEN `pt_co_share_details`.`follower_policy_no`
+                        ELSE `policy_transaction`.`policy_no` -- Default fallback
+                    END AS `policy_no`
                 ')
             ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left')
             ->join('clients', 'policy_transaction.client_id = clients.id', 'left')
@@ -1228,7 +1243,12 @@ class PolicyTransactionModel extends Model
                             AND co_share_stmt_details.is_active = 1
                     ),
                     2
-                ) AS variance_amt
+                ) AS variance_amt,
+                CASE 
+                    WHEN `pt_co_share_details`.`co_share_type` IN (0, 1) THEN `policy_transaction`.`policy_no`
+                    WHEN `pt_co_share_details`.`co_share_type` > 1 THEN `pt_co_share_details`.`follower_policy_no`
+                    ELSE `policy_transaction`.`policy_no` -- Default fallback
+                END AS `policy_no`
 
 
             ")
@@ -1317,7 +1337,6 @@ class PolicyTransactionModel extends Model
                 'clients.client_name',
                 'insurers.name AS insurer_name',
                 'policy_type.policy_type',
-                'policy_transaction.policy_no',
                 'policy_transaction.endorsement_no',
                 "CASE
                     WHEN policy_transaction.action_type = 'inception' THEN 'I'
@@ -1327,7 +1346,12 @@ class PolicyTransactionModel extends Model
                 'pt_co_share_details.bp_amt',
                 'pt_co_share_details.tp_amt',
                 'pt_co_share_details.tep_amt',
-                'policy_transaction.status'
+                'policy_transaction.status',
+                'CASE 
+                    WHEN `pt_co_share_details`.`co_share_type` IN (0, 1) THEN `policy_transaction`.`policy_no`
+                    WHEN `pt_co_share_details`.`co_share_type` > 1 THEN `pt_co_share_details`.`follower_policy_no`
+                    ELSE `policy_transaction`.`policy_no` -- Default fallback
+                END AS `policy_no`'
             ])
             ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left')
             ->join('clients', 'clients.id = policy_transaction.client_id', 'left')
@@ -1417,7 +1441,12 @@ class PolicyTransactionModel extends Model
                 policy_transaction.action_type AS action_type_full,
                 pt_co_share_details.exp_amt,
                 pt_co_share_details.variance,
-                policy_transaction.status
+                policy_transaction.status,
+                CASE 
+                    WHEN `pt_co_share_details`.`co_share_type` IN (0, 1) THEN `policy_transaction`.`policy_no`
+                    WHEN `pt_co_share_details`.`co_share_type` > 1 THEN `pt_co_share_details`.`follower_policy_no`
+                    ELSE `policy_transaction`.`policy_no` -- Default fallback
+                END AS `policy_no`
             ")
             ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left')
             ->join('clients', 'clients.id = policy_transaction.client_id', 'left')
@@ -1490,7 +1519,6 @@ class PolicyTransactionModel extends Model
                 clients.client_name,
                 insurers.name AS insurer_name,
                 policy_type.policy_type,
-                policy_transaction.policy_no,
                 policy_transaction.endorsement_no,
                 CASE
                     WHEN policy_transaction.action_type = 'inception' THEN 'I'
@@ -1525,7 +1553,12 @@ class PolicyTransactionModel extends Model
                         inv_payment_details.statement_id = insurer_statements.id
                         AND inv_payment_details.is_active = 1
                     ),
-                2) AS outstanding_amount
+                2) AS outstanding_amount,
+                CASE 
+                    WHEN `pt_co_share_details`.`co_share_type` IN (0, 1) THEN `policy_transaction`.`policy_no`
+                    WHEN `pt_co_share_details`.`co_share_type` > 1 THEN `pt_co_share_details`.`follower_policy_no`
+                    ELSE `policy_transaction`.`policy_no` -- Default fallback
+                END AS `policy_no`
             ")
             ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left')
             ->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id', 'left')
diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php
index f1a623fe..c754ecc0 100755
--- a/app/Views/batch_list.php
+++ b/app/Views/batch_list.php
@@ -62,8 +62,8 @@
                             
                              - 
                             
-                            
-                            
+                            
+                            
                             
 
                             
diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php
index f218a241..e59e467d 100755
--- a/app/Views/client_policy.php
+++ b/app/Views/client_policy.php
@@ -1,5 +1,26 @@
-
+ + +
Saved
+
@@ -7,9 +28,8 @@
- - - +
+ @@ -198,6 +218,7 @@ + @@ -237,8 +258,7 @@ - \ No newline at end of file diff --git a/app/Views/insurer_basic_info.php b/app/Views/insurer_basic_info.php index 524f2604..88628771 100755 --- a/app/Views/insurer_basic_info.php +++ b/app/Views/insurer_basic_info.php @@ -89,7 +89,7 @@ input:checked + .slider:before { > - +
diff --git a/app/Views/insurer_export_templete.php b/app/Views/insurer_export_templete.php index 1ef280c2..5a1b93ce 100755 --- a/app/Views/insurer_export_templete.php +++ b/app/Views/insurer_export_templete.php @@ -80,7 +80,7 @@
- + @@ -92,7 +92,7 @@ - +
Insurer Policy S.NO Policy Type Event TypeImport/ExportUpload/Download Template Action
-
+ -
+