From 52d9e90655cb54444e2e8e316ddd8f83c0adfe13 Mon Sep 17 00:00:00 2001 From: Joshua Ferraro Date: Sun, 25 Nov 2007 00:44:05 -0600 Subject: [PATCH] adding back count of remaining renewals to OPAC Signed-off-by: Joshua Ferraro --- C4/Circulation.pm | 30 +++++++++++++++++++ .../opac-tmpl/prog/en/modules/opac-user.tmpl | 4 +-- opac/opac-user.pl | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 018f649da5..d16a303b21 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -77,6 +77,7 @@ push @EXPORT, qw( &CanBookBeRenewed &AddIssue &AddRenewal + &GetRenewCount &GetItemIssue &GetItemIssues &GetBorrowerIssues @@ -1662,6 +1663,35 @@ sub AddRenewal { UpdateStats( C4::Context->userenv->{'branchcode'}, 'renew', $charge, '', $itemnumber ); } +sub GetRenewCount { + # check renewal status + my ($bornum,$itemno)=@_; + my $dbh = C4::Context->dbh; + my $renewcount = 0; + my $renewsallowed = 0; + my $renewsleft = 0; + # Look in the issues table for this item, lent to this borrower, + # and not yet returned. + + # FIXME - I think this function could be redone to use only one SQL call. + my $sth = $dbh->prepare("select * from issues + where (borrowernumber = ?) + and (itemnumber = ?) + and returndate is null"); + $sth->execute($bornum,$itemno); + my $data = $sth->fetchrow_hashref; + $renewcount = $data->{'renewals'} if $data->{'renewals'}; + my $sth2 = $dbh->prepare("select renewalsallowed from items,biblioitems,itemtypes + where (items.itemnumber = ?) + and (items.biblioitemnumber = biblioitems.biblioitemnumber) + and (biblioitems.itemtype = itemtypes.itemtype)"); + $sth2->execute($itemno); + my $data2 = $sth2->fetchrow_hashref(); + $renewsallowed = $data2->{'renewalsallowed'}; + $renewsleft = $renewsallowed - $renewcount; + warn "Renewcount:$renewcount RenewsAll:$renewsallowed RenewLeft:$renewsleft"; + return ($renewcount,$renewsallowed,$renewsleft); +} =head2 GetIssuingCharges ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber); diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl index 16a6f802ac..ea59c4d760 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tmpl @@ -161,7 +161,7 @@ - &borrowernumber=">Renew + &borrowernumber=">Renew ( of renewals remaining) Not renewable @@ -268,4 +268,4 @@ No renewals left - \ No newline at end of file + diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 0e0d037f13..ea9d5c45c8 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -113,6 +113,7 @@ foreach my $issue ( @$issues ) { # check if item is renewable my $status = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} ); + ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'}); $issue->{'status'} = $status; -- 2.39.5