From 372ef42af67949f56562121823b1cce3b02af47f 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 --- Koha/Hold.pm | 48 +++++++- .../prog/en/modules/reserve/request.tt | 10 ++- reserve/request.pl | 128 ++++++++++--------- 3 files changed, 121 insertions(+), 65 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index b874f13..1b743e8 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); @@ -62,6 +64,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 @@ -71,9 +87,23 @@ Returns true if hold is a waiting hold sub is_waiting { my ($self) = @_; + return 0 unless $self->found(); return $self->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 @@ -116,6 +146,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 80be359..5077637 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -732,12 +732,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 62f82a8..6ea4410 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -44,6 +44,7 @@ use C4::Utils::DataTables::Members; use C4::Members; use C4::Search; # enabled_staff_search_views use Koha::DateUtils; +use Koha::Holds; my $dbh = C4::Context->dbh; my $sth; @@ -461,87 +462,92 @@ 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'} = format_date( $res->{'expirationdate'} ) - unless ( !defined($res->{'expirationdate'}) || $res->{'expirationdate'} eq '0000-00-00' ); - $reserve{'date'} = format_date( $res->{'reservedate'} ); - $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{'constrainttypea'} = ( $res->{'constrainttype'} eq 'a' ); - $reserve{'constrainttypeo'} = ( $res->{'constrainttype'} eq 'o' ); - $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'} = format_date( $res->expirationdate() ) + unless ( !defined( $res->expirationdate() ) || $res->expirationdate() eq '0000-00-00' ); + $reserve{'date'} = format_date( $res->reservedate() ); + $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{'constrainttypea'} = ( $res->constrainttype() eq 'a' ); + $reserve{'constrainttypeo'} = ( $res->constrainttype() eq 'o' ); + $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 ); -- 1.7.2.5