Lines 63-68
use Koha::SearchEngine::Indexer;
Link Here
|
63 |
use Koha::Exceptions::Checkout; |
63 |
use Koha::Exceptions::Checkout; |
64 |
use Koha::Plugins; |
64 |
use Koha::Plugins; |
65 |
use Koha::Recalls; |
65 |
use Koha::Recalls; |
|
|
66 |
use Koha::Library::Hours; |
66 |
use Carp qw( carp ); |
67 |
use Carp qw( carp ); |
67 |
use List::MoreUtils qw( any ); |
68 |
use List::MoreUtils qw( any ); |
68 |
use Scalar::Util qw( looks_like_number ); |
69 |
use Scalar::Util qw( looks_like_number ); |
Lines 3729-3739
sub CalcDateDue {
Link Here
|
3729 |
} |
3730 |
} |
3730 |
); |
3731 |
); |
3731 |
|
3732 |
|
|
|
3733 |
my $considerlibraryhours = C4::Context->preference('ConsiderLibraryHoursWhenIssuing'); |
3734 |
# starter vars so don't do calculations directly to $datedue |
3735 |
my $potential_datedue = $datedue->clone; |
3736 |
my $library_close = $datedue->clone; |
3737 |
my $dayofweek = $datedue->local_day_of_week - 1; |
3738 |
my $todayhours = Koha::Library::Hours->find({ branchcode => $branch, day => $dayofweek }); |
3739 |
my @close = undef; |
3740 |
my $tomorrowhours = Koha::Library::Hours->find({ branchcode => $branch, day => $dayofweek+1 }); # get open hours of next day |
3741 |
my @open = undef; |
3742 |
if ( $todayhours->close_time and $tomorrowhours->open_time ) { |
3743 |
@close = split( ":", $todayhours->close_time ); |
3744 |
$library_close = $library_close->set( hour => $close[0], minute => $close[1] ); |
3745 |
$potential_datedue = $potential_datedue->add( hours => $loanlength->{$length_key} ); # datedue without consideration for open hours |
3746 |
@open = split( ":", $tomorrowhours->open_time ); |
3747 |
} |
3748 |
|
3732 |
# calculate the datedue as normal |
3749 |
# calculate the datedue as normal |
3733 |
if ( $daysmode eq 'Days' ) |
3750 |
if ( $daysmode eq 'Days' ) |
3734 |
{ # ignoring calendar |
3751 |
{ # ignoring calendar |
3735 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
3752 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
3736 |
$datedue->add( hours => $loanlength->{$length_key} ); |
3753 |
if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { |
|
|
3754 |
if ( $considerlibraryhours eq 'close' ) { |
3755 |
# datedue will be after the library closes on that day |
3756 |
# shorten loan period to end when library closes |
3757 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
3758 |
} elsif ( $considerlibraryhours eq 'open' ) { |
3759 |
# datedue will be after the library closes on that day |
3760 |
# extend loan period to when library opens following day |
3761 |
$datedue->add( days => 1 )->set( hour => $open[0], minute => $open[1] ); |
3762 |
} else { |
3763 |
# ignore library open hours |
3764 |
$datedue->add( hours => $loanlength->{$length_key} ); |
3765 |
} |
3766 |
} else { |
3767 |
# due time doesn't conflict with library open hours, don't need to check |
3768 |
$datedue->add( hours => $loanlength->{$length_key} ); |
3769 |
} |
3737 |
} else { # days |
3770 |
} else { # days |
3738 |
$datedue->add( days => $loanlength->{$length_key} ); |
3771 |
$datedue->add( days => $loanlength->{$length_key} ); |
3739 |
$datedue->set_hour(23); |
3772 |
$datedue->set_hour(23); |
Lines 3741-3757
sub CalcDateDue {
Link Here
|
3741 |
} |
3774 |
} |
3742 |
} else { |
3775 |
} else { |
3743 |
my $dur; |
3776 |
my $dur; |
|
|
3777 |
my $sethours; |
3744 |
if ($loanlength->{lengthunit} eq 'hours') { |
3778 |
if ($loanlength->{lengthunit} eq 'hours') { |
3745 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key}); |
3779 |
if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { |
|
|
3780 |
if ( $considerlibraryhours eq 'close' ) { |
3781 |
# datedue will be after the library closes on that day |
3782 |
# shorten loan period to end when library closes |
3783 |
$dur = $potential_datedue->delta_ms( $library_close ); |
3784 |
$sethours = $considerlibraryhours; |
3785 |
} elsif ( $considerlibraryhours eq 'open' ) { |
3786 |
# datedue will be after the library closes on that day |
3787 |
# extend loan period to when library opens following day |
3788 |
my $library_open = $datedue->clone->set( hour => $open[0], minute => $open[1] ); |
3789 |
$dur = $potential_datedue->delta_ms( $library_open )->add( days => 1 ); |
3790 |
$sethours = $considerlibraryhours; |
3791 |
} else { |
3792 |
# ignore library open hours |
3793 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); |
3794 |
} |
3795 |
} else { |
3796 |
# due time doesn't conflict with library open hours, don't need to check |
3797 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); |
3798 |
} |
3746 |
} |
3799 |
} |
3747 |
else { # days |
3800 |
else { # days |
3748 |
$dur = DateTime::Duration->new( days => $loanlength->{$length_key}); |
3801 |
$dur = DateTime::Duration->new( days => $loanlength->{$length_key} ); |
3749 |
} |
3802 |
} |
3750 |
my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); |
3803 |
my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); |
3751 |
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ); |
3804 |
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ); |
3752 |
if ($loanlength->{lengthunit} eq 'days') { |
3805 |
if ($loanlength->{lengthunit} eq 'days') { |
3753 |
$datedue->set_hour(23); |
3806 |
$datedue->set_hour(23); |
3754 |
$datedue->set_minute(59); |
3807 |
$datedue->set_minute(59); |
|
|
3808 |
} else { |
3809 |
if ( $sethours and $sethours eq 'close' ) { |
3810 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
3811 |
} elsif ( $sethours and $sethours eq 'open' ) { |
3812 |
$datedue->set( hour => $open[0], minute => $open[1] ); |
3813 |
} |
3755 |
} |
3814 |
} |
3756 |
} |
3815 |
} |
3757 |
|
3816 |
|