MERGE_BRANCH_WITH_CLAIM_INITIATE_API_FEAT

This commit is contained in:
Srinivas-Saravanan 2025-01-31 10:44:07 +05:30
commit 901762941e
10 changed files with 658 additions and 72 deletions

View File

@ -494,9 +494,10 @@ $routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrol
//BDSReports
$routes->group("/bdsReport", ["filter" => "authMVC"], function ($routes) {
$routes->match( ['get', 'post'], 'irba_report','BDSReportController::irba_report');
$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');
$routes->match( ['get', 'post'], 'renewal_report','BDSReportController::renewalReport');
});

View File

@ -47,6 +47,39 @@ class BDSReportController extends AdminController
$this->coShareStmtDetailsModel = new COShareStmtDetailsModel();
$this->policyTypeModel = new PolicyTypeModel();
}
// 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');
// try {
// $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 ptp.policy_category = $insurerCategory and pt_co.insurer_id = ins.id THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_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,
// COALESCE(SUM(CASE WHEN ptp.policy_category = $insurerCategory and pt_co.insurer_id = ins.id THEN pt_co.exp_amt ELSE 0 END), 0) AS Expected_amt
// 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 and ptp.is_active = 1
// 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();
// // log_message('error',$this->insurerModel->getLastQuery());
// // log_message('error',json_encode($data));
// } catch (\Exception $e) {
// $data['message'] = 'No data Found';
// $this->myLogger->logme('error', $e->getMessage());
// return $data;
// }
// return ($data);
// }
public function Insurer_wise_Data($insurerCategory, $fromDate, $toDate)
{
@ -54,18 +87,28 @@ class BDSReportController extends AdminController
$toDate = \DateTime::createFromFormat('d-m-Y', $toDate)->format('Y-m-d');
try {
$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 and ptp.is_active = 1
where ins.is_active = 1 and (ptp.policy_category = $insurerCategory or ptp.policy_category is null)
group by ins.id
";
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 ptp.policy_category = $insurerCategory AND pt_co.insurer_id = ins.id THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_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,
COALESCE(SUM(CASE WHEN ptp.policy_category = $insurerCategory AND pt_co.insurer_id = ins.id THEN pt_co.exp_amt ELSE 0 END), 0) AS Expected_amt
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 AND ptp.is_active = 1
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();
// log_message('error',$this->insurerModel->getLastQuery());
@ -88,12 +131,13 @@ class BDSReportController extends AdminController
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
COALESCE(SUM((pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_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,
COALESCE(SUM(pt_co.exp_amt), 0) AS Expected_amt
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
LEFT JOIN pt_co_share_details AS pt_co ON pt.id = pt_co.pt_id AND pt_co.is_active = 1
LEFT JOIN co_share_stmt_details AS co ON pt_co.id = co.co_share_id AND co.is_active = 1
WHERE pot.is_active = 1
AND pot.policy_category = $insurerCategory
GROUP BY pot.bap;
@ -219,57 +263,68 @@ class BDSReportController extends AdminController
$db = db_connect();
$builder = $db->query("
select ins.id, ins.name as insurer_name,
-- Health Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Health' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS health_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Health' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS health_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Health' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS health_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Health' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS health_revenue,
COALESCE(SUM(CASE WHEN ptp.bap = 'Health' THEN pt_co.exp_amt ELSE 0 END), 0) AS health_exp_amt,
-- Misc Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS misc_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS misc_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS misc_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS misc_revenue,
COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' THEN pt_co.exp_amt ELSE 0 END), 0) AS misc_exp_amt,
-- Motor Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS motor_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS motor_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS motor_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS motor_revenue,
COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' THEN pt_co.exp_amt ELSE 0 END), 0) AS motor_exp_amt,
-- Engineering Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS engineering_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS engineering_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS engineering_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS engineering_revenue,
COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' THEN pt_co.exp_amt ELSE 0 END), 0) AS engineering_exp_amt,
-- Fire Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS fire_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS fire_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS fire_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS fire_revenue,
COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' THEN pt_co.exp_amt ELSE 0 END), 0) AS fire_exp_amt,
-- Liability Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS liability_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS liability_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS liability_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS liability_revenue,
COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' THEN pt_co.exp_amt ELSE 0 END), 0) AS liability_exp_amt,
-- Life Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Life' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS life_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Life' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS life_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Life' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS life_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Life' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS life_revenue,
COALESCE(SUM(CASE WHEN ptp.bap = 'Life' THEN pt_co.exp_amt ELSE 0 END), 0) AS life_exp_amt,
-- Marine Cargo Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS marine_cargo_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS marine_cargo_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS marine_cargo_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS marine_cargoe_revenue,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN pt_co.exp_amt ELSE 0 END), 0) AS marine_cargo_exp_amt,
-- Marine Hull Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS marine_hull_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS marine_hull_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS marine_hull_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS marine_hull_revenue,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN pt_co.exp_amt ELSE 0 END), 0) AS marine_hull_exp_amt,
-- Grand Totals
COALESCE(
@ -286,15 +341,15 @@ class BDSReportController extends AdminController
) AS total_policy_count,
COALESCE(
SUM(CASE WHEN ptp.bap = 'Health' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Life' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Motor' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Fire' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Engineering' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Liability' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END)+
SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END)+
SUM(CASE WHEN ptp.bap = 'Misc' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END),
SUM(CASE WHEN ptp.bap = 'Health' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Life' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Motor' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Fire' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Engineering' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END) +
SUM(CASE WHEN ptp.bap = 'Liability' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END)+
SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END)+
SUM(CASE WHEN ptp.bap = 'Misc' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END),
0
) AS total_premium,
@ -374,49 +429,49 @@ class BDSReportController extends AdminController
-- Health Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Health' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS health_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Health' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS health_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Health' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS health_premium,
-- Misc Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS misc_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS misc_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS misc_premium,
-- Motor Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS motor_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS motor_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS motor_premium,
-- Engineering Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS engineering_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS engineering_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS engineering_premium,
-- Fire Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS fire_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS fire_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS fire_premium,
-- Liability Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS liability_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS liability_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS liability_premium,
-- Life Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Life' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS life_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Life' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS life_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Life' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS life_premium,
-- Marine Cargo Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS marine_cargo_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS marine_cargo_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS marine_cargo_premium,
-- Marine Hull Policies
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS marine_hull_policy_count,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS marine_hull_premium,
COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN (pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0) AS marine_hull_premium,
-- Grand Totals
COALESCE(SUM(CASE WHEN pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS total_policy_count,
COALESCE(SUM(stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt), 0) AS total_premium
COALESCE(SUM(pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt), 0) AS total_premium
FROM clients c
LEFT JOIN policy_transaction pt ON pt.client_id = c.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
LEFT JOIN pt_co_share_details ptco ON ptco.pt_id = pt.id AND ptco.is_active = 1
LEFT JOIN co_share_stmt_details stmt ON stmt.co_share_id = ptco.id AND stmt.is_active = 1
LEFT JOIN pt_co_share_details pt_co ON pt_co.pt_id = pt.id AND pt_co.is_active = 1
LEFT JOIN co_share_stmt_details stmt ON stmt.co_share_id = pt_co.id AND stmt.is_active = 1
WHERE c.is_active = 1
AND ptp.policy_category = $category
GROUP BY c.id
@ -487,13 +542,13 @@ class BDSReportController extends AdminController
COALESCE((
select
sum(stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt) as premium
sum(pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) as premium
from co_share_stmt_details stmt
left join pt_co_share_details ptco on stmt.co_share_id = ptco.id
left join policy_transaction pt on ptco.pt_id = pt.id
left join pt_co_share_details pt_co on stmt.co_share_id = pt_co.id
left join policy_transaction pt on pt_co.pt_id = pt.id
where pt.client_id = c.id
and stmt.is_active = 1
and ptco.is_active = 1
and pt_co.is_active = 1
and pt.is_active = 1
), 0) as premium
@ -518,4 +573,348 @@ class BDSReportController extends AdminController
return [];
}
}
// //Function for get BAP INSURE wise data for premium , policy count , revenue only
// public function getBAPInsurerData($category = 0, $start_date = null, $end_date = null)
// {
// try {
// $this->myLogger->logme('error', 'getBAPInsurerData function called');
// $this->myLogger->logme('error', 'category : {data}', ['data' => $category]);
// $this->myLogger->logme('error', 'start date : {start_date} - end date {end_date} ', ['start_date' => $start_date, 'end_date' => $end_date]);
// //set default last 3 months data date
// $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);
// }
// $this->myLogger->logme('error', 'From date : {fromDate} - To date {toDate} ', ['fromDate' => $fromDate, 'toDate' => $toDate]);
// $db = db_connect();
// $builder = $db->query("
// select ins.id, ins.name as insurer_name,
// -- Health Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Health' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS health_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Health' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS health_premium,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Health' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS health_revenue,
// -- Misc Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS misc_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS misc_premium,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS misc_revenue,
// -- Motor Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS motor_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS motor_premium,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS motor_revenue,
// -- Engineering Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS engineering_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS engineering_premium,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS engineering_revenue,
// -- Fire Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS fire_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS fire_premium,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS fire_revenue,
// -- Liability Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS liability_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS liability_premium,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS liability_revenue,
// -- Life Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Life' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS life_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Life' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS life_premium,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Life' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS life_revenue,
// -- Marine Cargo Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS marine_cargo_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS marine_cargo_premium,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS marine_cargoe_revenue,
// -- Marine Hull Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS marine_hull_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS marine_hull_premium,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END), 0) AS marine_hull_revenue,
// -- Grand Totals
// COALESCE(
// SUM(CASE WHEN ptp.bap = 'Health' AND pt.action_type = 'inception' THEN 1 ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Marine Hull' AND pt.action_type = 'inception' THEN 1 ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Life' AND pt.action_type = 'inception' THEN 1 ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Motor' AND pt.action_type = 'inception' THEN 1 ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Fire' AND pt.action_type = 'inception' THEN 1 ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Engineering' AND pt.action_type = 'inception' THEN 1 ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Liability' AND pt.action_type = 'inception' THEN 1 ELSE 0 END)+
// SUM(CASE WHEN ptp.bap = 'Marine Cargo' AND pt.action_type = 'inception' THEN 1 ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Misc' AND pt.action_type = 'inception' THEN 1 ELSE 0 END),
// 0
// ) AS total_policy_count,
// COALESCE(
// SUM(CASE WHEN ptp.bap = 'Health' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Life' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Motor' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Fire' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Engineering' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Liability' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END)+
// SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END)+
// SUM(CASE WHEN ptp.bap = 'Misc' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END),
// 0
// ) AS total_premium,
// COALESCE(
// SUM(CASE WHEN ptp.bap = 'Health' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Life' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Motor' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Fire' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Engineering' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END) +
// SUM(CASE WHEN ptp.bap = 'Liability' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END)+
// SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END)+
// SUM(CASE WHEN ptp.bap = 'Misc' THEN stmt.actual_bp_brokerage_amt + stmt.actual_tp_brokerage_amt + stmt.actual_tep_brokerage_amt + stmt.reward ELSE 0 END),
// 0
// ) AS total_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 = $category
// where ins.is_active = 1
// group by ins.id
// ORDER BY
// health_premium DESC,
// misc_premium DESC,
// motor_premium DESC,
// engineering_premium DESC,
// fire_premium DESC,
// liability_premium DESC,
// life_premium DESC,
// marine_cargo_premium DESC,
// marine_hull_premium DESC;
// ");
// // Get the query
// $result = $builder->getResultArray();
// $this->myLogger->logme('error', 'Query executed successfully.');
// // dd(db_connect()->getLastQuery(),$result);
// return $result;
// } catch (\Exception $e) {
// // Log the exception details for debugging
// $this->myLogger->logme('error', 'Error occurred in getBAPInsurerData: {message}', ['message' => $e->getMessage()]);
// $this->myLogger->logme('error', 'Stack trace: {trace}', ['trace' => $e->getTraceAsString()]);
// return [];
// }
// }
// //Function for get BAP CLIENT wise data for premium , policy count , revenue only
// public function getBAPClientData($category = 0, $start_date = null, $end_date = null)
// {
// try {
// $this->myLogger->logme('error', 'getBAPClientData function called');
// $this->myLogger->logme('error', 'category : {data}', ['data' => $category]);
// $this->myLogger->logme('error', 'start date : {start_date} - end date {end_date} ', ['start_date' => $start_date, 'end_date' => $end_date]);
// //set default last 3 months data date
// $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);
// }
// $this->myLogger->logme('error', 'From date : {fromDate} - To date {toDate} ', ['fromDate' => $fromDate, 'toDate' => $toDate]);
// $db = db_connect();
// $builder = $db->query("
// SELECT
// c.id AS client_id,
// c.client_name,
// -- Health Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Health' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS health_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Health' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS health_premium,
// -- Misc Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS misc_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Misc' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS misc_premium,
// -- Motor Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS motor_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Motor' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS motor_premium,
// -- Engineering Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS engineering_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Engineering' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS engineering_premium,
// -- Fire Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS fire_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Fire' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS fire_premium,
// -- Liability Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS liability_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Liability' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS liability_premium,
// -- Life Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Life' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS life_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Life' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS life_premium,
// -- Marine Cargo Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS marine_cargo_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS marine_cargo_premium,
// -- Marine Hull Policies
// COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' AND pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS marine_hull_policy_count,
// COALESCE(SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt ELSE 0 END), 0) AS marine_hull_premium,
// -- Grand Totals
// COALESCE(SUM(CASE WHEN pt.action_type = 'inception' THEN 1 ELSE 0 END), 0) AS total_policy_count,
// COALESCE(SUM(stmt.actual_bp_amt + stmt.actual_tp_amt + stmt.actual_tep_amt), 0) AS total_premium
// FROM clients c
// LEFT JOIN policy_transaction pt ON pt.client_id = c.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
// LEFT JOIN pt_co_share_details ptco ON ptco.pt_id = pt.id AND ptco.is_active = 1
// LEFT JOIN co_share_stmt_details stmt ON stmt.co_share_id = ptco.id AND stmt.is_active = 1
// WHERE c.is_active = 1
// AND ptp.policy_category = $category
// GROUP BY c.id
// ORDER BY
// health_premium DESC,
// misc_premium DESC,
// motor_premium DESC,
// engineering_premium DESC,
// fire_premium DESC,
// liability_premium DESC,
// life_premium DESC,
// marine_cargo_premium DESC,
// marine_hull_premium DESC
// ");
// // Get the query
// $result = $builder->getResultArray();
// // dd(db_connect()->getLastQuery(),$result);
// return $result;
// } catch (\Exception $e) {
// // Log the exception details for debugging
// $this->myLogger->logme('error', 'Error occurred in getBAPClientData: {message}', ['message' => $e->getMessage()]);
// $this->myLogger->logme('error', 'Stack trace: {trace}', ['trace' => $e->getTraceAsString()]);
// return [];
// }
// }
// //Function for get CLIENT wise data for premium and policy count only
// public function getClientData($category = 0, $start_date = null, $end_date = null)
// {
// try {
// $this->myLogger->logme('error', 'getClientData function called');
// $this->myLogger->logme('error', 'category : {data}', ['data' => $category]);
// $this->myLogger->logme('error', 'start date : {start_date} - end date {end_date} ', ['start_date' => $start_date, 'end_date' => $end_date]);
// //set default last 3 months data date
// $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);
// }
// $this->myLogger->logme('error', 'From date : {fromDate} - To date {toDate} ', ['fromDate' => $fromDate, 'toDate' => $toDate]);
// $db = db_connect();
// $builder = $db->query("
// select
// c.id as client_id,
// c.client_name,
// (
// select
// count(policy_transaction.id)
// from policy_transaction
// left join policy_type on policy_transaction.policy_type_id = policy_type.id
// where policy_transaction.client_id = c.id
// and policy_transaction.action_type = 'inception'
// 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
// from co_share_stmt_details stmt
// left join pt_co_share_details ptco on stmt.co_share_id = ptco.id
// left join policy_transaction pt on ptco.pt_id = pt.id
// where pt.client_id = c.id
// 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
// where c.is_active = 1
// group by client_name
// order by premium desc
// ");
// // Get the query
// $result = $builder->getResultArray();
// // dd(db_connect()->getLastQuery(),$result);
// return $result;
// } catch (\Exception $e) {
// // Log the exception details for debugging
// $this->myLogger->logme('error', 'Error occurred in getClientData: {message}', ['message' => $e->getMessage()]);
// $this->myLogger->logme('error', 'Stack trace: {trace}', ['trace' => $e->getTraceAsString()]);
// return [];
// }
// }
// ---------------RENEWAL REPORT-----------------------------------------------------------------------------------
public function renewalReport()
{
if ($this->request->is('get')) {
$default_start = new \DateTime();
$data['default_end'] = $default_start->format('d-m-Y');
$data['default_start'] = $default_start->modify('-60 days')->format('d-m-Y');
$data['page_name'] = "Renewal Report";
return $this->loadLayout('renewal_search', $data);
} else {
$data['page_name'] = "Renewal Report";
$html = view('bds_renewal_report_list', $data);
return $this->respond(['status' => true, 'html' => $html], 200);
}
}
}

