Bug 6796: Don't add a day if hourly loan period pushes due date

If ConsiderLibraryHoursWhenIssuing is set to shorten the loan period to
the closing time, if the loan period initially pushes the due date to
the following day, the day still gets added when calculating the due
date. We simply need to hardcode the due time here as the due day is the
same as the issue day.

We only need to calculate a due date if ConsiderLibraryHoursWhenIssuing
is set to extend the loan period to the next opening day, as we'll need
to consider holidays/closed days.

Sponsored-by: Catalyst IT
Sponsored-by: Auckland University of Technology
Signed-off-by: Sam Lau <samalau@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Aleisha Amohia 2022-08-05 15:00:52 +12:00 committed by Katrin Fischer
parent d80ef8df78
commit b2a6dd0c1d
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 6 additions and 14 deletions

View File

@ -3941,15 +3941,13 @@ sub CalcDateDue {
if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) {
if ( $considerlibraryhours eq 'close' ) {
# datedue will be after the library closes on that day
# shorten loan period to end when library closes
$dur = $potential_datedue->delta_ms( $library_close );
$sethours = $considerlibraryhours;
# shorten loan period to end when library closes by hardcoding due time
$datedue->set( hour => $close[0], minute => $close[1] );
} elsif ( $considerlibraryhours eq 'open' ) {
# datedue will be after the library closes on that day
# extend loan period to when library opens following day
my $library_open = $datedue->clone->set( hour => $open[0], minute => $open[1] );
$dur = $potential_datedue->delta_ms( $library_open )->add( days => 1 );
$sethours = $considerlibraryhours;
# extend loan period to when library opens following day by hardcoding due time for next open day
$dur = DateTime::Duration->new( days => 1 );
$datedue->set( hour => $open[0], minute => $open[1] );
} else {
# ignore library open hours
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} );
@ -3963,16 +3961,10 @@ sub CalcDateDue {
$dur = DateTime::Duration->new( days => $loanlength->{$length_key} );
}
my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode );
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} );
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ) if $dur;
if ($loanlength->{lengthunit} eq 'days') {
$datedue->set_hour(23);
$datedue->set_minute(59);
} else {
if ( $sethours and $sethours eq 'close' ) {
$datedue->set( hour => $close[0], minute => $close[1] );
} elsif ( $sethours and $sethours eq 'open' ) {
$datedue->set( hour => $open[0], minute => $open[1] );
}
}
}