From ee719cf10cf2f1c81de485228a98fc33e0f0c81b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 4 Jul 2016 12:21:19 +0100 Subject: [PATCH] Bug 16850: Remove C4::Members::IsMemberBlocked This subroutine is only called once and can be replaced with a call to is_debarred and has_overdues. Note that prior to this patch, IsMemberBlocked copy/paste code from HasOverdues, which did not make sense. Test plan: Debar a patron and make sure he is not able to checkout (the librarian is asked to overwrite if OverduesBlockCirc is set to 'confirmation') Remove the debarment and add overdues to this patron, same as previously, the checkout should be blocked Signed-off-by: Owen Leonard Signed-off-by: Tomas Cohen Arazi Signed-off-by: Brendan Gallagher --- C4/Circulation.pm | 31 +++++++++++++++---------------- C4/Members.pm | 44 -------------------------------------------- 2 files changed, 15 insertions(+), 60 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 9940d44372..0cac5edfb7 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -800,26 +800,25 @@ sub CanBookBeIssued { $alerts{OTHER_CHARGES} = sprintf( "%.2f", $other_charges ); } - my ($blocktype, $count) = C4::Members::IsMemberBlocked($borrower->{'borrowernumber'}); - if ($blocktype == -1) { - ## patron has outstanding overdue loans - if ( C4::Context->preference("OverduesBlockCirc") eq 'block'){ - $issuingimpossible{USERBLOCKEDOVERDUE} = $count; - } - elsif ( C4::Context->preference("OverduesBlockCirc") eq 'confirmation'){ - $needsconfirmation{USERBLOCKEDOVERDUE} = $count; - } - } elsif($blocktype == 1) { - # patron has accrued fine days or has a restriction. $count is a date - if ($count eq '9999-12-31') { - $issuingimpossible{USERBLOCKEDNOENDDATE} = $count; + my $patron = Koha::Patrons->find( $borrower->{borrowernumber} ); + if ( my $debarred_date = $patron->is_debarred ) { + # patron has accrued fine days or has a restriction. $count is a date + if ($debarred_date eq '9999-12-31') { + $issuingimpossible{USERBLOCKEDNOENDDATE} = $debarred_date; } else { - $issuingimpossible{USERBLOCKEDWITHENDDATE} = $count; + $issuingimpossible{USERBLOCKEDWITHENDDATE} = $debarred_date; + } + } elsif ( my $num_overdues = $patron->has_overdues ) { + ## patron has outstanding overdue loans + if ( C4::Context->preference("OverduesBlockCirc") eq 'block'){ + $issuingimpossible{USERBLOCKEDOVERDUE} = $num_overdues; + } + elsif ( C4::Context->preference("OverduesBlockCirc") eq 'confirmation'){ + $needsconfirmation{USERBLOCKEDOVERDUE} = $num_overdues; } } -# # JB34 CHECKS IF BORROWERS DON'T HAVE ISSUE TOO MANY BOOKS # my $switch_onsite_checkout = @@ -847,7 +846,7 @@ sub CanBookBeIssued { # # CHECKPREVCHECKOUT: CHECK IF ITEM HAS EVER BEEN LENT TO PATRON # - my $patron = Koha::Patrons->find($borrower->{borrowernumber}); + $patron = Koha::Patrons->find($borrower->{borrowernumber}); my $wants_check = $patron->wants_check_for_previous_checkout; $needsconfirmation{PREVISSUE} = 1 if ($wants_check and $patron->do_check_for_previous_checkout($item)); diff --git a/C4/Members.pm b/C4/Members.pm index 4b2d7ff1f9..4f004535ca 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -75,7 +75,6 @@ BEGIN { &GetHideLostItemsPreference - &IsMemberBlocked &GetMemberAccountRecords &GetBorNotifyAcctRecord @@ -461,49 +460,6 @@ sub GetMember { return; } -=head2 IsMemberBlocked - - my ($block_status, $count) = IsMemberBlocked( $borrowernumber ); - -Returns whether a patron is restricted or has overdue items that may result -in a block of circulation privileges. - -C<$block_status> can have the following values: - -1 if the patron is currently restricted, in which case -C<$count> is the expiration date (9999-12-31 for indefinite) - --1 if the patron has overdue items, in which case C<$count> is the number of them - -0 if the patron has no overdue items or outstanding fine days, in which case C<$count> is 0 - -Existing active restrictions are checked before current overdue items. - -=cut - -sub IsMemberBlocked { - my $borrowernumber = shift; - my $dbh = C4::Context->dbh; - - my $blockeddate = Koha::Patrons->find( $borrowernumber )->is_debarred; - - return ( 1, $blockeddate ) if $blockeddate; - - # if he have late issues - my $sth = $dbh->prepare( - "SELECT COUNT(*) as latedocs - FROM issues - WHERE borrowernumber = ? - AND date_due < now()" - ); - $sth->execute($borrowernumber); - my $latedocs = $sth->fetchrow_hashref->{'latedocs'}; - - return ( -1, $latedocs ) if $latedocs > 0; - - return ( 0, 0 ); -} - =head2 GetMemberIssuesAndFines ($overdue_count, $issue_count, $total_fines) = &GetMemberIssuesAndFines($borrowernumber); -- 2.39.5