From 82c90e2e65ff64ba34b675dc95aa9aa7e716b04c Mon Sep 17 00:00:00 2001 From: PTFS Date: Fri, 13 Mar 2009 19:44:42 -0400 Subject: [PATCH] Fix for Bug 3483 - Show number of OPAC renewals Content-Type: text/plain; charset="utf-8" On the circ screen, if the patron has renewed an item via the opac, the number of opac renewals is listed beside the total number of renewals. Cherry-picked from PTFS's "Harley" --- C4/Circulation.pm | 77 +++++++++++++++----- circ/circulation.pl | 4 + .../prog/en/modules/circ/circulation.tmpl | 4 +- .../prog/en/modules/members/moremember.tmpl | 2 +- members/moremember.pl | 5 ++ opac/opac-renew.pl | 2 +- 6 files changed, 71 insertions(+), 23 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index f7846ac..90b092e 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -60,6 +60,7 @@ BEGIN { push @EXPORT, qw( &FixOverduesOnReturn &barcodedecode + GetRenewalDetails ); # subs to deal with issuing a book @@ -2161,14 +2162,15 @@ from the book's item type. =cut sub AddRenewal { - my $borrowernumber = shift or return undef; - my $itemnumber = shift or return undef; - my $branch = shift; - my $datedue = shift; - my $lastreneweddate = shift || C4::Dates->new()->output('iso'); + my $borrowernumber = shift or return undef; + my $itemnumber = shift or return undef; + my $item = GetItem($itemnumber) or return undef; my $biblio = GetBiblioFromItemNumber($itemnumber) or return undef; - + my $branch = (@_) ? shift : $item->{homebranch}; # opac-renew doesn't send branch + my $datedue = shift; + my $lastreneweddate = shift; + my $source = shift; my $dbh = C4::Context->dbh; # Find the issues record for this book my $sth = @@ -2179,25 +2181,33 @@ sub AddRenewal { $sth->execute( $borrowernumber, $itemnumber ); my $issuedata = $sth->fetchrow_hashref; $sth->finish; - if($datedue && ! $datedue->output('iso')){ - warn "Invalid date passed to AddRenewal."; - return undef; - } + # If the due date wasn't specified, calculate it by adding the - # book's loan length to today's date or the current due date - # based on the value of the RenewalPeriodBase syspref. - unless ($datedue) { + # book's loan length to today's date. + unless ($datedue && $datedue->output('iso')) { my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return undef; my $loanlength = GetLoanLength( - $borrower->{'categorycode'}, - (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} , - $issuedata->{'branchcode'} ); # that's the circ control branch. - + $borrower->{'categorycode'}, + (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} , + $item->{homebranch} # item's homebranch determines loanlength OR do we want the branch specified by the AddRenewal argument? + ); + #FIXME -- use circControl? $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? C4::Dates->new($issuedata->{date_due}, 'iso') : C4::Dates->new(); - $datedue = CalcDateDue($datedue,$loanlength,$issuedata->{'branchcode'},$borrower); + $datedue = CalcDateDue(C4::Dates->new(),$loanlength,$branch); # this branch is the transactional branch. + # The question of whether to use item's homebranch calendar is open. + } + + # $lastreneweddate defaults to today. + unless (defined $lastreneweddate) { + $lastreneweddate = strftime( "%Y-%m-%d", localtime ); + } + + if($datedue && ! $datedue->output('iso')){ + warn "Invalid date passed to AddRenewal."; + return undef; } # Update the issues record to have the new due date, and a new count @@ -2234,7 +2244,7 @@ sub AddRenewal { $sth->finish; } # Log the renewal - UpdateStats( $branch, 'renew', $charge, '', $itemnumber, $item->{itype}, $borrowernumber); + UpdateStats( $branch, 'renew', $charge, $source, $itemnumber, $item->{itype}, $borrowernumber); return $datedue; } @@ -2410,6 +2420,35 @@ sub GetTransfersFromTo { return (@gettransfers); } +=head2 GetRenewalDetails + +( $intranet_renewals, $opac_renewals ) = GetRenewalDetails( $itemnumber, $renewals_limit ); + +Returns the number of renewals through intranet and opac for the given itemnumber, limited by $renewals_limit + +=cut + +sub GetRenewalDetails { + my ( $itemnumber, $renewals_limit ) = @_; + my $dbh = C4::Context->dbh; + my $query = "SELECT * FROM statistics WHERE type = 'renew' AND itemnumber = ? ORDER BY datetime DESC LIMIT ?"; + my $sth = $dbh->prepare($query); + $sth->execute( $itemnumber, $renewals_limit ); + + my $renewals_intranet = 0; + my $renewals_opac = 0; + + while ( my $data = $sth->fetchrow_hashref ) { + if ( $data->{'other'} eq 'opac' ) { + $renewals_opac++; + } else { + $renewals_intranet++; + } + } + + return ( $renewals_intranet, $renewals_opac ); +} + =head2 DeleteTransfer &DeleteTransfer($itemnumber); diff --git a/circ/circulation.pl b/circ/circulation.pl index ab681f1..8feaede 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -454,6 +454,10 @@ if ($borrower) { ($it->{'author'} eq '') and $it->{'author'} = ' '; $it->{'renew_failed'} = $renew_failed{$it->{'itemnumber'}}; + if ( $it->{'renewals'} ) { + ( $it->{'renewals_intranet'}, $it->{'renewals_opac'} ) = GetRenewalDetails( $it->{'itemnumber'}, $it->{'renewals'} ); + } + if ( $todaysdate eq $it->{'issuedate'} or $todaysdate eq $it->{'lastreneweddate'} ) { push @todaysissues, $it; } else { 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 df78c54..a4d62dc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl @@ -664,7 +664,7 @@ No patron matched Renewal Failed - 0 + ( via OPAC ) 0 " checked="checked" style="display: none;" /> @@ -731,7 +731,7 @@ No patron matched Renewal Failed - 0 + ( via OPAC ) 0 " checked="checked" style="display: none;" /> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl index 2cdc13a..723d054 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl @@ -442,7 +442,7 @@ function validate1(date) { Renewal Failed - 0 + ( via OPAC ) 0