From 03b9d3523de7fcbb4092d3b4c549d7173db941ab Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 8 Dec 2025 11:35:12 +0530 Subject: [PATCH] CHANGE_SHOW_RM_NAME --- .../PolicyTransactionController.php | 24 +++++- app/Models/PolicyTransactionModel.php | 58 +++++++++++++ .../policy_transaction_inception_form_2.php | 83 +++++++++++++++++-- 3 files changed, 152 insertions(+), 13 deletions(-) diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 5b348a0f..2708abc4 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -825,9 +825,15 @@ // Fetch Sales Team $data['salse_team'] = $this->userModel - ->select('user_profiles.*,nhance_branch.id as nhance_branch_id, nhance_branch.branch_name as nhance_branch_name') + ->select(' + user_profiles.*, + nhance_branch.id as nhance_branch_id, + nhance_branch.branch_name as nhance_branch_name, + rm.first_name AS rm_name + ') ->join('user_teams', 'user_profiles.id = user_teams.user_id') ->join('nhance_branch', 'user_profiles.nhance_branch_id = nhance_branch.id','left') + ->join('user_profiles AS rm', 'user_profiles.rm_id = rm.id', 'left') ->where('user_teams.team_id', 5) ->where('user_teams.is_active', 1) ->where('user_profiles.is_active', 1) @@ -841,9 +847,19 @@ // Fetch ACM $data['ACM'] = $this->userModel - ->where('role', 3) // Assuming `role` is in `user_profiles` - ->where('is_active', 1) - ->findAll(); + ->select(' + user_profiles.*, + nhance_branch.id AS nhance_branch_id, + nhance_branch.branch_name AS nhance_branch_name, + rm.first_name AS rm_name + ') + ->join('user_teams', 'user_profiles.id = user_teams.user_id') + ->join('nhance_branch', 'user_profiles.nhance_branch_id = nhance_branch.id', 'left') + ->join('user_profiles AS rm', 'user_profiles.rm_id = rm.id', 'left') + ->where('user_profiles.role', 3) + ->where('user_profiles.is_active', 1) + ->findAll(); + // echo '
';
             
             // print_r($data['ppTeamsData']); die;
diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php
index 44a0550d..7fed2681 100644
--- a/app/Models/PolicyTransactionModel.php
+++ b/app/Models/PolicyTransactionModel.php
@@ -85,6 +85,9 @@
             'agent_code',
             'file_id',
             'entry_from',
+            'salse_person_manager_id',
+            'service_person_manager_id',
+            'service_person_branch_id',
         ];
 
 
@@ -1794,6 +1797,61 @@
                 $toDate = change_date_format($end_date);
             }
 
