partner_id) { $this->redirect(route('dashboard'), navigate: true); return; } $role = $user->roles->first(); if ($role) { $this->roleIcon = $role->icon ?? 'shield-check'; $this->roleName = $role->display_name ?? $role->name; } $this->partner = Partner::with('users')->findOrFail($user->partner_id); $this->partnerType = $this->partner->type; // Vorausfüllen: Partner-Daten $this->companyName = $this->partner->company_name ?? ''; $this->displayName = $this->partner->display_name ?? ''; $this->salutation = $this->partner->salutation ?? ''; $this->firstName = $this->partner->first_name ?? ''; $this->lastName = $this->partner->last_name ?? ''; $this->description = $this->partner->description ?? ''; $this->street = $this->partner->street ?? ''; $this->houseNumber = $this->partner->house_number ?? ''; $this->zip = $this->partner->zip ?? ''; $this->city = $this->partner->city ?? ''; $this->country = $this->partner->country ?? 'Deutschland'; $this->phone = $this->partner->phone ?? ''; $this->website = $this->partner->website ?? ''; // Namen aus User übernehmen, falls Partner-Felder leer sind if (empty($this->firstName) && empty($this->lastName)) { $nameParts = explode(' ', $user->name, 2); $this->firstName = $nameParts[0] ?? ''; $this->lastName = $nameParts[1] ?? ''; } // Definiere Schritte basierend auf Rolle $this->defineSteps(); } protected function defineSteps(): void { $normalizedType = strtolower(str_replace('-', '', $this->partnerType)); switch ($normalizedType) { case 'retailer': $this->steps = ['Stammdaten', 'Liefergebiete', 'Fertig']; $this->totalSteps = 3; break; case 'manufacturer': $this->steps = ['Stammdaten', 'Marke anlegen', 'Fertig']; $this->totalSteps = 3; break; case 'broker': case 'estateagent': $this->steps = ['Stammdaten', 'Fertig']; $this->totalSteps = 2; break; case 'customer': $this->steps = ['Stammdaten', 'Fertig']; $this->totalSteps = 2; break; default: $this->steps = ['Stammdaten', 'Fertig']; $this->totalSteps = 2; break; } } public function saveStep1(): void { $normalizedType = strtolower(str_replace('-', '', $this->partnerType)); $isCustomer = $normalizedType === 'customer'; $isBroker = $normalizedType === 'broker' || $normalizedType === 'estateagent'; $rules = [ 'salutation' => 'required|in:Herr,Frau,Divers', 'firstName' => 'required|string|max:255', 'lastName' => 'required|string|max:255', 'street' => 'required|string|max:255', 'houseNumber' => 'required|string|max:20', 'zip' => 'required|string|max:10', 'city' => 'required|string|max:255', 'country' => 'required|string|max:255', 'phone' => 'nullable|string|max:50', ]; if (!$isCustomer) { $rules['companyName'] = 'required|string|max:255'; $rules['description'] = 'nullable|string|max:1000'; $rules['website'] = 'nullable|url|max:255'; } // Für Broker ist displayName Pflicht if ($isBroker) { $rules['displayName'] = 'required|string|max:255'; } $this->validate($rules, [ 'salutation.required' => __('Bitte wählen Sie eine Anrede.'), 'firstName.required' => __('Bitte geben Sie einen Vornamen ein.'), 'lastName.required' => __('Bitte geben Sie einen Nachnamen ein.'), 'companyName.required' => __('Bitte geben Sie einen Firmennamen ein.'), 'displayName.required' => __('Bitte geben Sie einen Anzeigenamen ein.'), 'street.required' => __('Bitte geben Sie eine Straße ein.'), 'houseNumber.required' => __('Bitte geben Sie eine Hausnummer ein.'), 'zip.required' => __('Bitte geben Sie eine Postleitzahl ein.'), 'city.required' => __('Bitte geben Sie eine Stadt ein.'), 'country.required' => __('Bitte wählen Sie ein Land.'), 'website.url' => __('Bitte geben Sie eine gültige URL ein.'), ]); // Update Partner $updateData = [ 'salutation' => $this->salutation, 'first_name' => $this->firstName, 'last_name' => $this->lastName, 'street' => $this->street, 'house_number' => $this->houseNumber, 'zip' => $this->zip, 'city' => $this->city, 'country' => $this->country, 'phone' => $this->phone, ]; if (!$isCustomer) { $updateData['company_name'] = $this->companyName; $updateData['description'] = $this->description; $updateData['website'] = $this->website; } if ($isBroker) { $updateData['display_name'] = $this->displayName; } $this->partner->update($updateData); // Für Broker und Kunden: Direkt zum Erfolg if ($isBroker || $isCustomer) { $this->completeSetup(); } else { $this->currentStep = 2; } } public function saveStep2Retailer(): void { $this->validate( [ 'deliveryRadius' => 'required|integer|min:1|max:500', 'assemblyRadius' => 'required|integer|min:1|max:500', ], [ 'deliveryRadius.required' => __('Bitte geben Sie einen Lieferradius ein.'), 'deliveryRadius.min' => __('Der Lieferradius muss mindestens 1 km betragen.'), 'assemblyRadius.required' => __('Bitte geben Sie einen Montageradius ein.'), 'assemblyRadius.min' => __('Der Montageradius muss mindestens 1 km betragen.'), ], ); $this->partner->update([ 'delivery_radius_km' => $this->deliveryRadius, 'assembly_radius_km' => $this->assemblyRadius, ]); $this->completeSetup(); } public function saveStep2Manufacturer(): void { $this->validate( [ 'brandName' => 'required|string|max:255', 'brandDescription' => 'nullable|string|max:1000', 'brandLogo' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:2048', ], [ 'brandName.required' => __('Bitte geben Sie einen Markennamen ein.'), 'brandLogo.image' => __('Das Marken-Logo muss eine Bilddatei sein.'), 'brandLogo.mimes' => __('Das Marken-Logo muss im Format JPG, PNG oder WebP sein.'), 'brandLogo.max' => __('Das Marken-Logo darf maximal 2 MB groß sein.'), ], ); // Speichere Brand-Logo falls hochgeladen $brandLogoPath = null; if ($this->brandLogo) { $brandLogoPath = $this->brandLogo->store('brand-logos', 'public'); } // Erstelle Brand Brand::create([ 'partner_id' => $this->partner->id, 'name' => $this->brandName, 'slug' => Str::slug($this->brandName), 'description' => $this->brandDescription, 'logo_url' => $brandLogoPath, 'is_active' => true, ]); $this->completeSetup(); } protected function completeSetup(): void { $this->partner->update([ 'is_active' => true, 'setup_completed' => true, 'setup_completed_at' => now(), ]); // Markiere Registrierungscode als verbraucht, falls vorhanden if ($this->registrationCode && $this->registrationCode->isAvailable()) { $this->registrationCode->markUsed(Auth::user()); session()->forget(['registration_code_id', 'registration_role']); } $this->currentStep = $this->totalSteps; } public function goToDashboard(): void { $this->redirect(route('dashboard'), navigate: true); } public function handleLogout(): void { Auth::guard('web')->logout(); session()->invalidate(); session()->regenerateToken(); $this->redirect(route('home'), navigate: false); } protected function loadRegistrationCode(): void { $codeId = session('registration_code_id'); $role = session('registration_role'); if (!$codeId || !$role) { return; } $this->registrationCode = RegistrationCode::where('id', $codeId) ->where('role', $role) ->first(); if (!$this->registrationCode || !$this->registrationCode->isAvailable()) { // Ungültig/verbraucht -> Session aufräumen session()->forget(['registration_code_id', 'registration_role']); $this->registrationCode = null; } } }; ?> {{-- Konfetti Script laden --}}