Bug 10076 - Add Bcc syspref for ClaimAcquisition and ClaimIssues
[koha.git] / Koha / Item.pm
blobe8543e1df166364cc3ab47b0d6e24d9e56aa395f
1 package Koha::Item;
3 # Copyright ByWater Solutions 2014
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Modern::Perl;
22 use Carp;
24 use Koha::Database;
26 use Koha::Branches;
27 use Koha::Borrowers;
29 use base qw(Koha::Object);
31 =head1 NAME
33 Koha::Item - Koha Item object class
35 =head1 API
37 =head2 Class Methods
39 =cut
41 =head3 effective_itemtype
43 Returns the itemtype for the item based on whether item level itemtypes are set or not.
45 =cut
47 sub effective_itemtype {
48 my ( $self ) = @_;
50 return $self->_result()->effective_itemtype();
53 =head3 home_branch
55 =cut
57 sub home_branch {
58 my ($self) = @_;
60 $self->{_home_branch} ||= Koha::Branches->find( $self->homebranch() );
62 return $self->{_home_branch};
65 =head3 holding_branch
67 =cut
69 sub holding_branch {
70 my ($self) = @_;
72 $self->{_holding_branch} ||= Koha::Branches->find( $self->holdingbranch() );
74 return $self->{_holding_branch};
77 =head3 last_returned_by
79 Gets and sets the last borrower to return an item.
81 Accepts and returns Koha::Borrower objects
83 $item->last_returned_by( $borrowernumber );
85 $last_returned_by = $item->last_returned_by();
87 =cut
89 sub last_returned_by {
90 my ( $self, $borrower ) = @_;
92 my $items_last_returned_by_rs = Koha::Database->new()->schema()->resultset('ItemsLastBorrower');
94 if ($borrower) {
95 return $items_last_returned_by_rs->update_or_create(
96 { borrowernumber => $borrower->borrowernumber, itemnumber => $self->id } );
98 else {
99 unless ( $self->{_last_returned_by} ) {
100 my $result = $items_last_returned_by_rs->single( { itemnumber => $self->id } );
101 if ($result) {
102 $self->{_last_returned_by} = Koha::Borrowers->find( $result->get_column('borrowernumber') );
106 return $self->{_last_returned_by};
110 =head3 type
112 =cut
114 sub type {
115 return 'Item';
118 =head1 AUTHOR
120 Kyle M Hall <kyle@bywatersolutions.com>
122 =cut