Files
nutzwerte_fi4/app/Filament/Pages/Auth/Register.php
T
2025-10-15 14:13:06 +02:00

217 lines
10 KiB
PHP

<?php
namespace App\Filament\Pages\Auth;
use App\Models\Auftraggeber;
use App\Models\Gutachter;
use App\Models\Konto;
use App\Models\Plan;
use Danielebarbaro\LaravelVatEuValidator\Rules\VatNumber;
use Filament\Auth\Pages\Register as BaseRegister;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Fieldset;
use Filament\Schemas\Components\Icon;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\View;
use Filament\Schemas\Components\Wizard;
use Filament\Schemas\Components\Wizard\Step;
use Filament\Schemas\Schema;
use Filament\Support\Enums\Alignment;
use Filament\Support\Enums\IconPosition;
use Filament\Support\Enums\IconSize;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\HtmlString;
use JaOcero\RadioDeck\Forms\Components\RadioDeck;
use Ysfkaya\FilamentPhoneInput\Forms\PhoneInput;
class Register extends BaseRegister
{
public function form(Schema $schema): Schema
{
return $schema
->components([
Wizard::make([
Step::make('Profile')
->icon('lucide-user-plus')
->description('Benutzer anlegen.')
->schema([
Select::make('gender')
->label('Geschlecht')
->options([
'Herr' => 'Herr',
'Frau' => 'Frau',
'Non-binary' => 'Non-binary',
])
->required()
->validationMessages([
'required' => 'Ein Geschlecht ist erforderlich.',
]),
$this->getNameFormComponent()->validationMessages([
'required' => 'Ein Name ist erforderlich.',
]),
$this->getEmailFormComponent()
->validationMessages([
'required' => 'Eine E-Mail-Adresse ist erforderlich.',
]),
$this->getPasswordFormComponent()
->validationMessages([
'required' => 'Ein Passwort ist erforderlich.',
'same' => 'Das Passwort muß mit dem "Passwort bestätigen" Feld übereinstimmen.',
'min' => [
'string' => 'Das :attribute muß mindestens :min Stellen lang sein.',
],
]),
$this->getPasswordConfirmationFormComponent(),
])->columnSpan(3),
Wizard\Step::make('Konto')
// ->columns(4)
->icon('lucide-key-square')
->description('Mit einem Konto verbinden.')
->schema([
Fieldset::make('Rechnungsdaten')
->schema([
TextInput::make('kontos.company')
->label('Firma')
->required(),
TextInput::make('kontos.uid_number')
->label('UID Nummer')
->rules([new VatNumber])
->required(),
Textarea::make('kontos.address')
->label('Adresse')
->required(),
])->columnSpan(4),
Fieldset::make('Kontaktperson')
->schema([
Select::make('kontos.gender')
->columnSpan(2)
->label('Geschlecht')
->options([
'Herr' => 'Herr',
'Frau' => 'Frau',
'Non-binary' => 'Non-binary',
])
->required(),
TextInput::make('kontos.title')
->label('Titel'),
TextInput::make('kontos.name')
->required(),
TextInput::make('kontos.email')
->label('E-Mail')
->unique(table: Konto::class)
->required(),
PhoneInput::make('kontos.phone')
->label('Telefon')
->defaultCountry('AT'),
])->columnSpan(4),
Fieldset::make('Mit diesen Daten auch einen')
->schema([
Checkbox::make('gutachter_anlegen')->inline(),
Checkbox::make('auftraggeber_anlegen')->inline(),
])->columnSpan(4),
]),
// Wizard\Step::make('Zahlungsmodus')
// ->icon('phosphor-coins')
// ->visible(fn (Get $get): bool => $get('register-modus') == 'new')
// ->description('Drei Optionen stehen zur Auswahl')
// ->schema([
// Section::make('Zahlungsoptionen')
// ->description('können jederzeit geändert werden. Im Moment bieten wir nur unseren Basic Plan an.')->columnSpanFull(),
// RadioDeck::make('plan_id')
// ->label('Wählen sie eine Option')
// ->options(fn () => Plan::pluck('name', 'id')->toArray())
// ->descriptions(Plan::options())
// ->icons(fn () => Plan::pluck('icon', 'id')->toArray())
// ->required()
// ->default(1)
// ->disabled()
// ->iconPosition(IconPosition::Before) // Before | After
// ->iconSize(IconSize::ExtraLarge)
// ->alignment(Alignment::Center) // Start | Center | End
// ->padding('p-2') // Padding around the deck
// ->extraCardsAttributes([
// 'class' => 'rounded-xl drop-shadow-xl mt-1',
// ])
// ->extraOptionsAttributes([
// 'class' => 'text-2xl font-black tracking-tight lg:text-3xl',
// ])
// ->colors('primary')
// ->columns(3)
// ->columnSpanFull(),
// ]),
Wizard\Step::make('AGB')
->icon('lucide-receipt-text')
->description('Allgemeine Geschäftsbedingungen')
->schema([
Fieldset::make('Bitte lesen und akzeptieren Sie die Allgemeinen Geschäftsbedinnungen.')
->schema([
View::make('pages.agb'),
Checkbox::make('agb_akzeptiert')
->default(false)
->label('Allgemeinen Geschäftsbedinnungen akzeptieren')
->accepted()
->validationMessages([
'accepted' => 'Das Akzeptieren der Allgemeinen Geschäftsbedinnungen ist erforderlich.',
]),
])->columns(1),
]),
])->submitAction(new HtmlString(Blade::render(<<<'BLADE'
<x-filament::button
type="submit"
size="sm"
wire:submit="register"
>
Registrieren
</x-filament::button>
BLADE))),
]);
}
protected function getFormActions(): array
{
return [];
}
public function handleRegistration(array $data): Model
{
// dd($data);
if (isset($data['kontos'])) {
$konto = new Konto($data['kontos']);
$konto->save();
$data['konto_id'] = $konto->id;
unset($data['kontos']['uid_number']);
}
if (isset($data['gutachter_anlegen'])) {
$gutachter = new Gutachter($data['kontos']);
$gutachter->konto_id = $konto->id;
$gutachter->save();
}
if (isset($data['auftraggeber_anlegen'])) {
$auftraggeber = new Auftraggeber($data['kontos']);
$auftraggeber->konto_id = $konto->id;
$auftraggeber->save();
}
unset($data['gutachter_anlegen']);
unset($data['auftraggeber_anlegen']);
unset($data['kontos']);
$user = parent::handleRegistration($data);
return $user;
}
}