1 package Koha::ArticleRequest;
3 # Copyright ByWater Solutions 2015
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 use Koha::DateUtils qw( dt_from_string );
29 use Koha::ArticleRequest::Status;
31 use base qw(Koha::Object);
35 Koha::ArticleRequest - Koha Article Request Object class
45 $article_request->request;
47 Marks the article as requested. Send a notification if appropriate.
54 $self->status(Koha::ArticleRequest::Status::Requested);
55 $self->SUPER::store();
62 $article_request->set_pending;
64 Marks the article as pending. Send a notification if appropriate.
71 $self->status(Koha::ArticleRequest::Status::Pending);
72 $self->SUPER::store();
79 $article_request->process;
81 Marks the article as in process. Send a notification if appropriate.
88 $self->status(Koha::ArticleRequest::Status::Processing);
96 $article_request->complete;
98 Marks the article as completed. Send a notification if appropriate.
105 $self->status(Koha::ArticleRequest::Status::Completed);
113 $article_request->cancel;
115 Marks the article as cancelled. Send a notification if appropriate.
120 my ( $self, $notes ) = @_;
122 $self->status(Koha::ArticleRequest::Status::Canceled);
123 $self->notes($notes) if $notes;
131 Returns the Koha::Biblio object for this article request
138 $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
140 return $self->{_biblio};
145 Returns the Koha::Item object for this article request
152 $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
154 return $self->{_item};
159 Returns the Koha::Patron object for this article request
166 $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
168 return $self->{_borrower};
173 Returns the Koha::Library object for this article request
180 $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
182 return $self->{_branch};
187 Override the default store behavior so that new opac requests
188 will have notifications sent.
194 if ( $self->in_storage ) {
195 return $self->SUPER::store;
197 $self->created_on( dt_from_string() );
198 return $self->request;
202 =head2 Internal methods
208 internal method to be called when changing an article request status.
209 If a letter exists for the new status, it enqueues it.
216 my $status = $self->status;
220 my $letter = C4::Letters::GetPreparedLetter(
221 module => 'circulation',
222 letter_code => "AR_$status", # AR_REQUESTED, AR_PENDING, AR_PROCESSING, AR_COMPLETED, AR_CANCELED
223 message_transport_type => 'email',
224 lang => $self->borrower->lang,
226 article_requests => $self->id,
227 borrowers => $self->borrowernumber,
228 biblio => $self->biblionumber,
229 biblioitems => $self->biblionumber,
230 items => $self->itemnumber,
231 branches => $self->branchcode,
236 C4::Letters::EnqueueLetter(
239 borrowernumber => $self->borrowernumber,
240 message_transport_type => 'email',
242 ) or warn "can't enqueue letter ". $letter->{code};
251 return 'ArticleRequest';
256 Kyle M Hall <kyle@bywatersolutions.com>