<?php
 namespace App\Modules\Citizenship\DE; use App\Core\Citizenship\AbstractCitizenship; class DE extends AbstractCitizenship { public function getVerificationFields(): array { return [ 'individual_id' => [ 'type' => 'text', 'label' => 'Steuerliche Identifikationsnummer', 'placeholder' => '12345678901', 'group' => 'individual', ], 'company_id' => [ 'type' => 'text', 'label' => 'USt-IdNr', 'placeholder' => 'DE123456789', 'group' => 'company', ], ]; } public function validateField(string $fieldKey, string $value, array $allData = []): array { return match ($fieldKey) { 'individual_id' => $this->validateSteuerId($value), 'company_id' => $this->validateUstIdNr($value), default => $this->successResult(), }; } protected function getModuleLabel(): string { return 'DE — Deutschland Identitätsprüfung'; } protected function getModuleDescription(): string { return 'Steuer-ID and USt-IdNr validation for Germany'; } private function validateSteuerId(string $value): array { $value = preg_replace('/\s+/', '', trim($value)); if (! preg_match('/^\d{11}$/', $value)) { return $this->failResult('Steuer-ID muss 11 Ziffern enthalten.'); } if ($value[0] === '0') { return $this->failResult('Steuer-ID darf nicht mit 0 beginnen.'); } $first10 = substr($value, 0, 10); if (! $this->steuerIdDigitDistributionValid($first10)) { return $this->failResult('Steuer-ID: ungültige Ziffernverteilung in den ersten 10 Stellen.'); } if (! $this->steuerIdChecksumValid($value)) { return $this->failResult('Steuer-ID: Prüfziffer stimmt nicht (ISO 7064 MOD 11,10).'); } return $this->successResult('Gültige Steuer-ID (Prüfziffer bestätigt).'); } private function steuerIdDigitDistributionValid(string $first10): bool { $counts = array_count_values(str_split($first10)); $max = max($counts); $distinct = count($counts); if ($max === 2 && $distinct === 9) { return count(array_filter($counts, fn ($c) => $c === 2)) === 1; } if ($max === 3 && $distinct === 8) { if (count(array_filter($counts, fn ($c) => $c === 3)) !== 1) { return false; } $tripleDigit = (string) array_search(3, $counts, true); return ! str_contains($first10, str_repeat($tripleDigit, 3)); } return false; } private function steuerIdChecksumValid(string $value): bool { $product = 10; for ($i = 0; $i < 10; $i++) { $sum = ((int) $value[$i] + $product) % 10; if ($sum === 0) { $sum = 10; } $product = ($sum * 2) % 11; } $check = (11 - $product) % 10; return $check === (int) $value[10]; } private function validateUstIdNr(string $value): array { $value = strtoupper(preg_replace('/\s+/', '', trim($value))); if (! preg_match('/^DE\d{9}$/', $value)) { return $this->failResult('USt-IdNr muss Format DE123456789 haben.'); } return $this->successResult('USt-IdNr: Format gültig (keine Offline-Prüfziffer verfügbar — belastbare Prüfung nur online via VIES/BZSt).'); } } 