From 494b86d60c26b4a4037103963fa40ffa1a277e97 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 Jan 2014 16:55:41 +0100 Subject: [PATCH] Bug 10827: Check if the item should be transfered in ModReserveAffect Before this patch, ModReserveAffect should know if the item have to be transfered. Now it is checked in the routine. Moreover, it is possible to pass an item key in parameters. If it is not given, the item's information is retrieved from GetBiblioFromItemNumber. --- C4/Reserves.pm | 26 ++++++++++++++++++++++---- circ/returns.pl | 13 ++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 30c221d..8a9173f 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1215,7 +1215,7 @@ sub ModReserveStatus { =head2 ModReserveAffect - &ModReserveAffect({ itemnumber => $itemnumber, borrowernumber => $borrowernumber, force_transfer => $diffBranchSend }); + &ModReserveAffect({ item => $item, itemnumber => $itemnumber, borrowernumber => $borrowernumber, force_transfer => $diffBranchSend }); This function affect an item and a status for a given reserve The itemnumber parameter is used to find the biblionumber. @@ -1230,10 +1230,17 @@ take care of the waiting status sub ModReserveAffect { my ( $params ) = @_; + my $item = $params->{item}; my $borrowernumber = $params->{borrowernumber}; my $itemnumber = $params->{itemnumber}; my $force_transfer = $params->{force_transfer}; + if ( $item ) { + $itemnumber = $item->{itemnumber}; + } else { + $item = GetBiblioFromItemNumber( $itemnumber ); + } + my $dbh = C4::Context->dbh; # we want to attach $itemnumber to $borrowernumber, find the biblionumber @@ -1252,9 +1259,18 @@ sub ModReserveAffect { my $request = GetReserveInfo($reserve_id); my $already_on_shelf = ($request && $request->{found} eq 'W') ? 1 : 0; + my $transfer_to_do = 0; + if ( defined $force_transfer ) { + $transfer_to_do = $force_transfer; + } else { + my $userenv_branch = C4::Context->userenv->{'branch'} || ''; + $transfer_to_do = 1 + if $userenv_branch ne $request->{branchcode}; + } + # If we affect a reserve that has to be transfered, don't set to Waiting my $query; - if ( $force_transfer ) { + if ( $transfer_to_do ) { $query = " UPDATE reserves SET priority = 0, @@ -1278,7 +1294,9 @@ sub ModReserveAffect { } $sth = $dbh->prepare($query); $sth->execute( $itemnumber, $borrowernumber,$biblionumber); - _koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber ) if ( !$force_transfer && !$already_on_shelf ); + + _koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber ) + unless $transfer_to_do or $already_on_shelf; if ( C4::Context->preference("ReturnToShelvingCart") ) { CartToShelf( $itemnumber ); @@ -1714,7 +1732,7 @@ sub _FixPriority { $priority[$j]->{'reserve_id'} ); } - + $sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); $sth->execute(); diff --git a/circ/returns.pl b/circ/returns.pl index 2693f53..51a5c4d 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -132,19 +132,18 @@ if ($query->param('WT-itemNumber')){ } if ( $query->param('resbarcode') ) { - my $item = $query->param('itemnumber'); + my $itemnumber = $query->param('itemnumber'); my $borrowernumber = $query->param('borrowernumber'); my $resbarcode = $query->param('resbarcode'); my $diffBranchReturned = $query->param('diffBranch'); - my $iteminfo = GetBiblioFromItemNumber($item); + my $iteminfo = GetBiblioFromItemNumber($itemnumber); # fix up item type for display $iteminfo->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $iteminfo->{'itype'} : $iteminfo->{'itemtype'}; - my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef; -# diffBranchSend tells ModReserveAffect whether document is expected in this library or not, -# i.e., whether to apply waiting status - ModReserveAffect({ itemnumber => $item, borrowernumber => $borrowernumber, force_transfer => $diffBranchSend }); + + ModReserveAffect({ item => $iteminfo, borrowernumber => $borrowernumber }); + # check if we have other reserves for this document, if we have a return send the message of transfer - my ( $messages, $nextreservinfo ) = GetOtherReserves($item); + my ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber); my ($borr) = GetMemberDetails( $nextreservinfo, 0 ); my $name = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'}; -- 1.7.10.4