Zentralen Belegungsplan und plattformuebergreifende Buchungs- und Gaesteverwaltung integrieren
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m41s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m41s
This commit is contained in:
1 parent
c74199e978
commit
f369018a68
41 files changed
+1343
-157
No files matched your search
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Availability\OccupancyOverview;
|
||||
use App\Filament\Concerns\FollowsAdminMode;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Property;
|
||||
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 mount(): void
|
||||
{
|
||||
$this->month = $this->month ?: now()->format('Y-m');
|
||||
$this->propertyId ??= Property::query()->where('is_active', true)->value('id') ?? Property::query()->value('id');
|
||||
}
|
||||
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user