@@ -, +, @@ --- C4/Circulation.pm | 36 +++++---- admin/branches.pl | 29 ++++--- .../prog/en/modules/admin/branches.tt | 12 +-- t/db_dependent/Circulation/CalcDateDue.t | 76 ++++++++++++------- 4 files changed, 94 insertions(+), 59 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -3895,20 +3895,23 @@ sub CalcDateDue { my $considerlibraryhours = C4::Context->preference('ConsiderLibraryHoursInCirculation'); # starter vars so don't do calculations directly to $datedue - my $potential_datedue = $datedue->clone; - my $library_close = $datedue->clone; - my $dayofweek = $datedue->day_of_week - 1; + my $potential_datedue = $datedue->clone; + my $library_close = $datedue->clone; + my $dayofweek = $datedue->day_of_week - 1; my $tomorrow_dayofweek = $dayofweek + 1; + # If it's Sunday and tomorrow would be == 7, make tomorrow 0 (Days are stored as 0-6) if ( $tomorrow_dayofweek > 6 ) { $tomorrow_dayofweek = 0; } - my $todayhours = Koha::Library::Hours->find({ library_id => $branch, day => $dayofweek }); - my @close = undef; - my $tomorrowhours = Koha::Library::Hours->find({ library_id => $branch, day => $dayofweek+1 }); # get open hours of next day + my $todayhours = Koha::Library::Hours->find( { library_id => $branch, day => $dayofweek } ); + my @close = undef; + my $tomorrowhours = Koha::Library::Hours->find( { library_id => $branch, day => $tomorrow_dayofweek } ) + ; # get open hours of next day my @open = undef; - if ( $todayhours->close_time and $tomorrowhours->open_time ) { - @close = split( ":", $todayhours->close_time ); - $library_close = $library_close->set( hour => $close[0], minute => $close[1] ); - $potential_datedue = $potential_datedue->add( hours => $loanlength->{$length_key} ); # datedue without consideration for open hours + if ( $considerlibraryhours ne 'ignore' and $todayhours->close_time and $tomorrowhours->open_time ) { + @close = split( ":", $todayhours->close_time ); + $library_close = $library_close->set( hour => $close[0], minute => $close[1] ); + $potential_datedue = $potential_datedue->add( hours => $loanlength->{$length_key} ) + ; # datedue without consideration for open hours @open = split( ":", $tomorrowhours->open_time ); } @@ -3916,20 +3919,24 @@ sub CalcDateDue { if ( $daysmode eq 'Days' ) { # ignoring calendar if ( $loanlength->{lengthunit} eq 'hours' ) { - if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { + if ( $considerlibraryhours ne 'ignore' and $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { if ( $considerlibraryhours eq 'close' ) { + # datedue will be after the library closes on that day # shorten loan period to end when library closes $datedue->set( hour => $close[0], minute => $close[1] ); } elsif ( $considerlibraryhours eq 'open' ) { + # datedue will be after the library closes on that day # extend loan period to when library opens following day $datedue->add( days => 1 )->set( hour => $open[0], minute => $open[1] ); } else { + # ignore library open hours $datedue->add( hours => $loanlength->{$length_key} ); } } else { + # due time doesn't conflict with library open hours, don't need to check $datedue->add( hours => $loanlength->{$length_key} ); } @@ -3940,23 +3947,26 @@ sub CalcDateDue { } } else { my $dur; - my $sethours; if ($loanlength->{lengthunit} eq 'hours') { - if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { + if ( $considerlibraryhours ne 'ignore' and $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { if ( $considerlibraryhours eq 'close' ) { + # datedue will be after the library closes on that day # shorten loan period to end when library closes by hardcoding due time $datedue->set( hour => $close[0], minute => $close[1] ); } elsif ( $considerlibraryhours eq 'open' ) { + # datedue will be after the library closes on that day # extend loan period to when library opens following day by hardcoding due time for next open day $dur = DateTime::Duration->new( days => 1 ); $datedue->set( hour => $open[0], minute => $open[1] ); } else { + # ignore library open hours $dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); } } else { + # due time doesn't conflict with library open hours, don't need to check $dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); } --- a/admin/branches.pl +++ a/admin/branches.pl @@ -50,11 +50,12 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( ); if ( $op eq 'add_form' ) { - my @opening_hours = Koha::Library::Hours->search({ library_id => $branchcode }, { order_by => { -asc => 'day' } })->as_list; + my @opening_hours = + Koha::Library::Hours->search( { library_id => $branchcode }, { order_by => { -asc => 'day' } } )->as_list; $template->param( - library => Koha::Libraries->find($branchcode), - smtp_servers => Koha::SMTP::Servers->search, + library => Koha::Libraries->find($branchcode), + smtp_servers => Koha::SMTP::Servers->search, opening_hours => \@opening_hours ); } elsif ( $branchcode && $op eq 'view' ) { @@ -120,11 +121,11 @@ if ( $op eq 'add_form' ) { } } - my @days = $input->multi_param("day"); - my @open_times = $input->multi_param("open_time"); + my @days = $input->multi_param("day"); + my @open_times = $input->multi_param("open_time"); my @close_times = $input->multi_param("close_time"); - foreach my $day ( @days ) { + foreach my $day (@days) { if ( $open_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) { $open_times[$day] = undef; } @@ -132,7 +133,8 @@ if ( $op eq 'add_form' ) { $close_times[$day] = undef; } - my $openday = Koha::Library::Hours->find({ library_id => $branchcode, day => $day })->update({ open_time => $open_times[$day], close_time => $close_times[$day] }); + my $openday = Koha::Library::Hours->find( { library_id => $branchcode, day => $day } ) + ->update( { open_time => $open_times[$day], close_time => $close_times[$day] } ); } push @messages, { type => 'message', code => 'success_on_update' }; @@ -173,11 +175,11 @@ if ( $op eq 'add_form' ) { } } - my @days = $input->multi_param("day"); - my @open_times = $input->multi_param("open_time"); + my @days = $input->multi_param("day"); + my @open_times = $input->multi_param("open_time"); my @close_times = $input->multi_param("close_time"); - foreach my $day ( @days ) { + foreach my $day (@days) { if ( $open_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) { $open_times[$day] = undef; } @@ -185,7 +187,12 @@ if ( $op eq 'add_form' ) { $close_times[$day] = undef; } - my $openday = Koha::Library::Hour->new({ library_id => $branchcode, day => $day, open_time => $open_times[$day], close_time => $close_times[$day] })->store; + my $openday = Koha::Library::Hour->new( + { + library_id => $branchcode, day => $day, open_time => $open_times[$day], + close_time => $close_times[$day] + } + )->store; } push @messages, { type => 'message', code => 'success_on_insert' }; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt @@ -303,21 +303,21 @@ [% IF opening_hours # Existing library %] [% daycount = 0 %] [% FOREACH hr IN opening_hours %] -