$item->{'itemnumber'},
$branch,
$datedue,
- $issuedate,
+ $issuedate, # here interpreted as the renewal date
);
}
=head2 AddRenewal
-&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$issuedate]);
+&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate]);
Renews a loan.
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.
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')) {
# 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 =
# 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
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'} );
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' ] ) );
}