Files
fewo-stommer/app/Filament/Pages/OccupancyCalendar.php
LarsandClaude Opus 5.5 8bcda9a4bc Wohnungsumschalter im Verwaltungsmenue und wohnungsbezogene Listen
Oben im Seitenmenue waehlt man die Wohnung; Listen, neue Eintraege, Belegungsplan
und Preise & Angebote folgen ihr. Ein geoeffneter Eintrag einer anderen Wohnung
schaltet auf diese um. Galerie und Ersatz-Titelbild der Website zeigen nur Fotos
der Wohnung des Bausteins und Fotos ohne Wohnung.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 18:40:13 +01:00

78 lines
2.3 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Availability\OccupancyOverview;
use App\Filament\Concerns\FollowsAdminMode;
use App\Models\Booking;
use App\Models\Property;
use App\Support\CurrentProperty;
use BackedEnum;
use Carbon\CarbonImmutable;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Validator;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Url;
use UnitEnum;
class OccupancyCalendar extends Page
{
use FollowsAdminMode;
protected string $view = 'filament.pages.occupancy-calendar';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCalendarDays;
protected static string|UnitEnum|null $navigationGroup = 'Vermietung';
protected static ?string $title = 'Belegungsplan';
protected static ?string $navigationLabel = 'Belegungsplan';
protected static ?string $slug = 'belegungsplan';
protected static ?int $navigationSort = 0;
#[Url(as: 'monat')]
public string $month = '';
#[Url(as: 'wohnung')]
public ?int $propertyId = null;
public static function canAccess(): bool
{
return Gate::allows('viewAny', Booking::class);
}
public function getSubheading(): ?string
{
return app(CurrentProperty::class)->hasChoice() ? Property::query()->find($this->propertyId)?->name : null;
}
public function mount(): void
{
$this->month = $this->month ?: now()->format('Y-m');
$this->propertyId = app(CurrentProperty::class)->followUrl($this->propertyId);
}
#[Computed]
public function calendar(): ?array
{
Validator::make(['month' => $this->month], ['month' => ['required', 'date_format:Y-m']])->validate();
if ($this->propertyId === null) {
return null;
}
return app(OccupancyOverview::class)->calendar(Property::findOrFail($this->propertyId), CarbonImmutable::createFromFormat('!Y-m', $this->month));
}
public function moveMonth(int $direction): void
{
Validator::make(['month' => $this->month, 'direction' => $direction], ['month' => ['required', 'date_format:Y-m'], 'direction' => ['in:-1,1']])->validate();
$this->month = CarbonImmutable::createFromFormat('!Y-m', $this->month)->addMonths($direction)->format('Y-m');
unset($this->calendar);
}
}