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 <oleonard@myacpl.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2016-07-04 12:21:19 +01:00 committed by Brendan Gallagher
parent 807ee1daa0
commit ee719cf10c
2 changed files with 15 additions and 60 deletions

View file

@ -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));

View file

@ -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);