@@ -, +, @@ interface --- C4/Reserves.pm | 34 +++ Koha/Biblio.pm | 4 +- Koha/Item.pm | 6 +- .../prog/en/includes/holds_table.inc | 6 + .../prog/en/modules/recalls/request.tt | 263 ++++++++++++++++-- .../prog/en/modules/reserve/request.tt | 8 + .../prog/js/patron-autocomplete.js | 4 +- opac/opac-recall.pl | 10 +- recalls/request.pl | 98 ++++++- reserve/modrequest.pl | 14 +- reserve/request.pl | 5 + t/db_dependent/Holds.t | 81 +++++- 12 files changed, 502 insertions(+), 31 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -1115,6 +1115,40 @@ sub ModReserve { if ( $rank eq "del" ) { $hold->cancel({ cancellation_reason => $cancellation_reason }); } + elsif ( $rank eq "recall" ) { + if ( !$biblionumber ) { + $biblionumber = $hold->biblionumber; + } + my $biblio = Koha::Biblios->find( $biblionumber ); + if ( !$borrowernumber ) { + $borrowernumber = $hold->borrowernumber; + } + my $patron = Koha::Patrons->find( $borrowernumber ); + if ( $hold->item_level_hold ) { + if ( $hold->item->can_be_recalled({ patron => $patron, hold_convert => 1 }) ) { + my ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({ + patron => $patron, + biblio => $biblio, + branchcode => $branchcode, + expirationdate => $date, + interface => 'intranet', + item => $hold->item, + }); + $hold->cancel({ cancellation_reason => 'RECALLED' }); + } + } else { + if ( $biblio->can_be_recalled({ patron => $patron, hold_convert => 1 }) ) { + my ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({ + patron => $patron, + biblio => $biblio, + branchcode => $branchcode, + expirationdate => $date, + interface => 'intranet', + }); + $hold->cancel({ cancellation_reason => 'RECALLED' }); + } + } + } elsif ($hold->found && $hold->priority eq '0' && $date) { logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold ) if C4::Context->preference('HoldsLog'); --- a/Koha/Biblio.pm +++ a/Koha/Biblio.pm @@ -1283,6 +1283,8 @@ sub recalls { Does biblio-level checks and returns the items attached to this biblio that are available for recall +if hold_convert $param is included, this is to say that this a check to convert a hold to a recall, so we should not check for an existing hold. + =cut sub can_be_recalled { @@ -1308,7 +1310,7 @@ sub can_be_recalled { my @all_itemnumbers; foreach my $item ( @all_items ) { push( @all_itemnumbers, $item->itemnumber ); - if ( $item->can_be_recalled({ patron => $patron }) ) { + if ( $item->can_be_recalled({ patron => $patron, hold_convert => $params->{hold_convert} }) ) { push( @itemtypes, $item->effective_itemtype ); push( @itemnumbers, $item->itemnumber ); push( @items, $item ); --- a/Koha/Item.pm +++ a/Koha/Item.pm @@ -1840,6 +1840,8 @@ sub recall { Does item-level checks and returns if items can be recalled by this borrower +if hold_convert $param is included, this is to say that this a check to convert a hold to a recall, so we should not check for an existing hold. + =cut sub can_be_recalled { @@ -1891,7 +1893,9 @@ sub can_be_recalled { return 0 if ( Koha::Checkouts->search({ itemnumber => $self->itemnumber, borrowernumber => $patron->borrowernumber })->count > 0 ); # check if this patron has already reserved this item - return 0 if ( Koha::Holds->search({ itemnumber => $self->itemnumber, borrowernumber => $patron->borrowernumber })->count > 0 ); + unless ( $params->{hold_convert} ) { + return 0 if ( Koha::Holds->search({ itemnumber => $self->itemnumber, borrowernumber => $patron->borrowernumber })->count > 0 ); + } } # check item availability --- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc @@ -64,6 +64,9 @@ [% END %] + [% IF Koha.Preference('UseRecalls') AND Koha.Preference('RecallsInterface') != 'opac' %] + + [% END %] [% ELSE %] @@ -79,6 +82,9 @@ [% ELSE %] [% END %] + [% IF Koha.Preference('UseRecalls') AND Koha.Preference('RecallsInterface') != 'opac' %] + + [% END %] [% END %] [% ELSE %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/recalls/request.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/recalls/request.tt @@ -2,8 +2,17 @@ [% USE Asset %] [% USE Koha %] [% USE KohaDates %] +[% USE TablesSettings %] +[% USE Branches %] +[% USE Categories %] +[% USE AuthorisedValues %] +[% USE ItemTypes %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] +[% SET libraries = Branches.all %] +[% SET categories = Categories.all.unblessed %] +[% SET columns = ['name', 'cardnumber', 'dateofbirth', 'category', 'branch', 'address', 'phone'] %] +[% PROCESS "patron-search.inc" %] Confirm recalls › Recalls › Koha [% INCLUDE 'doc-head-close.inc' %] @@ -12,36 +21,217 @@ [% INCLUDE 'circ-search.inc' %] [% END %] - +
-

Existing recalls

+

Recalls

- [% IF Koha.Preference('UseRecalls') %] - [% IF recalls.count %] -
- +

Place a recall on [% INCLUDE 'biblio-title.inc' link = 1 %]

+ + [% IF patron %] + + [% IF error %] +
+ Unable to place a recall. Check your circulation rules. +
+ [% END %] + +
+ Recall details + - Select all - [% INCLUDE 'recalls.inc' %] + +
    +
  1. + [% INCLUDE 'patron-title.inc' %] + +
  2. + + [% UNLESS ( single_branch_mode ) %]
  3. + + +
  4. [% END %] + +
  5. + +
  6. +
  7. + +
  8. +
+ +
+ + + [% IF error %] + + [% ELSE %] + + [% END %] + Cancel +
+ + + + + + + + + [% UNLESS ( single_branch_mode ) %] + + + [% END %] + + + + + + + + + [% FOREACH item IN items %] + + + + [% UNLESS ( single_branch_mode ) %] + + + [% END %] + + + + + + [% END %] + +
Place a recall on a specific item
 Item typeBarcodeHome libraryLast locationCollectionCall numberCopy numberVol no.Information
+ [% IF item.can_be_recalled( patron => patron ) %] + + [% ELSE %] + + + + [% END %] + [% ItemTypes.GetDescription( item.effective_itemtype ) | html %][% item.barcode | html %][% Branches.GetName( item.homebranch ) | html %][% Branches.GetName( item.holdingbranch) | html %][% AuthorisedValues.GetByCode( 'CCODE', item.ccode, 1 ) | html %][% item.itemcallnumber | html %][% item.copynumber | html %][% item.enumchron | html %] + [% IF ( item.checkout ) %] + Due [% item.checkout.date_due | $KohaDates %] + [% ELSIF ( item.get_transfer ) %] + In transit from [% Branches.GetName( item.get_transfer.frombranch ) | html %] to [% Branches.GetName( item.get_transfer.tobranch ) | html %] since [% item.get_transfer.datesent | $KohaDates %] + [% END %] + [% IF ( item.itemlost || item.withdrawn ) %] + Unavailable (lost or missing) + [% END %] + [% IF ( item.notforloan ) %] + Not for loan ([% item.notforloan | html %]) + [% END %] + [% hold = item.current_holds.next %] + [% IF ( item.recall ) %] + + [% IF ( item.recall.waiting_date ) %] + Waiting for patron at [% Branches.GetName( item.recall.pickup_library_id ) | html %] since [% item.recall.waiting_date | $KohaDates %]. + [% ELSIF ( item.recall.item_id == item.itemnumber ) %] + Recalled by patron expected at [% Branches.GetName( item.recall.pickup_library_id ) | html %] since [% item.recall.created_date | $KohaDates %]. + [% END %] + + [% ELSIF ( hold.waitingdate ) %] + + Waiting for patron at [% Branches.GetName( hold.branchcode ) | html %] since [% hold.waitingdate | $KohaDates %]. + + [% ELSIF ( hold.borrowernumber == logged_in_user.borrowernumber ) %] + + Patron has already placed a reserve on this item. + + [% END # / IF ( item.recall or hold ) %] +
+
- + + + [% IF error %] + + [% ELSE %] + + [% END %] + Cancel
+ +
+ + [% ELSE %] + + [% IF Koha.Preference('RecallsInterface') == 'opac' %] +
+ Due to the RecallsInterface system preference, recalls cannot be placed through the staff client. +
[% ELSE %] -
No recalls have been made.
+ +
+

Search patrons

+
+ +
+
+ [% PROCESS patron_search_filters_simple %] + [% PROCESS patron_search_table table_id => 'table_borrowers', open_on_row_click => 1 %] +
+
+
+
+ [% END %] - [% ELSE %] -
Recalls have not been enabled. Enable the UseRecalls system preference to use recalls.
+ +

Existing recalls

+ + [% IF Koha.Preference('UseRecalls') %] + [% IF recalls.count %] +
+ + Select all + [% INCLUDE 'recalls.inc' %] +
+ +
+
+ [% ELSE %] +
No recalls have been made.
+ [% END %] + [% ELSE %] +
Recalls have not been enabled. Enable the UseRecalls system preference to use recalls.
+ [% END %] + [% END %]
@@ -60,6 +250,45 @@ [% Asset.js("js/recalls.js") | $raw %] [% INCLUDE 'datatables.inc' %] [% INCLUDE 'columns_settings.inc' %] + [% INCLUDE 'calendar.inc' %] + [% SET url_biblio_params = "biblionumber=" _ biblio.biblionumber %] + [% PROCESS patron_search_js table_id => 'table_borrowers', categories => categories, libraries => libraries, extended_attribute_types => attribute_type_codes, columns => columns, open_on_row_click => 1, on_click_url => '/cgi-bin/koha/recalls/request.pl?' _ url_biblio_params, redirect_if_one_result => 1, redirect_url => '/cgi-bin/koha/recalls/request.pl?' _ url_biblio_params, redirect_if_attribute_equal => 'cardnumber' %] + [% END %] [% INCLUDE 'intranet-bottom.inc' %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -219,6 +219,14 @@

No club with this name, please, try another

[% END %] + + [% IF ( recallerror ) %] +
+

Hold cannot be converted to a recall

+

A recall cannot be placed on one or more holds. Check your circulation and fine rules.

+
+ [% END %] +
[% UNLESS multi_hold %] [% IF clubcount %] --- a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js +++ a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js @@ -67,7 +67,9 @@ function patron_autocomplete(node, options) { ? "/cgi-bin/koha/circ/circulation.pl" : link_to == 'reserve' ? "/cgi-bin/koha/reserve/request.pl" - : "/cgi-bin/koha/members/moremember.pl"; + : link_to == 'recall' + ? "/cgi-bin/koha/recalls/request.pl" + : "/cgi-bin/koha/members/moremember.pl"; item.link += ( url_params ? '?' + url_params + '&' : "?" ) + 'borrowernumber=' + item.patron_id; } else { item.link = null; --- a/opac/opac-recall.pl +++ a/opac/opac-recall.pl @@ -36,6 +36,12 @@ my $op = $query->param('op') || ''; my $biblionumber = $query->param('biblionumber'); my $biblio = Koha::Biblios->find( $biblionumber ); +if ($op eq 'cancel'){ + my $recall_id = $query->param('recall_id'); + Koha::Recalls->find( $recall_id )->set_cancelled; + print $query->redirect('/cgi-bin/koha/opac-user.pl'); +} + if ( C4::Context->preference('UseRecalls') and C4::Context->preference('RecallsInterface') ne 'staff' ) { my $patron = Koha::Patrons->find( $borrowernumber ); @@ -112,10 +118,6 @@ if ( C4::Context->preference('UseRecalls') and C4::Context->preference('RecallsI $error = 'failed'; } } - } elsif ($op eq 'cancel'){ - my $recall_id = $query->param('recall_id'); - Koha::Recalls->find( $recall_id )->set_cancelled; - print $query->redirect('/cgi-bin/koha/opac-user.pl'); } my $branches = Koha::Libraries->search(); --- a/recalls/request.pl +++ a/recalls/request.pl @@ -38,27 +38,115 @@ my ($template, $loggedinuser, $cookie)= get_template_and_user( my $op = $input->param('op') || 'list'; my @recall_ids = $input->multi_param('recall_ids'); my $biblionumber = $input->param('biblionumber'); -my $recalls = Koha::Recalls->search({ biblio_id => $biblionumber, completed => 0 }); my $biblio = Koha::Biblios->find( $biblionumber ); +my $borrowernumber = $input->param('borrowernumber'); +my $error = $input->param('error'); if ( $op eq 'cancel_multiple_recalls' ) { foreach my $id ( @recall_ids ) { Koha::Recalls->find( $id )->set_cancelled; } - $op = 'list' } +elsif ( $op eq 'request' ) { + + if ( C4::Context->preference('UseRecalls') and C4::Context->preference('RecallsInterface') ne 'opac' and $borrowernumber ) { + my $patron = Koha::Patrons->find( $borrowernumber ); + + unless ( $biblio->can_be_recalled({ patron => $patron }) ) { $error = 'unavailable'; } + my $items = Koha::Items->search({ biblionumber => $biblionumber })->as_list; + + # check if already recalled + my $recalled = $biblio->recalls->filter_by_current->search({ patron_id => $borrowernumber })->count; + if ( defined $recalled and $recalled > 0 ) { + my $recalls_per_record = Koha::CirculationRules->get_effective_rule({ + categorycode => $patron->categorycode, + branchcode => undef, + itemtype => undef, + rule_name => 'recalls_per_record' + }); + if ( defined $recalls_per_record and $recalls_per_record->rule_value and $recalled >= $recalls_per_record->rule_value ){ + $error = 'duplicate'; + } + } + + if ( !defined $error ){ + my $pickuploc = $input->param('pickup'); + my $expdate = $input->param('expirationdate'); + my $level = $input->param('type'); + my $itemnumber = $input->param('itemnumber'); + + my ( $recall, $due_interval, $due_date ); + + if ( !defined $level and defined $itemnumber ) { + my $item = Koha::Items->find( $itemnumber ); + if ( $item->can_be_recalled({ patron => $patron }) ) { + ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({ + patron => $patron, + biblio => $biblio, + branchcode => $pickuploc, + item => $item, + expirationdate => $expdate, + interface => 'staff', + }); + } else { + $error = 'cannot'; + } + } else { + if ( $biblio->can_be_recalled({ patron => $patron }) ) { + ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({ + patron => $patron, + biblio => $biblio, + branchcode => $pickuploc, + expirationdate => $expdate, + interface => 'staff', + }); + } else { + $error = 'cannot'; + } + } + if ( !defined $recall ) { + $error = 'failed'; + } else { + # successful recall, go back to Recalls tab + print $input->redirect("/cgi-bin/koha/recalls/request.pl?biblionumber=$biblionumber"); + } + } + } +} + +if ( $borrowernumber ) { + my $patron = Koha::Patrons->find( $borrowernumber ); + + if ( C4::Context->preference('UseRecalls') and C4::Context->preference('RecallsInterface') ne 'opac' and $patron and $patron->borrowernumber ) { + if ( !$biblio->can_be_recalled({ patron => $patron }) ) { + $error = 1; + } -if ( $op eq 'list' ) { - $recalls = Koha::Recalls->search({ biblio_id => $biblionumber, completed => 0 }); - $biblio = Koha::Biblios->find( $biblionumber ); + $template->param( + patron => $patron, + ); + } } +my $recalls = Koha::Recalls->search({ biblio_id => $biblionumber, completed => 0 }); +my $branches = Koha::Libraries->search; +my $single_branch_mode = $branches->count == 1; +my $items = Koha::Items->search({ biblionumber => $biblionumber }); + $template->param( recalls => $recalls, recallsview => 1, biblio => $biblio, checkboxes => 1, + branches => $branches, + items => $items, + error => $error, + single_branch_mode => $single_branch_mode, C4::Search::enabled_staff_search_views, + attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes') + ? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ] + : [] + ), ); output_html_with_http_headers $input, $cookie, $template->output; --- a/reserve/modrequest.pl +++ a/reserve/modrequest.pl @@ -52,6 +52,7 @@ my @branch = $query->multi_param('pickup'); my @itemnumber = $query->multi_param('itemnumber'); my @biblionumber = $query->multi_param('biblionumber'); my $count=@rank; +my $recallerror; @biblionumber = uniq @biblionumber; @@ -86,6 +87,13 @@ else { $params->{reservedate} = $reservedates[$i] || undef; } + if ( $rank[$i] eq 'recall' and !$recallerror ) { + my $hold = Koha::Holds->find( $reserve_id[$i] ); + if ( !$hold->biblio->can_be_recalled({ patron => $hold->patron }) ) { + $recallerror = 1; + } + } + try { ModReserve($params); } catch { @@ -112,6 +120,10 @@ if ( $from eq 'borrower'){ print $query->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrower[0]"); } else { my $url = URI->new("/cgi-bin/koha/reserve/request.pl"); - $url->query_form( biblionumber => [@biblionumber]); + if ( $recallerror ) { + $url->query_form( biblionumber => [@biblionumber], recallerror => 1 ); + } else { + $url->query_form( biblionumber => [@biblionumber] ); + } print $query->redirect($url); } --- a/reserve/request.pl +++ a/reserve/request.pl @@ -715,6 +715,11 @@ $template->param( pickup => $pickup || C4::Context->userenv->{branch} ); $template->param(borrowernumber => $borrowernumber_hold); +my $recallerror = $input->param('recallerror'); +if ( $recallerror ) { + $template->param( recallerror => 1 ); +} + # printout the page output_html_with_http_headers $input, $cookie, $template->output; --- a/t/db_dependent/Holds.t +++ a/t/db_dependent/Holds.t @@ -7,7 +7,7 @@ use t::lib::TestBuilder; use C4::Context; -use Test::More tests => 75; +use Test::More tests => 76; use Test::Exception; use MARC::Record; @@ -1801,3 +1801,82 @@ subtest 'Koha::Holds->get_items_that_can_fill returns items with datecancelled o $schema->storage->txn_rollback; }; + +subtest 'ModReserve to convert a hold to a recall' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + my $category = $builder->build({ source => 'Category' }); + my $branch = $builder->build({ source => 'Branch' })->{ branchcode }; + my $biblio = $builder->build_sample_biblio( { itemtype => 'DUMMY' } ); + my $item = $builder->build_sample_item( + { library => $branch, biblionumber => $biblio->biblionumber } ); + + my $patron = Koha::Patron->new( + { + firstname => 'my firstname', + surname => 'whatever surname', + categorycode => $category->{categorycode}, + branchcode => $branch, + } + )->store; + my $borrowernumber = $patron->borrowernumber; + + my $patron2 = Koha::Patron->new( + { + firstname => 'my firstname', + surname => 'whatever surname', + categorycode => $category->{categorycode}, + branchcode => $branch, + } + )->store; + + t::lib::Mocks::mock_preference("UseRecalls", 1); + t::lib::Mocks::mock_userenv( { branchcode => $branch } ); + + C4::Circulation::AddIssue( $patron2->unblessed, $item->barcode ); + + Koha::CirculationRules->set_rules({ + branchcode => undef, + categorycode => undef, + itemtype => undef, + rules => { + recalls_allowed => 5, + recalls_per_record => 1, + on_shelf_recalls => 'any', + }, + }); + + my $reserve_id = AddReserve( + { + branchcode => $branch, + borrowernumber => $borrowernumber, + biblionumber => $biblio->biblionumber, + priority => + C4::Reserves::CalculatePriority( $biblio->biblionumber ), + itemnumber => $item->id, + } + ); + + my $hold = Koha::Holds->find($reserve_id); + my $before_recalls = Koha::Recalls->search->filter_by_current->count; + + ModReserve( + { + reserve_id => $hold->id, + expirationdate => '1981-06-10', + priority => 99, + rank => "recall", + itemnumber => $item->id, + } + ); + + $hold = Koha::Holds->find($reserve_id); + my $after_recalls = Koha::Recalls->search->filter_by_current->count; + + ok( !defined $hold, 'Hold was cancelled' ); + is( $after_recalls, $before_recalls + 1, 'Recall count increased by 1 as hold was converted to a recall' ); + + $schema->storage->txn_rollback; +}; --