From 9e14f7bf9223735966c444d222dbd37ce32d8bc3 Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Wed, 30 Apr 2025 14:03:09 +0530 Subject: [PATCH] FEAT_POLICY_REPORTS,FIX_DASH_BDS SRI --- app/Config/Routes.php | 1 + app/Controllers/BDSReportController.php | 183 +++++++++++++++++++++--- app/Controllers/DashboardController.php | 3 +- app/Models/PolicyTransactionModel.php | 7 +- app/Views/DashBoard.php | 8 +- app/Views/bds_multi_report.php | 122 ++++++++++++++++ app/Views/layout/header.php | 20 +++ 7 files changed, 320 insertions(+), 24 deletions(-) create mode 100644 app/Views/bds_multi_report.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 36b9a672..842adbbc 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -537,6 +537,7 @@ $routes->group("/bdsReport", ["filter" => "authMVC"], function ($routes) { $routes->get('bap_wise_data/(:any)','BDSReportController::Bap_Wise_Data/$1'); $routes->match( ['get', 'post'], 'renewal_report','BDSReportController::renewalReport'); $routes->get('getTATReport','BDSReportController::bdsTATReport'); + $routes->get("getMultiReport/(:any)", "BDSReportController::getMultiReport/$1"); }); //New Tickets diff --git a/app/Controllers/BDSReportController.php b/app/Controllers/BDSReportController.php index f0fbd79a..c3005aac 100644 --- a/app/Controllers/BDSReportController.php +++ b/app/Controllers/BDSReportController.php @@ -33,6 +33,7 @@ class BDSReportController extends AdminController protected $PTCOShareDetailsModel; protected $coShareStmtDetailsModel; protected $policyTypeModel; + protected $policyTatReportType; public function __construct() { @@ -46,6 +47,13 @@ class BDSReportController extends AdminController $this->PTCOShareDetailsModel = new PTCOShareDetailsModel(); $this->coShareStmtDetailsModel = new COShareStmtDetailsModel(); $this->policyTypeModel = new PolicyTypeModel(); + + + $this->policyTatReportType = [ + '1' => "TAT Band Wise report", + '2' => "Account Manger Status Wise Report", + '3' => "Account Manger TAT Wise Report" + ]; } // public function Insurer_wise_Data($insurerCategory, $fromDate, $toDate) @@ -209,7 +217,7 @@ class BDSReportController extends AdminController $html = view('bds_report_bap_wise_data', $viewData); return $this->respond(['status' => true, 'html' => $html], 200); - } else if($report_type == 'bapInsurer'){ + } else if ($report_type == 'bapInsurer') { //Condition for BAP Insurer wise date $category = $category == 'life' ? 1 : 0; @@ -217,8 +225,7 @@ class BDSReportController extends AdminController $html = view('irda_bap_insurer_report_list', $viewData); return $this->respond(['status' => true, 'html' => $html], 200); - - }else if($report_type == 'bapClient'){ + } else if ($report_type == 'bapClient') { //Condition for BAP Client wise date $category = $category == 'life' ? 1 : 0; @@ -226,8 +233,7 @@ class BDSReportController extends AdminController $html = view('irda_bap_client_report_list', $viewData); return $this->respond(['status' => true, 'html' => $html], 200); - - }else if($report_type == 'client'){ + } else if ($report_type == 'client') { //Condition for Client wise date $category = $category == 'life' ? 1 : 0; @@ -517,7 +523,7 @@ class BDSReportController extends AdminController if (!empty($start_date) && !empty($end_date)) { $fromDate = change_date_format($start_date); - $toDate = change_date_format($end_date); + $toDate = change_date_format($end_date); } $this->myLogger->logme('error', 'From date : {fromDate} - To date {toDate} ', ['fromDate' => $fromDate, 'toDate' => $toDate]); @@ -597,7 +603,7 @@ class BDSReportController extends AdminController // $db = db_connect(); // $builder = $db->query(" - + // select ins.id, ins.name as insurer_name, // -- Health Policies @@ -706,7 +712,7 @@ class BDSReportController extends AdminController // life_premium DESC, // marine_cargo_premium DESC, // marine_hull_premium DESC; - + // "); // // Get the query @@ -745,7 +751,7 @@ class BDSReportController extends AdminController // $db = db_connect(); // $builder = $db->query(" - + // SELECT // c.id AS client_id, // c.client_name, @@ -808,7 +814,7 @@ class BDSReportController extends AdminController // life_premium DESC, // marine_cargo_premium DESC, // marine_hull_premium DESC - + // "); // // Get the query @@ -847,11 +853,11 @@ class BDSReportController extends AdminController // $db = db_connect(); // $builder = $db->query(" - + // select // c.id as client_id, // c.client_name, - + // ( // select // count(policy_transaction.id) @@ -862,7 +868,7 @@ class BDSReportController extends AdminController // and policy_transaction.is_active = 1 // ) as policy_count, - + // COALESCE(( // select // sum(stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt) as premium @@ -873,9 +879,9 @@ class BDSReportController extends AdminController // and stmt.is_active = 1 // and ptco.is_active = 1 // and pt.is_active = 1 - + // ), 0) as premium - + // from clients c // join policy_transaction on c.id = policy_transaction.client_id AND policy_transaction.policy_issue_date >= '$fromDate' AND policy_transaction.policy_issue_date <= '$toDate' // join policy_type on policy_transaction.policy_type_id = policy_type.id and policy_type.policy_category = $category @@ -910,7 +916,6 @@ class BDSReportController extends AdminController $data['issuer'] = [1 => 'JIBS', 2 => 'Nhance']; $data['page_name'] = "Renewal Report"; return $this->loadLayout('renewal_search', $data); - } else { $fromDate = $this->request->getPost('fromDate'); @@ -1001,6 +1006,150 @@ class BDSReportController extends AdminController // dd(db_connect()->getLastQuery(),$result); $data['data'] = $result; // dd($data, get_role_id(), ENROLLMENT_TEAM_ID, user_team()); - return $this->loadLayout('bds_tat_wise_report', $data); + // return $this->loadLayout('bds_tat_wise_report', $data); + + return $result; + } + + public function accountMangerStatusBDSReport() + { + $data['page_name'] = "Account Manager BDS Report"; + + $sql = " + SELECT + COALESCE(ACM_Name, 'Total') AS ACM_Name, + COALESCE(SUM(CASE WHEN status = 'instalment_pending' THEN 1 ELSE 0 END), 0) AS `Instalment Pending`, + COALESCE(SUM(CASE WHEN status = 'under_process' THEN 1 ELSE 0 END), 0) AS `Under Process`, + COALESCE(SUM(CASE WHEN status = 'client_pending' THEN 1 ELSE 0 END), 0) AS `Client Pending`, + COALESCE(SUM(CASE WHEN status = 'co_insurer_pending' THEN 1 ELSE 0 END), 0) AS `Co Insurer Pending`, + COALESCE(SUM(CASE WHEN status = 'tpa_pending' THEN 1 ELSE 0 END), 0) AS `TPA Pending`, + COALESCE(SUM(CASE WHEN status = 'validated' THEN 1 ELSE 0 END), 0) AS `Validated`, + COALESCE(SUM(CASE WHEN status = 'cancelled' THEN 1 ELSE 0 END), 0) AS `Cancelled`, + COALESCE(SUM(CASE WHEN status = 'completed' THEN 1 ELSE 0 END), 0) AS `Completed`, + COALESCE(SUM(CASE WHEN status = 'lost' THEN 1 ELSE 0 END), 0) AS `Lost`, + COALESCE(SUM(CASE WHEN status = 'insurer_pending' THEN 1 ELSE 0 END), 0) AS `Insurer Pending` + + FROM ( + SELECT + up.first_name AS ACM_Name, + ls.status + FROM policy_transaction pt + JOIN clients c ON pt.client_id = c.id AND c.is_active = 1 + JOIN client_rm crm ON crm.client_id = c.id AND crm.is_active = 1 AND crm.level = 3 + JOIN user_profiles up ON up.id = crm.user_id AND up.is_active = 1 + LEFT JOIN ( + SELECT + pts1.policy_tran_id, + pts1.status, + pts1.created_at + FROM policy_transaction_status pts1 + INNER JOIN ( + SELECT + policy_tran_id, + MAX(created_at) AS max_created_at + FROM policy_transaction_status + WHERE is_active = 1 + GROUP BY policy_tran_id + ) pts2 + ON pts1.policy_tran_id = pts2.policy_tran_id + AND pts1.created_at = pts2.max_created_at + WHERE pts1.is_active = 1 + ) ls ON pt.id = ls.policy_tran_id + WHERE pt.is_active = 1 + AND DATEDIFF(CURDATE(), ls.created_at) >= 4 + ) AS sub + GROUP BY ACM_Name; + "; + + $db = \Config\Database::connect(); + $query = $db->query($sql); + + // Get the result + $result = $query->getResultArray(); + + return $result; + } + + public function accountManagerTatBDSReport(){ + + $sql = " + SELECT + COALESCE(ACM_Name, 'Total') AS ACM_Name, + COALESCE(SUM(CASE WHEN tat_bucket = '0-4 Days' THEN 1 ELSE 0 END), 0) AS `0-4 Days`, + COALESCE(SUM(CASE WHEN tat_bucket = '5-8 Days' THEN 1 ELSE 0 END), 0) AS `5-8 Days`, + COALESCE(SUM(CASE WHEN tat_bucket = '9-12 Days' THEN 1 ELSE 0 END), 0) AS `9-12 Days`, + COALESCE(SUM(CASE WHEN tat_bucket = 'Above 12 Days' THEN 1 ELSE 0 END), 0) AS `Above 12 Days` + FROM ( + SELECT + up.first_name AS ACM_Name, + CASE + WHEN DATEDIFF(CURDATE(), ls.created_at) BETWEEN 0 AND 4 THEN '0-4 Days' + WHEN DATEDIFF(CURDATE(), ls.created_at) BETWEEN 5 AND 8 THEN '5-8 Days' + WHEN DATEDIFF(CURDATE(), ls.created_at) BETWEEN 9 AND 12 THEN '9-12 Days' + WHEN DATEDIFF(CURDATE(), ls.created_at) > 12 THEN 'Above 12 Days' + ELSE 'Unknown' + END AS tat_bucket + FROM policy_transaction pt + JOIN clients c ON pt.client_id = c.id AND c.is_active = 1 + JOIN client_rm crm ON crm.client_id = c.id AND crm.is_active = 1 AND crm.level = 3 + JOIN user_profiles up ON up.id = crm.user_id AND up.is_active = 1 + LEFT JOIN ( + SELECT + pts1.policy_tran_id, + pts1.status, + pts1.created_at + FROM policy_transaction_status pts1 + INNER JOIN ( + SELECT + policy_tran_id, + MAX(created_at) AS max_created_at + FROM policy_transaction_status + WHERE is_active = 1 + GROUP BY policy_tran_id + ) pts2 + ON pts1.policy_tran_id = pts2.policy_tran_id + AND pts1.created_at = pts2.max_created_at + WHERE pts1.is_active = 1 + ) ls ON pt.id = ls.policy_tran_id + WHERE pt.is_active = 1 + AND ls.created_at IS NOT NULL + ) AS sub + GROUP BY ACM_Name; + + "; + + $db = \Config\Database::connect(); + $query = $db->query($sql); + + // Get the result + $result = $query->getResultArray(); + + return $result; + + } + + public function getMultiReport($report_type){ + + $data['page_name'] = "BDS Report"; + + if ($report_type == 1){ + + $data['page_title'] = "BDS TAT Report"; + $data['data'] = $this->bdsTATReport(); + }else if ($report_type == 2){ + + $data['page_title'] = "Account Manager Status Report"; + $data['data'] = $this->accountMangerStatusBDSReport(); + + }else{ + + $data['page_title'] = "Account Manager TAT Report"; + $data['data'] = $this->accountManagerTatBDSReport(); + + } + + return $this->loadLayout('bds_multi_report', $data); + } } + diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index fc154a4b..b9ed11a4 100755 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -238,6 +238,7 @@ class DashboardController extends AdminController // echo "
";
             $data['pendingActionsData'] = $pendingActionsData;
             $data['businessTeamCount'] = count($businessTeamData) ?? 0;
