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