From 02c16ed4ec1dd3780ce48bd9b495893318c010be Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Wed, 15 Oct 2025 18:07:52 +0530 Subject: [PATCH] CHANGE_BDS_REPORT_CHANGE : RV --- .../PolicyTransactionController.php | 68 ++++---- .../policy_transaction_endorsement_form.php | 61 ++++++-- .../policy_transaction_inception_form.php | 19 ++- app/Views/report_bds.php | 147 +++++++++++------- 4 files changed, 189 insertions(+), 106 deletions(-) diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 41499b5a..b8f21a84 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -113,7 +113,8 @@ class PolicyTransactionController extends BaseController // Policy Transaction Inception public function viewInception() - { + { + $bds_edit_pt_id = $this->request->getGet('pt_id') ?? null; $data['tab_name'] = 'Policy'; $data['page_name'] = 'Policy'; @@ -183,34 +184,38 @@ class PolicyTransactionController extends BaseController $issuer = empty($issuer) ? 0 : $issuer; $status = empty($status) ? 0 : $status; // Corrected from `$issuer` - if ($this->request->is('get')) { + if(empty($bds_edit_pt_id)){ + if ($this->request->is('get')) { - // Fetch inception data list - $data['inception_data_list'] = $this->policyTransactionModel->getInceptionTranctionListData( - $start_date, - $end_date, - $client_id, - $insurer_id, - $policy_type_id, - $date_type, - $issuer, - $status - ); - } else { + // Fetch inception data list + $data['inception_data_list'] = $this->policyTransactionModel->getInceptionTranctionListData( + $start_date, + $end_date, + $client_id, + $insurer_id, + $policy_type_id, + $date_type, + $issuer, + $status + ); + } else { - $ids = $this->request->getPost('ids'); - $ids = array_filter(explode(',', $ids)); - $data['inception_data_list'] = $this->policyTransactionModel->getInceptionTranctionListData( - $start_date = 0, - $end_date = 0, - $client_id = 0, - $insurer_id = 0, - $policy_type_id = 0, - $date_type = 0, - $issuer = 0, - $status = 0, - $ids - ); + $ids = $this->request->getPost('ids'); + $ids = array_filter(explode(',', $ids)); + $data['inception_data_list'] = $this->policyTransactionModel->getInceptionTranctionListData( + $start_date = 0, + $end_date = 0, + $client_id = 0, + $insurer_id = 0, + $policy_type_id = 0, + $date_type = 0, + $issuer = 0, + $status = 0, + $ids + ); + } + }else{ + $data['inception_data_list'] = []; } @@ -1087,7 +1092,7 @@ class PolicyTransactionController extends BaseController { // echo '
';
         // !dd($this->getEndorsementDataForEdit(17));
-
+        $bds_edit_pt_id = $this->request->getGet('pt_id') ?? null;
         $data['tab_name'] = 'Endorsement';
         $data['page_name'] = 'Endorsement';
         $data['issuer'] = [1 => 'JIBS', 2 => 'Nhance'];
@@ -1154,8 +1159,11 @@ class PolicyTransactionController extends BaseController
         $issuer = (!isset($issuer) || $issuer === '' || $issuer === null) ? 0 : $issuer;
         $status = (!isset($issuer) || $status === '' || $status === null) ? 0 : $status;
 
-
-        $data['endorsement_data_list'] = $this->policyTransactionModel->getEndorsementTranctionListData($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer, $status);
+        if($bds_edit_pt_id == null){
+            $data['endorsement_data_list'] = $this->policyTransactionModel->getEndorsementTranctionListData($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer, $status);
+        }else{
+            $data['endorsement_data_list'] = [];
+        }
         $data['client'] = $this->clientModel->where('is_active', 1)->findAll();
         $data['policy_types'] = $this->policyTypeModel->where('is_active', 1)->findAll();
 
diff --git a/app/Views/policy_transaction_endorsement_form.php b/app/Views/policy_transaction_endorsement_form.php
index 9701ac2c..2aabb115 100644
--- a/app/Views/policy_transaction_endorsement_form.php
+++ b/app/Views/policy_transaction_endorsement_form.php
@@ -545,6 +545,7 @@
     console.log(" role_id : ", role_id);
     var insurer_count_array = [];
     var pt_co_share_count_data = 0;
