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/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..41a4f019 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); - } - - $builder->orderBy('policy_transaction.id', 'desc'); - $result = $builder->get()->getResultArray(); + // Optimize Query Execution + $builder->orderBy('policy_transaction.id', 'desc')->limit(10); - // 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/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php index 6f61ded5..ca90346c 100644 --- a/app/Views/policy_transaction_inception_form.php +++ b/app/Views/policy_transaction_inception_form.php @@ -151,7 +151,7 @@ - + @@ -310,7 +310,7 @@
`; break; case 5: // Co-Share % - newCell = ``; + newCell = ``; break; case 6: // Non commissionable Premium amount % - newCell = ``; + newCell = ``; break; case 7: // Base Premium - newCell = ``; + newCell = ``; break; case 8: // TP Premium - newCell = ``; + newCell = ``; break; case 9: // Ter Premium - newCell = ``; + newCell = ``; break; case 10: // co Premium - newCell = ``; + newCell = ``; break; - case 11: // CGST - newCell = ``; + + case 11: // Co TP Premium + newCell = ``; break; - case 12: // SGST - newCell = ``; + case 12: // Co Ter Premium + newCell = ``; break; - case 13: // IGST - newCell = ``; + + case 13: // CGST + newCell = ``; break; - case 14: // GST Amount - newCell = ``; + case 14: // SGST + newCell = ``; break; - case 15: // Stamp Duty - newCell = ``; + case 15: // IGST + newCell = ``; break; - case 16: // Total + case 16: // GST Amount + newCell = ``; + break; + case 17: // Stamp Duty + newCell = ``; + break; + case 18: // Total newCell = ``; break; - case 17: // Agreed BP % - newCell = ``; + case 19: // Agreed BP % + newCell = ``; break; - case 18: // Agreed TP % - newCell = ``; + case 20: // Agreed TP % + newCell = ``; break; - case 19: // Agreed Ter % - newCell = ``; + case 21: // Agreed Ter % + newCell = ``; break; - case 20: // Agreed Amount - newCell = ``; + case 22: // Agreed Amount + newCell = ``; break; - case 21: // Standard BP % + case 23: // Standard BP % newCell = ``; break; - case 22: // Standard TP % + case 24: // Standard TP % newCell = ``; break; - case 23: // Standard Ter % + case 25: // Standard Ter % newCell = ``; break; - case 24: // Actual BP Amount + case 26: // Actual BP Amount newCell = ``; break; - case 25: // Actual TP Amount + case 27: // Actual TP Amount newCell = ``; break; - case 26: // Actual TEP Amount + case 28: // Actual TEP Amount newCell = ``; break; - case 27: // Actual BP % + case 29: // Actual BP % newCell = ``; break; - case 28: // Actual TP % + case 30: // Actual TP % newCell = ``; break; - case 29: // Actual TEP % + case 31: // Actual TEP % newCell = ``; break; - case 30: // Actual BP Brokerage Amount + case 32: // Actual BP Brokerage Amount newCell = ``; break; - case 31: // Actual TP Brokerage Amount + case 33: // Actual TP Brokerage Amount newCell = ``; break; - case 32: // Actual TEP Brokerage Amount + case 34: // Actual TEP Brokerage Amount newCell = ``; break; - case 33: // Expected Amount - newCell = ``; + case 35: // Expected Amount + newCell = ``; break; // case 34: // Variance - // newCell = ``; + // newCell = ``; // break; - case 34: // ID For Update + case 36: // ID For Update newCell = ``; break; @@ -3804,61 +3887,67 @@ function addInsurerColumn() { newCell = ``; break; case 5: // Co-Share % - newCell = ``; + newCell = ``; break; case 6: // Non commissionable Premium amount % - newCell = ``; + newCell = ``; break; case 7: // Base Premium - newCell = ``; + newCell = ``; break; case 8: // TP Premium - newCell = ``; + newCell = ``; break; case 9: // Ter Premium - newCell = ``; + newCell = ``; break; case 10: // co Premium - newCell = ``; + newCell = ``; break; - case 11: // CGST - newCell = ``; + case 11: // Co TP Premium + newCell = ``; break; - case 12: // SGST - newCell = ``; + case 12: // Co Ter Premium + newCell = ``; break; - case 13: // IGST - newCell = ``; + case 13: // CGST + newCell = ``; break; - case 14: // GST Amount - newCell = ``; + case 14: // SGST + newCell = ``; break; - case 15: // Stamp Duty - newCell = ``; + case 15: // IGST + newCell = ``; break; - case 16: // Total + case 16: // GST Amount + newCell = ``; + break; + case 17: // Stamp Duty + newCell = ``; + break; + case 18: // Total newCell = ``; break; - case 17: // Agreed BP % - newCell = ``; + case 19: // Agreed BP % + newCell = ``; break; - case 18: // Agreed TP % - newCell = ``; + case 20: // Agreed TP % + newCell = ``; break; - case 19: // Agreed Ter % - newCell = ``; + case 21: // Agreed Ter % + newCell = ``; break; - case 20: // Standard BP % + case 22: // Standard BP % newCell = ``; break; - case 21: // Standard TP % + case 23: // Standard TP % newCell = ``; break; - case 22: // Standard Ter % + case 24: // Standard Ter % newCell = ``; break; - case 23: // ID For Update + case 25: // ID For Update newCell = ``; break; } @@ -3879,23 +3968,73 @@ function addInsurerColumn() { var bap = selectedOption.data('bap'); + var client_type_id = $('#client_type').val() ?? 1; + var is_co_pay_yes = $('#cop_yes').prop('checked') ? 1 : 0; + if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){ $('.hideter').show(); $('.hidetp').hide(); + + if(is_co_pay_yes == 1){ + $('.hidecoter').show() + $('.hidecotp').hide() + }else{ + $('.hidecoter').hide() + $('.hidecotp').hide() + } }else{ if(bap == 'Motor'){ + $('.hidetp').show() $('.hideter').hide() + + if(is_co_pay_yes == 1){ + $('.hidecotp').show() + $('.hidecoter').hide() + }else{ + $('.hidecoter').hide() + $('.hidecotp').hide() + } + }else{ $('.hideter').hide() $('.hidetp').hide() + $('.hidecoter').hide() + $('.hidecotp').hide() } } - $('[name="standard_bp[]"]').val(ebp); - $('[name="standard_tp[]"]').val(etp); - $('[name="standard_ter[]"]').val(etep); + var std_bp = 0; + var std_tp = 0; + var std_tep = 0; + + if(client_type_id == 1){ + std_bp = ebp; + std_tp = etp; + std_tep = etep; + }else{ + std_bp = iep; + std_tp = itp; + std_tep = itep; + } + + // console.log('client_type_id', client_type_id); + // console.log('std_bp', std_bp); + // console.log('std_tp', std_tp); + // console.log('std_tep', std_tep); + + // console.log('ebp', ebp); + // console.log('etp', etp); + // console.log('etep', etep); + // console.log('iep', iep); + // console.log('itp', itp); + // console.log('itep', itep); + + + $('[name="standard_bp[]"]').val(std_bp); + $('[name="standard_tp[]"]').val(std_tp); + $('[name="standard_ter[]"]').val(std_tep); if(insurerCount > 1){ $('.follow_insurer').prop('required', true); @@ -3908,19 +4047,16 @@ function addInsurerColumn() { insurer_count_array.push(insurerCount) // Add click event for delete button - $('.delete-insurer').off('click').on('click', function() { - const index = $(this).closest('th').index(); - let count_index = $(this).data('count'); - removeInsurerColumn(index, count_index); - setTimeout(() => { - getColumnIndexes(); - }, 2000); - }); - - // hidePermiumDetailsBasedOnTheTeam() + // $('.delete-insurer').off('click').on('click', function() { + // const index = $(this).closest('th').index(); + // let count_index = $(this).data('count'); + // removeInsurerColumn(index, count_index); + // setTimeout(() => { + // getColumnIndexes(); + // }, 2000); + // }); co_share_percentage_calculation(insurerCount, "add"); - } function removeInsurerColumn(index, count_index) { @@ -3952,6 +4088,13 @@ function populateTable(dataArray, cd_ac_pk) { } console.log('disable_td', disable_td); + console.log('populate cd_ac_pk', cd_ac_pk); + + + if(data.co_share_type == 1){ + if(index == 0) { index = 1;} + getCdAmount(cd_ac_pk, index); + } // Populate the fields with the provided data $('#insurerTable tbody tr').each(function(rowIndex, row) { @@ -3974,7 +4117,7 @@ function populateTable(dataArray, cd_ac_pk) { selectElement.val(cd_ac_pk).prop('selected', true); selectElement.toggleClass('readonly-select', !!disable_td) setTimeout(function(){ - console.log('selectElement', selectElement); + console.log('selectElement setTimeout', selectElement); selectElement.find('option[value="' + cd_ac_pk + '"]').prop('selected', true); selectElement.toggleClass('readonly-select', !!disable_td) }, 2000) @@ -4003,79 +4146,85 @@ function populateTable(dataArray, cd_ac_pk) { case 10: // Co Premium cell.find('input').val(data.cop_amt).toggleClass('readonly-select', !!disable_td); break; - case 11: // CGST + case 11: // Co TP Premium + cell.find('input').val(data.cotp_amt).toggleClass('readonly-select', !!disable_td); + break; + case 12: // Co Ter Premium + cell.find('input').val(data.cotep_amt).toggleClass('readonly-select', !!disable_td); + break; + case 13: // CGST cell.find('input').val(data.bp_cgst).toggleClass('readonly-select', !!disable_td); break; - case 12: // SGST + case 14: // SGST cell.find('input').val(data.bp_sgst).toggleClass('readonly-select', !!disable_td); break; - case 13: // IGST + case 15: // IGST cell.find('input').val(data.bp_igst).toggleClass('readonly-select', !!disable_td); break; - case 14: // GST Amount + case 16: // GST Amount cell.find('input').val(data.bp_gst_amt).toggleClass('readonly-select', !!disable_td); break; - case 15: // Stamp Duty + case 17: // Stamp Duty cell.find('input').val(data.stamp_duty).toggleClass('readonly-select', !!disable_td); break; - case 16: // Total + case 18: // Total cell.find('input').val(data.amount).toggleClass('readonly-select', !!disable_td); break; - case 17: // Agreed BP % + case 19: // Agreed BP % cell.find('input').val(data.agreed_bp_per).toggleClass('readonly-select', !!disable_td); break; - case 18: // Agreed TP % + case 20: // Agreed TP % cell.find('input').val(data.agreed_tp_per).toggleClass('readonly-select', !!disable_td); break; - case 19: // Agreed Ter % + case 21: // Agreed Ter % cell.find('input').val(data.agreed_tep_per).toggleClass('readonly-select', !!disable_td); break; - case 20: // Agreed Amount + case 22: // Agreed Amount cell.find('input').val(data.agreed_amt).toggleClass('readonly-select', !!disable_td); break; - case 21: // Standard BP % + case 23: // Standard BP % cell.find('input').val(data.standerd_bp_per).toggleClass('readonly-select', !!disable_td); break; - case 22: // Standard TP % + case 24: // Standard TP % cell.find('input').val(data.standerd_tp_per).toggleClass('readonly-select', !!disable_td); break; - case 23: // Standard Ter % + case 25: // Standard Ter % cell.find('input').val(data.standerd_tep_per).toggleClass('readonly-select', !!disable_td); break; - case 24: // Actual BP Amount + case 26: // Actual BP Amount cell.find('input').val(data.actual_bp_amount); break; - case 25: // Actual TP Amount + case 27: // Actual TP Amount cell.find('input').val(data.actual_tp_amount); break; - case 26: // Actual Ter Amount + case 28: // Actual Ter Amount cell.find('input').val(data.actual_tep_amount); break; - case 27: // Actual BP % + case 29: // Actual BP % cell.find('input').val(data.actual_bp_percentage); break; - case 28: // Actual TP % + case 30: // Actual TP % cell.find('input').val(data.actual_tp_percentage); break; - case 29: // Actual Ter % + case 31: // Actual Ter % cell.find('input').val(data.actual_tep_percentage); break; - case 30: // Actual BP Brokerage Amount + case 32: // Actual BP Brokerage Amount cell.find('input').val(data.actual_bp_brokerage_amount); break; - case 31: // Actual TP Brokerage Amount + case 33: // Actual TP Brokerage Amount cell.find('input').val(data.actual_tp_brokerage_amount); break; - case 32: // Actual Ter Brokerage Amount + case 34: // Actual Ter Brokerage Amount cell.find('input').val(data.actual_tep_brokerage_amount); break; - case 33: // Expected Amount + case 35: // Expected Amount cell.find('input').val(data.exp_amt); break; // case 34: // Variance // cell.find('input').val(data.variance); // break; - case 34: // Co-share ID (hidden field) + case 36: // Co-share ID (hidden field) cell.find('input[type="hidden"]').val(data.id); break; } @@ -4088,68 +4237,85 @@ function populateTable(dataArray, cd_ac_pk) { case 1: // Is Leader? cell.find('input[type="checkbox"]').prop('checked', data.co_share_type === '1').change().toggleClass('readonly-select', !!disable_td); break; - case 2: // CD Account Number selection - console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); - cell.find('select').val(cd_ac_pk).toggleClass('readonly-select', !!disable_td); + case 2: // CD Account Number + cell.find('select').val(cd_ac_pk); + var selectElement = cell.find('select'); + console.log('selectElement', selectElement); + selectElement.val(cd_ac_pk).prop('selected', true); + selectElement.toggleClass('readonly-select', !!disable_td) + setTimeout(function(){ + console.log('selectElement setTimeout', selectElement); + selectElement.find('option[value="' + cd_ac_pk + '"]').prop('selected', true); + selectElement.toggleClass('readonly-select', !!disable_td) + }, 2000) + break; + case 3: // CD AMOUNT + console.log('------- CD AMOUNT -------') break; - case 3: // follower_policy_no + case 4: // follower_policy_no cell.find('input').val(data.follower_policy_no).toggleClass('readonly-select', !!disable_td); break; - case 4: // co_share_per + case 5: // co_share_per cell.find('input').val(data.co_share_per).toggleClass('readonly-select', !!disable_td); break; - case 5: // non_comm_per_amt + case 6: // non_comm_per_amt cell.find('input').val(data.non_comm_per_amt); break; - case 6: // Base Premium + case 7: // Base Premium cell.find('input').val(data.bp_amt).toggleClass('readonly-select', !!disable_td); break; - case 7: // TP Premium + case 8: // TP Premium cell.find('input').val(data.tp_amt).toggleClass('readonly-select', !!disable_td); break; - case 8: // Ter Premium + case 9: // Ter Premium cell.find('input').val(data.tep_amt).toggleClass('readonly-select', !!disable_td); break; - case 9: // Co Premium + case 10: // Co Premium cell.find('input').val(data.cop_amt).toggleClass('readonly-select', !!disable_td); break; - case 10: // CGST + case 11: // Co TP Premium + cell.find('input').val(data.cotp_amt).toggleClass('readonly-select', !!disable_td); + break; + case 12: // Co Ter Premium + cell.find('input').val(data.cotep_amt).toggleClass('readonly-select', !!disable_td); + break; + case 13: // CGST cell.find('input').val(data.bp_cgst).toggleClass('readonly-select', !!disable_td); break; - case 11: // SGST + case 14: // SGST cell.find('input').val(data.bp_sgst).toggleClass('readonly-select', !!disable_td); break; - case 12: // IGST + case 15: // IGST cell.find('input').val(data.bp_igst).toggleClass('readonly-select', !!disable_td); break; - case 13: // GST Amount + case 16: // GST Amount cell.find('input').val(data.bp_gst_amt).toggleClass('readonly-select', !!disable_td); break; - case 14: // Stamp Duty + case 17: // Stamp Duty cell.find('input').val(data.stamp_duty).toggleClass('readonly-select', !!disable_td); break; - case 15: // Total + case 18: // Total cell.find('input').val(data.amount).toggleClass('readonly-select', !!disable_td); break; - case 16: // Agreed BP % + case 19: // Agreed BP % cell.find('input').val(data.agreed_bp_per).toggleClass('readonly-select', !!disable_td); break; - case 17: // Agreed TP % + case 20: // Agreed TP % cell.find('input').val(data.agreed_tp_per).toggleClass('readonly-select', !!disable_td); break; - case 18: // Agreed Ter % + case 21: // Agreed Ter % cell.find('input').val(data.agreed_tep_per).toggleClass('readonly-select', !!disable_td); break; - case 19: // Standard BP % + case 22: // Standard BP % cell.find('input').val(data.standerd_bp_per).toggleClass('readonly-select', !!disable_td); break; - case 20: // Standard TP % + case 23: // Standard TP % cell.find('input').val(data.standerd_tp_per).toggleClass('readonly-select', !!disable_td); break; - case 21: // Standard Ter % + case 24: // Standard Ter % cell.find('input').val(data.standerd_tep_per).toggleClass('readonly-select', !!disable_td); break; - case 22: // Co-share ID (hidden field) + case 25: // Co-share ID (hidden field) cell.find('input[type="hidden"]').val(data.id); break; } @@ -4158,17 +4324,20 @@ function populateTable(dataArray, cd_ac_pk) { } }); - // console.log('data.cd_ac_pk', cd_ac_pk) - if(data.co_share_type == 1){ - if(index == 0) { index = 1;} - getCdAmount(cd_ac_pk, index); - } + }); // $('input:disabled, select:disabled, textarea:disabled').addClass('readonly-color'); } +$(document).on('click', '.delete-insurer', function() { + const index = $(this).closest('th').index(); + const count_index = $(this).data('count') || $(this).attr('data-count'); // Ensure data attribute is retrieved + removeInsurerColumn(index, count_index); + getColumnIndexes(1); // Remove setTimeout unless necessary +}); + //----------------------------------------------------------------------------------------------------------- function getURLParamsForReport() { @@ -4184,7 +4353,7 @@ function getURLParamsForReport() { show_list_hide_add(); } - console.log('pt_id', pt_id); // Retain the log if necessary + console.log('getURLParamsForReport pt_id', pt_id); // Retain the log if necessary } function validateInput(input, table, field){ @@ -4255,53 +4424,59 @@ function setFormDataFromLocalStorage(formSelector, storageKey) { function checkCDAmountForBasePremium(input) { console.log(input) + let client_type = $('#client_type').val(); + console.log('client type', client_type); - let base_premium = $(input).val(); - console.log("base_premium:", base_premium); + if(client_type == 1){ - // Extract increment value from input ID - let input_id = input.id; - console.log("input_id:", input_id); - let increment = input_id.split("_").pop(); - console.log("increment:", increment); + let base_premium = $(input).val(); + console.log("base_premium:", base_premium); - // Get the corresponding `cd_ac_no` value - let cd_ac_no = $('#cd_ac_no_' + increment).val(); - console.log("cd_ac_no:", cd_ac_no); + // Extract increment value from input ID + let input_id = input.id; + console.log("input_id:", input_id); + let increment = input_id.split("_").pop(); + console.log("increment:", increment); - // Validate inputs - if (!base_premium || !cd_ac_no) { - toastr.warning('Base premium or CD account number is missing', 'WARNING'); - return; - } + // Get the corresponding `cd_ac_no` value + let cd_ac_no = $('#cd_ac_no_' + increment).val(); + console.log("cd_ac_no:", cd_ac_no); - let url = ''; - - // Data to send in the AJAX request - let requestData = { - base_premium: base_premium, - cd_ac_no: cd_ac_no - }; - - // Send AJAX request - sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) { - console.log('Data fetched successfully:', response); - - if (response.status) { - if (!response.base_premium_greater_than_balance) { - console.log('Base premium is less than or equal to CD balance:', 'SUCCESS'); - } else { - toastr.warning('Base premium greater than CD Amount', 'WARNING'); - $(input).val("0") - } - } else { - toastr.error(response.message || 'Unable to fetch data', 'ERROR'); + // Validate inputs + if (!base_premium || !cd_ac_no) { + toastr.warning('Base premium or CD account number is missing', 'WARNING'); + return; } - }, function(xhr, status, error) { - console.error('Error fetching data:', error); - console.error(xhr.responseText); - toastr.error('An error occurred while checking the CD amount.', 'ERROR'); - }); + + let url = ''; + + // Data to send in the AJAX request + let requestData = { + base_premium: base_premium, + cd_ac_no: cd_ac_no + }; + + // Send AJAX request + sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) { + console.log('Data fetched successfully:', response); + + if (response.status) { + if (!response.base_premium_greater_than_balance) { + console.log('Base premium is less than or equal to CD balance:', 'SUCCESS'); + } else { + toastr.warning('Base premium greater than CD Amount', 'WARNING'); + $(input).val("0") + } + } else { + toastr.error(response.message || 'Unable to fetch data', 'ERROR'); + } + }, function(xhr, status, error) { + console.error('Error fetching data:', error); + console.error(xhr.responseText); + toastr.error('An error occurred while checking the CD amount.', 'ERROR'); + }); + + } } function getCdAmount(cd_ac_pk, increment){ @@ -4360,12 +4535,16 @@ $(document).on('change', '#insurerTable input, #insurerTable select, #insurerTab getColumnIndexes() }); -function getColumnIndexes() { +function getColumnIndexes(count = 0) { $('#insurerTable thead th').each(function(index) { if (index === 0) { console.log("columnIndexes is", index); } else { amountCalculation(index); + if(count == 1){ + amountCalculation(index); + } + co_share_percentage_calculation(index); } }); } diff --git a/app/Views/policy_transaction_inception_list.php b/app/Views/policy_transaction_inception_list.php index a74a9a01..3108ff12 100644 --- a/app/Views/policy_transaction_inception_list.php +++ b/app/Views/policy_transaction_inception_list.php @@ -1254,7 +1254,7 @@ $('#issue_type').change(function(){ let value = $(this).val() if(value == 1){ - $('#revenue_type').val('NA'); + $('#revenue_type').val(''); $('#revenue_type option[value="NA"]').show(); $('#revenue_type option[value="EANR"]').show(); $('#revenue_type option[value="EA"]').hide(); diff --git a/writable/cache/.gitkeep b/writable/cache/.gitkeep new file mode 100755 index 00000000..b702fbc3 --- /dev/null +++ b/writable/cache/.gitkeep @@ -0,0 +1,11 @@ + + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + +