presseportale/app/Console/Commands/ReportLegacyApiCustomers.php
Kevin Adametz 5b8bdf4182
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
12-05-2026 Frontend dev
2026-05-12 18:32:33 +02:00

92 lines
3.2 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Services\Api\LegacyApiCustomerReporter;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class ReportLegacyApiCustomers extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'api:legacy-customers-report
{--portal=all : Portal (presseecho|businessportal24|both|all)}
{--classification=all : Filter (eligible|needs_review|blocked|all)}
{--no-report : Keinen JSON-Report schreiben}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Ermittelt Legacy-API-Kunden aus migrierten Daten und letzter bezahlter Rechnung.';
/**
* Execute the console command.
*/
public function handle(LegacyApiCustomerReporter $reporter): int
{
$portal = (string) $this->option('portal');
$classification = (string) $this->option('classification');
if (! in_array($portal, ['presseecho', 'businessportal24', 'both', 'all'], true)) {
$this->error("Unbekanntes Portal: {$portal}");
return self::FAILURE;
}
if (! in_array($classification, ['eligible', 'needs_review', 'blocked', 'all'], true)) {
$this->error("Unbekannte Klassifizierung: {$classification}");
return self::FAILURE;
}
$report = $reporter->report($portal);
$customers = collect($report['customers']);
if ($classification !== 'all') {
$customers = $customers
->where('classification', $classification)
->values();
}
$this->info('Legacy-API-Kundenreport');
$this->newLine();
$this->line("Portal: {$portal}");
$this->line("Kandidaten: {$report['summary']['total_candidates']}");
$this->line("Freigabefähig: {$report['summary']['eligible']}");
$this->line("Manuell prüfen: {$report['summary']['needs_review']}");
$this->line("Gesperrt: {$report['summary']['blocked']}");
if ($customers->isNotEmpty()) {
$this->newLine();
$this->table(
['ID', 'E-Mail', 'Portal', 'Letzte Rechnung', 'Status', 'Klassifizierung'],
$customers
->take(25)
->map(fn (array $customer): array => [
$customer['user_id'],
$customer['email'],
$customer['portal'],
$customer['latest_legacy_invoice']['number'] ?? '-',
$customer['latest_legacy_invoice']['status'] ?? '-',
$customer['classification'],
])
->all()
);
}
if (! (bool) $this->option('no-report')) {
$path = 'migration/legacy-api-customers-'.now()->format('Ymd-His').'.json';
Storage::disk('local')->put($path, json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$this->newLine();
$this->line("Report geschrieben: storage/app/private/{$path}");
}
return self::SUCCESS;
}
}