From 1a9737be768aa1e585addc596e2fcb5a77482c38 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 11 Mar 2013 14:28:57 +0100 Subject: [PATCH] Bug 9788: Improvements when calling GetReservesFromItemnumber This patch makes GetReservesFromItemnumber also returns the waiting date and removes some repeated code. Improves item status display on catalogue detail, when placing a hold at opac-reserve and in staff, and on transfers to receive form. This patch builds on work from reports 9367 and 9761. Test plan: Place a future next-av. hold (enable future holds prefs), say 2 days ahead. Check item status on catalogue detail. Nothing to see. Enable ConfirmFutureHolds by inserting a number of days, say 2. Confirm earlier hold by checking it in. Look at item status again on detail. Switch to other opac user. Try to place a hold again. Check item status with item level hold info. Try to place hold in staff, check item level status. Make a transfer for that item. Switch branch. Look at transfers to receive. Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart Signed-off-by: Galen Charlton --- C4/Reserves.pm | 13 ++++++++----- catalogue/detail.pl | 15 ++++++--------- circ/transferstoreceive.pl | 2 +- opac/opac-reserve.pl | 21 ++++++++------------- reserve/request.pl | 11 ++--------- 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 689f34d4e8..afef863fa7 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -358,9 +358,11 @@ sub GetReservesFromBiblionumber { =head2 GetReservesFromItemnumber - ( $reservedate, $borrowernumber, $branchcode, $reserve_id ) = GetReservesFromItemnumber($itemnumber); + ( $reservedate, $borrowernumber, $branchcode, $reserve_id, $waitingdate ) = GetReservesFromItemnumber($itemnumber, $all_dates); -TODO :: Description here +Get the first reserve for a specific item number (based on priority). Returns the abovementioned values for that reserve. + +all_dates is an optional parameter, telling Koha to include or exclude future holds =cut @@ -368,17 +370,18 @@ sub GetReservesFromItemnumber { my ( $itemnumber, $all_dates ) = @_; my $dbh = C4::Context->dbh; my $query = " - SELECT reservedate,borrowernumber,branchcode,reserve_id + SELECT reservedate,borrowernumber,branchcode,reserve_id,waitingdate FROM reserves WHERE itemnumber=? "; unless ( $all_dates ) { $query .= " AND reservedate <= CURRENT_DATE()"; } + $query .= ' ORDER BY priority'; my $sth_res = $dbh->prepare($query); $sth_res->execute($itemnumber); - my ( $reservedate, $borrowernumber, $branchcode, $reserve_id ) = $sth_res->fetchrow_array; - return ( $reservedate, $borrowernumber, $branchcode, $reserve_id ); + my ( $reservedate, $borrowernumber,$branchcode, $reserve_id, $wait ) = $sth_res->fetchrow_array; + return ( $reservedate, $borrowernumber, $branchcode, $reserve_id, $wait ); } =head2 GetReservesFromBorrowernumber diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 6bc0014c53..a8d15e9a3c 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -233,7 +233,8 @@ foreach my $item (@items) { } # checking for holds - my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($item->{itemnumber}); + my ($reservedate,$reservedfor,$expectedAt,undef,$wait) = GetReservesFromItemnumber($item->{itemnumber}, 1); #second parameter: all dates + # all dates will include a future item level hold or a future wait my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0); if (C4::Context->preference('HidePatronName')){ @@ -247,9 +248,12 @@ foreach my $item (@items) { $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'}; $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'}; $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname}; - $item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'}; + $item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'}; + # Check waiting status + $item->{waitingdate} = format_date($wait) if $wait; } + # Check the transit status my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber}); if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) { @@ -259,13 +263,6 @@ foreach my $item (@items) { $item->{nocancel} = 1; } - # FIXME: move this to a pm, check waiting status for holds - my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'"); - $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber}); - while (my $wait_hashref = $sth2->fetchrow_hashref) { - $item->{waitingdate} = format_date($wait_hashref->{waitingdate}); - } - # item has a host number if its biblio number does not match the current bib if ($item->{biblionumber} ne $biblionumber){ $item->{hostbiblionumber} = $item->{biblionumber}; diff --git a/circ/transferstoreceive.pl b/circ/transferstoreceive.pl index 224df5825e..676a2c5921 100755 --- a/circ/transferstoreceive.pl +++ b/circ/transferstoreceive.pl @@ -99,7 +99,7 @@ foreach my $br ( keys %$branches ) { $getransf{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($gettitle->{'biblionumber'})); # we check if we have a reserv for this transfer - my @checkreserv = GetReservesFromItemnumber($num->{'itemnumber'} ); + my @checkreserv = GetReservesFromItemnumber($num->{'itemnumber'},1 ); #alldate parameter for future holds and waits if ( $checkreserv[0] ) { my $getborrower = GetMemberDetails( $checkreserv[1] ); $getransf{'borrowernum'} = $getborrower->{'borrowernumber'}; diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 97d136a1f3..87d3128982 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -431,13 +431,13 @@ foreach my $biblioNum (@biblionumbers) { } # checking reserve - my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemNum); + my ($reservedate,$reservedfor,$expectedAt,undef,$wait) = GetReservesFromItemnumber($itemNum,1); #with alldates parameter include future item level holds and waits my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0); - # the item could be reserved for this borrower vi a host record, flag this - if ($reservedfor eq $borrowernumber){ - $itemLoopIter->{already_reserved} = 1; - } + # the item could be reserved for this borrower vi a host record, flag this + if ($reservedfor eq $borrowernumber){ + $itemLoopIter->{already_reserved} = 1; + } if ( defined $reservedate ) { $itemLoopIter->{backgroundcolor} = 'reserved'; @@ -446,6 +446,8 @@ foreach my $biblioNum (@biblionumbers) { $itemLoopIter->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'}; $itemLoopIter->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'}; $itemLoopIter->{ExpectedAtLibrary} = $expectedAt; + #waiting status + $itemLoopIter->{waitingdate} = format_date($wait) if $wait; } $itemLoopIter->{notforloan} = $itemInfo->{notforloan}; @@ -505,14 +507,7 @@ foreach my $biblioNum (@biblionumbers) { $numCopiesAvailable++; } - # FIXME: move this to a pm - my $dbh = C4::Context->dbh; - my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'"); - $sth2->execute($itemLoopIter->{ReservedForBorrowernumber}, $itemNum); - while (my $wait_hashref = $sth2->fetchrow_hashref) { - $itemLoopIter->{waitingdate} = format_date($wait_hashref->{waitingdate}); - } - $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemTypes->{ $itemInfo->{itype} }{imageurl} ); + $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemTypes->{ $itemInfo->{itype} }{imageurl} ); # Show serial enumeration when needed if ($itemLoopIter->{enumchron}) { diff --git a/reserve/request.pl b/reserve/request.pl index a735b0cce8..0afc53d7d5 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -328,7 +328,7 @@ foreach my $biblionumber (@biblionumbers) { } # checking reserve - my ($reservedate,$reservedfor,$expectedAt,$reserve_id) = GetReservesFromItemnumber($itemnumber); + my ($reservedate,$reservedfor,$expectedAt,$reserve_id,$wait) = GetReservesFromItemnumber($itemnumber,1); #alldates parameter to include future holds/waits my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor ); if ( defined $reservedate ) { @@ -338,7 +338,7 @@ foreach my $biblionumber (@biblionumbers) { $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'}; $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'}; $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname}; - + $item->{waitingdate} = format_date($wait) if $wait; } # Management of the notforloan document @@ -424,13 +424,6 @@ foreach my $biblionumber (@biblionumbers) { # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked - # FIXME: move this to a pm - my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'"); - $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber}); - while (my $wait_hashref = $sth2->fetchrow_hashref) { - $item->{waitingdate} = format_date($wait_hashref->{waitingdate}); - } - # Show serial enumeration when needed if ($item->{enumchron}) { $itemdata_enumchron = 1; -- 2.39.5