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 blessed ); |
69 |
use Scalar::Util qw( looks_like_number blessed ); |
Lines 3821-3831
sub CalcDateDue {
Link Here
|
3821 |
} |
3822 |
} |
3822 |
); |
3823 |
); |
3823 |
|
3824 |
|
|
|
3825 |
my $considerlibraryhours = C4::Context->preference('ConsiderLibraryHoursWhenIssuing'); |
3826 |
# starter vars so don't do calculations directly to $datedue |
3827 |
my $potential_datedue = $datedue->clone; |
3828 |
my $library_close = $datedue->clone; |
3829 |
my $dayofweek = $datedue->local_day_of_week - 1; |
3830 |
my $todayhours = Koha::Library::Hours->find({ branchcode => $branch, day => $dayofweek }); |
3831 |
my @close = undef; |
3832 |
my $tomorrowhours = Koha::Library::Hours->find({ branchcode => $branch, day => $dayofweek+1 }); # get open hours of next day |
3833 |
my @open = undef; |
3834 |
if ( $todayhours->close_time and $tomorrowhours->open_time ) { |
3835 |
@close = split( ":", $todayhours->close_time ); |
3836 |
$library_close = $library_close->set( hour => $close[0], minute => $close[1] ); |
3837 |
$potential_datedue = $potential_datedue->add( hours => $loanlength->{$length_key} ); # datedue without consideration for open hours |
3838 |
@open = split( ":", $tomorrowhours->open_time ); |
3839 |
} |
3840 |
|
3824 |
# calculate the datedue as normal |
3841 |
# calculate the datedue as normal |
3825 |
if ( $daysmode eq 'Days' ) |
3842 |
if ( $daysmode eq 'Days' ) |
3826 |
{ # ignoring calendar |
3843 |
{ # ignoring calendar |
3827 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
3844 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
3828 |
$datedue->add( hours => $loanlength->{$length_key} ); |
3845 |
if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { |
|
|
3846 |
if ( $considerlibraryhours eq 'close' ) { |
3847 |
# datedue will be after the library closes on that day |
3848 |
# shorten loan period to end when library closes |
3849 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
3850 |
} elsif ( $considerlibraryhours eq 'open' ) { |
3851 |
# datedue will be after the library closes on that day |
3852 |
# extend loan period to when library opens following day |
3853 |
$datedue->add( days => 1 )->set( hour => $open[0], minute => $open[1] ); |
3854 |
} else { |
3855 |
# ignore library open hours |
3856 |
$datedue->add( hours => $loanlength->{$length_key} ); |
3857 |
} |
3858 |
} else { |
3859 |
# due time doesn't conflict with library open hours, don't need to check |
3860 |
$datedue->add( hours => $loanlength->{$length_key} ); |
3861 |
} |
3829 |
} else { # days |
3862 |
} else { # days |
3830 |
$datedue->add( days => $loanlength->{$length_key} ); |
3863 |
$datedue->add( days => $loanlength->{$length_key} ); |
3831 |
$datedue->set_hour(23); |
3864 |
$datedue->set_hour(23); |
Lines 3833-3849
sub CalcDateDue {
Link Here
|
3833 |
} |
3866 |
} |
3834 |
} else { |
3867 |
} else { |
3835 |
my $dur; |
3868 |
my $dur; |
|
|
3869 |
my $sethours; |
3836 |
if ($loanlength->{lengthunit} eq 'hours') { |
3870 |
if ($loanlength->{lengthunit} eq 'hours') { |
3837 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key}); |
3871 |
if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { |
|
|
3872 |
if ( $considerlibraryhours eq 'close' ) { |
3873 |
# datedue will be after the library closes on that day |
3874 |
# shorten loan period to end when library closes |
3875 |
$dur = $potential_datedue->delta_ms( $library_close ); |
3876 |
$sethours = $considerlibraryhours; |
3877 |
} elsif ( $considerlibraryhours eq 'open' ) { |
3878 |
# datedue will be after the library closes on that day |
3879 |
# extend loan period to when library opens following day |
3880 |
my $library_open = $datedue->clone->set( hour => $open[0], minute => $open[1] ); |
3881 |
$dur = $potential_datedue->delta_ms( $library_open )->add( days => 1 ); |
3882 |
$sethours = $considerlibraryhours; |
3883 |
} else { |
3884 |
# ignore library open hours |
3885 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); |
3886 |
} |
3887 |
} else { |
3888 |
# due time doesn't conflict with library open hours, don't need to check |
3889 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); |
3890 |
} |
3838 |
} |
3891 |
} |
3839 |
else { # days |
3892 |
else { # days |
3840 |
$dur = DateTime::Duration->new( days => $loanlength->{$length_key}); |
3893 |
$dur = DateTime::Duration->new( days => $loanlength->{$length_key} ); |
3841 |
} |
3894 |
} |
3842 |
my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); |
3895 |
my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); |
3843 |
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ); |
3896 |
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ); |
3844 |
if ($loanlength->{lengthunit} eq 'days') { |
3897 |
if ($loanlength->{lengthunit} eq 'days') { |
3845 |
$datedue->set_hour(23); |
3898 |
$datedue->set_hour(23); |
3846 |
$datedue->set_minute(59); |
3899 |
$datedue->set_minute(59); |
|
|
3900 |
} else { |
3901 |
if ( $sethours and $sethours eq 'close' ) { |
3902 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
3903 |
} elsif ( $sethours and $sethours eq 'open' ) { |
3904 |
$datedue->set( hour => $open[0], minute => $open[1] ); |
3905 |
} |
3847 |
} |
3906 |
} |
3848 |
} |
3907 |
} |
3849 |
|
3908 |
|