From 21cbca3e858aa76c7ed775e0e6380e303486df82 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 | 22 ++++++++++++++++++---- C4/Overdues.pm | 14 ++++++++++++-- .../prog/en/modules/admin/smart-rules.tt | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 3dab3a0..c65f47d 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3487,12 +3487,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); @@ -3502,11 +3504,11 @@ sub CalcDateDue { my $dur; if ($loanlength->{lengthunit} eq 'hours') { $dur = DateTime::Duration->new( hours => $loanlength->{$length_key}); - } - else { # days + }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); @@ -3546,6 +3548,18 @@ 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 9a4a942..95834c3 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -308,8 +308,18 @@ sub get_chargeable_units { return 1; } return $charge_duration->in_units('hours'); - } - else { # days + }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 ); $charge_duration = $calendar->days_between( $date_due, $date_returned ); 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 d4451de..2cc28e4 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 @@ -320,6 +320,7 @@ $(document).ready(function() { -- 1.9.1