From f2b9e3b0bf0986ece301a22cf6b9d2acfa571dec Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Sun, 14 Sep 2014 12:05:42 +0300 Subject: [PATCH 2/6] Bug 12353 - Introducing last pickup date calculation functions. --- C4/Reserves.pm | 23 +++++++++++++++ Koha/Calendar.pm | 12 ++++++++ Koha/Reserves.pm | 30 +++++++++++++++++++- .../en/modules/admin/preferences/circulation.pref | 2 +- 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index cf4211e..08f452a 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -38,6 +38,9 @@ use C4::Branch qw( GetBranchDetail ); use C4::Dates qw( format_date_in_iso ); use Koha::DateUtils; +use Koha::Calendar; + +use DateTime; use List::MoreUtils qw( firstidx ); @@ -132,6 +135,8 @@ BEGIN { &ToggleSuspend &SuspendAll + &_reserve_last_pickup_date + &GetReservesControlBranch ); @EXPORT_OK = qw( MergeHolds ); @@ -1815,6 +1820,24 @@ sub _Findgroupreserve { return @results; } +=head2 _reserve_last_pickup_date + + my $last_dt = _reserve_last_pickup_date($reserve); + +Returns the DateTime for the last pickup date for reserve. + +=cut + +sub _reserve_last_pickup_date { + my ($reserve) = @_; + + my $startdate = $reserve->{waitingdate} ? dt_from_string($reserve->{waitingdate}) : DateTime->now( time_zone => C4::Context->tz() ); + my $calendar = Koha::Calendar->new( branchcode => $reserve->{branchcode} ); + my $expiration = $calendar->days_forward( $startdate, C4::Context->preference('ReservesMaxPickUpDelay') ); + + return $expiration; +} + =head2 _koha_notify_reserve _koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber, $reserve_id ); diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 276c7ce..04f655d 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -267,6 +267,18 @@ sub prev_open_day { return $base_date; } +sub days_forward { + my $self = shift; + my $start_dt = shift; + my $num_days = shift; + + my $base_dt = $start_dt->clone(); + + while ($num_days--) { $base_dt = $self->next_open_day($base_dt); } + + return $base_dt; +} + sub days_between { my $self = shift; my $start_dt = shift; diff --git a/Koha/Reserves.pm b/Koha/Reserves.pm index fb4adbc..6580a55 100644 --- a/Koha/Reserves.pm +++ b/Koha/Reserves.pm @@ -27,7 +27,8 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( - + &GetLastpickupdate + &GetWaitingReserves ); } @@ -35,3 +36,30 @@ use C4::Context; use Koha::DateUtils; use Koha::Database; +=head2 GetLastpickupdate + + my $last_dt = GetLastpickupdate($reserve); + +@PARAM1 Koha::Schema::Result::Reserve-object received via DBIx searching +@RETURNS the DateTime for the last pickup date for the given reserve. +=cut + +sub GetLastpickupdate { + my ($reserve) = @_; + + my $branchcode = $reserve->branchcode(); + if (ref $branchcode eq 'Koha::Schema::Result::Branch') { + $branchcode = $branchcode->branchcode(); + } + + my $waitingdate = $reserve->waitingdate(); + my $startdate = $waitingdate ? Koha::DateUtils::dt_from_string($waitingdate) : DateTime->now( time_zone => C4::Context->tz() ); + my $calendar = Koha::Calendar->new( branchcode => $branchcode ); + my $expiration = $calendar->days_forward( $startdate, C4::Context->preference('ReservesMaxPickUpDelay') ); + + return $expiration; +} + + + +return 1; \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 1ee6363..a205e24 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -404,7 +404,7 @@ Circulation: - Mark a hold as problematic if it has been waiting for more than - pref: ReservesMaxPickUpDelay class: integer - - days. + - non-holiday days. - - pref: ExpireReservesMaxPickUpDelay choices: -- 1.7.9.5