diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 34a9466e..20d56fb4 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -482,3 +482,12 @@ $routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrol // Ticketing System // Ticketing System End's + + +//BDSReports +$routes->group("/bdsReport", ["filter" => "authMVC"], function ($routes) { + $routes->match( ['get', 'post'], 'irba_report','BDSReportController::irba_report'); + $routes->get('insurer_wise_data/(:any)','BDSReportController::Insurer_wise_Data/$1'); + $routes->get('bap_wise_data/(:any)','BDSReportController::Bap_Wise_Data/$1'); + +}); diff --git a/app/Controllers/BDSReportController.php b/app/Controllers/BDSReportController.php index 09e872c3..96ccb68f 100644 --- a/app/Controllers/BDSReportController.php +++ b/app/Controllers/BDSReportController.php @@ -14,10 +14,16 @@ use App\Models\InsurerBranchModel; use App\Models\PolicyTransactionModel; use App\Models\PTCOShareDetailsModel; use App\Models\COShareStmtDetailsModel; +use App\Models\PolicyTypeModel; +use CodeIgniter\API\ResponseTrait; -class BDSReportController extends BaseController + +class BDSReportController extends AdminController { + use ResponseTrait; + + protected $myLogger; protected $clientModel; protected $clientPolicyModel; @@ -26,6 +32,7 @@ class BDSReportController extends BaseController protected $policyTransactionModel; protected $PTCOShareDetailsModel; protected $coShareStmtDetailsModel; + protected $policyTypeModel; public function __construct() { @@ -38,13 +45,122 @@ class BDSReportController extends BaseController $this->policyTransactionModel = new PolicyTransactionModel(); $this->PTCOShareDetailsModel = new PTCOShareDetailsModel(); $this->coShareStmtDetailsModel = new COShareStmtDetailsModel(); + $this->policyTypeModel = new PolicyTypeModel(); } - public function index() - { - // + public function Insurer_wise_Data($insurerCategory,$fromDate,$toDate){ + + $fromDate = \DateTime::createFromFormat('d-m-Y', $fromDate)->format('Y-m-d'); + $toDate = \DateTime::createFromFormat('d-m-Y', $toDate)->format('Y-m-d'); + + if($insurerCategory == 0 || $insurerCategory == 1){ + $sql = " + select ins.id,ins.name as insurers, + COALESCE(SUM(CASE WHEN pt.action_type = 'inception' and pt.insurer_id = ins.id and ptp.policy_category = $insurerCategory THEN 1 ELSE 0 END), 0) AS Policies, + COALESCE(SUM(CASE WHEN stmt.co_share_id = pt_co.id and ptp.policy_category = $insurerCategory and pt_co.insurer_id = ins.id THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS Premium, + COALESCE(SUM(CASE WHEN stmt.co_share_id = pt_co.id and ptp.policy_category = $insurerCategory and pt_co.insurer_id = ins.id THEN stmt.reward + stmt.actual_bp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.actual_tp_brokerage_amt ELSE 0 END), 0) AS Revenue + from insurers ins + left join pt_co_share_details pt_co on ins.id = pt_co.insurer_id and pt_co.is_active = 1 + left join co_share_stmt_details stmt on pt_co.id = stmt.co_share_id and stmt.is_active = 1 + left join policy_transaction pt on pt_co.pt_id = pt.id and pt.is_active = 1 and pt.policy_issue_date >= $fromDate and pt.policy_issue_date <= $toDate + left join policy_type ptp on pt.policy_type_id = ptp.id and ptp.policy_category = $insurerCategory + where ins.is_active = 1 and (ptp.policy_category = $insurerCategory or ptp.policy_category is null) + group by ins.id + "; + + $data['insurer_wise_data'] = $this->insurerModel->query($sql)->getResultArray(); + + + }else{ + $data['message'] = 'Insurer Category Not Valid'; + log_message('error',$data['message']); + return $data; + } + return view('bds_report_Insurer_wise_Data',$data); } + public function Bap_Wise_Data($insurerCategory,$fromDate,$toDate){ + $fromDate = \DateTime::createFromFormat('d-m-Y', $fromDate)->format('Y-m-d'); + $toDate = \DateTime::createFromFormat('d-m-Y', $toDate)->format('Y-m-d'); + + if($insurerCategory == 0 || $insurerCategory == 1){ + $sql = " + SELECT + pot.bap AS bap, + COALESCE(COUNT(DISTINCT pt.id), 0) AS Policies, + COALESCE(SUM(co.actual_bp_amt + co.actual_tep_amt + co.actual_tp_amt), 0) AS Premium, + COALESCE(SUM(co.reward + co.actual_bp_brokerage_amt + co.actual_tep_brokerage_amt + co.actual_tp_brokerage_amt), 0) AS Revenue + FROM policy_type AS pot + LEFT JOIN policy_transaction AS pt ON pot.id = pt.policy_type_id AND pt.is_active = 1 AND pt.action_type = 'inception' and pt.policy_issue_date >= $fromDate and pt.policy_issue_date <= $toDate + LEFT JOIN pt_co_share_details AS ptco ON pt.id = ptco.pt_id AND ptco.is_active = 1 + LEFT JOIN co_share_stmt_details AS co ON ptco.id = co.co_share_id AND co.is_active = 1 + WHERE pot.is_active = 1 + AND pot.policy_category = $insurerCategory + GROUP BY pot.bap; + + "; + $data['bap_wise_data'] = $this->policyTypeModel->query($sql)->getResultArray(); + }else{ + $data['message'] = 'Insurer Category Not Valid'; + log_message('error',$data['message']); + return $data; + } + + + return view('bds_report_bap_wise_data',$data); + } + + public function irba_report(){ + + if ($this->request->getMethod()=='get'){ + $default_start = new \DateTime(); + $data['default_end'] = $default_start->format('d-m-Y'); + $data['default_start'] = $default_start->modify('-90 days')->format('d-m-Y'); + $data['categories'] = [ + 'Life' => 'life','Non Life'=>'nonLife' + ]; + $data['report_type'] = [ + 'Insurer'=> 'insurer', + 'BAP' => 'bap', + 'BAP-Client' => 'bapClient', + 'BAP-Insurer' =>'bapInsurer', + 'Client' =>'client' + ]; + return $this->loadLayout('irba_report',$data); + }else{ + $fromDate = $this->request->getPost('fromDate'); + $toDate = $this->request->getPost('toDate'); + $category = $this->request->getPost('category'); + $report_type = $this->request->getPost('report_type'); + // log_message('error',json_encode($_POST));die(); + if($report_type == 'insurer'){ + $life = $category == 'life' ? 1:0; + $viewData = $this->Insurer_wise_Data($life,$fromDate,$toDate); + + // Ensure $viewData is an array + if (!is_array($viewData)) { + $viewData = []; + } + + $html = view('bds_report_Insurer_wise_Data', $viewData); + return $this->respond(['status'=>true, 'html'=>$html], 200); + } + else if($report_type == 'bap'){ + $life = $category == 'life'?1:0; + $viewData = $this->Bap_wise_Data($life,$fromDate,$toDate); + + // Ensure $viewData is an array + if (!is_array($viewData)) { + $viewData = []; + } + + $html = view('bds_report_bap_wise_data', $viewData); + return $this->respond(['status'=>true, 'html'=>$html], 200); + } + + } +} + // ----------------------------------------------------------------------------------------- } diff --git a/app/Views/bds_report_Insurer_wise_Data.php b/app/Views/bds_report_Insurer_wise_Data.php new file mode 100644 index 00000000..f93e5c55 --- /dev/null +++ b/app/Views/bds_report_Insurer_wise_Data.php @@ -0,0 +1,138 @@ + +
+
+
+
+
+

Employees

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
InsurerPoliciesPremiumRevenue
Total Amount
+
+
+
+
+ + diff --git a/app/Views/bds_report_bap_wise_data.php b/app/Views/bds_report_bap_wise_data.php new file mode 100644 index 00000000..b05960a8 --- /dev/null +++ b/app/Views/bds_report_bap_wise_data.php @@ -0,0 +1,138 @@ + +
+
+
+
+
+

Employees

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InsurerPoliciesPremiumRevenue
Total Amount
+
+
+
+
+ + + diff --git a/app/Views/irba_report.php b/app/Views/irba_report.php new file mode 100644 index 00000000..88f51ebb --- /dev/null +++ b/app/Views/irba_report.php @@ -0,0 +1,147 @@ +
+
+
+
+
+ + + +
+
+
+ +
+
+ +
+   + +
+ > + > +
+ + +
+
+ +
+ + +
+
+ +
+ + +
+
+ +
+ Submit +
+
+ +
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index e8f0dd11..02c29f7d 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -717,6 +717,9 @@
  • Outstanding
  • +
  • + IRBA Reports +