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