Phase 2: Kalender, Anfrage, Vorreservierung & Sonderangebote
- Gäste, Buchungen (Status-Workflow), Sperrzeiten, Sonderangebote - Vorreservierung mit Haltezeit je Wohnung; abgelaufene Holds geben den Kalender sofort frei, Cron setzt Status und benachrichtigt - Sonderangebote/Sonderkonditionen: %, € pro Aufenthalt, Sonderpreis/Nacht, Gratis-Nächte; Bedingungen u. a. Saison, Vorlauf, Wochentag, Nächte, Aktionscode; bestes Einzel- vs. kombinierte Angebote - Öffentliche Seite /buchen: Belegungskalender, Live-Preis, Anfrageformular (Honeypot, Rate-Limit) - E-Mails: Angebot an Gast, Benachrichtigung Vermieter, Bestätigung, Absage, Ablauf - Filament: Anfragen & Buchungen (bestätigen, ablehnen, verlängern, stornieren, Telefonbuchung), Gäste, Sperrzeiten, Sonderangebote - Deutsche Validierungstexte Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2e9a391b37
commit
08b6582fa1
79 files changed
+6213
-76
No files matched your search
@@ -63,3 +63,11 @@ AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
|
||||
FEWO_OWNER_NAME="Brigitte Stommer"
|
||||
FEWO_OWNER_EMAIL=fewo@stommer.de
|
||||
FEWO_NOTIFICATION_EMAIL=fewo@stommer.de
|
||||
FEWO_BANK_ACCOUNT_HOLDER=
|
||||
FEWO_BANK_IBAN=
|
||||
FEWO_BANK_BIC=
|
||||
FEWO_BANK_NAME=
|
||||
@@ -8,6 +8,10 @@ # Ferienwohnung Stommer
|
||||
- Season periods are half-open: a night belongs to a season when `starts_on <= night < ends_on`.
|
||||
- Pricing lives in `app/Pricing` (`PriceCalculator` → `PriceQuote`); guest-facing errors are `QuoteException` messages.
|
||||
- Portals must be integrated through a pluggable channel-connector system (see concept §7), never hard-coded.
|
||||
- Bookings/blocks use nights: `arrival <= night < departure`; same-day changeover is allowed. Reservations with an elapsed hold never occupy the calendar (scope `Booking::occupying()`), cron only updates status.
|
||||
- Business operations live in `app/Actions` (CreateReservation, ConfirmBooking, …); Filament pages and Livewire components call them instead of changing bookings directly.
|
||||
- Special offers are evaluated automatically by `PriceCalculator`; discounts are `QuoteLineType::Discount` lines with negative amounts.
|
||||
- Vite fonts plugin is removed on purpose (corporate proxy breaks remote font downloads, and fonts must be self-hosted for GDPR).
|
||||
- PHP/Composer on this machine: winget package dir `%LOCALAPPDATA%\Microsoft\WinGet\Packages\PHP.PHP.8.4_*` (Composer as `composer\composer.phar` there).
|
||||
- Git remote: Gitea `https://gitea.stommer.de/Lars/fewo-stommer.git`, branch `main`.
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ # Ferienwohnung Stommer
|
||||
- Season periods are half-open: a night belongs to a season when `starts_on <= night < ends_on`.
|
||||
- Pricing lives in `app/Pricing` (`PriceCalculator` → `PriceQuote`); guest-facing errors are `QuoteException` messages.
|
||||
- Portals must be integrated through a pluggable channel-connector system (see concept §7), never hard-coded.
|
||||
- Bookings/blocks use nights: `arrival <= night < departure`; same-day changeover is allowed. Reservations with an elapsed hold never occupy the calendar (scope `Booking::occupying()`), cron only updates status.
|
||||
- Business operations live in `app/Actions` (CreateReservation, ConfirmBooking, …); Filament pages and Livewire components call them instead of changing bookings directly.
|
||||
- Special offers are evaluated automatically by `PriceCalculator`; discounts are `QuoteLineType::Discount` lines with negative amounts.
|
||||
- Vite fonts plugin is removed on purpose (corporate proxy breaks remote font downloads, and fonts must be self-hosted for GDPR).
|
||||
- PHP/Composer on this machine: winget package dir `%LOCALAPPDATA%\Microsoft\WinGet\Packages\PHP.PHP.8.4_*` (Composer as `composer\composer.phar` there).
|
||||
- Git remote: Gitea `https://gitea.stommer.de/Lars/fewo-stommer.git`, branch `main`.
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Availability\AvailabilityChecker;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Mail\BookingConfirmed;
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/**
|
||||
* The landlord accepts a reservation. Expired reservations can still be confirmed while the dates are free.
|
||||
*/
|
||||
class ConfirmBooking
|
||||
{
|
||||
public function __construct(private AvailabilityChecker $availability) {}
|
||||
|
||||
/**
|
||||
* @throws ReservationException
|
||||
*/
|
||||
public function handle(Booking $booking, bool $notifyGuest = true): void
|
||||
{
|
||||
if (! in_array($booking->status, [BookingStatus::Reserved, BookingStatus::Expired], true)) {
|
||||
throw ReservationException::invalidTransition($booking->status->getLabel(), 'bestätigt');
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($booking): void {
|
||||
if (! $this->availability->isAvailable($booking->property, $booking->arrival, $booking->departure, ignore: $booking)) {
|
||||
throw ReservationException::notAvailable();
|
||||
}
|
||||
|
||||
$booking->update([
|
||||
'status' => BookingStatus::Confirmed,
|
||||
'hold_expires_at' => null,
|
||||
'confirmed_at' => now(),
|
||||
]);
|
||||
});
|
||||
|
||||
if ($notifyGuest) {
|
||||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingConfirmed($booking));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Availability\AvailabilityChecker;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Mail\NewReservation;
|
||||
use App\Mail\ReservationReceived;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Guest;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Turns a guest request into a reservation that holds the dates for the property's hold time,
|
||||
* and sends the quote to the guest and a notification to the landlord.
|
||||
*/
|
||||
class CreateReservation
|
||||
{
|
||||
public function __construct(
|
||||
private PriceCalculator $calculator,
|
||||
private AvailabilityChecker $availability,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param array{first_name: string, last_name: string, email: string, phone?: ?string, street?: ?string, postal_code?: ?string, city?: ?string, country?: ?string} $guestData
|
||||
*
|
||||
* @throws QuoteException
|
||||
* @throws ReservationException
|
||||
*/
|
||||
public function handle(Property $property, StayRequest $stay, array $guestData, ?string $message = null, string $source = 'website', bool $sendMails = true): Booking
|
||||
{
|
||||
$booking = DB::transaction(function () use ($property, $stay, $guestData, $message, $source): Booking {
|
||||
Property::whereKey($property->getKey())->lockForUpdate()->first();
|
||||
|
||||
if (! $this->availability->isAvailable($property, $stay->arrival, $stay->departure)) {
|
||||
throw ReservationException::notAvailable();
|
||||
}
|
||||
|
||||
$quote = $this->calculator->calculate($property, $stay);
|
||||
|
||||
$guest = Guest::firstOrNew(['email' => mb_strtolower($guestData['email'])]);
|
||||
$guest->fill($guestData)->fill(['email' => mb_strtolower($guestData['email'])])->save();
|
||||
|
||||
return $property->bookings()->create([
|
||||
'guest_id' => $guest->id,
|
||||
'status' => BookingStatus::Reserved,
|
||||
'source' => $source,
|
||||
'arrival' => $stay->arrival->toDateString(),
|
||||
'departure' => $stay->departure->toDateString(),
|
||||
'guests' => $stay->guests,
|
||||
'extras' => array_filter($stay->extras),
|
||||
'promo_code' => $quote->promoCodeApplied ? $stay->promoCode : null,
|
||||
'quote' => $quote->toArray(),
|
||||
'total' => $quote->total(),
|
||||
'deposit' => $quote->deposit(),
|
||||
'balance_due_on' => $quote->balanceDueOn->toDateString(),
|
||||
'hold_expires_at' => now()->addHours($property->hold_hours),
|
||||
'message' => $message,
|
||||
]);
|
||||
});
|
||||
|
||||
if ($sendMails) {
|
||||
$this->sendMails($booking);
|
||||
}
|
||||
|
||||
return $booking;
|
||||
}
|
||||
|
||||
/**
|
||||
* A failing mail server must not lose the reservation; failures are reported and visible in the log.
|
||||
*/
|
||||
private function sendMails(Booking $booking): void
|
||||
{
|
||||
try {
|
||||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new ReservationReceived($booking));
|
||||
Mail::to(config('fewo.notification_email'))->send(new NewReservation($booking));
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Mail\BookingDeclined;
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class DeclineBooking
|
||||
{
|
||||
/**
|
||||
* @throws ReservationException
|
||||
*/
|
||||
public function handle(Booking $booking, bool $notifyGuest = true): void
|
||||
{
|
||||
if (! in_array($booking->status, [BookingStatus::Reserved, BookingStatus::Expired], true)) {
|
||||
throw ReservationException::invalidTransition($booking->status->getLabel(), 'abgelehnt');
|
||||
}
|
||||
|
||||
$booking->update([
|
||||
'status' => BookingStatus::Declined,
|
||||
'hold_expires_at' => null,
|
||||
]);
|
||||
|
||||
if ($notifyGuest) {
|
||||
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingDeclined($booking));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Mail\ReservationExpired;
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/**
|
||||
* Marks reservations whose hold time is over as expired and tells the landlord.
|
||||
* The calendar already treats them as free once the hold time is over; this only updates the status.
|
||||
*/
|
||||
class ExpireReservations
|
||||
{
|
||||
public function handle(): int
|
||||
{
|
||||
$expired = Booking::query()
|
||||
->where('status', BookingStatus::Reserved)
|
||||
->where('hold_expires_at', '<=', now())
|
||||
->with(['guest', 'property'])
|
||||
->get();
|
||||
|
||||
foreach ($expired as $booking) {
|
||||
$booking->update(['status' => BookingStatus::Expired]);
|
||||
|
||||
Mail::to(config('fewo.notification_email'))->send(new ReservationExpired($booking));
|
||||
}
|
||||
|
||||
return $expired->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Availability;
|
||||
|
||||
use App\Models\BlockedPeriod;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Property;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
* Works on nights: a stay from $from to $until occupies the nights $from … $until - 1 day,
|
||||
* so changeover days (departure and arrival on the same day) are possible.
|
||||
*/
|
||||
class AvailabilityChecker
|
||||
{
|
||||
public function isAvailable(Property $property, CarbonImmutable $from, CarbonImmutable $until, ?Booking $ignore = null): bool
|
||||
{
|
||||
$bookingConflict = $property->bookings()
|
||||
->occupying()
|
||||
->overlapping($from, $until)
|
||||
->when($ignore, fn ($query) => $query->whereKeyNot($ignore->getKey()))
|
||||
->exists();
|
||||
|
||||
return ! $bookingConflict && ! $property->blockedPeriods()->overlapping($from, $until)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Occupied nights within [$from, $until) as a set of 'Y-m-d' strings.
|
||||
*
|
||||
* @return array<string, true>
|
||||
*/
|
||||
public function occupiedNights(Property $property, CarbonImmutable $from, CarbonImmutable $until): array
|
||||
{
|
||||
$periods = $property->bookings()->occupying()->overlapping($from, $until)->get(['arrival', 'departure'])
|
||||
->map(fn (Booking $booking): array => [$booking->arrival, $booking->departure])
|
||||
->concat($property->blockedPeriods()->overlapping($from, $until)->get(['starts_on', 'ends_on'])
|
||||
->map(fn (BlockedPeriod $period): array => [$period->starts_on, $period->ends_on]));
|
||||
|
||||
$nights = [];
|
||||
foreach ($periods as [$start, $end]) {
|
||||
for ($night = $start->max($from); $night->lessThan($end) && $night->lessThan($until); $night = $night->addDay()) {
|
||||
$nights[$night->toDateString()] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $nights;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Actions\ExpireReservations;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
#[Signature('bookings:expire-holds')]
|
||||
#[Description('Mark reservations with an elapsed hold time as expired and notify the landlord')]
|
||||
class ExpireReservationHolds extends Command
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(ExpireReservations $expireReservations): int
|
||||
{
|
||||
$count = $expireReservations->handle();
|
||||
|
||||
$this->info("{$count} Vormerkung(en) abgelaufen.");
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Filament\Support\Contracts\HasColor;
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
|
||||
enum BookingStatus: string implements HasColor, HasLabel
|
||||
{
|
||||
/** Guest request; the dates are held until hold_expires_at. */
|
||||
case Reserved = 'reserved';
|
||||
case Confirmed = 'confirmed';
|
||||
case DepositPaid = 'deposit_paid';
|
||||
case Paid = 'paid';
|
||||
case Completed = 'completed';
|
||||
case Declined = 'declined';
|
||||
case Expired = 'expired';
|
||||
case Cancelled = 'cancelled';
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Reserved => 'Vorreserviert',
|
||||
self::Confirmed => 'Bestätigt',
|
||||
self::DepositPaid => 'Anzahlung erhalten',
|
||||
self::Paid => 'Bezahlt',
|
||||
self::Completed => 'Abgeschlossen',
|
||||
self::Declined => 'Abgelehnt',
|
||||
self::Expired => 'Abgelaufen',
|
||||
self::Cancelled => 'Storniert',
|
||||
};
|
||||
}
|
||||
|
||||
public function getColor(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Reserved => 'warning',
|
||||
self::Confirmed, self::DepositPaid => 'info',
|
||||
self::Paid, self::Completed => 'success',
|
||||
self::Declined, self::Expired, self::Cancelled => 'gray',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Statuses that occupy the calendar regardless of any hold time.
|
||||
*
|
||||
* @return list<self>
|
||||
*/
|
||||
public static function occupying(): array
|
||||
{
|
||||
return [self::Confirmed, self::DepositPaid, self::Paid, self::Completed];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
|
||||
enum DiscountType: string implements HasLabel
|
||||
{
|
||||
/** discount_value = percent of the accommodation price */
|
||||
case Percent = 'percent';
|
||||
|
||||
/** discount_value = euro cents off the stay */
|
||||
case AmountPerStay = 'amount_per_stay';
|
||||
|
||||
/** discount_value = special price per night in euro cents */
|
||||
case NightlyRate = 'nightly_rate';
|
||||
|
||||
/** discount_value = number of cheapest nights that are free */
|
||||
case FreeNights = 'free_nights';
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Percent => 'Rabatt in %',
|
||||
self::AmountPerStay => 'Rabatt in € pro Aufenthalt',
|
||||
self::NightlyRate => 'Sonderpreis pro Nacht',
|
||||
self::FreeNights => 'Gratis-Nächte',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,13 @@ enum QuoteLineType: string
|
||||
case ExtraGuest = 'extra_guest';
|
||||
case Cleaning = 'cleaning';
|
||||
case Extra = 'extra';
|
||||
case Discount = 'discount';
|
||||
|
||||
/**
|
||||
* Whether the line counts towards the rent on which the deposit is calculated.
|
||||
*/
|
||||
public function isRent(): bool
|
||||
{
|
||||
return in_array($this, [self::Accommodation, self::ExtraGuest], true);
|
||||
return in_array($this, [self::Accommodation, self::ExtraGuest, self::Discount], true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* A reservation or status change that is not possible. Messages are shown to guests and administrators.
|
||||
*/
|
||||
class ReservationException extends RuntimeException
|
||||
{
|
||||
public static function notAvailable(): self
|
||||
{
|
||||
return new self('Der gewünschte Zeitraum ist leider nicht mehr frei.');
|
||||
}
|
||||
|
||||
public static function invalidTransition(string $statusLabel, string $action): self
|
||||
{
|
||||
return new self("Eine Buchung im Status „{$statusLabel}“ kann nicht {$action} werden.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Bookings;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Filament\Resources\Bookings\Pages\CreateBooking;
|
||||
use App\Filament\Resources\Bookings\Pages\ListBookings;
|
||||
use App\Filament\Resources\Bookings\Pages\ViewBooking;
|
||||
use App\Filament\Resources\Bookings\Schemas\BookingForm;
|
||||
use App\Filament\Resources\Bookings\Schemas\BookingInfolist;
|
||||
use App\Filament\Resources\Bookings\Tables\BookingsTable;
|
||||
use App\Models\Booking;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class BookingResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Booking::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCalendarDays;
|
||||
|
||||
protected static ?string $modelLabel = 'Buchung';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Anfragen & Buchungen';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'reference';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return BookingForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return BookingInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return BookingsTable::configure($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of open requests waiting for a decision.
|
||||
*/
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
$open = Booking::query()->where('status', BookingStatus::Reserved)->count();
|
||||
|
||||
return $open > 0 ? (string) $open : null;
|
||||
}
|
||||
|
||||
public static function getNavigationBadgeColor(): string
|
||||
{
|
||||
return 'warning';
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListBookings::route('/'),
|
||||
'create' => CreateBooking::route('/create'),
|
||||
'view' => ViewBooking::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Bookings\Pages;
|
||||
|
||||
use App\Actions\ConfirmBooking;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class CreateBooking extends CreateRecord
|
||||
{
|
||||
protected static string $resource = BookingResource::class;
|
||||
|
||||
protected static ?string $title = 'Buchung erfassen';
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
try {
|
||||
$booking = app(CreateReservation::class)->handle(
|
||||
Property::findOrFail($data['property_id']),
|
||||
new StayRequest(
|
||||
CarbonImmutable::parse($data['arrival']),
|
||||
CarbonImmutable::parse($data['departure']),
|
||||
(int) $data['guests'],
|
||||
promoCode: $data['promo_code'] ?: null,
|
||||
),
|
||||
Arr::only($data, ['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city']),
|
||||
source: 'manual',
|
||||
sendMails: $data['send_mails'],
|
||||
);
|
||||
|
||||
if ($data['confirm_immediately']) {
|
||||
app(ConfirmBooking::class)->handle($booking, notifyGuest: $data['send_mails']);
|
||||
}
|
||||
} catch (QuoteException|ReservationException $exception) {
|
||||
Notification::make()->title('Buchung nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
|
||||
$this->halt();
|
||||
}
|
||||
|
||||
$booking->update(['internal_notes' => $data['internal_notes'] ?: null]);
|
||||
|
||||
return $booking;
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return BookingResource::getUrl('view', ['record' => $this->getRecord()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Bookings\Pages;
|
||||
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListBookings extends ListRecords
|
||||
{
|
||||
protected static string $resource = BookingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Bookings\Pages;
|
||||
|
||||
use App\Actions\ConfirmBooking;
|
||||
use App\Actions\DeclineBooking;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use App\Models\Booking;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
|
||||
/**
|
||||
* @property Booking $record
|
||||
*/
|
||||
class ViewBooking extends ViewRecord
|
||||
{
|
||||
protected static string $resource = BookingResource::class;
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return "{$this->record->reference} · {$this->record->guest->full_name}";
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('confirm')
|
||||
->label('Bestätigen')
|
||||
->icon(Heroicon::OutlinedCheckCircle)
|
||||
->color('success')
|
||||
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::Expired], true))
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Buchung bestätigen')
|
||||
->modalDescription('Die Buchung wird verbindlich und der Zeitraum dauerhaft belegt.')
|
||||
->schema([
|
||||
Toggle::make('notify')->label('Buchungsbestätigung an den Gast senden')->default(true),
|
||||
])
|
||||
->action(fn (array $data, ConfirmBooking $confirm) => $this->runWorkflow(
|
||||
fn () => $confirm->handle($this->record, $data['notify']),
|
||||
'Buchung bestätigt',
|
||||
)),
|
||||
Action::make('decline')
|
||||
->label('Ablehnen')
|
||||
->icon(Heroicon::OutlinedXCircle)
|
||||
->color('danger')
|
||||
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::Expired], true))
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Anfrage ablehnen')
|
||||
->schema([
|
||||
Toggle::make('notify')->label('Absage an den Gast senden')->default(true),
|
||||
])
|
||||
->action(fn (array $data, DeclineBooking $decline) => $this->runWorkflow(
|
||||
fn () => $decline->handle($this->record, $data['notify']),
|
||||
'Anfrage abgelehnt',
|
||||
)),
|
||||
Action::make('extendHold')
|
||||
->label('Vormerkung verlängern')
|
||||
->icon(Heroicon::OutlinedClock)
|
||||
->color('gray')
|
||||
->visible(fn (): bool => $this->record->status === BookingStatus::Reserved)
|
||||
->schema([
|
||||
TextInput::make('hours')->label('Um')->integer()->minValue(1)->default(24)->suffix('Stunden')->required(),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$from = $this->record->hold_expires_at?->isFuture() ? $this->record->hold_expires_at : now()->toImmutable();
|
||||
$this->record->update(['hold_expires_at' => $from->addHours((int) $data['hours'])]);
|
||||
|
||||
Notification::make()->title('Vorgemerkt bis '.$this->record->hold_expires_at->format('d.m.Y, H:i'))->success()->send();
|
||||
}),
|
||||
ActionGroup::make([
|
||||
Action::make('notes')
|
||||
->label('Interne Notiz bearbeiten')
|
||||
->icon(Heroicon::OutlinedPencilSquare)
|
||||
->fillForm(fn (): array => ['internal_notes' => $this->record->internal_notes])
|
||||
->schema([
|
||||
Textarea::make('internal_notes')->label('Interne Notizen')->rows(6),
|
||||
])
|
||||
->action(fn (array $data) => $this->record->update($data)),
|
||||
Action::make('cancel')
|
||||
->label('Stornieren')
|
||||
->icon(Heroicon::OutlinedNoSymbol)
|
||||
->color('danger')
|
||||
->visible(fn (): bool => in_array($this->record->status, BookingStatus::occupying(), true))
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Der Zeitraum wird wieder freigegeben. Der Gast wird nicht automatisch benachrichtigt.')
|
||||
->action(function (): void {
|
||||
$this->record->update(['status' => BookingStatus::Cancelled, 'cancelled_at' => now()]);
|
||||
|
||||
Notification::make()->title('Buchung storniert')->success()->send();
|
||||
}),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
private function runWorkflow(callable $workflow, string $successTitle): void
|
||||
{
|
||||
try {
|
||||
$workflow();
|
||||
} catch (ReservationException $exception) {
|
||||
Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Notification::make()->title($successTitle)->success()->send();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Bookings\Schemas;
|
||||
|
||||
use App\Models\Property;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
/**
|
||||
* Manual entry of a booking received by phone or e-mail. The price is calculated automatically.
|
||||
*/
|
||||
class BookingForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Aufenthalt')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Select::make('property_id')
|
||||
->label('Wohnung')
|
||||
->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all())
|
||||
->default(fn (): ?int => Property::query()->value('id'))
|
||||
->required(),
|
||||
TextInput::make('guests')
|
||||
->label('Personen')
|
||||
->integer()
|
||||
->minValue(1)
|
||||
->default(2)
|
||||
->required(),
|
||||
DatePicker::make('arrival')
|
||||
->label('Anreise')
|
||||
->required(),
|
||||
DatePicker::make('departure')
|
||||
->label('Abreise')
|
||||
->after('arrival')
|
||||
->required(),
|
||||
TextInput::make('promo_code')
|
||||
->label('Aktionscode'),
|
||||
]),
|
||||
Section::make('Gast')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('first_name')->label('Vorname')->required()->maxLength(255),
|
||||
TextInput::make('last_name')->label('Nachname')->required()->maxLength(255),
|
||||
TextInput::make('email')->label('E-Mail')->email()->required()->maxLength(255),
|
||||
TextInput::make('phone')->label('Telefon')->tel()->maxLength(50),
|
||||
TextInput::make('street')->label('Straße')->maxLength(255),
|
||||
TextInput::make('postal_code')->label('PLZ')->maxLength(20),
|
||||
TextInput::make('city')->label('Ort')->maxLength(255),
|
||||
]),
|
||||
Section::make('Abschluss')
|
||||
->schema([
|
||||
Textarea::make('internal_notes')->label('Interne Notiz'),
|
||||
Toggle::make('confirm_immediately')->label('Sofort verbindlich bestätigen')->default(true),
|
||||
Toggle::make('send_mails')->label('E-Mails an den Gast senden')->default(false),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Bookings\Schemas;
|
||||
|
||||
use App\Models\Booking;
|
||||
use App\Support\Money;
|
||||
use Filament\Infolists\Components\RepeatableEntry;
|
||||
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class BookingInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(3)
|
||||
->components([
|
||||
Grid::make(1)
|
||||
->columnSpan(2)
|
||||
->schema([
|
||||
Section::make('Aufenthalt')
|
||||
->columns(3)
|
||||
->schema([
|
||||
TextEntry::make('property.name')->label('Wohnung'),
|
||||
TextEntry::make('arrival')->label('Anreise')->date('l, d.m.Y'),
|
||||
TextEntry::make('departure')->label('Abreise')->date('l, d.m.Y'),
|
||||
TextEntry::make('nights')->label('Nächte')->state(fn (Booking $record): int => $record->nights()),
|
||||
TextEntry::make('guests')->label('Personen'),
|
||||
TextEntry::make('promo_code')->label('Aktionscode')->placeholder('–'),
|
||||
]),
|
||||
Section::make('Preis')
|
||||
->schema([
|
||||
RepeatableEntry::make('quote.lines')
|
||||
->hiddenLabel()
|
||||
->table([
|
||||
TableColumn::make('Leistung'),
|
||||
TableColumn::make('Betrag')->alignEnd(),
|
||||
])
|
||||
->schema([
|
||||
TextEntry::make('label'),
|
||||
TextEntry::make('amount')->formatStateUsing(fn (int $state): string => Money::format($state))->alignEnd(),
|
||||
]),
|
||||
Grid::make(4)->schema([
|
||||
TextEntry::make('total')->label('Gesamtpreis')->money('EUR', divideBy: 100, locale: 'de')->weight('bold'),
|
||||
TextEntry::make('deposit')->label('Anzahlung')->money('EUR', divideBy: 100, locale: 'de'),
|
||||
TextEntry::make('balance')->label('Restzahlung')->state(fn (Booking $record): string => Money::format($record->total - $record->deposit)),
|
||||
TextEntry::make('balance_due_on')->label('Rest fällig am')->date('d.m.Y'),
|
||||
]),
|
||||
]),
|
||||
Section::make('Nachricht des Gastes')
|
||||
->visible(fn (Booking $record): bool => filled($record->message))
|
||||
->schema([
|
||||
TextEntry::make('message')->hiddenLabel(),
|
||||
]),
|
||||
]),
|
||||
Grid::make(1)
|
||||
->columnSpan(1)
|
||||
->schema([
|
||||
Section::make('Status')
|
||||
->schema([
|
||||
TextEntry::make('status')->label('Status')->badge(),
|
||||
TextEntry::make('hold_expires_at')->label('Vorgemerkt bis')->dateTime('d.m.Y, H:i')->visible(fn (Booking $record): bool => $record->hold_expires_at !== null),
|
||||
TextEntry::make('confirmed_at')->label('Bestätigt am')->dateTime('d.m.Y, H:i')->visible(fn (Booking $record): bool => $record->confirmed_at !== null),
|
||||
TextEntry::make('created_at')->label('Eingegangen')->dateTime('d.m.Y, H:i'),
|
||||
TextEntry::make('source')->label('Quelle'),
|
||||
]),
|
||||
Section::make('Gast')
|
||||
->schema([
|
||||
TextEntry::make('guest.full_name')->label('Name'),
|
||||
TextEntry::make('guest.email')->label('E-Mail')->copyable(),
|
||||
TextEntry::make('guest.phone')->label('Telefon')->placeholder('–'),
|
||||
TextEntry::make('guest_address')
|
||||
->label('Adresse')
|
||||
->state(fn (Booking $record): ?string => collect([$record->guest->street, trim("{$record->guest->postal_code} {$record->guest->city}")])->filter()->implode(', ') ?: null)
|
||||
->placeholder('–'),
|
||||
]),
|
||||
Section::make('Interne Notizen')
|
||||
->schema([
|
||||
TextEntry::make('internal_notes')->hiddenLabel()->placeholder('Keine Notizen'),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Bookings\Tables;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Models\Booking;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class BookingsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->modifyQueryUsing(fn (Builder $query): Builder => $query->with(['guest', 'property']))
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('reference')
|
||||
->label('Nr.')
|
||||
->searchable(),
|
||||
TextColumn::make('status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->description(fn (Booking $record): ?string => $record->isHoldActive() ? 'bis '.$record->hold_expires_at->format('d.m. H:i') : null),
|
||||
TextColumn::make('guest.last_name')
|
||||
->label('Gast')
|
||||
->formatStateUsing(fn (Booking $record): string => $record->guest->full_name)
|
||||
->description(fn (Booking $record): string => $record->guest->email)
|
||||
->searchable(['first_name', 'last_name', 'email']),
|
||||
TextColumn::make('property.name')
|
||||
->label('Wohnung')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('arrival')
|
||||
->label('Anreise')
|
||||
->date('D, d.m.Y')
|
||||
->sortable(),
|
||||
TextColumn::make('departure')
|
||||
->label('Abreise')
|
||||
->date('D, d.m.Y')
|
||||
->description(fn (Booking $record): string => $record->nights().' Nächte'),
|
||||
TextColumn::make('guests')
|
||||
->label('Pers.'),
|
||||
TextColumn::make('total')
|
||||
->label('Gesamt')
|
||||
->money('EUR', divideBy: 100, locale: 'de'),
|
||||
TextColumn::make('source')
|
||||
->label('Quelle')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('created_at')
|
||||
->label('Eingang')
|
||||
->since()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')
|
||||
->label('Status')
|
||||
->options(BookingStatus::class)
|
||||
->multiple(),
|
||||
Filter::make('upcoming')
|
||||
->label('Nur kommende Aufenthalte')
|
||||
->query(fn (Builder $query): Builder => $query->whereDate('departure', '>=', today())),
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests;
|
||||
|
||||
use App\Filament\Resources\Guests\Pages\CreateGuest;
|
||||
use App\Filament\Resources\Guests\Pages\EditGuest;
|
||||
use App\Filament\Resources\Guests\Pages\ListGuests;
|
||||
use App\Filament\Resources\Guests\Schemas\GuestForm;
|
||||
use App\Filament\Resources\Guests\Tables\GuestsTable;
|
||||
use App\Models\Guest;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class GuestResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Guest::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
|
||||
|
||||
protected static ?string $modelLabel = 'Gast';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Gäste';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'last_name';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return GuestForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return GuestsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListGuests::route('/'),
|
||||
'create' => CreateGuest::route('/create'),
|
||||
'edit' => EditGuest::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests\Pages;
|
||||
|
||||
use App\Filament\Resources\Guests\GuestResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateGuest extends CreateRecord
|
||||
{
|
||||
protected static string $resource = GuestResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests\Pages;
|
||||
|
||||
use App\Filament\Resources\Guests\GuestResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditGuest extends EditRecord
|
||||
{
|
||||
protected static string $resource = GuestResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests\Pages;
|
||||
|
||||
use App\Filament\Resources\Guests\GuestResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListGuests extends ListRecords
|
||||
{
|
||||
protected static string $resource = GuestResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class GuestForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
TextInput::make('first_name')->label('Vorname')->required()->maxLength(255),
|
||||
TextInput::make('last_name')->label('Nachname')->required()->maxLength(255),
|
||||
TextInput::make('email')->label('E-Mail')->email()->required()->maxLength(255),
|
||||
TextInput::make('phone')->label('Telefon')->tel()->maxLength(50),
|
||||
TextInput::make('street')->label('Straße')->maxLength(255),
|
||||
TextInput::make('postal_code')->label('PLZ')->maxLength(20),
|
||||
TextInput::make('city')->label('Ort')->maxLength(255),
|
||||
Select::make('country')
|
||||
->label('Land')
|
||||
->options(['DE' => 'Deutschland', 'AT' => 'Österreich', 'CH' => 'Schweiz', 'NL' => 'Niederlande', 'DK' => 'Dänemark', 'PL' => 'Polen'])
|
||||
->default('DE')
|
||||
->required(),
|
||||
Textarea::make('notes')->label('Notizen')->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests\Tables;
|
||||
|
||||
use App\Models\Guest;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class GuestsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('last_name')
|
||||
->columns([
|
||||
TextColumn::make('last_name')
|
||||
->label('Name')
|
||||
->formatStateUsing(fn (Guest $record): string => "{$record->last_name}, {$record->first_name}")
|
||||
->searchable(['first_name', 'last_name'])
|
||||
->sortable(),
|
||||
TextColumn::make('email')->label('E-Mail')->searchable(),
|
||||
TextColumn::make('phone')->label('Telefon')->placeholder('–'),
|
||||
TextColumn::make('city')->label('Ort')->placeholder('–'),
|
||||
TextColumn::make('bookings_count')->label('Buchungen')->counts('bookings')->sortable(),
|
||||
TextColumn::make('created_at')->label('Seit')->date('m/Y')->sortable(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,10 @@
|
||||
use App\Filament\Resources\Properties\Pages\CreateProperty;
|
||||
use App\Filament\Resources\Properties\Pages\EditProperty;
|
||||
use App\Filament\Resources\Properties\Pages\ListProperties;
|
||||
use App\Filament\Resources\Properties\RelationManagers\BlockedPeriodsRelationManager;
|
||||
use App\Filament\Resources\Properties\RelationManagers\ExtrasRelationManager;
|
||||
use App\Filament\Resources\Properties\RelationManagers\SeasonsRelationManager;
|
||||
use App\Filament\Resources\Properties\RelationManagers\SpecialOffersRelationManager;
|
||||
use App\Filament\Resources\Properties\Schemas\PropertyForm;
|
||||
use App\Filament\Resources\Properties\Tables\PropertiesTable;
|
||||
use App\Models\Property;
|
||||
@@ -42,7 +44,9 @@ public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
SeasonsRelationManager::class,
|
||||
SpecialOffersRelationManager::class,
|
||||
ExtrasRelationManager::class,
|
||||
BlockedPeriodsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Properties\RelationManagers;
|
||||
|
||||
use App\Models\BlockedPeriod;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class BlockedPeriodsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'blockedPeriods';
|
||||
|
||||
protected static ?string $title = 'Sperrzeiten';
|
||||
|
||||
protected static ?string $modelLabel = 'Sperrzeit';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Sperrzeiten';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
DatePicker::make('starts_on')
|
||||
->label('Von (erste gesperrte Nacht)')
|
||||
->required(),
|
||||
DatePicker::make('ends_on')
|
||||
->label('Bis (erster freier Tag)')
|
||||
->after('starts_on')
|
||||
->required(),
|
||||
TextInput::make('reason')
|
||||
->label('Grund')
|
||||
->placeholder('z. B. Eigennutzung, Renovierung')
|
||||
->maxLength(255)
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('reason')
|
||||
->description('Manuelle Sperren (z. B. Eigennutzung). Belegungen aus Portalen erscheinen hier später automatisch.')
|
||||
->defaultSort('starts_on')
|
||||
->columns([
|
||||
TextColumn::make('starts_on')->label('Von')->date('D, d.m.Y'),
|
||||
TextColumn::make('ends_on')->label('Bis')->date('D, d.m.Y'),
|
||||
TextColumn::make('reason')->label('Grund')->placeholder('–'),
|
||||
TextColumn::make('source')->label('Quelle'),
|
||||
])
|
||||
->filters([
|
||||
Filter::make('upcoming')
|
||||
->label('Nur kommende')
|
||||
->default()
|
||||
->query(fn (Builder $query): Builder => $query->whereDate('ends_on', '>=', today())),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
|
||||
DeleteAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\QuoteLine;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Support\Money;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
@@ -30,7 +32,6 @@
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
class SeasonsRelationManager extends RelationManager
|
||||
{
|
||||
@@ -224,29 +225,30 @@ private function priceCalculatorAction(): Action
|
||||
->integer()
|
||||
->minValue(1)
|
||||
->default(2),
|
||||
TextInput::make('promo_code')
|
||||
->label('Aktionscode (optional)'),
|
||||
])
|
||||
->action(function (array $data, PriceCalculator $calculator): void {
|
||||
try {
|
||||
$quote = $calculator->calculate(
|
||||
$this->getOwnerRecord(),
|
||||
$quote = $calculator->calculate($this->getOwnerRecord(), new StayRequest(
|
||||
CarbonImmutable::parse($data['arrival']),
|
||||
CarbonImmutable::parse($data['departure']),
|
||||
(int) $data['guests'],
|
||||
);
|
||||
promoCode: $data['promo_code'] ?? null,
|
||||
));
|
||||
} catch (QuoteException $exception) {
|
||||
Notification::make()->title('Nicht buchbar')->body($exception->getMessage())->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$euro = fn (int $cents): string => Number::currency($cents / 100, 'EUR', 'de');
|
||||
$lines = collect($quote->lines)
|
||||
->map(fn (QuoteLine $line): string => e($line->label).': '.$euro($line->amount))
|
||||
->push('Anzahlung: '.$euro($quote->deposit()).' · Rest: '.$euro($quote->balance()).' fällig am '.$quote->balanceDueOn->format('d.m.Y'))
|
||||
->map(fn (QuoteLine $line): string => e($line->label).': '.Money::format($line->amount))
|
||||
->push('Anzahlung: '.Money::format($quote->deposit()).' · Rest: '.Money::format($quote->balance()).' fällig am '.$quote->balanceDueOn->format('d.m.Y'))
|
||||
->implode('<br>');
|
||||
|
||||
Notification::make()
|
||||
->title('Gesamtpreis: '.$euro($quote->total()))
|
||||
->title('Gesamtpreis: '.Money::format($quote->total()))
|
||||
->body($lines)
|
||||
->success()
|
||||
->persistent()
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Properties\RelationManagers;
|
||||
|
||||
use App\Enums\DiscountType;
|
||||
use App\Models\SpecialOffer;
|
||||
use App\Support\Money;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ReplicateAction;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class SpecialOffersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'specialOffers';
|
||||
|
||||
protected static ?string $title = 'Sonderangebote';
|
||||
|
||||
protected static ?string $modelLabel = 'Sonderangebot';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Sonderangebote';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Angebot')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Bezeichnung')
|
||||
->helperText('Erscheint so in Angebot und Rechnung, z. B. „Last Minute“ oder „Special Weekend“.')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('public_description')
|
||||
->label('Kurzbeschreibung für die Webseite')
|
||||
->maxLength(255),
|
||||
Select::make('discount_type')
|
||||
->label('Art')
|
||||
->options(DiscountType::class)
|
||||
->default(DiscountType::Percent)
|
||||
->live()
|
||||
->required(),
|
||||
TextInput::make('discount_value')
|
||||
->label(fn (Get $get): string => match ($this->discountType($get)) {
|
||||
DiscountType::Percent => 'Rabatt',
|
||||
DiscountType::AmountPerStay => 'Rabatt pro Aufenthalt',
|
||||
DiscountType::NightlyRate => 'Sonderpreis pro Nacht',
|
||||
DiscountType::FreeNights => 'Anzahl Gratis-Nächte',
|
||||
})
|
||||
->suffix(fn (Get $get): string => match ($this->discountType($get)) {
|
||||
DiscountType::Percent => '%',
|
||||
DiscountType::FreeNights => 'Nächte',
|
||||
default => '€',
|
||||
})
|
||||
->helperText(fn (Get $get): ?string => $this->discountType($get) === DiscountType::FreeNights ? 'Die günstigsten Nächte des Aufenthalts sind gratis.' : null)
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->required()
|
||||
->formatStateUsing(fn (?int $state, ?SpecialOffer $record): int|string|null => $state !== null && $this->isMoney($record?->discount_type) ? number_format($state / 100, 2, '.', '') : $state)
|
||||
->dehydrateStateUsing(fn (string|int|float|null $state, Get $get): int => $this->isMoney($this->discountType($get)) ? (int) round((float) $state * 100) : (int) $state),
|
||||
Toggle::make('is_active')->label('Aktiv')->default(true),
|
||||
Toggle::make('is_public')->label('Auf der Webseite bewerben')->default(true),
|
||||
Toggle::make('is_combinable')
|
||||
->label('Mit anderen kombinierbaren Angeboten kombinierbar')
|
||||
->helperText('Sonst erhält der Gast automatisch das für ihn beste Einzelangebot.')
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Section::make('Bedingungen')
|
||||
->description('Leere Felder bedeuten: keine Einschränkung.')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('code')
|
||||
->label('Aktionscode (Sonderkondition)')
|
||||
->helperText('Nur mit diesem Code gültig, z. B. für Stammgäste. Leer = gilt automatisch.')
|
||||
->maxLength(50)
|
||||
->columnSpanFull(),
|
||||
CheckboxList::make('season_names')
|
||||
->label('Nur bei Anreise in Saison')
|
||||
->options(fn (): array => $this->getOwnerRecord()->seasons()->reorder('name')->distinct()->pluck('name', 'name')->all())
|
||||
->columns(3)
|
||||
->columnSpanFull(),
|
||||
TextInput::make('max_days_before_arrival')
|
||||
->label('Buchung höchstens … Tage vor Anreise')
|
||||
->helperText('Last Minute, z. B. 14')
|
||||
->integer()
|
||||
->minValue(0),
|
||||
TextInput::make('min_days_before_arrival')
|
||||
->label('Buchung mindestens … Tage vor Anreise')
|
||||
->helperText('Frühbucher, z. B. 180')
|
||||
->integer()
|
||||
->minValue(0),
|
||||
TextInput::make('min_nights')->label('Mindestens Nächte')->integer()->minValue(1),
|
||||
TextInput::make('max_nights')->label('Höchstens Nächte')->integer()->minValue(1),
|
||||
CheckboxList::make('arrival_weekdays')
|
||||
->label('Anreise nur am')
|
||||
->options([1 => 'Mo', 2 => 'Di', 3 => 'Mi', 4 => 'Do', 5 => 'Fr', 6 => 'Sa', 7 => 'So'])
|
||||
->columns(7)
|
||||
->columnSpanFull(),
|
||||
DatePicker::make('stay_from')->label('Aufenthalt frühestens ab'),
|
||||
DatePicker::make('stay_until')->label('Abreise spätestens am'),
|
||||
DateTimePicker::make('bookable_from')->label('Buchbar ab')->seconds(false),
|
||||
DateTimePicker::make('bookable_until')->label('Buchbar bis')->seconds(false),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->description('Sonderangebote werden bei jeder Preisberechnung automatisch geprüft und angewendet.')
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label('Angebot')
|
||||
->description(fn (SpecialOffer $record): ?string => $record->public_description),
|
||||
TextColumn::make('discount')
|
||||
->label('Vorteil')
|
||||
->state(fn (SpecialOffer $record): string => match ($record->discount_type) {
|
||||
DiscountType::Percent => "−{$record->discount_value} %",
|
||||
DiscountType::AmountPerStay => '−'.Money::format($record->discount_value),
|
||||
DiscountType::NightlyRate => Money::format($record->discount_value).' / Nacht',
|
||||
DiscountType::FreeNights => "{$record->discount_value} Nacht/Nächte gratis",
|
||||
}),
|
||||
TextColumn::make('code')->label('Code')->placeholder('automatisch')->badge(),
|
||||
TextColumn::make('season_names')->label('Saisons')->badge()->placeholder('alle'),
|
||||
IconColumn::make('is_combinable')->label('Kombinierbar')->boolean(),
|
||||
IconColumn::make('is_active')->label('Aktiv')->boolean(),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
ReplicateAction::make()->label('Duplizieren')->schema(fn (Schema $schema): Schema => $this->form($schema)),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function discountType(Get $get): DiscountType
|
||||
{
|
||||
$type = $get('discount_type');
|
||||
|
||||
return $type instanceof DiscountType ? $type : (DiscountType::tryFrom((string) $type) ?? DiscountType::Percent);
|
||||
}
|
||||
|
||||
private function isMoney(?DiscountType $type): bool
|
||||
{
|
||||
return in_array($type, [DiscountType::AmountPerStay, DiscountType::NightlyRate], true);
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,14 @@ public static function configure(Schema $schema): Schema
|
||||
->minValue(0)
|
||||
->suffix('Tage vor Anreise')
|
||||
->default(28),
|
||||
TextInput::make('hold_hours')
|
||||
->label('Vorreservierung halten')
|
||||
->helperText('So lange bleibt ein angefragter Zeitraum ohne Ihre Bestätigung blockiert.')
|
||||
->required()
|
||||
->integer()
|
||||
->minValue(1)
|
||||
->suffix('Stunden')
|
||||
->default(48),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Availability\AvailabilityChecker;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Extra;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\PriceQuote;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* Public availability calendar, live price and booking request form.
|
||||
*/
|
||||
class BookingRequest extends Component
|
||||
{
|
||||
private const MONTHS_SHOWN = 2;
|
||||
|
||||
#[Locked]
|
||||
public int $propertyId;
|
||||
|
||||
/** First shown month as 'Y-m'. */
|
||||
public string $month;
|
||||
|
||||
public ?string $arrival = null;
|
||||
|
||||
public ?string $departure = null;
|
||||
|
||||
public int $guests = 2;
|
||||
|
||||
/** @var array<int|string, int|string|null> quantity per extra id */
|
||||
public array $extras = [];
|
||||
|
||||
public string $promoCode = '';
|
||||
|
||||
public string $firstName = '';
|
||||
|
||||
public string $lastName = '';
|
||||
|
||||
public string $email = '';
|
||||
|
||||
public string $phone = '';
|
||||
|
||||
public string $street = '';
|
||||
|
||||
public string $postalCode = '';
|
||||
|
||||
public string $city = '';
|
||||
|
||||
public string $message = '';
|
||||
|
||||
public bool $privacyAccepted = false;
|
||||
|
||||
/** Honeypot, must stay empty. */
|
||||
public string $website = '';
|
||||
|
||||
#[Locked]
|
||||
public ?int $bookingId = null;
|
||||
|
||||
public function mount(?Property $property = null): void
|
||||
{
|
||||
$this->propertyId = ($property ?? Property::query()->where('is_active', true)->firstOrFail())->id;
|
||||
$this->month = CarbonImmutable::today()->format('Y-m');
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function property(): Property
|
||||
{
|
||||
return Property::findOrFail($this->propertyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Extra>
|
||||
*/
|
||||
#[Computed]
|
||||
public function availableExtras(): Collection
|
||||
{
|
||||
return $this->property->extras()->active()->get();
|
||||
}
|
||||
|
||||
public function previousMonth(): void
|
||||
{
|
||||
$previous = $this->firstMonth()->subMonth();
|
||||
if ($previous->greaterThanOrEqualTo(CarbonImmutable::today()->startOfMonth())) {
|
||||
$this->month = $previous->format('Y-m');
|
||||
}
|
||||
}
|
||||
|
||||
public function nextMonth(): void
|
||||
{
|
||||
$this->month = $this->firstMonth()->addMonth()->format('Y-m');
|
||||
}
|
||||
|
||||
/**
|
||||
* Calendar click: the first click sets the arrival, the second the departure.
|
||||
*/
|
||||
public function selectDate(string $date): void
|
||||
{
|
||||
$day = CarbonImmutable::parse($date);
|
||||
$occupied = $this->occupiedNights();
|
||||
|
||||
if ($this->arrival !== null && $this->departure === null && $day->greaterThan(CarbonImmutable::parse($this->arrival))) {
|
||||
if ($this->allNightsFree(CarbonImmutable::parse($this->arrival), $day, $occupied)) {
|
||||
$this->departure = $day->toDateString();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($day->isBefore(CarbonImmutable::today()) || isset($occupied[$day->toDateString()])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->arrival = $day->toDateString();
|
||||
$this->departure = null;
|
||||
}
|
||||
|
||||
public function clearDates(): void
|
||||
{
|
||||
$this->arrival = null;
|
||||
$this->departure = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{quote: ?PriceQuote, error: ?string}
|
||||
*/
|
||||
#[Computed]
|
||||
public function pricing(): array
|
||||
{
|
||||
if ($this->arrival === null || $this->departure === null) {
|
||||
return ['quote' => null, 'error' => null];
|
||||
}
|
||||
|
||||
$stay = $this->stayRequest();
|
||||
|
||||
if ($stay->arrival->isBefore(CarbonImmutable::today())) {
|
||||
return ['quote' => null, 'error' => 'Die Anreise darf nicht in der Vergangenheit liegen.'];
|
||||
}
|
||||
|
||||
if ($stay->departure->greaterThan($stay->arrival) && ! app(AvailabilityChecker::class)->isAvailable($this->property, $stay->arrival, $stay->departure)) {
|
||||
return ['quote' => null, 'error' => 'Der Zeitraum ist leider bereits belegt.'];
|
||||
}
|
||||
|
||||
try {
|
||||
return ['quote' => app(PriceCalculator::class)->calculate($this->property, $stay), 'error' => null];
|
||||
} catch (QuoteException $exception) {
|
||||
return ['quote' => null, 'error' => $exception->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Weeks of the shown months; every day knows whether its night is still free.
|
||||
*
|
||||
* @return list<array{label: string, weeks: list<list<?array{date: string, day: int, free: bool, past: bool, selected: bool, inRange: bool}>>}>
|
||||
*/
|
||||
#[Computed]
|
||||
public function calendar(): array
|
||||
{
|
||||
$occupied = $this->occupiedNights();
|
||||
$today = CarbonImmutable::today();
|
||||
$arrival = $this->arrival ? CarbonImmutable::parse($this->arrival) : null;
|
||||
$departure = $this->departure ? CarbonImmutable::parse($this->departure) : null;
|
||||
|
||||
$months = [];
|
||||
for ($index = 0; $index < self::MONTHS_SHOWN; $index++) {
|
||||
$first = $this->firstMonth()->addMonths($index);
|
||||
$days = array_fill(0, $first->isoWeekday() - 1, null);
|
||||
|
||||
for ($day = $first; $day->month === $first->month; $day = $day->addDay()) {
|
||||
$days[] = [
|
||||
'date' => $day->toDateString(),
|
||||
'day' => $day->day,
|
||||
'free' => ! isset($occupied[$day->toDateString()]),
|
||||
'past' => $day->isBefore($today),
|
||||
'selected' => in_array($day->toDateString(), [$this->arrival, $this->departure], true),
|
||||
'inRange' => $arrival && $departure && $day->greaterThan($arrival) && $day->lessThan($departure),
|
||||
];
|
||||
}
|
||||
|
||||
$months[] = ['label' => $first->translatedFormat('F Y'), 'weeks' => array_chunk($days, 7)];
|
||||
}
|
||||
|
||||
return $months;
|
||||
}
|
||||
|
||||
public function submit(CreateReservation $createReservation): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
if ($this->website !== '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$rateLimitKey = 'booking-request:'.request()->ip();
|
||||
if (RateLimiter::tooManyAttempts($rateLimitKey, 5)) {
|
||||
$this->addError('email', 'Zu viele Anfragen. Bitte versuchen Sie es später erneut oder rufen Sie uns an.');
|
||||
|
||||
return;
|
||||
}
|
||||
RateLimiter::hit($rateLimitKey, 3600);
|
||||
|
||||
try {
|
||||
$booking = $createReservation->handle(
|
||||
$this->property,
|
||||
$this->stayRequest(),
|
||||
[
|
||||
'first_name' => $this->firstName,
|
||||
'last_name' => $this->lastName,
|
||||
'email' => $this->email,
|
||||
'phone' => $this->phone ?: null,
|
||||
'street' => $this->street ?: null,
|
||||
'postal_code' => $this->postalCode ?: null,
|
||||
'city' => $this->city ?: null,
|
||||
],
|
||||
$this->message ?: null,
|
||||
);
|
||||
} catch (QuoteException|ReservationException $exception) {
|
||||
$this->addError('arrival', $exception->getMessage());
|
||||
unset($this->calendar, $this->pricing);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->bookingId = $booking->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<string>>
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'arrival' => ['required', 'date', 'after_or_equal:today'],
|
||||
'departure' => ['required', 'date', 'after:arrival'],
|
||||
'guests' => ['required', 'integer', 'min:1', 'max:'.$this->property->max_guests],
|
||||
'extras.*' => ['nullable', 'integer', 'min:0', 'max:10'],
|
||||
'promoCode' => ['nullable', 'string', 'max:50'],
|
||||
'firstName' => ['required', 'string', 'max:255'],
|
||||
'lastName' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'email', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:50'],
|
||||
'street' => ['nullable', 'string', 'max:255'],
|
||||
'postalCode' => ['nullable', 'string', 'max:20'],
|
||||
'city' => ['nullable', 'string', 'max:255'],
|
||||
'message' => ['nullable', 'string', 'max:5000'],
|
||||
'privacyAccepted' => ['accepted'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function validationAttributes(): array
|
||||
{
|
||||
return [
|
||||
'arrival' => 'Anreise',
|
||||
'departure' => 'Abreise',
|
||||
'guests' => 'Personen',
|
||||
'firstName' => 'Vorname',
|
||||
'lastName' => 'Nachname',
|
||||
'email' => 'E-Mail',
|
||||
'privacyAccepted' => 'Datenschutzerklärung',
|
||||
];
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.booking-request', [
|
||||
'booking' => $this->bookingId ? Booking::with('guest')->find($this->bookingId) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
private function stayRequest(): StayRequest
|
||||
{
|
||||
return new StayRequest(
|
||||
CarbonImmutable::parse($this->arrival),
|
||||
CarbonImmutable::parse($this->departure),
|
||||
$this->guests,
|
||||
array_map('intval', array_filter($this->extras, fn ($quantity): bool => (int) $quantity > 0)),
|
||||
$this->promoCode !== '' ? trim($this->promoCode) : null,
|
||||
);
|
||||
}
|
||||
|
||||
private function firstMonth(): CarbonImmutable
|
||||
{
|
||||
return CarbonImmutable::createFromFormat('!Y-m', $this->month);
|
||||
}
|
||||
|
||||
/**
|
||||
* Occupied nights from the first shown month until a year ahead, so departures can be checked beyond the view.
|
||||
*
|
||||
* @return array<string, true>
|
||||
*/
|
||||
private function occupiedNights(): array
|
||||
{
|
||||
$from = $this->firstMonth()->min(CarbonImmutable::parse($this->arrival ?? $this->month.'-01'));
|
||||
|
||||
return app(AvailabilityChecker::class)->occupiedNights($this->property, $from, $from->addYear());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, true> $occupied
|
||||
*/
|
||||
private function allNightsFree(CarbonImmutable $from, CarbonImmutable $until, array $occupied): bool
|
||||
{
|
||||
for ($night = $from; $night->lessThan($until); $night = $night->addDay()) {
|
||||
if (isset($occupied[$night->toDateString()])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Sent to the guest when the landlord confirms a reservation.
|
||||
*/
|
||||
class BookingConfirmed extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public Booking $booking) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Buchungsbestätigung '.$this->booking->reference,
|
||||
replyTo: [new Address(config('fewo.owner.email'), config('fewo.owner.name'))],
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'mail.booking-confirmed',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Sent to the guest when the landlord declines a reservation.
|
||||
*/
|
||||
class BookingDeclined extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public Booking $booking) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Ihre Anfrage '.$this->booking->reference,
|
||||
replyTo: [new Address(config('fewo.owner.email'), config('fewo.owner.name'))],
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'mail.booking-declined',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Notifies the landlord about a new request.
|
||||
*/
|
||||
class NewReservation extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public Booking $booking) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Neue Anfrage '.$this->booking->reference.': '.$this->booking->guest->full_name.', '.$this->booking->arrival->format('d.m.').'–'.$this->booking->departure->format('d.m.Y'),
|
||||
replyTo: [new Address($this->booking->guest->email, $this->booking->guest->full_name)],
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'mail.new-reservation',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Notifies the landlord that a hold expired without a decision.
|
||||
*/
|
||||
class ReservationExpired extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public Booking $booking) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Vormerkung abgelaufen: '.$this->booking->reference.' ('.$this->booking->guest->full_name.')',
|
||||
replyTo: [new Address($this->booking->guest->email, $this->booking->guest->full_name)],
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'mail.reservation-expired',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Sent to the guest right after a request: the quote and how long the dates are held.
|
||||
*/
|
||||
class ReservationReceived extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public Booking $booking) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Ihre Anfrage '.$this->booking->reference.' – Termin vorgemerkt',
|
||||
replyTo: [new Address(config('fewo.owner.email'), config('fewo.owner.name'))],
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'mail.reservation-received',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use Database\Factories\BlockedPeriodFactory;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Dates that are not bookable (own use, maintenance, bookings from portals).
|
||||
* Like bookings, ends_on is the first free day again.
|
||||
*/
|
||||
#[Fillable(['property_id', 'starts_on', 'ends_on', 'reason', 'source', 'external_uid'])]
|
||||
class BlockedPeriod extends Model
|
||||
{
|
||||
/** @use HasFactory<BlockedPeriodFactory> */
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<BlockedPeriod> $query
|
||||
* @return Builder<BlockedPeriod>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function overlapping(Builder $query, CarbonInterface $from, CarbonInterface $until): Builder
|
||||
{
|
||||
return $query
|
||||
->whereDate('starts_on', '<', $until)
|
||||
->whereDate('ends_on', '>', $from);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use Carbon\CarbonInterface;
|
||||
use Database\Factories\BookingFactory;
|
||||
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 reservation or booking. arrival is the first night, departure the day the guest leaves,
|
||||
* so a departure and the next arrival on the same day do not collide.
|
||||
*/
|
||||
#[Fillable([
|
||||
'property_id',
|
||||
'guest_id',
|
||||
'status',
|
||||
'source',
|
||||
'arrival',
|
||||
'departure',
|
||||
'guests',
|
||||
'extras',
|
||||
'promo_code',
|
||||
'quote',
|
||||
'total',
|
||||
'deposit',
|
||||
'balance_due_on',
|
||||
'hold_expires_at',
|
||||
'message',
|
||||
'internal_notes',
|
||||
'confirmed_at',
|
||||
'cancelled_at',
|
||||
])]
|
||||
class Booking extends Model
|
||||
{
|
||||
/** @use HasFactory<BookingFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::created(function (Booking $booking): void {
|
||||
$booking->forceFill(['reference' => $booking->created_at->format('Y').'-'.str_pad((string) $booking->id, 4, '0', STR_PAD_LEFT)])->saveQuietly();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'status' => BookingStatus::class,
|
||||
'arrival' => 'immutable_date',
|
||||
'departure' => 'immutable_date',
|
||||
'extras' => 'array',
|
||||
'quote' => 'array',
|
||||
'balance_due_on' => 'immutable_date',
|
||||
'hold_expires_at' => 'immutable_datetime',
|
||||
'confirmed_at' => 'immutable_datetime',
|
||||
'cancelled_at' => 'immutable_datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Property, $this>
|
||||
*/
|
||||
public function property(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Property::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Guest, $this>
|
||||
*/
|
||||
public function guest(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Guest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bookings that currently occupy their dates: confirmed ones and reservations whose hold has not expired.
|
||||
*
|
||||
* @param Builder<Booking> $query
|
||||
* @return Builder<Booking>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function occupying(Builder $query): Builder
|
||||
{
|
||||
return $query->where(fn (Builder $query) => $query
|
||||
->whereIn('status', BookingStatus::occupying())
|
||||
->orWhere(fn (Builder $query) => $query
|
||||
->where('status', BookingStatus::Reserved)
|
||||
->where('hold_expires_at', '>', now())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Booking> $query
|
||||
* @return Builder<Booking>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function overlapping(Builder $query, CarbonInterface $from, CarbonInterface $until): Builder
|
||||
{
|
||||
return $query
|
||||
->whereDate('arrival', '<', $until)
|
||||
->whereDate('departure', '>', $from);
|
||||
}
|
||||
|
||||
public function nights(): int
|
||||
{
|
||||
return (int) $this->arrival->diffInDays($this->departure);
|
||||
}
|
||||
|
||||
public function isHoldActive(): bool
|
||||
{
|
||||
return $this->status === BookingStatus::Reserved && $this->hold_expires_at?->isFuture();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\GuestFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city', 'country', 'locale', 'notes'])]
|
||||
class Guest extends Model
|
||||
{
|
||||
/** @use HasFactory<GuestFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* @return HasMany<Booking, $this>
|
||||
*/
|
||||
public function bookings(): HasMany
|
||||
{
|
||||
return $this->hasMany(Booking::class)->latest('arrival');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attribute<string, never>
|
||||
*/
|
||||
protected function fullName(): Attribute
|
||||
{
|
||||
return Attribute::get(fn (): string => "{$this->first_name} {$this->last_name}");
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
'cleaning_fee',
|
||||
'deposit_percent',
|
||||
'balance_due_days_before_arrival',
|
||||
'hold_hours',
|
||||
'check_in_time',
|
||||
'check_out_time',
|
||||
'is_active',
|
||||
@@ -52,6 +53,30 @@ public function seasons(): HasMany
|
||||
return $this->hasMany(Season::class)->orderBy('starts_on');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Booking, $this>
|
||||
*/
|
||||
public function bookings(): HasMany
|
||||
{
|
||||
return $this->hasMany(Booking::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<BlockedPeriod, $this>
|
||||
*/
|
||||
public function blockedPeriods(): HasMany
|
||||
{
|
||||
return $this->hasMany(BlockedPeriod::class)->orderBy('starts_on');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<SpecialOffer, $this>
|
||||
*/
|
||||
public function specialOffers(): HasMany
|
||||
{
|
||||
return $this->hasMany(SpecialOffer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Periods within [$from, $until) for which no season defines a price.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\DiscountType;
|
||||
use App\Pricing\StayRequest;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\SpecialOfferFactory;
|
||||
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 discount rule such as last minute, early bird, long stay, special weekends or a code for regular guests.
|
||||
* Every condition left empty means "no restriction".
|
||||
*/
|
||||
#[Fillable([
|
||||
'property_id',
|
||||
'name',
|
||||
'public_description',
|
||||
'is_active',
|
||||
'is_public',
|
||||
'is_combinable',
|
||||
'code',
|
||||
'discount_type',
|
||||
'discount_value',
|
||||
'stay_from',
|
||||
'stay_until',
|
||||
'bookable_from',
|
||||
'bookable_until',
|
||||
'min_days_before_arrival',
|
||||
'max_days_before_arrival',
|
||||
'min_nights',
|
||||
'max_nights',
|
||||
'arrival_weekdays',
|
||||
'season_names',
|
||||
])]
|
||||
class SpecialOffer extends Model
|
||||
{
|
||||
/** @use HasFactory<SpecialOfferFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
'is_public' => 'boolean',
|
||||
'is_combinable' => 'boolean',
|
||||
'discount_type' => DiscountType::class,
|
||||
'stay_from' => 'immutable_date',
|
||||
'stay_until' => 'immutable_date',
|
||||
'bookable_from' => 'immutable_datetime',
|
||||
'bookable_until' => 'immutable_datetime',
|
||||
'arrival_weekdays' => 'array',
|
||||
'season_names' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Property, $this>
|
||||
*/
|
||||
public function property(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Property::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<SpecialOffer> $query
|
||||
* @return Builder<SpecialOffer>
|
||||
*/
|
||||
#[Scope]
|
||||
protected function active(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether all conditions are met. Offers with a code only apply when the guest entered that code.
|
||||
*/
|
||||
public function appliesTo(StayRequest $stay, string $arrivalSeasonName, CarbonImmutable $bookedAt): bool
|
||||
{
|
||||
$nights = $stay->nights();
|
||||
$daysBeforeArrival = (int) $bookedAt->startOfDay()->diffInDays($stay->arrival, false);
|
||||
|
||||
return $this->is_active
|
||||
&& ($this->code === null || strcasecmp($this->code, (string) $stay->promoCode) === 0)
|
||||
&& ($this->stay_from === null || $stay->arrival->greaterThanOrEqualTo($this->stay_from))
|
||||
&& ($this->stay_until === null || $stay->departure->lessThanOrEqualTo($this->stay_until))
|
||||
&& ($this->bookable_from === null || $bookedAt->greaterThanOrEqualTo($this->bookable_from))
|
||||
&& ($this->bookable_until === null || $bookedAt->lessThanOrEqualTo($this->bookable_until))
|
||||
&& ($this->min_days_before_arrival === null || $daysBeforeArrival >= $this->min_days_before_arrival)
|
||||
&& ($this->max_days_before_arrival === null || $daysBeforeArrival <= $this->max_days_before_arrival)
|
||||
&& ($this->min_nights === null || $nights >= $this->min_nights)
|
||||
&& ($this->max_nights === null || $nights <= $this->max_nights)
|
||||
&& (empty($this->arrival_weekdays) || in_array($stay->arrival->isoWeekday(), array_map('intval', $this->arrival_weekdays), true))
|
||||
&& (empty($this->season_names) || in_array($arrivalSeasonName, $this->season_names, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* The discount in cents for the given nightly rates (one entry per night, in cents).
|
||||
*
|
||||
* @param list<int> $nightlyRates
|
||||
*/
|
||||
public function discountFor(array $nightlyRates): int
|
||||
{
|
||||
$accommodation = array_sum($nightlyRates);
|
||||
|
||||
$discount = match ($this->discount_type) {
|
||||
DiscountType::Percent => intdiv($accommodation * min($this->discount_value, 100) + 50, 100),
|
||||
DiscountType::AmountPerStay => $this->discount_value,
|
||||
DiscountType::NightlyRate => array_sum(array_map(fn (int $rate): int => max(0, $rate - $this->discount_value), $nightlyRates)),
|
||||
DiscountType::FreeNights => array_sum(array_slice($this->sortedAscending($nightlyRates), 0, $this->discount_value)),
|
||||
};
|
||||
|
||||
return min($discount, $accommodation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $rates
|
||||
* @return list<int>
|
||||
*/
|
||||
private function sortedAscending(array $rates): array
|
||||
{
|
||||
sort($rates);
|
||||
|
||||
return $rates;
|
||||
}
|
||||
}
|
||||
@@ -7,40 +7,44 @@
|
||||
use App\Models\Extra;
|
||||
use App\Models\Property;
|
||||
use App\Models\Season;
|
||||
use App\Models\SpecialOffer;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PriceCalculator
|
||||
{
|
||||
/**
|
||||
* Price a stay from $arrival (first night) to $departure (day of departure, not a night).
|
||||
*
|
||||
* @param array<int, int> $extraQuantities quantity per extra id
|
||||
* Price a stay. Special offers are applied automatically; $bookedAt (default: now) decides
|
||||
* time-dependent offers such as last minute or early bird.
|
||||
*
|
||||
* @throws QuoteException
|
||||
*/
|
||||
public function calculate(
|
||||
Property $property,
|
||||
CarbonImmutable $arrival,
|
||||
CarbonImmutable $departure,
|
||||
int $guests,
|
||||
array $extraQuantities = [],
|
||||
): PriceQuote {
|
||||
$arrival = $arrival->startOfDay();
|
||||
$departure = $departure->startOfDay();
|
||||
|
||||
if ($departure->lessThanOrEqualTo($arrival)) {
|
||||
public function calculate(Property $property, StayRequest $stay, ?CarbonImmutable $bookedAt = null): PriceQuote
|
||||
{
|
||||
if ($stay->departure->lessThanOrEqualTo($stay->arrival)) {
|
||||
throw QuoteException::invalidPeriod();
|
||||
}
|
||||
|
||||
if ($guests < 1 || $guests > $property->max_guests) {
|
||||
if ($stay->guests < 1 || $stay->guests > $property->max_guests) {
|
||||
throw QuoteException::invalidGuestCount($property->max_guests);
|
||||
}
|
||||
|
||||
$nights = (int) $arrival->diffInDays($departure);
|
||||
$lines = $this->accommodationLines($property, $arrival, $departure);
|
||||
$nights = $stay->nights();
|
||||
$nightSeasons = $this->seasonPerNight($property, $stay);
|
||||
|
||||
$extraGuests = max(0, $guests - $property->included_guests);
|
||||
$arrivalSeason = $nightSeasons[0];
|
||||
if ($nights < $arrivalSeason->min_nights) {
|
||||
throw QuoteException::minimumStay($arrivalSeason->min_nights, $arrivalSeason->name);
|
||||
}
|
||||
|
||||
$lines = $this->accommodationLines($nightSeasons);
|
||||
|
||||
$appliedOffers = $this->bestOffers($property, $stay, $nightSeasons, $bookedAt ?? CarbonImmutable::now());
|
||||
foreach ($appliedOffers as ['offer' => $offer, 'discount' => $discount]) {
|
||||
$lines[] = new QuoteLine(QuoteLineType::Discount, $offer->name, 1, -$discount, -$discount);
|
||||
}
|
||||
|
||||
$extraGuests = max(0, $stay->guests - $property->included_guests);
|
||||
if ($extraGuests > 0 && $property->extra_guest_fee_per_night > 0) {
|
||||
$lines[] = new QuoteLine(
|
||||
QuoteLineType::ExtraGuest,
|
||||
@@ -55,34 +59,47 @@ public function calculate(
|
||||
$lines[] = new QuoteLine(QuoteLineType::Cleaning, 'Endreinigung & Service', 1, $property->cleaning_fee, $property->cleaning_fee);
|
||||
}
|
||||
|
||||
array_push($lines, ...$this->extraLines($property, $extraQuantities, $nights));
|
||||
array_push($lines, ...$this->extraLines($property, $stay->extras, $nights));
|
||||
|
||||
return new PriceQuote(
|
||||
arrival: $arrival,
|
||||
departure: $departure,
|
||||
guests: $guests,
|
||||
arrival: $stay->arrival,
|
||||
departure: $stay->departure,
|
||||
guests: $stay->guests,
|
||||
lines: $lines,
|
||||
depositPercent: $property->deposit_percent,
|
||||
balanceDueOn: $arrival->subDays($property->balance_due_days_before_arrival),
|
||||
balanceDueOn: $stay->arrival->subDays($property->balance_due_days_before_arrival),
|
||||
promoCodeApplied: $stay->promoCode === null ? null : collect($appliedOffers)->contains(fn (array $applied): bool => $applied['offer']->code !== null),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return non-empty-list<Season>
|
||||
*/
|
||||
private function seasonPerNight(Property $property, StayRequest $stay): array
|
||||
{
|
||||
/** @var Collection<int, Season> $seasons */
|
||||
$seasons = $property->seasons()->overlapping($stay->arrival, $stay->departure)->get();
|
||||
|
||||
$nightSeasons = [];
|
||||
for ($night = $stay->arrival; $night->lessThan($stay->departure); $night = $night->addDay()) {
|
||||
$nightSeasons[] = $seasons->first(fn (Season $season): bool => $season->containsNight($night))
|
||||
?? throw QuoteException::noRateForNight($night);
|
||||
}
|
||||
|
||||
return $nightSeasons;
|
||||
}
|
||||
|
||||
/**
|
||||
* One line per consecutive run of nights in the same season.
|
||||
*
|
||||
* @param non-empty-list<Season> $nightSeasons
|
||||
* @return list<QuoteLine>
|
||||
*/
|
||||
private function accommodationLines(Property $property, CarbonImmutable $arrival, CarbonImmutable $departure): array
|
||||
private function accommodationLines(array $nightSeasons): array
|
||||
{
|
||||
/** @var Collection<int, Season> $seasons */
|
||||
$seasons = $property->seasons()->overlapping($arrival, $departure)->get();
|
||||
|
||||
/** @var list<array{season: Season, nights: int}> $runs */
|
||||
$runs = [];
|
||||
for ($night = $arrival; $night->lessThan($departure); $night = $night->addDay()) {
|
||||
$season = $seasons->first(fn (Season $season): bool => $season->containsNight($night))
|
||||
?? throw QuoteException::noRateForNight($night);
|
||||
|
||||
foreach ($nightSeasons as $season) {
|
||||
$lastRun = array_key_last($runs);
|
||||
if ($lastRun !== null && $runs[$lastRun]['season']->is($season)) {
|
||||
$runs[$lastRun]['nights']++;
|
||||
@@ -91,12 +108,6 @@ private function accommodationLines(Property $property, CarbonImmutable $arrival
|
||||
}
|
||||
}
|
||||
|
||||
$arrivalSeason = $runs[0]['season'];
|
||||
$nights = (int) $arrival->diffInDays($departure);
|
||||
if ($nights < $arrivalSeason->min_nights) {
|
||||
throw QuoteException::minimumStay($arrivalSeason->min_nights, $arrivalSeason->name);
|
||||
}
|
||||
|
||||
return array_map(fn (array $run): QuoteLine => new QuoteLine(
|
||||
QuoteLineType::Accommodation,
|
||||
"{$run['season']->name} ({$run['nights']} ".($run['nights'] === 1 ? 'Nacht' : 'Nächte').')',
|
||||
@@ -106,6 +117,46 @@ private function accommodationLines(Property $property, CarbonImmutable $arrival
|
||||
), $runs);
|
||||
}
|
||||
|
||||
/**
|
||||
* The guest gets whichever is cheaper for them: the single best non-combinable offer,
|
||||
* or all combinable offers together (capped at the accommodation price).
|
||||
*
|
||||
* @param non-empty-list<Season> $nightSeasons
|
||||
* @return list<array{offer: SpecialOffer, discount: int}>
|
||||
*/
|
||||
private function bestOffers(Property $property, StayRequest $stay, array $nightSeasons, CarbonImmutable $bookedAt): array
|
||||
{
|
||||
$nightlyRates = array_map(fn (Season $season): int => $season->nightly_rate, $nightSeasons);
|
||||
$accommodation = array_sum($nightlyRates);
|
||||
|
||||
$candidates = $property->specialOffers()->active()->get()
|
||||
->filter(fn (SpecialOffer $offer): bool => $offer->appliesTo($stay, $nightSeasons[0]->name, $bookedAt))
|
||||
->map(fn (SpecialOffer $offer): array => ['offer' => $offer, 'discount' => $offer->discountFor($nightlyRates)])
|
||||
->filter(fn (array $candidate): bool => $candidate['discount'] > 0);
|
||||
|
||||
[$combinable, $exclusive] = $candidates->partition(fn (array $candidate): bool => $candidate['offer']->is_combinable);
|
||||
|
||||
$bestExclusive = $exclusive->sortByDesc('discount')->first();
|
||||
|
||||
$combined = [];
|
||||
$remaining = $accommodation;
|
||||
foreach ($combinable->sortByDesc('discount') as $candidate) {
|
||||
$discount = min($candidate['discount'], $remaining);
|
||||
if ($discount > 0) {
|
||||
$combined[] = ['offer' => $candidate['offer'], 'discount' => $discount];
|
||||
$remaining -= $discount;
|
||||
}
|
||||
}
|
||||
|
||||
$combinedTotal = $accommodation - $remaining;
|
||||
|
||||
if ($bestExclusive !== null && $bestExclusive['discount'] >= $combinedTotal) {
|
||||
return [$bestExclusive];
|
||||
}
|
||||
|
||||
return $combined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, int> $extraQuantities
|
||||
* @return list<QuoteLine>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Pricing;
|
||||
|
||||
use App\Enums\QuoteLineType;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
@@ -19,8 +20,20 @@ public function __construct(
|
||||
public array $lines,
|
||||
public int $depositPercent,
|
||||
public CarbonImmutable $balanceDueOn,
|
||||
public ?bool $promoCodeApplied = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Total of all special offer discounts as a positive amount.
|
||||
*/
|
||||
public function discount(): int
|
||||
{
|
||||
return -array_sum(array_map(
|
||||
fn (QuoteLine $line): int => $line->type === QuoteLineType::Discount ? $line->amount : 0,
|
||||
$this->lines,
|
||||
));
|
||||
}
|
||||
|
||||
public function nights(): int
|
||||
{
|
||||
return (int) $this->arrival->diffInDays($this->departure);
|
||||
@@ -53,7 +66,7 @@ public function balance(): int
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{arrival: string, departure: string, nights: int, guests: int, lines: list<array<string, mixed>>, total: int, deposit: int, balance: int, balance_due_on: string}
|
||||
* @return array{arrival: string, departure: string, nights: int, guests: int, lines: list<array<string, mixed>>, total: int, deposit: int, balance: int, balance_due_on: string, discount: int}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
@@ -67,6 +80,7 @@ public function toArray(): array
|
||||
'deposit' => $this->deposit(),
|
||||
'balance' => $this->balance(),
|
||||
'balance_due_on' => $this->balanceDueOn->toDateString(),
|
||||
'discount' => $this->discount(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Pricing;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
* What a guest asks for: dates, number of guests, optional extras and a promo code.
|
||||
*/
|
||||
final readonly class StayRequest
|
||||
{
|
||||
public CarbonImmutable $arrival;
|
||||
|
||||
public CarbonImmutable $departure;
|
||||
|
||||
/**
|
||||
* @param array<int, int> $extras quantity per extra id
|
||||
*/
|
||||
public function __construct(
|
||||
CarbonImmutable $arrival,
|
||||
CarbonImmutable $departure,
|
||||
public int $guests,
|
||||
public array $extras = [],
|
||||
public ?string $promoCode = null,
|
||||
) {
|
||||
$this->arrival = $arrival->startOfDay();
|
||||
$this->departure = $departure->startOfDay();
|
||||
}
|
||||
|
||||
public function nights(): int
|
||||
{
|
||||
return (int) $this->arrival->diffInDays($this->departure);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
class Money
|
||||
{
|
||||
/**
|
||||
* Format euro cents for display, e.g. 12350 → "123,50 €".
|
||||
*/
|
||||
public static function format(int $cents): string
|
||||
{
|
||||
return (string) Number::currency($cents / 100, 'EUR', 'de');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Landlord
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Shown in e-mails and documents. Notifications about new requests are sent
|
||||
| to notification_email.
|
||||
|
|
||||
*/
|
||||
|
||||
'owner' => [
|
||||
'name' => env('FEWO_OWNER_NAME', 'Brigitte Stommer'),
|
||||
'street' => env('FEWO_OWNER_STREET', 'Erbstollen 3'),
|
||||
'city' => env('FEWO_OWNER_CITY', '44225 Dortmund'),
|
||||
'phone' => env('FEWO_OWNER_PHONE', '0170 8165208'),
|
||||
'email' => env('FEWO_OWNER_EMAIL', 'fewo@stommer.de'),
|
||||
],
|
||||
|
||||
'notification_email' => env('FEWO_NOTIFICATION_EMAIL', env('FEWO_OWNER_EMAIL', 'fewo@stommer.de')),
|
||||
|
||||
'bank' => [
|
||||
'account_holder' => env('FEWO_BANK_ACCOUNT_HOLDER'),
|
||||
'iban' => env('FEWO_BANK_IBAN'),
|
||||
'bic' => env('FEWO_BANK_BIC'),
|
||||
'bank_name' => env('FEWO_BANK_NAME'),
|
||||
],
|
||||
|
||||
/*
|
||||
| Days after confirmation within which the deposit has to be paid.
|
||||
*/
|
||||
'deposit_due_days' => (int) env('FEWO_DEPOSIT_DUE_DAYS', 7),
|
||||
|
||||
];
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\BlockedPeriod;
|
||||
use App\Models\Property;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<BlockedPeriod>
|
||||
*/
|
||||
class BlockedPeriodFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$startsOn = now()->addDays(fake()->numberBetween(30, 200))->startOfDay();
|
||||
|
||||
return [
|
||||
'property_id' => Property::factory(),
|
||||
'starts_on' => $startsOn->toDateString(),
|
||||
'ends_on' => $startsOn->copy()->addDays(5)->toDateString(),
|
||||
'reason' => 'Eigennutzung',
|
||||
'source' => 'manual',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Guest;
|
||||
use App\Models\Property;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Booking>
|
||||
*/
|
||||
class BookingFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$arrival = now()->addDays(fake()->numberBetween(30, 200))->startOfDay();
|
||||
|
||||
return [
|
||||
'property_id' => Property::factory(),
|
||||
'guest_id' => Guest::factory(),
|
||||
'status' => BookingStatus::Confirmed,
|
||||
'arrival' => $arrival->toDateString(),
|
||||
'departure' => $arrival->copy()->addDays(7)->toDateString(),
|
||||
'guests' => 2,
|
||||
'quote' => [],
|
||||
'total' => 80000,
|
||||
'deposit' => 20000,
|
||||
'balance_due_on' => $arrival->copy()->subDays(28)->toDateString(),
|
||||
];
|
||||
}
|
||||
|
||||
public function reserved(?\DateTimeInterface $holdExpiresAt = null): static
|
||||
{
|
||||
return $this->state(fn (): array => [
|
||||
'status' => BookingStatus::Reserved,
|
||||
'hold_expires_at' => $holdExpiresAt ?? now()->addHours(48),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Guest;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Guest>
|
||||
*/
|
||||
class GuestFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => fake()->firstName(),
|
||||
'last_name' => fake()->lastName(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'phone' => fake()->phoneNumber(),
|
||||
'street' => fake()->streetAddress(),
|
||||
'postal_code' => fake()->postcode(),
|
||||
'city' => fake()->city(),
|
||||
'country' => 'DE',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\DiscountType;
|
||||
use App\Models\Property;
|
||||
use App\Models\SpecialOffer;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<SpecialOffer>
|
||||
*/
|
||||
class SpecialOfferFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'property_id' => Property::factory(),
|
||||
'name' => 'Sonderangebot',
|
||||
'is_active' => true,
|
||||
'is_public' => true,
|
||||
'is_combinable' => false,
|
||||
'discount_type' => DiscountType::Percent,
|
||||
'discount_value' => 10,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('guests', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('first_name');
|
||||
$table->string('last_name');
|
||||
$table->string('email')->index();
|
||||
$table->string('phone')->nullable();
|
||||
$table->string('street')->nullable();
|
||||
$table->string('postal_code', 20)->nullable();
|
||||
$table->string('city')->nullable();
|
||||
$table->string('country', 2)->default('DE');
|
||||
$table->string('locale', 5)->default('de');
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('guests');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('bookings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('reference')->nullable()->unique();
|
||||
$table->foreignId('property_id')->constrained()->restrictOnDelete();
|
||||
$table->foreignId('guest_id')->constrained()->restrictOnDelete();
|
||||
$table->string('status')->index();
|
||||
$table->string('source')->default('website');
|
||||
$table->date('arrival');
|
||||
$table->date('departure');
|
||||
$table->unsignedTinyInteger('guests');
|
||||
$table->json('extras')->nullable();
|
||||
$table->string('promo_code')->nullable();
|
||||
$table->json('quote');
|
||||
$table->unsignedInteger('total');
|
||||
$table->unsignedInteger('deposit');
|
||||
$table->date('balance_due_on');
|
||||
$table->dateTime('hold_expires_at')->nullable();
|
||||
$table->text('message')->nullable();
|
||||
$table->text('internal_notes')->nullable();
|
||||
$table->dateTime('confirmed_at')->nullable();
|
||||
$table->dateTime('cancelled_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['property_id', 'arrival', 'departure']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bookings');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('blocked_periods', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('property_id')->constrained()->cascadeOnDelete();
|
||||
$table->date('starts_on');
|
||||
$table->date('ends_on');
|
||||
$table->string('reason')->nullable();
|
||||
$table->string('source')->default('manual');
|
||||
$table->string('external_uid')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['property_id', 'starts_on', 'ends_on']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('blocked_periods');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('special_offers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('property_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('public_description')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->boolean('is_public')->default(true);
|
||||
$table->boolean('is_combinable')->default(false);
|
||||
$table->string('code')->nullable();
|
||||
$table->string('discount_type');
|
||||
$table->unsignedInteger('discount_value');
|
||||
$table->date('stay_from')->nullable();
|
||||
$table->date('stay_until')->nullable();
|
||||
$table->dateTime('bookable_from')->nullable();
|
||||
$table->dateTime('bookable_until')->nullable();
|
||||
$table->unsignedSmallInteger('min_days_before_arrival')->nullable();
|
||||
$table->unsignedSmallInteger('max_days_before_arrival')->nullable();
|
||||
$table->unsignedSmallInteger('min_nights')->nullable();
|
||||
$table->unsignedSmallInteger('max_nights')->nullable();
|
||||
$table->json('arrival_weekdays')->nullable();
|
||||
$table->json('season_names')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('special_offers');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('properties', function (Blueprint $table) {
|
||||
$table->unsignedSmallInteger('hold_hours')->default(48)->after('balance_due_days_before_arrival');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('properties', function (Blueprint $table) {
|
||||
$table->dropColumn('hold_hours');
|
||||
});
|
||||
}
|
||||
};
|
||||
+23
-5
@@ -51,11 +51,27 @@ ## 5. Verwaltungssystem (Admin)
|
||||
- **Saisons & Preise:** pro Saison Zeitraum, Preis/Nacht, Mindestaufenthalt, optional An-/Abreisetage. Jahr kopieren („Preise 2027 = 2026“) mit einem Klick.
|
||||
- **Preisbestandteile (konfigurierbar):** Endreinigung/Service (108 €), Zusatzperson ab 3. Person (7,50 €/Nacht), Extras (Bettwäsche 14 €, Handtücher 11 €, Paket 23 €), Kurtaxe (Hinweis, vor Ort), Anzahlungsquote 35 %, Restzahlungsfrist 4 Wochen.
|
||||
- Darstellung wahlweise wie heute („erste Nacht inkl. Endreinigung“) oder transparent getrennt – die Berechnung ist identisch.
|
||||
- **Anfragen & Buchungen:** Statusworkflow, Notizen, komplette Kommunikationshistorie.
|
||||
- **Sonderangebote & Sonderkonditionen:** werden bei jeder Preisberechnung automatisch geprüft (siehe 5a).
|
||||
- **Anfragen & Buchungen:** Statusworkflow, Notizen, komplette Kommunikationshistorie. Manuelle Erfassung von Telefonbuchungen mit automatischer Preisberechnung.
|
||||
- **Gäste:** Kartei, Wiederkehrer, DSGVO-Löschfristen.
|
||||
- **Vorlagen:** E-Mail-Texte und Mietvertrag mit Platzhaltern editierbar.
|
||||
- **Portale/Connectoren:** siehe Abschnitt 7.
|
||||
|
||||
## 5a. Sonderangebote & Sonderkonditionen
|
||||
|
||||
Ein Angebot besteht aus einem **Vorteil** und beliebig vielen **Bedingungen** (leer = keine Einschränkung):
|
||||
|
||||
| Vorteil | Beispiel |
|
||||
|---|---|
|
||||
| Rabatt in % | Last Minute −15 % |
|
||||
| Rabatt in € pro Aufenthalt | Stammgast −25 € |
|
||||
| Sonderpreis pro Nacht | Special Weekend 59 €/Nacht |
|
||||
| Gratis-Nächte (die günstigsten) | 7 = 6 |
|
||||
|
||||
Bedingungen: Saison(s) der Anreise · Vorlauf (max./min. Tage vor Anreise → Last Minute/Frühbucher) · Mindest-/Höchstnächte · Anreise-Wochentage · Aufenthaltszeitraum · Buchungszeitraum · **Aktionscode** (Sonderkondition, z. B. für Stammgäste).
|
||||
|
||||
Rabatte gelten auf den Übernachtungspreis (nicht auf Endreinigung/Extras); die Anzahlung wird auf den rabattierten Mietpreis berechnet. Treffen mehrere Angebote zu, erhält der Gast automatisch die günstigere Variante: das beste Einzelangebot **oder** die Summe aller als „kombinierbar“ markierten Angebote.
|
||||
|
||||
## 6. Workflows
|
||||
|
||||
```
|
||||
@@ -105,14 +121,15 @@ ## 8. Rechtliches (Deutschland)
|
||||
## 9. Hosting & Deployment (Strato)
|
||||
|
||||
- Domain-Ziel auf das Verzeichnis `public/` zeigen lassen.
|
||||
- Zu prüfen im Strato-Paket: PHP-Version ≥ 8.3, SSH-Zugang, Cronjobs, MySQL-Datenbank, SMTP-Postfach (fewo@stommer.de).
|
||||
- Tarif: **Strato Hosting Pro**. Im Kundenlogin zu prüfen: PHP-Version ≥ 8.4, SSH-Zugang, Cronjobs, MySQL-Datenbank, SMTP-Postfach (fewo@stommer.de).
|
||||
- Cronjob (jede Minute oder alle 5 Min.): `php artisan schedule:run` – verarbeitet u. a. abgelaufene Vorreservierungen. Der Kalender gibt abgelaufene Vormerkungen auch ohne Cronjob sofort frei; der Cronjob setzt nur den Status und benachrichtigt den Vermieter.
|
||||
- Deployment per Skript (rsync/SFTP) mit Build lokal; Datenbank-Backups täglich.
|
||||
- Migration: Umleitungen (301) der alten WordPress-URLs, Bilder übernehmen.
|
||||
|
||||
## 10. Umsetzungsphasen
|
||||
|
||||
1. **Fundament:** Laravel + Filament, Datenmodell, Saisons/Preise, Preisberechnung (mit Tests). ✅
|
||||
2. **Kalender & Anfrage:** Belegung, Anfrageformular, Auto-Angebot per Mail.
|
||||
2. **Kalender & Anfrage:** Belegung, Anfrageformular, Auto-Angebot per Mail, Vorreservierung mit Haltezeit, Sonderangebote, Sperrzeiten, Buchungsverwaltung. ✅
|
||||
3. **Buchungsworkflow:** Bestätigung, Mietvertrag-PDF, Zahlungsfristen & Erinnerungen.
|
||||
4. **Webseite:** Design, Inhalte, Galerie, SEO, Barrierefreiheit.
|
||||
5. **Connectoren:** iCal-Import/-Export, Sync-Log, Konfliktwarnung.
|
||||
@@ -120,11 +137,12 @@ ## 10. Umsetzungsphasen
|
||||
|
||||
## 11. Offene Punkte / benötigte Inhalte
|
||||
|
||||
- [ ] Strato-Tarif prüfen (SSH, Cronjobs, PHP-Version)
|
||||
- [x] Strato-Tarif: Hosting Pro – noch prüfen: SSH, Cronjobs, PHP-Version
|
||||
- [x] Haltezeit der Vorreservierung: 48 h (je Wohnung einstellbar)
|
||||
- [ ] Bestehender Mietvertrag (Vorlage) und Mietbedingungen
|
||||
- [ ] Hochauflösende Fotos
|
||||
- [ ] An-/Abreisezeiten, Stornobedingungen, Haustiere/Rauchen
|
||||
- [ ] Preise 2027 bestätigen; Korrektur Weihnachten/Neujahr-Zeiträume
|
||||
- [ ] Bankverbindung für Zahlungsinformationen
|
||||
- [ ] Sprachen: Deutsch + Englisch?
|
||||
- [ ] Nachbarwohnung: ebenfalls verwalten (Kombi-Buchung „zwei Familien“)?
|
||||
- [x] Nachbarwohnung: System ist mehrwohnungsfähig
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"All rights reserved.": "Alle Rechte vorbehalten.",
|
||||
"Hello!": "Hallo!",
|
||||
"Regards,": "Viele Grüße",
|
||||
"If you're having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser:": "Falls der Button „:actionText“ nicht funktioniert, kopieren Sie bitte folgende Adresse in Ihren Browser:"
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Validation Language Lines (German)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'accepted' => ':Attribute muss akzeptiert werden.',
|
||||
'after' => ':Attribute muss ein Datum nach :date sein.',
|
||||
'after_or_equal' => ':Attribute muss ein Datum nach oder gleich :date sein.',
|
||||
'alpha_dash' => ':Attribute darf nur Buchstaben, Zahlen, Binde- und Unterstriche enthalten.',
|
||||
'array' => ':Attribute muss eine Liste sein.',
|
||||
'before' => ':Attribute muss ein Datum vor :date sein.',
|
||||
'before_or_equal' => ':Attribute muss ein Datum vor oder gleich :date sein.',
|
||||
'boolean' => ':Attribute muss wahr oder falsch sein.',
|
||||
'date' => ':Attribute muss ein gültiges Datum sein.',
|
||||
'email' => ':Attribute muss eine gültige E-Mail-Adresse sein.',
|
||||
'exists' => 'Der gewählte Wert für :attribute ist ungültig.',
|
||||
'gt' => [
|
||||
'numeric' => ':Attribute muss größer als :value sein.',
|
||||
],
|
||||
'gte' => [
|
||||
'numeric' => ':Attribute muss größer oder gleich :value sein.',
|
||||
],
|
||||
'in' => 'Der gewählte Wert für :attribute ist ungültig.',
|
||||
'integer' => ':Attribute muss eine ganze Zahl sein.',
|
||||
'lt' => [
|
||||
'numeric' => ':Attribute muss kleiner als :value sein.',
|
||||
],
|
||||
'lte' => [
|
||||
'numeric' => ':Attribute muss kleiner oder gleich :value sein.',
|
||||
],
|
||||
'max' => [
|
||||
'array' => ':Attribute darf höchstens :max Elemente haben.',
|
||||
'numeric' => ':Attribute darf maximal :max sein.',
|
||||
'string' => ':Attribute darf maximal :max Zeichen haben.',
|
||||
],
|
||||
'min' => [
|
||||
'array' => ':Attribute muss mindestens :min Elemente haben.',
|
||||
'numeric' => ':Attribute muss mindestens :min sein.',
|
||||
'string' => ':Attribute muss mindestens :min Zeichen lang sein.',
|
||||
],
|
||||
'numeric' => ':Attribute muss eine Zahl sein.',
|
||||
'required' => ':Attribute muss ausgefüllt werden.',
|
||||
'string' => ':Attribute muss ein Text sein.',
|
||||
'unique' => ':Attribute ist bereits vergeben.',
|
||||
|
||||
'attributes' => [
|
||||
'today' => 'heute',
|
||||
],
|
||||
|
||||
];
|
||||
Generated
+2419
File diff suppressed because it is too large.
Load diff
+30
-2
@@ -4,6 +4,34 @@
|
||||
@source '../../storage/framework/views/*.php';
|
||||
|
||||
@theme {
|
||||
--font-sans: 'Instrument Sans', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
|
||||
'Segoe UI Symbol', 'Noto Color Emoji';
|
||||
--font-sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
|
||||
--color-sea-50: oklch(0.97 0.015 230);
|
||||
--color-sea-100: oklch(0.93 0.035 230);
|
||||
--color-sea-700: oklch(0.45 0.11 235);
|
||||
--color-sea-800: oklch(0.38 0.1 237);
|
||||
--color-sea-900: oklch(0.3 0.08 240);
|
||||
|
||||
--color-sand-50: oklch(0.985 0.008 85);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
input:not([type='checkbox']):not([type='radio']),
|
||||
select,
|
||||
textarea {
|
||||
border-width: 1px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
input[type='checkbox'] {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
accent-color: var(--color-sea-700);
|
||||
}
|
||||
|
||||
:focus-visible {
|
||||
outline: 2px solid var(--color-sea-700);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<x-layouts.site title="Preise & Buchung" description="Freie Termine, Preise und unverbindliche Buchungsanfrage für die Ferienwohnung Stommer in Kühlungsborn.">
|
||||
<h1 class="text-3xl font-semibold tracking-tight text-sea-900">Preise & Buchung</h1>
|
||||
<p class="mt-2 max-w-2xl text-slate-600">
|
||||
Wählen Sie im Kalender Ihren Anreise- und Abreisetag. Sie sehen sofort den Gesamtpreis inklusive aller Nebenkosten.
|
||||
Ihre Anfrage ist unverbindlich – wir halten den Termin für Sie vor und bestätigen kurzfristig.
|
||||
</p>
|
||||
|
||||
<div class="mt-8">
|
||||
<livewire:booking-request />
|
||||
</div>
|
||||
</x-layouts.site>
|
||||
@@ -0,0 +1,39 @@
|
||||
@props(['title' => null, 'description' => null])
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{ $title ? $title.' · ' : '' }}Ferienwohnung Stommer in Kühlungsborn</title>
|
||||
@if ($description)
|
||||
<meta name="description" content="{{ $description }}">
|
||||
@endif
|
||||
@vite(['resources/css/app.css', 'resources/js/app.js'])
|
||||
@livewireStyles
|
||||
</head>
|
||||
<body class="min-h-screen bg-sand-50 text-slate-800 antialiased">
|
||||
<a href="#inhalt" class="sr-only focus:not-sr-only focus:absolute focus:left-4 focus:top-4 focus:rounded focus:bg-white focus:px-4 focus:py-2">Zum Inhalt springen</a>
|
||||
|
||||
<header class="border-b border-slate-200 bg-white">
|
||||
<div class="mx-auto flex max-w-6xl items-center justify-between px-4 py-4">
|
||||
<a href="{{ url('/') }}" class="text-lg font-semibold tracking-tight text-sea-900">Ferienwohnung Stommer</a>
|
||||
<nav aria-label="Hauptnavigation" class="flex gap-6 text-sm font-medium">
|
||||
<a href="{{ route('booking.create') }}" class="text-sea-700 hover:text-sea-900">Preise & Buchung</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main id="inhalt" class="mx-auto max-w-6xl px-4 py-10">
|
||||
{{ $slot }}
|
||||
</main>
|
||||
|
||||
<footer class="border-t border-slate-200 bg-white">
|
||||
<div class="mx-auto max-w-6xl px-4 py-6 text-sm text-slate-500">
|
||||
{{ config('fewo.owner.name') }} · {{ config('fewo.owner.street') }} · {{ config('fewo.owner.city') }} ·
|
||||
<a href="mailto:{{ config('fewo.owner.email') }}" class="underline">{{ config('fewo.owner.email') }}</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
@livewireScripts
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,211 @@
|
||||
<div>
|
||||
@if ($booking)
|
||||
<div class="rounded-2xl border border-emerald-200 bg-emerald-50 p-8" role="status">
|
||||
<h2 class="text-2xl font-semibold text-emerald-900">Vielen Dank, {{ $booking->guest->first_name }}!</h2>
|
||||
<p class="mt-3 text-emerald-900">
|
||||
Ihre Anfrage <strong>{{ $booking->reference }}</strong> ist eingegangen. Wir haben den Zeitraum
|
||||
<strong>{{ $booking->arrival->format('d.m.Y') }} – {{ $booking->departure->format('d.m.Y') }}</strong>
|
||||
bis <strong>{{ $booking->hold_expires_at->format('d.m.Y, H:i') }} Uhr</strong> für Sie vorgemerkt.
|
||||
</p>
|
||||
<p class="mt-2 text-emerald-900">Eine Bestätigung mit allen Details haben wir an {{ $booking->guest->email }} gesendet.</p>
|
||||
</div>
|
||||
@else
|
||||
<div class="grid gap-8 lg:grid-cols-5">
|
||||
{{-- Calendar --}}
|
||||
<section class="lg:col-span-3" aria-labelledby="calendar-heading">
|
||||
<div class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
|
||||
<div class="flex items-center justify-between">
|
||||
<h2 id="calendar-heading" class="text-lg font-semibold text-sea-900">Belegung</h2>
|
||||
<div class="flex gap-2">
|
||||
<button type="button" wire:click="previousMonth" class="rounded-lg border border-slate-200 px-3 py-1.5 text-sm hover:bg-slate-50" aria-label="Vorheriger Monat">‹</button>
|
||||
<button type="button" wire:click="nextMonth" class="rounded-lg border border-slate-200 px-3 py-1.5 text-sm hover:bg-slate-50" aria-label="Nächster Monat">›</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid gap-6 sm:grid-cols-2">
|
||||
@foreach ($this->calendar as $month)
|
||||
<div wire:key="month-{{ $month['label'] }}">
|
||||
<h3 class="mb-2 text-center text-sm font-semibold text-slate-700">{{ $month['label'] }}</h3>
|
||||
<table class="w-full table-fixed text-center text-sm">
|
||||
<thead>
|
||||
<tr class="text-xs text-slate-400">
|
||||
@foreach (['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'] as $weekday)
|
||||
<th scope="col" class="pb-1 font-medium">{{ $weekday }}</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($month['weeks'] as $week)
|
||||
<tr>
|
||||
@foreach (array_pad($week, 7, null) as $day)
|
||||
<td class="p-0.5">
|
||||
@if ($day)
|
||||
<button type="button"
|
||||
wire:click="selectDate('{{ $day['date'] }}')"
|
||||
@disabled($day['past'])
|
||||
aria-pressed="{{ $day['selected'] ? 'true' : 'false' }}"
|
||||
aria-label="{{ \Carbon\CarbonImmutable::parse($day['date'])->translatedFormat('l, d. F Y') }}{{ $day['free'] ? '' : ' (Nacht belegt)' }}"
|
||||
@class([
|
||||
'aspect-square w-full rounded-lg text-sm transition',
|
||||
'cursor-not-allowed text-slate-300' => $day['past'],
|
||||
'bg-sea-700 font-semibold text-white' => $day['selected'],
|
||||
'bg-sea-100 text-sea-900' => $day['inRange'] && ! $day['selected'],
|
||||
'bg-rose-100 text-rose-800 line-through decoration-rose-300' => ! $day['free'] && ! $day['past'] && ! $day['selected'],
|
||||
'hover:bg-sea-50' => $day['free'] && ! $day['past'] && ! $day['selected'] && ! $day['inRange'],
|
||||
])>
|
||||
{{ $day['day'] }}
|
||||
</button>
|
||||
@endif
|
||||
</td>
|
||||
@endforeach
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex flex-wrap gap-4 text-xs text-slate-500">
|
||||
<span class="flex items-center gap-1.5"><span class="inline-block size-3 rounded bg-white ring-1 ring-slate-300"></span> frei</span>
|
||||
<span class="flex items-center gap-1.5"><span class="inline-block size-3 rounded bg-rose-100"></span> Nacht belegt (Abreise möglich)</span>
|
||||
<span class="flex items-center gap-1.5"><span class="inline-block size-3 rounded bg-sea-700"></span> Ihre Auswahl</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid gap-4 sm:grid-cols-3">
|
||||
<label class="block text-sm">
|
||||
<span class="font-medium text-slate-700">Anreise</span>
|
||||
<input type="date" wire:model.live="arrival" min="{{ today()->toDateString() }}" class="mt-1 w-full rounded-lg border-slate-300">
|
||||
</label>
|
||||
<label class="block text-sm">
|
||||
<span class="font-medium text-slate-700">Abreise</span>
|
||||
<input type="date" wire:model.live="departure" min="{{ $arrival ?? today()->toDateString() }}" class="mt-1 w-full rounded-lg border-slate-300">
|
||||
</label>
|
||||
<label class="block text-sm">
|
||||
<span class="font-medium text-slate-700">Personen</span>
|
||||
<select wire:model.live="guests" class="mt-1 w-full rounded-lg border-slate-300">
|
||||
@for ($count = 1; $count <= $this->property->max_guests; $count++)
|
||||
<option value="{{ $count }}">{{ $count }}</option>
|
||||
@endfor
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
@error('arrival') <p class="mt-2 text-sm text-rose-700" role="alert">{{ $message }}</p> @enderror
|
||||
@error('departure') <p class="mt-2 text-sm text-rose-700" role="alert">{{ $message }}</p> @enderror
|
||||
</section>
|
||||
|
||||
{{-- Price and form --}}
|
||||
<section class="lg:col-span-2" aria-labelledby="price-heading">
|
||||
<div class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm" aria-live="polite">
|
||||
<h2 id="price-heading" class="text-lg font-semibold text-sea-900">Ihr Preis</h2>
|
||||
|
||||
@php($pricing = $this->pricing)
|
||||
@if ($pricing['error'])
|
||||
<p class="mt-3 rounded-lg bg-amber-50 p-3 text-sm text-amber-900">{{ $pricing['error'] }}</p>
|
||||
@elseif ($pricing['quote'])
|
||||
@php($quote = $pricing['quote'])
|
||||
<p class="mt-1 text-sm text-slate-500">
|
||||
{{ $quote->arrival->format('d.m.Y') }} – {{ $quote->departure->format('d.m.Y') }} · {{ $quote->nights() }} Nächte · {{ $quote->guests }} {{ $quote->guests === 1 ? 'Person' : 'Personen' }}
|
||||
<button type="button" wire:click="clearDates" class="ml-1 underline">ändern</button>
|
||||
</p>
|
||||
<dl class="mt-4 space-y-1.5 text-sm">
|
||||
@foreach ($quote->lines as $line)
|
||||
<div @class(['flex justify-between gap-4', 'text-emerald-700 font-medium' => $line->amount < 0])>
|
||||
<dt>{{ $line->label }}</dt>
|
||||
<dd class="tabular-nums">{{ \App\Support\Money::format($line->amount) }}</dd>
|
||||
</div>
|
||||
@endforeach
|
||||
<div class="flex justify-between gap-4 border-t border-slate-200 pt-2 text-base font-semibold text-sea-900">
|
||||
<dt>Gesamtpreis</dt>
|
||||
<dd class="tabular-nums">{{ \App\Support\Money::format($quote->total()) }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p class="mt-2 text-xs text-slate-500">
|
||||
Anzahlung {{ \App\Support\Money::format($quote->deposit()) }}, Rest bis {{ $quote->balanceDueOn->format('d.m.Y') }}. Kurtaxe wird vor Ort berechnet.
|
||||
</p>
|
||||
@if ($quote->promoCodeApplied === false)
|
||||
<p class="mt-2 text-sm text-amber-800">Der Aktionscode ist für diesen Zeitraum nicht gültig.</p>
|
||||
@endif
|
||||
@else
|
||||
<p class="mt-3 text-sm text-slate-500">Bitte wählen Sie im Kalender Anreise und Abreise.</p>
|
||||
@endif
|
||||
|
||||
@if ($this->availableExtras->isNotEmpty())
|
||||
<fieldset class="mt-5 border-t border-slate-100 pt-4">
|
||||
<legend class="text-sm font-medium text-slate-700">Zusatzleistungen</legend>
|
||||
<div class="mt-2 space-y-2">
|
||||
@foreach ($this->availableExtras as $extra)
|
||||
<label class="flex items-center justify-between gap-3 text-sm" wire:key="extra-{{ $extra->id }}">
|
||||
<span>
|
||||
{{ $extra->name }} <span class="text-slate-500">({{ \App\Support\Money::format($extra->price) }})</span>
|
||||
@if ($extra->description)<br><span class="text-xs text-slate-500">{{ $extra->description }}</span>@endif
|
||||
</span>
|
||||
<select wire:model.live="extras.{{ $extra->id }}" class="w-20 rounded-lg border-slate-300 text-sm">
|
||||
@for ($quantity = 0; $quantity <= $this->property->max_guests; $quantity++)
|
||||
<option value="{{ $quantity }}">{{ $quantity }}</option>
|
||||
@endfor
|
||||
</select>
|
||||
</label>
|
||||
@endforeach
|
||||
</div>
|
||||
</fieldset>
|
||||
@endif
|
||||
|
||||
<label class="mt-4 block text-sm">
|
||||
<span class="font-medium text-slate-700">Aktionscode</span>
|
||||
<input type="text" wire:model.live.debounce.600ms="promoCode" autocomplete="off" class="mt-1 w-full rounded-lg border-slate-300">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<form wire:submit="submit" class="mt-6 rounded-2xl border border-slate-200 bg-white p-5 shadow-sm" novalidate>
|
||||
<h2 class="text-lg font-semibold text-sea-900">Unverbindlich anfragen</h2>
|
||||
|
||||
<div class="mt-4 grid gap-4 sm:grid-cols-2">
|
||||
@foreach ([
|
||||
['firstName', 'Vorname', 'text', 'given-name', true],
|
||||
['lastName', 'Nachname', 'text', 'family-name', true],
|
||||
['email', 'E-Mail', 'email', 'email', true],
|
||||
['phone', 'Telefon', 'tel', 'tel', false],
|
||||
['street', 'Straße & Hausnr.', 'text', 'street-address', false],
|
||||
['postalCode', 'PLZ', 'text', 'postal-code', false],
|
||||
['city', 'Ort', 'text', 'address-level2', false],
|
||||
] as [$field, $label, $type, $autocomplete, $required])
|
||||
<label class="block text-sm" wire:key="field-{{ $field }}">
|
||||
<span class="font-medium text-slate-700">{{ $label }}@if ($required)<span class="text-rose-600" aria-hidden="true"> *</span>@endif</span>
|
||||
<input type="{{ $type }}" wire:model="{{ $field }}" autocomplete="{{ $autocomplete }}" @required($required)
|
||||
@error($field) aria-invalid="true" aria-describedby="{{ $field }}-error" @enderror
|
||||
class="mt-1 w-full rounded-lg border-slate-300">
|
||||
@error($field) <span id="{{ $field }}-error" class="mt-1 block text-xs text-rose-700">{{ $message }}</span> @enderror
|
||||
</label>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
<label class="mt-4 block text-sm">
|
||||
<span class="font-medium text-slate-700">Nachricht</span>
|
||||
<textarea wire:model="message" rows="3" class="mt-1 w-full rounded-lg border-slate-300"></textarea>
|
||||
</label>
|
||||
|
||||
<div class="hidden" aria-hidden="true">
|
||||
<label>Website <input type="text" wire:model="website" tabindex="-1" autocomplete="off"></label>
|
||||
</div>
|
||||
|
||||
<label class="mt-4 flex items-start gap-2 text-sm">
|
||||
<input type="checkbox" wire:model="privacyAccepted" class="mt-0.5 rounded border-slate-300">
|
||||
<span>Ich bin einverstanden, dass meine Angaben zur Bearbeitung der Anfrage gespeichert werden (siehe Datenschutzerklärung).<span class="text-rose-600" aria-hidden="true"> *</span></span>
|
||||
</label>
|
||||
@error('privacyAccepted') <p class="mt-1 text-xs text-rose-700">{{ $message }}</p> @enderror
|
||||
|
||||
<button type="submit"
|
||||
@disabled(! $pricing['quote'])
|
||||
wire:loading.attr="disabled"
|
||||
class="mt-5 w-full rounded-xl bg-sea-700 px-4 py-3 font-semibold text-white shadow-sm transition hover:bg-sea-800 disabled:cursor-not-allowed disabled:opacity-50">
|
||||
<span wire:loading.remove wire:target="submit">Termin vormerken & Angebot erhalten</span>
|
||||
<span wire:loading wire:target="submit">Wird gesendet …</span>
|
||||
</button>
|
||||
<p class="mt-2 text-center text-xs text-slate-500">Kostenlos und unverbindlich. Verbindlich wird die Buchung erst mit unserer Bestätigung.</p>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@@ -0,0 +1,34 @@
|
||||
<x-mail::message>
|
||||
# Ihre Buchung ist bestätigt!
|
||||
|
||||
Guten Tag {{ $booking->guest->full_name }},
|
||||
|
||||
wir freuen uns, Ihre Buchung der **{{ $booking->property->name }}** verbindlich zu bestätigen.
|
||||
|
||||
**Anreise:** {{ $booking->arrival->translatedFormat('l, d.m.Y') }}@if ($booking->property->check_in_time) ab {{ substr($booking->property->check_in_time, 0, 5) }} Uhr @endif<br>
|
||||
**Abreise:** {{ $booking->departure->translatedFormat('l, d.m.Y') }}@if ($booking->property->check_out_time) bis {{ substr($booking->property->check_out_time, 0, 5) }} Uhr @endif<br>
|
||||
**Personen:** {{ $booking->guests }}<br>
|
||||
**Buchungsnummer:** {{ $booking->reference }}
|
||||
|
||||
@include('mail.partials.quote')
|
||||
|
||||
## Zahlung
|
||||
|
||||
Bitte überweisen Sie die Anzahlung von **{{ \App\Support\Money::format($booking->deposit) }}** innerhalb von {{ config('fewo.deposit_due_days') }} Tagen und den Restbetrag von **{{ \App\Support\Money::format($booking->total - $booking->deposit) }}** bis zum {{ $booking->balance_due_on->format('d.m.Y') }}.
|
||||
|
||||
@if (config('fewo.bank.iban'))
|
||||
<x-mail::panel>
|
||||
Kontoinhaber: {{ config('fewo.bank.account_holder') }}<br>
|
||||
IBAN: {{ config('fewo.bank.iban') }}<br>
|
||||
@if (config('fewo.bank.bic'))
|
||||
BIC: {{ config('fewo.bank.bic') }}<br>
|
||||
@endif
|
||||
Verwendungszweck: {{ $booking->reference }}
|
||||
</x-mail::panel>
|
||||
@endif
|
||||
|
||||
Rechtzeitig vor Ihrer Anreise erhalten Sie von uns alle Informationen zu Schlüsselübergabe, Parken und WLAN.
|
||||
|
||||
Herzliche Grüße<br>
|
||||
{{ config('fewo.owner.name') }}
|
||||
</x-mail::message>
|
||||
@@ -0,0 +1,16 @@
|
||||
<x-mail::message>
|
||||
# Ihre Anfrage {{ $booking->reference }}
|
||||
|
||||
Guten Tag {{ $booking->guest->full_name }},
|
||||
|
||||
vielen Dank für Ihr Interesse an der **{{ $booking->property->name }}**. Leider können wir Ihnen den Zeitraum vom {{ $booking->arrival->format('d.m.Y') }} bis {{ $booking->departure->format('d.m.Y') }} nicht anbieten.
|
||||
|
||||
Vielleicht passt ein anderer Termin? Die freien Zeiträume finden Sie jederzeit in unserem Belegungskalender.
|
||||
|
||||
<x-mail::button :url="route('booking.create')">
|
||||
Freie Termine ansehen
|
||||
</x-mail::button>
|
||||
|
||||
Herzliche Grüße<br>
|
||||
{{ config('fewo.owner.name') }}
|
||||
</x-mail::message>
|
||||
@@ -0,0 +1,25 @@
|
||||
<x-mail::message>
|
||||
# Neue Anfrage {{ $booking->reference }}
|
||||
|
||||
**{{ $booking->guest->full_name }}** möchte die **{{ $booking->property->name }}** buchen.
|
||||
|
||||
**Zeitraum:** {{ $booking->arrival->format('d.m.Y') }} – {{ $booking->departure->format('d.m.Y') }} ({{ $booking->nights() }} Nächte)<br>
|
||||
**Personen:** {{ $booking->guests }}<br>
|
||||
**E-Mail:** {{ $booking->guest->email }}<br>
|
||||
**Telefon:** {{ $booking->guest->phone ?: '–' }}<br>
|
||||
@if ($booking->promo_code)
|
||||
**Aktionscode:** {{ $booking->promo_code }}<br>
|
||||
@endif
|
||||
**Vorgemerkt bis:** {{ $booking->hold_expires_at->format('d.m.Y, H:i') }} Uhr
|
||||
|
||||
@include('mail.partials.quote')
|
||||
|
||||
@if ($booking->message)
|
||||
**Nachricht des Gastes:**<br>
|
||||
{{ $booking->message }}
|
||||
@endif
|
||||
|
||||
<x-mail::button :url="\App\Filament\Resources\Bookings\BookingResource::getUrl('view', ['record' => $booking])">
|
||||
Anfrage bestätigen oder ablehnen
|
||||
</x-mail::button>
|
||||
</x-mail::message>
|
||||
@@ -0,0 +1,13 @@
|
||||
<x-mail::table>
|
||||
| Leistung | Betrag |
|
||||
|:---------|-------:|
|
||||
@foreach ($booking->quote['lines'] as $line)
|
||||
| {{ $line['label'] }} | {{ \App\Support\Money::format($line['amount']) }} |
|
||||
@endforeach
|
||||
| **Gesamtpreis** | **{{ \App\Support\Money::format($booking->total) }}** |
|
||||
</x-mail::table>
|
||||
|
||||
Anzahlung ({{ $booking->property->deposit_percent }} % der Miete): **{{ \App\Support\Money::format($booking->deposit) }}**<br>
|
||||
Restzahlung: **{{ \App\Support\Money::format($booking->total - $booking->deposit) }}**, fällig bis {{ $booking->balance_due_on->format('d.m.Y') }}
|
||||
|
||||
Die Kurtaxe ist nicht enthalten und wird vor Ort entrichtet.
|
||||
@@ -0,0 +1,11 @@
|
||||
<x-mail::message>
|
||||
# Vormerkung abgelaufen
|
||||
|
||||
Die Anfrage **{{ $booking->reference }}** von {{ $booking->guest->full_name }} ({{ $booking->arrival->format('d.m.Y') }} – {{ $booking->departure->format('d.m.Y') }}) wurde nicht rechtzeitig bestätigt. Der Zeitraum ist im Kalender wieder frei.
|
||||
|
||||
Sie können die Anfrage weiterhin bestätigen, sofern der Zeitraum noch frei ist.
|
||||
|
||||
<x-mail::button :url="\App\Filament\Resources\Bookings\BookingResource::getUrl('view', ['record' => $booking])">
|
||||
Anfrage öffnen
|
||||
</x-mail::button>
|
||||
</x-mail::message>
|
||||
@@ -0,0 +1,26 @@
|
||||
<x-mail::message>
|
||||
# Vielen Dank für Ihre Anfrage!
|
||||
|
||||
Guten Tag {{ $booking->guest->full_name }},
|
||||
|
||||
wir haben Ihre Anfrage für die **{{ $booking->property->name }}** erhalten und den Zeitraum für Sie **bis {{ $booking->hold_expires_at->format('d.m.Y, H:i') }} Uhr vorgemerkt**.
|
||||
|
||||
**Anreise:** {{ $booking->arrival->translatedFormat('l, d.m.Y') }}<br>
|
||||
**Abreise:** {{ $booking->departure->translatedFormat('l, d.m.Y') }}<br>
|
||||
**Personen:** {{ $booking->guests }}<br>
|
||||
**Anfragenummer:** {{ $booking->reference }}
|
||||
|
||||
@include('mail.partials.quote')
|
||||
|
||||
Wir prüfen Ihre Anfrage und melden uns in Kürze mit der Buchungsbestätigung. Erst mit unserer Bestätigung ist die Buchung verbindlich.
|
||||
|
||||
@if ($booking->message)
|
||||
**Ihre Nachricht:**<br>
|
||||
{{ $booking->message }}
|
||||
@endif
|
||||
|
||||
Bei Fragen antworten Sie einfach auf diese E-Mail oder rufen Sie uns an: {{ config('fewo.owner.phone') }}
|
||||
|
||||
Herzliche Grüße<br>
|
||||
{{ config('fewo.owner.name') }}
|
||||
</x-mail::message>
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
<title>{{ config('app.name', 'Laravel') }}</title>
|
||||
|
||||
@fonts
|
||||
|
||||
<!-- Styles / Scripts -->
|
||||
@if (file_exists(public_path('build/manifest.json')) || file_exists(public_path('hot')))
|
||||
|
||||
+2
-5
@@ -1,8 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Schedule;
|
||||
|
||||
Artisan::command('inspire', function () {
|
||||
$this->comment(Inspiring::quote());
|
||||
})->purpose('Display an inspiring quote');
|
||||
Schedule::command('bookings:expire-holds')->everyFiveMinutes()->withoutOverlapping();
|
||||
@@ -5,3 +5,5 @@
|
||||
Route::get('/', function () {
|
||||
return view('welcome');
|
||||
});
|
||||
|
||||
Route::view('/buchen', 'booking')->name('booking.create');
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use App\Filament\Resources\Bookings\Pages\CreateBooking;
|
||||
use App\Filament\Resources\Bookings\Pages\ListBookings;
|
||||
use App\Filament\Resources\Bookings\Pages\ViewBooking;
|
||||
use App\Filament\Resources\Guests\GuestResource;
|
||||
use App\Filament\Resources\Properties\Pages\EditProperty;
|
||||
use App\Filament\Resources\Properties\RelationManagers\BlockedPeriodsRelationManager;
|
||||
use App\Filament\Resources\Properties\RelationManagers\SpecialOffersRelationManager;
|
||||
use App\Mail\BookingConfirmed;
|
||||
use App\Mail\BookingDeclined;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Property;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\Testing\TestAction;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BookingAdminTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Property $property;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
|
||||
$this->seed(PropertySeeder::class);
|
||||
$this->property = Property::sole();
|
||||
$this->actingAs(User::factory()->create());
|
||||
Mail::fake();
|
||||
}
|
||||
|
||||
public function test_booking_pages_render(): void
|
||||
{
|
||||
$booking = Booking::factory()->for($this->property)->reserved()->create();
|
||||
|
||||
$this->get(BookingResource::getUrl('index'))->assertOk()->assertSee($booking->reference);
|
||||
$this->get(BookingResource::getUrl('view', ['record' => $booking]))->assertOk()->assertSee($booking->guest->email);
|
||||
$this->get(GuestResource::getUrl('index'))->assertOk()->assertSee($booking->guest->email);
|
||||
Livewire::test(ListBookings::class)->assertCanSeeTableRecords([$booking]);
|
||||
}
|
||||
|
||||
public function test_landlord_confirms_a_reservation(): void
|
||||
{
|
||||
$booking = Booking::factory()->for($this->property)->reserved()->create();
|
||||
|
||||
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
|
||||
->callAction('confirm', ['notify' => true])
|
||||
->assertNotified('Buchung bestätigt');
|
||||
|
||||
$this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status);
|
||||
Mail::assertSent(BookingConfirmed::class);
|
||||
}
|
||||
|
||||
public function test_landlord_declines_without_notifying_the_guest(): void
|
||||
{
|
||||
$booking = Booking::factory()->for($this->property)->reserved()->create();
|
||||
|
||||
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
|
||||
->callAction('decline', ['notify' => false]);
|
||||
|
||||
$this->assertSame(BookingStatus::Declined, $booking->fresh()->status);
|
||||
Mail::assertNotSent(BookingDeclined::class);
|
||||
}
|
||||
|
||||
public function test_hold_can_be_extended(): void
|
||||
{
|
||||
$booking = Booking::factory()->for($this->property)->reserved(now()->addHours(2))->create();
|
||||
|
||||
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
|
||||
->callAction('extendHold', ['hours' => 24]);
|
||||
|
||||
$this->assertSame('2026-10-23 12:00', $booking->fresh()->hold_expires_at->format('Y-m-d H:i'));
|
||||
}
|
||||
|
||||
public function test_phone_booking_is_entered_and_confirmed_with_calculated_price(): void
|
||||
{
|
||||
Livewire::test(CreateBooking::class)
|
||||
->fillForm([
|
||||
'property_id' => $this->property->id,
|
||||
'guests' => 2,
|
||||
'arrival' => '2026-11-07',
|
||||
'departure' => '2026-11-10',
|
||||
'first_name' => 'Peter',
|
||||
'last_name' => 'Telefon',
|
||||
'email' => 'peter@example.com',
|
||||
'confirm_immediately' => true,
|
||||
'send_mails' => false,
|
||||
])
|
||||
->call('create')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$booking = Booking::sole();
|
||||
$this->assertSame([BookingStatus::Confirmed, 'manual', 3 * 6500 + 10800], [$booking->status, $booking->source, $booking->total]);
|
||||
Mail::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_phone_booking_for_occupied_dates_is_refused(): void
|
||||
{
|
||||
Booking::factory()->for($this->property)->create(['arrival' => '2026-11-08', 'departure' => '2026-11-12']);
|
||||
|
||||
Livewire::test(CreateBooking::class)
|
||||
->fillForm([
|
||||
'property_id' => $this->property->id,
|
||||
'guests' => 2,
|
||||
'arrival' => '2026-11-07',
|
||||
'departure' => '2026-11-10',
|
||||
'first_name' => 'Peter',
|
||||
'last_name' => 'Telefon',
|
||||
'email' => 'peter@example.com',
|
||||
])
|
||||
->call('create')
|
||||
->assertNotified('Buchung nicht möglich');
|
||||
|
||||
$this->assertSame(1, Booking::count());
|
||||
}
|
||||
|
||||
public function test_special_offer_with_euro_value_is_stored_in_cents(): void
|
||||
{
|
||||
Livewire::test(SpecialOffersRelationManager::class, ['ownerRecord' => $this->property, 'pageClass' => EditProperty::class])
|
||||
->callAction(TestAction::make(CreateAction::class)->table(), [
|
||||
'name' => 'Special Weekend',
|
||||
'discount_type' => 'nightly_rate',
|
||||
'discount_value' => '59.50',
|
||||
'arrival_weekdays' => [5],
|
||||
'season_names' => ['Winter'],
|
||||
])
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$offer = $this->property->specialOffers()->sole();
|
||||
$this->assertSame([5950, ['5'], ['Winter']], [$offer->discount_value, array_map('strval', $offer->arrival_weekdays), $offer->season_names]);
|
||||
}
|
||||
|
||||
public function test_blocked_period_is_created(): void
|
||||
{
|
||||
Livewire::test(BlockedPeriodsRelationManager::class, ['ownerRecord' => $this->property, 'pageClass' => EditProperty::class])
|
||||
->callAction(TestAction::make(CreateAction::class)->table(), [
|
||||
'starts_on' => '2026-12-01',
|
||||
'ends_on' => '2026-12-05',
|
||||
'reason' => 'Eigennutzung',
|
||||
])
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$this->assertSame(1, $this->property->blockedPeriods()->count());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Livewire\BookingRequest;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Property;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BookingRequestPageTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
|
||||
$this->seed(PropertySeeder::class);
|
||||
Mail::fake();
|
||||
}
|
||||
|
||||
public function test_booking_page_renders(): void
|
||||
{
|
||||
$this->withoutVite()
|
||||
->get(route('booking.create'))
|
||||
->assertOk()
|
||||
->assertSee('Preise & Buchung', false)
|
||||
->assertSeeLivewire(BookingRequest::class);
|
||||
}
|
||||
|
||||
public function test_selecting_dates_shows_the_live_price(): void
|
||||
{
|
||||
Livewire::test(BookingRequest::class)
|
||||
->call('selectDate', '2026-11-07')
|
||||
->call('selectDate', '2026-11-10')
|
||||
->assertSet('arrival', '2026-11-07')
|
||||
->assertSet('departure', '2026-11-10')
|
||||
->assertSee('Gesamtpreis')
|
||||
->assertSee('303,00');
|
||||
}
|
||||
|
||||
public function test_occupied_nights_cannot_be_selected_as_arrival_and_ranges_over_them_are_refused(): void
|
||||
{
|
||||
Booking::factory()->for(Property::sole())->create(['arrival' => '2026-11-10', 'departure' => '2026-11-14']);
|
||||
|
||||
Livewire::test(BookingRequest::class)
|
||||
->call('selectDate', '2026-11-11')
|
||||
->assertSet('arrival', null)
|
||||
->call('selectDate', '2026-11-08')
|
||||
->call('selectDate', '2026-11-12')
|
||||
->assertSet('departure', null)
|
||||
->assertSet('arrival', '2026-11-08')
|
||||
->call('selectDate', '2026-11-10')
|
||||
->assertSet('departure', '2026-11-10');
|
||||
}
|
||||
|
||||
public function test_minimum_stay_is_explained_to_the_guest(): void
|
||||
{
|
||||
Livewire::test(BookingRequest::class)
|
||||
->set('arrival', '2026-12-26')
|
||||
->set('departure', '2026-12-28')
|
||||
->assertSee('Mindestaufenthalt 6 Nächte');
|
||||
}
|
||||
|
||||
public function test_guest_submits_a_request(): void
|
||||
{
|
||||
Livewire::test(BookingRequest::class)
|
||||
->set('arrival', '2026-11-07')
|
||||
->set('departure', '2026-11-10')
|
||||
->set('firstName', 'Anna')
|
||||
->set('lastName', 'Muster')
|
||||
->set('email', 'anna@example.com')
|
||||
->set('privacyAccepted', true)
|
||||
->call('submit')
|
||||
->assertHasNoErrors()
|
||||
->assertSee('Vielen Dank, Anna!');
|
||||
|
||||
$this->assertSame(BookingStatus::Reserved, Booking::sole()->status);
|
||||
}
|
||||
|
||||
public function test_request_requires_contact_data_and_consent(): void
|
||||
{
|
||||
Livewire::test(BookingRequest::class)
|
||||
->set('arrival', '2026-11-07')
|
||||
->set('departure', '2026-11-10')
|
||||
->call('submit')
|
||||
->assertHasErrors(['firstName', 'lastName', 'email', 'privacyAccepted']);
|
||||
|
||||
$this->assertSame(0, Booking::count());
|
||||
}
|
||||
|
||||
public function test_honeypot_silently_drops_spam(): void
|
||||
{
|
||||
Livewire::test(BookingRequest::class)
|
||||
->set('arrival', '2026-11-07')
|
||||
->set('departure', '2026-11-10')
|
||||
->set('firstName', 'Spam')
|
||||
->set('lastName', 'Bot')
|
||||
->set('email', 'bot@example.com')
|
||||
->set('privacyAccepted', true)
|
||||
->set('website', 'http://spam.example')
|
||||
->call('submit');
|
||||
|
||||
$this->assertSame(0, Booking::count());
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
use App\Models\Season;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@@ -47,7 +48,7 @@ public function test_totals_match_the_previous_price_list(string $arrival, strin
|
||||
{
|
||||
$this->seed(PropertySeeder::class);
|
||||
|
||||
$quote = $this->calculator->calculate(Property::sole(), CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2);
|
||||
$quote = $this->calculator->calculate(Property::sole(), new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2));
|
||||
|
||||
$this->assertSame($expectedTotal, $quote->total());
|
||||
}
|
||||
@@ -56,7 +57,7 @@ public function test_stay_across_two_seasons_is_split_per_season(): void
|
||||
{
|
||||
$this->seed(PropertySeeder::class);
|
||||
|
||||
$quote = $this->calculator->calculate(Property::sole(), CarbonImmutable::parse('2026-06-18'), CarbonImmutable::parse('2026-06-22'), 2);
|
||||
$quote = $this->calculator->calculate(Property::sole(), new StayRequest(CarbonImmutable::parse('2026-06-18'), CarbonImmutable::parse('2026-06-22'), 2));
|
||||
|
||||
$accommodation = array_values(array_filter($quote->lines, fn ($line) => $line->type === QuoteLineType::Accommodation));
|
||||
$this->assertCount(2, $accommodation);
|
||||
@@ -69,7 +70,7 @@ public function test_deposit_is_a_share_of_the_rent_and_balance_is_due_before_ar
|
||||
{
|
||||
$property = $this->propertyWithSeason(nightlyRate: 5500, cleaningFee: 10800, depositPercent: 35);
|
||||
|
||||
$quote = $this->calculator->calculate($property, CarbonImmutable::parse('2026-03-10'), CarbonImmutable::parse('2026-03-13'), 3);
|
||||
$quote = $this->calculator->calculate($property, new StayRequest(CarbonImmutable::parse('2026-03-10'), CarbonImmutable::parse('2026-03-13'), 3));
|
||||
|
||||
$rent = 3 * 5500 + 3 * 750;
|
||||
$this->assertSame($rent, $quote->rent());
|
||||
@@ -84,10 +85,10 @@ public function test_extras_are_priced_per_item_or_per_night(): void
|
||||
$linen = Extra::factory()->for($property)->create(['price' => 1400, 'pricing' => ExtraPricing::PerItem]);
|
||||
$babyBed = Extra::factory()->for($property)->create(['price' => 300, 'pricing' => ExtraPricing::PerNight]);
|
||||
|
||||
$quote = $this->calculator->calculate($property, CarbonImmutable::parse('2026-03-10'), CarbonImmutable::parse('2026-03-14'), 2, [
|
||||
$quote = $this->calculator->calculate($property, new StayRequest(CarbonImmutable::parse('2026-03-10'), CarbonImmutable::parse('2026-03-14'), 2, [
|
||||
$linen->id => 2,
|
||||
$babyBed->id => 1,
|
||||
]);
|
||||
]));
|
||||
|
||||
$extras = array_values(array_filter($quote->lines, fn ($line) => $line->type === QuoteLineType::Extra));
|
||||
$this->assertSame([2 * 1400, 4 * 300], array_map(fn ($line) => $line->amount, $extras));
|
||||
@@ -100,7 +101,7 @@ public function test_minimum_stay_of_the_arrival_season_is_enforced(): void
|
||||
$this->expectException(QuoteException::class);
|
||||
$this->expectExceptionMessage('Mindestaufenthalt 3 Nächte');
|
||||
|
||||
$this->calculator->calculate(Property::sole(), CarbonImmutable::parse('2026-08-29'), CarbonImmutable::parse('2026-08-31'), 2);
|
||||
$this->calculator->calculate(Property::sole(), new StayRequest(CarbonImmutable::parse('2026-08-29'), CarbonImmutable::parse('2026-08-31'), 2));
|
||||
}
|
||||
|
||||
public function test_nights_without_a_season_cannot_be_priced(): void
|
||||
@@ -110,7 +111,7 @@ public function test_nights_without_a_season_cannot_be_priced(): void
|
||||
$this->expectException(QuoteException::class);
|
||||
$this->expectExceptionMessage('01.04.2026');
|
||||
|
||||
$this->calculator->calculate($property, CarbonImmutable::parse('2026-03-30'), CarbonImmutable::parse('2026-04-02'), 2);
|
||||
$this->calculator->calculate($property, new StayRequest(CarbonImmutable::parse('2026-03-30'), CarbonImmutable::parse('2026-04-02'), 2));
|
||||
}
|
||||
|
||||
public function test_guest_count_is_limited_by_the_property(): void
|
||||
@@ -119,7 +120,7 @@ public function test_guest_count_is_limited_by_the_property(): void
|
||||
|
||||
$this->expectException(QuoteException::class);
|
||||
|
||||
$this->calculator->calculate($property, CarbonImmutable::parse('2026-03-10'), CarbonImmutable::parse('2026-03-12'), $property->max_guests + 1);
|
||||
$this->calculator->calculate($property, new StayRequest(CarbonImmutable::parse('2026-03-10'), CarbonImmutable::parse('2026-03-12'), $property->max_guests + 1));
|
||||
}
|
||||
|
||||
public function test_departure_must_be_after_arrival(): void
|
||||
@@ -128,7 +129,7 @@ public function test_departure_must_be_after_arrival(): void
|
||||
|
||||
$this->expectException(QuoteException::class);
|
||||
|
||||
$this->calculator->calculate($property, CarbonImmutable::parse('2026-03-10'), CarbonImmutable::parse('2026-03-10'), 2);
|
||||
$this->calculator->calculate($property, new StayRequest(CarbonImmutable::parse('2026-03-10'), CarbonImmutable::parse('2026-03-10'), 2));
|
||||
}
|
||||
|
||||
public function test_inactive_extras_cannot_be_booked(): void
|
||||
@@ -138,7 +139,7 @@ public function test_inactive_extras_cannot_be_booked(): void
|
||||
|
||||
$this->expectException(QuoteException::class);
|
||||
|
||||
$this->calculator->calculate($property, CarbonImmutable::parse('2026-03-10'), CarbonImmutable::parse('2026-03-12'), 2, [$extra->id => 1]);
|
||||
$this->calculator->calculate($property, new StayRequest(CarbonImmutable::parse('2026-03-10'), CarbonImmutable::parse('2026-03-12'), 2, [$extra->id => 1]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Actions\ConfirmBooking;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Actions\ExpireReservations;
|
||||
use App\Availability\AvailabilityChecker;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Mail\BookingConfirmed;
|
||||
use App\Mail\NewReservation;
|
||||
use App\Mail\ReservationExpired;
|
||||
use App\Mail\ReservationReceived;
|
||||
use App\Models\BlockedPeriod;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\StayRequest;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ReservationWorkflowTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Property $property;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
|
||||
$this->seed(PropertySeeder::class);
|
||||
$this->property = Property::sole();
|
||||
Mail::fake();
|
||||
}
|
||||
|
||||
public function test_active_reservations_and_blocked_periods_occupy_the_calendar_but_allow_changeover(): void
|
||||
{
|
||||
Booking::factory()->for($this->property)->reserved(now()->addHour())->create(['arrival' => '2026-11-10', 'departure' => '2026-11-14']);
|
||||
BlockedPeriod::factory()->for($this->property)->create(['starts_on' => '2026-11-20', 'ends_on' => '2026-11-22']);
|
||||
$availability = new AvailabilityChecker;
|
||||
|
||||
$this->assertFalse($availability->isAvailable($this->property, $this->date('2026-11-12'), $this->date('2026-11-16')));
|
||||
$this->assertFalse($availability->isAvailable($this->property, $this->date('2026-11-18'), $this->date('2026-11-21')));
|
||||
$this->assertTrue($availability->isAvailable($this->property, $this->date('2026-11-14'), $this->date('2026-11-16')), 'arrival on departure day');
|
||||
$this->assertTrue($availability->isAvailable($this->property, $this->date('2026-11-07'), $this->date('2026-11-10')), 'departure on arrival day');
|
||||
$this->assertSame(['2026-11-10', '2026-11-11', '2026-11-12', '2026-11-13', '2026-11-20', '2026-11-21'], array_keys(
|
||||
$availability->occupiedNights($this->property, $this->date('2026-11-01'), $this->date('2026-12-01')),
|
||||
));
|
||||
}
|
||||
|
||||
public function test_reservation_with_elapsed_hold_no_longer_occupies_the_calendar(): void
|
||||
{
|
||||
Booking::factory()->for($this->property)->reserved(now()->subMinute())->create(['arrival' => '2026-11-10', 'departure' => '2026-11-14']);
|
||||
|
||||
$this->assertTrue((new AvailabilityChecker)->isAvailable($this->property, $this->date('2026-11-10'), $this->date('2026-11-14')));
|
||||
}
|
||||
|
||||
public function test_request_creates_a_held_reservation_and_sends_quote_and_notification(): void
|
||||
{
|
||||
$booking = $this->reserve('2026-11-07', '2026-11-10');
|
||||
|
||||
$this->assertSame(BookingStatus::Reserved, $booking->status);
|
||||
$this->assertSame('2026-10-24 10:00', $booking->hold_expires_at->format('Y-m-d H:i'));
|
||||
$this->assertSame(3 * 6500 + 10800, $booking->total);
|
||||
$this->assertSame('2026-'.str_pad((string) $booking->id, 4, '0', STR_PAD_LEFT), $booking->reference);
|
||||
$this->assertSame('anna@example.com', $booking->guest->email);
|
||||
Mail::assertSent(ReservationReceived::class, fn (ReservationReceived $mail): bool => $mail->hasTo('anna@example.com'));
|
||||
Mail::assertSent(NewReservation::class, fn (NewReservation $mail): bool => $mail->hasTo(config('fewo.notification_email')));
|
||||
}
|
||||
|
||||
public function test_request_for_occupied_dates_is_rejected(): void
|
||||
{
|
||||
$this->reserve('2026-11-07', '2026-11-10');
|
||||
|
||||
$this->expectException(ReservationException::class);
|
||||
|
||||
$this->reserve('2026-11-09', '2026-11-12');
|
||||
}
|
||||
|
||||
public function test_returning_guest_is_recognised_by_email(): void
|
||||
{
|
||||
$first = $this->reserve('2026-11-07', '2026-11-10');
|
||||
$second = $this->reserve('2026-11-20', '2026-11-23', 'ANNA@example.com');
|
||||
|
||||
$this->assertTrue($first->guest->is($second->guest));
|
||||
}
|
||||
|
||||
public function test_expired_holds_are_marked_and_the_landlord_is_notified(): void
|
||||
{
|
||||
$booking = $this->reserve('2026-11-07', '2026-11-10');
|
||||
|
||||
$this->travel(47)->hours();
|
||||
$this->assertSame(0, (new ExpireReservations)->handle());
|
||||
|
||||
$this->travel(2)->hours();
|
||||
$this->assertSame(1, (new ExpireReservations)->handle());
|
||||
|
||||
$this->assertSame(BookingStatus::Expired, $booking->fresh()->status);
|
||||
Mail::assertSent(ReservationExpired::class);
|
||||
}
|
||||
|
||||
public function test_confirmation_makes_the_booking_binding_and_informs_the_guest(): void
|
||||
{
|
||||
$booking = $this->reserve('2026-11-07', '2026-11-10');
|
||||
|
||||
app(ConfirmBooking::class)->handle($booking);
|
||||
|
||||
$booking->refresh();
|
||||
$this->assertSame(BookingStatus::Confirmed, $booking->status);
|
||||
$this->assertNull($booking->hold_expires_at);
|
||||
$this->assertNotNull($booking->confirmed_at);
|
||||
Mail::assertSent(BookingConfirmed::class, fn (BookingConfirmed $mail): bool => $mail->hasTo('anna@example.com'));
|
||||
}
|
||||
|
||||
public function test_expired_reservation_cannot_be_confirmed_once_the_dates_are_taken(): void
|
||||
{
|
||||
$expired = $this->reserve('2026-11-07', '2026-11-10');
|
||||
$this->travel(3)->days();
|
||||
(new ExpireReservations)->handle();
|
||||
$this->reserve('2026-11-08', '2026-11-12', 'other@example.com');
|
||||
|
||||
$this->expectException(ReservationException::class);
|
||||
|
||||
app(ConfirmBooking::class)->handle($expired->fresh());
|
||||
}
|
||||
|
||||
public function test_mails_render(): void
|
||||
{
|
||||
$booking = $this->reserve('2026-11-07', '2026-11-10');
|
||||
|
||||
$this->assertStringContainsString('vorgemerkt', (new ReservationReceived($booking))->render());
|
||||
$this->assertStringContainsString($booking->reference, (new NewReservation($booking))->render());
|
||||
$this->assertStringContainsString('bestätigen', (new BookingConfirmed($booking))->render());
|
||||
}
|
||||
|
||||
private function reserve(string $arrival, string $departure, string $email = 'anna@example.com'): Booking
|
||||
{
|
||||
return app(CreateReservation::class)->handle(
|
||||
$this->property,
|
||||
new StayRequest($this->date($arrival), $this->date($departure), 2),
|
||||
['first_name' => 'Anna', 'last_name' => 'Muster', 'email' => $email],
|
||||
);
|
||||
}
|
||||
|
||||
private function date(string $date): CarbonImmutable
|
||||
{
|
||||
return CarbonImmutable::parse($date);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\DiscountType;
|
||||
use App\Models\Property;
|
||||
use App\Models\Season;
|
||||
use App\Models\SpecialOffer;
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\StayRequest;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SpecialOfferPricingTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Property $property;
|
||||
|
||||
private PriceCalculator $calculator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->calculator = new PriceCalculator;
|
||||
$this->property = Property::factory()->create(['cleaning_fee' => 10000, 'deposit_percent' => 50]);
|
||||
Season::factory()->for($this->property)->create(['name' => 'Winter', 'starts_on' => '2026-01-03', 'ends_on' => '2026-03-07', 'nightly_rate' => 5000, 'min_nights' => 2]);
|
||||
Season::factory()->for($this->property)->create(['name' => 'Nebensaison', 'starts_on' => '2026-03-07', 'ends_on' => '2026-04-03', 'nightly_rate' => 7000, 'min_nights' => 2]);
|
||||
}
|
||||
|
||||
public function test_last_minute_applies_only_within_the_booking_window(): void
|
||||
{
|
||||
$this->offer(['name' => 'Last Minute', 'max_days_before_arrival' => 14, 'discount_value' => 20]);
|
||||
$stay = $this->stay('2026-02-10', '2026-02-14');
|
||||
|
||||
$lastMinute = $this->calculator->calculate($this->property, $stay, CarbonImmutable::parse('2026-02-01'));
|
||||
$early = $this->calculator->calculate($this->property, $stay, CarbonImmutable::parse('2026-01-10'));
|
||||
|
||||
$this->assertSame(4000, $lastMinute->discount());
|
||||
$this->assertSame(0, $early->discount());
|
||||
}
|
||||
|
||||
public function test_offer_can_be_restricted_to_seasons_of_the_arrival(): void
|
||||
{
|
||||
$this->offer(['season_names' => ['Winter'], 'discount_value' => 10]);
|
||||
|
||||
$winter = $this->calculator->calculate($this->property, $this->stay('2026-02-10', '2026-02-12'));
|
||||
$spring = $this->calculator->calculate($this->property, $this->stay('2026-03-10', '2026-03-12'));
|
||||
|
||||
$this->assertSame(1000, $winter->discount());
|
||||
$this->assertSame(0, $spring->discount());
|
||||
}
|
||||
|
||||
public function test_special_weekend_with_fixed_nightly_rate_on_friday_arrival(): void
|
||||
{
|
||||
$this->offer([
|
||||
'name' => 'Special Weekend',
|
||||
'discount_type' => DiscountType::NightlyRate,
|
||||
'discount_value' => 3900,
|
||||
'arrival_weekdays' => [5],
|
||||
'max_nights' => 2,
|
||||
]);
|
||||
|
||||
$friday = $this->calculator->calculate($this->property, $this->stay('2026-02-13', '2026-02-15'));
|
||||
$saturday = $this->calculator->calculate($this->property, $this->stay('2026-02-14', '2026-02-16'));
|
||||
|
||||
$this->assertSame(2 * (5000 - 3900), $friday->discount());
|
||||
$this->assertSame(0, $saturday->discount());
|
||||
}
|
||||
|
||||
public function test_free_nights_discount_the_cheapest_nights(): void
|
||||
{
|
||||
$this->offer(['name' => '7 = 6', 'discount_type' => DiscountType::FreeNights, 'discount_value' => 1, 'min_nights' => 7]);
|
||||
|
||||
$quote = $this->calculator->calculate($this->property, $this->stay('2026-03-03', '2026-03-10'));
|
||||
|
||||
$this->assertSame(5000, $quote->discount());
|
||||
}
|
||||
|
||||
public function test_offer_with_code_needs_the_code(): void
|
||||
{
|
||||
$this->offer(['name' => 'Stammgast', 'code' => 'OSTSEE26', 'discount_type' => DiscountType::AmountPerStay, 'discount_value' => 2500]);
|
||||
|
||||
$withCode = $this->calculator->calculate($this->property, $this->stay('2026-02-10', '2026-02-12', 'ostsee26'));
|
||||
$wrongCode = $this->calculator->calculate($this->property, $this->stay('2026-02-10', '2026-02-12', 'FALSCH'));
|
||||
$withoutCode = $this->calculator->calculate($this->property, $this->stay('2026-02-10', '2026-02-12'));
|
||||
|
||||
$this->assertSame([2500, true], [$withCode->discount(), $withCode->promoCodeApplied]);
|
||||
$this->assertSame([0, false], [$wrongCode->discount(), $wrongCode->promoCodeApplied]);
|
||||
$this->assertSame([0, null], [$withoutCode->discount(), $withoutCode->promoCodeApplied]);
|
||||
}
|
||||
|
||||
public function test_guest_gets_the_better_of_best_exclusive_offer_and_all_combinable_offers(): void
|
||||
{
|
||||
$this->offer(['name' => 'Kombi A', 'discount_value' => 5, 'is_combinable' => true]);
|
||||
$this->offer(['name' => 'Kombi B', 'discount_value' => 5, 'is_combinable' => true]);
|
||||
$exclusive = $this->offer(['name' => 'Exklusiv', 'discount_value' => 8]);
|
||||
$stay = $this->stay('2026-02-10', '2026-02-20');
|
||||
|
||||
$this->assertSame(5000, $this->calculator->calculate($this->property, $stay)->discount());
|
||||
|
||||
$exclusive->update(['discount_value' => 15]);
|
||||
$quote = $this->calculator->calculate($this->property, $stay);
|
||||
|
||||
$this->assertSame(7500, $quote->discount());
|
||||
$this->assertSame(['Exklusiv'], array_values(array_map(fn ($line) => $line->label, array_filter($quote->lines, fn ($line) => $line->amount < 0))));
|
||||
}
|
||||
|
||||
public function test_deposit_is_calculated_on_the_discounted_rent(): void
|
||||
{
|
||||
$this->offer(['discount_value' => 10]);
|
||||
|
||||
$quote = $this->calculator->calculate($this->property, $this->stay('2026-02-10', '2026-02-14'));
|
||||
|
||||
$this->assertSame((20000 - 2000) / 2, $quote->deposit());
|
||||
$this->assertSame(20000 - 2000 + 10000, $quote->total());
|
||||
}
|
||||
|
||||
public function test_inactive_offers_are_ignored(): void
|
||||
{
|
||||
$this->offer(['is_active' => false]);
|
||||
|
||||
$this->assertSame(0, $this->calculator->calculate($this->property, $this->stay('2026-02-10', '2026-02-14'))->discount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $attributes
|
||||
*/
|
||||
private function offer(array $attributes): SpecialOffer
|
||||
{
|
||||
return SpecialOffer::factory()->for($this->property)->create($attributes);
|
||||
}
|
||||
|
||||
private function stay(string $arrival, string $departure, ?string $promoCode = null): StayRequest
|
||||
{
|
||||
return new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2, promoCode: $promoCode);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import laravel from 'laravel-vite-plugin';
|
||||
import { bunny } from 'laravel-vite-plugin/fonts';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
|
||||
export default defineConfig({
|
||||
@@ -8,11 +7,6 @@ export default defineConfig({
|
||||
laravel({
|
||||
input: ['resources/css/app.css', 'resources/js/app.js'],
|
||||
refresh: true,
|
||||
fonts: [
|
||||
bunny('Instrument Sans', {
|
||||
weights: [400, 500, 600],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
tailwindcss(),
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user