|
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::Patrons; |
42 |
use Koha::Patrons; |
|
Lines 379-397
sub holds {
Link Here
|
| 379 |
return Koha::Holds->_new_from_dbic( $holds_rs ); |
380 |
return Koha::Holds->_new_from_dbic( $holds_rs ); |
| 380 |
} |
381 |
} |
| 381 |
|
382 |
|
|
|
383 |
=head3 request_transfer |
| 384 |
|
| 385 |
my $transfer = $item->request_transfer( |
| 386 |
{ to => $to_library, reason => $reason, force => 0 } ); |
| 387 |
|
| 388 |
Add a transfer request for this item to the given branch for the given reason. |
| 389 |
|
| 390 |
An exception will be thrown if the BranchTransferLimits would prevent the requested |
| 391 |
transfer, unless 'force' is passed to override the limits. |
| 392 |
|
| 393 |
Note: At this time, only one active transfer (i.e pending arrival date) may exist |
| 394 |
at a time for any given item. An exception will be thrown should you attempt to |
| 395 |
add a request when a transfer has already been queued, whether it is in transit |
| 396 |
or just at the request stage. |
| 397 |
|
| 398 |
=cut |
| 399 |
|
| 400 |
sub request_transfer { |
| 401 |
my ( $self, $params ) = @_; |
| 402 |
|
| 403 |
# check for mandatory params |
| 404 |
my @mandatory = ( 'to', 'reason' ); |
| 405 |
for my $param (@mandatory) { |
| 406 |
unless ( defined( $params->{$param} ) ) { |
| 407 |
Koha::Exceptions::MissingParameter->throw( |
| 408 |
error => "The $param parameter is mandatory" ); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
my $request; |
| 413 |
Koha::Exceptions::Item::Transfer::Found->throw( transfer => $request ) |
| 414 |
if ( $request = $self->get_transfer ); |
| 415 |
# FIXME: Add override functionality to allow for queing transfers |
| 416 |
|
| 417 |
Koha::Exceptions::Item::Transfer::Limit->throw() |
| 418 |
unless ( $params->{force} || $self->can_be_transferred( { to => $params->{to} } ) ); |
| 419 |
|
| 420 |
my $transfer = Koha::Item::Transfer->new( |
| 421 |
{ |
| 422 |
itemnumber => $self->itemnumber, |
| 423 |
daterequested => dt_from_string, |
| 424 |
frombranch => $self->holdingbranch, |
| 425 |
tobranch => $params->{to}->branchcode, |
| 426 |
reason => $params->{reason}, |
| 427 |
comments => $params->{comment} |
| 428 |
} |
| 429 |
)->store(); |
| 430 |
return $transfer; |
| 431 |
} |
| 432 |
|
| 382 |
=head3 get_transfer |
433 |
=head3 get_transfer |
| 383 |
|
434 |
|
| 384 |
my $transfer = $item->get_transfer; |
435 |
my $transfer = $item->get_transfer; |
|
|
436 |
|
| 437 |
Return the active transfer request or undef |
| 385 |
|
438 |
|
| 386 |
Return the transfer if the item is in transit or undef |
439 |
Note: Transfers are retrieved in a LIFO (Last In First Out) order using this method. |
|
|
440 |
|
| 441 |
FIXME: Add Tests for LIFO functionality |
| 387 |
|
442 |
|
| 388 |
=cut |
443 |
=cut |
| 389 |
|
444 |
|
| 390 |
sub get_transfer { |
445 |
sub get_transfer { |
| 391 |
my ( $self ) = @_; |
446 |
my ($self) = @_; |
| 392 |
my $transfer_rs = $self->_result->branchtransfers->search({ datearrived => undef })->first; |
447 |
my $transfer_rs = $self->_result->branchtransfers->search( |
|
|
448 |
{ datearrived => undef }, |
| 449 |
{ |
| 450 |
order_by => [ { -asc => 'datesent' }, { -asc => 'daterequested' } ], |
| 451 |
rows => 1 |
| 452 |
} |
| 453 |
)->first; |
| 393 |
return unless $transfer_rs; |
454 |
return unless $transfer_rs; |
| 394 |
return Koha::Item::Transfer->_new_from_dbic( $transfer_rs ); |
455 |
return Koha::Item::Transfer->_new_from_dbic($transfer_rs); |
| 395 |
} |
456 |
} |
| 396 |
|
457 |
|
| 397 |
=head3 last_returned_by |
458 |
=head3 last_returned_by |