Koha::Biblio::Availability::Booking - Booking availability of a bibliographic record over a date range
use Koha::Biblio::Availability::Booking;
my $availability = Koha::Biblio::Availability::Booking->check(
{
biblio => $biblio,
from => $from,
to => $to,
}
);
Usually reached through the $biblio->booking_availability wrapper.
Calculates, for each calendar date in an inclusive range, the booking availability of a bibliographic record's bookable items: a sparse map of dates to item ids, where each cell records the blockers that prevent a new booking and the warnings that are advisory only.
my $availability = Koha::Biblio::Availability::Booking->check(
{
biblio => $biblio,
from => $from,
to => $to,
[ pickup_library_id => $pickup_library_id, ]
[ patron => $patron, ]
[ item_type_id => $item_type_id, ]
[ item_id => $item_id, ]
[ booking_id => $booking_id, ]
}
);
Computes the booking availability over the range and returns a hashref with the bookable item ids and a sparse per-(date, item) availability map. Each cell records three reason sets: blockers that prevent a new booking, confirms (always empty for bookings), and warnings that are advisory context only.
{
item_ids => [ 101, 102 ],
availability => {
'2026-08-10' => {
101 => { blockers => { booking => 1 }, confirms => {}, warnings => {} },
102 => { blockers => { lead => 1 }, confirms => {}, warnings => { holiday => 1 } },
},
},
}
blockers hold the reasons that block a new booking on that date for that item: booking, checkout, lead, trail. An item with no blockers on a date (or absent from the map) is bookable that day, so the available dates for an item are the complement of its blocked dates. warnings hold context that does NOT block a booking, for display only: holiday, lead_floor, lead_theoretical. A cell exists only when it carries at least one blocker or warning, but always carries all three category keys.
Booking dates and checkout due dates are both attributed to their local calendar day in the library timezone.
biblio, from and to are mandatory; a Koha::Exceptions::MissingParameter exception is thrown when one of them is missing. from and to bound the inclusive date range and are truncated to calendar days.
pickup_library_id, patron and item_type_id are the context for resolving the effective bookings_lead_period and bookings_trail_period circulation rules; the same context applies to every existing booking, matching the booking calendar. Holiday reasons are only emitted when a pickup library is passed.
item_id restricts the calculation to a single bookable item. When booking_id identifies the booking being edited, its assigned item remains eligible for the calculation even if it has since become unbookable. booking_id also excludes that booking from the calculation.
Marks the days blocked by existing bookings: booking over the booked span, lead before it and trail after it. Collects the trail window ends for _mark_lead_windows.
Marks the days blocked by current checkouts as checkout, from the issue date through the due date.
Marks the pickup library's closed days as holiday for every item. Does nothing unless a pickup library was passed.
Marks the lead_floor window (no new booking can start until the lead period from today has passed) and, for each existing booking, the lead_theoretical window of a hypothetical follow-up booking placed right after its trail period. Does nothing unless a lead period applies.
$self->_mark( { item_id => $item_id, reason => $reason, start => $start, end => $end } );
Records a reason for an item on every day of the passed span, clamped to the requested range. The reason is filed under its category (blockers or warnings, per REASON_CATEGORY) on that day's Koha::Result::Availability cell, creating it on first use.
$self->_soft_mark( { item_id => $item_id, reason => $reason, start => $start, end => $end } );
Like _mark, but skips the days on which the item is already blocked harder (booking or checkout).
Paul Derscheid <paul.derscheid@lmscloud.de>