Bug 19726: Move admin templates JavaScript to the footer: Preferences
[koha.git] / Koha / ArticleRequest.pm
blobf114eed338a4047be4730b8716e8b6fffd976fa8
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 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;
25 use Koha::Patrons;
26 use Koha::Biblios;
27 use Koha::Items;
28 use Koha::Libraries;
29 use Koha::ArticleRequest::Status;
30 use Koha::DateUtils qw(dt_from_string);
32 use base qw(Koha::Object);
34 =head1 NAME
36 Koha::ArticleRequest - Koha Article Request Object class
38 =head1 API
40 =head2 Class Methods
42 =cut
44 =head3 open
46 =cut
48 sub open {
49 my ($self) = @_;
51 $self->status(Koha::ArticleRequest::Status::Pending);
52 $self->notify();
53 return $self;
56 =head3 process
58 =cut
60 sub process {
61 my ($self) = @_;
63 $self->status(Koha::ArticleRequest::Status::Processing);
64 $self->store();
65 $self->notify();
66 return $self;
69 =head3 complete
71 =cut
73 sub complete {
74 my ($self) = @_;
76 $self->status(Koha::ArticleRequest::Status::Completed);
77 $self->store();
78 $self->notify();
79 return $self;
82 =head3 cancel
84 =cut
86 sub cancel {
87 my ( $self, $notes ) = @_;
89 $self->status(Koha::ArticleRequest::Status::Canceled);
90 $self->notes($notes) if $notes;
91 $self->store();
92 $self->notify();
93 return $self;
96 =head3 notify
98 =cut
100 sub notify {
101 my ($self) = @_;
103 my $status = $self->status;
105 require C4::Letters;
106 if (
107 my $letter = C4::Letters::GetPreparedLetter(
108 module => 'circulation',
109 letter_code => "AR_$status", # AR_PENDING, AR_PROCESSING, AR_COMPLETED, AR_CANCELED
110 message_transport_type => 'email',
111 lang => $self->borrower->lang,
112 tables => {
113 article_requests => $self->id,
114 borrowers => $self->borrowernumber,
115 biblio => $self->biblionumber,
116 biblioitems => $self->biblionumber,
117 items => $self->itemnumber,
118 branches => $self->branchcode,
123 C4::Letters::EnqueueLetter(
125 letter => $letter,
126 borrowernumber => $self->borrowernumber,
127 message_transport_type => 'email',
129 ) or warn "can't enqueue letter $letter";
133 =head3 biblio
135 Returns the Koha::Biblio object for this article request
137 =cut
139 sub biblio {
140 my ($self) = @_;
142 $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
144 return $self->{_biblio};
147 =head3 item
149 Returns the Koha::Item object for this article request
151 =cut
153 sub item {
154 my ($self) = @_;
156 $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
158 return $self->{_item};
161 =head3 borrower
163 Returns the Koha::Patron object for this article request
165 =cut
167 sub borrower {
168 my ($self) = @_;
170 $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
172 return $self->{_borrower};
175 =head3 branch
177 Returns the Koha::Library object for this article request
179 =cut
181 sub branch {
182 my ($self) = @_;
184 $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
186 return $self->{_branch};
189 =head3 store
191 Override the default store behavior so that new opan requests
192 will have notifications sent.
194 =cut
196 sub store {
197 my ($self) = @_;
199 if ( $self->in_storage() ) {
200 my $now = dt_from_string();
201 $self->updated_on($now);
203 return $self->SUPER::store();
205 else {
206 $self->open();
207 return $self->SUPER::store();
211 =head3 _type
213 =cut
215 sub _type {
216 return 'ArticleRequest';
219 =head1 AUTHOR
221 Kyle M Hall <kyle@bywatersolutions.com>
223 =cut