From 7931c58b843ae1d6c8e7cd82c65d6a885c9f3615 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 24 Feb 2011 14:05:32 +0100 Subject: [PATCH] Squashed commit of the following: Content-Type: text/plain; charset="utf-8" commit af0e18a3b28f736f8493162463621b9929547d35 Author: Owen Leonard Date: Fri Dec 31 14:49:44 2010 -0500 Removing markup from incorrect merge commit adb048eabc3929872d724841f152a1948d5b842a Author: dev3 Date: Wed May 5 23:50:29 2010 -0400 port this feature from checkout page onto details page. commit 9557c0c82faf86cb61a18483c4cf36170fc85a18 Author: J. David Bavousett Date: Wed May 5 23:34:28 2010 -0400 Fixed derangement of procedural call commit c0b0f5178e042566430f0fb053e0899e5b5cf535 Author: PTFS Date: Fri Mar 13 19:44:42 2009 -0400 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(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index b741794..0e618c5 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 @@ -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); 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 9663e02..16b9376 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl +++ b/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;" /> 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 030c78a..783ee19 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl @@ -437,7 +437,7 @@ function validate1(date) { Renewal Failed - 0 + ( via OPAC ) 0