Lines 30-37
use C4::Reserves qw(CheckReserves);
Link Here
|
30 |
use Koha::Database; |
30 |
use Koha::Database; |
31 |
|
31 |
|
32 |
use DBI; |
32 |
use DBI; |
33 |
|
33 |
use Try::Tiny; |
34 |
use Data::Dumper; |
|
|
35 |
|
34 |
|
36 |
use vars qw(@ISA @EXPORT); |
35 |
use vars qw(@ISA @EXPORT); |
37 |
|
36 |
|
Lines 410-417
Transfers a collection to another branch
Link Here
|
410 |
|
409 |
|
411 |
Output: |
410 |
Output: |
412 |
$success: 1 if all database operations were successful, 0 otherwise |
411 |
$success: 1 if all database operations were successful, 0 otherwise |
413 |
$errorCode: Code for reason of failure, good for translating errors in templates |
412 |
$messages: Arrayref of messages for user feedback |
414 |
$errorMessage: English description of error |
|
|
415 |
|
413 |
|
416 |
=cut |
414 |
=cut |
417 |
|
415 |
|
Lines 435-441
sub TransferCollection {
Link Here
|
435 |
colBranchcode = ? |
433 |
colBranchcode = ? |
436 |
WHERE colId = ?" |
434 |
WHERE colId = ?" |
437 |
); |
435 |
); |
438 |
$sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() ); |
436 |
$sth->execute( $colBranchcode, $colId ) or return 0; |
|
|
437 |
my $to_library = Koha::Libraries->find( $colBranchcode ); |
439 |
|
438 |
|
440 |
$sth = $dbh->prepare(q{ |
439 |
$sth = $dbh->prepare(q{ |
441 |
SELECT items.itemnumber, items.barcode FROM collections_tracking |
440 |
SELECT items.itemnumber, items.barcode FROM collections_tracking |
Lines 444-464
sub TransferCollection {
Link Here
|
444 |
WHERE issues.borrowernumber IS NULL |
443 |
WHERE issues.borrowernumber IS NULL |
445 |
AND collections_tracking.colId = ? |
444 |
AND collections_tracking.colId = ? |
446 |
}); |
445 |
}); |
447 |
$sth->execute($colId) or return ( 0, 4, $sth->errstr ); |
446 |
$sth->execute($colId) or return 0; |
448 |
my @results; |
447 |
my $messages; |
449 |
while ( my $item = $sth->fetchrow_hashref ) { |
448 |
while ( my $item = $sth->fetchrow_hashref ) { |
450 |
my ($status) = CheckReserves( $item->{itemnumber} ); |
449 |
my $item_object = Koha::Items->find( $item->{itemnumber} ); |
451 |
my @transfers = C4::Circulation::GetTransfers( $item->{itemnumber} ); |
450 |
try { |
452 |
C4::Circulation::transferbook({ |
451 |
$item_object->request_transfer( |
453 |
from_branch => $item->holdingbranch, |
452 |
{ |
454 |
to_branch => $colBranchcode, |
453 |
to => $to_library, |
455 |
barcode => $item->{barcode}, |
454 |
reason => 'RotatingCollection', |
456 |
ignore_reserves => 1, |
455 |
ignore_limits => 0 |
457 |
trigger => 'RotatingCollection' |
456 |
} |
458 |
}) unless ( $status eq 'Waiting' || $status eq 'Processing' || @transfers ); |
457 |
); # Request transfer |
|
|
458 |
} |
459 |
catch { |
460 |
if ( $_->isa('Koha::Exceptions::Item::Transfer::Found') ) { |
461 |
my $exception = $_; |
462 |
my $found_transfer = $_->transfer; |
463 |
if ( $found_transfer->in_transit |
464 |
|| $found_transfer->reason eq 'Reserve' ) |
465 |
{ |
466 |
my $transfer = $item_object->request_transfer( |
467 |
{ |
468 |
to => $to_library, |
469 |
reason => "RotatingCollection", |
470 |
ignore_limits => 0, |
471 |
enqueue => 1 |
472 |
} |
473 |
); # Queue transfer |
474 |
push @{$messages}, |
475 |
{ |
476 |
type => 'enqueu', |
477 |
item => $item_object, |
478 |
found_transfer => $found_transfer |
479 |
}; |
480 |
} |
481 |
else { |
482 |
my $transfer = $item_object->request_transfer( |
483 |
{ |
484 |
to => $to_library, |
485 |
reason => "RotatingCollection", |
486 |
ignore_limits => 0, |
487 |
replace => 1 |
488 |
} |
489 |
); # Replace transfer |
490 |
# NOTE: If we just replaced a StockRotationAdvance, |
491 |
# it will get enqueued afresh on the next cron run |
492 |
} |
493 |
} |
494 |
elsif ( $_->isa('Koha::Exceptions::Item::Transfer::Limit') ) { |
495 |
push @{$messages}, { type => 'failure', item => $item_object }; |
496 |
} |
497 |
else { |
498 |
$_->rethrow(); |
499 |
} |
500 |
}; |
459 |
} |
501 |
} |
460 |
|
502 |
|
461 |
return 1; |
503 |
return (1, $messages); |
462 |
} |
504 |
} |
463 |
|
505 |
|
464 |
=head2 GetCollectionItemBranches |
506 |
=head2 GetCollectionItemBranches |