PhoenixKitBookings.Engine.DayEngine (PhoenixKitBookings v0.1.1)

Copy Markdown View Source

Validation + per-date capacity for day/night services — the date-granular path phoenix_live_calendar's minute-based engine doesn't cover.

Semantics (hotel conventions, universal-products research):

  • A stay is [starts_on, ends_on) — exclusive end. ends_on is the checkout date; nights = Date.diff(ends_on, starts_on). For time_unit: "day" the same math reads as whole days.
  • Check-in/check-out clock times are service display attributes and take no part in availability math.
  • A date is open when: a date-override rule on it says available: true, or (no override) a weekly rule covers its weekday with available: true, or the service has no rules at all. Every OCCUPIED date [starts_on, ends_on) must be open (blackout = closed date; closed-to-arrival/-departure refinements are post-v1).
  • Capacity is pooled per date: active bookings covering a date must stay below seats (7 rooms of a type — Checkfront/Planyo-style; named unit assignment is post-v1).

Summary

Functions

Remaining seats per date over [from, until] (inclusive — a picker month): %{date => remaining}, 0 for closed or full dates.

True when the date is open per the service's rules (see moduledoc).

Validates a [starts_on, ends_on) stay request.

Functions

capacity_by_date(service, rules, from, until, bookings)

Remaining seats per date over [from, until] (inclusive — a picker month): %{date => remaining}, 0 for closed or full dates.

open_date?(rules, date)

True when the date is open per the service's rules (see moduledoc).

validate(service, rules, starts_on, ends_on, active_bookings, opts \\ [])

Validates a [starts_on, ends_on) stay request.

Returns :ok | {:error, reason, message} with the same reason-atom vocabulary as PhoenixLiveCalendar.Utils.Constraints where shapes match (:invalid_range, :in_past, :insufficient_notice, :too_far_ahead, :too_short, :too_long, :outside_availability, :at_capacity).