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>.
26 use Koha::Exceptions::Item::Transfer;
28 use base qw(Koha::Object);
32 Koha::Item::Transfer - Koha Item Transfer Object class
42 my $item = $transfer->item;
44 Returns the associated item for this transfer.
50 my $item_rs = $self->_result->itemnumber;
51 return Koha::Item->_new_from_dbic($item_rs);
56 my $from_library = $transfer->from_library;
58 Returns the associated from_library for this transfer.
64 my $from_library_rs = $self->_result->frombranch;
65 return Koha::Library->_new_from_dbic($from_library_rs);
70 my $to_library = $transfer->to_library;
72 Returns the associated to_library for this transfer.
78 my $to_library_rs = $self->_result->tobranch;
79 return Koha::Library->_new_from_dbic($to_library_rs);
84 Set the transfer as in transit by updating the datesent time.
86 Also, update date last seen and ensure item holdingbranch is correctly set.
93 # Throw exception if item is still checked out
94 Koha::Exceptions::Item::Transfer::OnLoan->throw() if ( $self->item->checkout );
96 # Remove the 'shelving cart' location status if it is being used (Bug 3701)
97 CartToShelf( $self->item->itemnumber )
98 if $self->item->location
99 && $self->item->location eq 'CART'
100 && (!$self->item->permanent_location
101 || $self->item->permanent_location ne 'CART' );
103 # Update the transit state
106 frombranch => $self->item->holdingbranch,
107 datesent => dt_from_string,
111 ModDateLastSeen( $self->item->itemnumber );
118 Boolean returning whether the transfer is in transit or waiting
125 return ( defined( $self->datesent )
126 && !defined( $self->datearrived )
127 && !defined( $self->datecancelled ) );
132 Receive the transfer by setting the datearrived time.
139 # Throw exception if item is checked out
140 Koha::Exceptions::Item::Transfer::OnLoan->throw() if ($self->item->checkout);
142 # Update the arrived date
143 $self->set({ datearrived => dt_from_string })->store;
145 ModDateLastSeen( $self->item->itemnumber );
151 $transfer->cancel({ reason => $reason, [force => 1]});
153 Cancel the transfer by setting the datecancelled time and recording the reason.
158 my ( $self, $params ) = @_;
160 Koha::Exceptions::MissingParameter->throw(
161 error => "The 'reason' parameter is mandatory" )
162 unless defined($params->{reason});
164 # Throw exception if item is in transit already
165 Koha::Exceptions::Item::Transfer::InTransit->throw() if ( !$params->{force} && $self->in_transit );
167 # Update the cancelled date
169 { datecancelled => dt_from_string, cancellation_reason => $params->{reason} } )
180 return 'Branchtransfer';