From f545101b43d0c7d512407cfe55f02ccf305ab1e2 Mon Sep 17 00:00:00 2001 From: mehdi Date: Mon, 23 Jan 2017 16:55:48 -0500 Subject: [PATCH] Bug 17983 - Enabled the use of minutes loan --- C4/Circulation.pm | 21 +++++++++++++++++++-- C4/Overdues.pm | 12 ++++++++++++ .../prog/en/modules/admin/smart-rules.tt | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 018fd01..2f8dd7d 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3438,12 +3438,14 @@ sub CalcDateDue { ->truncate( to => 'minute' ); } - + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch ); # calculate the datedue as normal if ( C4::Context->preference('useDaysMode') eq 'Days' ) { # ignoring calendar if ( $loanlength->{lengthunit} eq 'hours' ) { $datedue->add( hours => $loanlength->{$length_key} ); + } elsif ( $loanlength->{lengthunit} eq 'minutes' ) { + $datedue->add( minutes => $loanlength->{$length_key}); } else { # days $datedue->add( days => $loanlength->{$length_key} ); $datedue->set_hour(23); @@ -3454,10 +3456,12 @@ sub CalcDateDue { if ($loanlength->{lengthunit} eq 'hours') { $dur = DateTime::Duration->new( hours => $loanlength->{$length_key}); } + elsif ($loanlength->{lengthunit} eq 'minutes') { + $dur = DateTime::Duration->new( minutes => $loanlength->{$length_key}); + } else { # days $dur = DateTime::Duration->new( days => $loanlength->{$length_key}); } - my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branch }); $datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} ); if ($loanlength->{lengthunit} eq 'days') { $datedue->set_hour(23); @@ -3503,6 +3507,19 @@ sub CalcDateDue { } } } + + #check if it's minutes or hourly loan and set due date to close hour, if the current due date is passed closing hours. + if ($loanlength->{lengthunit} eq 'hours' || $loanlength->{lengthunit} eq 'minutes'){ + my $dateInfo = $calendar->get_date_info($datedue); + my $close = dt_from_string($dateInfo->{date} ." ". $dateInfo->{closehour}, 'iso', C4::Context->tz()); + + my $close_datetime = $datedue->clone()->set(hour => $close->hour(), minute=> $close->minute()); + + if(DateTime->compare($datedue, $close_datetime) > 0) { + $datedue = $close_datetime->clone(); + } + } + return $datedue; } diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 3f1436a..c2f3cec 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -304,6 +304,18 @@ sub get_chargeable_units { } return $charge_duration->in_units('hours'); } + elsif($unit eq 'minutes'){ + if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode ); + $charge_duration = $calendar->open_minutes_between( $date_due, $date_returned ); + } else { + $charge_duration = $date_returned->delta_ms( $date_due ); + } + if($charge_duration->in_units('minutes') == 0 && $charge_duration->in_units('seconds') > 0){ + return 1; + } + return $charge_duration->in_units('minutes'); + } else { # days if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branchcode }); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index ffa8776..b765805 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -245,6 +245,7 @@ -- 2.7.4