@@ -, +, @@ --- C4/Circulation.pm | 2 +- C4/RotatingCollections.pm | 31 ------------------------------- Koha/Item.pm | 19 +++++++++++++++++++ circ/returns.pl | 23 +++++++++++------------ 4 files changed, 31 insertions(+), 44 deletions(-) --- a/C4/Circulation.pm +++ a/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; --- a/C4/RotatingCollections.pm +++ a/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 ); --- a/Koha/Item.pm +++ a/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 --- a/circ/returns.pl +++ a/circ/returns.pl @@ -45,7 +45,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; @@ -645,17 +644,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, + ); } } --