- WHERE colId = ?");
- $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() );
- $sth->finish;
-
- $sth = $dbh->prepare("SELECT barcode FROM items, collections_tracking
+ WHERE colId = ?"
+ );
+ $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() );
+
+ $sth = $dbh->prepare(q{
+ SELECT items.itemnumber, items.barcode FROM collections_tracking
+ LEFT JOIN items ON collections_tracking.itemnumber = items.itemnumber
+ LEFT JOIN issues ON items.itemnumber = issues.itemnumber
+ WHERE issues.borrowernumber IS NULL
+ AND collections_tracking.colId = ?
+ });
+ $sth->execute($colId) or return ( 0, 4, $sth->errstr );
+ my @results;
+ while ( my $item = $sth->fetchrow_hashref ) {
+ my ($status) = CheckReserves( $item->{itemnumber} );
+ my @transfers = C4::Circulation::GetTransfers( $item->{itemnumber} );
+ C4::Circulation::transferbook( $colBranchcode, $item->{barcode}, my $ignore_reserves = 1 ) unless ( $status eq 'Waiting' || @transfers );
+ }
+
+ return 1;
+
+}
+
+=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