Bug 40101: Make opac-reserve.pl use `$patron->can_place_holds()`
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kristi Krueger <kkrueger@cuyahogalibrary.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 33032f99a8)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
acb0293cd9
commit
f37a09c2e4
|
|
@ -39,6 +39,7 @@ use Koha::Items;
|
|||
use Koha::ItemTypes;
|
||||
use Koha::Checkouts;
|
||||
use Koha::Libraries;
|
||||
use Koha::Logger;
|
||||
use Koha::Patrons;
|
||||
use List::MoreUtils qw( uniq );
|
||||
|
||||
|
|
@ -112,65 +113,42 @@ if ( $#biblionumbers < 0 && $op ne 'cud-place_reserve' ) {
|
|||
# Here we check that the borrower can actually make reserves Stage 1.
|
||||
#
|
||||
#
|
||||
my $noreserves = 0;
|
||||
if ( $category->effective_BlockExpiredPatronOpacActions_contains('hold') ) {
|
||||
if ( $patron->is_expired ) {
|
||||
|
||||
# cannot reserve, their card has expired and the rules set mean this is not allowed
|
||||
$noreserves = 1;
|
||||
$template->param( message => 1, expired_patron => 1 );
|
||||
my $can_place_holds = $patron->can_place_holds( { no_short_circuit => 1 } );
|
||||
|
||||
if ( !$can_place_holds ) {
|
||||
|
||||
$template->param( message => 1 );
|
||||
|
||||
my $messages = $can_place_holds->messages();
|
||||
foreach my $msg ( @{$messages} ) {
|
||||
if ( $msg->message eq 'expired' ) {
|
||||
$template->param( expired_patron => 1 );
|
||||
} elsif ( $msg->message eq 'debt_limit' ) {
|
||||
$template->param( too_much_oweing => sprintf( "%.02f", $msg->{payload}->{total_outstanding} ) );
|
||||
} elsif ( $msg->message eq 'bad_address' ) {
|
||||
$template->param( GNA => 1 );
|
||||
} elsif ( $msg->message eq 'card_lost' ) {
|
||||
$template->param( lost => 1 );
|
||||
} elsif ( $msg->message eq 'restricted' ) {
|
||||
$template->param(
|
||||
debarred => 1,
|
||||
debarred_comment => $patron->debarredcomment,
|
||||
debarred_date => $patron->debarred,
|
||||
);
|
||||
} elsif ( $msg->message eq 'hold_limit' ) {
|
||||
$template->param( too_many_reserves => $msg->{payload}->{total_holds} );
|
||||
} else {
|
||||
Koha::Logger->get->warn( sprintf( "Unhandled 'can_place_holds' error code: %s", $msg->message ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $maxoutstanding = C4::Context->preference("maxoutstanding");
|
||||
my $amountoutstanding = $patron->account->balance;
|
||||
if ( $amountoutstanding && ( $amountoutstanding > $maxoutstanding ) ) {
|
||||
my $amount = sprintf "%.02f", $amountoutstanding;
|
||||
$template->param( message => 1 );
|
||||
$noreserves = 1;
|
||||
$template->param( too_much_oweing => $amount );
|
||||
}
|
||||
|
||||
if ( $patron->gonenoaddress && ( $patron->gonenoaddress == 1 ) ) {
|
||||
$noreserves = 1;
|
||||
$template->param(
|
||||
message => 1,
|
||||
GNA => 1
|
||||
);
|
||||
}
|
||||
|
||||
if ( $patron->lost && ( $patron->lost == 1 ) ) {
|
||||
$noreserves = 1;
|
||||
$template->param(
|
||||
message => 1,
|
||||
lost => 1
|
||||
);
|
||||
}
|
||||
|
||||
if ( $patron->is_debarred ) {
|
||||
$noreserves = 1;
|
||||
$template->param(
|
||||
message => 1,
|
||||
debarred => 1,
|
||||
debarred_comment => $patron->debarredcomment,
|
||||
debarred_date => $patron->debarred,
|
||||
);
|
||||
}
|
||||
|
||||
my $holds = $patron->holds;
|
||||
my $reserves_count = $holds->count;
|
||||
$template->param( RESERVES => $holds->unblessed );
|
||||
if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
|
||||
$template->param( message => 1 );
|
||||
$noreserves = 1;
|
||||
$template->param( too_many_reserves => $holds->count );
|
||||
}
|
||||
|
||||
if ($noreserves) {
|
||||
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
|
||||
exit;
|
||||
}
|
||||
|
||||
my $reserves_count = $patron->holds->count;
|
||||
|
||||
# pass the pickup branch along....
|
||||
my $branch = $query->param('branch') || $patron->branchcode || C4::Context->userenv->{branch} || '';
|
||||
$template->param( branch => $branch );
|
||||
|
|
|
|||
Loading…
Reference in New Issue