+            // dd($businessTeamData);
             $data['financeTeamCount'] = count($financeTeamData) ?? 0;
             $data['businessTeamStatusData'] = $businessTeamStatusData;
             $data['financeTeamStatusData'] = $financeTeamStatusData;
@@ -257,6 +258,7 @@ class DashboardController extends AdminController
         }
 
         // dd(get_role_id(),user_team());
+        // dd($data);
         
         $data['page_name'] = 'Dashboard';
 
@@ -725,7 +727,6 @@ class DashboardController extends AdminController
             'validated' => [],
             'cancelled' => [],
             'instalment_pending' => [],
-            'completed' => [],
         ];
 
         // Loop through results and group them by their status
diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php
index 2e697698..ec355e34 100644
--- a/app/Models/PolicyTransactionModel.php
+++ b/app/Models/PolicyTransactionModel.php
@@ -1335,6 +1335,8 @@ class PolicyTransactionModel extends Model
             )
             ->where("th.last_policy_status_change <= '{$dateThreshold}'", null, false)
             ->where('policy_transaction.is_active', 1)
+            ->where("policy_transaction.status is not null", null, false)
+            ->whereNotIn("policy_transaction.status", ['completed'])
             // ->where('policy_transaction.status', 'completed')
             ->where('(pt_co_share_details.bp_amt IS NULL OR pt_co_share_details.bp_amt = 0)', null, false);
 
