FEAT_DYNAMIC_CLAIMS_REPORT_SRINIVAS

This commit is contained in:
Srinivas-Saravanan 2025-02-05 09:50:58 +05:30
commit 2e6eef942e
2 changed files with 114 additions and 41 deletions

View File

@ -144,20 +144,52 @@ class TicketController extends BaseController
{
//action 1 get last 100 rows, action 2 filter and get all rows related to that
if ($action == 1) {
$data = $this->ticketMasterModel
->select('ticket_master.id, ticket_claim_status.claim_status as status,
ticket_master.claim_number as claim_no,ticket_master.tpa_id,ticket_master.emp_name,
insurers.name as insurer_name, clients.client_name,ticket_master.insured_name,clients.short_name,
DATE_FORMAT(ticket_master.created_at, "%d-%m-%Y") as tat')
->select("
ticket_master.id,
ticket_claim_status.claim_status as status,
ticket_master.claim_number as claim_no,
ticket_master.tpa_id,
ticket_master.emp_name,
insurers.name as insurer_name,
clients.client_name,
ticket_master.insured_name,
clients.short_name,
DATE_FORMAT(ticket_master.created_at, '%d-%m-%Y') as ticket_created_date,
CASE
WHEN DATEDIFF(
ticket_master.updated_at,
COALESCE(ticket_master.updated_at, ticket_history.created_at)
) BETWEEN 0 AND 6 THEN '0-6 Days'
WHEN DATEDIFF(
ticket_master.updated_at,
COALESCE(ticket_master.updated_at, ticket_history.created_at)
) BETWEEN 7 AND 12 THEN '7-12 Days'
WHEN DATEDIFF(
ticket_master.updated_at,
COALESCE(ticket_master.updated_at, ticket_history.created_at)
) BETWEEN 13 AND 20 THEN '13-20 Days'
ELSE 'Above 20 Days'
END AS tat
")
->join('insurers', 'insurers.id = ticket_master.insurer_id and insurers.is_active = 1', 'left')
->join('clients', 'clients.id = ticket_master.client_id and clients.is_active = 1', 'left')
->join('ticket_claim_status', 'ticket_claim_status.id = ticket_master.claim_status_id and ticket_claim_status.is_active = 1', 'left')
->join('ticket_history', "ticket_master.id = ticket_history.ticket_id")
->where('ticket_master.is_active', 1)
->where('ticket_history.is_active', 1)
->groupBy('ticket_master.id')
->orderBy('ticket_master.id', 'DESC')
->limit(100)
->findAll();
// dd($data);
return $data;
} else {
$search_data = $this->request->getPost();
// print_r($search_data);
@ -169,15 +201,41 @@ class TicketController extends BaseController
}
// print_rr($where);
$data = $this->ticketMasterModel
->select('ticket_master.id, ticket_claim_status.claim_status as status,
ticket_master.claim_number as claim_no,ticket_master.tpa_id,ticket_master.emp_name,
insurers.name as insurer_name, clients.client_name,ticket_master.insured_name,clients.short_name,
DATE_FORMAT(ticket_master.created_at, "%d-%m-%Y") as tat')
->select("
ticket_master.id,
ticket_claim_status.claim_status as status,
ticket_master.claim_number as claim_no,
ticket_master.tpa_id,
ticket_master.emp_name,
insurers.name as insurer_name,
clients.client_name,ticket_master.insured_name,
clients.short_name,
DATE_FORMAT(ticket_master.created_at, '%d-%m-%Y') as ticket_created_date,
CASE
WHEN DATEDIFF(
ticket_master.updated_at,
COALESCE(ticket_master.updated_at, ticket_history.created_at)
) BETWEEN 0 AND 6 THEN '0-6 Days'
WHEN DATEDIFF(
ticket_master.updated_at,
COALESCE(ticket_master.updated_at, ticket_history.created_at)
) BETWEEN 7 AND 12 THEN '7-12 Days'
WHEN DATEDIFF(
ticket_master.updated_at,
COALESCE(ticket_master.updated_at, ticket_history.created_at)
) BETWEEN 13 AND 20 THEN '13-20 Days'
ELSE 'Above 20 Days'
END AS tat
")
->join('insurers', 'insurers.id = ticket_master.insurer_id and insurers.is_active = 1', 'left')
->join('clients', 'clients.id = ticket_master.client_id and clients.is_active = 1', 'left')
->join('ticket_claim_status', 'ticket_claim_status.id = ticket_master.claim_status_id and ticket_claim_status.is_active = 1', 'left')
->join('ticket_history', "ticket_master.id = ticket_history.ticket_id")
->where('ticket_master.is_active', 1)
->where('ticket_history.is_active', 1)
->where($where)
->groupBy('ticket_master.id')
->orderBy('ticket_master.id', 'DESC')
->findAll();
// print_rr($data);
// log_message('error',' Claims Master Data '.json_encode($data));die();
@ -842,23 +900,24 @@ class TicketController extends BaseController
return 'Ticket id\'s : '.json_encode($ticket_ids);
}
public function ticketReports(){
public function ticketReports()
{
if ($this->request->is('get')){
if ($this->request->is('get')) {
$default_start = new \DateTime();
$data['default_end'] = $default_start->format('d-m-Y');
$data['default_start'] = $default_start->modify('-60 days')->format('d-m-Y');
$data['policy_type'] = $this->ticketType;
$data['account_manager'] = $this->userModel->select('first_name')->where('is_active',1)->where('role',3)->findAll();
$data['default_start'] = $default_start->modify('-60 days')->format('d-m-Y');
$data['policy_type'] = $this->ticketType;
$data['account_manager'] = $this->userModel->select('first_name')->where('is_active', 1)->where('role', 3)->findAll();
$data['report_type'] = [
'acc_manager_wise_status'=>'Account Manger Wise Status Report',
'acc_manager_wise_status' => 'Account Manger Wise Status Report',
'tpa_wise_status' => 'TPA Wise Status Report',
'tat_band_wise' => 'TAT Wise Status Report'
];
//
$this->loadLayout('ticket_reports',$data);
}else{
$this->loadLayout('ticket_reports', $data);
} else {
$received_data = $this->request->getPost();
$from_Date = $received_data['fromDate'];
$to_Date = $received_data['toDate'];
@ -908,8 +967,7 @@ class TicketController extends BaseController
$html = view('claims_report_acc_manager_wise', $viewData);
return $this->respond(['status' => true, 'html' => $html], 200);
}
}elseif ($received_data['report_type'] == 'tpa_wise_status'){
} elseif ($received_data['report_type'] == 'tpa_wise_status') {
$viewData['tpa_wise_data'] = $this->ticketMasterModel->tpaWiseReport($policy_type, $fromDate, $toDate);
@ -935,18 +993,13 @@ class TicketController extends BaseController
$html = view('claims_report_tpa_wise',$viewData);
return $this->respond(['status' => true, 'html' => $html], 200);
}else if ($received_data['report_type'] == 'tat_band_wise'){
} else if ($received_data['report_type'] == 'tat_band_wise') {
$viewData['data'] = $this->ticketMasterModel->getTATReport($policy_type, $fromDate, $toDate);
$html = view('tat_report_band_wise_list',$viewData);
$html = view('tat_report_band_wise_list', $viewData);
return $this->respond(['status' => true, 'html' => $html], 200);
}
}
}
// public function accountManagerWiseReport($policy_type = null ,$start_date = null, $end_date = null){

View File

@ -166,7 +166,7 @@ class TicketMasterModel extends Model
// Fetch claim statuses from the `ticket_claim_status` table
$statusQuery = " SELECT
id, claim_status
id, claim_status, ticket_type
FROM ticket_claim_status
Where is_active = 1
$ticket_type_data_1
@ -176,20 +176,40 @@ class TicketMasterModel extends Model
// Initialize dynamic query parts
$dynamicSelect = '';
// Loop through each claim status and generate the COALESCE and CASE statements for the SELECT
foreach ($statusResult as $status) {
// Dynamically add the COALESCE and CASE for each status in the SELECT part
$columnName = $status['claim_status']; // Default column name
if (empty($ticket_type)) {
// Append the insurance type prefix based on `ticket_type`
switch ($status['ticket_type']) {
case 1:
$columnName = "GMC - {$status['claim_status']}";
break;
case 2:
$columnName = "GPA - {$status['claim_status']}";
break;
case 3:
$columnName = "EDLI - {$status['claim_status']}";
break;
case 4:
$columnName = "GTLI - {$status['claim_status']}";
break;
}
}
$dynamicSelect .= "
COALESCE(
SUM(
CASE
WHEN subquery.status_id = {$status['id']} THEN 1
ELSE 0
END
),
0
) AS `{$status['claim_status']}`, ";
COALESCE(
SUM(
CASE
WHEN subquery.status_id = {$status['id']} THEN 1
ELSE 0
END
),
0
) AS `$columnName`, ";
}
// Remove the trailing comma from the SELECT part
@ -219,15 +239,15 @@ class TicketMasterModel extends Model
tcs.id AS status_id,
CASE
WHEN DATEDIFF(
th.created_at,
tm.updated_at,
COALESCE(tm.updated_at, th.created_at)
) BETWEEN 0 AND 6 THEN '0-6 Days'
WHEN DATEDIFF(
th.created_at,
tm.updated_at,
COALESCE(tm.updated_at, th.created_at)
) BETWEEN 7 AND 12 THEN '7-12 Days'
WHEN DATEDIFF(
th.created_at,
tm.updated_at,
COALESCE(tm.updated_at, th.created_at)
) BETWEEN 13 AND 20 THEN '13-20 Days'
ELSE 'Above 20 Days'