Original Author: PTFS Contractor <[email protected]>

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.

This work was sponsored by:
Middletown Township Public Library, Middletown, NJ USA

Signed-off-by: Colin Campbell <[email protected]>
---
 C4/Circulation.pm                                  |   55 +++++++++++++++++++-
 circ/circulation.pl                                |    4 ++
 .../prog/en/modules/circ/circulation.tmpl          |    4 +-
 opac/opac-renew.pl                                 |    2 +-
 opac/opac-user.pl                                  |    4 ++
 5 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index e2c9e94..65adf48 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -58,6 +58,7 @@ BEGIN {
        push @EXPORT, qw(
                &FixOverduesOnReturn
                &barcodedecode
+               GetRenewalDetails
        );
 
        # subs to deal with issuing a book
@@ -2070,8 +2071,31 @@ sub AddRenewal {
     my $branch          = shift;
     my $datedue         = shift;
     my $lastreneweddate = shift || C4::Dates->new()->output('iso');
+    my $source = shift;
+
     my $item   = GetItem($itemnumber) or return undef;
     my $biblio = GetBiblioFromItemNumber($itemnumber) or return undef;
+    $branch ||= $item=>{homebranch}; # opac-renew doesn't send branch
+
+    # If the due date wasn't specified, calculate it by adding the
+    # 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'} ,
+                       $item->{homebranch}                     # item's 
homebranch determines loanlength OR do we want the branch specified by the 
AddRenewal argument?
+        );
+               #FIXME -- use circControl?
+               $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 );
+    }
 
     my $dbh = C4::Context->dbh;
     # Find the issues record for this book
@@ -2138,7 +2162,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;
 }
 
@@ -2311,6 +2335,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 986b10c..4d1fc15 100755
--- a/circ/circulation.pl
+++ b/circ/circulation.pl
@@ -451,6 +451,10 @@ if ($borrower) {
         # ADDED BY JF: NEW ITEMTYPE COUNT DISPLAY
         $issued_itemtypes_count->{ $it->{'itemtype'} }++;
 
+        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 050c72c..bfa72f3 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl
@@ -469,7 +469,7 @@ No patron matched <span class="ex"><!-- TMPL_VAR 
name="message" --></span>
         </td>
         <td><!-- TMPL_VAR NAME="itemcallnumber" --></td>
         <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=<!-- 
TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnumber" 
-->#item<!-- TMPL_VAR NAME="itemnumber" -->"><!-- TMPL_VAR NAME="barcode" 
--></a></td>
-        <td><!-- TMPL_VAR NAME="renewals" --></td>
+        <td><!-- TMPL_VAR NAME="renewals" --> <!-- TMPL_IF 
NAME="renewals_opac" -->( <!-- TMPL_VAR NAME="renewals_opac" --> via OPAC ) 
<!-- /TMPL_IF --></td>
         <td>
         <!-- TMPL_IF NAME="can_renew" -->
         <input type="checkbox" name="all_items[]" value="<!-- TMPL_VAR 
NAME="itemnumber" -->" checked="checked" style="display: none;" />
@@ -530,7 +530,7 @@ No patron matched <span class="ex"><!-- TMPL_VAR 
name="message" --></span>
         </td>
         <td><!-- TMPL_VAR NAME="itemcallnumber" --></td>
         <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=<!-- 
TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnumber" 
-->#item<!-- TMPL_VAR NAME="itemnumber" -->"><!-- TMPL_VAR NAME="barcode" 
--></a></td>
-        <td><!-- TMPL_VAR NAME="renewals" --></td>
+        <td><!-- TMPL_VAR NAME="renewals" --> <!-- TMPL_IF 
NAME="renewals_opac" -->( <!-- TMPL_VAR NAME="renewals_opac" --> via OPAC ) 
<!-- /TMPL_IF --></td>
         <td>
         <!-- TMPL_IF NAME="can_renew" -->
         <input type="checkbox" name="all_items[]" value="<!-- TMPL_VAR 
NAME="itemnumber" -->" checked="checked" style="display: none;" />
diff --git a/opac/opac-renew.pl b/opac/opac-renew.pl
index 88bbacb..964087d 100755
--- a/opac/opac-renew.pl
+++ b/opac/opac-renew.pl
@@ -27,7 +27,7 @@ my $opacrenew = C4::Context->preference("OpacRenewalAllowed");
 for my $itemnumber ( @items ) {
     my ($status,$error) = CanBookBeRenewed( $borrowernumber, $itemnumber );
     if ( $status == 1 && $opacrenew == 1 ) {
-        AddRenewal( $borrowernumber, $itemnumber );
+        AddRenewal( $borrowernumber, $itemnumber, '', '', '', my $source = 
'opac' );
     }
 }
 # FIXME: else return ERROR to user!!
diff --git a/opac/opac-user.pl b/opac/opac-user.pl
index 708ba7f..a30f472 100755
--- a/opac/opac-user.pl
+++ b/opac/opac-user.pl
@@ -131,6 +131,10 @@ foreach my $issue ( @issue_list ) {
     $issue->{'too_many'} = 1 if $renewerror and $renewerror eq 'too_many';
     $issue->{'on_reserve'} = 1 if $renewerror and $renewerror eq 'on_reserve';
 
+    if ( $issue->{'renewsleft'} < 0 ) {
+      $issue->{'renewsleft'} = '0';
+    }
+
     if ( $issue->{'overdue'} ) {
         push @overdues, $issue;
         $overdues_count++;
-- 
1.6.2.5

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches

Reply via email to