From 0ca53ec8ba98a86ef7e9db61e953870607299cda Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 7 Dec 2021 14:38:06 +0000 Subject: [PATCH] Bug 33737: Add bookings tab to patron details --- Koha/Bookings.pm | 23 +++++ Koha/Patron.pm | 14 +++ .../prog/en/includes/patron-detail-tabs.inc | 11 +++ .../prog/en/modules/members/moremember.tt | 85 ++++++++++++++++++- members/moremember.pl | 5 ++ 5 files changed, 137 insertions(+), 1 deletion(-) diff --git a/Koha/Bookings.pm b/Koha/Bookings.pm index 44bc032b02d..00137489686 100644 --- a/Koha/Bookings.pm +++ b/Koha/Bookings.pm @@ -20,6 +20,8 @@ package Koha::Bookings; use Modern::Perl; use Koha::Database; +use Koha::DateUtils qw(dt_from_string); + use Koha::Booking; use base qw(Koha::Objects); @@ -32,8 +34,29 @@ Koha::Bookings - Koha Booking object set class =head2 Class Methods +=head3 filter_by_active + + Koha::Bookings->filter_by_active; + +Returns set of Koha bookings objects that are currently active. + +Active is defined as having a end date in the future. + =cut +sub filter_by_active { + my ($self) = @_; + + my $dtf = Koha::Database->new->schema->storage->datetime_parser; + my $now = $dtf->format_datetime(dt_from_string()); + + return $self->search( + { + end_date => { '>=' => $now } + } + ); +} + =head3 type =cut diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 1a4a9205806..5c19e71dfc3 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1591,6 +1591,20 @@ sub curbside_pickups { return Koha::CurbsidePickups->_new_from_dbic($curbside_pickups_rs); } +=head3 bookings + + my $bookings = $item->bookings(); + +Returns the bookings for this patron. + +=cut + +sub bookings { + my ( $self, $params ) = @_; + my $bookings_rs = $self->_result->bookings->search($params); + return Koha::Bookings->_new_from_dbic( $bookings_rs ); +} + =head3 return_claims my $return_claims = $patron->return_claims diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc index 8b4659064b1..430d7ef9ac2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc @@ -29,6 +29,9 @@ [% WRAPPER tab_item tabname= "holds" %] Holds ([% holds_count || 0 | html %]) [% END %] + [% WRAPPER tab_item tabname="bookings" %] + Bookings ([% bookings_count || 0 | html %]) + [% END %] [% END %] [% IF Koha.Preference('UseRecalls') %] @@ -215,6 +218,14 @@

Patron has nothing on hold.

[% END %] [% END # /tab_panel#holds %] + + [% WRAPPER tab_panel tabname="bookings" %] + [% IF ( bookings_count ) %] +
+ [% ELSE %] +

Patron has nothing booked.

+ [% END %] + [% END %] [% END %] [% IF Koha.Preference('UseRecalls') %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 3a1278e3cfe..237e35b2e24 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -667,7 +667,6 @@ [% INCLUDE 'patron-detail-tabs.inc' patronpage = "borrower" %] - @@ -682,6 +681,8 @@ [% INCLUDE 'modals/resolve_return_claim.inc' %] [% END %] + [% INCLUDE modals/cancel_booking.inc %] + [% MACRO jsinclude BLOCK %] [% INCLUDE 'datatables.inc' %] [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %] @@ -717,6 +718,8 @@ [% END %] [% Asset.js("js/holds.js") | $raw %] [% INCLUDE 'calendar.inc' %] + [% Asset.js("js/bookings.js") | $raw %] + [% Asset.js("js/cancel_booking_modal.js") | $raw %] [% INCLUDE 'str/members-menu.inc' %] [% Asset.js("js/members-menu.js") | $raw %] [% Asset.js("js/recalls.js") | $raw %] @@ -745,7 +748,87 @@ $('#guarantees_finesandcharges-tab').click(); }); + // Bookings + var bookings_table; + // Load bookings table on tab selection + $("#bookings-tab").on( "click", function(){ + if ( !bookings_table ) { + var today = new Date(); + var bookings_table_url = "/api/v1/bookings"; + bookings_table = $('#bookings-table').kohaTable({ + "ajax": { + "url": bookings_table_url + }, + "embed": [ + "biblio", + "item", + "patron" + ], + "columns": [{ + "data": "booking_id", + "title": "Booking ID", + "visible": false, + "searchable": false, + "orderable": false + }, + { + "data": "biblio.title", + "title": "Title", + "searchable": true, + "orderable": true, + "render": function(data,type,row,meta) { + return row.biblio.title; + } + }, + { + "data": "item.external_id", + "title": "Item", + "searchable": true, + "orderable": true, + "defaultContent": "Any item", + "render": function(data,type,row,meta) { + if ( row.item ) { + return row.item.external_id; + } else { + return null; + } + } + }, + { + "data": "start_date", + "title": "Start date", + "searchable": true, + "orderable": true, + "render": function(data, type, row, meta) { + return $datetime(row.start_date); + } + }, + { + "data": "end_date", + "title": "End date", + "searchable": true, + "orderable": true, + "render": function(data, type, row, meta) { + return $datetime(row.end_date); + } + }, + { + "data": "", + "title": "Actions", + "searchable": false, + "orderable": false, + "render": function(data, type, row, meta) { + var result = ''; + return result; + } + }] + }, [], 1, { patron_id: "[% patron.borrowernumber | html %]", end_date: { ">=": today.toISOString() } }); + }; + }); + // Bookings + }); + function uncheck_sibling(me){ nodename=me.getAttribute("name"); if (nodename =="barcodes[]"){ diff --git a/members/moremember.pl b/members/moremember.pl index 7a419e9fb93..6f6c8bf29ad 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -217,6 +217,11 @@ if ( C4::Context->preference('UseRecalls') ) { $template->param( waiting_recalls => $waiting_recalls ); } +my $bookings = $patron->bookings->filter_by_active; +$template->param( + bookings_count => $bookings->count() +); + my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees"); $no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees ); if ( defined $no_issues_charge_guarantees ) { -- 2.43.0