View File

@ -4047,10 +4047,11 @@ class ClientController extends AdminController
// -----------BDS REPORT CONTROLLER---------------------------------------------------------------------------------
// $BDSReportController = new BDSReportController();
$BDSReportController = new BDSReportController();
// $data['data'] = $BDSReportController->getBAPInsurerData();
// return $this->loadLayout('irda_bap_insurer_report_list', $data);
$data['data'] = $BDSReportController->getBAPInsurerData();
return $this->loadLayout('irda_bap_insurer_report_list', $data);
// $data['data'] = $BDSReportController->getBAPClientData();
// return $this->loadLayout('irda_bap_client_report_list', $data);

View File

View File

@ -45,7 +45,7 @@ table.dataTable tbody td {
<td><?= $data['insurers'] ?></td>
<td><?= $data['Policies'] ?></td>
<td><?= $data['Premium'] ?></td>
<td><?= $data['Revenue'] ?></td>
<td><?= $data['Revenue'] == 0.00 ? $data['Expected_amt'] : $data['Revenue']?></td>
</tr>
<?php endforeach ?>
</tbody>

View File

@ -45,7 +45,7 @@ table.dataTable tbody td {
<td><?= $data['bap'] ?></td>
<td><?= $data['Policies'] ?></td>
<td><?= $data['Premium'] ?></td>
<td><?= $data['Revenue'] ?></td>
<td><?= $data['Revenue']== 0.00 ? $data['Expected_amt'] : $data['Revenue']?></td>
</tr>
<?php endforeach ?>
</tbody>

View File

@ -87,7 +87,8 @@
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
'Last Year': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')]
}
}, cb);

