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;
30 use Koha::Exceptions::ArticleRequest;
32 use base qw(Koha::Object);
36 Koha::ArticleRequest - Koha Article Request Object class
46 $article_request->request;
48 Marks the article as requested. Send a notification if appropriate.
55 Koha::Exceptions::ArticleRequest::LimitReached->throw(
56 error => 'Patron cannot request more articles for today'
57 ) unless $self->borrower->can_request_article;
59 $self->status(Koha::ArticleRequest::Status::Requested);
60 $self->SUPER::store();
67 $article_request->set_pending;
69 Marks the article as pending. Send a notification if appropriate.
76 $self->status(Koha::ArticleRequest::Status::Pending);
77 $self->SUPER::store();
84 $article_request->process;
86 Marks the article as in process. Send a notification if appropriate.
93 $self->status(Koha::ArticleRequest::Status::Processing);
101 $article_request->complete;
103 Marks the article as completed. Send a notification if appropriate.
110 $self->status(Koha::ArticleRequest::Status::Completed);
118 $article_request->cancel;
120 Marks the article as cancelled. Send a notification if appropriate.
125 my ( $self, $notes ) = @_;
127 $self->status(Koha::ArticleRequest::Status::Canceled);
128 $self->notes($notes) if $notes;
136 Returns the Koha::Biblio object for this article request
143 $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
145 return $self->{_biblio};
150 Returns the Koha::Item object for this article request
157 $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
159 return $self->{_item};
164 Returns the Koha::Patron object for this article request
171 $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
173 return $self->{_borrower};
178 Returns the Koha::Library object for this article request
185 $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
187 return $self->{_branch};
192 Override the default store behavior so that new opac requests
193 will have notifications sent.
199 if ( $self->in_storage ) {
200 return $self->SUPER::store;
202 $self->created_on( dt_from_string() );
203 return $self->request;
207 =head2 Internal methods
213 internal method to be called when changing an article request status.
214 If a letter exists for the new status, it enqueues it.
221 my $status = $self->status;
225 my $letter = C4::Letters::GetPreparedLetter(
226 module => 'circulation',
227 letter_code => "AR_$status", # AR_REQUESTED, AR_PENDING, AR_PROCESSING, AR_COMPLETED, AR_CANCELED
228 message_transport_type => 'email',
229 lang => $self->borrower->lang,
231 article_requests => $self->id,
232 borrowers => $self->borrowernumber,
233 biblio => $self->biblionumber,
234 biblioitems => $self->biblionumber,
235 items => $self->itemnumber,
236 branches => $self->branchcode,
241 C4::Letters::EnqueueLetter(
244 borrowernumber => $self->borrowernumber,
245 message_transport_type => 'email',
247 ) or warn "can't enqueue letter ". $letter->{code};
256 return 'ArticleRequest';
261 Kyle M Hall <kyle@bywatersolutions.com>