0 AND $filter GROUP BY k"); while ($row = mysqli_fetch_assoc($sql)) { $rows[(string) $row['k']] = reportSlaFigures($row); } return $rows; }; $buckets = reportBuckets($period); if ($buckets['unit'] === 'day') { // A day's handful of tickets makes a jumpy line - weeks read better $buckets = reportBuckets(['start' => $period['start'], 'end' => $period['end'], 'days' => 60]); } $by_bucket = $grouped(reportBucketSql('ticket_created_at', $buckets['unit'])); $by_priority = $grouped('ticket_priority'); $by_agent = $grouped('ticket_assigned_to'); $priority_rows = []; foreach (['Urgent', 'High', 'Medium', 'Low'] as $priority) { if (isset($by_priority[$priority])) { $priority_rows[] = ['priority' => $priority] + $by_priority[$priority]; } } $agent_rows = []; $names = []; $sql = mysqli_query($mysqli, "SELECT user_id, user_name, user_avatar FROM users WHERE user_type = 1"); while ($row = mysqli_fetch_assoc($sql)) { $names[intval($row['user_id'])] = $row; } foreach ($by_agent as $user_id => $figures) { $user_id = intval($user_id); $agent_rows[] = ['user_id' => $user_id, 'agent' => $names[$user_id]['user_name'] ?? '', 'avatar' => $names[$user_id]['user_avatar'] ?? ''] + $figures; } usort($agent_rows, function ($a, $b) { return $b['tickets'] <=> $a['tickets']; }); // On screen each share carries its late count; the export keeps every count apart $figure_columns = [ 'tickets' => ['label' => 'Tickets', 'type' => 'count'], 'response_met' => ['label' => 'Replied in time', 'type' => 'count', 'screen' => false], 'response_missed' => ['label' => 'Replied late', 'type' => 'count', 'screen' => false], 'response_percent' => ['label' => 'Response', 'type' => 'percent', 'title' => 'First replies in time, of those judged', 'html' => function ($row) { return reportRateHtml($row['response_percent']) . reportLateHtml($row['response_missed']); }], 'resolution_met' => ['label' => 'Resolved in time', 'type' => 'count', 'screen' => false], 'resolution_missed' => ['label' => 'Resolved late', 'type' => 'count', 'screen' => false], 'resolution_percent' => ['label' => 'Resolution', 'type' => 'percent', 'title' => 'Resolved in time, of those judged', 'html' => function ($row) { return reportRateHtml($row['resolution_percent']) . reportLateHtml($row['resolution_missed']); }], 'resolution_pending' => ['label' => 'Still running', 'type' => 'count', 'class' => 'text-body-secondary', 'title' => 'Resolution clock still running'], ]; $priority_columns = ['priority' => ['label' => 'Priority', 'html' => function ($row) { return reportPriorityDot($row['priority']) . escapeHtml($row['priority']); }]] + $figure_columns; $agent_columns = ['agent' => ['label' => 'Assigned to', 'csv' => function ($row) { return $row['user_id'] ? $row['agent'] : 'Unassigned'; }, 'html' => function ($row) { return formatAssignee($row['user_id'], $row['agent'], $row['avatar'], true); }]] + $figure_columns; $month_rows = []; foreach ($buckets['keys'] as $i => $key) { if (isset($by_bucket[$key])) { $month_rows[] = ['when' => $buckets['labels'][$i]] + $by_bucket[$key]; } } $month_columns = ['when' => ['label' => ucfirst($buckets['unit']), 'sort' => false]] + $figure_columns; if (reportExporting('agents')) { reportCsv('SLA by Agent', $agent_columns, $agent_rows); } if (reportExporting('priorities')) { reportCsv('SLA by Priority', $priority_columns, $priority_rows); } if (reportExporting()) { reportCsv('SLA by ' . ucfirst($buckets['unit']), $month_columns, $month_rows, ['when' => 'Total'] + $overall); } require_once "includes/inc_report_layout.php"; $has_sla = $overall['tickets'] > 0; ?>