diff --git a/app/Controllers/BDSReportController.php b/app/Controllers/BDSReportController.php index 67634315..54abf46f 100644 --- a/app/Controllers/BDSReportController.php +++ b/app/Controllers/BDSReportController.php @@ -91,7 +91,7 @@ class BDSReportController extends AdminController 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 ptp.policy_category = $insurerCategory AND pt_co.insurer_id = ins.id THEN (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 @@ -131,7 +131,7 @@ class BDSReportController extends AdminController SELECT pot.bap AS bap, COALESCE(COUNT(DISTINCT pt.id), 0) AS Policies, - 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((pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 @@ -267,26 +267,26 @@ 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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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, @@ -294,35 +294,35 @@ class BDSReportController extends AdminController -- 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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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, @@ -341,15 +341,15 @@ class BDSReportController extends AdminController ) AS total_policy_count, 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) + - 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), + SUM(CASE WHEN ptp.bap = 'Health' THEN (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_amt + pt_co.non_comm_per_amt) ELSE 0 END) + + SUM(CASE WHEN ptp.bap = 'Marine Hull' THEN (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_amt + pt_co.non_comm_per_amt) ELSE 0 END) + + SUM(CASE WHEN ptp.bap = 'Life' THEN (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_amt + pt_co.non_comm_per_amt) ELSE 0 END) + + SUM(CASE WHEN ptp.bap = 'Motor' THEN (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_amt + pt_co.non_comm_per_amt) ELSE 0 END) + + SUM(CASE WHEN ptp.bap = 'Fire' THEN (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_amt + pt_co.non_comm_per_amt) ELSE 0 END) + + SUM(CASE WHEN ptp.bap = 'Engineering' THEN (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_amt + pt_co.non_comm_per_amt) ELSE 0 END) + + SUM(CASE WHEN ptp.bap = 'Liability' THEN (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_amt + pt_co.non_comm_per_amt) ELSE 0 END)+ + SUM(CASE WHEN ptp.bap = 'Marine Cargo' THEN (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_amt + pt_co.non_comm_per_amt) ELSE 0 END)+ + SUM(CASE WHEN ptp.bap = 'Misc' THEN (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_amt + pt_co.non_comm_per_amt) ELSE 0 END), 0 ) AS total_premium, @@ -429,43 +429,43 @@ 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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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 (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 (pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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(pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt), 0) AS total_premium + COALESCE(SUM(pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_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' @@ -542,7 +542,7 @@ class BDSReportController extends AdminController COALESCE(( select - sum(pt_co.bp_amt + pt_co.tp_amt + pt_co.tep_amt + pt_co.non_comm_per_amt) as premium + sum(pt_co.cop_amt + pt_co.cotp_amt + pt_co.cotep_amt + pt_co.non_comm_per_amt) as premium from co_share_stmt_details stmt 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 diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 8ee7765d..d1a48afb 100755 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -100,16 +100,52 @@ class DashboardController extends AdminController $data = []; - $results = $this->clientModel->select('clients.id as client_id, clients.client_name, clients.short_name, - client_branch.id as client_branch_id, client_branch.branch_name, - client_branch.branch_code, employees.id as employee_id, - employees.name as employee_name, employees.relationship, - employees.emp_code, employees.emp_status, auth_history.user_type, client_policy.policy_type_id, client_policy.id as client_policy_id') - ->join('client_branch', 'clients.id = client_branch.client_id', 'left') - ->join('client_policy', 'client_branch.id = client_policy.client_branch_id', 'left') - ->join('employees', 'client_branch.id = employees.client_branch_id', 'left') - ->join('auth_history', 'employees.id = auth_history.user_id AND "employee" = auth_history.user_type', 'left') - ->findAll(); + $db = db_connect(); + $sql = "SELECT + clients.id AS client_id, + clients.client_name, + clients.short_name, + client_branch.id AS client_branch_id, + client_branch.branch_name, + client_branch.branch_code, + + COUNT(employees.id) AS total_employees, + SUM(CASE WHEN employees.emp_status = 'draft' THEN 1 ELSE 0 END) AS draft_count, + SUM(CASE WHEN employees.emp_status IN ('enrolled', 'active') THEN 1 ELSE 0 END) AS enrolled_count, + + SUM(CASE WHEN auth_history.user_id IS NOT NULL THEN 1 ELSE 0 END) AS logged_in_count, + SUM(CASE WHEN auth_history.user_id IS NULL THEN 1 ELSE 0 END) AS not_logged_in_count, + + CASE + WHEN EXISTS ( + SELECT 1 FROM client_policy + WHERE client_policy.client_branch_id = client_branch.id + AND client_policy.is_active = 1 + AND client_policy.open_for_enrollment = 1 + ) THEN 1 + ELSE 0 + END AS open_or_close_enrollment + + FROM clients + LEFT JOIN client_branch ON clients.id = client_branch.client_id + LEFT JOIN employees ON client_branch.id = employees.client_branch_id + LEFT JOIN ( + SELECT user_id, user_type + FROM auth_history + WHERE user_type = 'employee' + GROUP BY user_id + ) AS auth_history ON employees.id = auth_history.user_id + + WHERE employees.relationship = 'Self' + AND employees.emp_status IN ('draft', 'enrolled', 'active') + AND employees.is_active = 1 + AND clients.is_active = 1 + AND client_branch.is_active = 1 + + GROUP BY clients.id, client_branch.id"; + + $query = $db->query($sql); + $results = $query->getResultArray(); $pendingActionsController = new PendingActionsController; $pendingActionsData = $pendingActionsController->getPendingActionsForDashBoard(); @@ -118,94 +154,11 @@ class DashboardController extends AdminController $businessTeamStatusData = $this->data_construct_for_bds($businessTeamData); $financeTeamStatusData = $this->data_construct_for_bds($financeTeamData); - $groupedData = []; - foreach ($results as $row) { - $clientId = $row['client_id']; - $clientName = $row['client_name']; - $shortName = $row['short_name']; - $branchId = $row['client_branch_id']; - $branchName = $row['branch_name']; - $branchCode = $row['branch_code']; - - $clientPolicyId = $row['client_policy_id']; - $policyTypeId = $row['policy_type_id']; - $employeeId = ''; - if ($employeeId != $row['employee_id']) { - $employeeId = $row['employee_id']; - } else { - $employeeId = null; - } - $employeeName = $row['employee_name']; - $employeeRelationship = $row['relationship']; - $employeeEmpCode = $row['emp_code']; - $employeeEmpStatus = $row['emp_status']; - $employeeUserType = $row['user_type']; - - // Initialize the client entry if it doesn't exist - if (!isset($groupedData[$clientId])) { - $groupedData[$clientId] = [ - 'client_id' => $clientId, - 'client_name' => $clientName, - 'short_name' => $shortName, - 'branches' => [] - ]; - } - - // Initialize the branch entry if it doesn't exist - if (!isset($groupedData[$clientId]['branches'][$branchId])) { - $groupedData[$clientId]['branches'][$branchId] = [ - 'client_branch_id' => $branchId, - 'branch_name' => $branchName, - 'branch_code' => $branchCode, - 'emp_login' => 0, - 'emp_enroll' => 0, - 'client_policies' => [], - 'employees' => [] - ]; - } - - // Add the client policy to the branch's policies list if it exists, not already added, and policyTypeId is not equal to 1 - if ($clientPolicyId !== null && $policyTypeId != 1 && !in_array(['client_policy_id' => $clientPolicyId, 'policy_type_id' => $policyTypeId], $groupedData[$clientId]['branches'][$branchId]['client_policies'])) { - $groupedData[$clientId]['branches'][$branchId]['client_policies'][] = [ - 'client_policy_id' => $clientPolicyId, - 'policy_type_id' => $policyTypeId - ]; - } - - // Append employee error to the branch's employees list if relationship is 'Self' and not already added - $employeeKey = $employeeId . '-' . $employeeName; // unique key to identify an employee - if ($employeeId !== null && $employeeRelationship == 'Self' && !isset($groupedData[$clientId]['branches'][$branchId]['employees'][$employeeKey])) { - $groupedData[$clientId]['branches'][$branchId]['employees'][$employeeKey] = [ - 'employee_id' => $employeeId, - 'employee_name' => $employeeName, - 'relationship' => $employeeRelationship, - 'emp_code' => $employeeEmpCode, - 'emp_status' => $employeeEmpStatus, - 'user_type' => $employeeUserType - ]; - if (!empty($employeeUserType)) { - $groupedData[$clientId]['branches'][$branchId]['emp_login']++; - } - - // Increment emp_enroll if emp_status is not 'draft' - if ($employeeEmpStatus !== 'draft') { - $groupedData[$clientId]['branches'][$branchId]['emp_enroll']++; - } - } - } - - // Re-index the arrays to match the expected structure - foreach ($groupedData as &$client) { - foreach ($client['branches'] as &$branch) { - $branch['employees'] = array_values($branch['employees']); - } - $client['branches'] = array_values($client['branches']); - } - - $data['client_branch_emp_list'] = $groupedData; + $data['client_branch_emp_list'] = $results; $session = \Config\Services::session(); - $session->set('enrollment_data', json_encode($data)); + $session->set('enrollment_data', json_encode($data)); + // echo "
";
         $data['pendingActionsData'] = $pendingActionsData;
         $data['businessTeamCount'] = count($businessTeamData) ?? 0;
diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php
index 348417bf..dc8517c9 100644
--- a/app/Controllers/PolicyTransactionController.php
+++ b/app/Controllers/PolicyTransactionController.php
@@ -438,6 +438,8 @@ class PolicyTransactionController extends BaseController
                     'bp_cgst' => $data['cgst'][$index] ?? 0,
                     'tp_amt' => $data['tp_premium'][$index] ?? 0,
                     'tep_amt' => $data['ter_premium'][$index] ?? 0,
+                    'cotp_amt' => $data['co_tp_premium'][$index] ?? 0,
+                    'cotep_amt' => $data['co_ter_premium'][$index] ?? 0,
                     'agreed_amt' => $data['agreed_amount'][$index] ?? 0,
                     'agreed_bp_per' => $data['agreed_bp'][$index] ?? 0,
                     'agreed_tp_per' => $data['agreed_tp'][$index] ?? 0,
diff --git a/app/Models/PTCOShareDetailsModel.php b/app/Models/PTCOShareDetailsModel.php
index dc6b2cec..1b2c84fd 100644
--- a/app/Models/PTCOShareDetailsModel.php
+++ b/app/Models/PTCOShareDetailsModel.php
@@ -66,6 +66,8 @@ class PTCOShareDetailsModel extends Model
         'statement_id',
         'follower_policy_no',
         'non_comm_per_amt',
+        'cotp_amt',
+        'cotep_amt',
     ];
 
     public function getNonReconcileredPolicyTransactions(string $insurer_id,string $insurer_branch_id)
diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php
index e2a25cc6..136529d6 100644
--- a/app/Models/PolicyTransactionModel.php
+++ b/app/Models/PolicyTransactionModel.php
@@ -318,6 +318,280 @@ class PolicyTransactionModel extends Model
 
     // BDS Report NEW Functin for QUERY
     // public function getBDSReportList($client_id, $policy_id, $branch_id, $issuer)
+
+    // public function getBDSReportList($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $client_branch_id = 0, $insurer_branch_id = 0, $client_policy_id = 0)
+    // {   
+
+    //     $date_condition = '';
+    //     if($date_type == 'statement_month' && $start_date != 0 && $end_date != 0) {
+    //         $date_condition = "
+    //              AND insurer_statements.month >= '".$start_date ."'
+    //              AND insurer_statements.month <= '".$end_date ."'
+    //         ";
+    //     }
+
+    //     $builder = $this->db->table('policy_transaction')
+    //         ->select("
+    //             policy_transaction.*,
+    //             DATE_FORMAT(policy_transaction.policy_issue_date, '%d %b %Y') AS policy_issue_date,
+    //             DATE_FORMAT(
+    //                 IF(policy_transaction.month IS NULL, 
+    //                 policy_transaction.policy_issue_date, 
+    //                 policy_transaction.month), 
+    //                 '%b %Y') AS policy_issue_month,
+    //             CASE
+    //                 WHEN clients.client_type = 1 THEN 'Group'
+    //                 WHEN clients.client_type = 2 THEN 'Retail'
+    //                 ELSE '-'
+    //             END AS client_type,
+    //             CASE
+    //                 WHEN policy_transaction.revenue_type = 'NA' THEN 'Fresh'
+    //                 ELSE 'Renewal'
+    //             END AS revenue_type,
+    //             CASE
+    //                 WHEN policy_transaction.action_type = 'inception' THEN 'Policy'
+    //                 ELSE 'Endorsement'
+    //             END AS action_type,
+    //             clients.client_name AS client_name,
+    //             clients.short_name AS client_short_name,
+    //             client_branch.branch_name AS client_branch_name,
+    //             client_branch.address1 AS client_address,
+    //             policy_type.policy_type,
+    //             policy_type.bap,
+    //             insurers.name AS insurer_name,
+    //             insurers.short_name AS insurer_short_name,
+    //             insurer_branch.branch_name AS insurer_branch_name,
+    //             insurer_branch.branch_code AS insurer_branch_code,
+    //             user_profiles.first_name as user_name,
+    //             vehicle.vehicle_no,
+    //             tpa.name as tpa_name,
+    //             pt_co_share_details.remark as remarks,
+    //             pt_co_share_details.bp_amt,
+    //             pt_co_share_details.exp_amt,
+    //             pt_co_share_details.id as pt_id,
+    //             sales_user.first_name as salse_person_name,
+    //             service_user.first_name as service_person_name,
+
+    //             ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) AS premium_wo_gst,
+
+    //             ROUND((ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) * 18 / 100), 2) AS gst_amount,
+
+    //             ROUND((ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) + ROUND((ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) * 18 / 100), 2)), 2) AS total_premium,
+
+    //             ROUND((pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) AS tp_or_ter,
+
+    //             DATEDIFF(policy_transaction.policy_end_date, CURDATE()) AS days,
+
+    //             (pt_co_share_details.agreed_tp_per + pt_co_share_details.agreed_tep_per) AS agreed_tp_or_ter_per,
+
+    //             pt_co_share_details.agreed_bp_per,
+    //             ROUND(
+    //             (
+    //                 SELECT
+    //                 (
+    //                     SUM(co_share_stmt_details.actual_bp_brokerage_amt) + 
+    //                     SUM(co_share_stmt_details.actual_tp_brokerage_amt) + 
+    //                     SUM(co_share_stmt_details.actual_tep_brokerage_amt) +
+    //                     SUM(co_share_stmt_details.reward) 
+
+    //                 ) AS total_irda_amt
+    //                 FROM
+    //                 co_share_stmt_details
+    //                 JOIN insurer_statements ON co_share_stmt_details.statement_id = insurer_statements.id
+    //                 WHERE
+    //                 co_share_stmt_details.co_share_id = pt_co_share_details.id
+    //                 AND co_share_stmt_details.is_active = 1
+    //                 AND insurer_statements.is_active = 1
+    //                 $date_condition
+    //             ),
+    //             2
+    //             ) AS total_irda_amt,
+    //             ROUND(
+    //             (
+    //                 SELECT
+    //                 (
+    //                     SUM(co_share_stmt_details.reward) 
+
+    //                 ) AS reward
+    //                 FROM
+    //                 co_share_stmt_details
+    //                 JOIN insurer_statements ON co_share_stmt_details.statement_id = insurer_statements.id
+    //                 WHERE
+    //                 co_share_stmt_details.co_share_id = pt_co_share_details.id
+    //                 AND co_share_stmt_details.is_active = 1
+    //                 AND insurer_statements.is_active = 1
+    //                 $date_condition
+    //             ),
+    //             2
+    //             ) AS reward,
+
+    //             ROUND(
+    //             (
+    //                 SELECT
+    //                 SUM(
+    //                     COALESCE(co_share_stmt_details.actual_bp_brokerage_amt, 0) + 
+    //                     COALESCE(co_share_stmt_details.actual_tp_brokerage_amt, 0) + 
+    //                     COALESCE(co_share_stmt_details.actual_tep_brokerage_amt, 0) +
+    //                     COALESCE(co_share_stmt_details.reward, 0) 
+    //                 ) AS total_irda_amt
+    //                 FROM
+    //                 co_share_stmt_details
+    //                 JOIN pt_co_share_details AS pt_table ON co_share_stmt_details.co_share_id = pt_table.id
+    //                 JOIN insurer_statements ON co_share_stmt_details.statement_id = insurer_statements.id
+    //                 WHERE
+    //                 co_share_stmt_details.co_share_id = pt_co_share_details.id
+    //                 AND co_share_stmt_details.is_active = 1
+    //                 AND pt_table.is_active = 1
+    //                 AND insurer_statements.is_active = 1
+    //                 AND insurer_statements.invoice_status IS NOT NULL
+    //                 $date_condition
+                   
+    //             ),
+    //             2
+    //             ) AS billed_amt,
+
+    //             ROUND(
+    //             (
+    //                 (
+    //                     SELECT
+    //                         SUM(
+    //                             COALESCE(co_share_stmt_details.actual_bp_brokerage_amt, 0) 
+    //                             + COALESCE(co_share_stmt_details.actual_tp_brokerage_amt, 0) 
+    //                             + COALESCE(co_share_stmt_details.actual_tep_brokerage_amt, 0)
+    //                             + COALESCE(co_share_stmt_details.reward, 0)
+    //                         )
+    //                     FROM
+    //                         co_share_stmt_details
+    //                     JOIN insurer_statements ON co_share_stmt_details.statement_id = insurer_statements.id
+    //                     WHERE
+    //                         co_share_stmt_details.co_share_id = pt_co_share_details.id
+    //                         AND co_share_stmt_details.is_active = 1
+    //                         $date_condition
+    //                 )
+    //                 -
+    //                 (
+    //                     SELECT
+    //                         SUM(
+    //                             COALESCE(co_share_stmt_details.actual_bp_brokerage_amt, 0) 
+    //                             + COALESCE(co_share_stmt_details.actual_tp_brokerage_amt, 0) 
+    //                             + COALESCE(co_share_stmt_details.actual_tep_brokerage_amt, 0)
+    //                             + COALESCE(co_share_stmt_details.reward, 0)
+    //                         )
+    //                     FROM
+    //                         co_share_stmt_details
+    //                     JOIN pt_co_share_details AS pt_table ON co_share_stmt_details.co_share_id = pt_table.id
+    //                     JOIN insurer_statements ON co_share_stmt_details.statement_id = insurer_statements.id
+    //                     WHERE
+    //                         co_share_stmt_details.co_share_id = pt_co_share_details.id
+    //                         AND co_share_stmt_details.is_active = 1
+    //                         AND pt_table.is_active = 1
+    //                         AND insurer_statements.is_active = 1
+    //                         AND insurer_statements.invoice_status IS NULL
+    //                         $date_condition
+    //                 )
+    //             ), 
+    //             2
+    //             ) AS unbilled_amt
+
+    //         ")
+    //         ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left')
+    //         // ->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id', 'left')
+    //         ->join('clients', 'clients.id = policy_transaction.client_id')
+    //         ->join('client_branch', 'policy_transaction.client_branch_id = client_branch.id', 'left')
+    //         ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left')
+    //         ->join('user_profiles', 'policy_transaction.created_by = user_profiles.id', 'left')
+    //         ->join('vehicle', 'policy_transaction.vehicle_id = vehicle.id', 'left')
+    //         ->join('policy_type', 'policy_transaction.policy_type_id = policy_type.id', 'left')
+    //         ->join('insurers', 'pt_co_share_details.insurer_id = insurers.id', 'left')
+    //         ->join('insurer_branch', 'pt_co_share_details.insurer_branch_id = insurer_branch.id', 'left')
+    //         ->join('tpa', 'policy_transaction.tpa_id = tpa.id', 'left')
+    //         ->join('tpa_branch', 'policy_transaction.tpa_branch_id = tpa_branch.id', 'left')
+    //         ->join('user_profiles AS sales_user', 'policy_transaction.sales_generated_by = sales_user.id', 'left')
+    //         ->join('user_profiles AS service_user', 'policy_transaction.serviced_by = service_user.id', 'left')
+    //         ->where('policy_transaction.is_active', 1)  
+    //         ->where('pt_co_share_details.is_active', 1);
+        
+    //     // Check if the start date and end date are provided
+    //     if ($start_date != 0 && $end_date != 0 && $date_type != 0 && $date_type != 'statement_month') {
+
+    //         $startDate = date('Y-m-d 00:00:00', strtotime($start_date));
+    //         $endDate = date('Y-m-d 23:59:59', strtotime($end_date));
+
+    //         $builder->where('policy_transaction.'.$date_type.'>=', $startDate)
+    //                 ->where('policy_transaction.'.$date_type.'<=', $endDate);
+
+    //     }
+
+    //     // if($date_type == 'statement_month' && $start_date != 0 && $end_date != 0){
+
+    //     //     $startDate = date('Y-m-d 00:00:00', strtotime($start_date));
+    //     //     $endDate = date('Y-m-d 23:59:59', strtotime($end_date));
+    //     //     $builder->where('policy_transaction.month >=', $startDate)
+    //     //     ->where('policy_transaction.month <=', $endDate);
+    //     // }
+
+    //     // Conditionally join insurer_statements if $date_type == 'statement_month'
+    //     if ($date_type == 'statement_month'  && $start_date != 0 && $end_date != 0) {
+    //         $startDate = date('Y-m-d', strtotime($start_date));
+    //         $endDate = date('Y-m-d', strtotime($end_date));
+
+    //         $builder->join('co_share_stmt_details', 'pt_co_share_details.id = co_share_stmt_details.co_share_id', 'left')
+    //         ->join('insurer_statements', 'co_share_stmt_details.statement_id = insurer_statements.id','left')
+    //         ->where('insurer_statements.is_active', 1)
+    //         ->where('insurer_statements.month >=', $startDate)
+    //         ->where('insurer_statements.month <=', $endDate)
+    //         ->groupBy('co_share_stmt_details.co_share_id');
+    //     }
+
+    //     if ($client_id != 0) {
+    //         $builder->where('policy_transaction.client_id', $client_id);
+    //     }
+    
+    //     if ($insurer_id != 0) {
+    //         $builder->where('policy_transaction.insurer_id', $insurer_id);
+    //     }
+
+    //     if ($client_branch_id != 0) {
+    //         $builder->where('policy_transaction.client_branch_id', $client_branch_id);
+    //     }
+    
+    //     if ($insurer_branch_id != 0) {
+    //         $builder->where('policy_transaction.insurer_branch_id', $insurer_branch_id);
+    //     }
+
+    //     if ($client_policy_id != 0) {
+    //         $builder->where('policy_transaction.client_policy_id', $client_policy_id);
+    //     }
+
+
+    
+    //     if ($policy_type_id != 0) {
+    //         $builder->where('client_policy.policy_type_id', $policy_type_id);
+    //     }
+    
+    //     if ($issuer != 0) {
+    //         $builder->where('policy_transaction.issuer', $issuer);
+    //     }
+
+    //     if($client_id == 0 && $insurer_id == 0 && $policy_type_id == 0 && $date_type == 0 && $issuer == 0){
+
+    //         $fromDate = date('Y-m-d', strtotime('-30 days'));
+    //         $toDate = date('Y-m-d 23:59:59');
+    
+    //         $builder->where('policy_transaction.created_at >=', $fromDate)
+    //                 ->where('policy_transaction.created_at <=', $toDate);
+
+    //     }
+
+    //     $builder->orderBy('policy_transaction.id', 'desc');
+
+    //     $result = $builder->get()->getResultArray();
+
+    //     // dd($this->db->getLastQuery());
+    
+    //     return $result;
+    // }
+
     public function getBDSReportList($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $client_branch_id = 0, $insurer_branch_id = 0, $client_policy_id = 0)
     {   
 
@@ -365,19 +639,19 @@ class PolicyTransactionModel extends Model
                 vehicle.vehicle_no,
                 tpa.name as tpa_name,
                 pt_co_share_details.remark as remarks,
-                pt_co_share_details.bp_amt,
+                pt_co_share_details.cop_amt as bp_amt,
                 pt_co_share_details.exp_amt,
                 pt_co_share_details.id as pt_id,
                 sales_user.first_name as salse_person_name,
                 service_user.first_name as service_person_name,
 
-                ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) AS premium_wo_gst,
+                ROUND((pt_co_share_details.cop_amt + pt_co_share_details.cotp_amt + pt_co_share_details.cotep_amt), 2) AS premium_wo_gst,
 
-                ROUND((ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) * 18 / 100), 2) AS gst_amount,
+                ROUND((ROUND((pt_co_share_details.cop_amt + pt_co_share_details.cotp_amt + pt_co_share_details.cotep_amt), 2) * 18 / 100), 2) AS gst_amount,
 
-                ROUND((ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) + ROUND((ROUND((pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) * 18 / 100), 2)), 2) AS total_premium,
+                ROUND((ROUND((pt_co_share_details.cop_amt + pt_co_share_details.cotp_amt + pt_co_share_details.cotep_amt), 2) + ROUND((ROUND((pt_co_share_details.cop_amt + pt_co_share_details.cotp_amt + pt_co_share_details.cotep_amt), 2) * 18 / 100), 2)), 2) AS total_premium,
 
-                ROUND((pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 2) AS tp_or_ter,
+                ROUND((pt_co_share_details.cotp_amt + pt_co_share_details.cotep_amt), 2) AS tp_or_ter,
 
                 DATEDIFF(policy_transaction.policy_end_date, CURDATE()) AS days,
 
@@ -591,9 +865,89 @@ class PolicyTransactionModel extends Model
         return $result;
     }
     
+    // public function getInceptionTranctionListData($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0)
+    // {
+    //     // dd($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer, $status);
+    //     $builder = $this->db->table('policy_transaction')
+    //         ->select('
+    //             policy_transaction.*, 
+    //             clients.short_name AS client_short_name,
+    //             clients.client_code,
+    //             clients.client_type,
+    //             clients.client_name,
+    //             client_branch.branch_name AS client_branch_name,
+    //             insurers.name AS insurer_name,
+    //             insurers.short_name AS insurer_short_name,
+    //             policy_type.policy_type,
+    //             pt_co_share_details.agreed_amt AS amount,
+    //             pt_co_share_details.bp_amt AS bp,
+    //             pt_co_share_details.tp_amt AS tp
+    //         ')
+    //         ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left')
+    //         ->join('clients', 'clients.id = policy_transaction.client_id', 'left')
+    //         ->join('client_branch', 'policy_transaction.client_branch_id = client_branch.id', 'left')
+    //         ->join('insurers', 'pt_co_share_details.insurer_id = insurers.id', 'left')
+    //         ->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left')
+    //         ->join('policy_type', 'policy_transaction.policy_type_id = policy_type.id', 'left')
+    //         ->where('policy_transaction.is_active', 1)
+    //         ->where('policy_transaction.action_type', 'inception');
+
+    //     if ($start_date != 0 && $end_date != 0 && $date_type != 0) {
+
+    //         $startDate = date('Y-m-d 00:00:00', strtotime($start_date));
+    //         $endDate = date('Y-m-d 23:59:59', strtotime($end_date));
+
+    //         $builder->where('policy_transaction.'.$date_type.'>=', $startDate)
+    //                 ->where('policy_transaction.'.$date_type.'<=', $endDate);
+    //     }else{
+
+    //         // $fromDate = date('Y-m-d', strtotime('-30 days'));
+    //         // $toDate = date('Y-m-d 23:59:59');
+    
+    //         // $builder->where('policy_transaction.created_at >=', $fromDate)
+    //         //         ->where('policy_transaction.created_at <=', $toDate);
+    //     }
+
+    //     if ($client_id != 0) {
+    //         $builder->where('policy_transaction.client_id', $client_id);
+    //     }
+    
+    //     if ($insurer_id != 0) {
+    //         $builder->where('policy_transaction.insurer_id', $insurer_id);
+    //     }
+    
+    //     if ($policy_type_id != 0) {
+    //         $builder->where('client_policy.policy_type_id', $policy_type_id);
+    //     }
+    
+    //     if ($issuer != 0) {
+    //         $builder->where('policy_transaction.issuer', $issuer);
+    //     }
+    //     if ($status != 0) {
+    //         $builder->where('policy_transaction.status', $status);
+    //     }
+
+    //     if($client_id == 0 && $insurer_id == 0 && $policy_type_id == 0 && $date_type == 0 && $issuer == 0){
+
+    //         $fromDate = date('Y-m-d', strtotime('-30 days'));
+    //         $toDate = date('Y-m-d 23:59:59');
+    
+    //         $builder->where('policy_transaction.created_at >=', $fromDate)
+    //                 ->where('policy_transaction.created_at <=', $toDate);
+
+    //     }
+        
+    //     $builder->orderBy('policy_transaction.id', 'desc')->limit(10);
+
+    //     $result = $builder->get()->getResultArray();
+
+    //     // dd($this->db->getLastQuery());
+
+    //     return $result;
+    // }
+
     public function getInceptionTranctionListData($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0)
     {
-        // dd($start_date, $end_date, $client_id, $insurer_id, $policy_type_id, $date_type, $issuer, $status);
         $builder = $this->db->table('policy_transaction')
             ->select('
                 policy_transaction.*, 
@@ -619,59 +973,44 @@ class PolicyTransactionModel extends Model
             ->where('policy_transaction.is_active', 1)
             ->where('policy_transaction.action_type', 'inception');
 
-        if ($start_date != 0 && $end_date != 0 && $date_type != 0) {
-
-            $startDate = date('Y-m-d 00:00:00', strtotime($start_date));
-            $endDate = date('Y-m-d 23:59:59', strtotime($end_date));
-
-            $builder->where('policy_transaction.'.$date_type.'>=', $startDate)
-                    ->where('policy_transaction.'.$date_type.'<=', $endDate);
-        }else{
-
-            // $fromDate = date('Y-m-d', strtotime('-30 days'));
-            // $toDate = date('Y-m-d 23:59:59');
-    
-            // $builder->where('policy_transaction.created_at >=', $fromDate)
-            //         ->where('policy_transaction.created_at <=', $toDate);
+        // Optimize Date Filtering
+        if (!empty($start_date) && !empty($end_date) && !empty($date_type)) {
+            $builder->where("policy_transaction.$date_type >=", date('Y-m-d 00:00:00', strtotime($start_date)))
+                    ->where("policy_transaction.$date_type <=", date('Y-m-d 23:59:59', strtotime($end_date)));
         }
 
-        if ($client_id != 0) {
+        // Apply Filters Only When Necessary
+        if (!empty($client_id)) {
             $builder->where('policy_transaction.client_id', $client_id);
         }
-    
-        if ($insurer_id != 0) {
+        if (!empty($insurer_id)) {
             $builder->where('policy_transaction.insurer_id', $insurer_id);
         }
-    
-        if ($policy_type_id != 0) {
+        if (!empty($policy_type_id)) {
             $builder->where('client_policy.policy_type_id', $policy_type_id);
         }
-    
-        if ($issuer != 0) {
+        if (!empty($issuer)) {
             $builder->where('policy_transaction.issuer', $issuer);
         }
-        if ($status != 0) {
+        if (!empty($status)) {
             $builder->where('policy_transaction.status', $status);
         }
 
-        if($client_id == 0 && $insurer_id == 0 && $policy_type_id == 0 && $date_type == 0 && $issuer == 0){
-
+        // Default to Last 30 Days if No Filters Are Applied
+        if (empty($client_id) && empty($insurer_id) && empty($policy_type_id) && empty($date_type) && empty($issuer)) {
             $fromDate = date('Y-m-d', strtotime('-30 days'));
             $toDate = date('Y-m-d 23:59:59');
-    
+
             $builder->where('policy_transaction.created_at >=', $fromDate)
                     ->where('policy_transaction.created_at <=', $toDate);
-
         }
-        
+
+        // Optimize Query Execution
         $builder->orderBy('policy_transaction.id', 'desc');
 
-        $result = $builder->get()->getResultArray();
-
-        // dd($this->db->getLastQuery());
-
-        return $result;
+        return $builder->get()->getResultArray();
     }
+
     
     public function getEndorsementTranctionListData($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0)
     {
@@ -762,7 +1101,7 @@ class PolicyTransactionModel extends Model
 
                 pt_co_share_details.exp_amt,
                 pt_co_share_details.variance,
-                ROUND ( (pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt),2) as original_premium,
+                ROUND ( (pt_co_share_details.cop_amt + pt_co_share_details.cotp_amt + pt_co_share_details.cotep_amt),2) as original_premium,
                 ROUND(
                 (
                     SELECT
@@ -780,7 +1119,7 @@ class PolicyTransactionModel extends Model
                 ) AS statement_premium,
 
                                COALESCE(
-                    (pt_co_share_details.bp_amt + pt_co_share_details.tp_amt + pt_co_share_details.tep_amt), 0
+                    (pt_co_share_details.cop_amt + pt_co_share_details.cotp_amt + pt_co_share_details.cotep_amt), 0
                 ) - 
                 COALESCE(
                     (
diff --git a/app/Views/client_list.php b/app/Views/client_list.php
index ce079c60..592031dc 100755
--- a/app/Views/client_list.php
+++ b/app/Views/client_list.php
@@ -202,6 +202,7 @@ table.dataTable thead th {
 
         customDropdown.querySelectorAll('.dropdown-item').forEach(item => {
             item.addEventListener('click', function(e) {
+                e.preventDefault(); 
                 const onclickAttr = this.getAttribute('onclick');
                 if (onclickAttr) {
                     eval(onclickAttr);
diff --git a/app/Views/employee_list.php b/app/Views/employee_list.php
index 976e2f69..292d5c21 100755
--- a/app/Views/employee_list.php
+++ b/app/Views/employee_list.php
@@ -232,7 +232,6 @@ table.dataTable tbody td {
 document.addEventListener("DOMContentLoaded", init);
 
 function init() {
-
     const table = document.getElementById("tickets-table");
     let activeDropdown = null;
 
@@ -264,8 +263,21 @@ function init() {
         
         const customDropdown = document.createElement('div');
         customDropdown.className = 'custom-dropdown-menu';
+        
+        // Clone original dropdown items while moving onclick handlers to data attributes
+        const originalItems = originalDropdown.querySelectorAll('.dropdown-item');
         customDropdown.innerHTML = originalDropdown.innerHTML;
         
+        // Transfer onclick handlers to data attributes
+        customDropdown.querySelectorAll('.dropdown-item').forEach((item, index) => {
+            const originalItem = originalItems[index];
+            const originalOnclick = originalItem.getAttribute('onclick');
+            if (originalOnclick) {
+                item.setAttribute('data-onclick', originalOnclick);
+                item.removeAttribute('onclick');  // Remove original handler
+            }
+        });
+
         return customDropdown;
     }
 
@@ -287,11 +299,15 @@ function init() {
     }
 
     function handleItemClick(e, item) {
-        const onclickAttr = item.getAttribute('onclick');
+        e.preventDefault(); 
+        
+        // Execute the stored onclick handler
+        const onclickAttr = item.getAttribute('data-onclick');
         if (onclickAttr) {
             eval(onclickAttr);
         }
         
+        // Handle href navigation
         const href = item.getAttribute('href');
         if (href && href !== '#') {
             window.location.href = href;
diff --git a/app/Views/enrollment_dash.php b/app/Views/enrollment_dash.php
index 88d9fda6..e9256345 100755
--- a/app/Views/enrollment_dash.php
+++ b/app/Views/enrollment_dash.php
@@ -1,9 +1,9 @@
-
 
-
+
@@ -14,7 +14,8 @@
- +
@@ -25,36 +26,46 @@ $currentItem = 0; // Counter for items $isActive = true; // Variable to set the first item as active foreach ($client_branch_emp_list as $clients) { - foreach ($clients['branches'] as $branches) { + // Start a new carousel item if needed if ($currentItem % $itemsPerSlide == 0) { if (!$isActive) echo '
'; // Close previous carousel item - echo '