From b4faaf1b93a34625386c22af5f04eabf1cc50b10 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Thu, 5 Mar 2026 14:20:59 +0100 Subject: [PATCH] Bug 42000: Add bookings count info on result page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Display number of bookings if: - items are bookable and syspref booking enabled of course - at least on item is available for booking - exclude past bookings and completed bookings (checked out normally) Test plan: 1) Apply this patch and restart_all 2) Perform a search and see new bookings count info Display number of bookings if: - items are bookable - at least on item is available for booking - exclude past bookings and completed bookings (checkouts normally) Sponsored by: Association de Gestion des Ĺ’uvres Sociales d'Inria (AGOS) --- catalogue/search.pl | 16 ++++++++++++++++ .../prog/en/modules/catalogue/results.tt | 3 +++ 2 files changed, 19 insertions(+) diff --git a/catalogue/search.pl b/catalogue/search.pl index 957a9f9dcfc..ea3aa8fadf8 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -160,6 +160,7 @@ use Koha::SearchFilters; use URI::Escape; use JSON qw( decode_json encode_json ); +use Koha::DateUtils qw( dt_from_string ); my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold"); @@ -694,6 +695,21 @@ if ($hits) { $line->{has_local_cover_image} = $line->{biblio_object} ? $line->{biblio_object}->cover_images->count : 0; } + + if ( $line->{biblio_object} ) { + my $bookable_items_count = $line->{biblio_object}->bookable_items->count; + if ( $bookable_items_count > 0 ) { + my $today = dt_from_string()->ymd; + $line->{future_bookings_count} = $line->{biblio_object}->bookings->search({ + start_date => { '>=' => $today }, + status => { '-not_in' => ['cancelled', 'completed'] } + })->count; + $line->{has_bookable_items} = 1; + } else { + $line->{future_bookings_count} = 0; + $line->{has_bookable_items} = 0; + } + } } my ( $page_numbers, $hits_to_paginate, $pages, $current_page_number, $previous_page_offset, $next_page_offset, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index 6ac67649634..8c5247bdd22 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -708,6 +708,9 @@ [% ELSE %] Holds ([% SEARCH_RESULT.biblio_object.holds.count | html %]) [% END %] + [% IF Koha.Preference('EnableBooking') && CAN_user_circulate_manage_bookings && SEARCH_RESULT.has_bookable_items %] + | Bookings ([% SEARCH_RESULT.future_bookings_count | html %]) + [% END %] [% END # /IF SEARCH_RESULT.norequests %] [% IF Koha.Preference('UseRecalls') and CAN_user_recalls %] | -- 2.39.5