|
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 3773-3783
sub CalcDateDue {
Link Here
|
| 3773 |
} |
3774 |
} |
| 3774 |
); |
3775 |
); |
| 3775 |
|
3776 |
|
|
|
3777 |
my $considerlibraryhours = C4::Context->preference('ConsiderLibraryHoursWhenIssuing'); |
| 3778 |
# starter vars so don't do calculations directly to $datedue |
| 3779 |
my $potential_datedue = $datedue->clone; |
| 3780 |
my $library_close = $datedue->clone; |
| 3781 |
my $dayofweek = $datedue->local_day_of_week - 1; |
| 3782 |
my $todayhours = Koha::Library::Hours->find({ branchcode => $branch, day => $dayofweek }); |
| 3783 |
my @close = undef; |
| 3784 |
my $tomorrowhours = Koha::Library::Hours->find({ branchcode => $branch, day => $dayofweek+1 }); # get open hours of next day |
| 3785 |
my @open = undef; |
| 3786 |
if ( $todayhours->close_time and $tomorrowhours->open_time ) { |
| 3787 |
@close = split( ":", $todayhours->close_time ); |
| 3788 |
$library_close = $library_close->set( hour => $close[0], minute => $close[1] ); |
| 3789 |
$potential_datedue = $potential_datedue->add( hours => $loanlength->{$length_key} ); # datedue without consideration for open hours |
| 3790 |
@open = split( ":", $tomorrowhours->open_time ); |
| 3791 |
} |
| 3792 |
|
| 3776 |
# calculate the datedue as normal |
3793 |
# calculate the datedue as normal |
| 3777 |
if ( $daysmode eq 'Days' ) |
3794 |
if ( $daysmode eq 'Days' ) |
| 3778 |
{ # ignoring calendar |
3795 |
{ # ignoring calendar |
| 3779 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
3796 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
| 3780 |
$datedue->add( hours => $loanlength->{$length_key} ); |
3797 |
if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { |
|
|
3798 |
if ( $considerlibraryhours eq 'close' ) { |
| 3799 |
# datedue will be after the library closes on that day |
| 3800 |
# shorten loan period to end when library closes |
| 3801 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
| 3802 |
} elsif ( $considerlibraryhours eq 'open' ) { |
| 3803 |
# datedue will be after the library closes on that day |
| 3804 |
# extend loan period to when library opens following day |
| 3805 |
$datedue->add( days => 1 )->set( hour => $open[0], minute => $open[1] ); |
| 3806 |
} else { |
| 3807 |
# ignore library open hours |
| 3808 |
$datedue->add( hours => $loanlength->{$length_key} ); |
| 3809 |
} |
| 3810 |
} else { |
| 3811 |
# due time doesn't conflict with library open hours, don't need to check |
| 3812 |
$datedue->add( hours => $loanlength->{$length_key} ); |
| 3813 |
} |
| 3781 |
} else { # days |
3814 |
} else { # days |
| 3782 |
$datedue->add( days => $loanlength->{$length_key} ); |
3815 |
$datedue->add( days => $loanlength->{$length_key} ); |
| 3783 |
$datedue->set_hour(23); |
3816 |
$datedue->set_hour(23); |
|
Lines 3785-3801
sub CalcDateDue {
Link Here
|
| 3785 |
} |
3818 |
} |
| 3786 |
} else { |
3819 |
} else { |
| 3787 |
my $dur; |
3820 |
my $dur; |
|
|
3821 |
my $sethours; |
| 3788 |
if ($loanlength->{lengthunit} eq 'hours') { |
3822 |
if ($loanlength->{lengthunit} eq 'hours') { |
| 3789 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key}); |
3823 |
if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { |
|
|
3824 |
if ( $considerlibraryhours eq 'close' ) { |
| 3825 |
# datedue will be after the library closes on that day |
| 3826 |
# shorten loan period to end when library closes |
| 3827 |
$dur = $potential_datedue->delta_ms( $library_close ); |
| 3828 |
$sethours = $considerlibraryhours; |
| 3829 |
} elsif ( $considerlibraryhours eq 'open' ) { |
| 3830 |
# datedue will be after the library closes on that day |
| 3831 |
# extend loan period to when library opens following day |
| 3832 |
my $library_open = $datedue->clone->set( hour => $open[0], minute => $open[1] ); |
| 3833 |
$dur = $potential_datedue->delta_ms( $library_open )->add( days => 1 ); |
| 3834 |
$sethours = $considerlibraryhours; |
| 3835 |
} else { |
| 3836 |
# ignore library open hours |
| 3837 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); |
| 3838 |
} |
| 3839 |
} else { |
| 3840 |
# due time doesn't conflict with library open hours, don't need to check |
| 3841 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); |
| 3842 |
} |
| 3790 |
} |
3843 |
} |
| 3791 |
else { # days |
3844 |
else { # days |
| 3792 |
$dur = DateTime::Duration->new( days => $loanlength->{$length_key}); |
3845 |
$dur = DateTime::Duration->new( days => $loanlength->{$length_key} ); |
| 3793 |
} |
3846 |
} |
| 3794 |
my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); |
3847 |
my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); |
| 3795 |
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ); |
3848 |
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ); |
| 3796 |
if ($loanlength->{lengthunit} eq 'days') { |
3849 |
if ($loanlength->{lengthunit} eq 'days') { |
| 3797 |
$datedue->set_hour(23); |
3850 |
$datedue->set_hour(23); |
| 3798 |
$datedue->set_minute(59); |
3851 |
$datedue->set_minute(59); |
|
|
3852 |
} else { |
| 3853 |
if ( $sethours and $sethours eq 'close' ) { |
| 3854 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
| 3855 |
} elsif ( $sethours and $sethours eq 'open' ) { |
| 3856 |
$datedue->set( hour => $open[0], minute => $open[1] ); |
| 3857 |
} |
| 3799 |
} |
3858 |
} |
| 3800 |
} |
3859 |
} |
| 3801 |
|
3860 |
|