[Koha-patches] [PATCH] bug 2582 [1/2]: don't set issuedate during renewal
Galen Charlton
galen.charlton at liblime.com
Thu Sep 4 19:23:46 CEST 2008
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.
---
C4/Circulation.pm | 19 +++++++++++++------
t/lib/KohaTest/Circulation/AddIssue.pm | 4 ++--
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 5d936c3..1abd58f 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -882,7 +882,7 @@ sub AddIssue {
$item->{'itemnumber'},
$branch,
$datedue,
- $issuedate,
+ $issuedate, # here interpreted as the renewal date
);
}
@@ -1934,7 +1934,7 @@ sub CanBookBeRenewed {
=head2 AddRenewal
-&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$issuedate]);
+&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate]);
Renews a loan.
@@ -1947,7 +1947,8 @@ C<$branch> is the library branch. Defaults to the homebranch of the ITEM.
C<$datedue> can be a C4::Dates object used to set the due date.
-C<$issuedate> can be a iso formatted date to use for the issuedate.
+C<$lastreneweddate> is an optional ISO-formatted date used to set issues.lastreneweddate. If
+this parameter is not supplied, lastreneweddate is set to the current date.
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically
from the book's item type.
@@ -1961,7 +1962,8 @@ sub AddRenewal {
my $biblio = GetBiblioFromItemNumber($itemnumber) or return undef;
my $branch = (@_) ? shift : $item->{homebranch}; # opac-renew doesn't send branch
my $datedue = shift;
- my $issuedate = 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')) {
@@ -1977,6 +1979,11 @@ sub AddRenewal {
# 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
my $sth =
@@ -1991,11 +1998,11 @@ sub AddRenewal {
# Update the issues record to have the new due date, and a new count
# of how many times it has been renewed.
my $renews = $issuedata->{'renewals'} + 1;
- $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = CURRENT_DATE, issuedate = ?
+ $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
WHERE borrowernumber=?
AND itemnumber=?"
);
- $sth->execute( $datedue->output('iso'), $renews, $issuedate, $borrowernumber, $itemnumber );
+ $sth->execute( $datedue->output('iso'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
$sth->finish;
# Update the renewal count on the item, and tell zebra to reindex
diff --git a/t/lib/KohaTest/Circulation/AddIssue.pm b/t/lib/KohaTest/Circulation/AddIssue.pm
index 4e02d16..dde87e2 100644
--- a/t/lib/KohaTest/Circulation/AddIssue.pm
+++ b/t/lib/KohaTest/Circulation/AddIssue.pm
@@ -93,7 +93,7 @@ sub set_issuedate : Test( 7 ) {
is( $loanlength, $self->{'loanlength'} );
}
-sub set_issuedate_on_renewal : Test( 6 ) {
+sub set_lastreneweddate_on_renewal : Test( 6 ) {
my $self = shift;
my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
@@ -112,7 +112,7 @@ sub set_issuedate_on_renewal : Test( 6 ) {
my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
is( $after_issues->{'borrowernumber'}, $self->{'memberid'}, 'We found this item checked out to our member.' )
or diag( Data::Dumper->Dump( [ $after_issues ], [ 'issues' ] ) );
- is( $after_issues->{'issuedate'}, $issuedate, "...and it was issued on $issuedate" )
+ is( $after_issues->{'lastreneweddate'}, $issuedate, "...and it was renewed on $issuedate" )
or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );
}
--
1.5.5.GIT
More information about the Koha-patches
mailing list