bug 2582 [1/2]: don't set issuedate during renewal
authorGalen Charlton <galen.charlton@liblime.com>
Thu, 4 Sep 2008 17:23:46 +0000 (12:23 -0500)
committerChris Cormack <chris@bigballofwax.co.nz>
Thu, 3 Sep 2009 23:42:11 +0000 (11:42 +1200)
Changed so that issues.issuedate is never modified
during a renewal, since that column records the original
date of the loan.  Changed the name and interpretation
of the $issuedate parameter of AddRenewal() to
$lastreneweddate, allowing (e.g.) offline circulation
to set the date of the renewal without changing the
issue date.

As a result of the original bug, issues.issuedate can be
set to NULL for loans that were renewed via the OPAC,
self checkout, or the staff interface when explicitly
renewing a loan.  Loans that were renewed by checking
the item out to the same patron will have the issue date
changed to the date of the last renewal.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
C4/Circulation.pm

index c9830fe..d460957 100644 (file)
@@ -1957,6 +1957,22 @@ sub AddRenewal {
     my $branch  = (@_) ? shift : $item->{homebranch};  # opac-renew doesn't send branch
     my $datedue = shift;
     my $lastreneweddate = shift;
+
+    # 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 );