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
@@ -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