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