> $rows @return list> */ public function build(array $rows, string $audience = 'internal'): array { $filters = $this->filters ?? new ReportFilters(); $mapper = $this->mapper ?? new ReportDataMapper(); $totals = []; foreach ($rows as $row) { if (!$filters->matches($row)) continue; $key = (string)(int)($row['technician_id'] ?? 0) . ':' . (string)(int)($row['client_id'] ?? 0); if (!isset($totals[$key])) $totals[$key] = ['technician_id' => (int)($row['technician_id'] ?? 0), 'technician_name' => (string)($row['technician_name'] ?? ''), 'client_id' => (int)($row['client_id'] ?? 0), 'client_name' => (string)($row['client_name'] ?? ''), 'hours' => 0.0, 'sla_hours' => 0.0]; $hours = max(0.0, (float)($row['hours'] ?? 0)); $totals[$key]['hours'] += $hours; if (!empty($row['counts_toward_sla'])) $totals[$key]['sla_hours'] += $hours; } $result = array_values($totals); foreach ($result as &$item) { $item['hours'] = round($item['hours'], 2); $item['sla_hours'] = round($item['sla_hours'], 2); if ($audience === 'client') $item = $mapper->clientActivity($item); } unset($item); usort($result, static fn(array $a,array $b): int => strcmp((string)($a['technician_name'] ?? ''), (string)($b['technician_name'] ?? '')) ?: ((int)($a['technician_id'] ?? 0) <=> (int)($b['technician_id'] ?? 0))); return $result; } public function query(array $rows, string $audience = 'internal'): array { return $this->build($rows, $audience); } }