From 3fdfa1b4c763f072975624eef68cab0eeca01e71 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) Select a start date and end date from the calender 6) Submit --- Koha/Biblio.pm | 21 +- Koha/Items.pm | 18 + Koha/REST/V1/Biblios.pm | 2 + 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 | 319 ++++++++++++++++++ 8 files changed, 420 insertions(+), 3 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 0a4bf7d2ee..34071f73c8 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -200,6 +200,7 @@ sub can_article_request { return q{}; } + =head3 check_booking my $bookable = @@ -218,7 +219,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; @@ -285,8 +286,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; @@ -570,6 +571,20 @@ sub items { return Koha::Items->_new_from_dbic( $items_rs ); } +=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 9db9a3ae7c..8e49ec7067 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -290,6 +290,7 @@ sub get_items { my $c = shift->openapi->valid_input or return; my $biblio = Koha::Biblios->find( { biblionumber => $c->validation->param('biblio_id') }, { prefetch => ['items'] } ); + my $bookable_only = delete $c->validation->output->{bookable}; unless ( $biblio ) { return $c->render( @@ -303,6 +304,7 @@ sub get_items { return try { 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, diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml index 9ce749c470..aba96c7f8d 100644 --- a/api/v1/swagger/paths/biblios.yaml +++ b/api/v1/swagger/paths/biblios.yaml @@ -424,6 +424,11 @@ - $ref: "../swagger.yaml#/parameters/q_body" - $ref: "../swagger.yaml#/parameters/q_header" - $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 b9a4c3184f..401b7d10db 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') %]
Request article
[% 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..752b703086 --- /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 60a2944610..b637e46b01 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -1345,6 +1345,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 %] @@ -1814,6 +1817,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 %]