From ef6b767117ca79cc9dadd51c6efc07d6b84c54ec Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Tue, 8 Jan 2008 15:44:17 -0600 Subject: [PATCH] Changing CanBookBeRenewed to pass back the reason a renewal cannot proceed Signed-off-by: Joshua Ferraro --- C4/Circulation.pm | 13 +++++++++---- C4/SIP/ILS/Transaction/Checkout.pm | 5 +++-- C4/SIP/ILS/Transaction/Renew.pm | 3 ++- .../prog/en/modules/circ/circulation.tmpl | 10 ++++++++++ opac/opac-renew.pl | 2 +- opac/opac-user.pl | 2 +- reserve/renewscript.pl | 3 ++- 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 0e2694a4d0..5f0571ee01 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -770,7 +770,7 @@ sub CanBookBeIssued { # Already issued to current borrower. Ask whether the loan should # be renewed. - my ($CanBookBeRenewed) = CanBookBeRenewed( + my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed( $borrower->{'borrowernumber'}, $item->{'itemnumber'} ); @@ -1562,7 +1562,7 @@ sub GetBiblioIssues { =head2 CanBookBeRenewed -$ok = &CanBookBeRenewed($borrowernumber, $itemnumber); +($ok,$error) = &CanBookBeRenewed($borrowernumber, $itemnumber); Find out whether a borrowed item may be renewed. @@ -1576,7 +1576,7 @@ C<$itemnumber> is the number of the item to renew. C<$CanBookBeRenewed> returns a true value iff the item may be renewed. The item must currently be on loan to the specified borrower; renewals must be allowed for the item's type; and the borrower must not have -already renewed the loan. +already renewed the loan. $error will contain the reason the renewal can not proceed =cut @@ -1587,6 +1587,7 @@ sub CanBookBeRenewed { my $dbh = C4::Context->dbh; my $renews = 1; my $renewokay = 0; + my $error; # Look in the issues table for this item, lent to this borrower, # and not yet returned. @@ -1621,15 +1622,19 @@ sub CanBookBeRenewed { if ( $renews && $renews >= $data1->{'renewals'} ) { $renewokay = 1; } + else { + $error="too_many"; + } $sth2->finish; my ( $resfound, $resrec ) = C4::Reserves::CheckReserves($itemnumber); if ($resfound) { $renewokay = 0; + $error="on_reserve" } } $sth1->finish; - return ($renewokay); + return ($renewokay,$error); } =head2 AddRenewal diff --git a/C4/SIP/ILS/Transaction/Checkout.pm b/C4/SIP/ILS/Transaction/Checkout.pm index 07d55ea1f6..262434f63a 100644 --- a/C4/SIP/ILS/Transaction/Checkout.pm +++ b/C4/SIP/ILS/Transaction/Checkout.pm @@ -60,9 +60,10 @@ sub do_checkout { } foreach my $confirmation ( keys %$needsconfirmation ) { if ($confirmation eq 'RENEW_ISSUE'){ - if (!CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber})){ + my ($renewokay,$renewerror)= CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber}); + if (! $renewokay){ $noerror = 0; - warn "cant renew $borrower->{borrowernumber} $self->{item}->{itemnumber}"; + warn "cant renew $borrower->{borrowernumber} $self->{item}->{itemnumber} $renewerror"; } } else { diff --git a/C4/SIP/ILS/Transaction/Renew.pm b/C4/SIP/ILS/Transaction/Renew.pm index 679e06b038..da6542cd8e 100644 --- a/C4/SIP/ILS/Transaction/Renew.pm +++ b/C4/SIP/ILS/Transaction/Renew.pm @@ -36,7 +36,8 @@ sub new { sub do_renew { my $self = shift; my $borrower = my $borrower = GetMember( $self->{patron}->id, 'cardnumber'); - if (CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber})){ + my ($renewokay,$renewerror) = CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber}); + if ($renewokay){ my $datedue = AddIssue( $borrower, $self->{item}->id, undef, 0 ); $self->{'due'} = $datedue; $self->ok(1); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl index 0e8ce4f5b0..2bceff959c 100755 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl @@ -404,6 +404,8 @@ No patron matched " /> + + " checked="checked" style="display: none;" /> @@ -446,6 +448,14 @@ No patron matched " /> + + + On Hold + + + Too Many Renewals + + " checked="checked" style="display: none;" /> diff --git a/opac/opac-renew.pl b/opac/opac-renew.pl index 66afc60d2e..0832b5e5d0 100755 --- a/opac/opac-renew.pl +++ b/opac/opac-renew.pl @@ -23,7 +23,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $itemnumber = $query->param('item'); my $borrowernumber = $query->param("borrowernumber"); -my $status = CanBookBeRenewed( $borrowernumber, $itemnumber ); +my ($status,$error) = CanBookBeRenewed( $borrowernumber, $itemnumber ); if ( $status == 1 ) { AddRenewal( $borrowernumber, $itemnumber ); } diff --git a/opac/opac-user.pl b/opac/opac-user.pl index fdbaabff0d..96e0bdd9b6 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -116,7 +116,7 @@ foreach my $issue ( @$issues ) { $issue->{$publictype} = 1; # check if item is renewable - my $status = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} ); + my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} ); ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'}); $issue->{'status'} = $status; diff --git a/reserve/renewscript.pl b/reserve/renewscript.pl index b01c43eb13..28e81f270c 100755 --- a/reserve/renewscript.pl +++ b/reserve/renewscript.pl @@ -65,7 +65,8 @@ my $borrowernumber = $input->param("borrowernumber"); my $failedrenews; foreach my $itemno (@data) { # check status before renewing issue - if (CanBookBeRenewed($borrowernumber,$itemno)){ + my ($renewokay,$error) = CanBookBeRenewed($borrowernumber,$itemno); + if ($renewokay){ AddRenewal($borrowernumber,$itemno,$branch); } else { -- 2.39.5