From 9fff2e1f4e082e470667ad1b338eaab6164896b4 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 29 Sep 2021 15:17:38 +0100 Subject: [PATCH] Bug 29002: Add ability to book material from the staff client This patch introduces a new modal to the biblio details page to allow booking of materials. Test plan 1) Navigate to the details page of a biblio 2) Note the new 'Place booking' button in the toolbar 3) Click the new button and note the new modal dialogue 4) Enter part of a patron name or cardnumber and then select from the presented results 5) Optionally pick an item from the select list 6) Select a start date and end date from the calender 7) Submit 8) Attempt to book the same item to another user, note that the dates previously selected are now greyed out. 9) Experiment with different items and all items options to confirm the available slots in the datepicker update as expected. 10) Sign off 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/Biblio.pm | 21 +- Koha/Items.pm | 18 + Koha/REST/V1/Biblios.pm | 7 +- api/v1/swagger/paths/biblios.yaml | 5 + .../prog/en/includes/cat-toolbar.inc | 4 + .../prog/en/includes/modals/place_booking.inc | 50 +++ .../prog/en/modules/catalogue/detail.tt | 4 + .../prog/js/place_booking_modal.js | 324 ++++++++++++++++++ 8 files changed, 428 insertions(+), 5 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/js/place_booking_modal.js diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 814cba7f92..10959879b3 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -218,6 +218,7 @@ sub can_article_request { return q{}; } + =head3 check_booking my $bookable = @@ -236,7 +237,7 @@ sub check_booking { my $end_date = dt_from_string( $params->{end_date} ); my $booking_id = $params->{booking_id}; - my $bookable_items = $self->items; + my $bookable_items = $self->bookable_items; my $total_bookable = $bookable_items->count; my $dtf = Koha::Database->new->schema->storage->datetime_parser; @@ -303,8 +304,8 @@ sub place_booking { { start_date => $params->{start_date}, end_date => $params->{end_date}, - borrowernumber => $patron->borrowernumber, - biblionumber => $self->biblionumber + patron_id => $patron->borrowernumber, + biblio_id => $self->biblionumber } )->store(); return $booking; @@ -595,6 +596,20 @@ sub items { return Koha::Items->search({ "me.itemnumber" => { -in => \@itemnumbers } }); } +=head3 bookable_items + + my $bookable_items = $biblio->bookable_items; + +Returns the related Koha::Items resultset filtered to those items that can be booked. + +=cut + +sub bookable_items { + my ($self) = @_; + return $self->items->filter_by_bookable; +} + + =head3 host_items my $host_items = $biblio->host_items(); diff --git a/Koha/Items.pm b/Koha/Items.pm index 3f3ba3fb4f..873da63a3e 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -158,6 +158,24 @@ sub filter_out_lost { return $self->search( $params ); } +=head3 filter_by_bookable + + my $filterd_items = $items->filter_by_bookable; + +Returns a new resultset, containing only those items that are allowed to be booked. + +=cut + +sub filter_by_bookable { + my ($self) = @_; + + return $self->search( + { + notforloan => [ 0, undef ], + withdrawn => [ 0, undef ] + } + ); +} =head3 move_to_biblio diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 057eb74f53..8fb58a0a73 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -255,7 +255,7 @@ Controller function that handles retrieving biblio's bookings sub get_bookings { my $c = shift->openapi->valid_input or return; - my $biblio = Koha::Biblios->find( { biblionumber => $c->validation->param('biblio_id') }, { prefetch => ['bookings'] } ); + my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['bookings'] } ); unless ( $biblio ) { return $c->render( @@ -290,6 +290,7 @@ sub get_items { my $c = shift->openapi->valid_input or return; my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['items'] } ); + my $bookable_only = $c->param('bookable'); unless ( $biblio ) { return $c->render( @@ -302,7 +303,9 @@ sub get_items { return try { - my $items = $c->objects->search( $biblio->items ); + my $items_rs = $biblio->items; + $items_rs = $items_rs->filter_by_bookable if $bookable_only; + my $items = $c->objects->search( $items_rs ); return $c->render( status => 200, openapi => $items diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml index c1f9872274..c0eb8be6f8 100644 --- a/api/v1/swagger/paths/biblios.yaml +++ b/api/v1/swagger/paths/biblios.yaml @@ -431,6 +431,11 @@ - $ref: "../swagger.yaml#/parameters/q_param" - $ref: "../swagger.yaml#/parameters/q_body" - $ref: "../swagger.yaml#/parameters/request_id_header" + - name: bookable + in: query + description: Limit to items that are bookable + required: false + type: boolean consumes: - application/json produces: diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc index 03bcb38059..93d26e7426 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -194,6 +194,8 @@ [% END %] [% END %] +
+ [% IF Koha.Preference('ArticleRequests') %] [% END %] @@ -244,3 +246,5 @@ + + [% INCLUDE modals/place_booking.inc %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc new file mode 100644 index 0000000000..e5df814c5f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc @@ -0,0 +1,50 @@ + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 5671a3d7db..05da5acf56 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -1353,6 +1353,9 @@ [% MACRO jsinclude BLOCK %] [% INCLUDE 'catalog-strings.inc' %] + [% INCLUDE 'calendar.inc' %] + [% INCLUDE 'select2.inc' %] + [% INCLUDE 'js-date-format.inc' %] [% Asset.js("js/catalog.js") | $raw %] [% Asset.js("js/recalls.js") | $raw %] [% Asset.js("js/coce.js") | $raw %] @@ -1822,6 +1825,7 @@ [% INCLUDE 'js-biblio-format.inc' %] [% Asset.js("js/browser.js") | $raw %] [% Asset.js("js/table_filters.js") | $raw %] + [% Asset.js("js/place_booking_modal.js") | $raw %]