Phase 1: Wohnungen, Saisons & Preisberechnung
- Datenmodell Property/Season/Extra (Beträge in Cent), Seeder mit Preisliste 2026 - PriceCalculator: Saison-Splitting, Mindestaufenthalt, Zusatzperson, Endreinigung, Extras, Anzahlung/Restzahlung - Filament-Verwaltung: Wohnungen, Saisons (Überschneidungsprüfung, Lückenwarnung, Kopie ins Folgejahr, Preisrechner), Zusatzleistungen - Tests für Preisberechnung und Saisonverwaltung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bf4c1c0838
commit
2e9a391b37
35 files changed
+1766
-12
No files matched your search
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ExtraPricing;
|
||||
use Database\Factories\ExtraFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* An optional bookable service such as bed linen or towels.
|
||||
*/
|
||||
#[Fillable(['property_id', 'name', 'description', 'price', 'pricing', 'is_active', 'sort_order'])]
|
||||
class Extra extends Model
|
||||
{
|
||||
/** @use HasFactory<ExtraFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'pricing' => ExtraPricing::class,
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Property, $this>
|
||||
*/
|
||||
public function property(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Property::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Extra> $query
|
||||
* @return Builder<Extra>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function active(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\PropertyFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* A rentable holiday apartment. All money amounts are stored in euro cents.
|
||||
*/
|
||||
#[Fillable([
|
||||
'name',
|
||||
'slug',
|
||||
'address',
|
||||
'size_sqm',
|
||||
'max_guests',
|
||||
'included_guests',
|
||||
'extra_guest_fee_per_night',
|
||||
'cleaning_fee',
|
||||
'deposit_percent',
|
||||
'balance_due_days_before_arrival',
|
||||
'check_in_time',
|
||||
'check_out_time',
|
||||
'is_active',
|
||||
])]
|
||||
class Property extends Model
|
||||
{
|
||||
/** @use HasFactory<PropertyFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Season, $this>
|
||||
*/
|
||||
public function seasons(): HasMany
|
||||
{
|
||||
return $this->hasMany(Season::class)->orderBy('starts_on');
|
||||
}
|
||||
|
||||
/**
|
||||
* Periods within [$from, $until) for which no season defines a price.
|
||||
*
|
||||
* @return list<array{from: CarbonImmutable, until: CarbonImmutable}>
|
||||
*/
|
||||
public function uncoveredPeriods(CarbonImmutable $from, CarbonImmutable $until): array
|
||||
{
|
||||
$gaps = [];
|
||||
$cursor = $from;
|
||||
|
||||
foreach ($this->seasons()->overlapping($from, $until)->get() as $season) {
|
||||
if ($season->starts_on->greaterThan($cursor)) {
|
||||
$gaps[] = ['from' => $cursor, 'until' => $season->starts_on];
|
||||
}
|
||||
|
||||
$cursor = $cursor->max($season->ends_on);
|
||||
}
|
||||
|
||||
if ($cursor->lessThan($until)) {
|
||||
$gaps[] = ['from' => $cursor, 'until' => $until];
|
||||
}
|
||||
|
||||
return $gaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Extra, $this>
|
||||
*/
|
||||
public function extras(): HasMany
|
||||
{
|
||||
return $this->hasMany(Extra::class)->orderBy('sort_order');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use Database\Factories\SeasonFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* A pricing period. A night belongs to the season when starts_on <= night < ends_on,
|
||||
* so consecutive seasons share their boundary date (e.g. 03.01.–07.03. and 07.03.–03.04.).
|
||||
*/
|
||||
#[Fillable(['property_id', 'name', 'starts_on', 'ends_on', 'nightly_rate', 'min_nights'])]
|
||||
class Season extends Model
|
||||
{
|
||||
/** @use HasFactory<SeasonFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'starts_on' => 'immutable_date',
|
||||
'ends_on' => 'immutable_date',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Property, $this>
|
||||
*/
|
||||
public function property(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Property::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seasons that share at least one night with the half-open period [$from, $until).
|
||||
*
|
||||
* @param Builder<Season> $query
|
||||
* @return Builder<Season>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function overlapping(Builder $query, CarbonInterface $from, CarbonInterface $until): Builder
|
||||
{
|
||||
return $query
|
||||
->whereDate('starts_on', '<', $until)
|
||||
->whereDate('ends_on', '>', $from);
|
||||
}
|
||||
|
||||
public function containsNight(CarbonInterface $night): bool
|
||||
{
|
||||
return $this->starts_on->lessThanOrEqualTo($night) && $this->ends_on->greaterThan($night);
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -4,6 +4,8 @@
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -12,11 +14,19 @@
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements FilamentUser
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* Only administrators have accounts; there is no public registration.
|
||||
*/
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user