Lines 37-42
use Koha::Checkouts;
Link Here
|
37 |
use Koha::CirculationRules; |
37 |
use Koha::CirculationRules; |
38 |
use Koha::CoverImages; |
38 |
use Koha::CoverImages; |
39 |
use Koha::SearchEngine::Indexer; |
39 |
use Koha::SearchEngine::Indexer; |
|
|
40 |
use Koha::Exceptions::Item::Transfer; |
40 |
use Koha::Item::Transfer::Limits; |
41 |
use Koha::Item::Transfer::Limits; |
41 |
use Koha::Item::Transfers; |
42 |
use Koha::Item::Transfers; |
42 |
use Koha::ItemTypes; |
43 |
use Koha::ItemTypes; |
Lines 401-419
sub holds {
Link Here
|
401 |
return Koha::Holds->_new_from_dbic( $holds_rs ); |
402 |
return Koha::Holds->_new_from_dbic( $holds_rs ); |
402 |
} |
403 |
} |
403 |
|
404 |
|
|
|
405 |
=head3 request_transfer |
406 |
|
407 |
my $transfer = $item->request_transfer( |
408 |
{ to => $to_library, reason => $reason, force => 0 } ); |
409 |
|
410 |
Add a transfer request for this item to the given branch for the given reason. |
411 |
|
412 |
An exception will be thrown if the BranchTransferLimits would prevent the requested |
413 |
transfer, unless 'force' is passed to override the limits. |
414 |
|
415 |
Note: At this time, only one active transfer (i.e pending arrival date) may exist |
416 |
at a time for any given item. An exception will be thrown should you attempt to |
417 |
add a request when a transfer has already been queued, whether it is in transit |
418 |
or just at the request stage. |
419 |
|
420 |
=cut |
421 |
|
422 |
sub request_transfer { |
423 |
my ( $self, $params ) = @_; |
424 |
|
425 |
# check for mandatory params |
426 |
my @mandatory = ( 'to', 'reason' ); |
427 |
for my $param (@mandatory) { |
428 |
unless ( defined( $params->{$param} ) ) { |
429 |
Koha::Exceptions::MissingParameter->throw( |
430 |
error => "The $param parameter is mandatory" ); |
431 |
} |
432 |
} |
433 |
|
434 |
my $request; |
435 |
Koha::Exceptions::Item::Transfer::Found->throw( transfer => $request ) |
436 |
if ( $request = $self->get_transfer ); |
437 |
# FIXME: Add override functionality to allow for queing transfers |
438 |
|
439 |
Koha::Exceptions::Item::Transfer::Limit->throw() |
440 |
unless ( $params->{force} || $self->can_be_transferred( { to => $params->{to} } ) ); |
441 |
|
442 |
my $transfer = Koha::Item::Transfer->new( |
443 |
{ |
444 |
itemnumber => $self->itemnumber, |
445 |
daterequested => dt_from_string, |
446 |
frombranch => $self->holdingbranch, |
447 |
tobranch => $params->{to}->branchcode, |
448 |
reason => $params->{reason}, |
449 |
comments => $params->{comment} |
450 |
} |
451 |
)->store(); |
452 |
return $transfer; |
453 |
} |
454 |
|
404 |
=head3 get_transfer |
455 |
=head3 get_transfer |
405 |
|
456 |
|
406 |
my $transfer = $item->get_transfer; |
457 |
my $transfer = $item->get_transfer; |
407 |
|
458 |
|
408 |
Return the transfer if the item is in transit or undef |
459 |
Return the active transfer request or undef |
|
|
460 |
|
461 |
Note: Transfers are retrieved in a LIFO (Last In First Out) order using this method. |
462 |
|
463 |
FIXME: Add Tests for LIFO functionality |
409 |
|
464 |
|
410 |
=cut |
465 |
=cut |
411 |
|
466 |
|
412 |
sub get_transfer { |
467 |
sub get_transfer { |
413 |
my ( $self ) = @_; |
468 |
my ($self) = @_; |
414 |
my $transfer_rs = $self->_result->branchtransfers->search({ datearrived => undef })->first; |
469 |
my $transfer_rs = $self->_result->branchtransfers->search( |
|
|
470 |
{ datearrived => undef }, |
471 |
{ |
472 |
order_by => [ { -asc => 'datesent' }, { -asc => 'daterequested' } ], |
473 |
rows => 1 |
474 |
} |
475 |
)->first; |
415 |
return unless $transfer_rs; |
476 |
return unless $transfer_rs; |
416 |
return Koha::Item::Transfer->_new_from_dbic( $transfer_rs ); |
477 |
return Koha::Item::Transfer->_new_from_dbic($transfer_rs); |
417 |
} |
478 |
} |
418 |
|
479 |
|
419 |
=head3 last_returned_by |
480 |
=head3 last_returned_by |