From 6bfe8467cba089fb83d0c4ef93c173078bd72bb1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 19 May 2023 16:48:40 +0100 Subject: [PATCH] Bug 29002: (follow-up) Add bookings count to side menu This patch adds booking counts to the bookings option in the side menu for biblio display pages. Signed-off-by: Martin Renvoize Signed-off-by: Janet McGowan Signed-off-by: Caroline Cyr La Rose Signed-off-by: Laurence Rault Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/Template/Plugin/Biblio.pm | 17 +++++++++++++++++ .../prog/en/includes/biblio-view-menu.inc | 2 +- .../prog/js/cancel_booking_modal.js | 1 + .../prog/js/place_booking_modal.js | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Koha/Template/Plugin/Biblio.pm b/Koha/Template/Plugin/Biblio.pm index f2163e41b3..c638c6e251 100644 --- a/Koha/Template/Plugin/Biblio.pm +++ b/Koha/Template/Plugin/Biblio.pm @@ -24,10 +24,13 @@ use base qw( Template::Plugin ); use Koha::Holds; use Koha::Biblios; +use Koha::Database; use Koha::Patrons; use Koha::ArticleRequests; use Koha::Recalls; +use Koha::DateUtils qw(dt_from_string); + sub HoldsCount { my ( $self, $biblionumber ) = @_; @@ -72,4 +75,18 @@ sub CanBook { return $biblio->bookable_items->count ? 1 : 0; } +sub BookingsCount { + my ( $self, $biblionumber ) = @_; + + my $biblio = Koha::Biblios->find($biblionumber); + + my $now = dt_from_string; + my $dtf = Koha::Database->new->schema->storage->datetime_parser; + return $biblio->bookings->search( + { + start_date => { '>' => $dtf->format_datetime($now) } + } + )->count; +} + 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc index a03124820b..77aba3c844 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc @@ -56,7 +56,7 @@ [%- ELSE -%]
  • [%- END -%] - Bookings + Bookings ([% Biblio.BookingsCount( biblio_object_id ) | html %])
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/cancel_booking_modal.js b/koha-tmpl/intranet-tmpl/prog/js/cancel_booking_modal.js index 0d70a5d1d1..4090ed853c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cancel_booking_modal.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cancel_booking_modal.js @@ -23,6 +23,7 @@ $("#cancelBookingForm").on('submit', function(e) { if (timeline) { timeline.itemsData.remove(Number(booking_id)); } + $('.bookings_count').html(parseInt($('.bookings_count').html(), 10)-1); $('#cancelBookingModal').modal('hide'); }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js b/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js index a67d9e4573..13f6f382c8 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js +++ b/koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js @@ -326,6 +326,9 @@ $("#placeBookingForm").on('submit', function(e) { }); } + // Update bookings counts + $('.bookings_count').html(parseInt($('.bookings_count').html(), 10)+1); + // Close modal $('#placeBookingModal').modal('hide'); -- 2.39.5