@@ -1426,8 +1428,9 @@ class PolicyTransactionModel extends Model
             // ->where('policy_transaction.status', 'completed')
             ->where('COALESCE(pt_co_share_details.agreed_bp_per, 0) + COALESCE(pt_co_share_details.agreed_tp_per, 0) + COALESCE(pt_co_share_details.agreed_tep_per, 0) = 0')
             ->where('COALESCE(pt_co_share_details.actual_bp_amt, 0) + COALESCE(pt_co_share_details.actual_tp_amt, 0) + COALESCE(pt_co_share_details.actual_tep_amt, 0) = 0')
-            ->where('COALESCE(pt_co_share_details.actual_bp_brokerage_amt, 0) + COALESCE(pt_co_share_details.actual_tp_brokerage_amt, 0) + COALESCE(pt_co_share_details.actual_tep_brokerage_amt, 0) = 0');
-
+            ->where('COALESCE(pt_co_share_details.actual_bp_brokerage_amt, 0) + COALESCE(pt_co_share_details.actual_tp_brokerage_amt, 0) + COALESCE(pt_co_share_details.actual_tep_brokerage_amt, 0) = 0')
+            ->where("policy_transaction.status is not null", null, false)
+            ->whereNotIn("policy_transaction.status", ['completed']);
 
         if ($start_date != 0 && $end_date != 0 && $date_type != 0) {
 
diff --git a/app/Views/DashBoard.php b/app/Views/DashBoard.php
index 40d25654..08e08855 100755
--- a/app/Views/DashBoard.php
+++ b/app/Views/DashBoard.php
@@ -259,10 +259,10 @@
                         
                         
                     
-
-                    
-                        
-                    
+                    
 
                     
                 
diff --git a/app/Views/bds_multi_report.php b/app/Views/bds_multi_report.php
new file mode 100644
index 00000000..05b38e6c
--- /dev/null
+++ b/app/Views/bds_multi_report.php
@@ -0,0 +1,122 @@
+
+
+
+
+
+
+
+
+
+

+
+
+ +
+ + + + + + + + + + + + + + $value): + $numValue = is_numeric($value) ? (int) $value : 0; + if ($key != 'TAT_Category') { + $columnTotals[$key] += $numValue; + $rowTotal += $numValue; + } + ?> + + + + + + + + + + $total): ?> + + + + + +
TOTAL
+
+ +
+
+
+
+ + diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index a7500816..a30e0d10 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -766,6 +766,26 @@ +
  • + + + Policy TAT Reports + +
    + +
    +