Files
nutzwerte_fi4/app/Filament/Pages/Auth/Register.php
T
2025-09-21 18:10:18 +02:00

254 lines
8.9 KiB
PHP

<?php
namespace App\Filament\Pages\Auth;
use App\Models\Konto;
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\TextInput;
use Filament\Schemas\Components\Fieldset;
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 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([
$this->getGenderFormComponent(),
$this->getNameFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
])->columnSpan(3),
Wizard\Step::make('Konto')
// ->columns(4)
->icon('lucide-key-square')
->description('Mit einem Konto verbinden.')
->schema([
$this->getKontoModusFormComponent(),
/** OLD */
$this->getKontoFormComponent(),
/** NEU */
Fieldset::make('Rechnungsdaten')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->schema([
$this->getCompanyFormComponent(),
$this->getUIDFormComponent(),
$this->getPLZFormComponent(),
$this->getLocationFormComponent(),
$this->getAdresseFormComponent(),
$this->getCountryFormComponent(),
])->columnSpan(4),
Fieldset::make('Kontaktperson')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->schema([
$this->getKontoGenderFormComponent(),
$this->getTitleFormComponent(),
$this->getKontoFirstNameFormComponent(),
$this->getKontoLastNameFormComponent(),
$this->getKontoEmailFormComponent(),
$this->getPhoneFormComponent(),
])->columnSpan(4),
]),
Wizard\Step::make('AGB')
->icon('lucide-receipt-text')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->description(' Allgemein Geschäftsbedignugen')
->schema([
Fieldset::make('Bitte lesen und akzeptieren Sie die allgemeinen Geschäftsbedignungen um die Registrierung abzuschließen.')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->schema([
$this->getABGFormComponent(),
]),
View::make('pages.agb'),
]),
]),
]);
}
/**
* MODUS
*/
protected function getKontoModusFormComponent(): Select
{
return Select::make('konto')
->columnSpan(4)
->label('Registriermodus')
->prefixIcon('lucide-key-square')
->prefixIconColor('primary')
->aboveLabel([
'Bitte wählen Sie ein bestehendes Konto oder erstellen Sie ein neues. Eine Registrierung bei einem bestehenden Konto muß vom Kontoinhaber bestätigt werden.',
])
->options([
'old' => 'Mit einem bestehenden Konto verbinden',
'new' => 'Ein neues Konto erstellen',
])
->live()
->required();
}
/**
* USER
*/
protected function getGenderFormComponent(): Select
{
return Select::make('gender')
->label('Geschlecht')
->options([
'Herr' => 'Herr',
'Frau' => 'Frau',
'Non-binary' => 'Non-binary',
])
->required();
}
/**
* KONTO WÄHLEN
*/
protected function getKontoFormComponent(): Select
{
return Select::make('konto_id')
->columnSpan(4)
->label('Konto auswählen')
->belowLabel([
'Um das erstellte Profil zu aktivieren muß der Kontoinhaber die Anmeldung im Programm freischalten',
])
->visible(fn (Get $get): bool => $get('konto') == 'old')
->options(Konto::query()->pluck('konto_company', 'id'))
->searchable()
->required();
}
/**
* KONTO NEU
*/
protected function getABGFormComponent(): Checkbox
{
return Checkbox::make('konto_agb_akzeptiert')
->label('ABG akzeptieren')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getTitleFormComponent(): TextInput
{
return TextInput::make('konto_title')
->label('Title')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getKontoGenderFormComponent(): Select
{
return Select::make('konto_gender')
->columnSpan(2)
->label('Geschlecht')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->options([
'Herr' => 'Herr',
'Frau' => 'Frau',
'Non-binary' => 'Non-binary',
])
->required();
}
protected function getKontoFirstNameFormComponent(): TextInput
{
return TextInput::make('konto_first_name')
->label('Vorname')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getKontoLastNameFormComponent(): TextInput
{
return TextInput::make('konto_last_name')
->label('Nachname')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getCompanyFormComponent(): TextInput
{
return TextInput::make('konto_company')
->label('Firma')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getKontoEmailFormComponent(): TextInput
{
return TextInput::make('konto_email')
->label('E-Mail')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->unique(table: Konto::class)
->required();
}
protected function getAdresseFormComponent(): TextInput
{
return TextInput::make('konto_address')
->label('Adresse')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getLocationFormComponent(): TextInput
{
return TextInput::make('konto_location')
->label('Ort')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getPLZFormComponent(): TextInput
{
return TextInput::make('konto_plz')
->label('Postleitzahl')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getPhoneFormComponent(): PhoneInput
{
return PhoneInput::make('konto_phone')
->label('Telefon')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->defaultCountry('AT');
}
protected function getCountryFormComponent(): TextInput
{
return TextInput::make('konto_country')
->label('Land')
->default('Österreich')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getUIDFormComponent(): TextInput
{
return TextInput::make('konto_uid_number')
->label('UID Nummer')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->rules([new VatNumber])
->required();
}
}