89 lines
3.4 KiB
PHP
89 lines
3.4 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Pages;
|
||
|
||
use App\Enums\UserRole;
|
||
use App\Filament\Concerns\FollowsAdminMode;
|
||
use App\Filament\Resources\Properties\Pages\EditProperty;
|
||
use App\Filament\Resources\Properties\RelationManagers\ExtrasRelationManager;
|
||
use App\Filament\Resources\Properties\RelationManagers\SeasonsRelationManager;
|
||
use App\Filament\Resources\Properties\RelationManagers\SpecialOffersRelationManager;
|
||
use App\Models\Property;
|
||
use BackedEnum;
|
||
use Filament\Forms\Components\Select;
|
||
use Filament\Pages\Page;
|
||
use Filament\Schemas\Components\Livewire;
|
||
use Filament\Schemas\Components\Tabs;
|
||
use Filament\Schemas\Components\Tabs\Tab;
|
||
use Filament\Schemas\Components\Text;
|
||
use Filament\Schemas\Schema;
|
||
use Filament\Support\Icons\Heroicon;
|
||
use Livewire\Attributes\Url;
|
||
use UnitEnum;
|
||
|
||
/**
|
||
* The yearly price work in one place, without the other apartment settings: seasons & prices,
|
||
* special offers & promo codes, extras. Reuses the relation managers of the apartment.
|
||
*/
|
||
class PricesAndOffers extends Page
|
||
{
|
||
use FollowsAdminMode;
|
||
|
||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCurrencyEuro;
|
||
|
||
protected static string|UnitEnum|null $navigationGroup = 'Vermietung';
|
||
|
||
protected static ?string $navigationLabel = 'Preise & Angebote';
|
||
|
||
protected static ?string $title = 'Preise & Angebote';
|
||
|
||
protected static ?string $slug = 'preise-und-angebote';
|
||
|
||
protected static ?int $navigationSort = 5;
|
||
|
||
#[Url(as: 'wohnung')]
|
||
public ?int $propertyId = null;
|
||
|
||
public static function canAccess(): bool
|
||
{
|
||
return (bool) auth()->user()?->hasRole(UserRole::Admin, UserRole::Rentals);
|
||
}
|
||
|
||
public function mount(): void
|
||
{
|
||
$this->propertyId ??= Property::query()->where('is_active', true)->value('id') ?? Property::query()->value('id');
|
||
}
|
||
|
||
public function content(Schema $schema): Schema
|
||
{
|
||
$property = Property::find($this->propertyId);
|
||
if ($property === null) {
|
||
return $schema->components([Text::make('Es ist noch keine Wohnung angelegt (Expertenansicht › Wohnungen).')]);
|
||
}
|
||
|
||
$context = ['ownerRecord' => $property, 'pageClass' => EditProperty::class];
|
||
|
||
return $schema->components([
|
||
Select::make('propertyId')
|
||
->label('Wohnung')
|
||
->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all())
|
||
->live()
|
||
->afterStateUpdated(fn () => $this->redirect(static::getUrl(['wohnung' => $this->propertyId])))
|
||
->visible(fn (): bool => Property::query()->count() > 1),
|
||
Tabs::make('prices')
|
||
->persistTabInQueryString()
|
||
->tabs([
|
||
Tab::make('Saisons & Preise')->icon(Heroicon::OutlinedCalendar)->schema([
|
||
Livewire::make(SeasonsRelationManager::class, $context)->key("seasons-{$property->id}"),
|
||
]),
|
||
Tab::make('Sonderangebote & Rabattcodes')->icon(Heroicon::OutlinedSparkles)->schema([
|
||
Livewire::make(SpecialOffersRelationManager::class, $context)->key("offers-{$property->id}"),
|
||
]),
|
||
Tab::make('Extras')->icon(Heroicon::OutlinedGift)->schema([
|
||
Livewire::make(ExtrasRelationManager::class, $context)->key("extras-{$property->id}"),
|
||
]),
|
||
]),
|
||
]);
|
||
}
|
||
}
|