@@ -, +, @@ Removing markup from incorrect merge port this feature from checkout page onto details page. Fixed derangement of procedural call 3-1 Renewals List - detail in checkout screen shows total number of items renewed and number renewed via OPAC, if any. 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. --- 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(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -60,6 +60,7 @@ BEGIN { push @EXPORT, qw( &FixOverduesOnReturn &barcodedecode + GetRenewalDetails ); # subs to deal with issuing a book @@ -2148,14 +2149,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 = @@ -2166,25 +2168,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 @@ -2221,7 +2231,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; } @@ -2397,6 +2407,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); --- a/circ/circulation.pl +++ a/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 { --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl @@ -659,7 +659,7 @@ No patron matched Renewal Failed - 0 + ( via OPAC ) 0 " checked="checked" style="display: none;" /> @@ -726,7 +726,7 @@ No patron matched Renewal Failed - 0 + ( via OPAC ) 0 " checked="checked" style="display: none;" /> --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl @@ -437,7 +437,7 @@ function validate1(date) { Renewal Failed - 0 + ( via OPAC ) 0