Bug 25767: Add Koha::Item::Transfer->receive method
[srvgit] / Koha / Item / Transfer.pm
1 package Koha::Item::Transfer;
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Carp;
21
22 use C4::Items;
23
24 use Koha::Database;
25 use Koha::DateUtils;
26 use Koha::Exceptions::Item::Transfer;
27
28 use base qw(Koha::Object);
29
30 =head1 NAME
31
32 Koha::Item::Transfer - Koha Item Transfer Object class
33
34 =head1 API
35
36 =head2 Class Methods
37
38 =cut
39
40 =head3 item
41
42   my $item = $transfer->item;
43
44 Returns the associated item for this transfer.
45
46 =cut
47
48 sub item {
49     my ($self) = @_;
50     my $item_rs = $self->_result->itemnumber;
51     return Koha::Item->_new_from_dbic($item_rs);
52 }
53
54 =head3 transit
55
56 Set the transfer as in transit by updating the datesent time.
57
58 Also, update date last seen and ensure item holdingbranch is correctly set.
59
60 =cut
61
62 sub transit {
63     my ($self) = @_;
64
65     # Throw exception if item is still checked out
66     Koha::Exceptions::Item::Transfer::Out->throw() if ( $self->item->checkout );
67
68     # Remove the 'shelving cart' location status if it is being used (Bug 3701)
69     CartToShelf( $self->item->itemnumber )
70       if $self->item->location
71       && $self->item->location eq 'CART'
72       && (!$self->item->permanent_location
73         || $self->item->permanent_location ne 'CART' );
74
75     # Update the transit state
76     $self->set(
77         {
78             frombranch => $self->item->holdingbranch,
79             datesent   => dt_from_string,
80         }
81     )->store;
82
83     ModDateLastSeen( $self->item->itemnumber );
84     return $self;
85 }
86
87 =head3 receive
88
89 Receive the transfer by setting the datearrived time.
90
91 =cut
92
93 sub receive {
94     my ($self) = @_;
95
96     # Throw exception if item is checked out
97     Koha::Exceptions::Item::Transfer::Out->throw() if ($self->item->checkout);
98
99     # Update the arrived date
100     $self->set({ datearrived => dt_from_string })->store;
101
102     ModDateLastSeen( $self->item->itemnumber );
103     return $self;
104 }
105
106 =head3 type
107
108 =cut
109
110 sub _type {
111     return 'Branchtransfer';
112 }
113
114 1;