Files
nutzwerte_fi4/app/Filament/Pages/Auth/Register.php
T
2025-09-25 14:37:34 +02:00

200 lines
7.4 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\Textarea;
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 User $user;
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(),
/** BESTEHENDES KONTO */
$this->getKontoFormComponent(),
/** NEU */
Fieldset::make('Rechnungsdaten')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->schema([
TextInput::make('company')
->label('Firma')
->required(),
TextInput::make('uid_number')
->label('UID Nummer')
->rules([new VatNumber])
->required(),
Textarea::make('address')
->label('Adresse')
->required(),
TextInput::make('country')
->label('Land')
->default('Österreich')
->required(),
])->columnSpan(4),
Fieldset::make('Kontaktperson')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->schema([
// $this->getKontoGenderFormComponent(),
// $this->getTitleFormComponent(),
// $this->getNameFormComponent(),
// $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([
Checkbox::make('agb_akzeptiert')
->label('ABG akzeptieren')
->required(),
]),
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('company', 'id'))
->searchable()
->required();
}
/**
* KONTO NEU
*/
protected function getTitleFormComponent(): TextInput
{
return TextInput::make('title')
->label('Title')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->required();
}
protected function getKontoGenderFormComponent(): Select
{
return Select::make('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 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('email')
->label('E-Mail')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->unique(table: Konto::class)
->required();
}
protected function getPhoneFormComponent(): PhoneInput
{
return PhoneInput::make('phone')
->label('Telefon')
->visible(fn (Get $get): bool => $get('konto') == 'new')
->defaultCountry('AT');
}
}