|
Lines 61-66
use Koha::Config::SysPref;
Link Here
|
| 61 |
use Koha::Checkouts::ReturnClaims; |
61 |
use Koha::Checkouts::ReturnClaims; |
| 62 |
use Koha::SearchEngine::Indexer; |
62 |
use Koha::SearchEngine::Indexer; |
| 63 |
use Koha::Exceptions::Checkout; |
63 |
use Koha::Exceptions::Checkout; |
|
|
64 |
use Koha::Library::Hours; |
| 64 |
use Carp qw( carp ); |
65 |
use Carp qw( carp ); |
| 65 |
use List::MoreUtils qw( any ); |
66 |
use List::MoreUtils qw( any ); |
| 66 |
use Scalar::Util qw( looks_like_number ); |
67 |
use Scalar::Util qw( looks_like_number ); |
|
Lines 3649-3659
sub CalcDateDue {
Link Here
|
| 3649 |
} |
3650 |
} |
| 3650 |
); |
3651 |
); |
| 3651 |
|
3652 |
|
|
|
3653 |
my $considerlibraryhours = C4::Context->preference('ConsiderLibraryHoursWhenIssuing'); |
| 3654 |
# starter vars so don't do calculations directly to $datedue |
| 3655 |
my $potential_datedue = $datedue->clone; |
| 3656 |
my $library_close = $datedue->clone; |
| 3657 |
my $dayofweek = $datedue->local_day_of_week - 1; |
| 3658 |
my $todayhours = Koha::Library::Hours->find({ branchcode => $branch, day => $dayofweek }); |
| 3659 |
my @close = undef; |
| 3660 |
my $tomorrowhours = Koha::Library::Hours->find({ branchcode => $branch, day => $dayofweek+1 }); # get open hours of next day |
| 3661 |
my @open = undef; |
| 3662 |
if ( $todayhours->close_time and $tomorrowhours->open_time ) { |
| 3663 |
@close = split( ":", $todayhours->close_time ); |
| 3664 |
$library_close = $library_close->set( hour => $close[0], minute => $close[1] ); |
| 3665 |
$potential_datedue = $potential_datedue->add( hours => $loanlength->{$length_key} ); # datedue without consideration for open hours |
| 3666 |
@open = split( ":", $tomorrowhours->open_time ); |
| 3667 |
} |
| 3668 |
|
| 3652 |
# calculate the datedue as normal |
3669 |
# calculate the datedue as normal |
| 3653 |
if ( $daysmode eq 'Days' ) |
3670 |
if ( $daysmode eq 'Days' ) |
| 3654 |
{ # ignoring calendar |
3671 |
{ # ignoring calendar |
| 3655 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
3672 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
| 3656 |
$datedue->add( hours => $loanlength->{$length_key} ); |
3673 |
if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { |
|
|
3674 |
if ( $considerlibraryhours eq 'close' ) { |
| 3675 |
# datedue will be after the library closes on that day |
| 3676 |
# shorten loan period to end when library closes |
| 3677 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
| 3678 |
} elsif ( $considerlibraryhours eq 'open' ) { |
| 3679 |
# datedue will be after the library closes on that day |
| 3680 |
# extend loan period to when library opens following day |
| 3681 |
$datedue->add( days => 1 )->set( hour => $open[0], minute => $open[1] ); |
| 3682 |
} else { |
| 3683 |
# ignore library open hours |
| 3684 |
$datedue->add( hours => $loanlength->{$length_key} ); |
| 3685 |
} |
| 3686 |
} else { |
| 3687 |
# due time doesn't conflict with library open hours, don't need to check |
| 3688 |
$datedue->add( hours => $loanlength->{$length_key} ); |
| 3689 |
} |
| 3657 |
} else { # days |
3690 |
} else { # days |
| 3658 |
$datedue->add( days => $loanlength->{$length_key} ); |
3691 |
$datedue->add( days => $loanlength->{$length_key} ); |
| 3659 |
$datedue->set_hour(23); |
3692 |
$datedue->set_hour(23); |
|
Lines 3661-3677
sub CalcDateDue {
Link Here
|
| 3661 |
} |
3694 |
} |
| 3662 |
} else { |
3695 |
} else { |
| 3663 |
my $dur; |
3696 |
my $dur; |
|
|
3697 |
my $sethours; |
| 3664 |
if ($loanlength->{lengthunit} eq 'hours') { |
3698 |
if ($loanlength->{lengthunit} eq 'hours') { |
| 3665 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key}); |
3699 |
if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { |
|
|
3700 |
if ( $considerlibraryhours eq 'close' ) { |
| 3701 |
# datedue will be after the library closes on that day |
| 3702 |
# shorten loan period to end when library closes |
| 3703 |
$dur = $potential_datedue->delta_ms( $library_close ); |
| 3704 |
$sethours = $considerlibraryhours; |
| 3705 |
} elsif ( $considerlibraryhours eq 'open' ) { |
| 3706 |
# datedue will be after the library closes on that day |
| 3707 |
# extend loan period to when library opens following day |
| 3708 |
my $library_open = $datedue->clone->set( hour => $open[0], minute => $open[1] ); |
| 3709 |
$dur = $potential_datedue->delta_ms( $library_open )->add( days => 1 ); |
| 3710 |
$sethours = $considerlibraryhours; |
| 3711 |
} else { |
| 3712 |
# ignore library open hours |
| 3713 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); |
| 3714 |
} |
| 3715 |
} else { |
| 3716 |
# due time doesn't conflict with library open hours, don't need to check |
| 3717 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); |
| 3718 |
} |
| 3666 |
} |
3719 |
} |
| 3667 |
else { # days |
3720 |
else { # days |
| 3668 |
$dur = DateTime::Duration->new( days => $loanlength->{$length_key}); |
3721 |
$dur = DateTime::Duration->new( days => $loanlength->{$length_key} ); |
| 3669 |
} |
3722 |
} |
| 3670 |
my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); |
3723 |
my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); |
| 3671 |
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ); |
3724 |
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ); |
| 3672 |
if ($loanlength->{lengthunit} eq 'days') { |
3725 |
if ($loanlength->{lengthunit} eq 'days') { |
| 3673 |
$datedue->set_hour(23); |
3726 |
$datedue->set_hour(23); |
| 3674 |
$datedue->set_minute(59); |
3727 |
$datedue->set_minute(59); |
|
|
3728 |
} else { |
| 3729 |
if ( $sethours and $sethours eq 'close' ) { |
| 3730 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
| 3731 |
} elsif ( $sethours and $sethours eq 'open' ) { |
| 3732 |
$datedue->set( hour => $open[0], minute => $open[1] ); |
| 3733 |
} |
| 3675 |
} |
3734 |
} |
| 3676 |
} |
3735 |
} |
| 3677 |
|
3736 |
|