[Koha-patches] [PATCH] [bug #2770][3.2] change the date calc, to set the date_due to date_due+loanlength.

Nahuel Angelinetti nahuel.angelinetti at biblibre.com
Mon Nov 10 14:25:17 CET 2008


At the moment when you renew a document the date_due calculated is now+loanlength, but it's a bad thing, It should be
date_due+loanlength.
This patch do change Circulation.pm to use the date_due as renew base and add the loanlength to get the new date_due after
renewal.
---
 C4/Circulation.pm |   58 +++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 084e109..dda5e72 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -1962,6 +1962,17 @@ sub AddRenewal {
     my $datedue = shift;
     my $lastreneweddate = shift;
 
+    my $dbh = C4::Context->dbh;
+    # Find the issues record for this book
+    my $sth =
+      $dbh->prepare("SELECT * FROM issues
+                        WHERE borrowernumber=? 
+                        AND itemnumber=?"
+      );
+    $sth->execute( $borrowernumber, $itemnumber );
+    my $issuedata = $sth->fetchrow_hashref;
+    $sth->finish;
+
     # 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')) {
@@ -1972,9 +1983,9 @@ sub AddRenewal {
              (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.
+        #FIXME -- use circControl?
+        $datedue =  CalcDateDue(C4::Dates->new($issuedata->{date_due}, 'iso'),$loanlength,$branch); # this branch is the transactional branch.
+        # The question of whether to use item's homebranch calendar is open.
     }
 
     # $lastreneweddate defaults to today.
@@ -1982,16 +1993,37 @@ sub AddRenewal {
         $lastreneweddate = strftime( "%Y-%m-%d", localtime );
     }
 
-    my $dbh = C4::Context->dbh;
-    # Find the issues record for this book
-    my $sth =
-      $dbh->prepare("SELECT * FROM issues
-                        WHERE borrowernumber=? 
-                        AND itemnumber=?"
-      );
-    $sth->execute( $borrowernumber, $itemnumber );
-    my $issuedata = $sth->fetchrow_hashref;
-    $sth->finish;
+    # If the due date wasn't specified, calculate it by adding the
+    # book's loan length to due's date.
+    unless (@_ and $datedue = shift and $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($issuedata->{date_due}, 'iso'),$loanlength,$branch);	# this branch is the transactional branch.
+        # The question of whether to use item's homebranch calendar is open.
+    }
+
+    # If the due date wasn't specified, calculate it by adding the
+    # book's loan length to due's date.
+    unless (@_ and $datedue = shift and $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($issuedata->{date_due}, 'iso'),$loanlength,$branch);	# this branch is the transactional branch.
+        # The question of whether to use item's homebranch calendar is open.
+    }
 
     # Update the issues record to have the new due date, and a new count
     # of how many times it has been renewed.
-- 
1.5.6.3




More information about the Koha-patches mailing list