From d48354808144d6e2d1ec2dc4ba74bf435767b38b Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Wed, 17 May 2017 10:36:05 +0000 Subject: [PATCH] Bug 18606: Get rid of GetCollectionItemBranches --- C4/Circulation.pm | 2 +- C4/RotatingCollections.pm | 31 ------------------------------- Koha/Item.pm | 19 +++++++++++++++++++ circ/returns.pl | 23 +++++++++++------------ 4 files changed, 31 insertions(+), 44 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index fba723f..636487a 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -35,7 +35,7 @@ use C4::Message; use C4::Debug; use C4::Log; # logaction use C4::Overdues qw(CalcFine UpdateFine get_chargeable_units); -use C4::RotatingCollections qw(GetCollectionItemBranches); +use C4::RotatingCollections; use Algorithm::CheckDigits; use Data::Dumper; diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm index dafc1dc..521a4e9 100644 --- a/C4/RotatingCollections.pm +++ b/C4/RotatingCollections.pm @@ -51,8 +51,6 @@ BEGIN { AddItemToCollection RemoveItemFromCollection TransferCollection - - GetCollectionItemBranches ); } @@ -204,35 +202,6 @@ sub TransferCollection { } -=head2 GetCollectionItemBranches - - my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber ); - -=cut - -sub GetCollectionItemBranches { - my ($itemnumber) = @_; - - if ( !$itemnumber ) { - return; - } - - my $dbh = C4::Context->dbh; - - my ( $sth, @results ); - $sth = $dbh->prepare( -"SELECT holdingbranch, colBranchcode FROM items, collections, collections_tracking - WHERE items.itemnumber = collections_tracking.itemnumber - AND collections.colId = collections_tracking.colId - AND items.itemnumber = ?" - ); - $sth->execute($itemnumber); - - my $row = $sth->fetchrow_hashref; - - return ( $$row{'holdingbranch'}, $$row{'colBranchcode'}, ); -} - =head2 isItemInThisCollection $inCollection = isItemInThisCollection( $itemnumber, $colId ); diff --git a/Koha/Item.pm b/Koha/Item.pm index bea05f8..3a15571 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -30,6 +30,7 @@ use Koha::IssuingRules; use Koha::Item::Transfer; use Koha::Patrons; use Koha::Libraries; +use Koha::RotatingCollections; use base qw(Koha::Object); @@ -235,6 +236,24 @@ sub current_holds { return Koha::Holds->_new_from_dbic($hold_rs); } +=head3 rotating_collection + +=cut + +sub rotating_collection { + my ( $self ) = @_; + my $collection = Koha::RotatingCollections->search( + { + 'collections_trackings.itemnumber' => $self->itemnumber + }, + { + join => [ 'collections_trackings' ] + } + ); + + return $collection->single; +} + =head3 type =cut diff --git a/circ/returns.pl b/circ/returns.pl index 5fe3c70..599291b 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -48,7 +48,6 @@ use C4::Items; use C4::Members; use C4::Members::Messaging; use C4::Koha; # FIXME : is it still useful ? -use C4::RotatingCollections; use Koha::AuthorisedValues; use Koha::DateUtils; use Koha::Calendar; @@ -644,17 +643,17 @@ $template->param( $itemnumber = GetItemnumberFromBarcode( $barcode ); if ( $itemnumber ) { - my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber ); - if ( $holdingBranch and $collectionBranch ) { - $holdingBranch //= ''; - $collectionBranch //= $returnbranch; - if ( ! ( $holdingBranch eq $collectionBranch ) ) { - $template->param( - collectionItemNeedsTransferred => 1, - collectionBranch => $collectionBranch, - itemnumber => $itemnumber, - ); - } + my $item = Koha::Items->find( $itemnumber ); + my $holdingBranch = $item->holdingbranch; + my $collection = $item->rotating_collection; + my $collectionBranch; + $collectionBranch = $collection->colBranchcode if $collection; + if ( $holdingBranch and $collectionBranch and ( $holdingBranch ne $collectionBranch ) ) { + $template->param( + collectionItemNeedsTransferred => 1, + collectionBranch => $collectionBranch, + itemnumber => $itemnumber, + ); } } -- 2.1.4