From 4a584d528dbe8e227eb481636b1f9f32da2ec514 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 18 Mar 2015 08:50:21 -0400 Subject: [PATCH] Bug 13517 - Show waiting date on reserve/request.pl The holds table should show the waiting date for a hold in s similar manner to the way it does on catalogue/detail.pl In addition, if the ReservesMaxPickUpDelay syspref is set, we should display the date when the waiting hold expires. Test Plan: 1) Apply this patch 2) Set ReservesMaxPickUpDelay to 7 3) Find a waiting hold 4) Browse to reserve/request.pl for that record 5) Notice the "Item waiting" message now has "since " 6) Notice the expiration field now has the date of + 7 days Signed-off-by: Kyle M Hall Signed-off-by: Cathi Wiggins Signed-off-by: Megan Wianecki Signed-off-by: Jonathan Druart Signed-off-by: Jesse Weaver --- Koha/Hold.pm | 47 ++++++- .../prog/en/modules/reserve/request.tt | 10 +- reserve/request.pl | 124 +++++++++--------- 3 files changed, 118 insertions(+), 63 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index ad84af3b99..975f69933c 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -22,10 +22,12 @@ use Modern::Perl; use Carp; use C4::Context qw(preference); -use Koha::Branches; +use Koha::DateUtils qw(dt_from_string); + +use Koha::Borrowers; use Koha::Biblios; +use Koha::Branches; use Koha::Items; -use Koha::DateUtils qw(dt_from_string); use base qw(Koha::Object); @@ -63,6 +65,20 @@ sub waiting_expires_on { return $dt; } +=head3 is_found + +Returns true if hold is a waiting or in transit + +=cut + +sub is_found { + my ($self) = @_; + + return 0 unless $self->found(); + return 1 if $self->found() eq 'W'; + return 1 if $self->found() eq 'T'; +} + =head3 is_waiting Returns true if hold is a waiting hold @@ -76,6 +92,19 @@ sub is_waiting { return $found && $found eq 'W'; } +=head3 is_in_transit + +Returns true if hold is a in_transit hold + +=cut + +sub is_in_transit { + my ($self) = @_; + + return 0 unless $self->found(); + return $self->found() eq 'T'; +} + =head3 biblio Returns the related Koha::Biblio object for this hold @@ -118,6 +147,20 @@ sub branch { return $self->{_branch}; } +=head3 borrower + +Returns the related Koha::Borrower object for this Hold + +=cut + +sub borrower { + my ($self) = @_; + + $self->{_borrower} ||= Koha::Borrowers->find( $self->borrowernumber() ); + + return $self->{_borrower}; +} + =head3 type =cut diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index bf85bf69e3..3152f7f75f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -742,12 +742,18 @@ function checkMultiHold() { [% reserveloo.notes %] [% reserveloo.date %] - [% reserveloo.expirationdate %] + + [% IF reserveloo.waiting_until %] + [% reserveloo.waiting_until | $KohaDates %] + [% ELSE %] + [% reserveloo.expirationdate %] + [% END %] + [% IF ( reserveloo.wait ) %] [% IF ( reserveloo.atdestination ) %] [% IF ( reserveloo.found ) %] - Item waiting at [% reserveloo.wbrname %] + Item waiting at [% reserveloo.wbrname %] since [% reserveloo.waiting_date | $KohaDates %] [% ELSE %] Waiting to be pulled [% END %] diff --git a/reserve/request.pl b/reserve/request.pl index 80cf0d6118..4860dcde23 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -45,6 +45,7 @@ use C4::Members; use C4::Search; # enabled_staff_search_views use Koha::DateUtils; use Koha::Borrower::Debarments qw(IsDebarred); +use Koha::Holds; my $dbh = C4::Context->dbh; my $sth; @@ -486,85 +487,90 @@ foreach my $biblionumber (@biblionumbers) { # existingreserves building my @reserveloop; - $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 }); - foreach my $res ( sort { - my $a_found = $a->{found} || ''; - my $b_found = $a->{found} || ''; + my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } ); + foreach my $res ( + sort { + my $a_found = $a->found() || ''; + my $b_found = $a->found() || ''; $a_found cmp $b_found; - } @$reserves ) { + } @reserves + ) + { my %reserve; my @optionloop; for ( my $i = 1 ; $i <= $totalcount ; $i++ ) { push( - @optionloop, - { - num => $i, - selected => ( $i == $res->{priority} ), - } - ); + @optionloop, + { + num => $i, + selected => ( $i == $res->priority() ), + } + ); } - if ( defined $res->{'found'} && ($res->{'found'} eq 'W' || $res->{'found'} eq 'T' )) { - my $item = $res->{'itemnumber'}; - $item = GetBiblioFromItemNumber($item,undef); - $reserve{'wait'}= 1; - $reserve{'holdingbranch'}=$item->{'holdingbranch'}; - $reserve{'biblionumber'}=$item->{'biblionumber'}; - $reserve{'barcodenumber'} = $item->{'barcode'}; - $reserve{'wbrcode'} = $res->{'branchcode'}; - $reserve{'itemnumber'} = $res->{'itemnumber'}; - $reserve{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'}; - if($reserve{'holdingbranch'} eq $reserve{'wbrcode'}){ + if ( $res->is_found() ) { + $reserve{'wait'} = 1; + $reserve{'holdingbranch'} = $res->item()->holdingbranch(); + $reserve{'biblionumber'} = $res->item()->biblionumber(); + $reserve{'barcodenumber'} = $res->item()->barcode(); + $reserve{'wbrcode'} = $res->branchcode(); + $reserve{'itemnumber'} = $res->itemnumber(); + $reserve{'wbrname'} = $res->branch()->branchname(); + + if ( $reserve{'holdingbranch'} eq $reserve{'wbrcode'} ) { + # Just because the holdingbranch matches the reserve branch doesn't mean the item # has arrived at the destination, check for an open transfer for the item as well - my ( $transfertwhen, $transfertfrom, $transferto ) = C4::Circulation::GetTransfers( $res->{itemnumber} ); - if ( not $transferto or $transferto ne $res->{branchcode} ) { + my ( $transfertwhen, $transfertfrom, $transferto ) = + C4::Circulation::GetTransfers( $res->itemnumber() ); + if ( not $transferto or $transferto ne $res->branchcode() ) { $reserve{'atdestination'} = 1; } } + # set found to 1 if reserve is waiting for patron pickup - $reserve{'found'} = 1 if $res->{'found'} eq 'W'; - $reserve{'intransit'} = 1 if $res->{'found'} eq 'T'; - } elsif ($res->{priority} > 0) { - if (defined($res->{itemnumber})) { - my $item = GetItem($res->{itemnumber}); - $reserve{'itemnumber'} = $res->{'itemnumber'}; - $reserve{'barcodenumber'} = $item->{'barcode'}; + $reserve{'found'} = $res->is_found(); + $reserve{'intransit'} = $res->is_in_transit(); + } + elsif ( $res->priority() > 0 ) { + if ( my $item = $res->item() ) { + $reserve{'itemnumber'} = $item->id(); + $reserve{'barcodenumber'} = $item->barcode(); $reserve{'item_level_hold'} = 1; } } # get borrowers reserve info - my $reserveborrowerinfo = GetMember( borrowernumber => $res->{'borrowernumber'} ); - if (C4::Context->preference('HidePatronName')){ - $reserve{'hidename'} = 1; - $reserve{'cardnumber'} = $reserveborrowerinfo->{'cardnumber'}; - } - $reserve{'expirationdate'} = output_pref({ dt => dt_from_string( $res->{'expirationdate'} ), dateonly => 1 }) - unless ( !defined($res->{'expirationdate'}) || $res->{'expirationdate'} eq '0000-00-00' ); - $reserve{'date'} = output_pref({ dt => dt_from_string( $res->{'reservedate'} ), dateonly => 1 }); - $reserve{'borrowernumber'} = $res->{'borrowernumber'}; - $reserve{'biblionumber'} = $res->{'biblionumber'}; - $reserve{'borrowernumber'} = $res->{'borrowernumber'}; - $reserve{'firstname'} = $reserveborrowerinfo->{'firstname'}; - $reserve{'surname'} = $reserveborrowerinfo->{'surname'}; - $reserve{'notes'} = $res->{'reservenotes'}; - $reserve{'wait'} = - ( ( defined $res->{'found'} and $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) ); - $reserve{'voldesc'} = $res->{'volumeddesc'}; - $reserve{'ccode'} = $res->{'ccode'}; - $reserve{'barcode'} = $res->{'barcode'}; - $reserve{'priority'} = $res->{'priority'}; - $reserve{'lowestPriority'} = $res->{'lowestPriority'}; - $reserve{'optionloop'} = \@optionloop; - $reserve{'suspend'} = $res->{'suspend'}; - $reserve{'suspend_until'} = $res->{'suspend_until'}; - $reserve{'reserve_id'} = $res->{'reserve_id'}; + if ( C4::Context->preference('HidePatronName') ) { + $reserve{'hidename'} = 1; + $reserve{'cardnumber'} = $res->borrower()->cardnumber(); + } + $reserve{'expirationdate'} = output_pref( { dt => dt_from_string( $res->expirationdate ), dateonly => 1 } ) + unless ( !defined( $res->expirationdate ) || $res->expirationdate eq '0000-00-00' ); + $reserve{'date'} = output_pref( { dt => dt_from_string( $res->reservedate ), dateonly => 1 } ); + $reserve{'borrowernumber'} = $res->borrowernumber(); + $reserve{'biblionumber'} = $res->biblionumber(); + $reserve{'borrowernumber'} = $res->borrowernumber(); + $reserve{'firstname'} = $res->borrower()->firstname(); + $reserve{'surname'} = $res->borrower()->surname(); + $reserve{'notes'} = $res->reservenotes(); + $reserve{'wait'} = $res->is_waiting(); + $reserve{'waiting_date'} = $res->waitingdate(); + $reserve{'waiting_until'} = $res->is_waiting() ? $res->waiting_expires_on() : undef; + $reserve{'ccode'} = $res->item() ? $res->item()->ccode() : undef; + $reserve{'barcode'} = $res->item() ? $res->item()->barcode() : undef; + $reserve{'priority'} = $res->priority(); + $reserve{'lowestPriority'} = $res->lowestPriority(); + $reserve{'optionloop'} = \@optionloop; + $reserve{'suspend'} = $res->suspend(); + $reserve{'suspend_until'} = $res->suspend_until(); + $reserve{'reserve_id'} = $res->reserve_id(); if ( C4::Context->preference('IndependentBranches') && $flags->{'superlibrarian'} != 1 ) { - $reserve{'branchloop'} = [ GetBranchDetail($res->{'branchcode'}) ]; - } else { - $reserve{'branchloop'} = GetBranchesLoop($res->{'branchcode'}); + $reserve{'branchloop'} = [ GetBranchDetail( $res->branchcode() ) ]; + } + else { + $reserve{'branchloop'} = GetBranchesLoop( $res->branchcode() ); } push( @reserveloop, \%reserve ); -- 2.39.5