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