From 62ab50d888ce375ff4893da9e7a28dbd68bccb2f Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 20 Feb 2012 08:01:46 -0500 Subject: [PATCH] Bug 7560 - SIP Self Checkout Ignoring Fines Thresholds for Not Being able to Check Out Books Add checks in C4::ILS::Patron and C4::ILS::Transaction::Renew to make sure the patron is below the noissuescharge system pref for issues and OPACFineNoRenewals for renewals. --- C4/Overdues.pm | 20 ++++++++++++++++++++ C4/SIP/ILS/Patron.pm | 4 ++-- C4/SIP/ILS/Transaction/Renew.pm | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 660e10b..a74791d 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -53,6 +53,7 @@ BEGIN { &GetOverdueDelays &GetOverduerules &GetFine + &GetTotalFines &CreateItemAccountLine &ReplacementCost2 @@ -655,6 +656,25 @@ sub GetFine { return 0; } +=head2 GetTotalFines + + my $total_fines_owed = GetTotalFines( $borrowernumber ); + + Returns the total amount owed by the given borrower. + +=cut + +sub GetTotalFines { + my ( $borrowernumber ) = @_; + my $dbh = C4::Context->dbh(); + my $query = "SELECT SUM( amountoutstanding ) AS total FROM accountlines WHERE borrowernumber = ?"; + my $sth = $dbh->prepare( $query ); + $sth->execute( $borrowernumber ); + my $row = $sth->fetchrow_hashref(); + my $total = $row->{'total'}; + $total = $total || 0; + return $total; +} =head2 GetIssuingRules diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 95981fb..47ffb8e 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -87,8 +87,8 @@ sub new { address => $adr, home_phone => $kp->{phone}, email_addr => $kp->{email}, - charge_ok => ( !$debarred && !$expired ), - renew_ok => ( !$debarred && !$expired ), + charge_ok => ( !$debarred && !$expired && ( $fines_amount < C4::Context->preference('noissuescharge') ) ), + renew_ok => ( !$debarred && !$expired && ( $fines_amount < C4::Context->preference('OPACFineNoRenewals') ) ), recall_ok => ( !$debarred && !$expired ), hold_ok => ( !$debarred && !$expired ), card_lost => ( $kp->{lost} || $kp->{gonenoaddress} || $flags->{LOST} ), diff --git a/C4/SIP/ILS/Transaction/Renew.pm b/C4/SIP/ILS/Transaction/Renew.pm index 73acaa3..0a9b932 100644 --- a/C4/SIP/ILS/Transaction/Renew.pm +++ b/C4/SIP/ILS/Transaction/Renew.pm @@ -35,7 +35,14 @@ sub new { sub do_renew_for ($$) { my $self = shift; my $borrower = shift; + my ($renewokay,$renewerror) = CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber}); + + unless ( C4::Overdues::GetTotalFines($borrower->{borrowernumber}) < C4::Context->preference('OPACFineNoRenewals') ) { + $renewokay = 0; + $renewerror = 'too_many_fines' + } + if ($renewokay){ my $datedue = AddIssue( $borrower, $self->{item}->id, undef, 0 ); $self->{due} = $datedue; -- 1.7.2.5