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
@@ -3,7 +3,9 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\DiscountType;
|
||||
use App\Enums\OfferKind;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Support\Money;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Factories\SpecialOfferFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
@@ -14,16 +16,19 @@
|
||||
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".
|
||||
* A discount rule such as last minute, early bird, long stay, special weekends or a code for regular guests,
|
||||
* a fixed date package or a gap filler (see OfferKind). Every condition left empty means "no restriction".
|
||||
*/
|
||||
#[Fillable([
|
||||
'property_id',
|
||||
'name',
|
||||
'kind',
|
||||
'public_description',
|
||||
'is_active',
|
||||
'is_public',
|
||||
'is_combinable',
|
||||
'priority',
|
||||
'is_featured',
|
||||
'code',
|
||||
'discount_type',
|
||||
'discount_value',
|
||||
@@ -35,6 +40,8 @@
|
||||
'max_days_before_arrival',
|
||||
'min_nights',
|
||||
'max_nights',
|
||||
'max_gap_nights',
|
||||
'waives_min_stay',
|
||||
'arrival_weekdays',
|
||||
'season_names',
|
||||
])]
|
||||
@@ -54,6 +61,9 @@ protected function casts(): array
|
||||
'is_active' => 'boolean',
|
||||
'is_public' => 'boolean',
|
||||
'is_combinable' => 'boolean',
|
||||
'is_featured' => 'boolean',
|
||||
'waives_min_stay' => 'boolean',
|
||||
'kind' => OfferKind::class,
|
||||
'discount_type' => DiscountType::class,
|
||||
'stay_from' => 'immutable_date',
|
||||
'stay_until' => 'immutable_date',
|
||||
@@ -84,13 +94,23 @@ protected function active(Builder $query): Builder
|
||||
|
||||
/**
|
||||
* Whether all conditions are met. Offers with a code only apply when the guest entered that code.
|
||||
* $gapNights is the length of the calendar gap containing the stay (null = not inside a gap); it only
|
||||
* matters for gap fillers.
|
||||
*/
|
||||
public function appliesTo(StayRequest $stay, string $arrivalSeasonName, CarbonImmutable $bookedAt): bool
|
||||
public function appliesTo(StayRequest $stay, string $arrivalSeasonName, CarbonImmutable $bookedAt, ?int $gapNights = null): bool
|
||||
{
|
||||
$nights = $stay->nights();
|
||||
$daysBeforeArrival = (int) $bookedAt->startOfDay()->diffInDays($stay->arrival, false);
|
||||
|
||||
$kindMatches = match ($this->kind ?? OfferKind::Rule) {
|
||||
OfferKind::Rule => true,
|
||||
OfferKind::FixedDates => $this->stay_from !== null && $this->stay_until !== null
|
||||
&& $stay->arrival->isSameDay($this->stay_from) && $stay->departure->isSameDay($this->stay_until),
|
||||
OfferKind::GapFiller => $gapNights !== null && ($this->max_gap_nights === null || $gapNights <= $this->max_gap_nights),
|
||||
};
|
||||
|
||||
return $this->is_active
|
||||
&& $kindMatches
|
||||
&& ($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))
|
||||
@@ -118,11 +138,55 @@ public function discountFor(array $nightlyRates): int
|
||||
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)),
|
||||
DiscountType::FixedStayPrice => max(0, $accommodation - $this->discount_value),
|
||||
};
|
||||
|
||||
return min($discount, $accommodation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Short label of the advantage, e.g. "−10 %", "59,00 € / Nacht" or "Pauschal 560,00 €".
|
||||
*/
|
||||
public function advantageLabel(): string
|
||||
{
|
||||
return match ($this->discount_type) {
|
||||
DiscountType::Percent => "−{$this->discount_value} %",
|
||||
DiscountType::AmountPerStay => '−'.Money::format($this->discount_value),
|
||||
DiscountType::NightlyRate => Money::format($this->discount_value).' / Nacht',
|
||||
DiscountType::FreeNights => $this->discount_value === 1 ? '1 Nacht gratis' : "{$this->discount_value} Nächte gratis",
|
||||
DiscountType::FixedStayPrice => 'Pauschal '.Money::format($this->discount_value),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The conditions in plain German for guests, e.g. ["ab 3 Nächten", "Anreise freitags", "bis 14 Tage vor Anreise"].
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function conditionSummary(): array
|
||||
{
|
||||
$weekdays = [1 => 'montags', 2 => 'dienstags', 3 => 'mittwochs', 4 => 'donnerstags', 5 => 'freitags', 6 => 'samstags', 7 => 'sonntags'];
|
||||
|
||||
return array_values(array_filter([
|
||||
match (true) {
|
||||
$this->kind === OfferKind::FixedDates => null,
|
||||
$this->min_nights !== null && $this->max_nights !== null && $this->min_nights === $this->max_nights => "genau {$this->min_nights} Nächte",
|
||||
$this->min_nights !== null && $this->max_nights !== null => "{$this->min_nights} bis {$this->max_nights} Nächte",
|
||||
$this->min_nights !== null => "ab {$this->min_nights} Nächten",
|
||||
$this->max_nights !== null => "bis {$this->max_nights} Nächte",
|
||||
default => null,
|
||||
},
|
||||
empty($this->arrival_weekdays) ? null : 'Anreise '.collect($this->arrival_weekdays)->map(fn ($day): string => $weekdays[(int) $day] ?? '')->implode(' oder '),
|
||||
$this->max_days_before_arrival !== null ? "Buchung bis {$this->max_days_before_arrival} Tage vor Anreise" : null,
|
||||
$this->min_days_before_arrival !== null ? "Buchung mindestens {$this->min_days_before_arrival} Tage vor Anreise" : null,
|
||||
empty($this->season_names) ? null : 'Anreise in: '.implode(', ', $this->season_names),
|
||||
$this->kind !== OfferKind::FixedDates && ($this->stay_from || $this->stay_until)
|
||||
? 'Reisezeitraum '.($this->stay_from?->format('d.m.Y') ?? 'ab sofort').' – '.($this->stay_until?->format('d.m.Y') ?? 'offen')
|
||||
: null,
|
||||
$this->bookable_until !== null ? 'buchbar bis '.$this->bookable_until->format('d.m.Y') : null,
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $rates
|
||||
* @return list<int>
|
||||
|
||||
Reference in new issue
Block a user