1 package Koha::Item::Transfer;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 use Koha::Exceptions::Item::Transfer;
29 use base qw(Koha::Object);
33 Koha::Item::Transfer - Koha Item Transfer Object class
43 my $item = $transfer->item;
45 Returns the associated item for this transfer.
51 my $item_rs = $self->_result->itemnumber;
52 return Koha::Item->_new_from_dbic($item_rs);
57 my $from_library = $transfer->from_library;
59 Returns the associated from_library for this transfer.
65 my $from_library_rs = $self->_result->frombranch;
66 return Koha::Library->_new_from_dbic($from_library_rs);
71 my $to_library = $transfer->to_library;
73 Returns the associated to_library for this transfer.
79 my $to_library_rs = $self->_result->tobranch;
80 return Koha::Library->_new_from_dbic($to_library_rs);
85 Set the transfer as in transit by updating the datesent time.
87 Also, update date last seen and ensure item holdingbranch is correctly set.
94 # Throw exception if item is still checked out
95 Koha::Exceptions::Item::Transfer::OnLoan->throw() if ( $self->item->checkout );
97 # Remove the 'shelving cart' location status if it is being used (Bug 3701)
98 CartToShelf( $self->item->itemnumber )
99 if $self->item->location
100 && $self->item->location eq 'CART'
101 && (!$self->item->permanent_location
102 || $self->item->permanent_location ne 'CART' );
104 # Update the transit state
107 frombranch => $self->item->holdingbranch,
108 datesent => dt_from_string,
112 ModDateLastSeen( $self->item->itemnumber );
119 Boolean returning whether the transfer is in transit or waiting
126 return ( defined( $self->datesent )
127 && !defined( $self->datearrived )
128 && !defined( $self->datecancelled ) );
133 Receive the transfer by setting the datearrived time.
140 # Throw exception if item is checked out
141 Koha::Exceptions::Item::Transfer::OnLoan->throw() if ($self->item->checkout);
143 # Update the arrived date
144 $self->set({ datearrived => dt_from_string })->store;
146 ModDateLastSeen( $self->item->itemnumber );
152 $transfer->cancel({ reason => $reason, [force => 1]});
154 Cancel the transfer by setting the datecancelled time and recording the reason.
159 my ( $self, $params ) = @_;
161 Koha::Exceptions::MissingParameter->throw(
162 error => "The 'reason' parameter is mandatory" )
163 unless defined($params->{reason});
165 my $in_transit = $self->in_transit;
167 # Throw exception if item is in transit already
168 Koha::Exceptions::Item::Transfer::InTransit->throw() if ( !$params->{force} && $in_transit );
170 # Update the cancelled date
172 { datecancelled => dt_from_string, cancellation_reason => $params->{reason} } )
175 # Set up return transfer if transfer was force cancelled whilst in transit
176 # NOTE: We don't catch here, as we're happy to fail if there are already
177 # other transfers in the queue.
179 $self->item->request_transfer(
180 { to => $self->from_library, reason => 'TransferCancellation' } );
191 return 'Branchtransfer';