diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 4dd09ce2..7f340fa5 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -45,6 +45,7 @@ use App\Controllers\GoogleDriveController; use App\Helpers\sendMailNotification; use App\Models\RFQModel; +use App\Models\TicketMasterModel; class ClientController extends AdminController { @@ -4047,11 +4048,11 @@ class ClientController extends AdminController // -----------BDS REPORT CONTROLLER--------------------------------------------------------------------------------- - $BDSReportController = new BDSReportController(); + // $BDSReportController = new BDSReportController(); - $data['data'] = $BDSReportController->getBAPInsurerData(); + // $data['data'] = $BDSReportController->getBAPInsurerData(); - return $this->loadLayout('irda_bap_insurer_report_list', $data); + // return $this->loadLayout('irda_bap_insurer_report_list', $data); // $data['data'] = $BDSReportController->getBAPClientData(); // return $this->loadLayout('irda_bap_client_report_list', $data); @@ -4080,6 +4081,15 @@ class ClientController extends AdminController // $result = MailHelper::send_email($data[0]); // echo json_encode($result); // log_message('error',json_encode($result)); + + //-------------------------------------------------------------------------------------------------------- + + $ticketModel = new TicketMasterModel(); + $reportData['data'] = $ticketModel->getTATReport(1); + // print_rr($reportData); + $this->loadLayout('tat_report_band_wise_list', $reportData); + // $data = $ticketModel->getTATReport(1); + } // ------------------------------------------------------------------------------------------------------- diff --git a/app/Models/TicketMasterModel.php b/app/Models/TicketMasterModel.php index 2d562005..87998389 100644 --- a/app/Models/TicketMasterModel.php +++ b/app/Models/TicketMasterModel.php @@ -146,5 +146,125 @@ class TicketMasterModel extends Model return $ticket_data; } + //get TAT report BAND wise Data + public function getTATReport($ticket_type = null, $start_date = null, $end_date = null) + { + //set default last 3 months data date + $fromDate = date('Y-m-d', strtotime('-90 days')); + $toDate = date('Y-m-d 23:59:59'); + if (!empty($start_date) && !empty($end_date)) { + $fromDate = change_date_format($start_date); + $toDate = change_date_format($end_date); + } + $ticket_type_data_1 = ""; + $ticket_type_data_2 = ""; + if(!empty($ticket_type)){ + $ticket_type_data_1 = "WHERE ticket_type = $ticket_type"; + $ticket_type_data_2 = "AND tm.ticket_type_id = $ticket_type"; + } + + // Fetch claim statuses from the `ticket_claim_status` table + $statusQuery = " SELECT + id, claim_status + FROM ticket_claim_status + $ticket_type_data_1 + "; + $statusResult = $this->db->query($statusQuery)->getResultArray(); + // dd($statusResult); + + // 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 + $dynamicSelect .= " + COALESCE( + SUM( + CASE + WHEN subquery.status_id = {$status['id']} THEN 1 + ELSE 0 + END + ), + 0 + ) AS `{$status['claim_status']}`, "; + } + + // Remove the trailing comma from the SELECT part + $dynamicSelect = rtrim($dynamicSelect, ', '); + // dd($dynamicSelect); + + + // Construct the full SQL query + $sql = " + SELECT + tc.TAT_Category, + $dynamicSelect + FROM + ( + SELECT 'Above 20 Days' AS TAT_Category + UNION ALL + SELECT '13-20 Days' + UNION ALL + SELECT '7-12 Days' + UNION ALL + SELECT '0-6 Days' + ) AS tc + LEFT JOIN ( + SELECT + th.ticket_id, + tcs.claim_status, + tcs.id AS status_id, + CASE + WHEN DATEDIFF( + th.created_at, + COALESCE(tm.updated_at, th.created_at) + ) BETWEEN 0 AND 6 THEN '0-6 Days' + WHEN DATEDIFF( + th.created_at, + COALESCE(tm.updated_at, th.created_at) + ) BETWEEN 7 AND 12 THEN '7-12 Days' + WHEN DATEDIFF( + th.created_at, + COALESCE(tm.updated_at, th.created_at) + ) BETWEEN 13 AND 20 THEN '13-20 Days' + ELSE 'Above 20 Days' + END AS TAT_Category + FROM + ticket_master tm + JOIN ticket_history th ON tm.id = th.ticket_id + JOIN ticket_claim_status tcs ON th.field_name = 'claim_status_id' + AND th.new_value = tcs.id + $ticket_type_data_2 + AND tm.created_at >= '$fromDate' + AND tm.created_at <= '$toDate' + ) AS subquery ON tc.TAT_Category = subquery.TAT_Category + GROUP BY + tc.TAT_Category + ORDER BY + FIELD( + tc.TAT_Category, + 'Above 20 Days', + '13-20 Days', + '7-12 Days', + '0-6 Days' + ); + "; + + // Execute the query and return the result + $data = $this->db->query($sql)->getResultArray(); + // dd($this->db->getLastQuery(), $data); + + $tableData = []; + if (!empty($data)) { + // Extract table headers from the first row keys + $headers = array_keys($data[0]); + $tableData['headers'] = $headers; + $tableData['body'] = $data; + } + + return $data; + } + } diff --git a/app/Views/tat_report_band_wise_list.php b/app/Views/tat_report_band_wise_list.php new file mode 100644 index 00000000..204b4542 --- /dev/null +++ b/app/Views/tat_report_band_wise_list.php @@ -0,0 +1,101 @@ + + +
| = esc($header) ?> | + +
|---|
| = esc($value) ?> | + +