View File

@ -20,6 +20,17 @@ table.dataTable tbody td {
.right-align-input {
text-align: right;
}
.right-align-input:nth-child(4n+1),
.right-align-input:nth-child(4n+2) {
background-color: #f9f9f9; /* Light gray shade */
}
.right-align-input:nth-child(4n+3),
.right-align-input:nth-child(4n+4) {
background-color: #ffffff; /* White shade */
}
</style>
<div class="col-12" id="second_page">
@ -46,8 +57,8 @@ table.dataTable tbody td {
<th colspan="2" style="text-align: center;">Life</th>
<th colspan="2" style="text-align: center;">Marine Cargo</th>
<th colspan="2" style="text-align: center;">Misc</th>
<th colspan="2" style="text-align: center;">Motor</th>
<th colspan="2" style="text-align: center;">Marine Hull</th>
<th colspan="2" style="text-align: center;">Motor</th>
<th colspan="2" style="text-align: center;">Grand Total</th>
</tr>
@ -118,7 +129,6 @@ table.dataTable tbody td {
<td class="right-align-input"><?php echo $row['marine_hull_policy_count']; ?></td>
<td class="right-align-input"><?php echo $row['marine_hull_premium']; ?></td>
<td class="right-align-input"><?php echo $row['misc_policy_count']; ?></td>
<td class="right-align-input"><?php echo $row['misc_premium']; ?></td>

View File

@ -44,8 +44,8 @@ table.dataTable tbody td {
<th colspan="3" style="text-align: center;">Life</th>
<th colspan="3" style="text-align: center;">Marine Cargo</th>
<th colspan="3" style="text-align: center;">Misc</th>
<th colspan="3" style="text-align: center;">Motor</th>
<th colspan="3" style="text-align: center;">Marine Hull</th>
<th colspan="3" style="text-align: center;">Motor</th>
<th colspan="3" style="text-align: center;">Grand Total</th>
</tr>
@ -107,44 +107,59 @@ table.dataTable tbody td {
<td class="right-align-input"><?php echo $row['engineering_policy_count']; ?> </td>
<td class="right-align-input"><?php echo $row['engineering_premium']; ?></td>
<td class="right-align-input"><?php echo $row['engineering_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['engineering_revenue']== 0.00 ? $row['engineering_exp_amt'] : $row['engineering_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['fire_policy_count']; ?></td>
<td class="right-align-input"><?php echo $row['fire_premium']; ?></td>
<td class="right-align-input"><?php echo $row['fire_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['fire_revenue']== 0.00 ? $row['fire_exp_amt'] : $row['fire_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['health_policy_count']; ?></td>
<td class="right-align-input"><?php echo $row['health_premium']; ?></td>
<td class="right-align-input"><?php echo $row['health_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['health_revenue']== 0.00 ? $row['health_exp_amt'] : $row['health_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['liability_policy_count']; ?></td>
<td class="right-align-input"><?php echo $row['liability_premium']; ?></td>
<td class="right-align-input"><?php echo $row['liability_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['liability_revenue']== 0.00 ? $row['liability_exp_amt'] : $row['liability_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['life_policy_count']; ?></td>
<td class="right-align-input"><?php echo $row['life_premium']; ?></td>
<td class="right-align-input"><?php echo $row['life_revenue'];?></td>
<td class="right-align-input"><?php echo $row['life_revenue']== 0.00 ? $row['life_exp_amt'] : $row['life_revenue'];?></td>
<td class="right-align-input"><?php echo $row['marine_cargo_policy_count']; ?></td>
<td class="right-align-input"><?php echo $row['marine_cargo_premium']; ?></td>
<td class="right-align-input"><?php echo $row['marine_cargoe_revenue'];?></td>
<td class="right-align-input"><?php echo $row['marine_cargoe_revenue']== 0.00 ? $row['marine_cargo_exp_amt'] : $row['marine_cargoe_revenue'];?></td>
<td class="right-align-input"><?php echo $row['marine_hull_policy_count']; ?></td>
<td class="right-align-input"><?php echo $row['marine_hull_premium']; ?></td>
<td class="right-align-input"><?php echo $row['marine_hull_revenue'];?></td>
<td class="right-align-input"><?php echo $row['marine_hull_revenue']== 0.00 ? $row['marine_hull_exp_amt'] : $row['marine_hull_revenue'];?></td>
<td class="right-align-input"><?php echo $row['misc_policy_count']; ?></td>
<td class="right-align-input"><?php echo $row['misc_premium']; ?></td>
<td class="right-align-input"><?php echo $row['misc_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['misc_revenue']== 0.00 ? $row['misc_exp_amt'] : $row['misc_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['motor_policy_count'] ?></td>
<td class="right-align-input"><?php echo $row['motor_premium']; ?></td>
<td class="right-align-input"><?php echo $row['motor_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['motor_revenue']== 0.00 ? $row['motor_exp_amt'] : $row['motor_revenue']; ?></td>
<td class="right-align-input"><?php echo $row['total_policy_count'] ?></td>
<td class="right-align-input"><?php echo $row['total_premium']; ?></td>
<td class="right-align-input"><?php echo $row['total_revenue']; ?></td>
<?php
$total_revenue = 0; // Initialize total revenue
// Calculate total revenue by summing all individual revenues
$total_revenue += $row['engineering_revenue']== 0.00 ? $row['engineering_exp_amt'] : $row['engineering_revenue'];
$total_revenue += $row['fire_revenue']== 0.00 ? $row['fire_exp_amt'] : $row['fire_revenue'];
$total_revenue += $row['health_revenue']== 0.00 ? $row['health_exp_amt'] : $row['health_revenue'];
$total_revenue += $row['liability_revenue']== 0.00 ? $row['liability_exp_amt'] : $row['liability_revenue'];
$total_revenue += $row['life_revenue']== 0.00 ? $row['life_exp_amt'] : $row['life_revenue'];
$total_revenue += $row['marine_cargoe_revenue']== 0.00 ? $row['marine_cargo_exp_amt'] : $row['marine_cargoe_revenue'];
$total_revenue += $row['marine_hull_revenue']== 0.00 ? $row['marine_hull_exp_amt'] : $row['marine_hull_revenue'];
$total_revenue += $row['misc_revenue']== 0.00 ? $row['misc_exp_amt'] : $row['misc_revenue'];
$total_revenue += $row['motor_revenue']== 0.00 ? $row['motor_exp_amt'] : $row['motor_revenue'];
?>
<td class="right-align-input"><?php echo round($total_revenue, 2); ?></td>
</tr>
<?php } ?>

View File

@ -0,0 +1,159 @@
<div class="row">
<div class="col-xl-12">
<div id="accordion" class="mb-3">
<div class="card mb-1">
<h5 class="m-1">
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne"
aria-expanded="true">
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
</a>
</h5>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
<!-- <div class="text-center"> -->
<div class="form-row">
<div class="form-group col-md-4" id="date_div">
<label>Date<span class="text-danger"></span></label>
<div id="reportrange" class="form-control"
style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
<i class="fa fa-calendar"></i>&nbsp;
<span></span> <i class="fa fa-caret-down"></i>
</div>
<input type="hidden" id="startDate" value=<?= $default_start ?>>
<input type="hidden" id="endDate" value=<?= $default_end ?>>
</div>
<div class="form-group col-md-3 client_type_div">
<label for="client_type">Client Type<span class="text-danger">*</span></label>
<select class="form-control" id="client_type" name="client_type" required>
<option value="">Select Client type</option>
<option value="1">Group</option>
<option value="2">Individual</option>
</select>
</div>
<div class="form-group col-md-3">
<label for="client_branch">Client<span class="text-danger">*</span></label>
<select class="form-control" id="client_id" name="client_id" required>
<option value="">Select Client</option>
</select>
</div>
</div>
<div class="row justify-content-end">
<div class="col-auto">
<a href="#" class="btn btn-primary waves-effect waves-light" id="get-report-page"
onclick="fetchReportPage(event);">Submit</a>
</div>
</div>
<!-- </div> -->
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card mb-1">
<div id="report"></div>
</div>
<script>
$(function() {
var start = $('#startDate').val();
var end = $('#endDate').val();
var start = moment(start, 'DD/MM/YYYY');
var end = moment(end, 'DD/MM/YYYY');
function cb(start, end) {
$('#reportrange span').html(start.format('D-MM-YYYY') + ' - ' + end.format('D-MM-YYYY'));
$('#startDate').val(start.format('DD-MM-YYYY'));
$('#endDate').val(end.format('DD-MM-YYYY'));
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month')
.endOf('month')
],
'Last Year': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year')
.endOf('year')
]
}
}, cb);
cb(start, end);
});
</script>
<script>
$('#category').on('click', function() {
var choosed_option = $('#category').val();
$("#report_type").val('0');
if (choosed_option == 'life') {
$("#report_type option[value='insurer']").show();
$("#report_type option[value='bap']").hide();
$("#report_type option[value='bapClient']").hide();
$("#report_type option[value='bapInsurer']").hide();
$("#report_type option[value='client']").show();
} else if (choosed_option == 'nonLife') {
$("#report_type option[value='insurer']").show();
$("#report_type option[value='bap']").show();
$("#report_type option[value='bapClient']").show();
$("#report_type option[value='bapInsurer']").show();
$("#report_type option[value='client']").hide();
}
})
function fetchReportPage() {
var fromDate = $('#startDate').val();
var toDate = $('#endDate').val();
var client_id = $('#client_id').val();
var report_type = $('#report_type').val();
var requestData = {
fromDate: fromDate,
toDate: toDate,
category: category,
report_type: report_type
};
console.log(typeof fromDate);
var url = '<?= base_url('/bdsReport/renewal_report') ?>';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
if (response.status == true) {
$('#report').html(response.html);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
} else {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
let message = response.message;
toastr.error(message, 'ERROR');
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
toastr.error('An error occurred while fetching the report page.', 'ERROR');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
});
}
</script>