+            $query = $this->db->table('policy_transaction pt')
+                ->select('
+                    pt.*, 
+                    c.client_name, 
+                    c.short_name AS client_short_name, 
+                    c.client_type,
+                    policy_type.policy_type,
+                    i.name as insurer_name,
+                    ib.branch_name as insurer_branch_name,
+                    vehicle.vehicle_no,
+                    leads.status as lead_status
+                ')
+                ->join('clients c', 'pt.client_id = c.id', 'left')
+                ->join('pt_co_share_details pt_co', 'pt.id = pt_co.pt_id and pt_co.co_share_type = 1', 'left')
+                ->join('insurers i', 'pt_co.insurer_id = i.id', 'left')
+                ->join('insurer_branch ib', 'pt_co.insurer_branch_id = ib.id', 'left')
+                ->join('policy_type', 'pt.policy_type_id = policy_type.id', 'left')
+                ->join('vehicle', 'pt.vehicle_id = vehicle.id and vehicle.is_active = 1', 'left')
+                // ->join('leads', 'pt.client_policy_id = leads.source_policy_id and leads.source_policy_id != 0 and leads.is_active = 1', 'left')
+                ->where('pt.renewal_date >=', $fromDate)
+                ->where('pt.renewal_date <=', $toDate)
+                ->where('pt.is_active', 1)
+                ->where('pt.source_client_policy_id != pt.client_policy_id')
+                ->where('pt_co.is_active', 1)
+                ->where('pt.action_type', "inception");
+
+            // Apply filters if parameters are provided
+            if (!empty($client_type)) {
+                $query->where('c.client_type', $client_type);
+            }
+            if (!empty($client)) {
+                $query->where('pt.client_id', $client);
+            }
+            if (!empty($issuer)) { // Corrected condition to check $issuer
+                $query->where('pt.issuer', $issuer);
+            }
+
+            $query->groupBy('pt.id');
+            $query->orderBy('pt.id', 'DESC');
+            // Fetch and return results
+            $results = $query->get()->getResultArray();
+            // print($this->db->getLastQuery()); die;
+            return $results;
+        }
+        
+        public function getRenewalReportDataOld($start_date = null, $end_date = null, $client_type = null, $client = null, $issuer = null)
+        {
+            $fromDate = date('Y-m-d', strtotime('-90 days'));
+            $toDate = date('Y-m-d 23:59:59');
+
+            if (!empty($start_date) && !empty($end_date)) {
+                $fromDate = change_date_format($start_date);
+                $toDate = change_date_format($end_date);
+            }
+
             $query = $this->db->table('policy_transaction pt')
                 ->select('
                     pt.*, 
diff --git a/app/Views/policy_transaction_inception_form_2.php b/app/Views/policy_transaction_inception_form_2.php
index 79ac1444..dfd6a662 100644
--- a/app/Views/policy_transaction_inception_form_2.php
+++ b/app/Views/policy_transaction_inception_form_2.php
@@ -333,6 +333,9 @@
                         
                         
                         
+                        
+                        
+                        
 
                         
                         
@@ -439,14 +442,21 @@
                                                             class="text-right"
                                                             style="font-size: x-small;">
                                                         
+                                                        
+                                                        
                                                     
-                                                    
                                                         
                                                         
                                                             
                                                                 
                                                             
@@ -456,12 +466,27 @@
                                                 
 
                                                 
- - - @@ -6543,7 +6568,7 @@ } - function setNhanceBranch(select) { + function setNhanceBranch(select, show_id) { if (!select || !select.options || select.selectedIndex < 0) { console.warn('No option selected yet'); @@ -6558,9 +6583,13 @@ console.log('NB ID:', nbID); console.log('NB Name:', nbName); - $('#issuer_branch').val(nbID ? nbID : ''); + if(show_id == "nhance_branch_info"){ + $('#issuer_branch').val(nbID ? nbID : ''); + }else{ + $('#service_person_branch_id').val(nbID ? nbID : ''); + } - let nbDiv = document.getElementById('nhance_branch_info'); + let nbDiv = document.getElementById(show_id); if (!nbID || !nbName) { nbDiv.innerHTML = ''; @@ -6575,6 +6604,42 @@ nbDiv.classList.add('show'); } + function setRM(select, show_id) { + + if (!select || !select.options || select.selectedIndex < 0) { + console.warn('No option selected yet'); + return; + } + + let selectedOption = select.options[select.selectedIndex]; + + let rmid = selectedOption.getAttribute('data-rmid'); + let rmname = selectedOption.getAttribute('data-rmname'); + + console.log('RM ID:', rmid); + console.log('RM Name:', rmname); + + if(show_id == "salse_rm_info"){ + $('#salse_person_manager_id').val(rmid ? rmid : ''); + }else{ + $('#service_person_manager_id').val(rmid ? rmid : ''); + } + + let rmDiv = document.getElementById(show_id); + + if (!rmid || !rmname) { + rmDiv.innerHTML = ''; + rmDiv.classList.remove('show'); + return; + } + + rmDiv.innerHTML = + '' + rmname + '' + + ' ✓ RM'; + + rmDiv.classList.add('show'); + } + function setPolicyIssueMonth(){ let monthDiv = document.getElementById('policy_issue_month_info'); monthAbbr = document.getElementById('month').value;