submitter ??= $this->submitters->first()?->id; } #[Computed] public function submitters(): \Illuminate\Support\Collection { return app(SubmitterContactReport::class)->submitters(12); } #[Computed] public function user(): ?User { return $this->submitter === null ? null : User::query()->withoutGlobalScopes()->find($this->submitter); } /** * Der Bericht als Text — genau das, was in eine Mail an den Einlieferer * kopiert wird. */ #[Computed] public function plainText(): string { $user = $this->user; if ($user === null) { return ''; } $report = app(SubmitterContactReport::class); $contacts = $report->brokenContacts($user, $this->months); $rejected = $report->rejectedReleases($user, $this->months); $lines = [ sprintf('Kontakt- und Prüfbericht %s', now()->format('d.m.Y')), sprintf('Einlieferer: %s (%s)', $user->name, $user->email), sprintf('Zeitraum: letzte %d Monate', $this->months), '', sprintf('1. Nicht erreichbare E-Mail-Adressen (%d)', $contacts->count()), '', ]; foreach ($contacts as $row) { $lines[] = sprintf('- %s — %s', $row->email, $row->company); $lines[] = sprintf(' Grund: %s%s', $row->reason, $row->detail !== null ? ' ('.$row->detail.')' : ''); $lines[] = sprintf(' Betroffene Meldungen im Zeitraum: %d', $row->releases); } if ($contacts->isEmpty()) { $lines[] = '- keine'; } $lines[] = ''; $lines[] = sprintf('2. Automatisch abgelehnte Meldungen (%d)', $rejected->count()); $lines[] = ''; foreach ($rejected as $release) { $lines[] = sprintf('- %s — %s', $release->title, $release->company); $lines[] = sprintf(' %s: %s', $release->rejectedAt?->format('d.m.Y') ?? '', $release->reason); } if ($rejected->isEmpty()) { $lines[] = '- keine'; } return implode("\n", $lines); } public function downloadContacts(): StreamedResponse { $user = $this->user; abort_if($user === null, 404); $rows = app(SubmitterContactReport::class)->brokenContacts($user, $this->months); $name = sprintf('kontakte-%s-%s.csv', \Illuminate\Support\Str::slug($user->name), now()->format('Y-m-d')); return response()->streamDownload(function () use ($rows): void { $handle = fopen('php://output', 'wb'); fputcsv($handle, ['E-Mail', 'Firma', 'Befund', 'Grund', 'Detail', 'Meldungen', 'Zuletzt'], ';'); foreach ($rows as $row) { fputcsv($handle, [ $row->email, $row->company, $row->fromDomain ? 'Domainprüfung' : 'Rückläufer', $row->reason, $row->detail ?? '', $row->releases, $row->lastEvent?->format('d.m.Y') ?? '', ], ';'); } fclose($handle); }, $name, ['Content-Type' => 'text/csv; charset=UTF-8']); } public function downloadRejected(): StreamedResponse { $user = $this->user; abort_if($user === null, 404); $rows = app(SubmitterContactReport::class)->rejectedReleases($user, $this->months); $name = sprintf('ablehnungen-%s-%s.csv', \Illuminate\Support\Str::slug($user->name), now()->format('Y-m-d')); return response()->streamDownload(function () use ($rows): void { $handle = fopen('php://output', 'wb'); fputcsv($handle, ['ID', 'Titel', 'Firma', 'Datum', 'Begründung'], ';'); foreach ($rows as $row) { fputcsv($handle, [$row->id, $row->title, $row->company, $row->rejectedAt?->format('d.m.Y') ?? '', $row->reason], ';'); } fclose($handle); }, $name, ['Content-Type' => 'text/csv; charset=UTF-8']); } public function with(): array { $user = $this->user; if ($user === null) { return ['contacts' => collect(), 'rejected' => collect(), 'policy' => collect()]; } $report = app(SubmitterContactReport::class); return [ 'contacts' => $report->brokenContacts($user, $this->months), 'rejected' => $report->rejectedReleases($user, $this->months), 'policy' => $report->policyRejections($user, $this->months), ]; } }; ?>
{{ $release->reason }}