691 lines
29 KiB
PHP
691 lines
29 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class PolicyTransactionModel extends Model
|
|
{
|
|
protected $table = 'policy_transaction';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
protected $protectFields = true;
|
|
protected $allowedFields = [
|
|
'id',
|
|
'issuer',
|
|
'client_id',
|
|
'client_branch_id',
|
|
'insurer_id',
|
|
'insurer_branch_id',
|
|
'tpa_id',
|
|
'tpa_branch_id',
|
|
'client_policy_id',
|
|
'vehicle_id',
|
|
'issue_type',
|
|
'source_client_policy_id',
|
|
'policy_no',
|
|
'cd_ac_no',
|
|
'policy_issue_date',
|
|
'policy_start_date',
|
|
'policy_end_date',
|
|
'action_type',
|
|
'endorsement_no',
|
|
'data_received_date',
|
|
'closure_date',
|
|
'emp_count',
|
|
'dependent_count',
|
|
'status',
|
|
'created_by',
|
|
'updated_by',
|
|
'created_at',
|
|
'updated_at',
|
|
'is_active',
|
|
'invoice_status',
|
|
'invoice_no',
|
|
'revenue_type',
|
|
'tsi',
|
|
'co_share',
|
|
'pre_payable_by',
|
|
'bro_payable_by',
|
|
'ct_status',
|
|
'co_broking_status',
|
|
'installment',
|
|
'installment_data',
|
|
'location',
|
|
'links',
|
|
'stage',
|
|
'etat',
|
|
'etat_band',
|
|
'edate',
|
|
'renewal_date',
|
|
'rollover_date',
|
|
'policy_holder_name',
|
|
'same_as_proposer',
|
|
'ref',
|
|
'spl',
|
|
'fund_received',
|
|
'listed_insurers',
|
|
'ppteam',
|
|
'policy_type_id',
|
|
'endorse_eff_date',
|
|
'sales_generated_by',
|
|
'serviced_by',
|
|
'ct_type',
|
|
'ct_tran_id',
|
|
'remarks',
|
|
'month',
|
|
];
|
|
|
|
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = [];
|
|
protected $afterFind = [];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
|
|
protected function checkAndADDCreatedByValue(array $data)
|
|
{
|
|
// Check if 'updated_by' value is null or empty
|
|
if (empty($data['data']['created_by'])) {
|
|
// Set 'updated_by' value to the current session user ID
|
|
$data['data']['created_by'] = get_session_userid();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function checkAndUpdateUpdatedByValue(array $data)
|
|
{
|
|
// Check if 'updated_by' value is null or empty
|
|
if (empty($data['data']['updated_by'])) {
|
|
// Set 'updated_by' value to the current session user ID
|
|
$data['data']['updated_by'] = get_session_userid();
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
// 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)
|
|
{
|
|
$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.reward,
|
|
pt_co_share_details.bp_amt,
|
|
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(
|
|
(pt_co_share_details.bp_amt * pt_co_share_details.agreed_bp_per +
|
|
(pt_co_share_details.tp_amt + pt_co_share_details.tep_amt) *
|
|
(pt_co_share_details.agreed_tp_per + pt_co_share_details.agreed_tep_per)) / 100,
|
|
2) AS total_irda,
|
|
|
|
ROUND(
|
|
(ROUND(
|
|
(pt_co_share_details.bp_amt * pt_co_share_details.agreed_bp_per +
|
|
(pt_co_share_details.tp_amt + pt_co_share_details.tep_amt) *
|
|
(pt_co_share_details.agreed_tp_per + pt_co_share_details.agreed_tep_per)) / 100,
|
|
2) * 18 / 100),
|
|
2) AS gst_on_revenue,
|
|
|
|
ROUND(
|
|
(ROUND(
|
|
(pt_co_share_details.bp_amt * pt_co_share_details.agreed_bp_per +
|
|
(pt_co_share_details.tp_amt + pt_co_share_details.tep_amt) *
|
|
(pt_co_share_details.agreed_tp_per + pt_co_share_details.agreed_tep_per)) / 100,
|
|
2) +
|
|
ROUND(
|
|
(ROUND(
|
|
(pt_co_share_details.bp_amt * pt_co_share_details.agreed_bp_per +
|
|
(pt_co_share_details.tp_amt + pt_co_share_details.tep_amt) *
|
|
(pt_co_share_details.agreed_tp_per + pt_co_share_details.agreed_tep_per)) / 100,
|
|
2) * 18 / 100),
|
|
2)),
|
|
2) AS total_amt_received,
|
|
insurer_statements.invoice_date,
|
|
insurer_statements.invoice_no,
|
|
insurer_statements.invoice_amount,
|
|
|
|
(
|
|
SELECT
|
|
(SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds)) AS realization_amount
|
|
FROM
|
|
inv_payment_details
|
|
WHERE
|
|
inv_payment_details.statement_id = insurer_statements.id
|
|
AND inv_payment_details.is_active = 1
|
|
|
|
) AS realization_amount,
|
|
|
|
ROUND(
|
|
insurer_statements.invoice_amount -
|
|
(
|
|
SELECT
|
|
(SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds))
|
|
FROM
|
|
inv_payment_details
|
|
WHERE
|
|
inv_payment_details.statement_id = insurer_statements.id
|
|
AND inv_payment_details.is_active = 1
|
|
),
|
|
2) AS outstanding_amount,
|
|
|
|
(
|
|
SELECT
|
|
GROUP_CONCAT(inv_payment_details.utr_no SEPARATOR ', ') AS utr_numbers
|
|
FROM
|
|
inv_payment_details
|
|
WHERE
|
|
inv_payment_details.statement_id = insurer_statements.id
|
|
AND inv_payment_details.is_active = 1
|
|
) AS utr_numbers,
|
|
|
|
(
|
|
SELECT
|
|
GROUP_CONCAT(inv_payment_details.received_date SEPARATOR ', ') AS payment_dates
|
|
FROM
|
|
inv_payment_details
|
|
WHERE
|
|
inv_payment_details.statement_id = insurer_statements.id
|
|
AND inv_payment_details.is_active = 1
|
|
) AS payment_dates
|
|
|
|
")
|
|
->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', 'policy_transaction.insurer_id = insurers.id', 'left')
|
|
->join('insurer_branch', 'policy_transaction.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);
|
|
|
|
// Check if the start date and end date are provided
|
|
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($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');
|
|
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
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');
|
|
|
|
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)
|
|
{
|
|
// 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,
|
|
client_branch.branch_name as client_branch_name,
|
|
insurers.name AS insurer_name,
|
|
insurers.short_name AS insurer_short_name,
|
|
policy_type.policy_type
|
|
')
|
|
->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left')
|
|
->join('clients', 'policy_transaction.client_id = clients.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', 'client_policy.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');
|
|
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
public function getVarienceReportLIst($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0)
|
|
{
|
|
$builder = $this->db->table('policy_transaction')
|
|
->select("
|
|
policy_transaction.id,
|
|
clients.client_name,
|
|
insurers.name AS insurer_name,
|
|
policy_type.policy_type,
|
|
policy_transaction.policy_no,
|
|
policy_transaction.endorsement_no,
|
|
CASE
|
|
WHEN policy_transaction.action_type = 'inception' THEN 'I'
|
|
ELSE 'E'
|
|
END AS action_type,
|
|
pt_co_share_details.exp_amt,
|
|
pt_co_share_details.variance,
|
|
insurer_statements.invoice_amount,
|
|
insurer_statements.invoice_status,
|
|
|
|
ROUND((pt_co_share_details.actual_bp_brokerage_amt + pt_co_share_details.actual_tp_brokerage_amt + pt_co_share_details.actual_tep_brokerage_amt), 2) AS realization_amount2,
|
|
|
|
(
|
|
SELECT
|
|
(SUM(inv_payment_details.inv_amt) + SUM(inv_payment_details.tds)) AS realization_amount
|
|
FROM
|
|
inv_payment_details
|
|
WHERE
|
|
inv_payment_details.statement_id = insurer_statements.id
|
|
AND inv_payment_details.is_active = 1
|
|
|
|
) AS realization_amount,
|
|
|
|
")
|
|
->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('inv_payment_details', 'insurer_statements.id = inv_payment_details.statement_id', 'left')
|
|
->join('clients', 'clients.id = policy_transaction.client_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('pt_co_share_details.actual_bp_brokerage_amt IS NOT NULL AND pt_co_share_details.actual_bp_brokerage_amt != 0')
|
|
->where('pt_co_share_details.variance IS NOT NULL')
|
|
->where('pt_co_share_details.variance !=', 0);
|
|
|
|
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);
|
|
}
|
|
|
|
$builder->orderBy('policy_transaction.id', 'desc');
|
|
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
public function getBusinessReportList($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0)
|
|
{
|
|
$builder = $this->db->table('policy_transaction')
|
|
->select([
|
|
'policy_transaction.id AS policy_trns_id',
|
|
'clients.client_name',
|
|
'insurers.name AS insurer_name',
|
|
'policy_type.policy_type',
|
|
'policy_transaction.policy_no',
|
|
'policy_transaction.endorsement_no',
|
|
"CASE
|
|
WHEN policy_transaction.action_type = 'inception' THEN 'I'
|
|
ELSE 'E'
|
|
END AS action_type",
|
|
'policy_transaction.action_type as action_type_full',
|
|
'pt_co_share_details.bp_amt',
|
|
'pt_co_share_details.tp_amt',
|
|
'pt_co_share_details.tep_amt'
|
|
])
|
|
->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('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.status', 'completed')
|
|
->where('pt_co_share_details.bp_amt IS NULL OR pt_co_share_details.bp_amt = 0');
|
|
|
|
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);
|
|
}
|
|
|
|
$builder->orderBy('policy_transaction.id', 'desc');
|
|
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
public function getFinanceReportList($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0)
|
|
{
|
|
$builder = $this->db->table('policy_transaction')
|
|
->select("
|
|
policy_transaction.id,
|
|
clients.client_name,
|
|
insurers.name AS insurer_name,
|
|
policy_type.policy_type,
|
|
policy_transaction.policy_no,
|
|
policy_transaction.endorsement_no,
|
|
CASE
|
|
WHEN policy_transaction.action_type = 'inception' THEN 'I'
|
|
ELSE 'E'
|
|
END AS action_type,
|
|
policy_transaction.action_type AS action_type_full,
|
|
pt_co_share_details.exp_amt,
|
|
pt_co_share_details.variance
|
|
")
|
|
->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('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.status', 'completed')
|
|
->where('COALESCE(pt_co_share_details.agreed_bp_per, 0) + COALESCE(pt_co_share_details.agreed_tp_per, 0) + COALESCE(pt_co_share_details.agreed_tep_per, 0) = 0')
|
|
->where('COALESCE(pt_co_share_details.actual_bp_amt, 0) + COALESCE(pt_co_share_details.actual_tp_amt, 0) + COALESCE(pt_co_share_details.actual_tep_amt, 0) = 0')
|
|
->where('COALESCE(pt_co_share_details.actual_bp_brokerage_amt, 0) + COALESCE(pt_co_share_details.actual_tp_brokerage_amt, 0) + COALESCE(pt_co_share_details.actual_tep_brokerage_amt, 0) = 0');
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
$builder->orderBy('policy_transaction.id', 'desc');
|
|
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
}
|