From 79da38c1206d2770a21817beeea3e054222dfc09 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 26 Aug 2020 10:49:04 +0200 Subject: [PATCH] Bug 25758: Fix renewal at the OPAC --- opac/opac-renew.pl | 9 +++++---- opac/opac-user.pl | 30 ++++++++++++++++++------------ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/opac/opac-renew.pl b/opac/opac-renew.pl index 2246725dff..64194e798c 100755 --- a/opac/opac-renew.pl +++ b/opac/opac-renew.pl @@ -49,29 +49,30 @@ my $opacrenew = C4::Context->preference("OpacRenewalAllowed"); my $errorstring = q{}; my $renewed = q{}; +my @errors; my $patron = Koha::Patrons->find( $borrowernumber ); if ( $patron->category->effective_BlockExpiredPatronOpacActions && $patron->is_expired ) { - $errorstring = 'card_expired'; + push @errors, 'card_expired'; } else { - my @renewed; + my ( @renewed, @errors ); for my $itemnumber (@items) { my ( $status, $error ) = CanBookBeRenewed( $borrowernumber, $itemnumber ); - $error = $error->[0] if @$error; if ( $status == 1 && $opacrenew == 1 ) { AddRenewal( $borrowernumber, $itemnumber, undef, undef, undef ); push( @renewed, $itemnumber ); } else { - $errorstring .= $error . "|"; + push @errors, @$error; } } $renewed = join( ':', @renewed ); + $errorstring = join "|", @errors; } print $query->redirect("/cgi-bin/koha/opac-user.pl?renew_error=$errorstring&renewed=$renewed"); diff --git a/opac/opac-user.pl b/opac/opac-user.pl index d931ee9142..fff7fc5cc9 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -232,18 +232,18 @@ if ( $pending_checkouts->count ) { # Useless test $issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} }; + use Data::Printer colored => 1; warn p $renewerror; if (@$renewerror) { - $renewerror = $renewerror->[0]; - $issue->{'too_many'} = 1 if $renewerror eq 'too_many'; - $issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve'; - $issue->{'norenew_overdue'} = 1 if $renewerror eq 'overdue'; - $issue->{'auto_renew'} = 1 if $renewerror eq 'auto_renew'; - $issue->{'auto_too_soon'} = 1 if $renewerror eq 'auto_too_soon'; - $issue->{'auto_too_late'} = 1 if $renewerror eq 'auto_too_late'; - $issue->{'auto_too_much_oweing'} = 1 if $renewerror eq 'auto_too_much_oweing'; - $issue->{'item_denied_renewal'} = 1 if $renewerror eq 'item_denied_renewal'; - - if ( $renewerror eq 'too_soon' ) { + $issue->{'too_many'} = 1 if grep { $_ eq 'too_many' } @$renewerror; + $issue->{'on_reserve'} = 1 if grep { $_ eq 'on_reserve' } @$renewerror; + $issue->{'norenew_overdue'} = 1 if grep { $_ eq 'overdue' } @$renewerror; + $issue->{'auto_renew'} = 1 if grep { $_ eq 'auto_renew' } @$renewerror; + $issue->{'auto_too_soon'} = 1 if grep { $_ eq 'auto_too_soon' } @$renewerror; + $issue->{'auto_too_late'} = 1 if grep { $_ eq 'auto_too_late' } @$renewerror; + $issue->{'auto_too_much_oweing'} = 1 if grep { $_ eq 'auto_too_much_oweing' } @$renewerror; + $issue->{'item_denied_renewal'} = 1 if grep { $_ eq 'item_denied_renewal' } @$renewerror; + + if ( grep { $_ eq 'too_soon' } @$renewerror ) { $issue->{'too_soon'} = 1; $issue->{'soonestrenewdate'} = output_pref( C4::Circulation::GetSoonestRenewDate( @@ -254,6 +254,8 @@ if ( $pending_checkouts->count ) { # Useless test } } + $issue->{can_renew} = ! scalar @$renewerror; + if ( $c->is_overdue ) { push @overdues, $issue; $overdues_count++; @@ -301,7 +303,11 @@ if ( $pending_checkouts->count ) { # Useless test } } my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); -$canrenew = 0 if ($overduesblockrenewing ne 'allow' and $overdues_count == $count); +my $canrenew_count = grep { $_->{canrenew} } @issuedat; +$canrenew = 0 + if ( $overduesblockrenewing ne 'allow' + && $overdues_count == $count ) + || $canrenew_count == 0; $template->param( ISSUES => \@issuedat ); $template->param( issues_count => $count ); -- 2.20.1