+    var redirect_url = '';
 
     $(document).ready(function(){
 
@@ -838,7 +839,7 @@
                 if (res.status == true) {
                     toastr.success(res.message, 'Success');
                     $('#policy_tranction_primarykey').val(res.pt_id);
-                    window.location.href = '';
+                    window.location.href = redirect_url;
                 } else {
                     toastr.error(res.message, 'Error');
                 }
@@ -2647,28 +2648,56 @@
 
     //-----------------------------------------------------------------------------------------------------------
 
-    function getURLParamsForReport() 
-    {   
-        console.log('getURLParamsForReport()  function called')
-        const url = new URL(window.location.href);
-        const params = new URLSearchParams(url.search);
-        const pt_id = params.get('pt_id') ?? 0
+    // function getURLParamsForReport() 
+    // {   
+    //     console.log('getURLParamsForReport()  function called')
+    //     const url = new URL(window.location.href);
+    //     const params = new URLSearchParams(url.search);
+    //     const pt_id = params.get('pt_id') ?? 0
 
-        console.log('policy tranction id ', pt_id);
+    //     console.log('policy tranction id ', pt_id);
         
-        if(pt_id != 0){
-            setTimeout(function(){
-                hide_list_show_add()
-                getPolicyTransactionDataForEndorsementEdit(pt_id)
-            }, 2000)
-        }else{
-            show_list_hide_add() 
+    //     if(pt_id != 0){
+    //         setTimeout(function(){
+    //             hide_list_show_add()
+    //             getPolicyTransactionDataForEndorsementEdit(pt_id)
+    //         }, 2000)
+    //     }else{
+    //         show_list_hide_add() 
+    //     }
+
+    //     console.log('pt_id', pt_id)
+
+    // }
+
+    function getURLParamsForReport() {   
+        const params = new URLSearchParams(window.location.search);
+        const pt_id = params.get('pt_id') ?? 0;
+
+        // ✅ Get the previous page URL
+        const previousUrl = document.referrer || '';
+
+        console.log("PT ID:", pt_id);
+        console.log("Previous Page URL:", previousUrl);
+
+        if (pt_id != 0) {
+            hide_list_show_add();
+            setTimeout(() => 
+                getPolicyTransactionDataForEndorsementEdit(pt_id), 
+            1500);  // Reduced timeout
+        } else {
+            show_list_hide_add();
         }
 
-        console.log('pt_id', pt_id)
+        if(previousUrl != "" && pt_id != 0){
+            redirect_url = previousUrl;
+            $('#btnAdd').attr('href', previousUrl);
+        }
 
+        console.log('getURLParamsForReport pt_id', pt_id);  // Retain the log if necessary
     }
 
+
     function onlyNumbers(event) 
     {
         var charcode = event.which || event.keyCode;
diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php
index c9a1408d..1f744d39 100644
--- a/app/Views/policy_transaction_inception_form.php
+++ b/app/Views/policy_transaction_inception_form.php
@@ -1338,6 +1338,7 @@
     let isClientFormSubmitting = false;
     let isVehicleFormSubmitting = false;
     var insurer_count_array = [];
+    var redirect_url = '';
 
     $(document).ready(function(){
 
@@ -3608,10 +3609,7 @@
         $('.loader').fadeIn();
         $('.loader-mask').fadeIn();
 
-        var formData = new FormData($('#inception_form_id')[0]);
-
-        console.log(formData);
-        
+        var formData = new FormData($('#inception_form_id')[0]);        
 
         const jsonString = JSON.stringify(shortListedInsurer);
         // console.log('jsonString', jsonString);
@@ -3658,7 +3656,7 @@
                     toastr.success(res.message, 'Success');
 
                     show_list_hide_add();
-                    window.location.href = '';
+                    window.location.href = redirect_url;
 
 
                     $('#policy_tranction_primarykey').val(res.pt_id);
@@ -5036,6 +5034,12 @@
         const params = new URLSearchParams(window.location.search);
         const pt_id = params.get('pt_id') ?? 0;
 
+        // ✅ Get the previous page URL
+        const previousUrl = document.referrer || '';
+
+        console.log("PT ID:", pt_id);
+        console.log("Previous Page URL:", previousUrl);
+
         if (pt_id != 0) {
             hide_list_show_add();
             setTimeout(() => 
@@ -5045,6 +5049,11 @@
             show_list_hide_add();
         }
 
+        if(previousUrl != "" && pt_id != 0){
+            redirect_url = previousUrl;
+            $('#btnAdd').attr('href', previousUrl);
+        }
+
         console.log('getURLParamsForReport pt_id', pt_id);  // Retain the log if necessary
     }
 
diff --git a/app/Views/report_bds.php b/app/Views/report_bds.php
index 9104d9f5..446f2ada 100644
--- a/app/Views/report_bds.php
+++ b/app/Views/report_bds.php
@@ -79,36 +79,36 @@ table.dataTable tbody td {
                     
                         
                             S. No
-                            User
+                            User
                             Month
-                            Business Type
-                            Client Type
+                            
+                            Client Type
                             Insured Name
                             Policy/
Endorsement Policy Type - BAP Group - Vehicle Number + BAP Group + Vehicle Number Policy No Endorsement No - Insurer Name + Insurer Branch - TPA - Endorsement
Effective Date - Policy
Effective Date - Policy
Expiry Date - Reference - Remarks - Base Premium - Terrorism/TP - Premium
(without GST) - GST @ 18% + + Endorsement
Effective Date + Policy
Effective Date + Policy
Expiry Date + Reference + Remarks + BP Premium + TP/Ter Premium + Premium
(without GST) + Total Premium - Base
Revenue % - TP / Terrorism
Revenue % - Rewards - Total IRDA
Revenue INR - Billed Amount - UnBilled Amount + BP % + TP/Ter % + Rewards + Agreed Amount + Invoiced Amount + Outstanding Amount @@ -116,34 +116,40 @@ table.dataTable tbody td { $row){ ?> - - +   " class="mdi mdi-pencil" > + - - + + - - + + - + - - - - - - + + + + + + - - + +  %  % - + @@ -415,33 +421,64 @@ $(document).ready(function() { paging: true, // Enable pagination pageLength: 10, // Set default number of rows per page (optional) ordering: false, - "footerCallback": function(row, data, start, end, display) { + // "footerCallback": function(row, data, start, end, display) { + // var api = this.api(); + + // // Calculate column totals + // var totalPremium = api.column(23).data().reduce(function(a, b) { + // return parseFloat(a) + parseFloat(b) || 0; + // }, 0); + + // var total_rewards = api.column(26).data().reduce(function(a, b) { + // return parseFloat(a) + parseFloat(b) || 0; + // }, 0); // Add initial value 0 here + + // console.log('total_rewards - ' + total_rewards); + + // var totalIrda = api.column(27).data().reduce(function(a, b) { + // return parseFloat(a) + parseFloat(b) || 0; + // }, 0); + + // var totalBilled = api.column(28).data().reduce(function(a, b) { + // return parseFloat(a) + parseFloat(b) || 0; + // }, 0); + + // var totalUnbilled = api.column(29).data().reduce(function(a, b) { + // return parseFloat(a) + parseFloat(b) || 0; + // }, 0); + + // // Update the totals in the div above the table + // $('#total_premium').text(totalPremium.toFixed(2)); + // $('#total_rewards').text(total_rewards.toFixed(2)); + // $('#total_irda').text(totalIrda.toFixed(2)); + // $('#total_billed').text(totalBilled.toFixed(2)); + // $('#total_unbilled').text(totalUnbilled.toFixed(2)); + // } + "footerCallback": function(row, data, start, end, display) { var api = this.api(); - // Calculate column totals - var totalPremium = api.column(23).data().reduce(function(a, b) { - return parseFloat(a) + parseFloat(b) || 0; + // Calculate column totals (adjust indices based on VISIBLE columns) + var totalPremium = api.column(20, {search: 'applied'}).data().reduce(function(a, b) { + return parseFloat(a) + parseFloat(b || 0); }, 0); - var total_rewards = api.column(26).data().reduce(function(a, b) { - return parseFloat(a) + parseFloat(b) || 0; - }, 0); // Add initial value 0 here - - console.log('total_rewards - ' + total_rewards); - - var totalIrda = api.column(27).data().reduce(function(a, b) { - return parseFloat(a) + parseFloat(b) || 0; + var total_rewards = api.column(23, {search: 'applied'}).data().reduce(function(a, b) { + return parseFloat(a) + parseFloat(b || 0); }, 0); - var totalBilled = api.column(28).data().reduce(function(a, b) { - return parseFloat(a) + parseFloat(b) || 0; + var totalIrda = api.column(24, {search: 'applied'}).data().reduce(function(a, b) { + return parseFloat(a) + parseFloat(b || 0); }, 0); - var totalUnbilled = api.column(29).data().reduce(function(a, b) { - return parseFloat(a) + parseFloat(b) || 0; + var totalBilled = api.column(25, {search: 'applied'}).data().reduce(function(a, b) { + return parseFloat(a) + parseFloat(b || 0); }, 0); - // Update the totals in the div above the table + var totalUnbilled = api.column(26, {search: 'applied'}).data().reduce(function(a, b) { + return parseFloat(a) + parseFloat(b || 0); + }, 0); + + // Update the totals $('#total_premium').text(totalPremium.toFixed(2)); $('#total_rewards').text(total_rewards.toFixed(2)); $('#total_irda').text(totalIrda.toFixed(2));