Offers by their own rules, seasonal photos per section, theme authoring tooling
- Special offers: kinds (rule, fixed dates, gap filler), package price, priority, highlight;
GapFinder detects calendar gaps (optionally waiving the minimum stay); OfferShowcase decides
what the website advertises and prices fixed dates/gaps with PriceCalculator; offers section
shows them side by side, as a list or rotating; hero can show the top offer. Appearances no
longer carry a featured offer.
- Sections get stable ids; appearances set photos per section ("Bilder je Baustein") and
sections can be limited to appearances. Photo pickers show thumbnails everywhere.
- Themes: themes:make (scaffold, never overwrites), themes:check (contract, build, markup,
colours, external resources, WCAG contrast), themes:preview (signed links per page and
appearance), signed ?theme= preview and preview action in the site form, inherited colour
tokens in the admin. Base CSS split into theme.css + reusable theme-base.css.
- docs/THEME-ERSTELLUNG.md: binding guide for building additional themes elsewhere.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bc77b64ea7
commit
7d0bc93abc
50 files changed
+2805
-259
No files matched your search
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Pricing;
|
||||
|
||||
use App\Models\SpecialOffer;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
* An offer as the website shows it: for fixed dates and gap fillers with concrete dates and an example price.
|
||||
*/
|
||||
final readonly class AdvertisedOffer
|
||||
{
|
||||
/**
|
||||
* @param list<string> $conditions
|
||||
*/
|
||||
public function __construct(
|
||||
public SpecialOffer $offer,
|
||||
public string $title,
|
||||
public ?string $description,
|
||||
public string $advantage,
|
||||
public array $conditions,
|
||||
public ?CarbonImmutable $arrival = null,
|
||||
public ?CarbonImmutable $departure = null,
|
||||
public ?PriceQuote $quote = null,
|
||||
) {}
|
||||
|
||||
public function nights(): ?int
|
||||
{
|
||||
return $this->arrival && $this->departure ? (int) $this->arrival->diffInDays($this->departure) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Price before the discount (accommodation, extra guests, cleaning) – for "statt …".
|
||||
*/
|
||||
public function regularTotal(): ?int
|
||||
{
|
||||
return $this->quote ? $this->quote->total() + $this->quote->discount() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the booking page, with the dates filled in when the offer has concrete dates.
|
||||
*/
|
||||
public function bookingUrl(): string
|
||||
{
|
||||
return route('booking.create', array_filter([
|
||||
'anreise' => $this->arrival?->toDateString(),
|
||||
'abreise' => $this->departure?->toDateString(),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stable key for the view (an offer can appear several times with different gaps).
|
||||
*/
|
||||
public function key(): string
|
||||
{
|
||||
return $this->offer->id.'-'.($this->arrival?->toDateString() ?? 'rule');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace App\Pricing;
|
||||
|
||||
use App\Availability\AvailabilityChecker;
|
||||
use App\Availability\GapFinder;
|
||||
use App\Enums\OfferKind;
|
||||
use App\Enums\QuoteLineType;
|
||||
use App\Models\Property;
|
||||
use App\Models\SpecialOffer;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Which offers the website advertises right now – independent of the seasonal appearance.
|
||||
*
|
||||
* Shown are active, public offers without a code whose booking window is open. Fixed dates only while they
|
||||
* are still free; gap fillers once per free gap found in the calendar. Fixed dates and gaps are priced
|
||||
* with PriceCalculator, so the advertised price is exactly what the guest is quoted. Order: highlighted
|
||||
* first, then priority, then the earliest date.
|
||||
*/
|
||||
class OfferShowcase
|
||||
{
|
||||
/** Gap fillers without a lead time limit look this many days ahead. */
|
||||
public const GAP_HORIZON_DAYS = 60;
|
||||
|
||||
/** At most this many gaps per gap filler. */
|
||||
public const GAPS_PER_OFFER = 3;
|
||||
|
||||
public function __construct(
|
||||
private PriceCalculator $calculator,
|
||||
private AvailabilityChecker $availability = new AvailabilityChecker,
|
||||
private GapFinder $gaps = new GapFinder,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return Collection<int, AdvertisedOffer>
|
||||
*/
|
||||
public function current(Property $property, ?CarbonImmutable $now = null, ?int $limit = null, bool $featuredOnly = false): Collection
|
||||
{
|
||||
$now ??= CarbonImmutable::now();
|
||||
$today = $now->startOfDay();
|
||||
|
||||
$offers = $property->specialOffers()
|
||||
->active()
|
||||
->where('is_public', true)
|
||||
->whereNull('code')
|
||||
->when($featuredOnly, fn ($query) => $query->where('is_featured', true))
|
||||
->where(fn ($query) => $query->whereNull('bookable_from')->orWhere('bookable_from', '<=', $now))
|
||||
->where(fn ($query) => $query->whereNull('bookable_until')->orWhere('bookable_until', '>=', $now))
|
||||
->get();
|
||||
|
||||
$advertised = $offers->flatMap(fn (SpecialOffer $offer): array => match ($offer->kind ?? OfferKind::Rule) {
|
||||
OfferKind::Rule => $this->rule($offer, $today),
|
||||
OfferKind::FixedDates => $this->fixedDates($property, $offer, $now),
|
||||
OfferKind::GapFiller => $this->gapFiller($property, $offer, $now),
|
||||
});
|
||||
|
||||
$sorted = $advertised->sortBy([
|
||||
fn (AdvertisedOffer $a, AdvertisedOffer $b): int => $b->offer->is_featured <=> $a->offer->is_featured,
|
||||
fn (AdvertisedOffer $a, AdvertisedOffer $b): int => $b->offer->priority <=> $a->offer->priority,
|
||||
fn (AdvertisedOffer $a, AdvertisedOffer $b): int => ($a->arrival?->getTimestamp() ?? PHP_INT_MAX) <=> ($b->arrival?->getTimestamp() ?? PHP_INT_MAX),
|
||||
])->values();
|
||||
|
||||
return $limit ? $sorted->take($limit)->values() : $sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<AdvertisedOffer>
|
||||
*/
|
||||
private function rule(SpecialOffer $offer, CarbonImmutable $today): array
|
||||
{
|
||||
if ($offer->stay_until !== null && $offer->stay_until->lessThanOrEqualTo($today)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [$this->advertised($offer)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<AdvertisedOffer>
|
||||
*/
|
||||
private function fixedDates(Property $property, SpecialOffer $offer, CarbonImmutable $now): array
|
||||
{
|
||||
if ($offer->stay_from === null || $offer->stay_until === null || $offer->stay_from->lessThanOrEqualTo($now->startOfDay())) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! $this->availability->isAvailable($property, $offer->stay_from, $offer->stay_until)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$quote = $this->pricedWith($property, $offer, $offer->stay_from, $offer->stay_until, $now);
|
||||
|
||||
return $quote ? [$this->advertised($offer, $offer->stay_from, $offer->stay_until, $quote)] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<AdvertisedOffer>
|
||||
*/
|
||||
private function gapFiller(Property $property, SpecialOffer $offer, CarbonImmutable $now): array
|
||||
{
|
||||
$today = $now->startOfDay();
|
||||
$from = $today->addDays(max(1, $offer->min_days_before_arrival ?? 1));
|
||||
$until = $today->addDays($offer->max_days_before_arrival ?? self::GAP_HORIZON_DAYS)->addDay();
|
||||
if ($offer->stay_from !== null && $offer->stay_from->greaterThan($from)) {
|
||||
$from = $offer->stay_from;
|
||||
}
|
||||
|
||||
$advertised = [];
|
||||
foreach ($this->gaps->gaps($property, $from, $until, $offer->max_gap_nights ?? 7) as [$arrival, $departure]) {
|
||||
$quote = $this->pricedWith($property, $offer, $arrival, $departure, $now);
|
||||
if ($quote !== null) {
|
||||
$advertised[] = $this->advertised($offer, $arrival, $departure, $quote);
|
||||
}
|
||||
|
||||
if (count($advertised) >= self::GAPS_PER_OFFER) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $advertised;
|
||||
}
|
||||
|
||||
/**
|
||||
* The quote for the stay, if the offer is actually applied to it (it may lose against a better offer
|
||||
* or fail a condition such as the minimum stay); priced for the number of guests included in the rent.
|
||||
*/
|
||||
private function pricedWith(Property $property, SpecialOffer $offer, CarbonImmutable $arrival, CarbonImmutable $departure, CarbonImmutable $now): ?PriceQuote
|
||||
{
|
||||
$quote = rescue(
|
||||
fn (): PriceQuote => $this->calculator->calculate($property, new StayRequest($arrival, $departure, max(1, $property->included_guests)), $now),
|
||||
null,
|
||||
false,
|
||||
);
|
||||
|
||||
$applied = $quote !== null && collect($quote->lines)
|
||||
->contains(fn (QuoteLine $line): bool => $line->type === QuoteLineType::Discount && $line->label === $offer->name);
|
||||
|
||||
return $applied ? $quote : null;
|
||||
}
|
||||
|
||||
private function advertised(SpecialOffer $offer, ?CarbonImmutable $arrival = null, ?CarbonImmutable $departure = null, ?PriceQuote $quote = null): AdvertisedOffer
|
||||
{
|
||||
return new AdvertisedOffer(
|
||||
offer: $offer,
|
||||
title: $offer->name,
|
||||
description: $offer->public_description,
|
||||
advantage: $offer->advantageLabel(),
|
||||
conditions: $offer->conditionSummary(),
|
||||
arrival: $arrival,
|
||||
departure: $departure,
|
||||
quote: $quote,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Pricing;
|
||||
|
||||
use App\Availability\GapFinder;
|
||||
use App\Enums\ExtraPricing;
|
||||
use App\Enums\OfferKind;
|
||||
use App\Enums\QuoteLineType;
|
||||
use App\Models\Extra;
|
||||
use App\Models\Property;
|
||||
@@ -13,6 +15,8 @@
|
||||
|
||||
class PriceCalculator
|
||||
{
|
||||
public function __construct(private GapFinder $gaps = new GapFinder) {}
|
||||
|
||||
/**
|
||||
* Price a stay. Special offers are applied automatically; $bookedAt (default: now) decides
|
||||
* time-dependent offers such as last minute or early bird.
|
||||
@@ -32,14 +36,18 @@ public function calculate(Property $property, StayRequest $stay, ?CarbonImmutabl
|
||||
$nights = $stay->nights();
|
||||
$nightSeasons = $this->seasonPerNight($property, $stay);
|
||||
|
||||
$bookedAt ??= CarbonImmutable::now();
|
||||
$offers = $this->applicableOffers($property, $stay, $nightSeasons, $bookedAt);
|
||||
|
||||
$arrivalSeason = $nightSeasons[0];
|
||||
if ($nights < $arrivalSeason->min_nights) {
|
||||
$minimumStayWaived = $offers->contains(fn (SpecialOffer $offer): bool => $offer->waives_min_stay && $offer->kind === OfferKind::GapFiller);
|
||||
if ($nights < $arrivalSeason->min_nights && ! $minimumStayWaived) {
|
||||
throw QuoteException::minimumStay($arrivalSeason->min_nights, $arrivalSeason->name);
|
||||
}
|
||||
|
||||
$lines = $this->accommodationLines($nightSeasons);
|
||||
|
||||
$appliedOffers = $this->bestOffers($property, $stay, $nightSeasons, $bookedAt ?? CarbonImmutable::now());
|
||||
$appliedOffers = $this->bestOffers($offers, $nightSeasons);
|
||||
foreach ($appliedOffers as ['offer' => $offer, 'discount' => $discount]) {
|
||||
$lines[] = new QuoteLine(QuoteLineType::Discount, $offer->name, 1, -$discount, -$discount);
|
||||
}
|
||||
@@ -117,20 +125,37 @@ private function accommodationLines(array $nightSeasons): array
|
||||
), $runs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Active offers whose conditions the stay meets. The calendar gap is only looked up if a gap filler exists.
|
||||
*
|
||||
* @param non-empty-list<Season> $nightSeasons
|
||||
* @return Collection<int, SpecialOffer>
|
||||
*/
|
||||
private function applicableOffers(Property $property, StayRequest $stay, array $nightSeasons, CarbonImmutable $bookedAt): Collection
|
||||
{
|
||||
$offers = $property->specialOffers()->active()->get();
|
||||
|
||||
$gapNights = $offers->contains(fn (SpecialOffer $offer): bool => $offer->kind === OfferKind::GapFiller)
|
||||
? $this->gaps->gapContaining($property, $stay->arrival, $stay->departure)
|
||||
: null;
|
||||
|
||||
return $offers->filter(fn (SpecialOffer $offer): bool => $offer->appliesTo($stay, $nightSeasons[0]->name, $bookedAt, $gapNights))->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Collection<int, SpecialOffer> $offers
|
||||
* @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
|
||||
private function bestOffers(Collection $offers, array $nightSeasons): 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))
|
||||
$candidates = $offers
|
||||
->map(fn (SpecialOffer $offer): array => ['offer' => $offer, 'discount' => $offer->discountFor($nightlyRates)])
|
||||
->filter(fn (array $candidate): bool => $candidate['discount'] > 0);
|
||||
|
||||
|
||||
Reference in new issue
Block a user